Josh Thompson     about     projects     blog     ☕️ with josh

How to Log Dead Sidekiq jobs to Sentry

Article Table of Contents

I wanted to log dead jobs to Sidekiq. Found this issue, lead to:

Sidekiq.configure_server do |config|
  config.death_handlers << ->(job, ex) do
    # do stuff
    # job keys: ["class", "args", "retry", "queue", "backtrace", "jid", "created_at", "enqueued_at", "error_message", "error_class", "failed_at", "retry_count", "error_backtrace"]
  end
end

So, tossed this into our config/sidekiq.rb

config.death_handlers << ->(job, ex) do
  # job keys:
  # ["class", "args", "retry", "queue", "backtrace", "jid", "created_at",
  #  "enqueued_at", "error_message", "error_class", "failed_at",
  # "retry_count", "error_backtrace"]
  Sentry.capture_message("#{job["class"]} entered Dead queue with #{job["args"]}
    after #{job["retry_count"]} retries. #{job["error_message"]}. Exception: #{ex}")
end

So far, so good.