Basic Options
Configuration is passed as part of the client initialization:
Sentry.init do |config|
config.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0'
config.attr = 'value'
end
Optional settings
async
- When an error or message occurs, the notification is immediately sent to Sentry, synchronously. This means that returning a response to a user may be delayed.
We recommend creating a background job, using your background job processor, that will send Sentry notifications. The client will pass a JSON-compatible Hash representation of the Event into the callback.
config.async = lambda { |event|
SentryJob.perform_later(event)
}
If the async callback raises an exception, Sentry will attempt to send synchronously.
backtrace_cleanup_callback
- If you want to clean up exceptions' backtrace before it's sent to Sentry, you can specify a callback with
backtrace_cleanup_callback
to do that. For example:
config.backtrace_cleanup_callback = lambda do |backtrace|
Rails.backtrace_cleaner.clean(backtrace)
end
before_send
- Provide a lambda or proc. This will be
called
before sending an event to Sentry. Receives anevent
andhint
as parameter.hint
is a dict{:exception => ex | nil, :message => message | nil}
. It is possible to mutate the event, also if this function returnsnil
the event will be dropped and not sent.
Sentry.init do |config|
config.before_send = lambda do |event, hint|
event[:key] = value
event
end
end
breadcrumbs_logger
- Sentry supports two breadcrumbs loggers in the Ruby SDK:
SentryLogger
- A general breadcrumbs logger for all Ruby applications.ActiveSupportLogger
- Built on top of Rails ActiveSupport's instrumentation and provides many Rails-specific information.
And you can enable them with the breadcrumbs_logger
option:
config.breadcrumbs_logger = :sentry_logger
config.breadcrumbs_logger = :active_support_logger
config.breadcrumbs_logger = [:sentry_logger, :active_support_logger]
enabled_environments
- As of v0.10.0, events will be sent to Sentry in all environments. If you do not wish to send events in an environment, we suggest you unset the SENTRY_DSN variable in that environment.
Alternately, you can configure Sentry to run only in certain environments by configuring the enabled_environments
list. For example, to only run Sentry in production:
config.enabled_environments = %w[production]
environment
- Sentry automatically sets the current environment to RAILS_ENV, or if it is not present, RACK_ENV. If you are using Sentry outside of Rack or Rails, or wish to override environment detection, you’ll need to set the current environment by setting SENTRY_CURRENT_ENV or configuring the client yourself:
Sentry.init do |config|
config.environment = 'production'
end
excluded_exceptions
- If you never wish to be notified of certain exceptions, specify ‘excluded_exceptions’ in your config file.
In the example below, the exceptions Rails uses to generate 404 responses will be suppressed.
config.excluded_exceptions += ['ActionController::RoutingError', 'ActiveRecord::RecordNotFound']
You can find the list of exceptions that are excluded by default in Sentry::Configuration::IGNORE_DEFAULT
. It is suggested that you append to these defaults rather than overwrite them with =
.
inspect_exception_causes_for_exclusion
- Inspect an incoming exception's causes when determining whether or not that exception should be excluded. This option works together with
excluded_exceptions
. Default value isfalse
.
config.inspect_exception_causes_for_exclusion = false
logger
- The logger used by Sentry. Default is an instance of Sentry::Logger.
config.logger = Sentry::Logger.new(STDOUT)
Sentry respects logger levels.
release
- Track the version of your application in Sentry.
We guess the release intelligently in the following order of preference:
- Commit SHA of the last commit (git)
- Reading from the REVISION file in the app root
- Heroku’s dyno metadata (must have enabled via Heroku Labs)
Sentry.init do |config|
config.release = 'my-project-name@2.3.12'
end
We'll automatically attempt to detect the release in certain environments, such as Heroku and Capistrano.
sample_rate
- The sampling factor to apply to events. A value of 0.00 will deny sending any events, and a value of 1.00 will send 100% of events.
# send 50% of events
config.sample_rate = 0.5
send_default_pii
- When its value is
false
(default), sensitive information like
- user ip
- user cookie
- request body
will not be sent to Sentry.
You can re-enable it by setting:
config.send_default_pii = true
Tracing Options
traces_sample_rate
- By providing a float between
0.0
and1.0
, you can control the sampling factor of tracing events.
nil
(default) or0.0
means the tracing feature is disabled.1.0
means sending all the events.
Sentry.init do |config|
# ...
config.traces_sample_rate = 0.5
end
traces_sampler
- You can gain more control on tracing event (transaction)'s sampling decision by providing a callable object (
Proc
orLambda
) as atraces_sampler
:
Sentry.init do |config|
config.traces_sampler = lambda do |sampling_context|
# transaction_context is the transaction object in hash form
# keep in mind that sampling happens right after the transaction is initialized
# e.g. at the beginning of the request
transaction = sampling_context[:transaction_context]
# if the transaction is important, set a higher rate
if transaction[:name].match?("orders")
0.5
# otherwise, give it a lower rate
else
0.1
end
end
end
Transport Options
transport_class
- By default, the SDK uses
Sentry::HTTPTransport
class for sending events to Sentry, which should work for the majority of users. But if you want to use your own Transport class, you can change it with this option:
config.transport.transport_class = MyTransportClass
Environment Variables
SENTRY_DSN
- After you complete setting up a project, you’ll be given a value which we call a DSN, or Data Source Name. It looks a lot like a standard URL, but it’s actually just a representation of the configuration required by Sentry (the Sentry client). It consists of a few pieces, including the protocol, public and secret keys, the server address, and the project identifier.
With Sentry, you may either set the SENTRY_DSN environment variable (recommended), or set your DSN manually in a config block:
# in Rails, this might be in config/initializers/sentry.rb
Sentry.init do |config|
config.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0'
end
- Package:
- gem:sentry-ruby
- Version:
- 4.0.1
- Repository:
- https://github.com/getsentry/sentry-ruby