Name: raven-ruby
Owner: looker
Description: Raven is a Ruby client for Sentry
Forked from: getsentry/raven-ruby
Created: 2017-01-06 22:25:30.0
Updated: 2017-01-06 22:25:32.0
Pushed: 2017-01-10 18:44:43.0
Homepage: https://getsentry.com
Size: 1178
Language: Ruby
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A client and integration layer for the Sentry error reporting API.
We test on Ruby 1.9, 2.2 and 2.3 at the latest patchlevel/teeny version. We also support JRuby 1.7 and 9.0. Our Rails integration works with Rails 4.2+.
"sentry-raven"
Raven will capture and send exceptions to the Sentry server whenever its DSN is set. This makes environment-based configuration easy - if you don't want to send errors in a certain environment, just don't set the DSN in that environment!
t your SENTRY_DSN environment variable.
rt SENTRY_DSN=http://public:secret@example.com/project-id
you can configure the client in the code (not recommended - keep your DSN secret!)
n.configure do |config|
nfig.dsn = 'http://public:secret@example.com/project-id'
Raven ignores some exceptions by default - most of these are related to 404s or controller actions not being found. For a complete list, see the IGNORE_DEFAULT
constant.
Raven doesn't report POST data or cookies by default. In addition, it will attempt to remove any obviously sensitive data, such as credit card or Social Security numbers. For more information about how Sentry processes your data, check out the documentation on the processors
config setting.
If you use Rails, you're already done - no more configuration required! Check Integrations for more details on other gems Sentry integrates with automatically.
Otherwise, Raven supports two methods of capturing exceptions:
n.capture do
capture any exceptions which happen during execution of this block
/ 0
n
/ 0
ue ZeroDivisionError => exception
ven.capture_exception(exception)
You're all set - but there's a few more settings you may want to know about too!
While we advise that you set your Sentry DSN through the SENTRY_DSN
environment
variable, there are two other configuration settings for controlling Raven:
N can be configured as a config setting instead.
ace in config/initializers or similar.
n.configure do |config|
nfig.dsn = 'your_dsn'
And, while not necessary if using SENTRY_DSN
, you can also provide an environments
setting. Raven will only capture events when RACK_ENV
or RAILS_ENV
matches
an environment in the list.
n.configure do |config|
nfig.environments = %w[staging production]
When an error or message occurs, the notification is immediately sent to Sentry. Raven can be configured to send asynchronously:
ig.async = lambda { |event|
read.new { Raven.send_event(event) }
Using a thread to send events will be adequate for truly parallel Ruby platforms such as JRuby, though the benefit on MRI/CRuby will be limited. If the async callback raises an exception, Raven will attempt to send synchronously.
We recommend creating a background job, using your background job processor, that will send Sentry notifications in the background. Rather than enqueuing an entire Raven::Event object, we recommend providing the Hash representation of an event as a job argument. Here?s an example for ActiveJob:
ig.async = lambda { |event|
ntryJob.perform_later(event.to_hash)
s SentryJob < ActiveJob::Base
eue_as :default
f perform(event)
Raven.send_event(event)
d
If Raven fails to send an event to Sentry for any reason (either the Sentry server has returned a 4XX or 5XX response), this Proc or lambda will be called.
ig.transport_failure_callback = lambda { |event|
minMailer.email_admins("Oh god, it's on fire!", event).deliver_later
Much of the usefulness of Sentry comes from additional context data with the events. Raven 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:
nd the logged in user
n.user_context email: 'foo@example.com'
g the request with something interesting
n.tags_context interesting: 'yes'
ovide a bit of additional context
n.extra_context happiness: 'very'
For more information, see Context.