-
Notifications
You must be signed in to change notification settings - Fork 148
Description
This is a follow-up to #648.
We have code like this:
class ApplicationJob < ActiveJob::Base
before_perform do
Rails.error.set_context(...)
end
...
We're attempting to provide additional context about the user action (if any) that resulted in performing the job, by taking advantage of the Honeybadger Rails plugin's after_change
callback on ActiveSupport::ExecutionContext
. However, we've discovered that the Active Job plugin's around_perform
callback on ActiveJob::Base
gets set after our before_perform
callback. Therefore, the Active Job plugin's callback gets called after ours. The result is that before a job is performed, we set the Honeybadger global context, and then the Active Job plugin clears it:
module Honeybadger
module Plugins
module ActiveJob
...
class << self
def perform_around(job, block)
Honeybadger.clear!
context = context(job)
block.call
...
We've resorted to monkey-patching Honeybadger::Plugins::ActiveJob.context
to add our context data there instead of relying on our callback. We'd prefer to be able to use our callback, and we could, if only the Honeybadger Active Job plugin's callback would run first. That can be accomplished by adding the prepend: true
option when setting the plugin's callback. I will submit a PR with that change.
@roelbondoc, what do you think?
Activity