Created
March 19, 2019 16:15
-
-
Save joshuap/020e86fbfcda0f36f3b00c8013ff04ef to your computer and use it in GitHub Desktop.
Report ActiveJob exceptions to Honeybadger (default backend/unsupported backends)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/jobs/application_job.rb | |
class ApplicationJob < ActiveJob::Base | |
include HoneybadgerActiveJob | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/honeybadger.rb | |
module HoneybadgerActiveJob | |
def self.included(base) | |
# See https://edgeguides.rubyonrails.org/active_job_basics.html#exceptions | |
base.send :rescue_from, StandardError do |exception| | |
Honeybadger.notify(exception, context: { | |
job: self.class.name, | |
job_id: job_id, | |
arguments: arguments | |
}) | |
raise exception | |
end | |
end | |
end | |
# Report errors in ActionMailer jobs | |
ActionMailer::DeliveryJob.send(:include, HoneybadgerActiveJob) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment