From e36501f44983eb0de6e1aee23b7de86baec636ec Mon Sep 17 00:00:00 2001 From: Marc Boquet Date: Fri, 24 Apr 2026 18:57:33 +0200 Subject: [PATCH] fix(sidekiq): Report error when retry limit is below attempt_threshold MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a job's `retry` option is lower than its `attempt_threshold` (e.g. `retry: 1` with `attempt_threshold: 3`), the error handler skipped every attempt and the job was silently dropped — it died before ever reaching the threshold. Cap the threshold at the job's final attempt so these jobs still report before entering the dead set. Jobs whose retry count meets or exceeds the threshold behave exactly as before. --- CHANGELOG.md | 6 ++++++ sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb | 4 +++- sentry-sidekiq/spec/sentry/sidekiq_spec.rb | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbad637a9..fc51cf2d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased + +### Bug Fixes 🐛 + +- (sidekiq) Report final attempt when retry limit is below `attempt_threshold` by @marcboquet in [#XXXX](https://github.com/getsentry/sentry-ruby/pull/XXXX) + ## 6.5.0 ### New Features ✨ diff --git a/sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb b/sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb index af5b78900..eef27a321 100644 --- a/sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb +++ b/sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb @@ -43,8 +43,10 @@ def call(ex, context, sidekiq_config = nil) # attempt 2 - this is your first retry so retry_count is 0 # attempt 3 - you have retried once, retry_count is 1 attempt = retry_count.nil? ? 1 : retry_count.to_i + 2 + # Cap at the final attempt so jobs with fewer retries than the threshold still report. + effective_threshold = [attempt_threshold, retry_limit(context, sidekiq_config) + 1].min - return if attempt < attempt_threshold + return if attempt < effective_threshold end Sentry::Sidekiq.capture_exception( diff --git a/sentry-sidekiq/spec/sentry/sidekiq_spec.rb b/sentry-sidekiq/spec/sentry/sidekiq_spec.rb index 4c2cc344a..a7b727eb3 100644 --- a/sentry-sidekiq/spec/sentry/sidekiq_spec.rb +++ b/sentry-sidekiq/spec/sentry/sidekiq_spec.rb @@ -141,6 +141,17 @@ def retry_last_failed_job retry_last_failed_job expect(transport.events.count).to eq(0) end + + it "reports on the final attempt when retry limit is below the threshold" do + worker = Class.new(SadWorker) + worker.sidekiq_options attempt_threshold: 3, retry: 1 + + execute_worker(processor, worker) + expect(transport.events.count).to eq(0) + + retry_last_failed_job + expect(transport.events.count).to eq(1) + end end context "with config.report_only_dead_jobs = true" do