How To Install Airbrake In Your Rails App

When an app chokes on an unexpected condition or data, developers can spend hours going down rabbit holes trying to reproduce and diagnose the issue. It helps to have as much information as possible about the error and the environment at the time of the error, so that’s why I want to look at the error reporting and monitoring tool called Airbrake. This tool lets you get into the guts of your application’s errors to see what is going on.

I have personally used Airbrake to monitor some applications that I previously built at a startup, so you can imagine that I was really excited when Exceptional Cloud Services, the team behind Airbrake, recently became part of the Rackspace family. You can get started with Airbrake by going to to learn more information about its plans and pricing (note: there is a free developer plan). I have included a screencast below that walks you through a step-by-step guide on installing Airbrake to your Rails app.

Getting started with Rails? Find out how Bret taught himself the framework.

After you get Airbrake set up, there are several features that I have found helpful:

  1. You can set up Demo, Staging and Production environments, which can help you monitor errors that a specific version of your application is throwing as well as make sure you prioritize issues based on environment. Keep production running smoothly first, then worry about the Dev environment!
  2. Clicking on the text of the error message will pull up more information, such as: the stack trace, the user agent and IP addresses of the browsers that triggered it. This information is incredibly powerful at helping you debug your application. You don’t want to spend hours trying to recreate the issue in Chrome if the user is on Firefox.
  3. There is also information under “deploy” about when you last deployed the particular release. You can also integrate with GitHub, which can associate an issue with a particular code release and will reset all notices when you push up a new code version.
  4. Airbrake does a great job at aggregating similar errors. Instead of giving you a list of the same error repeated over and over, you have the latest date and time when the error occurred as well as a count of the number of times the error happened. This has helped save my email inbox from blowing up when there was repetitive error.

To setup Airbrake in your Rails application, open up your gem file and type:

gem ‘airbrake’

Now go into terminal and type:

bundle install

Once that’s done, go back into your Rails application, and go to your application controller file and make sure that it does not include “exceptionnotifiable” up in the top. It should look something like this:

class ApplicationController < ActionController::Base

Go back into terminal and type:

rails generate airbrake --api-key [your_key_here]

Where [your_key_here] is your API key from Airbrake. This will install Airbrake and throw an example error in the Airbrake portal to verify you did the installation correctly. Logging back into the Airbrake application, you can see the error that was just generated here in your log that reads, “If you can see this, it works.” You now have Airbrake up and running, and can rest a little bit easier knowing that your application is being monitored.

Check out Bret’s previous post where he talks about monitoring the cloud infrastructure that your app is sitting on. In his next post and screencast, Bret discusses a tool that can help developers monitor the hosting costs of their application.

Head over to the Rackspace DevOps blog for a drill down into using Airbrake on the Rackspace Cloud.


Please enter your comment!
Please enter your name here