Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure the Airbrake gem to log all Rails exceptions in both development and production environments?

I have found it difficult to send exceptions of my Rails 3 app via the Airbrake gem. At first I thought there was an Airbrake configuration error on my part, but after trial and error and reading the documentation (https://github.com/thoughtbot/airbrake#readme) very closely, I found out that Airbrake does not report errors when an app is running in the development environment. It does report errors when the app is running in the production environment.

Is there a flag to generate an Airbrake configuration file that automatically includes the development environment in the list of environments in which notifications should not be sent?

Currently I am executing the command listed in the README

script/rails generate airbrake --api-key your_key_here
like image 701
Alan David Garcia Avatar asked Sep 26 '11 22:09

Alan David Garcia


2 Answers

Straightforward.

  config.consider_all_requests_local       = false

instead of

  config.consider_all_requests_local       = true

in your config/environments/development.rb. In my case, like I suspect in many others, it was just a temporary change so I can "test" Airbrake's notify_airbrake.

You do need config.development_environments = [] in airbrake.rb

like image 63
StuFF mc Avatar answered Nov 07 '22 02:11

StuFF mc


Not sure about a config options, but you can explicitly send notifications to Airbrake from a controller using

notify_airbrake(exception)

So to do this in development, you could catch all errors in your application_controller, send a notification and then handle the errors as before. Take a look at rescue_from to get started. This is how I'm doing this to get notifications from my staging environment (or, to be exact, any environment other than development and test).

class ApplicationController < ActionController::Base

  rescue_from Exception, :with => :render_error

  private

  def render_error(exception)
    render :file => "#{Rails.root}/public/500.html", :layout => false, :status => 500
    logger.error(exception)
    notify_airbrake(exception) unless Rails.env.development? || Rails.env.test?
  end
end
like image 29
Thilo Avatar answered Nov 07 '22 02:11

Thilo