Sentry's Ruby SDK is a client and integration layer for the Sentry error reporting API. It supports Ruby >= 2.3. JRuby support is provided but experimental.
If you don't already have an account and Sentry project established, head over to sentry.io, then return to this page.
Using a framework? Take a look at our specific guides to get started.
Sentry captures data by using an SDK within your application’s runtime. Sentry's Ruby SDK comes as a gem and is straightforward to install. If you are using Bundler just add this to your
To install the development version from GitHub:
gem "sentry-raven", :github => "getsentry/raven-ruby"
To activate integrations manually (or don’t want them activated by default), require “raven/base” instead of “raven” or “sentry-raven”. In that case disable the requiring in the
gem "sentry-raven", :require => false
And in your initialization code:
require "raven/base" require "raven/integrations/rails" require "raven/integrations/delayed_job"
This stops you from calling
Raven.inject, which is where all this integration loading occurs.
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 = 'https://examplePublicKey@o0.ingest.sentry.io/0' 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
You can add either of the snippets above into your application to verify that Sentry is set up correctly.
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: 'firstname.lastname@example.org' # 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.