Skip to content

Commit

Permalink
feat: set context during rails error report (#649)
Browse files Browse the repository at this point in the history
This will always set the context from Rails when an error is reported
even if it is not handled. This will allow applications to use
`Rails.error.set_context` instead of `Honeybadger.context` and still see
that context in errors in the UI.

It would have been nice if Rails provided an event for when
`set_context` is called so that we can hook into that, but this should
be ok for now.
  • Loading branch information
roelbondoc authored Nov 26, 2024
1 parent 6501265 commit dee37e1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/honeybadger/plugins/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ 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 @@ -41,7 +43,7 @@ def self.report(exception, handled:, severity:, context: {}, source: nil)

tags = ["severity:#{severity}", "handled:#{handled}"]
tags << "source:#{source}" if source
Honeybadger.notify(exception, context: context, tags: tags)
Honeybadger.notify(exception, tags: tags)
end

def self.source_ignored?(source)
Expand Down

0 comments on commit dee37e1

Please sign in to comment.