Skip to content

Commit

Permalink
Merge pull request #666 from bugsnag/fix-railtie-undefined-method-error
Browse files Browse the repository at this point in the history
Fix `NoMethodError` in Bugsnag Railtie
  • Loading branch information
imjoehaines authored Jun 22, 2021
2 parents 2ddfeca + 13aa40e commit 5ef7cdc
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions lib/bugsnag/integrations/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,44 @@

module Bugsnag
class Railtie < ::Rails::Railtie

FRAMEWORK_ATTRIBUTES = {
:framework => "Rails"
}

##
# Subscribes to an ActiveSupport event, leaving a breadcrumb when it triggers
#
# @api private
# @param event [Hash] details of the event to subscribe to
def event_subscription(event)
ActiveSupport::Notifications.subscribe(event[:id]) do |*, event_id, data|
filtered_data = data.slice(*event[:allowed_data])
filtered_data[:event_name] = event[:id]
filtered_data[:event_id] = event_id

if event[:id] == "sql.active_record"
if data.key?(:binds)
binds = data[:binds].each_with_object({}) { |bind, output| output[bind.name] = '?' if defined?(bind.name) }
filtered_data[:binds] = JSON.dump(binds) unless binds.empty?
end

# Rails < 6.1 included connection_id in the event data, but now
# includes the connection object instead
if data.key?(:connection) && !data.key?(:connection_id)
# the connection ID is the object_id of the connection object
filtered_data[:connection_id] = data[:connection].object_id
end
end

Bugsnag.leave_breadcrumb(
event[:message],
filtered_data,
event[:type],
:auto
)
end
end

rake_tasks do
require "bugsnag/integrations/rake"
load "bugsnag/tasks/bugsnag.rake"
Expand Down Expand Up @@ -80,39 +113,5 @@ class Railtie < ::Rails::Railtie
Bugsnag.configuration.warn("Unable to add Bugsnag::Rack middleware as the middleware stack is frozen")
end
end

##
# Subscribes to an ActiveSupport event, leaving a breadcrumb when it triggers
#
# @api private
# @param event [Hash] details of the event to subscribe to
def event_subscription(event)
ActiveSupport::Notifications.subscribe(event[:id]) do |*, event_id, data|
filtered_data = data.slice(*event[:allowed_data])
filtered_data[:event_name] = event[:id]
filtered_data[:event_id] = event_id

if event[:id] == "sql.active_record"
if data.key?(:binds)
binds = data[:binds].each_with_object({}) { |bind, output| output[bind.name] = '?' if defined?(bind.name) }
filtered_data[:binds] = JSON.dump(binds) unless binds.empty?
end

# Rails < 6.1 included connection_id in the event data, but now
# includes the connection object instead
if data.key?(:connection) && !data.key?(:connection_id)
# the connection ID is the object_id of the connection object
filtered_data[:connection_id] = data[:connection].object_id
end
end

Bugsnag.leave_breadcrumb(
event[:message],
filtered_data,
event[:type],
:auto
)
end
end
end
end

0 comments on commit 5ef7cdc

Please sign in to comment.