Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NoMethodError in Bugsnag Railtie #666

Merged
merged 1 commit into from
Jun 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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