Class: Sentry::Configuration
- Inherits:
-
Object
- Object
- Sentry::Configuration
- Includes:
- ArgumentCheckingHelper, CustomInspection, LoggingHelper
- Defined in:
- lib/sentry/configuration.rb
Constant Summary collapse
- PUMA_IGNORE_DEFAULT =
These exceptions could enter Puma's
lowlevel_error_handlercallback and the SDK's Puma integration But they are mostly considered as noise and should be ignored by default Please see https://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
- 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
- SKIP_INSPECTION_ATTRIBUTES =
[:@linecache, :@stacktrace_builder]
- INSTRUMENTERS =
[:sentry, :otel]
Instance Attribute Summary collapse
-
#app_dirs_pattern ⇒ Regexp?
Directories to be recognized as part of your app.
-
#async ⇒ Proc?
deprecated
Deprecated.
It will be removed in the next major release. Please read https://github.com/getsentry/sentry-ruby/issues/1522 for more information
-
#auto_session_tracking ⇒ Boolean
Track sessions in request/response cycles automatically.
-
#background_worker_threads ⇒ Integer
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.
-
#backtrace_cleanup_callback ⇒ Proc?
a proc/lambda that takes an array of stack traces it'll be used to silence (reduce) backtrace of the exception.
-
#before_breadcrumb ⇒ Proc
Optional Proc, called before adding the breadcrumb to the current scope.
-
#before_send ⇒ Proc
Optional Proc, called before sending an event to the server.
-
#before_send_transaction ⇒ Proc
Optional Proc, called before sending an event to the server.
-
#breadcrumbs_logger ⇒ Array<Symbol>
An array of breadcrumbs loggers to be used.
-
#context_lines ⇒ Integer?
Number of lines of code context to capture, or nil for none.
-
#debug ⇒ Boolean
Whether the SDK should run in the debugging mode.
-
#dsn ⇒ String
the dsn value, whether it's set via
config.dsn=orENV["SENTRY_DSN"]. -
#enable_tracing ⇒ Boolean?
Easier way to use performance tracing If set to true, will set traces_sample_rate to 1.0.
-
#enabled_environments ⇒ Array<String>
Whitelist of enabled_environments that will send notifications to Sentry.
-
#environment ⇒ String
RACK_ENV by default.
-
#exclude_loggers ⇒ Array<String>
Logger 'progname's to exclude from breadcrumbs.
-
#excluded_exceptions ⇒ Array<String>
Array of exception classes that should never be sent.
-
#include_local_variables ⇒ Boolean
(also: #capture_exception_frame_locals)
Whether to capture local variables from the raised exception's frame.
-
#inspect_exception_causes_for_exclusion ⇒ Boolean
(also: #inspect_exception_causes_for_exclusion?)
Boolean to check nested exceptions when deciding if to exclude.
-
#instrumenter ⇒ Symbol
The instrumenter to use, :sentry or :otel.
-
#linecache ⇒ LineCache
You may provide your own LineCache for matching paths with source files.
-
#logger ⇒ Logger
Logger used by Sentry.
-
#max_breadcrumbs ⇒ Integer
Max number of breadcrumbs a breadcrumb buffer can hold.
-
#profiles_sample_rate ⇒ Float?
Take a float between 0.0 and 1.0 as the sample rate for capturing profiles.
-
#project_root ⇒ String
Project directory root for in_app detection.
-
#propagate_traces ⇒ Boolean
Insert sentry-trace to outgoing requests' headers.
-
#rack_env_whitelist ⇒ Array<String>
Array of rack env parameters to be included in the event sent to sentry.
-
#release ⇒ String
Release tag to be passed with every event sent to Sentry.
-
#sample_rate ⇒ Float
The sampling factor to apply to events.
-
#send_client_reports ⇒ Boolean
Send diagnostic client reports about dropped events, true by default tries to attach to an existing envelope max once every 30s.
-
#send_default_pii ⇒ Boolean
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.
-
#send_modules ⇒ Boolean
Include module versions in reports - boolean.
- #server_name ⇒ String
-
#skip_rake_integration ⇒ Boolean
Allow to skip Sentry emails within rake tasks.
-
#traces_sample_rate ⇒ Float?
Take a float between 0.0 and 1.0 as the sample rate for tracing events (transactions).
-
#traces_sampler ⇒ Proc
Take a Proc that controls the sample rate for every tracing event, e.g.
-
#transport ⇒ Transport
readonly
Return a Transport::Configuration object for transport-related configurations.
-
#trusted_proxies ⇒ Object
IP ranges for trusted proxies that will be skipped when calculating IP address.
Class Method Summary collapse
-
.add_post_initialization_callback(&block) ⇒ Object
allow extensions to add their hooks to the Configuration class.
-
.post_initialization_callbacks ⇒ Object
Post initialization callbacks are called at the end of initialization process allowing extending the configuration of sentry-ruby by multiple extensions.
Instance Method Summary collapse
-
#capture_exception_frame_locals=(value) ⇒ Object
deprecated
Deprecated.
Use #include_local_variables= instead.
- #csp_report_uri ⇒ String?
- #detect_release ⇒ Object private
- #enabled_in_current_env? ⇒ Boolean
- #error_messages ⇒ Object private
- #exception_class_allowed?(exc) ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #is_numeric_or_nil?(value) ⇒ Boolean
- #profiling_enabled? ⇒ Boolean
- #sample_allowed? ⇒ Boolean
- #sending_allowed? ⇒ Boolean
- #stacktrace_builder ⇒ Object private
- #tracing_enabled? ⇒ Boolean
- #valid_sample_rate?(sample_rate) ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/sentry/configuration.rb', line 306 def initialize self.app_dirs_pattern = nil self.debug = false self.background_worker_threads = Concurrent.processor_count self.backtrace_cleanup_callback = nil self. = BreadcrumbBuffer::DEFAULT_SIZE self. = [] self.context_lines = 3 self.include_local_variables = false self.environment = environment_from_env self.enabled_environments = [] self.exclude_loggers = [] self.excluded_exceptions = IGNORE_DEFAULT + PUMA_IGNORE_DEFAULT self.inspect_exception_causes_for_exclusion = true self.linecache = ::Sentry::LineCache.new self.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.trusted_proxies = [] self.dsn = ENV['SENTRY_DSN'] self.server_name = server_name_from_env self.instrumenter = :sentry self.before_send = nil self.before_send_transaction = nil self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT self.traces_sampler = nil self.enable_tracing = nil @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_pattern ⇒ Regexp?
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)/
24 25 26 |
# File 'lib/sentry/configuration.rb', line 24 def app_dirs_pattern @app_dirs_pattern end |
#async ⇒ Proc?
It will be removed in the next major release. Please read https://github.com/getsentry/sentry-ruby/issues/1522 for more information
Provide an object that responds to call to send events asynchronously.
E.g.: lambda { |event| Thread.new { Sentry.send_event(event) } }
31 32 33 |
# File 'lib/sentry/configuration.rb', line 31 def async @async end |
#auto_session_tracking ⇒ Boolean
Track sessions in request/response cycles automatically
244 245 246 |
# File 'lib/sentry/configuration.rb', line 244 def auto_session_tracking @auto_session_tracking end |
#background_worker_threads ⇒ Integer
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
41 42 43 |
# File 'lib/sentry/configuration.rb', line 41 def background_worker_threads @background_worker_threads end |
#backtrace_cleanup_callback ⇒ Proc?
a proc/lambda that takes an array of stack traces it'll be used to silence (reduce) backtrace of the exception
52 53 54 |
# File 'lib/sentry/configuration.rb', line 52 def backtrace_cleanup_callback @backtrace_cleanup_callback end |
#before_breadcrumb ⇒ Proc
Optional Proc, called before adding the breadcrumb to the current scope
61 62 63 |
# File 'lib/sentry/configuration.rb', line 61 def @before_breadcrumb end |
#before_send ⇒ Proc
Optional Proc, called before sending an event to the server
75 76 77 |
# File 'lib/sentry/configuration.rb', line 75 def before_send @before_send end |
#before_send_transaction ⇒ Proc
Optional Proc, called before sending an event to the server
88 89 90 |
# File 'lib/sentry/configuration.rb', line 88 def before_send_transaction @before_send_transaction end |
#breadcrumbs_logger ⇒ Array<Symbol>
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
- :monotonic_active_support_logger
100 101 102 |
# File 'lib/sentry/configuration.rb', line 100 def @breadcrumbs_logger end |
#context_lines ⇒ Integer?
Number of lines of code context to capture, or nil for none
108 109 110 |
# File 'lib/sentry/configuration.rb', line 108 def context_lines @context_lines end |
#debug ⇒ Boolean
Whether the SDK should run in the debugging mode. Default is false. If set to true, SDK errors will be logged with backtrace
117 118 119 |
# File 'lib/sentry/configuration.rb', line 117 def debug @debug end |
#dsn ⇒ String
the dsn value, whether it's set via config.dsn= or ENV["SENTRY_DSN"]
121 122 123 |
# File 'lib/sentry/configuration.rb', line 121 def dsn @dsn end |
#enable_tracing ⇒ Boolean?
Easier way to use performance tracing If set to true, will set traces_sample_rate to 1.0
235 236 237 |
# File 'lib/sentry/configuration.rb', line 235 def enable_tracing @enable_tracing end |
#enabled_environments ⇒ Array<String>
Whitelist of enabled_environments that will send notifications to Sentry. Array of Strings.
125 126 127 |
# File 'lib/sentry/configuration.rb', line 125 def enabled_environments @enabled_environments end |
#environment ⇒ String
RACK_ENV by default.
112 113 114 |
# File 'lib/sentry/configuration.rb', line 112 def environment @environment end |
#exclude_loggers ⇒ Array<String>
Logger 'progname's to exclude from breadcrumbs
129 130 131 |
# File 'lib/sentry/configuration.rb', line 129 def exclude_loggers @exclude_loggers end |
#excluded_exceptions ⇒ Array<String>
Array of exception classes that should never be sent. See IGNORE_DEFAULT. You should probably append to this rather than overwrite it.
134 135 136 |
# File 'lib/sentry/configuration.rb', line 134 def excluded_exceptions @excluded_exceptions end |
#include_local_variables ⇒ Boolean Also known as: capture_exception_frame_locals
Whether to capture local variables from the raised exception's frame. Default is false.
143 144 145 |
# File 'lib/sentry/configuration.rb', line 143 def include_local_variables @include_local_variables end |
#inspect_exception_causes_for_exclusion ⇒ Boolean Also known as: inspect_exception_causes_for_exclusion?
Boolean to check nested exceptions when deciding if to exclude. Defaults to true
138 139 140 |
# File 'lib/sentry/configuration.rb', line 138 def inspect_exception_causes_for_exclusion @inspect_exception_causes_for_exclusion end |
#instrumenter ⇒ Symbol
The instrumenter to use, :sentry or :otel
248 249 250 |
# File 'lib/sentry/configuration.rb', line 248 def instrumenter @instrumenter end |
#linecache ⇒ LineCache
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.
161 162 163 |
# File 'lib/sentry/configuration.rb', line 161 def linecache @linecache end |
#logger ⇒ Logger
Logger used by Sentry. In Rails, this is the Rails logger, otherwise Sentry provides its own Sentry::Logger.
166 167 168 |
# File 'lib/sentry/configuration.rb', line 166 def logger @logger end |
#max_breadcrumbs ⇒ Integer
Max number of breadcrumbs a breadcrumb buffer can hold
104 105 106 |
# File 'lib/sentry/configuration.rb', line 104 def @max_breadcrumbs end |
#profiles_sample_rate ⇒ Float?
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.
254 255 256 |
# File 'lib/sentry/configuration.rb', line 254 def profiles_sample_rate @profiles_sample_rate end |
#project_root ⇒ String
Project directory root for in_app detection. Could be Rails root, etc. Set automatically for Rails.
171 172 173 |
# File 'lib/sentry/configuration.rb', line 171 def project_root @project_root end |
#propagate_traces ⇒ Boolean
Insert sentry-trace to outgoing requests' headers
175 176 177 |
# File 'lib/sentry/configuration.rb', line 175 def propagate_traces @propagate_traces end |
#rack_env_whitelist ⇒ Array<String>
Array of rack env parameters to be included in the event sent to sentry.
179 180 181 |
# File 'lib/sentry/configuration.rb', line 179 def rack_env_whitelist @rack_env_whitelist end |
#release ⇒ String
Release tag to be passed with every event sent to Sentry. We automatically try to set this to a git SHA or Capistrano release.
184 185 186 |
# File 'lib/sentry/configuration.rb', line 184 def release @release end |
#sample_rate ⇒ Float
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.
189 190 191 |
# File 'lib/sentry/configuration.rb', line 189 def sample_rate @sample_rate end |
#send_client_reports ⇒ Boolean
Send diagnostic client reports about dropped events, true by default tries to attach to an existing envelope max once every 30s
240 241 242 |
# File 'lib/sentry/configuration.rb', line 240 def send_client_reports @send_client_reports end |
#send_default_pii ⇒ Boolean
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.
202 203 204 |
# File 'lib/sentry/configuration.rb', line 202 def send_default_pii @send_default_pii end |
#send_modules ⇒ Boolean
Include module versions in reports - boolean.
193 194 195 |
# File 'lib/sentry/configuration.rb', line 193 def send_modules @send_modules end |
#server_name ⇒ String
212 213 214 |
# File 'lib/sentry/configuration.rb', line 212 def server_name @server_name end |
#skip_rake_integration ⇒ Boolean
Allow to skip Sentry emails within rake tasks
206 207 208 |
# File 'lib/sentry/configuration.rb', line 206 def skip_rake_integration @skip_rake_integration end |
#traces_sample_rate ⇒ Float?
Take a float between 0.0 and 1.0 as the sample rate for tracing events (transactions).
220 221 222 |
# File 'lib/sentry/configuration.rb', line 220 def traces_sample_rate @traces_sample_rate end |
#traces_sampler ⇒ Proc
Take a Proc that controls the sample rate for every tracing event, e.g.
230 231 232 |
# File 'lib/sentry/configuration.rb', line 230 def traces_sampler @traces_sampler end |
#transport ⇒ Transport (readonly)
Return a Transport::Configuration object for transport-related configurations.
216 217 218 |
# File 'lib/sentry/configuration.rb', line 216 def transport @transport end |
#trusted_proxies ⇒ Object
IP ranges for trusted proxies that will be skipped when calculating IP address.
209 210 211 |
# File 'lib/sentry/configuration.rb', line 209 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
301 302 303 |
# File 'lib/sentry/configuration.rb', line 301 def add_post_initialization_callback(&block) post_initialization_callbacks << block end |
.post_initialization_callbacks ⇒ Object
Post initialization callbacks are called at the end of initialization process allowing extending the configuration of sentry-ruby by multiple extensions
296 297 298 |
# File 'lib/sentry/configuration.rb', line 296 def post_initialization_callbacks @post_initialization_callbacks ||= [] end |
Instance Method Details
#capture_exception_frame_locals=(value) ⇒ Object
Use #include_local_variables= instead.
149 150 151 152 153 154 155 |
# File 'lib/sentry/configuration.rb', line 149 def capture_exception_frame_locals=(value) log_warn <<~MSG `capture_exception_frame_locals` is now deprecated in favor of `include_local_variables`. MSG self.include_local_variables = value end |
#csp_report_uri ⇒ String?
482 483 484 485 486 487 488 489 |
# File 'lib/sentry/configuration.rb', line 482 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_release ⇒ Object
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.
503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/sentry/configuration.rb', line 503 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 |
#enabled_in_current_env? ⇒ Boolean
460 461 462 |
# File 'lib/sentry/configuration.rb', line 460 def enabled_in_current_env? enabled_environments.empty? || enabled_environments.include?(environment) end |
#error_messages ⇒ Object
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.
516 517 518 519 |
# File 'lib/sentry/configuration.rb', line 516 def @errors = [@errors[0]] + @errors[1..-1].map(&:downcase) # fix case of all but first @errors.join(", ") end |
#exception_class_allowed?(exc) ⇒ Boolean
447 448 449 450 451 452 453 454 455 456 457 458 |
# File 'lib/sentry/configuration.rb', line 447 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 |
#is_numeric_or_nil?(value) ⇒ Boolean
420 421 422 |
# File 'lib/sentry/configuration.rb', line 420 def is_numeric_or_nil?(value) value.is_a?(Numeric) || value.nil? end |
#profiling_enabled? ⇒ Boolean
475 476 477 478 479 |
# File 'lib/sentry/configuration.rb', line 475 def profiling_enabled? valid_sampler = !!(valid_sample_rate?(@profiles_sample_rate)) tracing_enabled? && valid_sampler && sending_allowed? end |
#sample_allowed? ⇒ Boolean
441 442 443 444 445 |
# File 'lib/sentry/configuration.rb', line 441 def sample_allowed? return true if sample_rate == 1.0 Random.rand < sample_rate end |
#sending_allowed? ⇒ Boolean
435 436 437 438 439 |
# File 'lib/sentry/configuration.rb', line 435 def sending_allowed? @errors = [] valid? && capture_in_environment? end |
#stacktrace_builder ⇒ Object
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.
492 493 494 495 496 497 498 499 500 |
# File 'lib/sentry/configuration.rb', line 492 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
469 470 471 472 473 |
# File 'lib/sentry/configuration.rb', line 469 def tracing_enabled? valid_sampler = !!((valid_sample_rate?(@traces_sample_rate)) || @traces_sampler) (@enable_tracing != false) && valid_sampler && sending_allowed? end |
#valid_sample_rate?(sample_rate) ⇒ Boolean
464 465 466 467 |
# File 'lib/sentry/configuration.rb', line 464 def valid_sample_rate?(sample_rate) return false unless sample_rate.is_a?(Numeric) sample_rate >= 0.0 && sample_rate <= 1.0 end |