Skip to content
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

feat: track exceptions in :async activejob adapter #503

Merged
merged 9 commits into from
Dec 4, 2023
28 changes: 28 additions & 0 deletions lib/honeybadger/plugins/active_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Honeybadger
module Plugins
module ActiveJob

Plugin.register {
requirement { defined?(::Rails.application) && ::Rails.application }
requirement {
::Rails.application.config.active_job[:queue_adapter] == :async
}

execution {
::ActiveJob::Base.class_eval do |base|
base.set_callback :perform, :around do |param, block|
Honeybadger.clear!
begin
joshuap marked this conversation as resolved.
Show resolved Hide resolved
block.call
rescue => error
Honeybadger.notify(error, parameters: { job_arguments: self.arguments })
raise error
end
end
end
}
}
end
end

end
3 changes: 3 additions & 0 deletions spec/fixtures/rails/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class RailsApp < Rails::Application
config.serve_static_files = false
config.consider_all_requests_local = false

config.active_job.queue_adapter = :async

routes.append do
get '/runtime_error', :to => 'rails#runtime_error'
get '/record_not_found', :to => 'rails#record_not_found'
Expand Down Expand Up @@ -62,3 +64,4 @@ def index
Rails.logger = Logger.new(File::NULL)

require_relative './breadcrumbs'
require_relative './queue_adapter'
13 changes: 13 additions & 0 deletions spec/fixtures/rails/config/queue_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ErrorJob < ActiveJob::Base
around_perform :around_for_testing

def perform(opts={})
raise "exception raised in job"
end

def around_for_testing(*args)
yield
end
end


20 changes: 20 additions & 0 deletions spec/integration/rails/async_queue_adapter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require_relative '../rails_helper'

describe "Rails Async Queue Adapter Test", if: RAILS_PRESENT, type: :request do
include ActiveJob::TestHelper if RAILS_PRESENT
load_rails_hooks(self)

it "reports exceptions" do
Honeybadger.flush do
perform_enqueued_jobs do
expect {
ErrorJob.perform_later({some: 'data'})
}.to raise_error(StandardError)
end
end

expect(Honeybadger::Backend::Test.notifications[:notices].size).to eq(1)
expect(Honeybadger::Backend::Test.notifications[:notices][0].params[:job_arguments][0]).to eq({some: 'data'})
end

end