From 4e2d4287bbbe0100d6f82a38b7314fc8dc5a1571 Mon Sep 17 00:00:00 2001 From: Benjamin Curtis Date: Tue, 5 Mar 2024 09:04:35 -0800 Subject: [PATCH] feat: track exceptions in :solid_queue (#526) And any other ActiveJob adapters that come along :) Fixes #518 --- lib/honeybadger/plugins/active_job.rb | 15 ++++++++------- .../integration/rails/async_queue_adapter_spec.rb | 7 +++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/honeybadger/plugins/active_job.rb b/lib/honeybadger/plugins/active_job.rb index f473a671..d626ac8b 100644 --- a/lib/honeybadger/plugins/active_job.rb +++ b/lib/honeybadger/plugins/active_job.rb @@ -1,29 +1,30 @@ module Honeybadger module Plugins module ActiveJob - + # Ignore inline and test adapters, as well as the adapters that we support with their own plugins + EXCLUDED_ADAPTERS = %i[inline test delayed_job faktory karafka resque shoryuken sidekiq sucker_punch].freeze + Plugin.register { requirement { defined?(::Rails.application) && ::Rails.application } requirement { ::Rails.application.config.respond_to?(:active_job) && - ::Rails.application.config.active_job[:queue_adapter] == :async + !EXCLUDED_ADAPTERS.include?(::Rails.application.config.active_job[:queue_adapter]) } - + execution { - ::ActiveJob::Base.class_eval do |base| + ::ActiveJob::Base.class_eval do |base| base.set_callback :perform, :around do |param, block| Honeybadger.clear! begin block.call rescue => error - Honeybadger.notify(error, parameters: { job_arguments: self.arguments }) + Honeybadger.notify(error, parameters: {job_id: job_id, arguments: arguments}) raise error end end - end + end } } end end - end diff --git a/spec/integration/rails/async_queue_adapter_spec.rb b/spec/integration/rails/async_queue_adapter_spec.rb index 871f8568..0af636a2 100644 --- a/spec/integration/rails/async_queue_adapter_spec.rb +++ b/spec/integration/rails/async_queue_adapter_spec.rb @@ -1,4 +1,4 @@ -require_relative '../rails_helper' +require_relative "../rails_helper" describe "Rails Async Queue Adapter Test", if: RAILS_PRESENT, type: :request do include ActiveJob::TestHelper if RAILS_PRESENT @@ -8,13 +8,12 @@ Honeybadger.flush do perform_enqueued_jobs do expect { - ErrorJob.perform_later({some: 'data'}) + 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'}) + expect(Honeybadger::Backend::Test.notifications[:notices][0].params[:arguments][0]).to eq({some: "data"}) end - end