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

feat: use after_change for context changes #651

Merged
merged 1 commit into from
Nov 27, 2024
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
10 changes: 7 additions & 3 deletions lib/honeybadger/plugins/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down