Guides
Ruby
For Sinatra, Hanami, Roda, plain Rack apps, background workers and scripts, use the official
sentry-ruby gem. On Rails, follow the Rails guide instead.
1. Install the gem
gem "sentry-ruby"2. Initialize it at boot
Run this once, before your app handles any work:
require "sentry-ruby"
Sentry.init do |config|
config.dsn = ENV["SENTRY_DSN"] # https://<key>@uncaught.thistinct.tools/<project-id>
config.environment = ENV.fetch("APP_ENV", "production")
config.release = ENV["GIT_SHA"]
config.traces_sample_rate = 0.1 # time one in ten requests for Performance
end3. Catch exceptions
For Rack apps (Sinatra, Hanami, Roda), add the middleware in config.ru:
use Sentry::Rack::CaptureExceptions
run MyAppAnywhere else, like a worker or a script, report what you rescue:
begin
sync_inventory
rescue => error
Sentry.capture_exception(error)
raise
endSidekiq, Resque and Delayed Job have their own gems that report job failures for you:
gem "sentry-sidekiq" # or sentry-resque, sentry-delayed_jobAdd context
Sentry.set_user(id: user.id, email: user.email)
Sentry.set_tags(queue: "imports", tenant: tenant.slug)
Sentry.add_breadcrumb(Sentry::Breadcrumb.new(category: "import", message: "Read #{rows.size} rows"))