Raven for Ruby is a client and integration layer for the Sentry error reporting API. It supports Ruby 1.9.3 and 2.x. JRuby support is provided but experimental.
Getting started with Sentry is a three step process:
Raven Ruby comes as a gem and is straightforward to install. If you are using Bundler just add this to your
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 do |config| config.dsn = '___DSN___' end
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 end begin 1 / 0 rescue ZeroDivisionError => exception Raven.capture_exception(exception) end
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: 'email@example.com' # 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.
Want to know more? We have a detailed documentation about all parts of the library and the client integrations.