sentry-ruby 5.28.1 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +26 -2
- data/README.md +3 -3
- data/lib/sentry/background_worker.rb +1 -4
- data/lib/sentry/backtrace/line.rb +99 -0
- data/lib/sentry/backtrace.rb +44 -76
- data/lib/sentry/baggage.rb +2 -2
- data/lib/sentry/breadcrumb.rb +1 -1
- data/lib/sentry/breadcrumb_buffer.rb +2 -2
- data/lib/sentry/check_in_event.rb +2 -2
- data/lib/sentry/client.rb +57 -135
- data/lib/sentry/configuration.rb +155 -75
- data/lib/sentry/cron/monitor_check_ins.rb +3 -3
- data/lib/sentry/cron/monitor_config.rb +2 -2
- data/lib/sentry/cron/monitor_schedule.rb +2 -2
- data/lib/sentry/dsn.rb +33 -1
- data/lib/sentry/envelope/item.rb +3 -3
- data/lib/sentry/error_event.rb +3 -3
- data/lib/sentry/event.rb +4 -10
- data/lib/sentry/exceptions.rb +3 -0
- data/lib/sentry/hub.rb +26 -4
- data/lib/sentry/interface.rb +1 -1
- data/lib/sentry/interfaces/exception.rb +2 -2
- data/lib/sentry/interfaces/request.rb +2 -0
- data/lib/sentry/interfaces/single_exception.rb +4 -4
- data/lib/sentry/interfaces/stacktrace.rb +3 -3
- data/lib/sentry/interfaces/stacktrace_builder.rb +0 -8
- data/lib/sentry/interfaces/threads.rb +2 -2
- data/lib/sentry/log_event.rb +24 -142
- data/lib/sentry/log_event_buffer.rb +13 -60
- data/lib/sentry/metric_event.rb +49 -0
- data/lib/sentry/metric_event_buffer.rb +28 -0
- data/lib/sentry/metrics.rb +47 -54
- data/lib/sentry/profiler.rb +4 -5
- data/lib/sentry/propagation_context.rb +48 -8
- data/lib/sentry/rack/capture_exceptions.rb +90 -2
- data/lib/sentry/release_detector.rb +1 -1
- data/lib/sentry/rspec.rb +1 -1
- data/lib/sentry/scope.rb +51 -18
- data/lib/sentry/sequel.rb +35 -0
- data/lib/sentry/span.rb +5 -17
- data/lib/sentry/std_lib_logger.rb +4 -0
- data/lib/sentry/telemetry_event_buffer.rb +130 -0
- data/lib/sentry/test_helper.rb +8 -0
- data/lib/sentry/transaction.rb +53 -103
- data/lib/sentry/transaction_event.rb +4 -9
- data/lib/sentry/transport/http_transport.rb +7 -11
- data/lib/sentry/transport.rb +9 -7
- data/lib/sentry/utils/encoding_helper.rb +6 -0
- data/lib/sentry/utils/logging_helper.rb +25 -9
- data/lib/sentry/utils/telemetry_attributes.rb +30 -0
- data/lib/sentry/vernier/profiler.rb +4 -3
- data/lib/sentry/version.rb +1 -1
- data/lib/sentry-ruby.rb +53 -30
- data/sentry-ruby-core.gemspec +1 -1
- data/sentry-ruby.gemspec +2 -1
- metadata +27 -16
- data/lib/sentry/metrics/aggregator.rb +0 -248
- data/lib/sentry/metrics/configuration.rb +0 -57
- data/lib/sentry/metrics/counter_metric.rb +0 -25
- data/lib/sentry/metrics/distribution_metric.rb +0 -25
- data/lib/sentry/metrics/gauge_metric.rb +0 -35
- data/lib/sentry/metrics/local_aggregator.rb +0 -53
- data/lib/sentry/metrics/metric.rb +0 -19
- data/lib/sentry/metrics/set_metric.rb +0 -28
- data/lib/sentry/metrics/timing.rb +0 -51
data/lib/sentry/configuration.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "cgi/escape"
|
|
3
4
|
require "concurrent/utility/processor_counter"
|
|
4
5
|
|
|
5
6
|
require "sentry/utils/exception_cause_chain"
|
|
@@ -9,12 +10,12 @@ require "sentry/dsn"
|
|
|
9
10
|
require "sentry/release_detector"
|
|
10
11
|
require "sentry/transport/configuration"
|
|
11
12
|
require "sentry/cron/configuration"
|
|
12
|
-
require "sentry/metrics/configuration"
|
|
13
13
|
require "sentry/linecache"
|
|
14
14
|
require "sentry/interfaces/stacktrace_builder"
|
|
15
15
|
require "sentry/logger"
|
|
16
16
|
require "sentry/structured_logger"
|
|
17
17
|
require "sentry/log_event_buffer"
|
|
18
|
+
require "sentry/metric_event_buffer"
|
|
18
19
|
|
|
19
20
|
module Sentry
|
|
20
21
|
class Configuration
|
|
@@ -31,13 +32,6 @@ module Sentry
|
|
|
31
32
|
# @return [Regexp, nil]
|
|
32
33
|
attr_accessor :app_dirs_pattern
|
|
33
34
|
|
|
34
|
-
# Provide an object that responds to `call` to send events asynchronously.
|
|
35
|
-
# E.g.: lambda { |event| Thread.new { Sentry.send_event(event) } }
|
|
36
|
-
#
|
|
37
|
-
# @deprecated It will be removed in the next major release. Please read https://github.com/getsentry/sentry-ruby/issues/1522 for more information
|
|
38
|
-
# @return [Proc, nil]
|
|
39
|
-
attr_reader :async
|
|
40
|
-
|
|
41
35
|
# to send events in a non-blocking way, sentry-ruby has its own background worker
|
|
42
36
|
# by default, the worker holds a thread pool that has [the number of processors] threads
|
|
43
37
|
# but you can configure it with this configuration option
|
|
@@ -75,11 +69,10 @@ module Sentry
|
|
|
75
69
|
# @return [Proc]
|
|
76
70
|
attr_reader :before_breadcrumb
|
|
77
71
|
|
|
78
|
-
# Optional Proc, called before sending an event to the server
|
|
72
|
+
# Optional Proc, called before sending an error event to the server
|
|
79
73
|
# @example
|
|
80
74
|
# config.before_send = lambda do |event, hint|
|
|
81
75
|
# # skip ZeroDivisionError exceptions
|
|
82
|
-
# # note: hint[:exception] would be a String if you use async callback
|
|
83
76
|
# if hint[:exception].is_a?(ZeroDivisionError)
|
|
84
77
|
# nil
|
|
85
78
|
# else
|
|
@@ -89,7 +82,7 @@ module Sentry
|
|
|
89
82
|
# @return [Proc]
|
|
90
83
|
attr_reader :before_send
|
|
91
84
|
|
|
92
|
-
# Optional Proc, called before sending
|
|
85
|
+
# Optional Proc, called before sending a transaction event to the server
|
|
93
86
|
# @example
|
|
94
87
|
# config.before_send_transaction = lambda do |event, hint|
|
|
95
88
|
# # skip unimportant transactions or strip sensitive data
|
|
@@ -102,6 +95,18 @@ module Sentry
|
|
|
102
95
|
# @return [Proc]
|
|
103
96
|
attr_reader :before_send_transaction
|
|
104
97
|
|
|
98
|
+
# Optional Proc, called before sending a check-in event to the server
|
|
99
|
+
# @example
|
|
100
|
+
# config.before_send_check_in = lambda do |event, hint|
|
|
101
|
+
# if event.monitor_slug == "unimportant_job"
|
|
102
|
+
# nil
|
|
103
|
+
# else
|
|
104
|
+
# event
|
|
105
|
+
# end
|
|
106
|
+
# end
|
|
107
|
+
# @return [Proc]
|
|
108
|
+
attr_reader :before_send_check_in
|
|
109
|
+
|
|
105
110
|
# Optional Proc, called before sending an event to the server
|
|
106
111
|
# @example
|
|
107
112
|
# config.before_send_log = lambda do |log|
|
|
@@ -118,7 +123,6 @@ module Sentry
|
|
|
118
123
|
#
|
|
119
124
|
# And if you also use sentry-rails:
|
|
120
125
|
# - :active_support_logger
|
|
121
|
-
# - :monotonic_active_support_logger
|
|
122
126
|
#
|
|
123
127
|
# @return [Array<Symbol>]
|
|
124
128
|
attr_reader :breadcrumbs_logger
|
|
@@ -145,7 +149,7 @@ module Sentry
|
|
|
145
149
|
attr_reader :dsn
|
|
146
150
|
|
|
147
151
|
# Whitelist of enabled_environments that will send notifications to Sentry. Array of Strings.
|
|
148
|
-
# @return [Array<String
|
|
152
|
+
# @return [Array<String>, nil]
|
|
149
153
|
attr_accessor :enabled_environments
|
|
150
154
|
|
|
151
155
|
# Logger 'progname's to exclude from breadcrumbs
|
|
@@ -174,18 +178,6 @@ module Sentry
|
|
|
174
178
|
# @return [Boolean, String]
|
|
175
179
|
attr_accessor :spotlight
|
|
176
180
|
|
|
177
|
-
# @deprecated Use {#include_local_variables} instead.
|
|
178
|
-
alias_method :capture_exception_frame_locals, :include_local_variables
|
|
179
|
-
|
|
180
|
-
# @deprecated Use {#include_local_variables=} instead.
|
|
181
|
-
def capture_exception_frame_locals=(value)
|
|
182
|
-
log_warn <<~MSG
|
|
183
|
-
`capture_exception_frame_locals` is now deprecated in favor of `include_local_variables`.
|
|
184
|
-
MSG
|
|
185
|
-
|
|
186
|
-
self.include_local_variables = value
|
|
187
|
-
end
|
|
188
|
-
|
|
189
181
|
# You may provide your own LineCache for matching paths with source files.
|
|
190
182
|
# This may be useful if you need to get source code from places other than the disk.
|
|
191
183
|
# @see LineCache
|
|
@@ -202,18 +194,6 @@ module Sentry
|
|
|
202
194
|
# @return [String, nil]
|
|
203
195
|
attr_accessor :sdk_debug_transport_log_file
|
|
204
196
|
|
|
205
|
-
# @deprecated Use {#sdk_logger=} instead.
|
|
206
|
-
def logger=(logger)
|
|
207
|
-
warn "[sentry] `config.logger=` is deprecated. Please use `config.sdk_logger=` instead."
|
|
208
|
-
self.sdk_logger = logger
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
# @deprecated Use {#sdk_logger} instead.
|
|
212
|
-
def logger
|
|
213
|
-
warn "[sentry] `config.logger` is deprecated. Please use `config.sdk_logger` instead."
|
|
214
|
-
self.sdk_logger
|
|
215
|
-
end
|
|
216
|
-
|
|
217
197
|
# Project directory root for in_app detection. Could be Rails root, etc.
|
|
218
198
|
# Set automatically for Rails.
|
|
219
199
|
# @return [String]
|
|
@@ -255,6 +235,12 @@ module Sentry
|
|
|
255
235
|
# @return [Boolean]
|
|
256
236
|
attr_accessor :send_default_pii
|
|
257
237
|
|
|
238
|
+
# Capture queue time from X-Request-Start header set by reverse proxies.
|
|
239
|
+
# Works with any Rack app behind Nginx, HAProxy, Heroku router, etc.
|
|
240
|
+
# Defaults to true.
|
|
241
|
+
# @return [Boolean]
|
|
242
|
+
attr_accessor :capture_queue_time
|
|
243
|
+
|
|
258
244
|
# Allow to skip Sentry emails within rake tasks
|
|
259
245
|
# @return [Boolean]
|
|
260
246
|
attr_accessor :skip_rake_integration
|
|
@@ -273,10 +259,6 @@ module Sentry
|
|
|
273
259
|
# @return [Cron::Configuration]
|
|
274
260
|
attr_reader :cron
|
|
275
261
|
|
|
276
|
-
# Metrics related configuration.
|
|
277
|
-
# @return [Metrics::Configuration]
|
|
278
|
-
attr_reader :metrics
|
|
279
|
-
|
|
280
262
|
# Take a float between 0.0 and 1.0 as the sample rate for tracing events (transactions).
|
|
281
263
|
# @return [Float, nil]
|
|
282
264
|
attr_reader :traces_sample_rate
|
|
@@ -299,12 +281,6 @@ module Sentry
|
|
|
299
281
|
# @return [StructuredLoggingConfiguration]
|
|
300
282
|
attr_reader :structured_logging
|
|
301
283
|
|
|
302
|
-
# Easier way to use performance tracing
|
|
303
|
-
# If set to true, will set traces_sample_rate to 1.0
|
|
304
|
-
# @deprecated It will be removed in the next major release.
|
|
305
|
-
# @return [Boolean, nil]
|
|
306
|
-
attr_reader :enable_tracing
|
|
307
|
-
|
|
308
284
|
# Send diagnostic client reports about dropped events, true by default
|
|
309
285
|
# tries to attach to an existing envelope max once every 30s
|
|
310
286
|
# @return [Boolean]
|
|
@@ -325,6 +301,18 @@ module Sentry
|
|
|
325
301
|
# @return [Array<String, Regexp>]
|
|
326
302
|
attr_accessor :trace_propagation_targets
|
|
327
303
|
|
|
304
|
+
# Collection of HTTP status codes or ranges of codes to ignore when tracing incoming requests.
|
|
305
|
+
# If a transaction's http.response.status_code matches one of these values,
|
|
306
|
+
# the transaction will be dropped and marked as not sampled.
|
|
307
|
+
# Defaults to TRACE_IGNORE_STATUS_CODES_DEFAULT.
|
|
308
|
+
#
|
|
309
|
+
# @example
|
|
310
|
+
# # ignore 404 and 502 <= status_code <= 511
|
|
311
|
+
# config.trace_ignore_status_codes = [404, (502..511)]
|
|
312
|
+
#
|
|
313
|
+
# @return [Array<Integer>, Array<Range>]
|
|
314
|
+
attr_reader :trace_ignore_status_codes
|
|
315
|
+
|
|
328
316
|
# The instrumenter to use, :sentry or :otel
|
|
329
317
|
# @return [Symbol]
|
|
330
318
|
attr_reader :instrumenter
|
|
@@ -339,6 +327,15 @@ module Sentry
|
|
|
339
327
|
# @return [Float, nil]
|
|
340
328
|
attr_reader :profiles_sample_rate
|
|
341
329
|
|
|
330
|
+
# Interval in microseconds at which to take samples.
|
|
331
|
+
# The default is 1e6 / 101, or 101Hz.
|
|
332
|
+
# Note that the 101 is intentional to avoid lockstep sampling.
|
|
333
|
+
#
|
|
334
|
+
# @example
|
|
335
|
+
# config.profiles_sample_interval = 1e5 / 101
|
|
336
|
+
# @return [Float]
|
|
337
|
+
attr_accessor :profiles_sample_interval
|
|
338
|
+
|
|
342
339
|
# Array of patches to apply.
|
|
343
340
|
# Default is {DEFAULT_PATCHES}
|
|
344
341
|
# @return [Array<Symbol>]
|
|
@@ -348,6 +345,50 @@ module Sentry
|
|
|
348
345
|
# @return [Integer]
|
|
349
346
|
attr_accessor :max_log_events
|
|
350
347
|
|
|
348
|
+
# Enable metrics collection, defaults to true
|
|
349
|
+
# @return [Boolean]
|
|
350
|
+
attr_accessor :enable_metrics
|
|
351
|
+
|
|
352
|
+
# Maximum number of metric events to buffer before sending
|
|
353
|
+
# @return [Integer]
|
|
354
|
+
attr_accessor :max_metric_events
|
|
355
|
+
|
|
356
|
+
# Optional Proc, called before sending a metric
|
|
357
|
+
# @example
|
|
358
|
+
# config.before_send_metric = lambda do |metric|
|
|
359
|
+
# # return nil to drop the metric
|
|
360
|
+
# metric
|
|
361
|
+
# end
|
|
362
|
+
# @return [Proc, nil]
|
|
363
|
+
attr_reader :before_send_metric
|
|
364
|
+
|
|
365
|
+
# Optional Proc, called to filter log messages before sending to Sentry
|
|
366
|
+
# @example
|
|
367
|
+
# config.std_lib_logger_filter = lambda do |logger, message, level|
|
|
368
|
+
# # Only send error and fatal logs to Sentry
|
|
369
|
+
# [:error, :fatal].include?(level)
|
|
370
|
+
# end
|
|
371
|
+
# @return [Proc, nil]
|
|
372
|
+
attr_reader :std_lib_logger_filter
|
|
373
|
+
|
|
374
|
+
# An optional organization ID. The SDK will try to extract it from the DSN in most cases
|
|
375
|
+
# but you can provide it explicitly for self-hosted and Relay setups.
|
|
376
|
+
# This value is used for trace propagation and for features like strict_trace_continuation.
|
|
377
|
+
# @return [String, nil]
|
|
378
|
+
attr_reader :org_id
|
|
379
|
+
|
|
380
|
+
# If set to true, the SDK will only continue a trace if the org_id of the incoming trace found in the
|
|
381
|
+
# baggage header matches the org_id of the current Sentry client and only if BOTH are present.
|
|
382
|
+
#
|
|
383
|
+
# If set to false, consistency of org_id will only be enforced if both are present.
|
|
384
|
+
# If either are missing, the trace will be continued.
|
|
385
|
+
#
|
|
386
|
+
# The client's organization ID is extracted from the DSN or can be set with the org_id option.
|
|
387
|
+
# If the organization IDs do not match, the SDK will start a new trace instead of continuing the incoming one.
|
|
388
|
+
# This is useful to prevent traces of unknown third-party services from being continued in your application.
|
|
389
|
+
# @return [Boolean]
|
|
390
|
+
attr_accessor :strict_trace_continuation
|
|
391
|
+
|
|
351
392
|
# these are not config options
|
|
352
393
|
# @!visibility private
|
|
353
394
|
attr_reader :errors, :gem_specs
|
|
@@ -376,6 +417,8 @@ module Sentry
|
|
|
376
417
|
SERVER_PORT
|
|
377
418
|
].freeze
|
|
378
419
|
|
|
420
|
+
TRACE_IGNORE_STATUS_CODES_DEFAULT = [(301..303), (305..399), (401..404)]
|
|
421
|
+
|
|
379
422
|
HEROKU_DYNO_METADATA_MESSAGE = "You are running on Heroku but haven't enabled Dyno Metadata. For Sentry's "\
|
|
380
423
|
"release detection to work correctly, please run `heroku labs:enable runtime-dyno-metadata`"
|
|
381
424
|
|
|
@@ -391,6 +434,9 @@ module Sentry
|
|
|
391
434
|
|
|
392
435
|
APP_DIRS_PATTERN = /(bin|exe|app|config|lib|test|spec)/
|
|
393
436
|
|
|
437
|
+
# 101 Hz in microseconds
|
|
438
|
+
DEFAULT_PROFILES_SAMPLE_INTERVAL = 1e6 / 101
|
|
439
|
+
|
|
394
440
|
class << self
|
|
395
441
|
# Post initialization callbacks are called at the end of initialization process
|
|
396
442
|
# allowing extending the configuration of sentry-ruby by multiple extensions
|
|
@@ -473,7 +519,7 @@ module Sentry
|
|
|
473
519
|
self.context_lines = 3
|
|
474
520
|
self.include_local_variables = false
|
|
475
521
|
self.environment = environment_from_env
|
|
476
|
-
self.enabled_environments =
|
|
522
|
+
self.enabled_environments = nil
|
|
477
523
|
self.exclude_loggers = []
|
|
478
524
|
self.excluded_exceptions = IGNORE_DEFAULT + PUMA_IGNORE_DEFAULT
|
|
479
525
|
self.inspect_exception_causes_for_exclusion = true
|
|
@@ -491,6 +537,9 @@ module Sentry
|
|
|
491
537
|
self.enable_backpressure_handling = false
|
|
492
538
|
self.trusted_proxies = []
|
|
493
539
|
self.dsn = ENV["SENTRY_DSN"]
|
|
540
|
+
self.capture_queue_time = true
|
|
541
|
+
self.org_id = nil
|
|
542
|
+
self.strict_trace_continuation = false
|
|
494
543
|
|
|
495
544
|
spotlight_env = ENV["SENTRY_SPOTLIGHT"]
|
|
496
545
|
spotlight_bool = Sentry::Utils::EnvHelper.env_to_bool(spotlight_env, strict: true)
|
|
@@ -498,25 +547,30 @@ module Sentry
|
|
|
498
547
|
self.server_name = server_name_from_env
|
|
499
548
|
self.instrumenter = :sentry
|
|
500
549
|
self.trace_propagation_targets = [PROPAGATION_TARGETS_MATCH_ALL]
|
|
550
|
+
self.trace_ignore_status_codes = TRACE_IGNORE_STATUS_CODES_DEFAULT
|
|
501
551
|
self.enabled_patches = DEFAULT_PATCHES.dup
|
|
502
552
|
|
|
503
553
|
self.before_send = nil
|
|
504
554
|
self.before_send_transaction = nil
|
|
555
|
+
self.before_send_check_in = nil
|
|
505
556
|
self.before_send_log = nil
|
|
557
|
+
self.before_send_metric = nil
|
|
558
|
+
self.std_lib_logger_filter = nil
|
|
506
559
|
self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT
|
|
507
560
|
self.traces_sampler = nil
|
|
508
|
-
self.enable_tracing = nil
|
|
509
561
|
self.enable_logs = false
|
|
562
|
+
self.enable_metrics = true
|
|
510
563
|
|
|
511
564
|
self.profiler_class = Sentry::Profiler
|
|
565
|
+
self.profiles_sample_interval = DEFAULT_PROFILES_SAMPLE_INTERVAL
|
|
512
566
|
|
|
513
567
|
@transport = Transport::Configuration.new
|
|
514
568
|
@cron = Cron::Configuration.new
|
|
515
|
-
@metrics = Metrics::Configuration.new(self.sdk_logger)
|
|
516
569
|
@structured_logging = StructuredLoggingConfiguration.new
|
|
517
570
|
@gem_specs = Hash[Gem::Specification.map { |spec| [spec.name, spec.version.to_s] }] if Gem::Specification.respond_to?(:map)
|
|
518
571
|
|
|
519
572
|
self.max_log_events = LogEventBuffer::DEFAULT_MAX_EVENTS
|
|
573
|
+
self.max_metric_events = MetricEventBuffer::DEFAULT_MAX_METRICS
|
|
520
574
|
|
|
521
575
|
run_callbacks(:after, :initialize)
|
|
522
576
|
|
|
@@ -555,22 +609,6 @@ module Sentry
|
|
|
555
609
|
@release = value
|
|
556
610
|
end
|
|
557
611
|
|
|
558
|
-
def async=(value)
|
|
559
|
-
check_callable!("async", value)
|
|
560
|
-
|
|
561
|
-
log_warn <<~MSG
|
|
562
|
-
|
|
563
|
-
sentry-ruby now sends events asynchronously by default with its background worker (supported since 4.1.0).
|
|
564
|
-
The `config.async` callback has become redundant while continuing to cause issues.
|
|
565
|
-
(The problems of `async` are detailed in https://github.com/getsentry/sentry-ruby/issues/1522)
|
|
566
|
-
|
|
567
|
-
Therefore, we encourage you to remove it and let the background worker take care of async job sending.
|
|
568
|
-
It's deprecation is planned in the next major release (6.0), which is scheduled around the 3rd quarter of 2022.
|
|
569
|
-
MSG
|
|
570
|
-
|
|
571
|
-
@async = value
|
|
572
|
-
end
|
|
573
|
-
|
|
574
612
|
def breadcrumbs_logger=(logger)
|
|
575
613
|
loggers =
|
|
576
614
|
if logger.is_a?(Array)
|
|
@@ -596,12 +634,30 @@ module Sentry
|
|
|
596
634
|
@before_send_transaction = value
|
|
597
635
|
end
|
|
598
636
|
|
|
637
|
+
def before_send_check_in=(value)
|
|
638
|
+
check_callable!("before_send_check_in", value)
|
|
639
|
+
|
|
640
|
+
@before_send_check_in = value
|
|
641
|
+
end
|
|
642
|
+
|
|
643
|
+
def before_send_metric=(value)
|
|
644
|
+
check_callable!("before_send_metric", value)
|
|
645
|
+
|
|
646
|
+
@before_send_metric = value
|
|
647
|
+
end
|
|
648
|
+
|
|
599
649
|
def before_breadcrumb=(value)
|
|
600
650
|
check_callable!("before_breadcrumb", value)
|
|
601
651
|
|
|
602
652
|
@before_breadcrumb = value
|
|
603
653
|
end
|
|
604
654
|
|
|
655
|
+
def std_lib_logger_filter=(value)
|
|
656
|
+
check_callable!("std_lib_logger_filter", value)
|
|
657
|
+
|
|
658
|
+
@std_lib_logger_filter = value
|
|
659
|
+
end
|
|
660
|
+
|
|
605
661
|
def environment=(environment)
|
|
606
662
|
@environment = environment.to_s
|
|
607
663
|
end
|
|
@@ -610,15 +666,12 @@ module Sentry
|
|
|
610
666
|
@instrumenter = INSTRUMENTERS.include?(instrumenter) ? instrumenter : :sentry
|
|
611
667
|
end
|
|
612
668
|
|
|
613
|
-
def
|
|
614
|
-
unless
|
|
615
|
-
|
|
616
|
-
`enable_tracing` is now deprecated in favor of `traces_sample_rate = 1.0`.
|
|
617
|
-
MSG
|
|
669
|
+
def trace_ignore_status_codes=(codes)
|
|
670
|
+
unless codes.is_a?(Array) && codes.all? { |code| valid_status_code_entry?(code) }
|
|
671
|
+
raise ArgumentError, "trace_ignore_status_codes must be an Array of integers or ranges between (100-599) where begin <= end"
|
|
618
672
|
end
|
|
619
673
|
|
|
620
|
-
@
|
|
621
|
-
@traces_sample_rate ||= 1.0 if enable_tracing
|
|
674
|
+
@trace_ignore_status_codes = codes
|
|
622
675
|
end
|
|
623
676
|
|
|
624
677
|
def traces_sample_rate=(traces_sample_rate)
|
|
@@ -640,6 +693,16 @@ module Sentry
|
|
|
640
693
|
@profiler_class = profiler_class
|
|
641
694
|
end
|
|
642
695
|
|
|
696
|
+
def org_id=(value)
|
|
697
|
+
@org_id = value&.to_s
|
|
698
|
+
end
|
|
699
|
+
|
|
700
|
+
# Returns the effective org ID, preferring the explicit config option over the DSN-parsed value.
|
|
701
|
+
# @return [String, nil]
|
|
702
|
+
def effective_org_id
|
|
703
|
+
org_id || dsn&.org_id
|
|
704
|
+
end
|
|
705
|
+
|
|
643
706
|
def sending_allowed?
|
|
644
707
|
spotlight || sending_to_dsn_allowed?
|
|
645
708
|
end
|
|
@@ -674,7 +737,7 @@ module Sentry
|
|
|
674
737
|
end
|
|
675
738
|
|
|
676
739
|
def enabled_in_current_env?
|
|
677
|
-
enabled_environments.
|
|
740
|
+
enabled_environments.nil? || enabled_environments.include?(environment)
|
|
678
741
|
end
|
|
679
742
|
|
|
680
743
|
def valid_sample_rate?(sample_rate)
|
|
@@ -685,7 +748,7 @@ module Sentry
|
|
|
685
748
|
def tracing_enabled?
|
|
686
749
|
valid_sampler = !!((valid_sample_rate?(@traces_sample_rate)) || @traces_sampler)
|
|
687
750
|
|
|
688
|
-
|
|
751
|
+
valid_sampler && sending_allowed?
|
|
689
752
|
end
|
|
690
753
|
|
|
691
754
|
def profiling_enabled?
|
|
@@ -816,6 +879,23 @@ module Sentry
|
|
|
816
879
|
available_processor_count = Concurrent.available_processor_count if Concurrent.respond_to?(:available_processor_count)
|
|
817
880
|
available_processor_count || Concurrent.processor_count
|
|
818
881
|
end
|
|
882
|
+
|
|
883
|
+
def valid_http_status_code?(code)
|
|
884
|
+
code.is_a?(Integer) && code >= 100 && code <= 599
|
|
885
|
+
end
|
|
886
|
+
|
|
887
|
+
def valid_status_code_entry?(entry)
|
|
888
|
+
case entry
|
|
889
|
+
when Integer
|
|
890
|
+
valid_http_status_code?(entry)
|
|
891
|
+
when Range
|
|
892
|
+
valid_http_status_code?(entry.begin) &&
|
|
893
|
+
valid_http_status_code?(entry.end) &&
|
|
894
|
+
entry.begin <= entry.end
|
|
895
|
+
else
|
|
896
|
+
false
|
|
897
|
+
end
|
|
898
|
+
end
|
|
819
899
|
end
|
|
820
900
|
|
|
821
901
|
class StructuredLoggingConfiguration
|
|
@@ -14,12 +14,12 @@ module Sentry
|
|
|
14
14
|
:in_progress,
|
|
15
15
|
monitor_config: monitor_config)
|
|
16
16
|
|
|
17
|
-
start =
|
|
17
|
+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
18
18
|
|
|
19
19
|
begin
|
|
20
20
|
# need to do this on ruby <= 2.6 sadly
|
|
21
21
|
ret = method(:perform).super_method.arity == 0 ? super() : super
|
|
22
|
-
duration =
|
|
22
|
+
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
|
|
23
23
|
|
|
24
24
|
Sentry.capture_check_in(slug,
|
|
25
25
|
:ok,
|
|
@@ -29,7 +29,7 @@ module Sentry
|
|
|
29
29
|
|
|
30
30
|
ret
|
|
31
31
|
rescue Exception
|
|
32
|
-
duration =
|
|
32
|
+
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
|
|
33
33
|
|
|
34
34
|
Sentry.capture_check_in(slug,
|
|
35
35
|
:error,
|
|
@@ -40,9 +40,9 @@ module Sentry
|
|
|
40
40
|
new(MonitorSchedule::Interval.new(num, unit), **options)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
def
|
|
43
|
+
def to_h
|
|
44
44
|
{
|
|
45
|
-
schedule: schedule.
|
|
45
|
+
schedule: schedule.to_h,
|
|
46
46
|
checkin_margin: checkin_margin,
|
|
47
47
|
max_runtime: max_runtime,
|
|
48
48
|
timezone: timezone
|
|
@@ -12,7 +12,7 @@ module Sentry
|
|
|
12
12
|
@value = value
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def
|
|
15
|
+
def to_h
|
|
16
16
|
{ type: :crontab, value: value }
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -33,7 +33,7 @@ module Sentry
|
|
|
33
33
|
@unit = unit
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
def
|
|
36
|
+
def to_h
|
|
37
37
|
{ type: :interval, value: value, unit: unit }
|
|
38
38
|
end
|
|
39
39
|
end
|
data/lib/sentry/dsn.rb
CHANGED
|
@@ -6,12 +6,14 @@ require "resolv"
|
|
|
6
6
|
|
|
7
7
|
module Sentry
|
|
8
8
|
class DSN
|
|
9
|
+
PROTOCOL_VERSION = "7"
|
|
9
10
|
PORT_MAP = { "http" => 80, "https" => 443 }.freeze
|
|
10
11
|
REQUIRED_ATTRIBUTES = %w[host path public_key project_id].freeze
|
|
11
12
|
LOCALHOST_NAMES = %w[localhost 127.0.0.1 ::1 [::1]].freeze
|
|
12
13
|
LOCALHOST_PATTERN = /\.local(host|domain)?$/i
|
|
14
|
+
ORG_ID_REGEX = /\Ao(\d+)\./
|
|
13
15
|
|
|
14
|
-
attr_reader :scheme, :secret_key, :port, *REQUIRED_ATTRIBUTES
|
|
16
|
+
attr_reader :scheme, :secret_key, :port, :org_id, *REQUIRED_ATTRIBUTES
|
|
15
17
|
|
|
16
18
|
def initialize(dsn_string)
|
|
17
19
|
@raw_value = dsn_string
|
|
@@ -30,6 +32,8 @@ module Sentry
|
|
|
30
32
|
@host = uri.host
|
|
31
33
|
@port = uri.port if uri.port
|
|
32
34
|
@path = uri_path.join("/")
|
|
35
|
+
|
|
36
|
+
@org_id = extract_org_id_from_host
|
|
33
37
|
end
|
|
34
38
|
|
|
35
39
|
def valid?
|
|
@@ -54,6 +58,10 @@ module Sentry
|
|
|
54
58
|
"#{path}/api/#{project_id}/envelope/"
|
|
55
59
|
end
|
|
56
60
|
|
|
61
|
+
def otlp_traces_endpoint
|
|
62
|
+
"#{path}/api/#{project_id}/integration/otlp/v1/traces/"
|
|
63
|
+
end
|
|
64
|
+
|
|
57
65
|
def local?
|
|
58
66
|
@local ||= (localhost? || private_ip? || resolved_ips_private?)
|
|
59
67
|
end
|
|
@@ -81,5 +89,29 @@ module Sentry
|
|
|
81
89
|
end
|
|
82
90
|
end
|
|
83
91
|
end
|
|
92
|
+
|
|
93
|
+
def generate_auth_header(client: nil)
|
|
94
|
+
now = Sentry.utc_now.to_i
|
|
95
|
+
|
|
96
|
+
fields = {
|
|
97
|
+
"sentry_version" => PROTOCOL_VERSION,
|
|
98
|
+
"sentry_timestamp" => now,
|
|
99
|
+
"sentry_key" => @public_key
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
fields["sentry_client"] = client if client
|
|
103
|
+
fields["sentry_secret"] = @secret_key if @secret_key
|
|
104
|
+
|
|
105
|
+
"Sentry " + fields.map { |key, value| "#{key}=#{value}" }.join(", ")
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
private
|
|
109
|
+
|
|
110
|
+
def extract_org_id_from_host
|
|
111
|
+
return nil unless @host
|
|
112
|
+
|
|
113
|
+
match = ORG_ID_REGEX.match(@host)
|
|
114
|
+
match ? match[1] : nil
|
|
115
|
+
end
|
|
84
116
|
end
|
|
85
117
|
end
|
data/lib/sentry/envelope/item.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Sentry
|
|
4
4
|
# @api private
|
|
5
5
|
class Envelope::Item
|
|
6
|
-
STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD =
|
|
6
|
+
STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD = 1000
|
|
7
7
|
MAX_SERIALIZED_PAYLOAD_SIZE = 1024 * 1000
|
|
8
8
|
|
|
9
9
|
SIZE_LIMITS = Hash.new(MAX_SERIALIZED_PAYLOAD_SIZE).update(
|
|
@@ -15,10 +15,10 @@ module Sentry
|
|
|
15
15
|
# rate limits and client reports use the data_category rather than envelope item type
|
|
16
16
|
def self.data_category(type)
|
|
17
17
|
case type
|
|
18
|
-
when "session", "attachment", "transaction", "profile", "span", "
|
|
18
|
+
when "session", "attachment", "transaction", "profile", "span", "trace_metric" then type
|
|
19
|
+
when "log" then "log_item"
|
|
19
20
|
when "sessions" then "session"
|
|
20
21
|
when "check_in" then "monitor"
|
|
21
|
-
when "statsd", "metric_meta" then "metric_bucket"
|
|
22
22
|
when "event" then "error"
|
|
23
23
|
when "client_report" then "internal"
|
|
24
24
|
else "default"
|
data/lib/sentry/error_event.rb
CHANGED
|
@@ -10,10 +10,10 @@ module Sentry
|
|
|
10
10
|
attr_reader :threads
|
|
11
11
|
|
|
12
12
|
# @return [Hash]
|
|
13
|
-
def
|
|
13
|
+
def to_h
|
|
14
14
|
data = super
|
|
15
|
-
data[:threads] = threads.
|
|
16
|
-
data[:exception] = exception.
|
|
15
|
+
data[:threads] = threads.to_h if threads
|
|
16
|
+
data[:exception] = exception.to_h if exception
|
|
17
17
|
data
|
|
18
18
|
end
|
|
19
19
|
|
data/lib/sentry/event.rb
CHANGED
|
@@ -81,12 +81,6 @@ module Sentry
|
|
|
81
81
|
@message = (message || "").byteslice(0..MAX_MESSAGE_SIZE_IN_BYTES)
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
-
# @deprecated This method will be removed in v5.0.0. Please just use Sentry.configuration
|
|
85
|
-
# @return [Configuration]
|
|
86
|
-
def configuration
|
|
87
|
-
Sentry.configuration
|
|
88
|
-
end
|
|
89
|
-
|
|
90
84
|
# Sets the event's timestamp.
|
|
91
85
|
# @param time [Time, Float]
|
|
92
86
|
# @return [void]
|
|
@@ -118,16 +112,16 @@ module Sentry
|
|
|
118
112
|
end
|
|
119
113
|
|
|
120
114
|
# @return [Hash]
|
|
121
|
-
def
|
|
115
|
+
def to_h
|
|
122
116
|
data = serialize_attributes
|
|
123
|
-
data[:breadcrumbs] = breadcrumbs.
|
|
124
|
-
data[:request] = request.
|
|
117
|
+
data[:breadcrumbs] = breadcrumbs.to_h if breadcrumbs
|
|
118
|
+
data[:request] = request.to_h if request
|
|
125
119
|
data
|
|
126
120
|
end
|
|
127
121
|
|
|
128
122
|
# @return [Hash]
|
|
129
123
|
def to_json_compatible
|
|
130
|
-
JSON.parse(JSON.generate(
|
|
124
|
+
JSON.parse(JSON.generate(to_h))
|
|
131
125
|
end
|
|
132
126
|
|
|
133
127
|
private
|