Skip to content

Introduce active_job_report_on_retry_error #2617

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

solnic
Copy link
Collaborator

@solnic solnic commented May 5, 2025

⚡ TL;DR

⏳ Longer explanation

Plot twist: the active_job_report_after_retries turned out to be problematic because if we want to report on each retry failure too, then we must always report on the last retry in the perform patch.

Previously the retry_stopped handler would do the reporting of the final attempt error and the perform patch would skip reporting to avoid duped reports, but that does not work when reporting on each retry error is meant to work too, because there is no way to tell whether the final attempt was already reported by the retry_stopped handler or not. This means that when a job failed but there was no retry, and the reporting on retry errors is turned on, then we would not get any report because the perform patch would skip reporting since reporting on retry errors is turned on.

This is really confusing, I know!

Luckily, this PR changes our original new setting to become active_job_report_on_retry_error which is a simpler solution since it only adds new logic for reporting errors on each retry and stays away from the original final-failure handling implemented in the perform patch.

This setting is disabled by default because it is the original behavior of the SDK and we don't want to change it in a patch release.

Once you enable active_job_report_on_retry_error, Sentry will be reporting exceptions on each job retry error using enqueue_retry.active_job handler, and the final (last retry attempt) failure will be reported by the perform patch.

There is no other way of doing this because of how ActiveJob works. We cannot use around_perform as described here 9303b9a and there are no AS notifications about errors at the moment that we could leverage except the one for retries.

In a future Rails release there errors will be reported using an error reported that we'll be able to hook into though, so we will most likely have a dedicated handling logic for future Rails versions eventually.

Refs #2500
Refs #2598
Refs #2597

@solnic solnic changed the title Introduce active job report on retry error Introduce active_job_report_on_retry_error May 5, 2025
@solnic solnic marked this pull request as ready for review May 5, 2025 11:44
@solnic solnic requested review from sl0thentr0py and st0012 May 5, 2025 11:44
@solnic
Copy link
Collaborator Author

solnic commented May 5, 2025

@modosc 👋🏻 I ended up reworking the solution that you originally implemented in #2500 after all. Please let me know if this makes sense for you.

@aburgel this most likely addresses the issue you reported in #2573 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant