Tracking Sidekiq workers exceptions with Errbit/Airbrake

If you’ve set up Errbit/Airbrake and you use Sidekiq, by default you would expect, that Errbit tracks things that happen in Sidekiq workers as well. Unfortunately it doesn’t.

In order to make Sidekiq retry failed jobs in needs to catch and handle exceptions on its own. And that’s the reason why you need a bit of “magic” to make it work with Errbit. You need to add an custom error handler that will notify Errbit app about errors that occured in Sidekiq workers.

To do so, just create an initializer like this:

# Errbit error catching for Sidekiq workers
Sidekiq.configure_server do |config|
  config.error_handlers << Proc.new { |ex,ctx_hash| Airbrake.notify_or_ignore(ex, ctx_hash) }
end

And that’s all!

22
Jul 2014
POSTED BY
DISCUSSION 3 Comments
  • http://www.krautcomputing.com Manuel Meurer

    Use `Airbrake.notify_or_ignore` instead!

    Sidekiq.configure_server do |config|
    config.error_handlers << Proc.new { |exception, context| Airbrake.notify_or_ignore(exception, parameters: context) }
    end

    https://github.com/airbrake/airbrake/issues/269#issuecomment-39036722

  • http://www.mensfeld.pl Maciej Mensfeld

    You’re absolutely right ;) Thanks for the update!

  • http://drunkonrails.com/ David Lesches

    I’m noticing that many times the arguments for the Sidekiq job don’t make it to Errbit – the Errbit parameters tab remains empty, which makes it hard to debug. Any ideas?