Skip to content

Active Job plugin prevents propagating global context set in other before_perform/around_perform callback #675

@douglasshuang

Description

@douglasshuang
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @douglasshuang

      Issue actions

        Active Job plugin prevents propagating global context set in other `before_perform`/`around_perform` callback · Issue #675 · honeybadger-io/honeybadger-ruby