diff --git a/CHANGELOG.md b/CHANGELOG.md index 6693b44e9..0ce566aed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,18 @@ Changelog ========= +## TBD + ### Enhancements * Classify `ActionDispatch::Http::MimeNegotiation::InvalidType` as info severity level | [#654](https://github.com/bugsnag/bugsnag-ruby/pull/654) +### Fixes + +* Include `connection_id` in ActiveRecord breadcrumb metadata on new versons of Rails + | [#655](https://github.com/bugsnag/bugsnag-ruby/pull/655) + ## 6.19.0 (6 January 2021) ### Enhancements diff --git a/lib/bugsnag/integrations/rails/rails_breadcrumbs.rb b/lib/bugsnag/integrations/rails/rails_breadcrumbs.rb index aa163963e..9659bce19 100644 --- a/lib/bugsnag/integrations/rails/rails_breadcrumbs.rb +++ b/lib/bugsnag/integrations/rails/rails_breadcrumbs.rb @@ -38,6 +38,8 @@ module Bugsnag::Rails :type => Bugsnag::Breadcrumbs::PROCESS_BREADCRUMB_TYPE, :allowed_data => [ :name, + # :connection_id is no longer provided in Rails 6.1+ but we can get it + # from the :connection key of the event instead :connection_id, :cached ] diff --git a/lib/bugsnag/integrations/railtie.rb b/lib/bugsnag/integrations/railtie.rb index d58dd3b8f..c43f738bf 100644 --- a/lib/bugsnag/integrations/railtie.rb +++ b/lib/bugsnag/integrations/railtie.rb @@ -91,10 +91,21 @@ def event_subscription(event) 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" && 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? + + 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,