Ruby Exception Tracking

Typical installation time: 3 minutes

Hi there! You've found Honeybadger's guide to Ruby exception tracking. Once installed, Honeybadger will automatically report exceptions wherever they may happen:

  • During a web request
  • In a background job
  • In a rake task
  • When a process crashes (at_exit)

If you're new to Honeybadger, read our Getting Started guide to become familiar with our Ruby gem. For a refresher on working with exceptions in Ruby, check out the Honeybadger guide to Ruby exceptions.

On this page:

Installation

The first step is to add the honeybadger gem to your Gemfile:

gem 'honeybadger'

Tell bundler to install:

$ bundle install

Next, you'll set the API key for this project.

$ bundle exec honeybadger install [YOUR API KEY HERE]

This will do three things:

  1. Generate a config/honeybadger.yml file. If you don't like config files, you can place your API key in the $HONEYBADGER_API_KEY environment variable.
  2. If Capistrano is installed, we'll add a require statement to Capfile.
  3. Send a test exception to your Honeybadger project.

Next, require the honeybadger gem after any other gems you're using:

# ...
require 'honeybadger'

Honeybadger will detect any supported 3rd-party gems you're using such as Sidekiq, Rake, etc. and integrate with them automatically.

To notify Honeybadger of an exception you've rescued, use Honeybadger.notify:

begin
  fail 'oops'
rescue => exception
  Honeybadger.notify(exception)
end

For additional ways to use Honeybadger.notify, check out the Reporting errors chapter of our Getting started guide.

For Rack-based web applications, see the Rack integration guide for instructions on how to automatically report exceptions in web requests.