Raven for Ruby is a client and integration layer for the Sentry error reporting API. It supports Ruby >= 2.3. JRuby support is provided but experimental.

Getting Started

Getting started with Sentry is a three step process:

  1. Sign up for an account
  2. Install your SDK
  3. Configure it


Raven Ruby comes as a gem and is straightforward to install. If you are using Bundler just add this to your Gemfile:

gem "sentry-raven"

For other means of installation see Installation.


To use Raven Ruby all you need is your DSN. Like most Sentry libraries it will honor the SENTRY_DSN environment variable. You can find it on the project settings page under API Keys. You can either export it as environment variable or manually configure it with Raven.configure:

Raven.configure do |config|
  config.dsn = '___PUBLIC_DSN___'

Reporting Failures

If you use Rails, Rake, Sidekiq, etc, you’re already done - no more configuration required! Check Integrations for more details on other gems Sentry integrates with automatically.

Rack requires a little more setup: Rack (Sinatra etc.)

Otherwise, Raven supports two methods of capturing exceptions:

Raven.capture do
  # capture any exceptions which happen during execution of this block
  1 / 0

  1 / 0
rescue ZeroDivisionError => exception

You can add either of the snippets above into your application to verify that Sentry is set up correctly.

Additional Context

Much of the usefulness of Sentry comes from additional context data with the events. Raven Ruby makes this very convenient by providing methods to set thread local context data that is then submitted automatically with all events.

There are three primary methods for providing request context:

# bind the logged in user
Raven.user_context email: ''

# tag the request with something interesting
Raven.tags_context interesting: 'yes'

# provide a bit of additional context
Raven.extra_context happiness: 'very'

For more information, see Context.

Deep Dive

Want to know more? We have a detailed documentation about all parts of the library and the client integrations.