Skip to content

Commit 8539224

Browse files
committed
[active_job] patch retry_job to report all errors during retries
1 parent 6b15516 commit 8539224

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

sentry-rails/lib/sentry/rails/active_job.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ def already_supported_by_sentry_integration?
1717
Sentry.configuration.rails.skippable_job_adapters.include?(self.class.queue_adapter.class.to_s)
1818
end
1919

20+
def retry_job(error:, **opts)
21+
unless Sentry.configuration.rails.active_job_report_after_job_retries
22+
SentryReporter.capture_exception(self, error)
23+
end
24+
super
25+
end
26+
2027
class SentryReporter
2128
OP_NAME = "queue.active_job"
2229
SPAN_ORIGIN = "auto.queue.active_job"

sentry-rails/spec/sentry/rails/activejob_spec.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,11 @@ def perform(event, hint)
440440
allow(Sentry::Rails::ActiveJobExtensions::SentryReporter)
441441
.to receive(:capture_exception).and_call_original
442442

443-
assert_performed_jobs 3 do
444-
FailedJobWithRetryOn.perform_later rescue nil
445-
end
443+
FailedJobWithRetryOn.perform_later rescue nil
444+
445+
perform_enqueued_jobs
446+
perform_enqueued_jobs
447+
perform_enqueued_jobs rescue nil
446448

447449
expect(Sentry::Rails::ActiveJobExtensions::SentryReporter)
448450
.to have_received(:capture_exception)
@@ -463,9 +465,11 @@ def perform(event, hint)
463465
allow(Sentry::Rails::ActiveJobExtensions::SentryReporter)
464466
.to receive(:capture_exception).and_call_original
465467

466-
assert_performed_jobs 3 do
467-
FailedJobWithRetryOn.perform_later rescue nil
468-
end
468+
FailedJobWithRetryOn.perform_later rescue nil
469+
470+
perform_enqueued_jobs
471+
perform_enqueued_jobs
472+
perform_enqueued_jobs rescue nil
469473

470474
expect(Sentry::Rails::ActiveJobExtensions::SentryReporter)
471475
.to have_received(:capture_exception)

0 commit comments

Comments
 (0)