10

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
Alan David Garcia
  • 1,523
  • 2
  • 14
  • 23

2 Answers2

18

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

Michael
  • 10,124
  • 1
  • 34
  • 49
StuFF mc
  • 4,137
  • 2
  • 33
  • 32
  • 20
    I should point that in addition you **do** need `config.development_environments = []` in `airbrake.rb`! – StuFF mc Oct 18 '11 at 21:33
  • Another thing is that, for the error to show in airbrake, it must come from the subdomain you have configured in your airbrake account settings (e.g., probably not `localhost`). You can use `/etc/hosts` to give yourself a suitable domain (e.g. dev.example.com). This is needed in addition to the other two things. – connec Aug 20 '13 at 09:57
14

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
Thilo
  • 17,565
  • 5
  • 68
  • 84
  • 1
    This is a great place to start. When I added a rescue_from method for Exception I saw that the 500.html file was rendered and the log was written to, as specified in the first two lines of the block. Unfortunately, notify_airbrake did not work in either development or default environments, only in production (even after I removed the unless condition). – Alan David Garcia Sep 27 '11 at 14:50
  • I think my ideal solution lies somewhere in the `Airbrake::Configuration` class, specifically the `development_environments` object. http://rdoc.info/github/thoughtbot/airbrake/master/Airbrake/Configuration#development_environments-instance_method – Alan David Garcia Sep 27 '11 at 14:54
  • Please look below for a complementary answer! – Alan David Garcia Oct 20 '11 at 16:00