Ruby

Installing Airbrake in a Ruby application

Features

  • Simple to install and configure
  • Automatic reporting of unhandled exceptions
  • Ignore specific errors and filter out sensitive information
  • Add extra context to errors before they are sent
  • Set error severity and control notification thresholds

See all features

Supported Frameworks

Rubybrake provides a ready-to-use solution with minimal configuration for ruby frameworks.

Rack

Rails

Sinatra

Installation & Configuration

Install with bundler

Add the Airbrake Ruby gem to your Gemfile and run bundle install:

gem 'airbrake-ruby'

Manual installation

Invoke the following command from your terminal:

gem install airbrake-ruby

Configuration

This is the minimal example that you can use to test Airbrake Ruby with your project. You can find your PROJECT ID and PROJECT API KEY available from with your project’s settings page.

require 'airbrake-ruby'

# Every Airbrake notifier must configure
# two options: `project_id` and `project_key`.
Airbrake.configure do |c|
  c.project_id = <Your project ID>
  c.project_key = '<Your project API KEY>'
end

# Asynchronous error delivery.
begin
  1/0
rescue ZeroDivisionError => ex
  # Return value is always `nil`.
  Airbrake.notify(ex)
end

puts 'A ZeroDivisionError was sent to Airbrake asynchronously!',
     "Find it at your project's dashboard on https://airbrake.io"

# Synchronous error delivery.
begin
  1/0
rescue ZeroDivisionError => ex
  # Return value is a Hash.
  response = Airbrake.notify_sync(ex)
end

puts "Another ZeroDivisionError was sent to Airbrake synchronously!",
     "See it at #{response['url']}!"

Going further

For advanced configuration options like ignoring errors, adding extra context, and filtering sensitive information please visit our official GitHub repo.

Proxy support

Can I configure Airbrake to send errors through a proxy?

Yes, you can! If your server is not able to directly reach the Airbrake servers you can configure the Airbrake ruby notifier to send errors through your proxy.

Configuring Airbrake to use your proxy is as simple as setting the relevant proxy options in the initializer

Configuring Airbrake V5 to use a proxy

Airbrake.configure do |c|
  c.proxy = {
    host: 'example.com',
    port: 8080,
    user: 'user',
    password: 'p4ssw0rd'
  }
end

Upgrading your notifier

Note: If you are upgrading from version 4.X.X or older, please follow our guide to upgrade from a deprecated version.

Step 1: To upgrade to the latest version of the airbrake gem just edit your Gemfile:

gem 'airbrake'

Step: 2: Run the update command to update the airbrake gem and airbrake-ruby gem it depends on:

bundle update airbrake airbrake-ruby

That’s it! Your upgrade is complete.

Problems upgrading?

If you run into any issues upgrading, we are happy to help. Just let us know what happened at support@airbrake.io.

Upgrading from deprecated versions

Support for version 4 of our gem ended November 2016. If your app is using version or earlier, we would recommend upgrading to a currently supported version using the guide below.

Step 1: Update your gems

Upgrade to the latest version of our gem by updating your Gemfile:

gem 'airbrake'

Then run the update command to update our main gem and the airbrake-ruby gem it uses:

bundle update airbrake airbrake-ruby

Step 2: Regenerate config

Run generate command to overwrite old Airbrake config (make sure to replace PROJECT_ID and API_KEY with your project’s actual values which can be found in your project settings page):

rails generate airbrake PROJECT_ID API_KEY

To overwrite your old config, answer Y when prompted:

$ rails generate airbrake PROJECT_ID API_KEY
    conflict  config/initializers/airbrake.rb
Overwrite /Users/arthur/my-app/config/initializers/airbrake.rb? (enter "h" for help) [Ynaqdhm]

For a full migration guide, check out our doc on GitHub.

Upgrading from Hoptoad

The old Hoptoad gem is no longer supported. To get all the latest features and fixes, you should upgrade to the latest version of our gem.

Step 1: Uninstall the old Hoptoad notifier

Uninstall the old Hoptoad notifier by removing it from your Gemfile, then run the command:

bundle install

You should also replace references in your app to HoptoadNotifier to Airbrake. For example:

# Old name
HoptoadNotifier.notify(err)

# Current name
Airbrake.notify(err)

Upgrade to the latest version of our gem by updating your Gemfile:

gem 'airbrake'

Then run the update command to update our main gem and the airbrake-ruby gem it uses:

bundle update airbrake airbrake-ruby

Step 2: Regenerate config

Run generate command to overwrite old Airbrake config (make sure to replace PROJECT_ID and API_KEY with your project’s actual values which can be found in your project settings page):

rails generate airbrake PROJECT_ID API_KEY

To overwrite your old config, answer Y when prompted:

$ rails generate airbrake PROJECT_ID API_KEY
    conflict  config/initializers/airbrake.rb
Overwrite /Users/arthur/my-app/config/initializers/airbrake.rb? (enter "h" for help) [Ynaqdhm]

For a full migration guide, check out our doc on GitHub.