sentry-ruby 5.22.1 → 5.22.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cf4ebc58389dd621be706b53b86c30e689f9f52c5d5cbda72ef01528c540e5a
4
- data.tar.gz: f347cb6245d5d37f2d883870b26d846244d33ef6cbb67b838fe231d1c17e95f8
3
+ metadata.gz: ccdc435e6c9cc7602051e6ae33794509604f6a6973e8098acb3b39cdaa727056
4
+ data.tar.gz: 7963e284f23ac79656f94eccbed48840be1746927bcae3ae18a66c60aea923c5
5
5
  SHA512:
6
- metadata.gz: 2dae846cd0a9d3c10d41d44a775bd39e6d175f559924bf101cd2a88816145ea2cf048962504615d5f05acca0b59451483a2b602a9fb87bba3b2be4364493fd27
7
- data.tar.gz: b17875017e20c0126c8ddc5d360873430c92d69f0633134743198140c2258f828b3b444748c7a4cd8e0bb9137a9990f2dc394182ffcfe6a19d1e0f3795beebcd
6
+ metadata.gz: da82afec03f9100f4d1389ac96069328a61f658b3ebf39b982aa8eb1284fbc19bd00168d4d89b3b4e8b0a0d82b98e161a4d38f4e5afbc88bdbbcfa3b7aadd958
7
+ data.tar.gz: 1711020af1887f806b3cc01a9e1d2540b616e5f3e5d77da85cb252e85ae90af9062de51eb9e552a434595345d0978a10b6002cd2944e0baaf4414275e58fd399
data/Gemfile CHANGED
@@ -9,6 +9,8 @@ rack_version = ENV["RACK_VERSION"]
9
9
  rack_version = "3.0.0" if rack_version.nil?
10
10
  gem "rack", "~> #{Gem::Version.new(rack_version)}" unless rack_version == "0"
11
11
 
12
+ gem "ostruct" if RUBY_VERSION >= "3.4"
13
+
12
14
  redis_rb_version = ENV.fetch("REDIS_RB_VERSION", "5.0")
13
15
  gem "redis", "~> #{redis_rb_version}"
14
16
 
data/README.md CHANGED
@@ -33,7 +33,7 @@ If you're using `sentry-raven`, we recommend you to migrate to this new SDK. You
33
33
 
34
34
  ## Requirements
35
35
 
36
- We test from Ruby 2.4 to Ruby 3.2 at the latest patchlevel/teeny version. We also support JRuby 9.0.
36
+ We test from Ruby 2.4 to Ruby 3.4 at the latest patchlevel/teeny version. We also support JRuby 9.0.
37
37
 
38
38
  If you use self-hosted Sentry, please also make sure its version is above `20.6.0`.
39
39
 
@@ -12,7 +12,7 @@ module Sentry
12
12
  RUBY_INPUT_FORMAT = /
13
13
  ^ \s* (?: [a-zA-Z]: | uri:classloader: )? ([^:]+ | <.*>):
14
14
  (\d+)
15
- (?: :in\s('|`)([^']+)')?$
15
+ (?: :in\s('|`)(?:([\w:]+)\#)?([^']+)')?$
16
16
  /x
17
17
 
18
18
  # org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
@@ -37,10 +37,11 @@ module Sentry
37
37
  # @return [Line] The parsed backtrace line
38
38
  def self.parse(unparsed_line, in_app_pattern = nil)
39
39
  ruby_match = unparsed_line.match(RUBY_INPUT_FORMAT)
40
+
40
41
  if ruby_match
41
- _, file, number, _, method = ruby_match.to_a
42
+ _, file, number, _, module_name, method = ruby_match.to_a
42
43
  file.sub!(/\.class$/, RB_EXTENSION)
43
- module_name = nil
44
+ module_name = module_name
44
45
  else
45
46
  java_match = unparsed_line.match(JAVA_INPUT_FORMAT)
46
47
  _, module_name, method, file, number = java_match.to_a
data/lib/sentry/client.rb CHANGED
@@ -183,8 +183,19 @@ module Sentry
183
183
  if event_type != TransactionEvent::TYPE && configuration.before_send
184
184
  event = configuration.before_send.call(event, hint)
185
185
 
186
- if event.nil?
187
- log_debug("Discarded event because before_send returned nil")
186
+ case event
187
+ when ErrorEvent, CheckInEvent
188
+ # do nothing
189
+ when Hash
190
+ log_debug(<<~MSG)
191
+ Returning a Hash from before_send is deprecated and will be removed in the next major version.
192
+ Please return a Sentry::ErrorEvent object instead.
193
+ MSG
194
+ else
195
+ # Avoid serializing the event object in this case because we aren't sure what it is and what it contains
196
+ log_debug(<<~MSG)
197
+ Discarded event because before_send didn't return a Sentry::ErrorEvent object but an instance of #{event.class}
198
+ MSG
188
199
  transport.record_lost_event(:before_send, data_category)
189
200
  return
190
201
  end
@@ -193,15 +204,25 @@ module Sentry
193
204
  if event_type == TransactionEvent::TYPE && configuration.before_send_transaction
194
205
  event = configuration.before_send_transaction.call(event, hint)
195
206
 
196
- if event.nil?
197
- log_debug("Discarded event because before_send_transaction returned nil")
198
- transport.record_lost_event(:before_send, "transaction")
199
- transport.record_lost_event(:before_send, "span", num: spans_before + 1)
200
- return
201
- else
207
+ if event.is_a?(TransactionEvent) || event.is_a?(Hash)
202
208
  spans_after = event.is_a?(TransactionEvent) ? event.spans.size : 0
203
209
  spans_delta = spans_before - spans_after
204
210
  transport.record_lost_event(:before_send, "span", num: spans_delta) if spans_delta > 0
211
+
212
+ if event.is_a?(Hash)
213
+ log_debug(<<~MSG)
214
+ Returning a Hash from before_send_transaction is deprecated and will be removed in the next major version.
215
+ Please return a Sentry::TransactionEvent object instead.
216
+ MSG
217
+ end
218
+ else
219
+ # Avoid serializing the event object in this case because we aren't sure what it is and what it contains
220
+ log_debug(<<~MSG)
221
+ Discarded event because before_send_transaction didn't return a Sentry::TransactionEvent object but an instance of #{event.class}
222
+ MSG
223
+ transport.record_lost_event(:before_send, "transaction")
224
+ transport.record_lost_event(:before_send, "span", num: spans_before + 1)
225
+ return
205
226
  end
206
227
  end
207
228
 
@@ -360,8 +360,47 @@ module Sentry
360
360
  def add_post_initialization_callback(&block)
361
361
  post_initialization_callbacks << block
362
362
  end
363
+
364
+ def validations
365
+ @validations ||= {}
366
+ end
367
+
368
+ def validate(attribute, optional: false, type: nil)
369
+ validations[attribute] = {
370
+ optional: optional,
371
+ type: type,
372
+ proc: build_validation_proc(optional, type)
373
+ }
374
+ end
375
+
376
+ private
377
+
378
+ def build_validation_proc(optional, type)
379
+ case type
380
+ when :numeric
381
+ ->(value) do
382
+ if optional && value.nil?
383
+ true
384
+ else
385
+ unless value.is_a?(Numeric)
386
+ message = "must be a Numeric"
387
+ message += " or nil" if optional
388
+
389
+ { error: message, value: value }
390
+ else
391
+ true
392
+ end
393
+ end
394
+ end
395
+ else
396
+ ->(value) { true }
397
+ end
398
+ end
363
399
  end
364
400
 
401
+ validate :traces_sample_rate, optional: true, type: :numeric
402
+ validate :profiles_sample_rate, optional: true, type: :numeric
403
+
365
404
  def initialize
366
405
  self.app_dirs_pattern = APP_DIRS_PATTERN
367
406
  self.debug = Sentry::Utils::EnvHelper.env_to_bool(ENV["SENTRY_DEBUG"])
@@ -417,6 +456,24 @@ module Sentry
417
456
  run_post_initialization_callbacks
418
457
  end
419
458
 
459
+ def validate
460
+ if profiler_class == Sentry::Profiler && profiles_sample_rate && !Sentry.dependency_installed?(:StackProf)
461
+ log_warn("Please add the 'stackprof' gem to your Gemfile to use the StackProf profiler with Sentry.")
462
+ end
463
+
464
+ if profiler_class == Sentry::Vernier::Profiler && profiles_sample_rate && !Sentry.dependency_installed?(:Vernier)
465
+ log_warn("Please add the 'vernier' gem to your Gemfile to use the Vernier profiler with Sentry.")
466
+ end
467
+
468
+ self.class.validations.each do |attribute, validation|
469
+ value = public_send(attribute)
470
+
471
+ next if (result = validation[:proc].call(value)) === true
472
+
473
+ raise ArgumentError, result[:error]
474
+ end
475
+ end
476
+
420
477
  def dsn=(value)
421
478
  @dsn = init_dsn(value)
422
479
  end
@@ -489,18 +546,11 @@ module Sentry
489
546
  @traces_sample_rate ||= 1.0 if enable_tracing
490
547
  end
491
548
 
492
- def is_numeric_or_nil?(value)
493
- value.is_a?(Numeric) || value.nil?
494
- end
495
-
496
549
  def traces_sample_rate=(traces_sample_rate)
497
- raise ArgumentError, "traces_sample_rate must be a Numeric or nil" unless is_numeric_or_nil?(traces_sample_rate)
498
550
  @traces_sample_rate = traces_sample_rate
499
551
  end
500
552
 
501
553
  def profiles_sample_rate=(profiles_sample_rate)
502
- raise ArgumentError, "profiles_sample_rate must be a Numeric or nil" unless is_numeric_or_nil?(profiles_sample_rate)
503
- log_warn("Please make sure to include the 'stackprof' gem in your Gemfile to use Profiling with Sentry.") unless defined?(StackProf)
504
554
  @profiles_sample_rate = profiles_sample_rate
505
555
  end
506
556
 
@@ -509,7 +559,6 @@ module Sentry
509
559
  begin
510
560
  require "vernier"
511
561
  rescue LoadError
512
- raise ArgumentError, "Please add the 'vernier' gem to your Gemfile to use the Vernier profiler with Sentry."
513
562
  end
514
563
  end
515
564
 
@@ -14,12 +14,12 @@ module Sentry
14
14
  :in_progress,
15
15
  monitor_config: monitor_config)
16
16
 
17
- start = Sentry.utc_now.to_i
17
+ start = Metrics::Timing.duration_start
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 = Sentry.utc_now.to_i - start
22
+ duration = Metrics::Timing.duration_end(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 = Sentry.utc_now.to_i - start
32
+ duration = Metrics::Timing.duration_end(start)
33
33
 
34
34
  Sentry.capture_check_in(slug,
35
35
  :error,
@@ -37,6 +37,14 @@ module Sentry
37
37
  def week
38
38
  Sentry.utc_now.to_i / (3600.0 * 24.0 * 7.0)
39
39
  end
40
+
41
+ def duration_start
42
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
43
+ end
44
+
45
+ def duration_end(start)
46
+ Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
47
+ end
40
48
  end
41
49
  end
42
50
  end
@@ -13,6 +13,7 @@ module Sentry
13
13
  OP_NAME = "http.client"
14
14
  SPAN_ORIGIN = "auto.http.net_http"
15
15
  BREADCRUMB_CATEGORY = "net.http"
16
+ URI_PARSER = URI.const_defined?("RFC2396_PARSER") ? URI::RFC2396_PARSER : URI::DEFAULT_PARSER
16
17
 
17
18
  # To explain how the entire thing works, we need to know how the original Net::HTTP#request works
18
19
  # Here's part of its definition. As you can see, it usually calls itself inside a #start block
@@ -66,7 +67,7 @@ module Sentry
66
67
  # IPv6 url could look like '::1/path', and that won't parse without
67
68
  # wrapping it in square brackets.
68
69
  hostname = address =~ Resolv::IPv6::Regex ? "[#{address}]" : address
69
- uri = req.uri || URI.parse(URI::DEFAULT_PARSER.escape("#{use_ssl? ? 'https' : 'http'}://#{hostname}#{req.path}"))
70
+ uri = req.uri || URI.parse(URI_PARSER.escape("#{use_ssl? ? 'https' : 'http'}://#{hostname}#{req.path}"))
70
71
  url = "#{uri.scheme}://#{uri.host}#{uri.path}" rescue uri.to_s
71
72
 
72
73
  result = { method: req.method, url: url }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sentry
4
- VERSION = "5.22.1"
4
+ VERSION = "5.22.4"
5
5
  end
data/lib/sentry-ruby.rb CHANGED
@@ -232,6 +232,7 @@ module Sentry
232
232
  yield(config) if block_given?
233
233
  config.detect_release
234
234
  apply_patches(config)
235
+ config.validate
235
236
  client = Client.new(config)
236
237
  scope = Scope.new(max_breadcrumbs: config.max_breadcrumbs)
237
238
  hub = Hub.new(client, scope)
@@ -308,6 +309,9 @@ module Sentry
308
309
  # @return [Hub]
309
310
  def get_main_hub
310
311
  MUTEX.synchronize { @main_hub }
312
+ rescue ThreadError
313
+ # In some rare cases this may be called in a trap context so we need to handle it gracefully
314
+ @main_hub
311
315
  end
312
316
 
313
317
  # Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
@@ -605,6 +609,11 @@ module Sentry
605
609
  def utc_now
606
610
  Time.now.utc
607
611
  end
612
+
613
+ # @!visibility private
614
+ def dependency_installed?(name)
615
+ Object.const_defined?(name)
616
+ end
608
617
  end
609
618
  end
610
619
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.22.1
4
+ version: 5.22.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-16 00:00:00.000000000 Z
10
+ date: 2025-02-06 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: concurrent-ruby
@@ -151,16 +150,15 @@ files:
151
150
  - lib/sentry/version.rb
152
151
  - sentry-ruby-core.gemspec
153
152
  - sentry-ruby.gemspec
154
- homepage: https://github.com/getsentry/sentry-ruby/tree/5.22.1/sentry-ruby
153
+ homepage: https://github.com/getsentry/sentry-ruby/tree/5.22.4/sentry-ruby
155
154
  licenses:
156
155
  - MIT
157
156
  metadata:
158
- homepage_uri: https://github.com/getsentry/sentry-ruby/tree/5.22.1/sentry-ruby
159
- source_code_uri: https://github.com/getsentry/sentry-ruby/tree/5.22.1/sentry-ruby
160
- changelog_uri: https://github.com/getsentry/sentry-ruby/blob/5.22.1/CHANGELOG.md
157
+ homepage_uri: https://github.com/getsentry/sentry-ruby/tree/5.22.4/sentry-ruby
158
+ source_code_uri: https://github.com/getsentry/sentry-ruby/tree/5.22.4/sentry-ruby
159
+ changelog_uri: https://github.com/getsentry/sentry-ruby/blob/5.22.4/CHANGELOG.md
161
160
  bug_tracker_uri: https://github.com/getsentry/sentry-ruby/issues
162
- documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/5.22.1
163
- post_install_message:
161
+ documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/5.22.4
164
162
  rdoc_options: []
165
163
  require_paths:
166
164
  - lib
@@ -175,8 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
173
  - !ruby/object:Gem::Version
176
174
  version: '0'
177
175
  requirements: []
178
- rubygems_version: 3.5.22
179
- signing_key:
176
+ rubygems_version: 3.6.2
180
177
  specification_version: 4
181
178
  summary: A gem that provides a client interface for the Sentry error logger
182
179
  test_files: []