Class: Raven::Configuration

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

Constant Summary collapse

IGNORE_DEFAULT =
[
  'AbstractController::ActionNotFound',
  'ActionController::InvalidAuthenticityToken',
  'ActionController::RoutingError',
  'ActionController::UnknownAction',
  'ActiveRecord::RecordNotFound',
  'CGI::Session::CookieStore::TamperedWithCookie',
  'Mongoid::Errors::DocumentNotFound',
  '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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/raven/configuration.rb', line 163

def initialize
  self.async = false
  self.context_lines = 3
  self.current_environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
  self.encoding = 'gzip'
  self.environments = []
  self.exclude_loggers = []
  self.excluded_exceptions = IGNORE_DEFAULT.dup
  self.open_timeout = 1
  self.processors = DEFAULT_PROCESSORS.dup
  self.proxy = nil
  self.rails_activesupport_breadcrumbs = false
  self.rails_report_rescued_exceptions = true
  self.release = detect_release
  self.sanitize_credit_cards = true
  self.sanitize_fields = []
  self.sanitize_http_headers = []
  self.send_modules = true
  self.server = ENV['SENTRY_DSN'] if ENV['SENTRY_DSN']
  self.server_name = resolve_hostname
  self.should_capture = false
  self.ssl_verification = true
  self.tags = {}
  self.timeout = 2
  self.transport_failure_callback = false
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)/



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

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



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

def async
  @async
end

#context_linesObject

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



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

def context_lines
  @context_lines
end

#current_environmentObject

RACK_ENV by default.



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

def current_environment
  @current_environment
end

#encodingObject

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



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

def encoding
  @encoding
end

#environmentsObject

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



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

def environments
  @environments
end

#exclude_loggersObject

Logger ‘progname’s to exclude from breadcrumbs



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

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.



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

def excluded_exceptions
  @excluded_exceptions
end

#hostObject

DSN component - set automatically if DSN provided



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

def host
  @host
end

#http_adapterObject

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



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

def http_adapter
  @http_adapter
end

#loggerObject

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



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

def logger
  @logger
end

#open_timeoutObject

Timeout waiting for the Sentry server connection to open in seconds



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

def open_timeout
  @open_timeout
end

#pathObject

DSN component - set automatically if DSN provided



49
50
51
# File 'lib/raven/configuration.rb', line 49

def path
  @path
end

#portObject

DSN component - set automatically if DSN provided



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

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.



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

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.



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

def project_id
  @project_id
end

#project_rootObject

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



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

def project_root
  @project_root
end

#proxyObject

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



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

def proxy
  @proxy
end

#public_keyObject

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



71
72
73
# File 'lib/raven/configuration.rb', line 71

def public_key
  @public_key
end

#rails_activesupport_breadcrumbsObject

Turns on ActiveSupport breadcrumbs integration



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

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.



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

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.



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

def release
  @release
end

#sanitize_credit_cardsObject

Boolean - sanitize values that look like credit card numbers



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

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.



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

def sanitize_fields
  @sanitize_fields
end

#sanitize_http_headersObject

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



95
96
97
# File 'lib/raven/configuration.rb', line 95

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”



99
100
101
# File 'lib/raven/configuration.rb', line 99

def scheme
  @scheme
end

#secret_keyObject

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



103
104
105
# File 'lib/raven/configuration.rb', line 103

def secret_key
  @secret_key
end

#send_modulesObject

Include module versions in reports - boolean.



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

def send_modules
  @send_modules
end

#serverObject

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



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

def server
  @server
end

#server_nameObject

Returns the value of attribute server_name.



111
112
113
# File 'lib/raven/configuration.rb', line 111

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 }



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

def should_capture
  @should_capture
end

#silence_readyObject

Silences ready message when true.



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

def silence_ready
  @silence_ready
end

#sslObject

SSL settings passed directly to Faraday’s ssl option



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

def ssl
  @ssl
end

#ssl_ca_fileObject

The path to the SSL certificate file



126
127
128
# File 'lib/raven/configuration.rb', line 126

def ssl_ca_file
  @ssl_ca_file
end

#ssl_verificationObject

Should the SSL certificate of the server be verified?



129
130
131
# File 'lib/raven/configuration.rb', line 129

def ssl_verification
  @ssl_verification
end

#tagsObject

Default tags for events. Hash.



132
133
134
# File 'lib/raven/configuration.rb', line 132

def tags
  @tags
end

#timeoutObject

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



135
136
137
# File 'lib/raven/configuration.rb', line 135

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



139
140
141
# File 'lib/raven/configuration.rb', line 139

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



242
243
244
# File 'lib/raven/configuration.rb', line 242

def [](option)
  public_send(option)
end

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

Returns:

  • (Boolean)


250
251
252
253
# File 'lib/raven/configuration.rb', line 250

def capture_allowed?(message_or_exc = nil)
  capture_in_current_environment? &&
    capture_allowed_by_callback?(message_or_exc)
end

#detect_releaseObject



269
270
271
272
273
# File 'lib/raven/configuration.rb', line 269

def detect_release
  detect_release_from_git ||
    detect_release_from_capistrano ||
    detect_release_from_heroku
end

#verify!Object



258
259
260
261
262
# File 'lib/raven/configuration.rb', line 258

def verify!
  %w(server public_key secret_key project_id).each do |key|
    raise(Error, "No #{key} specified") unless public_send key
  end
end