Skip to content

Instantly share code, notes, and snippets.

@MrAlexLau
Created June 27, 2013 13:25
Show Gist options
  • Save MrAlexLau/5876372 to your computer and use it in GitHub Desktop.
Save MrAlexLau/5876372 to your computer and use it in GitHub Desktop.
How to ignore Sidekiq exceptions in Airbrake for a rails project.
#config/initializers/airbrake.rb
Airbrake.configure do |config|
config.api_key = 'mySecretKeyGoesHere'
config.ignore << "CustomSidekiqException" #do not report our custom exceptions to Airbrake
end
#app/models/custom_sidekiq_exception.rb
class CustomSidekiqException < StandardError
#just make sure this inherits from standard error
#you can add whatever attributes you want to this class, but don't need to
end
#config/initializers/sidekiq.rb
module WrappedErrors
class Sidekiq
#call a worker per usual
#only this time wrap in a begin/rescue block for errors
#re-raise the error using our custom error type
def call(worker, msg, queue)
begin
yield
rescue => ex
raise CustomSidekiqException, ex.message
end
end
end
end
Sidekiq.configure_server do |config|
config.redis = { :url => 'redis://localhost:6379/0', :namespace => 'sidekiq_namespace' }
config.server_middleware do |chain|
#add the WrappedErrors module to the sidekiq chain of events
chain.add ::WrappedErrors::Sidekiq
end
end
Sidekiq.configure_client do |config|
config.redis = { :url => 'redis://localhost:6379/0', :namespace => 'sidekiq_namespace' }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment