Search code examples
rubyrubygemssinatraairbrake

Can't adapt the airbrake gem to a Sinatra app


I am using the airbrake gem like so:

require 'airbrake'

Airbrake.configure do |config|
  config.api_key = 'XXXXX'
  config.development_environments = ["development", "test", "cucumber"]
end

use Airbrake::Rack
enable :raise_errors

but it still sends airbrake notifications in development.

My environment is saved in ENV['RACK_ENV'].

I don't want to hack my way into this, is there an "outside" solution?

Also, I do want to raise exceptions in development - I just don't want them to be sent to airbrake..


Solution

  • You could use a configure block to only setup Airbrake in production:

    configure :production do
      require 'airbrake'
    
      Airbrake.configure do |config|
        config.api_key = 'XXXXX'
      end
    
      use Airbrake::Rack
    end
    

    If you have more than one environment you want Airbrake enabled in, you can specify a list, e.g.:

    configure :production, :staging do
      ...