diff --git a/CHANGELOG.md b/CHANGELOG.md index b9100a03..0c587346 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Changelog ========= +## TBD + +### Enhancements + +* Use `ActiveSupport::Notifications.monotonic_subscribe` for performance improvement on compatible Rails versions + | [#856](https://github.com/bugsnag/bugsnag-ruby/pull/856) + ## v6.29.0 (21 January 2026) ### Enhancements diff --git a/lib/bugsnag/integrations/railtie.rb b/lib/bugsnag/integrations/railtie.rb index c875972a..ce178254 100644 --- a/lib/bugsnag/integrations/railtie.rb +++ b/lib/bugsnag/integrations/railtie.rb @@ -15,7 +15,9 @@ class Railtie < ::Rails::Railtie # @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| + # monotonic_subscribe was introduced in Rails 6.1+, check if it exists + subscription_method = ActiveSupport::Notifications.respond_to?(:monotonic_subscribe) ? :monotonic_subscribe : :subscribe + ActiveSupport::Notifications.send(subscription_method, 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