Class: Sentry::Configuration

Inherits:
Object
  • Object
show all
Includes:
ArgumentCheckingHelper, CustomInspection, LoggingHelper
Defined in:
lib/sentry/configuration.rb

Constant Summary collapse

PUMA_IGNORE_DEFAULT =

These exceptions could enter Puma’s lowlevel_error_handler callback and the SDK’s Puma integration But they are mostly considered as noise and should be ignored by default Please see github.com/getsentry/sentry-ruby/pull/2026 for more information

[
  "Puma::MiniSSL::SSLError",
  "Puma::HttpParserError",
  "Puma::HttpParserError501"
].freeze
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
TRACE_IGNORE_STATUS_CODES_DEFAULT =
[(301..303), (305..399), (401..404)]
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`"
LOG_PREFIX =
"** [Sentry] "
MODULE_SEPARATOR =
"::"
SKIP_INSPECTION_ATTRIBUTES =
[:@linecache, :@stacktrace_builder]
INSTRUMENTERS =
[:sentry, :otel]
PROPAGATION_TARGETS_MATCH_ALL =
/.*/
DEFAULT_PATCHES =
%i[redis puma http].freeze
APP_DIRS_PATTERN =
/(bin|exe|app|config|lib|test|spec)/
DEFAULT_PROFILES_SAMPLE_INTERVAL =

101 Hz in microseconds

1e6 / 101

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Configuration

Returns a new instance of Configuration.

Yields:

  • (_self)

Yield Parameters:



508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/sentry/configuration.rb', line 508

def initialize
  run_callbacks(:before, :initialize)

  self.app_dirs_pattern = APP_DIRS_PATTERN
  self.debug = Sentry::Utils::EnvHelper.env_to_bool(ENV["SENTRY_DEBUG"])
  self.background_worker_threads = (processor_count / 2.0).ceil
  self.background_worker_max_queue = BackgroundWorker::DEFAULT_MAX_QUEUE
  self.backtrace_cleanup_callback = nil
  self.strip_backtrace_load_path = true
  self.max_breadcrumbs = BreadcrumbBuffer::DEFAULT_SIZE
  self.breadcrumbs_logger = []
  self.context_lines = 3
  self.include_local_variables = false
  self.environment = environment_from_env
  self.enabled_environments = nil
  self.exclude_loggers = []
  self.excluded_exceptions = IGNORE_DEFAULT + PUMA_IGNORE_DEFAULT
  self.inspect_exception_causes_for_exclusion = true
  self.linecache = ::Sentry::LineCache.new
  self.sdk_logger = ::Sentry::Logger.new(STDOUT)
  self.project_root = Dir.pwd
  self.propagate_traces = true

  self.sample_rate = 1.0
  self.send_modules = true
  self.send_default_pii = false
  self.skip_rake_integration = false
  self.send_client_reports = true
  self.auto_session_tracking = true
  self.enable_backpressure_handling = false
  self.trusted_proxies = []
  self.dsn = ENV["SENTRY_DSN"]
  self.capture_queue_time = true
  self.org_id = nil
  self.strict_trace_continuation = false

  spotlight_env = ENV["SENTRY_SPOTLIGHT"]
  spotlight_bool = Sentry::Utils::EnvHelper.env_to_bool(spotlight_env, strict: true)
  self.spotlight = spotlight_bool.nil? ? (spotlight_env || false) : spotlight_bool
  self.server_name = server_name_from_env
  self.instrumenter = :sentry
  self.trace_propagation_targets = [PROPAGATION_TARGETS_MATCH_ALL]
  self.trace_ignore_status_codes = TRACE_IGNORE_STATUS_CODES_DEFAULT
  self.enabled_patches = DEFAULT_PATCHES.dup

  self.before_send = nil
  self.before_send_transaction = nil
  self.before_send_check_in = nil
  self.before_send_log = nil
  self.before_send_metric = nil
  self.std_lib_logger_filter = nil
  self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT
  self.traces_sampler = nil
  self.enable_logs = false
  self.enable_metrics = true

  self.profiler_class = Sentry::Profiler
  self.profiles_sample_interval = DEFAULT_PROFILES_SAMPLE_INTERVAL

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

  self.max_log_events = LogEventBuffer::DEFAULT_MAX_EVENTS
  self.max_metric_events = MetricEventBuffer::DEFAULT_MAX_METRICS

  run_callbacks(:after, :initialize)

  yield(self) if block_given?

  run_callbacks(:after, :configured)
end

Instance Attribute Details

#app_dirs_patternRegexp?

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

The default is value is /(bin|exe|app|config|lib|test|spec)/

Returns:

  • (Regexp, nil)


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

def app_dirs_pattern
  @app_dirs_pattern
end

#auto_session_trackingBoolean

Track sessions in request/response cycles automatically

Returns:

  • (Boolean)


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

def auto_session_tracking
  @auto_session_tracking
end

#background_worker_max_queueInteger

The maximum queue size for the background worker. Jobs will be rejected above this limit.

Default is BackgroundWorker::DEFAULT_MAX_QUEUE.

Returns:

  • (Integer)


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

def background_worker_max_queue
  @background_worker_max_queue
end

#background_worker_threadsInteger

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

Returns:

  • (Integer)


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

def background_worker_threads
  @background_worker_threads
end

#backtrace_cleanup_callbackProc?

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

Examples:

config.backtrace_cleanup_callback = lambda do |backtrace|
  Rails.backtrace_cleaner.clean(backtrace)
end

Returns:

  • (Proc, nil)


61
62
63
# File 'lib/sentry/configuration.rb', line 61

def backtrace_cleanup_callback
  @backtrace_cleanup_callback
end

#before_breadcrumbProc

Optional Proc, called before adding the breadcrumb to the current scope

Examples:

config.before = lambda do |breadcrumb, hint|
  breadcrumb.message = 'a'
  breadcrumb
end

Returns:

  • (Proc)


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

def before_breadcrumb
  @before_breadcrumb
end

#before_sendProc

Optional Proc, called before sending an error event to the server

Examples:

config.before_send = lambda do |event, hint|
  # skip ZeroDivisionError exceptions
  if hint[:exception].is_a?(ZeroDivisionError)
    nil
  else
    event
  end
end

Returns:

  • (Proc)


83
84
85
# File 'lib/sentry/configuration.rb', line 83

def before_send
  @before_send
end

#before_send_check_inProc

Optional Proc, called before sending a check-in event to the server

Examples:

config.before_send_check_in = lambda do |event, hint|
  if event.monitor_slug == "unimportant_job"
    nil
  else
    event
  end
end

Returns:

  • (Proc)


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

def before_send_check_in
  @before_send_check_in
end

#before_send_logProc

Optional Proc, called before sending an event to the server

Examples:

config.before_send_log = lambda do |log|
  log.attributes["sentry"] = true
  log
end

Returns:

  • (Proc)


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

def before_send_log
  @before_send_log
end

#before_send_metricProc?

Optional Proc, called before sending a metric

Examples:

config.before_send_metric = lambda do |metric|
  # return nil to drop the metric
  metric
end

Returns:

  • (Proc, nil)


363
364
365
# File 'lib/sentry/configuration.rb', line 363

def before_send_metric
  @before_send_metric
end

#before_send_transactionProc

Optional Proc, called before sending a transaction event to the server

Examples:

config.before_send_transaction = lambda do |event, hint|
  # skip unimportant transactions or strip sensitive data
  if event.transaction == "/healthcheck/route"
    nil
  else
    event
  end
end

Returns:

  • (Proc)


96
97
98
# File 'lib/sentry/configuration.rb', line 96

def before_send_transaction
  @before_send_transaction
end

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

  • :sentry_logger

  • :http_logger

  • :redis_logger

And if you also use sentry-rails:

  • :active_support_logger

Returns:

  • (Array<Symbol>)


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

def breadcrumbs_logger
  @breadcrumbs_logger
end

#capture_queue_timeBoolean

Capture queue time from X-Request-Start header set by reverse proxies. Works with any Rack app behind Nginx, HAProxy, Heroku router, etc. Defaults to true.

Returns:

  • (Boolean)


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

def capture_queue_time
  @capture_queue_time
end

#context_linesInteger?

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

Returns:

  • (Integer, nil)


136
137
138
# File 'lib/sentry/configuration.rb', line 136

def context_lines
  @context_lines
end

#cronCron::Configuration (readonly)

Cron related configuration.

Returns:



260
261
262
# File 'lib/sentry/configuration.rb', line 260

def cron
  @cron
end

#debugBoolean

Whether the SDK should run in the debugging mode. Default is false. If set to true, SDK errors will be logged with backtrace

Returns:

  • (Boolean)


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

def debug
  @debug
end

#dsnString

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

Returns:

  • (String)


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

def dsn
  @dsn
end

#enable_backpressure_handlingBoolean

Whether to downsample transactions automatically because of backpressure. Starts a new monitor thread to check health of the SDK every 10 seconds. Default is false

Returns:

  • (Boolean)


297
298
299
# File 'lib/sentry/configuration.rb', line 297

def enable_backpressure_handling
  @enable_backpressure_handling
end

#enable_logsBoolean

Enable Structured Logging

Returns:

  • (Boolean)


278
279
280
# File 'lib/sentry/configuration.rb', line 278

def enable_logs
  @enable_logs
end

#enable_metricsBoolean

Enable metrics collection, defaults to true

Returns:

  • (Boolean)


350
351
352
# File 'lib/sentry/configuration.rb', line 350

def enable_metrics
  @enable_metrics
end

#enabled_environmentsArray<String>?

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

Returns:

  • (Array<String>, nil)


153
154
155
# File 'lib/sentry/configuration.rb', line 153

def enabled_environments
  @enabled_environments
end

#enabled_patchesArray<Symbol>

Array of patches to apply. Default is DEFAULT_PATCHES

Returns:

  • (Array<Symbol>)


342
343
344
# File 'lib/sentry/configuration.rb', line 342

def enabled_patches
  @enabled_patches
end

#environmentString

RACK_ENV by default.

Returns:

  • (String)


140
141
142
# File 'lib/sentry/configuration.rb', line 140

def environment
  @environment
end

#exclude_loggersArray<String>

Logger ‘progname’s to exclude from breadcrumbs

Returns:

  • (Array<String>)


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

def exclude_loggers
  @exclude_loggers
end

#excluded_exceptionsArray<String>

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

Returns:

  • (Array<String>)


162
163
164
# File 'lib/sentry/configuration.rb', line 162

def excluded_exceptions
  @excluded_exceptions
end

#include_local_variablesBoolean

Whether to capture local variables from the raised exception’s frame. Default is false.

Returns:

  • (Boolean)


171
172
173
# File 'lib/sentry/configuration.rb', line 171

def include_local_variables
  @include_local_variables
end

#inspect_exception_causes_for_exclusionBoolean Also known as: inspect_exception_causes_for_exclusion?

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

Returns:

  • (Boolean)


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

def inspect_exception_causes_for_exclusion
  @inspect_exception_causes_for_exclusion
end

#instrumenterSymbol

The instrumenter to use, :sentry or :otel

Returns:

  • (Symbol)


318
319
320
# File 'lib/sentry/configuration.rb', line 318

def instrumenter
  @instrumenter
end

#linecacheLineCache

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.

Returns:

See Also:



185
186
187
# File 'lib/sentry/configuration.rb', line 185

def linecache
  @linecache
end

#max_breadcrumbsInteger

Max number of breadcrumbs a breadcrumb buffer can hold

Returns:

  • (Integer)


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

def max_breadcrumbs
  @max_breadcrumbs
end

#max_log_eventsInteger

Maximum number of log events to buffer before sending

Returns:

  • (Integer)


346
347
348
# File 'lib/sentry/configuration.rb', line 346

def max_log_events
  @max_log_events
end

#max_metric_eventsInteger

Maximum number of metric events to buffer before sending

Returns:

  • (Integer)


354
355
356
# File 'lib/sentry/configuration.rb', line 354

def max_metric_events
  @max_metric_events
end

#org_idString?

An optional organization ID. The SDK will try to extract it from the DSN in most cases but you can provide it explicitly for self-hosted and Relay setups. This value is used for trace propagation and for features like strict_trace_continuation.

Returns:

  • (String, nil)


378
379
380
# File 'lib/sentry/configuration.rb', line 378

def org_id
  @org_id
end

#profiler_classClass

The profiler class

Returns:

  • (Class)


322
323
324
# File 'lib/sentry/configuration.rb', line 322

def profiler_class
  @profiler_class
end

#profiles_sample_intervalFloat

Interval in microseconds at which to take samples. The default is 1e6 / 101, or 101Hz. Note that the 101 is intentional to avoid lockstep sampling.

Examples:

config.profiles_sample_interval = 1e5 / 101

Returns:

  • (Float)


337
338
339
# File 'lib/sentry/configuration.rb', line 337

def profiles_sample_interval
  @profiles_sample_interval
end

#profiles_sample_rateFloat?

Take a float between 0.0 and 1.0 as the sample rate for capturing profiles. Note that this rate is relative to traces_sample_rate / traces_sampler, i.e. the profile is sampled by this rate after the transaction is sampled.

Returns:

  • (Float, nil)


328
329
330
# File 'lib/sentry/configuration.rb', line 328

def profiles_sample_rate
  @profiles_sample_rate
end

#project_rootString

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

Returns:

  • (String)


200
201
202
# File 'lib/sentry/configuration.rb', line 200

def project_root
  @project_root
end

#propagate_tracesBoolean

Insert sentry-trace to outgoing requests’ headers

Returns:

  • (Boolean)


209
210
211
# File 'lib/sentry/configuration.rb', line 209

def propagate_traces
  @propagate_traces
end

#rack_env_whitelistArray<String>

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

Returns:

  • (Array<String>)


213
214
215
# File 'lib/sentry/configuration.rb', line 213

def rack_env_whitelist
  @rack_env_whitelist
end

#releaseString

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

Returns:

  • (String)


218
219
220
# File 'lib/sentry/configuration.rb', line 218

def release
  @release
end

#sample_rateFloat

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.

Returns:

  • (Float)


223
224
225
# File 'lib/sentry/configuration.rb', line 223

def sample_rate
  @sample_rate
end

#sdk_debug_transport_log_fileString?

File path for DebugTransport to log events to. If not set, defaults to a temporary file. This is useful for debugging and testing purposes.

Returns:

  • (String, nil)


195
196
197
# File 'lib/sentry/configuration.rb', line 195

def sdk_debug_transport_log_file
  @sdk_debug_transport_log_file
end

#sdk_loggerLogger

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

Returns:



190
191
192
# File 'lib/sentry/configuration.rb', line 190

def sdk_logger
  @sdk_logger
end

#send_client_reportsBoolean

Send diagnostic client reports about dropped events, true by default tries to attach to an existing envelope max once every 30s

Returns:

  • (Boolean)


287
288
289
# File 'lib/sentry/configuration.rb', line 287

def send_client_reports
  @send_client_reports
end

#send_default_piiBoolean

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

  • user ip

  • user cookie

  • request body

  • query string

will not be sent to Sentry.

Returns:

  • (Boolean)


236
237
238
# File 'lib/sentry/configuration.rb', line 236

def send_default_pii
  @send_default_pii
end

#send_modulesBoolean

Include module versions in reports - boolean.

Returns:

  • (Boolean)


227
228
229
# File 'lib/sentry/configuration.rb', line 227

def send_modules
  @send_modules
end

#server_nameString

Returns:

  • (String)


252
253
254
# File 'lib/sentry/configuration.rb', line 252

def server_name
  @server_name
end

#skip_rake_integrationBoolean

Allow to skip Sentry emails within rake tasks

Returns:

  • (Boolean)


246
247
248
# File 'lib/sentry/configuration.rb', line 246

def skip_rake_integration
  @skip_rake_integration
end

#spotlightBoolean, String

Whether to capture events and traces into Spotlight. Default is false. If you set this to true, Sentry will send events and traces to the local Sidecar proxy at localhost:8969/stream. If you want to use a different Sidecar proxy address, set this to String with the proxy URL.

Returns:

  • (Boolean, String)


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

def spotlight
  @spotlight
end

#std_lib_logger_filterProc?

Optional Proc, called to filter log messages before sending to Sentry

Examples:

config.std_lib_logger_filter = lambda do |logger, message, level|
  # Only send error and fatal logs to Sentry
  [:error, :fatal].include?(level)
end

Returns:

  • (Proc, nil)


372
373
374
# File 'lib/sentry/configuration.rb', line 372

def std_lib_logger_filter
  @std_lib_logger_filter
end

#strict_trace_continuationBoolean

If set to true, the SDK will only continue a trace if the org_id of the incoming trace found in the baggage header matches the org_id of the current Sentry client and only if BOTH are present.

If set to false, consistency of org_id will only be enforced if both are present. If either are missing, the trace will be continued.

The client’s organization ID is extracted from the DSN or can be set with the org_id option. If the organization IDs do not match, the SDK will start a new trace instead of continuing the incoming one. This is useful to prevent traces of unknown third-party services from being continued in your application.

Returns:

  • (Boolean)


390
391
392
# File 'lib/sentry/configuration.rb', line 390

def strict_trace_continuation
  @strict_trace_continuation
end

#strip_backtrace_load_pathBoolean

Whether to strip the load path while constructing the backtrace frame filename. Defaults to true.

Returns:

  • (Boolean)


205
206
207
# File 'lib/sentry/configuration.rb', line 205

def strip_backtrace_load_path
  @strip_backtrace_load_path
end

#structured_loggingStructuredLoggingConfiguration (readonly)

Structured logging configuration.



282
283
284
# File 'lib/sentry/configuration.rb', line 282

def structured_logging
  @structured_logging
end

#trace_ignore_status_codesArray<Integer>, Array<Range>

Collection of HTTP status codes or ranges of codes to ignore when tracing incoming requests. If a transaction’s http.response.status_code matches one of these values, the transaction will be dropped and marked as not sampled. Defaults to TRACE_IGNORE_STATUS_CODES_DEFAULT.

Examples:

# ignore 404 and 502 <= status_code <= 511
config.trace_ignore_status_codes = [404, (502..511)]

Returns:

  • (Array<Integer>, Array<Range>)


314
315
316
# File 'lib/sentry/configuration.rb', line 314

def trace_ignore_status_codes
  @trace_ignore_status_codes
end

#trace_propagation_targetsArray<String, Regexp>

Allowlist of outgoing request targets to which sentry-trace and baggage headers are attached. Default is all (/.*/)

Returns:

  • (Array<String, Regexp>)


302
303
304
# File 'lib/sentry/configuration.rb', line 302

def trace_propagation_targets
  @trace_propagation_targets
end

#traces_sample_rateFloat?

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

Returns:

  • (Float, nil)


264
265
266
# File 'lib/sentry/configuration.rb', line 264

def traces_sample_rate
  @traces_sample_rate
end

#traces_samplerProc

Take a Proc that controls the sample rate for every tracing event, e.g.

Examples:

config.traces_sampler =  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

Returns:

  • (Proc)


274
275
276
# File 'lib/sentry/configuration.rb', line 274

def traces_sampler
  @traces_sampler
end

#transportTransport::Configuration (readonly)

Transport related configuration.



256
257
258
# File 'lib/sentry/configuration.rb', line 256

def transport
  @transport
end

#trusted_proxiesObject

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



249
250
251
# File 'lib/sentry/configuration.rb', line 249

def trusted_proxies
  @trusted_proxies
end

Class Method Details

.add_post_initialization_callback(&block) ⇒ Object

allow extensions to add their hooks to the Configuration class



448
449
450
# File 'lib/sentry/configuration.rb', line 448

def add_post_initialization_callback(&block)
  callbacks[:initialize][:after] << block
end

.after(event, &block) ⇒ Object



456
457
458
# File 'lib/sentry/configuration.rb', line 456

def after(event, &block)
  callbacks[event.to_sym][:after] << block
end

.before(event, &block) ⇒ Object



452
453
454
# File 'lib/sentry/configuration.rb', line 452

def before(event, &block)
  callbacks[event.to_sym][:before] << block
end

.post_initialization_callbacksObject

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



443
444
445
# File 'lib/sentry/configuration.rb', line 443

def post_initialization_callbacks
  @post_initialization_callbacks ||= []
end

.validate(attribute, optional: false, type: nil) ⇒ Object



472
473
474
475
476
477
478
# File 'lib/sentry/configuration.rb', line 472

def validate(attribute, optional: false, type: nil)
  validations[attribute] = {
    optional: optional,
    type: type,
    proc: build_validation_proc(optional, type)
  }
end

.validationsObject



468
469
470
# File 'lib/sentry/configuration.rb', line 468

def validations
  @validations ||= {}
end

Instance Method Details

#csp_report_uriString?

Returns:

  • (String, nil)


761
762
763
764
765
766
767
768
# File 'lib/sentry/configuration.rb', line 761

def csp_report_uri
  if dsn && dsn.valid?
    uri = dsn.csp_report_uri
    uri += "&sentry_release=#{CGI.escape(release)}" if release && !release.empty?
    uri += "&sentry_environment=#{CGI.escape(environment)}" if environment && !environment.empty?
    uri
  end
end

#detect_releaseObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



783
784
785
786
787
788
789
790
791
792
793
# File 'lib/sentry/configuration.rb', line 783

def detect_release
  return unless sending_allowed?

  @release ||= ReleaseDetector.detect_release(project_root: project_root, running_on_heroku: running_on_heroku?)

  if running_on_heroku? && release.nil?
    log_warn(HEROKU_DYNO_METADATA_MESSAGE)
  end
rescue => e
  log_error("Error detecting release", e, debug: debug)
end

#effective_org_idString?

Returns the effective org ID, preferring the explicit config option over the DSN-parsed value.

Returns:

  • (String, nil)


702
703
704
# File 'lib/sentry/configuration.rb', line 702

def effective_org_id
  org_id || dsn&.org_id
end

#enabled_in_current_env?Boolean

Returns:

  • (Boolean)


739
740
741
# File 'lib/sentry/configuration.rb', line 739

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

#error_messagesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



796
797
798
799
# File 'lib/sentry/configuration.rb', line 796

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)


726
727
728
729
730
731
732
733
734
735
736
737
# File 'lib/sentry/configuration.rb', line 726

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

#profiling_enabled?Boolean

Returns:

  • (Boolean)


754
755
756
757
758
# File 'lib/sentry/configuration.rb', line 754

def profiling_enabled?
  valid_sampler = !!(valid_sample_rate?(@profiles_sample_rate))

  tracing_enabled? && valid_sampler && sending_allowed?
end

#sample_allowed?Boolean

Returns:

  • (Boolean)


716
717
718
719
720
# File 'lib/sentry/configuration.rb', line 716

def sample_allowed?
  return true if sample_rate == 1.0

  Random.rand < sample_rate
end

#sending_allowed?Boolean

Returns:

  • (Boolean)


706
707
708
# File 'lib/sentry/configuration.rb', line 706

def sending_allowed?
  spotlight || sending_to_dsn_allowed?
end

#sending_to_dsn_allowed?Boolean

Returns:

  • (Boolean)


710
711
712
713
714
# File 'lib/sentry/configuration.rb', line 710

def sending_to_dsn_allowed?
  @errors = []

  valid? && capture_in_environment?
end

#session_tracking?Boolean

Returns:

  • (Boolean)


722
723
724
# File 'lib/sentry/configuration.rb', line 722

def session_tracking?
  auto_session_tracking && enabled_in_current_env?
end

#stacktrace_builderObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



771
772
773
774
775
776
777
778
779
780
# File 'lib/sentry/configuration.rb', line 771

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,
    strip_backtrace_load_path: @strip_backtrace_load_path
  )
end

#tracing_enabled?Boolean

Returns:

  • (Boolean)


748
749
750
751
752
# File 'lib/sentry/configuration.rb', line 748

def tracing_enabled?
  valid_sampler = !!((valid_sample_rate?(@traces_sample_rate)) || @traces_sampler)

  valid_sampler && sending_allowed?
end

#valid_sample_rate?(sample_rate) ⇒ Boolean

Returns:

  • (Boolean)


743
744
745
746
# File 'lib/sentry/configuration.rb', line 743

def valid_sample_rate?(sample_rate)
  return false unless sample_rate.is_a?(Numeric)
  sample_rate >= 0.0 && sample_rate <= 1.0
end

#validateObject



582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
# File 'lib/sentry/configuration.rb', line 582

def validate
  if profiler_class == Sentry::Profiler && profiles_sample_rate && !Sentry.dependency_installed?(:StackProf)
    log_warn("Please add the 'stackprof' gem to your Gemfile to use the StackProf profiler with Sentry.")
  end

  if profiler_class == Sentry::Vernier::Profiler && profiles_sample_rate && !Sentry.dependency_installed?(:Vernier)
    log_warn("Please add the 'vernier' gem to your Gemfile to use the Vernier profiler with Sentry.")
  end

  self.class.validations.each do |attribute, validation|
    value = public_send(attribute)

    next if (result = validation[:proc].call(value)) === true

    raise ArgumentError, result[:error]
  end
end