Class: Raven::Configuration

Inherits:
Object show all
Defined in:
lib/raven/configuration.rb

Constant Summary collapse

IGNORE_DEFAULT =

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

[
  'AbstractController::ActionNotFound',
  'ActionController::BadRequest',
  'ActionController::InvalidAuthenticityToken',
  'ActionController::InvalidCrossOriginRequest',
  'ActionController::MethodNotAllowed',
  'ActionController::NotImplemented',
  'ActionController::ParameterMissing',
  'ActionController::RoutingError',
  'ActionController::UnknownAction',
  'ActionController::UnknownFormat',
  'ActionController::UnknownHttpMethod',
  'ActionDispatch::Http::Parameters::ParseError',
  'ActiveJob::DeserializationError', # Can cause infinite loops
  'ActiveRecord::RecordNotFound',
  'CGI::Session::CookieStore::TamperedWithCookie',
  'Mongoid::Errors::DocumentNotFound',
  'Rack::QueryParser::InvalidParameterError',
  'Rack::QueryParser::ParameterTypeError',
  'Sinatra::NotFound'
].freeze
DEFAULT_PROCESSORS =

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

[
  Raven::Processor::RemoveCircularReferences,
  Raven::Processor::UTF8Conversion,
  Raven::Processor::SanitizeData,
  Raven::Processor::Cookies,
  Raven::Processor::PostData,
  Raven::Processor::HTTPHeaders
].freeze
HEROKU_DYNO_METADATA_MESSAGE =
"You are running on Heroku but haven't enabled Dyno Metadata. For Sentry's "\
"release detection to work correctly, please run `heroku labs:enable runtime-dyno-metadata`".freeze
RACK_ENV_WHITELIST_DEFAULT =
%w(
  REMOTE_ADDR
  SERVER_NAME
  SERVER_PORT
).freeze
LOG_PREFIX =
"** [Raven] ".freeze
MODULE_SEPARATOR =
"::".freeze
AVAILABLE_BREADCRUMBS_LOGGERS =
[:sentry_logger, :active_support_logger].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File '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

Instance Attribute Details

#app_dirs_patternObject

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)/



8
9
10
# File 'lib/raven/configuration.rb', line 8

def app_dirs_pattern
  @app_dirs_pattern
end

#asyncObject Also known as: async?

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



12
13
14
# File 'lib/raven/configuration.rb', line 12

def async
  @async
end

#backtrace_cleanup_callbackObject

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 “‘



137
138
139
# File 'lib/raven/configuration.rb', line 137

def backtrace_cleanup_callback
  @backtrace_cleanup_callback
end

#before_sendObject

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

}



188
189
190
# File 'lib/raven/configuration.rb', line 188

def before_send
  @before_send
end

An array of breadcrumbs loggers to be used. Available options are:

  • :sentry_logger

  • :active_support_logger



18
19
20
# File 'lib/raven/configuration.rb', line 18

def breadcrumbs_logger
  @breadcrumbs_logger
end

#context_linesObject

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



21
22
23
# File 'lib/raven/configuration.rb', line 21

def context_lines
  @context_lines
end

#current_environmentObject

RACK_ENV by default.



24
25
26
# File 'lib/raven/configuration.rb', line 24

def current_environment
  @current_environment
end

#dsnObject (readonly)

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



194
195
196
# File 'lib/raven/configuration.rb', line 194

def dsn
  @dsn
end

#encodingObject

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



27
28
29
# File 'lib/raven/configuration.rb', line 27

def encoding
  @encoding
end

#environmentsObject

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



30
31
32
# File 'lib/raven/configuration.rb', line 30

def environments
  @environments
end

#errorsObject (readonly)

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



191
192
193
# File 'lib/raven/configuration.rb', line 191

def errors
  @errors
end

#exclude_loggersObject

Logger ‘progname’s to exclude from breadcrumbs



33
34
35
# File 'lib/raven/configuration.rb', line 33

def exclude_loggers
  @exclude_loggers
end

#excluded_exceptionsObject

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



37
38
39
# File 'lib/raven/configuration.rb', line 37

def excluded_exceptions
  @excluded_exceptions
end

#faraday_builderObject

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



51
52
53
# File 'lib/raven/configuration.rb', line 51

def faraday_builder
  @faraday_builder
end

#hostObject

DSN component - set automatically if DSN provided



44
45
46
# File 'lib/raven/configuration.rb', line 44

def host
  @host
end

#http_adapterObject

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



47
48
49
# File 'lib/raven/configuration.rb', line 47

def http_adapter
  @http_adapter
end

#inspect_exception_causes_for_exclusionObject Also known as: inspect_exception_causes_for_exclusion?

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



40
41
42
# File 'lib/raven/configuration.rb', line 40

def inspect_exception_causes_for_exclusion
  @inspect_exception_causes_for_exclusion
end

#linecacheObject

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.



56
57
58
# File 'lib/raven/configuration.rb', line 56

def linecache
  @linecache
end

#loggerObject

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



60
61
62
# File 'lib/raven/configuration.rb', line 60

def logger
  @logger
end

#open_timeoutObject

Timeout waiting for the Sentry server connection to open in seconds



63
64
65
# File 'lib/raven/configuration.rb', line 63

def open_timeout
  @open_timeout
end

#pathObject

DSN component - set automatically if DSN provided



66
67
68
# File 'lib/raven/configuration.rb', line 66

def path
  @path
end

#portObject

DSN component - set automatically if DSN provided



69
70
71
# File 'lib/raven/configuration.rb', line 69

def port
  @port
end

#processorsObject

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



73
74
75
# File 'lib/raven/configuration.rb', line 73

def processors
  @processors
end

#project_idObject

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



77
78
79
# File 'lib/raven/configuration.rb', line 77

def project_id
  @project_id
end

#project_rootObject

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



81
82
83
# File 'lib/raven/configuration.rb', line 81

def project_root
  @project_root
end

#proxyObject

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



84
85
86
# File 'lib/raven/configuration.rb', line 84

def proxy
  @proxy
end

#public_keyObject

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



88
89
90
# File 'lib/raven/configuration.rb', line 88

def public_key
  @public_key
end

#rack_env_whitelistObject

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



197
198
199
# File 'lib/raven/configuration.rb', line 197

def rack_env_whitelist
  @rack_env_whitelist
end

#rails_activesupport_breadcrumbsObject

Turns on ActiveSupport breadcrumbs integration



91
92
93
# File 'lib/raven/configuration.rb', line 91

def rails_activesupport_breadcrumbs
  @rails_activesupport_breadcrumbs
end

#rails_report_rescued_exceptionsObject

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.



97
98
99
# File 'lib/raven/configuration.rb', line 97

def rails_report_rescued_exceptions
  @rails_report_rescued_exceptions
end

#releaseObject

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



101
102
103
# File 'lib/raven/configuration.rb', line 101

def release
  @release
end

#sample_rateObject

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.



105
106
107
# File 'lib/raven/configuration.rb', line 105

def sample_rate
  @sample_rate
end

#sanitize_credit_cardsObject

Boolean - sanitize values that look like credit card numbers



108
109
110
# File 'lib/raven/configuration.rb', line 108

def sanitize_credit_cards
  @sanitize_credit_cards
end

#sanitize_fieldsObject

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.



113
114
115
# File 'lib/raven/configuration.rb', line 113

def sanitize_fields
  @sanitize_fields
end

#sanitize_fields_excludedObject

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)



117
118
119
# File 'lib/raven/configuration.rb', line 117

def sanitize_fields_excluded
  @sanitize_fields_excluded
end

#sanitize_http_headersObject

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



120
121
122
# File 'lib/raven/configuration.rb', line 120

def sanitize_http_headers
  @sanitize_http_headers
end

#schemeObject

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



124
125
126
# File 'lib/raven/configuration.rb', line 124

def scheme
  @scheme
end

#secret_keyObject

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.



143
144
145
# File 'lib/raven/configuration.rb', line 143

def secret_key
  @secret_key
end

#send_modulesObject

Include module versions in reports - boolean.



146
147
148
# File 'lib/raven/configuration.rb', line 146

def send_modules
  @send_modules
end

#serverObject

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



149
150
151
# File 'lib/raven/configuration.rb', line 149

def server
  @server
end

#server_nameObject

Returns the value of attribute server_name.



151
152
153
# File 'lib/raven/configuration.rb', line 151

def server_name
  @server_name
end

#should_captureObject

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 }



157
158
159
# File 'lib/raven/configuration.rb', line 157

def should_capture
  @should_capture
end

#silence_readyObject

Silences ready message when true.



160
161
162
# File 'lib/raven/configuration.rb', line 160

def silence_ready
  @silence_ready
end

#sslObject

SSL settings passed directly to Faraday’s ssl option



163
164
165
# File 'lib/raven/configuration.rb', line 163

def ssl
  @ssl
end

#ssl_ca_fileObject

The path to the SSL certificate file



166
167
168
# File 'lib/raven/configuration.rb', line 166

def ssl_ca_file
  @ssl_ca_file
end

#ssl_verificationObject

Should the SSL certificate of the server be verified?



169
170
171
# File 'lib/raven/configuration.rb', line 169

def ssl_verification
  @ssl_verification
end

#tagsObject

Default tags for events. Hash.



172
173
174
# File 'lib/raven/configuration.rb', line 172

def tags
  @tags
end

#timeoutObject

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



175
176
177
# File 'lib/raven/configuration.rb', line 175

def timeout
  @timeout
end

#transport_failure_callbackObject

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



179
180
181
# File 'lib/raven/configuration.rb', line 179

def transport_failure_callback
  @transport_failure_callback
end

Instance Method Details

#[](option) ⇒ Object

Allows config options to be read like a hash

Parameters:

  • option (Symbol)

    Key for a given attribute



369
370
371
# File 'lib/raven/configuration.rb', line 369

def [](option)
  public_send(option)
end

#capture_allowed?(message_or_exc = nil) ⇒ Boolean Also known as: sending_allowed?

Returns:

  • (Boolean)


377
378
379
380
381
382
383
384
# File '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

#enabled_in_current_env?Boolean

Returns:

  • (Boolean)


416
417
418
# File 'lib/raven/configuration.rb', line 416

def enabled_in_current_env?
  environments.empty? || environments.include?(current_environment)
end

#error_messagesObject



388
389
390
391
# File '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) ⇒ Boolean

Returns:

  • (Boolean)


403
404
405
406
407
408
409
410
411
412
413
414
# File '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