sentry-ruby-core 5.6.0 → 5.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/Gemfile +6 -3
- data/README.md +3 -0
- data/lib/sentry/client.rb +10 -0
- data/lib/sentry/configuration.rb +60 -19
- data/lib/sentry/hub.rb +5 -2
- data/lib/sentry/redis.rb +27 -8
- data/lib/sentry/scope.rb +20 -2
- data/lib/sentry/span.rb +8 -6
- data/lib/sentry/test_helper.rb +1 -1
- data/lib/sentry/transaction.rb +57 -13
- data/lib/sentry/transaction_event.rb +6 -0
- data/lib/sentry/version.rb +1 -1
- data/lib/sentry-ruby.rb +19 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea12eade70f48185f12a34b1ef04c656d29f9a700ec375e1eef91fb66db9b648
|
4
|
+
data.tar.gz: 14f4b9a532cc0d1f401ee0bcb942787951f107358e9fbfadc2b1c655d00da3b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd74a92d1f3524b775a74aca3df9bdf72947e15fc1565d74a3a71fe1726a925357d0dfe48f87fce27ad514de17c991b6c55f269ba2852b1f3b3f8285637357d0
|
7
|
+
data.tar.gz: 4d5e8d3fe56644431b33fbec3eeaf4ceec01eb85b21bd2abfa5a0d8bc4c812aef9beb06b89048525186f00170677b160154414d5cb9b8972725532ba35277130
|
data/.rspec
CHANGED
data/Gemfile
CHANGED
@@ -7,12 +7,14 @@ rack_version = ENV["RACK_VERSION"]
|
|
7
7
|
rack_version = "3.0.0" if rack_version.nil?
|
8
8
|
gem "rack", "~> #{Gem::Version.new(rack_version)}" unless rack_version == "0"
|
9
9
|
|
10
|
+
redis_rb_version = ENV.fetch("REDIS_RB_VERSION", "5.0")
|
11
|
+
gem "redis", "~> #{redis_rb_version}"
|
12
|
+
|
10
13
|
gem "rake", "~> 12.0"
|
11
14
|
gem "rspec", "~> 3.0"
|
12
15
|
gem "rspec-retry"
|
13
|
-
gem "fakeredis"
|
14
16
|
gem "timecop"
|
15
|
-
gem
|
17
|
+
gem "simplecov"
|
16
18
|
gem "simplecov-cobertura", "~> 1.4"
|
17
19
|
gem "rexml"
|
18
20
|
|
@@ -25,4 +27,5 @@ gem "benchmark_driver"
|
|
25
27
|
gem "benchmark-ipsa"
|
26
28
|
gem "benchmark-memory"
|
27
29
|
|
28
|
-
gem "yard",
|
30
|
+
gem "yard", github: "lsegal/yard"
|
31
|
+
gem "webrick"
|
data/README.md
CHANGED
@@ -20,6 +20,7 @@ Sentry SDK for Ruby
|
|
20
20
|
| [![Gem Version](https://img.shields.io/gem/v/sentry-sidekiq?label=sentry-sidekiq)](https://rubygems.org/gems/sentry-sidekiq) | [![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-sidekiq%20Test/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_sidekiq_test.yml) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![Downloads](https://img.shields.io/gem/dt/sentry-sidekiq.svg)](https://rubygems.org/gems/sentry-sidekiq/) |
|
21
21
|
| [![Gem Version](https://img.shields.io/gem/v/sentry-delayed_job?label=sentry-delayed_job)](https://rubygems.org/gems/sentry-delayed_job) | [![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-delayed_job%20Test/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_delayed_job_test.yml) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![Downloads](https://img.shields.io/gem/dt/sentry-delayed_job.svg)](https://rubygems.org/gems/sentry-delayed_job/) |
|
22
22
|
| [![Gem Version](https://img.shields.io/gem/v/sentry-resque?label=sentry-resque)](https://rubygems.org/gems/sentry-resque) | [![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-resque%20Test/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_resque_test.yml) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![Downloads](https://img.shields.io/gem/dt/sentry-resque.svg)](https://rubygems.org/gems/sentry-resque/) |
|
23
|
+
| [![Gem Version](https://img.shields.io/gem/v/sentry-opentelemetry?label=sentry-opentelemetry)](https://rubygems.org/gems/sentry-opentelemetry) | [![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-opentelemetry%20Test/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_opentelemetry_test.yml) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![Downloads](https://img.shields.io/gem/dt/sentry-opentelemetry.svg)](https://rubygems.org/gems/sentry-opentelemetry/) |
|
23
24
|
|
24
25
|
|
25
26
|
|
@@ -51,6 +52,7 @@ gem "sentry-rails"
|
|
51
52
|
gem "sentry-sidekiq"
|
52
53
|
gem "sentry-delayed_job"
|
53
54
|
gem "sentry-resque"
|
55
|
+
gem "sentry-opentelemetry"
|
54
56
|
```
|
55
57
|
|
56
58
|
### Configuration
|
@@ -88,6 +90,7 @@ To learn more about sampling transactions, please visit the [official documentat
|
|
88
90
|
- [Sidekiq](https://docs.sentry.io/platforms/ruby/guides/sidekiq/)
|
89
91
|
- [DelayedJob](https://docs.sentry.io/platforms/ruby/guides/delayed_job/)
|
90
92
|
- [Resque](https://docs.sentry.io/platforms/ruby/guides/resque/)
|
93
|
+
- [OpenTemeletry](https://docs.sentry.io/platforms/ruby/performance/instrumentation/opentelemetry/)
|
91
94
|
|
92
95
|
### Enriching Events
|
93
96
|
|
data/lib/sentry/client.rb
CHANGED
@@ -122,6 +122,16 @@ module Sentry
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
+
if event_type == TransactionEvent::TYPE && configuration.before_send_transaction
|
126
|
+
event = configuration.before_send_transaction.call(event, hint)
|
127
|
+
|
128
|
+
if event.nil?
|
129
|
+
log_info("Discarded event because before_send_transaction returned nil")
|
130
|
+
transport.record_lost_event(:before_send, 'transaction')
|
131
|
+
return
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
125
135
|
transport.send_event(event)
|
126
136
|
|
127
137
|
event
|
data/lib/sentry/configuration.rb
CHANGED
@@ -72,6 +72,19 @@ module Sentry
|
|
72
72
|
# @return [Proc]
|
73
73
|
attr_reader :before_send
|
74
74
|
|
75
|
+
# Optional Proc, called before sending an event to the server
|
76
|
+
# @example
|
77
|
+
# config.before_send_transaction = lambda do |event, hint|
|
78
|
+
# # skip unimportant transactions or strip sensitive data
|
79
|
+
# if event.transaction == "/healthcheck/route"
|
80
|
+
# nil
|
81
|
+
# else
|
82
|
+
# event
|
83
|
+
# end
|
84
|
+
# end
|
85
|
+
# @return [Proc]
|
86
|
+
attr_reader :before_send_transaction
|
87
|
+
|
75
88
|
# An array of breadcrumbs loggers to be used. Available options are:
|
76
89
|
# - :sentry_logger
|
77
90
|
# - :http_logger
|
@@ -84,10 +97,6 @@ module Sentry
|
|
84
97
|
# @return [Array<Symbol>]
|
85
98
|
attr_reader :breadcrumbs_logger
|
86
99
|
|
87
|
-
# Whether to capture local variables from the raised exception's frame. Default is false.
|
88
|
-
# @return [Boolean]
|
89
|
-
attr_accessor :capture_exception_frame_locals
|
90
|
-
|
91
100
|
# Max number of breadcrumbs a breadcrumb buffer can hold
|
92
101
|
# @return [Integer]
|
93
102
|
attr_accessor :max_breadcrumbs
|
@@ -127,6 +136,22 @@ module Sentry
|
|
127
136
|
attr_accessor :inspect_exception_causes_for_exclusion
|
128
137
|
alias inspect_exception_causes_for_exclusion? inspect_exception_causes_for_exclusion
|
129
138
|
|
139
|
+
# Whether to capture local variables from the raised exception's frame. Default is false.
|
140
|
+
# @return [Boolean]
|
141
|
+
attr_accessor :include_local_variables
|
142
|
+
|
143
|
+
# @deprecated Use {#include_local_variables} instead.
|
144
|
+
alias_method :capture_exception_frame_locals, :include_local_variables
|
145
|
+
|
146
|
+
# @deprecated Use {#include_local_variables=} instead.
|
147
|
+
def capture_exception_frame_locals=(value)
|
148
|
+
log_warn <<~MSG
|
149
|
+
`capture_exception_frame_locals` is now deprecated in favor of `include_local_variables`.
|
150
|
+
MSG
|
151
|
+
|
152
|
+
self.include_local_variables = value
|
153
|
+
end
|
154
|
+
|
130
155
|
# You may provide your own LineCache for matching paths with source files.
|
131
156
|
# This may be useful if you need to get source code from places other than the disk.
|
132
157
|
# @see LineCache
|
@@ -211,6 +236,10 @@ module Sentry
|
|
211
236
|
# @return [Boolean]
|
212
237
|
attr_accessor :auto_session_tracking
|
213
238
|
|
239
|
+
# The instrumenter to use, :sentry or :otel
|
240
|
+
# @return [Symbol]
|
241
|
+
attr_reader :instrumenter
|
242
|
+
|
214
243
|
# these are not config options
|
215
244
|
# @!visibility private
|
216
245
|
attr_reader :errors, :gem_specs
|
@@ -237,9 +266,20 @@ module Sentry
|
|
237
266
|
MODULE_SEPARATOR = "::".freeze
|
238
267
|
SKIP_INSPECTION_ATTRIBUTES = [:@linecache, :@stacktrace_builder]
|
239
268
|
|
240
|
-
|
241
|
-
|
242
|
-
|
269
|
+
INSTRUMENTERS = [:sentry, :otel]
|
270
|
+
|
271
|
+
class << self
|
272
|
+
# Post initialization callbacks are called at the end of initialization process
|
273
|
+
# allowing extending the configuration of sentry-ruby by multiple extensions
|
274
|
+
def post_initialization_callbacks
|
275
|
+
@post_initialization_callbacks ||= []
|
276
|
+
end
|
277
|
+
|
278
|
+
# allow extensions to add their hooks to the Configuration class
|
279
|
+
def add_post_initialization_callback(&block)
|
280
|
+
post_initialization_callbacks << block
|
281
|
+
end
|
282
|
+
end
|
243
283
|
|
244
284
|
def initialize
|
245
285
|
self.app_dirs_pattern = nil
|
@@ -249,7 +289,7 @@ module Sentry
|
|
249
289
|
self.max_breadcrumbs = BreadcrumbBuffer::DEFAULT_SIZE
|
250
290
|
self.breadcrumbs_logger = []
|
251
291
|
self.context_lines = 3
|
252
|
-
self.
|
292
|
+
self.include_local_variables = false
|
253
293
|
self.environment = environment_from_env
|
254
294
|
self.enabled_environments = []
|
255
295
|
self.exclude_loggers = []
|
@@ -269,8 +309,10 @@ module Sentry
|
|
269
309
|
self.trusted_proxies = []
|
270
310
|
self.dsn = ENV['SENTRY_DSN']
|
271
311
|
self.server_name = server_name_from_env
|
312
|
+
self.instrumenter = :sentry
|
272
313
|
|
273
314
|
self.before_send = nil
|
315
|
+
self.before_send_transaction = nil
|
274
316
|
self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT
|
275
317
|
self.traces_sample_rate = nil
|
276
318
|
self.traces_sampler = nil
|
@@ -322,6 +364,12 @@ module Sentry
|
|
322
364
|
@before_send = value
|
323
365
|
end
|
324
366
|
|
367
|
+
def before_send_transaction=(value)
|
368
|
+
check_callable!("before_send_transaction", value)
|
369
|
+
|
370
|
+
@before_send_transaction = value
|
371
|
+
end
|
372
|
+
|
325
373
|
def before_breadcrumb=(value)
|
326
374
|
check_callable!("before_breadcrumb", value)
|
327
375
|
|
@@ -332,6 +380,10 @@ module Sentry
|
|
332
380
|
@environment = environment.to_s
|
333
381
|
end
|
334
382
|
|
383
|
+
def instrumenter=(instrumenter)
|
384
|
+
@instrumenter = INSTRUMENTERS.include?(instrumenter) ? instrumenter : :sentry
|
385
|
+
end
|
386
|
+
|
335
387
|
def sending_allowed?
|
336
388
|
@errors = []
|
337
389
|
|
@@ -487,16 +539,5 @@ module Sentry
|
|
487
539
|
instance_eval(&hook)
|
488
540
|
end
|
489
541
|
end
|
490
|
-
|
491
|
-
# allow extensions to add their hooks to the Configuration class
|
492
|
-
def self.add_post_initialization_callback(&block)
|
493
|
-
self.post_initialization_callbacks << block
|
494
|
-
end
|
495
|
-
|
496
|
-
protected
|
497
|
-
|
498
|
-
def self.post_initialization_callbacks
|
499
|
-
@@post_initialization_callbacks
|
500
|
-
end
|
501
542
|
end
|
502
543
|
end
|
data/lib/sentry/hub.rb
CHANGED
@@ -76,8 +76,9 @@ module Sentry
|
|
76
76
|
@stack.pop
|
77
77
|
end
|
78
78
|
|
79
|
-
def start_transaction(transaction: nil, custom_sampling_context: {}, **options)
|
79
|
+
def start_transaction(transaction: nil, custom_sampling_context: {}, instrumenter: :sentry, **options)
|
80
80
|
return unless configuration.tracing_enabled?
|
81
|
+
return unless instrumenter == configuration.instrumenter
|
81
82
|
|
82
83
|
transaction ||= Transaction.new(**options.merge(hub: self))
|
83
84
|
|
@@ -92,7 +93,9 @@ module Sentry
|
|
92
93
|
transaction
|
93
94
|
end
|
94
95
|
|
95
|
-
def with_child_span(**attributes, &block)
|
96
|
+
def with_child_span(instrumenter: :sentry, **attributes, &block)
|
97
|
+
return yield(nil) unless instrumenter == configuration.instrumenter
|
98
|
+
|
96
99
|
current_span = current_scope.get_span
|
97
100
|
return yield(nil) unless current_span
|
98
101
|
|
data/lib/sentry/redis.rb
CHANGED
@@ -54,7 +54,8 @@ module Sentry
|
|
54
54
|
def parsed_commands
|
55
55
|
commands.map do |statement|
|
56
56
|
command, key, *arguments = statement
|
57
|
-
command_set = { command: command.to_s.upcase
|
57
|
+
command_set = { command: command.to_s.upcase }
|
58
|
+
command_set[:key] = key if Utils::EncodingHelper.valid_utf_8?(key)
|
58
59
|
|
59
60
|
if Sentry.configuration.send_default_pii
|
60
61
|
command_set[:arguments] = arguments
|
@@ -70,19 +71,37 @@ module Sentry
|
|
70
71
|
"#{host}:#{port}/#{db}"
|
71
72
|
end
|
72
73
|
|
73
|
-
module
|
74
|
+
module OldClientPatch
|
74
75
|
def logging(commands, &block)
|
75
|
-
Sentry::Redis.new(commands, host, port, db).instrument
|
76
|
-
|
77
|
-
|
76
|
+
Sentry::Redis.new(commands, host, port, db).instrument { super }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
module GlobalRedisInstrumentation
|
81
|
+
def call(command, redis_config)
|
82
|
+
Sentry::Redis
|
83
|
+
.new([command], redis_config.host, redis_config.port, redis_config.db)
|
84
|
+
.instrument { super }
|
85
|
+
end
|
86
|
+
|
87
|
+
def call_pipelined(commands, redis_config)
|
88
|
+
Sentry::Redis
|
89
|
+
.new(commands, redis_config.host, redis_config.port, redis_config.db)
|
90
|
+
.instrument { super }
|
78
91
|
end
|
79
92
|
end
|
80
93
|
end
|
81
94
|
end
|
82
95
|
|
83
96
|
if defined?(::Redis::Client)
|
84
|
-
|
85
|
-
|
86
|
-
|
97
|
+
if Gem::Version.new(::Redis::VERSION) < Gem::Version.new("5.0")
|
98
|
+
Sentry.register_patch do
|
99
|
+
patch = Sentry::Redis::OldClientPatch
|
100
|
+
unless Redis::Client.ancestors.include?(patch)
|
101
|
+
Redis::Client.prepend(patch)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
elsif defined?(RedisClient)
|
105
|
+
RedisClient.register(Sentry::Redis::GlobalRedisInstrumentation)
|
87
106
|
end
|
88
107
|
end
|
data/lib/sentry/scope.rb
CHANGED
@@ -58,8 +58,10 @@ module Sentry
|
|
58
58
|
event.breadcrumbs = breadcrumbs
|
59
59
|
event.rack_env = rack_env if rack_env
|
60
60
|
|
61
|
-
|
62
|
-
|
61
|
+
all_event_processors = self.class.global_event_processors + @event_processors
|
62
|
+
|
63
|
+
unless all_event_processors.empty?
|
64
|
+
all_event_processors.each do |processor_block|
|
63
65
|
event = processor_block.call(event, hint)
|
64
66
|
end
|
65
67
|
end
|
@@ -315,6 +317,22 @@ module Sentry
|
|
315
317
|
version: RUBY_DESCRIPTION || Sentry.sys_command("ruby -v")
|
316
318
|
}
|
317
319
|
end
|
320
|
+
|
321
|
+
# Returns the global event processors array.
|
322
|
+
# @return [Array<Proc>]
|
323
|
+
def global_event_processors
|
324
|
+
@global_event_processors ||= []
|
325
|
+
end
|
326
|
+
|
327
|
+
# Adds a new global event processor [Proc].
|
328
|
+
# Sometimes we need a global event processor without needing to configure scope.
|
329
|
+
# These run before scope event processors.
|
330
|
+
#
|
331
|
+
# @param block [Proc]
|
332
|
+
# @return [void]
|
333
|
+
def add_global_event_processor(&block)
|
334
|
+
global_event_processors << block
|
335
|
+
end
|
318
336
|
end
|
319
337
|
|
320
338
|
end
|
data/lib/sentry/span.rb
CHANGED
@@ -68,13 +68,14 @@ module Sentry
|
|
68
68
|
op: nil,
|
69
69
|
status: nil,
|
70
70
|
trace_id: nil,
|
71
|
+
span_id: nil,
|
71
72
|
parent_span_id: nil,
|
72
73
|
sampled: nil,
|
73
74
|
start_timestamp: nil,
|
74
75
|
timestamp: nil
|
75
76
|
)
|
76
77
|
@trace_id = trace_id || SecureRandom.uuid.delete("-")
|
77
|
-
@span_id = SecureRandom.hex(8)
|
78
|
+
@span_id = span_id || SecureRandom.hex(8)
|
78
79
|
@parent_span_id = parent_span_id
|
79
80
|
@sampled = sampled
|
80
81
|
@start_timestamp = start_timestamp || Sentry.utc_now.to_f
|
@@ -89,11 +90,8 @@ module Sentry
|
|
89
90
|
|
90
91
|
# Finishes the span by adding a timestamp.
|
91
92
|
# @return [self]
|
92
|
-
def finish
|
93
|
-
|
94
|
-
return if @timestamp
|
95
|
-
|
96
|
-
@timestamp = Sentry.utc_now.to_f
|
93
|
+
def finish(end_timestamp: nil)
|
94
|
+
@timestamp = end_timestamp || @timestamp || Sentry.utc_now.to_f
|
97
95
|
self
|
98
96
|
end
|
99
97
|
|
@@ -171,6 +169,10 @@ module Sentry
|
|
171
169
|
yield(child_span)
|
172
170
|
|
173
171
|
child_span.finish
|
172
|
+
rescue
|
173
|
+
child_span.set_http_status(500)
|
174
|
+
child_span.finish
|
175
|
+
raise
|
174
176
|
end
|
175
177
|
|
176
178
|
def deep_dup
|
data/lib/sentry/test_helper.rb
CHANGED
@@ -25,7 +25,7 @@ module Sentry
|
|
25
25
|
copied_config.background_worker_threads = 0
|
26
26
|
|
27
27
|
# user can overwrite some of the configs, with a few exceptions like:
|
28
|
-
# -
|
28
|
+
# - include_local_variables
|
29
29
|
# - auto_session_tracking
|
30
30
|
block&.call(copied_config)
|
31
31
|
|
data/lib/sentry/transaction.rb
CHANGED
@@ -37,6 +37,10 @@ module Sentry
|
|
37
37
|
# @return [Baggage, nil]
|
38
38
|
attr_reader :baggage
|
39
39
|
|
40
|
+
# The measurements added to the transaction.
|
41
|
+
# @return [Hash]
|
42
|
+
attr_reader :measurements
|
43
|
+
|
40
44
|
# @deprecated Use Sentry.get_current_hub instead.
|
41
45
|
attr_reader :hub
|
42
46
|
|
@@ -50,6 +54,10 @@ module Sentry
|
|
50
54
|
# @return [Float, nil]
|
51
55
|
attr_reader :effective_sample_rate
|
52
56
|
|
57
|
+
# Additional contexts stored directly on the transaction object.
|
58
|
+
# @return [Hash]
|
59
|
+
attr_reader :contexts
|
60
|
+
|
53
61
|
def initialize(
|
54
62
|
hub:,
|
55
63
|
name: nil,
|
@@ -60,8 +68,7 @@ module Sentry
|
|
60
68
|
)
|
61
69
|
super(transaction: self, **options)
|
62
70
|
|
63
|
-
|
64
|
-
@source = SOURCES.include?(source) ? source.to_sym : :custom
|
71
|
+
set_name(name, source: source)
|
65
72
|
@parent_sampled = parent_sampled
|
66
73
|
@hub = hub
|
67
74
|
@baggage = baggage
|
@@ -74,6 +81,8 @@ module Sentry
|
|
74
81
|
@environment = hub.configuration.environment
|
75
82
|
@dsn = hub.configuration.dsn
|
76
83
|
@effective_sample_rate = nil
|
84
|
+
@contexts = {}
|
85
|
+
@measurements = {}
|
77
86
|
init_span_recorder
|
78
87
|
end
|
79
88
|
|
@@ -91,16 +100,10 @@ module Sentry
|
|
91
100
|
return unless hub.configuration.tracing_enabled?
|
92
101
|
return unless sentry_trace
|
93
102
|
|
94
|
-
|
95
|
-
return
|
96
|
-
trace_id, parent_span_id, sampled_flag = match[1..3]
|
103
|
+
sentry_trace_data = extract_sentry_trace(sentry_trace)
|
104
|
+
return unless sentry_trace_data
|
97
105
|
|
98
|
-
parent_sampled =
|
99
|
-
if sampled_flag.nil?
|
100
|
-
nil
|
101
|
-
else
|
102
|
-
sampled_flag != "0"
|
103
|
-
end
|
106
|
+
trace_id, parent_span_id, parent_sampled = sentry_trace_data
|
104
107
|
|
105
108
|
baggage = if baggage && !baggage.empty?
|
106
109
|
Baggage.from_incoming_header(baggage)
|
@@ -123,6 +126,20 @@ module Sentry
|
|
123
126
|
)
|
124
127
|
end
|
125
128
|
|
129
|
+
# Extract the trace_id, parent_span_id and parent_sampled values from a sentry-trace header.
|
130
|
+
#
|
131
|
+
# @param sentry_trace [String] the sentry-trace header value from the previous transaction.
|
132
|
+
# @return [Array, nil]
|
133
|
+
def self.extract_sentry_trace(sentry_trace)
|
134
|
+
match = SENTRY_TRACE_REGEXP.match(sentry_trace)
|
135
|
+
return nil if match.nil?
|
136
|
+
|
137
|
+
trace_id, parent_span_id, sampled_flag = match[1..3]
|
138
|
+
parent_sampled = sampled_flag.nil? ? nil : sampled_flag != "0"
|
139
|
+
|
140
|
+
[trace_id, parent_span_id, parent_sampled]
|
141
|
+
end
|
142
|
+
|
126
143
|
# @return [Hash]
|
127
144
|
def to_hash
|
128
145
|
hash = super
|
@@ -151,6 +168,15 @@ module Sentry
|
|
151
168
|
copy
|
152
169
|
end
|
153
170
|
|
171
|
+
# Sets a custom measurement on the transaction.
|
172
|
+
# @param name [String] name of the measurement
|
173
|
+
# @param value [Float] value of the measurement
|
174
|
+
# @param unit [String] unit of the measurement
|
175
|
+
# @return [void]
|
176
|
+
def set_measurement(name, value, unit = "")
|
177
|
+
@measurements[name] = { value: value, unit: unit }
|
178
|
+
end
|
179
|
+
|
154
180
|
# Sets initial sampling decision of the transaction.
|
155
181
|
# @param sampling_context [Hash] a context Hash that'll be passed to `traces_sampler` (if provided).
|
156
182
|
# @return [void]
|
@@ -210,7 +236,7 @@ module Sentry
|
|
210
236
|
# Finishes the transaction's recording and send it to Sentry.
|
211
237
|
# @param hub [Hub] the hub that'll send this transaction. (Deprecated)
|
212
238
|
# @return [TransactionEvent]
|
213
|
-
def finish(hub: nil)
|
239
|
+
def finish(hub: nil, end_timestamp: nil)
|
214
240
|
if hub
|
215
241
|
log_warn(
|
216
242
|
<<~MSG
|
@@ -222,7 +248,7 @@ module Sentry
|
|
222
248
|
|
223
249
|
hub ||= @hub
|
224
250
|
|
225
|
-
super()
|
251
|
+
super(end_timestamp: end_timestamp)
|
226
252
|
|
227
253
|
if @name.nil?
|
228
254
|
@name = UNLABELD_NAME
|
@@ -244,6 +270,24 @@ module Sentry
|
|
244
270
|
@baggage
|
245
271
|
end
|
246
272
|
|
273
|
+
# Set the transaction name directly.
|
274
|
+
# Considered internal api since it bypasses the usual scope logic.
|
275
|
+
# @param name [String]
|
276
|
+
# @param source [Symbol]
|
277
|
+
# @return [void]
|
278
|
+
def set_name(name, source: :custom)
|
279
|
+
@name = name
|
280
|
+
@source = SOURCES.include?(source) ? source.to_sym : :custom
|
281
|
+
end
|
282
|
+
|
283
|
+
# Set contexts directly on the transaction.
|
284
|
+
# @param key [String, Symbol]
|
285
|
+
# @param value [Object]
|
286
|
+
# @return [void]
|
287
|
+
def set_context(key, value)
|
288
|
+
@contexts[key] = value
|
289
|
+
end
|
290
|
+
|
247
291
|
protected
|
248
292
|
|
249
293
|
def init_span_recorder(limit = 1000)
|
@@ -11,6 +11,9 @@ module Sentry
|
|
11
11
|
# @return [Hash, nil]
|
12
12
|
attr_accessor :dynamic_sampling_context
|
13
13
|
|
14
|
+
# @return [Hash]
|
15
|
+
attr_accessor :measurements
|
16
|
+
|
14
17
|
# @return [Float, nil]
|
15
18
|
attr_reader :start_timestamp
|
16
19
|
|
@@ -19,11 +22,13 @@ module Sentry
|
|
19
22
|
|
20
23
|
self.transaction = transaction.name
|
21
24
|
self.transaction_info = { source: transaction.source }
|
25
|
+
self.contexts.merge!(transaction.contexts)
|
22
26
|
self.contexts.merge!(trace: transaction.get_trace_context)
|
23
27
|
self.timestamp = transaction.timestamp
|
24
28
|
self.start_timestamp = transaction.start_timestamp
|
25
29
|
self.tags = transaction.tags
|
26
30
|
self.dynamic_sampling_context = transaction.get_baggage.dynamic_sampling_context
|
31
|
+
self.measurements = transaction.measurements
|
27
32
|
|
28
33
|
finished_spans = transaction.span_recorder.spans.select { |span| span.timestamp && span != transaction }
|
29
34
|
self.spans = finished_spans.map(&:to_hash)
|
@@ -41,6 +46,7 @@ module Sentry
|
|
41
46
|
data = super
|
42
47
|
data[:spans] = @spans.map(&:to_hash) if @spans
|
43
48
|
data[:start_timestamp] = @start_timestamp
|
49
|
+
data[:measurements] = @measurements
|
44
50
|
data
|
45
51
|
end
|
46
52
|
end
|
data/lib/sentry/version.rb
CHANGED
data/lib/sentry-ruby.rb
CHANGED
@@ -212,7 +212,7 @@ module Sentry
|
|
212
212
|
nil
|
213
213
|
end
|
214
214
|
|
215
|
-
if config.
|
215
|
+
if config.include_local_variables
|
216
216
|
exception_locals_tp.enable
|
217
217
|
end
|
218
218
|
|
@@ -234,7 +234,7 @@ module Sentry
|
|
234
234
|
@session_flusher = nil
|
235
235
|
end
|
236
236
|
|
237
|
-
if configuration&.
|
237
|
+
if configuration&.include_local_variables
|
238
238
|
exception_locals_tp.disable
|
239
239
|
end
|
240
240
|
|
@@ -462,6 +462,23 @@ module Sentry
|
|
462
462
|
!!exc.instance_variable_get(CAPTURED_SIGNATURE)
|
463
463
|
end
|
464
464
|
|
465
|
+
# Add a global event processor [Proc].
|
466
|
+
# These run before scope event processors.
|
467
|
+
#
|
468
|
+
# @yieldparam event [Event]
|
469
|
+
# @yieldparam hint [Hash, nil]
|
470
|
+
# @return [void]
|
471
|
+
#
|
472
|
+
# @example
|
473
|
+
# Sentry.add_global_event_processor do |event, hint|
|
474
|
+
# event.tags = { foo: 42 }
|
475
|
+
# event
|
476
|
+
# end
|
477
|
+
#
|
478
|
+
def add_global_event_processor(&block)
|
479
|
+
Scope.add_global_event_processor(&block)
|
480
|
+
end
|
481
|
+
|
465
482
|
##### Helpers #####
|
466
483
|
|
467
484
|
# @!visibility private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentry-ruby-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sentry Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sentry-ruby
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.
|
19
|
+
version: 5.8.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 5.
|
26
|
+
version: 5.8.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: concurrent-ruby
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|