Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[active_job] support exception reporting only after last retry failed #2573

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Properly detach retry_stopped.active_job subscriber
Otherwise specs would be failing randomly
solnic committed Mar 11, 2025
commit a1fc642669c07aff1f367d328f456fb9841a8e8a
13 changes: 11 additions & 2 deletions sentry-rails/lib/sentry/rails/active_job.rb
Original file line number Diff line number Diff line change
@@ -68,8 +68,17 @@ def capture_exception(job, e)
end

def register_retry_stopped_subscriber
ActiveSupport::Notifications.subscribe(NOTIFICATION_NAME) do |*args|
retry_stopped_handler(*args)
unless @retry_stopped_subscriber
@retry_stopped_subscriber = ActiveSupport::Notifications.subscribe(NOTIFICATION_NAME) do |*args|
retry_stopped_handler(*args)
end
end
end

def detach_retry_stopped_subscriber
if @retry_stopped_subscriber
ActiveSupport::Notifications.unsubscribe(@retry_stopped_subscriber)
@retry_stopped_subscriber = nil
end
end

2 changes: 1 addition & 1 deletion sentry-rails/spec/sentry/rails/activejob_spec.rb
Original file line number Diff line number Diff line change
@@ -463,7 +463,7 @@ def perform(event, hint)
allow(Sentry::Rails::ActiveJobExtensions::SentryReporter)
.to receive(:capture_exception).and_call_original

assert_performed_jobs 1 do
assert_performed_jobs 3 do
FailedJobWithRetryOn.perform_later rescue nil
end

4 changes: 4 additions & 0 deletions sentry-rails/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -52,6 +52,10 @@
expect(Sentry::Rails::Tracing.subscribed_tracing_events).to be_empty
Sentry::Rails::Tracing.remove_active_support_notifications_patch

if defined?(Sentry::Rails::ActiveJobExtensions::SentryReporter)
Sentry::Rails::ActiveJobExtensions::SentryReporter.detach_retry_stopped_subscriber
end

reset_sentry_globals!
end