# class Raven::Configuration

### Constants

AVAILABLE_BREADCRUMBS_LOGGERS
DEFAULT_PROCESSORS

  Note the order - we have to remove circular references and bad characters before passing to other processors.

HEROKU_DYNO_METADATA_MESSAGE
IGNORE_DEFAULT

  Most of these errors generate 4XX responses. In general, Sentry clients only automatically report 5xx responses.

LOG_PREFIX
MODULE_SEPARATOR
RACK_ENV_WHITELIST_DEFAULT

### Attributes

app_dirs_pattern[RW]

Directories to be recognized as part of your app. e.g. if you have an `engines` dir at the root of your project, you may want to set this to something like /(app|config|engines|lib)/

async[R]

Provide an object that responds to `call` to send events asynchronously. E.g.: lambda { |event| Thread.new { Raven.send_event(event) } }

async?[R]

Provide an object that responds to `call` to send events asynchronously. E.g.: lambda { |event| Thread.new { Raven.send_event(event) } }

backtrace_cleanup_callback[RW]

a proc/lambda that takes an array of stack traces it'll be used to silence (reduce) backtrace of the exception

for example:

“`ruby Raven.configuration.backtrace_cleanup_callback = lambda do |backtrace|

    Rails.backtrace_cleaner.clean(backtrace)

end “`

before_send[R]

Optional Proc, called before sending an event to the server/ E.g.: lambda { |event, hint| event } E.g.: lambda { |event, hint| nil } E.g.: lambda { |event, hint|

    event[:message] = 'a'
    event

}

context_lines[RW]

Number of lines of code context to capture, or nil for none

current_environment[R]

RACK_ENV by default.

dsn[R]

the dsn value, whether it's set via `config.dsn=` or `ENV`

encoding[R]

Encoding type for event bodies. Must be :json or :gzip.

environments[RW]

Whitelist of environments that will send notifications to Sentry. `Array` of Strings.

errors[R]

Errors object - an `Array` that contains error messages. See #

exclude_loggers[RW]

`Logger` 'progname's to exclude from breadcrumbs

excluded_exceptions[RW]

`Array` of exception classes that should never be sent. See `IGNORE_DEFAULT`. You should probably append to this rather than overwrite it.

faraday_builder[RW]

A Proc yeilding the faraday builder allowing for further configuration of the faraday adapter

host[RW]

DSN component - set automatically if DSN provided

http_adapter[RW]

The Faraday adapter to be used. Will default to Net::HTTP when not set.

inspect_exception_causes_for_exclusion[RW]

Boolean to check nested exceptions when deciding if to exclude. Defaults to false

inspect_exception_causes_for_exclusion?[RW]

Boolean to check nested exceptions when deciding if to exclude. Defaults to false

linecache[RW]

You may provide your own `LineCache` for matching paths with source files. This may be useful if you need to get source code from places other than the disk. See `Raven::LineCache` for the required interface you must implement.

logger[RW]

`Logger` used by `Raven`. In `Rails`, this is the `Rails` logger, otherwise `Raven` provides its own `Raven::Logger`.

open_timeout[RW]

Timeout waiting for the Sentry server connection to open in seconds

path[RW]

DSN component - set automatically if DSN provided

port[RW]

DSN component - set automatically if DSN provided

processors[RW]

Processors to run on data before sending upstream. See `DEFAULT_PROCESSORS`. You should probably append to this rather than overwrite it.

project_id[RW]

Project ID number to send to the Sentry server If you provide a DSN, this will be set automatically.

project_root[R]

Project directory root for in_app detection. Could be `Rails` root, etc. Set automatically for `Rails`.

proxy[RW]

Proxy information to pass to the HTTP adapter (via Faraday)

public_key[RW]

Public key for authentication with the Sentry server If you provide a DSN, this will be set automatically.

rack_env_whitelist[RW]

`Array` of rack env parameters to be included in the event sent to sentry.

rails_report_rescued_exceptions[RW]

`Rails` catches exceptions in the ActionDispatch::ShowExceptions or ActionDispatch::DebugExceptions middlewares, depending on the environment. When `rails_report_rescued_exceptions` is true (it is by default), `Raven` will report exceptions even when they are rescued by these middlewares.

release[RW]

Release tag to be passed with every event sent to Sentry. We automatically try to set this to a git SHA or Capistrano release.

sample_rate[RW]

The sampling factor to apply to events. A value of 0.0 will not send any events, and a value of 1.0 will send 100% of events.

sanitize_credit_cards[RW]

Boolean - sanitize values that look like credit card numbers

sanitize_fields[RW]

By default, Sentry censors `Hash` values when their keys match things like “secret”, “password”, etc. Provide an array of Strings that, when matched in a hash key, will be censored and not sent to Sentry.

sanitize_fields_excluded[RW]

If you're sure you want to override the default sanitization values, you can add to them to an array of Strings here, e.g. %w(authorization password)

sanitize_http_headers[RW]

Sanitize additional HTTP headers - only Authorization is removed by default.

scheme[RW]

DSN component - set automatically if DSN provided. Otherwise, can be one of “http”, “https”, or “dummy”

secret_key[RW]

Secret key for authentication with the Sentry server If you provide a DSN, this will be set automatically.

This is deprecated and not necessary for newer Sentry installations any more.

send_modules[RW]

Include module versions in reports - boolean.

server[R]

Simple server string - set this to the DSN found on your Sentry settings.

server_name[RW]
should_capture[R]

Provide a configurable callback to determine event capture. Note that the object passed into the block will be a String (messages) or an exception. e.g. lambda { |exc_or_msg| exc_or_msg.some_attr == false }

silence_ready[RW]

Silences ready message when true.

ssl[RW]

SSL settings passed directly to Faraday's ssl option

ssl_ca_file[RW]

The path to the SSL certificate file

ssl_verification[RW]

Should the SSL certificate of the server be verified?

tags[RW]

Default tags for events. `Hash`.

timeout[RW]

Timeout when waiting for the server to return data in seconds.

transport_failure_callback[R]

Optional Proc, called when the Sentry server cannot be contacted for any reason E.g. lambda { |event| Thread.new { MyJobProcessor.send_email(event) } }

### Public Class Methods

new() click to toggle source

    # File sentry-raven/lib/raven/configuration.rb, line 248
    def initialize
      self.async = false
      self.breadcrumbs_logger = []
      self.context_lines = 3
      self.current_environment = current_environment_from_env
      self.encoding = 'gzip'
      self.environments = []
      self.exclude_loggers = []
      self.excluded_exceptions = IGNORE_DEFAULT.dup
      self.inspect_exception_causes_for_exclusion = false
      self.linecache = ::Raven::LineCache.new
      self.logger = ::Raven::Logger.new(STDOUT)
      self.open_timeout = 1
      self.processors = DEFAULT_PROCESSORS.dup
      self.project_root = detect_project_root
      @rails_activesupport_breadcrumbs = false

      self.rails_report_rescued_exceptions = true
      self.release = detect_release
      self.sample_rate = 1.0
      self.sanitize_credit_cards = true
      self.sanitize_fields = []
      self.sanitize_fields_excluded = []
      self.sanitize_http_headers = []
      self.send_modules = true
      self.server = ENV['SENTRY_DSN']
      self.server_name = server_name_from_env
      self.should_capture = false
      self.ssl_verification = true
      self.tags = {}
      self.timeout = 2
      self.transport_failure_callback = false
      self.before_send = false
      self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT
    end

### Public Instance Methods

[](option) click to toggle source

Allows config options to be read like a hash

@param [Symbol] option Key for a given attribute

    # File sentry-raven/lib/raven/configuration.rb, line 369
    def [](option)
      public_send(option)
    end

async=(value) click to toggle source

    # File sentry-raven/lib/raven/configuration.rb, line 317
    def async=(value)
      unless value == false || value.respond_to?(:call)
        raise(ArgumentError, "async must be callable (or false to disable)")
      end

      @async = value
    end

before_send=(value) click to toggle source

    # File sentry-raven/lib/raven/configuration.rb, line 358
    def before_send=(value)
      unless value == false || value.respond_to?(:call)
        raise ArgumentError, "before_send must be callable (or false to disable)"
      end

      @before_send = value
    end

capture_allowed?(message_or_exc = nil) click to toggle source

    # File sentry-raven/lib/raven/configuration.rb, line 377
    def capture_allowed?(message_or_exc = nil)
      @errors = []

      valid? &&
        capture_in_current_environment? &&
        capture_allowed_by_callback?(message_or_exc) &&
        sample_allowed?
    end

Also aliased as: sending_allowed?
current_environment=(environment) click to toggle source

    # File sentry-raven/lib/raven/configuration.rb, line 373
    def current_environment=(environment)
      @current_environment = environment.to_s
    end

dsn=(value)
Alias for: server=
enabled_in_current_env?() click to toggle source

    # File sentry-raven/lib/raven/configuration.rb, line 416
    def enabled_in_current_env?
      environments.empty? || environments.include?(current_environment)
    end

encoding=(encoding) click to toggle source

    # File sentry-raven/lib/raven/configuration.rb, line 311
    def encoding=(encoding)
      raise(Error, 'Unsupported encoding') unless %w(gzip json).include? encoding

      @encoding = encoding
    end

error_messages() click to toggle source

    # File sentry-raven/lib/raven/configuration.rb, line 388
    def error_messages
      @errors = [errors[0]] + errors[1..-1].map(&:downcase) # fix case of all but first
      errors.join(", ")
    end

exception_class_allowed?(exc) click to toggle source

    # File sentry-raven/lib/raven/configuration.rb, line 403
    def exception_class_allowed?(exc)
      if exc.is_a?(Raven::Error)
        # Try to prevent error reporting loops
        logger.debug "Refusing to capture Raven error: #{exc.inspect}"
        false
      elsif excluded_exception?(exc)
        logger.debug "User excluded error: #{exc.inspect}"
        false
      else
        true
      end
    end

project_root=(root_dir) click to toggle source

    # File sentry-raven/lib/raven/configuration.rb, line 393
    def project_root=(root_dir)
      @project_root = root_dir
      Backtrace::Line.instance_variable_set(:@in_app_pattern, nil) # blow away cache
    end

sending_allowed?(message_or_exc = nil)

If we cannot capture, we cannot send.

Alias for: capture_allowed?
server=(value) click to toggle source

    # File sentry-raven/lib/raven/configuration.rb, line 284
    def server=(value)
      return if value.nil?

      @dsn = value

      uri = URI.parse(value)
      uri_path = uri.path.split('/')

      if uri.user
        # DSN-style string
        self.project_id = uri_path.pop
        self.public_key = uri.user
        self.secret_key = !(uri.password.nil? || uri.password.empty?) ? uri.password : nil
      end

      self.scheme = uri.scheme
      self.host = uri.host
      self.port = uri.port if uri.port
      self.path = uri_path.join('/')

      # For anyone who wants to read the base server string
      @server = "#{scheme}://#{host}"
      @server += ":#{port}" unless port == { 'http' => 80, 'https' => 443 }[scheme]
      @server += path
    end

Also aliased as: dsn=
should_capture=(value) click to toggle source

    # File sentry-raven/lib/raven/configuration.rb, line 350
    def should_capture=(value)
      unless value == false || value.respond_to?(:call)
        raise ArgumentError, "should_capture must be callable (or false to disable)"
      end

      @should_capture = value
    end

transport_failure_callback=(value) click to toggle source

    # File sentry-raven/lib/raven/configuration.rb, line 342
    def transport_failure_callback=(value)
      unless value == false || value.respond_to?(:call)
        raise(ArgumentError, "transport_failure_callback must be callable (or false to disable)")
      end

      @transport_failure_callback = value
    end