Class: Sentry::Configuration

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

Constant Summary collapse

IGNORE_DEFAULT =

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

[
  'Mongoid::Errors::DocumentNotFound',
  'Rack::QueryParser::InvalidParameterError',
  'Rack::QueryParser::ParameterTypeError',
  'Sinatra::NotFound'
].freeze
RACK_ENV_WHITELIST_DEFAULT =
%w(
  REMOTE_ADDR
  SERVER_NAME
  SERVER_PORT
).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
LOG_PREFIX =
"** [Sentry] ".freeze
MODULE_SEPARATOR =
"::".freeze
AVAILABLE_BREADCRUMBS_LOGGERS =
[:sentry_logger, :active_support_logger].freeze
@@post_initialization_callbacks =

Post initialization callbacks are called at the end of initialization process allowing extending the configuration of sentry-ruby by multiple extensions

[]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/sentry/configuration.rb', line 176

def initialize
  self.background_worker_threads = Concurrent.processor_count
  self.max_breadcrumbs = BreadcrumbBuffer::DEFAULT_SIZE
  self.breadcrumbs_logger = []
  self.context_lines = 3
  self.environment = environment_from_env
  self.enabled_environments = []
  self.exclude_loggers = []
  self.excluded_exceptions = IGNORE_DEFAULT.dup
  self.inspect_exception_causes_for_exclusion = true
  self.linecache = ::Sentry::LineCache.new
  self.logger = ::Sentry::Logger.new(STDOUT)
  self.project_root = Dir.pwd

  self.release = detect_release
  self.sample_rate = 1.0
  self.send_modules = true
  self.send_default_pii = false
  self.trusted_proxies = []
  self.dsn = ENV['SENTRY_DSN']
  self.server_name = server_name_from_env

  self.before_send = false
  self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT

  @transport = Transport::Configuration.new
  @gem_specs = Hash[Gem::Specification.map { |spec| [spec.name, spec.version.to_s] }] if Gem::Specification.respond_to?(:map)

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



14
15
16
# File 'lib/sentry/configuration.rb', line 14

def app_dirs_pattern
  @app_dirs_pattern
end

#asyncObject

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



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

def async
  @async
end

#background_worker_threadsObject

to send events in a non-blocking way, sentry-ruby has 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 E.g.: config.background_worker_threads = 5

if you want to send events synchronously, set the value to 0 E.g.: config.background_worker_threads = 0



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

def background_worker_threads
  @background_worker_threads
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 Sentry.configuration.backtrace_cleanup_callback = lambda do |backtrace|

Rails.backtrace_cleaner.clean(backtrace)

end “‘



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

def backtrace_cleanup_callback
  @backtrace_cleanup_callback
end

#before_breadcrumbObject

Optional Proc, called before adding the breadcrumb to the current scope E.g.: lambda { |breadcrumb, hint| breadcrumb } E.g.: lambda { |breadcrumb, hint| nil } E.g.: lambda { |breadcrumb, hint|

breadcrumb.message = 'a'
breadcrumb

}



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

def before_breadcrumb
  @before_breadcrumb
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

}



58
59
60
# File 'lib/sentry/configuration.rb', line 58

def before_send
  @before_send
end

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

  • :sentry_logger

  • :active_support_logger



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

def breadcrumbs_logger
  @breadcrumbs_logger
end

#context_linesObject

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



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

def context_lines
  @context_lines
end

#dsnObject

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



75
76
77
# File 'lib/sentry/configuration.rb', line 75

def dsn
  @dsn
end

#enabled_environmentsObject

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



78
79
80
# File 'lib/sentry/configuration.rb', line 78

def enabled_environments
  @enabled_environments
end

#environmentObject

RACK_ENV by default.



72
73
74
# File 'lib/sentry/configuration.rb', line 72

def environment
  @environment
end

#errorsObject (readonly)

these are not config options



147
148
149
# File 'lib/sentry/configuration.rb', line 147

def errors
  @errors
end

#exclude_loggersObject

Logger ‘progname’s to exclude from breadcrumbs



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

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.



85
86
87
# File 'lib/sentry/configuration.rb', line 85

def excluded_exceptions
  @excluded_exceptions
end

#gem_specsObject (readonly)

these are not config options



147
148
149
# File 'lib/sentry/configuration.rb', line 147

def gem_specs
  @gem_specs
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



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

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 Sentry::LineCache for the required interface you must implement.



94
95
96
# File 'lib/sentry/configuration.rb', line 94

def linecache
  @linecache
end

#loggerObject

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



98
99
100
# File 'lib/sentry/configuration.rb', line 98

def logger
  @logger
end

#max_breadcrumbsObject

Max number of breadcrumbs a breadcrumb buffer can hold



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

def max_breadcrumbs
  @max_breadcrumbs
end

#project_rootObject

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



102
103
104
# File 'lib/sentry/configuration.rb', line 102

def project_root
  @project_root
end

#rack_env_whitelistObject

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



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

def rack_env_whitelist
  @rack_env_whitelist
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.



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

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.



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

def sample_rate
  @sample_rate
end

#send_default_piiObject

When send_default_pii’s value is false (default), sensitive information like

  • user ip

  • user cookie

  • request body

will not be sent to Sentry.



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

def send_default_pii
  @send_default_pii
end

#send_modulesObject

Include module versions in reports - boolean.



116
117
118
# File 'lib/sentry/configuration.rb', line 116

def send_modules
  @send_modules
end

#server_nameObject

Returns the value of attribute server_name.



128
129
130
# File 'lib/sentry/configuration.rb', line 128

def server_name
  @server_name
end

#traces_sample_rateObject

Take a float between 0.0 and 1.0 as the sample rate for tracing events (transactions).



134
135
136
# File 'lib/sentry/configuration.rb', line 134

def traces_sample_rate
  @traces_sample_rate
end

#traces_samplerObject

Take a Proc that controls the sample rate for every tracing event, e.g. “‘ lambda do |tracing_context|

# tracing_context[:transaction_context] contains the information about the transaction
# tracing_context[:parent_sampled] contains the transaction's parent's sample decision
true # return value can be a boolean or a float between 0.0 and 1.0

end “‘



144
145
146
# File 'lib/sentry/configuration.rb', line 144

def traces_sampler
  @traces_sampler
end

#transportObject (readonly)

Return a Transport::Configuration object for transport-related configurations.



131
132
133
# File 'lib/sentry/configuration.rb', line 131

def transport
  @transport
end

#trusted_proxiesObject

IP ranges for trusted proxies that will be skipped when calculating IP address.



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

def trusted_proxies
  @trusted_proxies
end

Instance Method Details

#enabled_in_current_env?Boolean

Returns:

  • (Boolean)


291
292
293
# File 'lib/sentry/configuration.rb', line 291

def enabled_in_current_env?
  enabled_environments.empty? || enabled_environments.include?(environment)
end

#error_messagesObject



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

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)


278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/sentry/configuration.rb', line 278

def exception_class_allowed?(exc)
  if exc.is_a?(Sentry::Error)
    # Try to prevent error reporting loops
    logger.debug(LOGGER_PROGNAME) { "Refusing to capture Sentry error: #{exc.inspect}" }
    false
  elsif excluded_exception?(exc)
    logger.debug(LOGGER_PROGNAME) { "User excluded error: #{exc.inspect}" }
    false
  else
    true
  end
end

#sending_allowed?Boolean

Returns:

  • (Boolean)


261
262
263
264
265
266
267
# File 'lib/sentry/configuration.rb', line 261

def sending_allowed?
  @errors = []

  valid? &&
    capture_in_environment? &&
    sample_allowed?
end

#stacktrace_builderObject



299
300
301
302
303
304
305
306
307
# File 'lib/sentry/configuration.rb', line 299

def stacktrace_builder
  @stacktrace_builder ||= StacktraceBuilder.new(
    project_root: @project_root.to_s,
    app_dirs_pattern: @app_dirs_pattern,
    linecache: @linecache,
    context_lines: @context_lines,
    backtrace_cleanup_callback: @backtrace_cleanup_callback
  )
end

#tracing_enabled?Boolean

Returns:

  • (Boolean)


295
296
297
# File 'lib/sentry/configuration.rb', line 295

def tracing_enabled?
  !!((@traces_sample_rate && @traces_sample_rate > 0.0) || @traces_sampler)
end