Skip to content

Commit b4bd321

Browse files
committed
[active_job] patch retry_job to report all errors during retries
1 parent 7265f14 commit b4bd321

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
@@ -446,9 +446,11 @@ def perform(event, hint)
446446
allow(Sentry::Rails::ActiveJobExtensions::SentryReporter)
447447
.to receive(:capture_exception).and_call_original
448448

449-
assert_performed_jobs 3 do
450-
FailedJobWithRetryOn.perform_later rescue nil
451-
end
449+
FailedJobWithRetryOn.perform_later rescue nil
450+
451+
perform_enqueued_jobs
452+
perform_enqueued_jobs
453+
perform_enqueued_jobs rescue nil
452454

453455
expect(Sentry::Rails::ActiveJobExtensions::SentryReporter)
454456
.to have_received(:capture_exception)
@@ -469,9 +471,11 @@ def perform(event, hint)
469471
allow(Sentry::Rails::ActiveJobExtensions::SentryReporter)
470472
.to receive(:capture_exception).and_call_original
471473

472-
assert_performed_jobs 3 do
473-
FailedJobWithRetryOn.perform_later rescue nil
474-
end
474+
FailedJobWithRetryOn.perform_later rescue nil
475+
476+
perform_enqueued_jobs
477+
perform_enqueued_jobs
478+
perform_enqueued_jobs rescue nil
475479

476480
expect(Sentry::Rails::ActiveJobExtensions::SentryReporter)
477481
.to have_received(:capture_exception)

0 commit comments

Comments
 (0)