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

Use prepended method instead of around_perform for ActiveJob integration #1631

Merged
merged 4 commits into from
Dec 1, 2021

Conversation

st0012
Copy link
Collaborator

@st0012 st0012 commented Nov 27, 2021

Since the sdk registers its around_perform as the "first" callback, it needs to call all error handlers manually (which naturally should happen later) to see if it should report the exception.

Usually, this approach works well because if an exception will be handled later, handling it ealier doesn't make much of a difference.

However, as described in #956, if there's another exception happened inside one of the error handlers, it'll re-enter the error handler again in here: https://github.com/rails/rails/blob/38cb5610b1/activejob/lib/active_job/execution.rb#l50-l51

Of course, it may be possible to handle such case by adding more rescue block inside the capture_and_reraise_with_sentry method. But it'll force the entire exception handling flow to be performed inside the first around_perform block. And that's something we should avoid.

This also fixes a rescue_from callback issue in Sentry::SendEventJob.

Closes #956 and #1629

since the sdk registers its around_perform as the "first" callback, it
needs to call all error handlers manually (which naturally should happen
later) to see if it should report the exception.

usually, this approach works well because if an exception will be
handled later, handling it ealier doesn't make much of a difference.

however, as described in #956, if there's another exception happened
inside one of the error handlers, it'll re-enter the error handler again
in here: https://github.com/rails/rails/blob/38cb5610b1/activejob/lib/active_job/execution.rb#l50-l51

Of course, it may be possible to handle such case by adding more rescue
block inside the `capture_and_reraise_with_sentry` method. But it'll
force the entire exception handling flow to be performed inside the
first `around_perform` block. And that's something we should avoid.
@st0012 st0012 added this to the 4.9.0 milestone Nov 27, 2021
@st0012 st0012 self-assigned this Nov 27, 2021
@st0012 st0012 added this to In progress in 4.x via automation Nov 27, 2021
@codecov-commenter
Copy link

codecov-commenter commented Nov 27, 2021

Codecov Report

Merging #1631 (1efe494) into master (27da65b) will increase coverage by 0.01%.
The diff coverage is 93.93%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1631      +/-   ##
==========================================
+ Coverage   98.52%   98.54%   +0.01%     
==========================================
  Files         133      133              
  Lines        7404     7414      +10     
==========================================
+ Hits         7295     7306      +11     
+ Misses        109      108       -1     
Impacted Files Coverage Δ
sentry-rails/app/jobs/sentry/send_event_job.rb 60.00% <0.00%> (ø)
sentry-rails/lib/sentry/rails/active_job.rb 100.00% <100.00%> (+2.85%) ⬆️
sentry-rails/spec/sentry/rails/activejob_spec.rb 99.25% <100.00%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 27da65b...1efe494. Read the comment docs.

Copy link
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool fix!

@st0012 st0012 linked an issue Dec 1, 2021 that may be closed by this pull request
@st0012 st0012 merged commit 9303b9a into master Dec 1, 2021
4.x automation moved this from In progress to Done Dec 1, 2021
@st0012 st0012 deleted the fix-#956 branch December 1, 2021 17:30
@st0012 st0012 modified the milestones: 4.9.0, 4.8.2 Dec 4, 2021
@st0012 st0012 modified the milestones: 4.8.2, 4.9.0 Dec 25, 2021
st0012 added a commit that referenced this pull request Jan 4, 2022
…ion (#1631)

* use prepended method instead of around_perform for activejob integration

since the sdk registers its around_perform as the "first" callback, it
needs to call all error handlers manually (which naturally should happen
later) to see if it should report the exception.

usually, this approach works well because if an exception will be
handled later, handling it ealier doesn't make much of a difference.

however, as described in #956, if there's another exception happened
inside one of the error handlers, it'll re-enter the error handler again
in here: https://github.com/rails/rails/blob/38cb5610b1/activejob/lib/active_job/execution.rb#l50-l51

Of course, it may be possible to handle such case by adding more rescue
block inside the `capture_and_reraise_with_sentry` method. But it'll
force the entire exception handling flow to be performed inside the
first `around_perform` block. And that's something we should avoid.

* Refactor ActiveJob integration

* Fix SendEventJob's rescue_from callback

* Update changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4.x
  
Done
3 participants