Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ def call(ex, context, sidekiq_config = nil)
scope = Sentry.get_current_scope
scope.set_transaction_name(context_filter.transaction_name, source: :task) unless scope.transaction_name

retry_lim = retry_limit(context, sidekiq_config)

# If Sentry is configured to only report an error _after_ all retries have been exhausted,
# and if the job is retryable, and have not exceeded the retry_limit,
# return early.
if Sentry.configuration.sidekiq.report_after_job_retries && retryable?(context)
retry_count = context.dig(:job, "retry_count")
if retry_count.nil? || retry_count < retry_limit(context, sidekiq_config) - 1
if retry_count.nil? || retry_count < retry_lim - 1
return
end
end
Expand All @@ -43,8 +45,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_lim + 1].min

return if attempt < attempt_threshold
return if attempt < effective_threshold
end

Sentry::Sidekiq.capture_exception(
Expand Down
11 changes: 11 additions & 0 deletions sentry-sidekiq/spec/sentry/sidekiq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading