Rails

Installing Airbrake in a Rails application

Airbrake gem vs Airbrake Ruby

The Airbrake gem: Acts as a collection of integrations with frameworks and other libraries and is built on top of Airbrake Ruby.

Airbrake Ruby: The core library that performs exception sending, filtering sensitive values, ignoring errors, managing the configuration, and other heavy lifting.

We link to both projects in this guide and want to be clear about their responsibilities.

Integrating Airbrake in your Rails app

Install the Airbrake gem

Open up your Gemfile in your favorite text editor and add the airbrake gem.

gem 'airbrake'

To install the Airbrake gem, run from the root directory of your application.

bundle install

Configure the Airbrake gem to report to your project

This generation command is meant to be run from the root directory of your application.

rails g airbrake

INFO: This creates the config/initializers/airbrake.rb file containing your Airbrake config along with some common options and descriptions.

Make sure to export AIRBRAKE_PROJECT_ID & AIRBRAKE_PROJECT_KEY prior to running your server.

export AIRBRAKE_PROJECT_ID=<PROJECT_ID>
export AIRBRAKE_PROJECT_KEY=<PROJECT_KEY>

Additional configuration options are detailed in the airbrake-ruby README.

Testing your configuration

The following rake command to sends a test exception to verify your app’s configuration.

rake airbrake:test
# A successful test should result in a locate link to see your test exception
The test exception was sent. Find it here: https://airbrake.io/locate/1745875337968541048

HELP: If you don’t see the locate link, please email the complete output of rake airbrake:test to support@airbrake.io.

Ignoring errors

You can choose which errors to ignore before sending them to Airbrake with the add_filter method. This makes it simple to ignore errors based on type, message, file, region, or any other part of the error’s JSON.

For example, to ignore all StandardErrors you could use the following add_filter:

Airbrake.add_filter do |notice|
  if notice[:errors].any? { |error| error[:type] == 'StandardError' }
    notice.ignore!
  end
end

TIP: A good place to keep your add_filters is below your configure block in config/initializers/airbrake.rb

Filtering keys

You can use blocklist or allowlist filtering to specify keys to filter out of the payload (environment, parameters, session, etc). Before sending an error, filtered keys will be substituted with the [Filtered] label.

Reporting JavaScript errors from your Rails app

Please see our guide on Installing airbrake-js in a Rails app for full details.

Deploy tracking

With deploy tracking you can send information about the deployment of your app to Airbrake. This unlocks error filtering by deploy and deploy markers are added to your error graphs.

We offer several ways to track your deploys:

Supported frameworks

Since it’s not all about Rails, here are some of our favorite supported ruby frameworks:

Web frameworks

Job processing libraries

Additional libraries

More information available on GitHub

Please visit the Airbrake gem repo for more configuration options, use cases, examples, and tips.