Last active
April 21, 2022 02:09
-
-
Save electron0zero/c915ae433ba82a524b35fb4a8a01fc5b to your computer and use it in GitHub Desktop.
Sidekiq Sentry Middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sidekiq Middleware to report all errors to sentry | |
# This is a server-side middleware that reports any exception from any job | |
# See more: https://github.com/mperham/sidekiq/wiki/Middleware | |
module Sidekiq::Middleware::Server | |
class SentryErrorLogger | |
def call(worker, job, queue) | |
begin | |
yield | |
rescue => error | |
Raven.capture_exception(error, | |
extra: { | |
worker: worker, | |
job: job, | |
queue: queue | |
}) | |
# we raise it after reporting it to sentry. | |
# Raise is important here because this raise will tell | |
# sidekiq to mark this job as failed and move that job in retry queue | |
raise | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment