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
Clear stale breadcrumbs and context after Sidekiq jobs #637
Conversation
The error handler is only called after an exception so the context will carry over from previous jobs that completed successfully. Fixes getsentry#636
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've provided some pretty detailed testing instructions so hopefully this will be easy enough to review.
@@ -2,7 +2,16 @@ | |||
require 'sidekiq' | |||
|
|||
module Raven | |||
class Sidekiq | |||
class SidekiqCleanupMiddleware |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you think of these names. I was going for explicit to to make the role clear.
Hi @drewish, did you explicitly also test the case that tags added in SadWorker actually end up recorded in Sentry with the exception raised by it (ie. not leaked tags from previous jobs but those that we intentionally want to report for the current job)? From some limited testing it seems that the |
I think it might work if the middleware only cleared context when no exception was raised and the error handler also cleared context. I'll try if that works. |
@tarmo Can you say more about how the tags would be provided? I was definitely testing that tags and breadcrumbs from the failed job were being reported. Now specifically it was picking up breadcrumbs from the failed jobs but the extra and tags were being passed in when capturing, e.g. |
@drewish if you call |
@tarmo Ah okay yeah I wasn't relying on the default capture so I understand the case you're highlighting now. Definitely a shortcoming in my testing. |
The error handler is only called after an exception so the context (specifically breadcrumbs) will carry over from previous jobs that completed successfully.
Fixes #636
I'm not sure this is exactly the way the maintainers would want to approach it but it seems to be working better for me. I'm not using ActiveJob so I don't know if that would play into this.
You can test this out by creating two new sidekiq jobs:
Then fill in some basic processing logic to have one record breadcrumbs and context:
And the other just raise an exception and doesn't retry
Start up sidekiq with a single thread (so we don't have to worry about which worker picks up which job):
Open up a rails console in another terminal window and queue up a couple of jobs:
On the master branch the Sentry issue from
SadWorker
will include the breadcrumbs and tags from theHappyWorker
: