-
Notifications
You must be signed in to change notification settings - Fork 141
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
Issue with "on_thread_error" override #120
Comments
Doesn't seem like on_thread_error is ever called. If I |
Likewise, I have the following config and it does not notify Honeybadger when an error occurs: config.solid_queue.on_thread_error = ->(exception) {
Honeybadger.notify(exception, context: {error_message: exception.message, source: "solid_queue"})
} |
Hey @chiraggshah, @npezza93, @kylekeesling thanks for reporting this and sorry for the delay. I've been working mostly on unrelated stuff this past week.
For errors in the job itself, you could try to hook into Active Job's itself, similarly to what Sentry's client does here. |
@rosa I started to wonder that based on the wording |
Using the Sentry example Rosa provided, I was able to get the following working in my app by adding it to class ApplicationJob < ActiveJob::Base
around_perform do |job, block|
capture_and_record_errors(job, block)
end
def capture_and_record_errors(job, block)
block.call
# I had to use rescue here instead of a `Rails.error` block because Honeybadger ignores the `Rails.error.report` call
# in favor of their own error handler, which is fine in most cases, but unfortunately doesn't work here. Report would be
# great here because it re-raises the error, but instead I have to do that manually
rescue Exception => e
Rails.error.set_context(**error_context(job))
Rails.error.report(e)
raise e
end
def error_context(job)
{
active_job: job.class.name,
arguments: job.arguments,
scheduled_at: job.scheduled_at,
job_id: job.job_id
}
end
end It's important to note that you must include Thanks again @rosa for the wonderful gem and the assistance in figuring this out! |
@rosa : Thanks for clarification and for this wonderful gem. Your explanation clears up the confusion I had. @kylekeesling : Thanks for the above snippet. I used the same and got it working for ApplicationJob by directly calling class ApplicationJob < ActiveJob::Base
around_perform do |job, block|
capture_and_record_errors(job, block)
end
def capture_and_record_errors(job, block)
block.call
rescue => exception
context = {
error_class: job.class.name,
args: job.arguments,
scheduled_at: job.scheduled_at,
job_id: job.job_id
}
Honeybadger.notify(exception, context:)
raise exception
end
end I also added similar code to the around block for # application_mailer.rb
ActionMailer::MailDeliveryJob.around_perform do |job, block|
block.call
rescue => exception
context = {
error_class: job.class.name,
args: job.arguments,
scheduled_at: job.scheduled_at,
job_id: job.job_id
}
Honeybadger.notify(exception, context:)
raise exception
end While searching for ways on why just adding it to application_job.rb wasn't working for mailers, I came across this section in the readme of good_job gem which helped clear up the confusion and provide the above solution for mailers. @rosa : Do you think it would be a good thing to add both of the above in the readme? If yes, then I would be happy to raise a PR. |
Oops, sorry for the delay! I missed this mention. I think that'd be super helpful, please do raise a PR if you have time 🙏 If not, I'll address it soon. |
So many months later, I updated and merged that PR 😅 I kept debating whether to change the behaviour or document the existing behaviour, and in the end, with the v1.0.0 pressure, went for documenting for now 😅 |
I am trying to override
on_thread_error
by adding the following in application.rb.I have a sample job to trigger the above
But the proc doesn't get executed when I run
SendMailJob.perform_later
in the rails console.The text was updated successfully, but these errors were encountered: