diff --git a/lib/honeybadger/plugins/rails.rb b/lib/honeybadger/plugins/rails.rb index 2954da1d..5b8b039d 100644 --- a/lib/honeybadger/plugins/rails.rb +++ b/lib/honeybadger/plugins/rails.rb @@ -32,8 +32,6 @@ def render_exception(arg, exception, *args) class ErrorSubscriber def self.report(exception, handled:, severity:, context: {}, source: nil) - Honeybadger.context(context) - # We only report handled errors (`Rails.error.handle`) # Unhandled errors will be caught by our integrations (eg middleware), # which have richer context than the Rails error reporter @@ -43,7 +41,7 @@ def self.report(exception, handled:, severity:, context: {}, source: nil) tags = ["severity:#{severity}", "handled:#{handled}"] tags << "source:#{source}" if source - Honeybadger.notify(exception, tags: tags) + Honeybadger.notify(exception, context: context, tags: tags) end def self.source_ignored?(source) @@ -67,6 +65,12 @@ def self.source_ignored?(source) end if Honeybadger.config[:'exceptions.enabled'] && defined?(::ActiveSupport::ErrorReporter) # Rails 7 + if defined?(::ActiveSupport::ExecutionContext) + ::ActiveSupport::ExecutionContext.after_change do + Honeybadger.context(::ActiveSupport::ExecutionContext.to_h) + end + end + ::Rails.error.subscribe(ErrorSubscriber) end end