Basic Options

Configuration is passed as part of the client initialization:

Copied
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.

Copied
config.async = lambda { |event|
  SentryJob.perform_later(event)
}

If the async callback raises an exception, Sentry will attempt to send synchronously.

background_worker_threads
If config.async isn't provided, Sentry will send events in a non-blocking way with its own background worker. By default, the worker holds a thread pool that has [the number of processors] threads. But you can configure it with this configuration option:

Copied
config.background_worker_threads = 5

Or if you want to send events synchronously, set the value to 0:

Copied
config.background_worker_threads = 0

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:

Copied
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 an event and hint as parameter. hint is a dict {:exception => ex | nil, :message => message | nil}. It is possible to mutate the event, also if this function returns nil the event will be dropped and not sent.

Copied
Sentry.init do |config|
  filter = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters)
  config.before_send = lambda do |event, hint|
    # note1: if you have config.async configured, the event here will be a Hash instead of an Event object
    # note2: the code below is just an example, you should adjust the logic based on your needs
    event.request.data = filter.filter(event.request.data)
    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:

Copied
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:

Copied
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:

Copied
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.

Copied
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 is false.

Copied
config.inspect_exception_causes_for_exclusion = false

logger
The logger used by Sentry. Default is an instance of Sentry::Logger.

Copied
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)
Copied
Sentry.init do |config|
  config.release = 'my-project-name@2.3.12'
end

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.

Copied
# 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:

Copied
config.send_default_pii = true

Tracing Options

traces_sample_rate
By providing a float between 0.0 and 1.0, you can control the sampling factor of tracing events.

  • nil (default) or 0.0 means the tracing feature is disabled.
  • 1.0 means sending all the events.
Copied
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 or Lambda) as a traces_sampler:

Copied
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:

Copied
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:

Copied
# in Rails, this might be in config/initializers/sentry.rb
Sentry.init do |config|
  config.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0'
end
You can edit this page on GitHub.