I'm using Sidekiq and Airbrake in my Rails application. I would like Airbrake to catch any errors that occur during Sidekiq jobs. As per instructions I found online, I've added the following to sidekiq.rb:
config.error_handlers << Proc.new { |ex,context| Airbrake.notify_or_ignore(ex, parameters: context) }
Airbrake then was able to catch errors when they occurred in my development environment. However, once I deployed to a higher environment, Airbrake stopped being able to catch Sidekiq errors. Is there any reason this would happen? Is there anything else I need to configure inside my app?
I'm using sidekiq gem version ~>3.0.2, airbrake gem version ~>4.0.0, and rails 3.2.18
Here is my full sidekiq.rb:
require 'sidekiq'
require 'sidekiq-status'
redis_connection = "redis://127.0.0.1:6379/0"
Sidekiq.configure_server do |config|
config.redis = { :url => redis_connection, :namespace => 'sidekiq' }
config.server_middleware do |chain|
chain.add Sidekiq::Status::ServerMiddleware, expiration: 30.minutes
end
config.client_middleware do |chain|
chain.add Sidekiq::Status::ClientMiddleware
end
config.error_handlers << Proc.new { |ex,context| Airbrake.notify_or_ignore(ex, parameters: context) }
end
Sidekiq.configure_client do |config|
config.redis = { :url => redis_connection, :namespace => 'sidekiq' }
config.client_middleware do |chain|
chain.add Sidekiq::Status::ClientMiddleware
end
end
And here is my full airbrake.rb:
Airbrake.configure do |config|
config.user_attributes = [:id, :email]
config.api_key = '*my_api_key*'
end
It turns out that if your app is also using rubber, then you also have to change your rubber sidekiq initializer (config/rubber/common/initializers/sidekiq) to include the line:
config.error_handlers << Proc.new { |ex,context| Airbrake.notify_or_ignore(ex, parameters: context) }
The rubber sidekiq initializer is used for all non-development environments, whereas the sidekiq.rb file is used for development environment.