sentry-ruby 5.22.2 → 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: f8b76c7e3289d19422a8ab07bdc53a2ac0fd907d3e55fd86c18ee1eb37daa7d7
4
- data.tar.gz: a560347120c4a0781e7ef67d9252e90dacf37c6d32f36a3c41da01110e0cbdc9
3
+ metadata.gz: ccdc435e6c9cc7602051e6ae33794509604f6a6973e8098acb3b39cdaa727056
4
+ data.tar.gz: 7963e284f23ac79656f94eccbed48840be1746927bcae3ae18a66c60aea923c5
5
5
  SHA512:
6
- metadata.gz: 2b04dafc81567da6edc9dc86436b1815db4001962c0dc8bea82fcced79c8f95ec23f22122b1eb127fc278edcd39da0c91569284f5a170db4ef9c19827ba4cbc8
7
- data.tar.gz: 7ee0819a7f3ea956a96123fb813731c440ffacbfc73e5ae37b47b650f8dded96dc4379321d1b714505c8f87a34c1b93a1ca6849a4a59697ad35f9eee5b827934
6
+ metadata.gz: da82afec03f9100f4d1389ac96069328a61f658b3ebf39b982aa8eb1284fbc19bd00168d4d89b3b4e8b0a0d82b98e161a4d38f4e5afbc88bdbbcfa3b7aadd958
7
+ data.tar.gz: 1711020af1887f806b3cc01a9e1d2540b616e5f3e5d77da85cb252e85ae90af9062de51eb9e552a434595345d0978a10b6002cd2944e0baaf4414275e58fd399
data/lib/sentry/client.rb CHANGED
@@ -183,7 +183,15 @@ module Sentry
183
183
  if event_type != TransactionEvent::TYPE && configuration.before_send
184
184
  event = configuration.before_send.call(event, hint)
185
185
 
186
- unless event.is_a?(ErrorEvent)
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
187
195
  # Avoid serializing the event object in this case because we aren't sure what it is and what it contains
188
196
  log_debug(<<~MSG)
189
197
  Discarded event because before_send didn't return a Sentry::ErrorEvent object but an instance of #{event.class}
@@ -196,10 +204,17 @@ module Sentry
196
204
  if event_type == TransactionEvent::TYPE && configuration.before_send_transaction
197
205
  event = configuration.before_send_transaction.call(event, hint)
198
206
 
199
- if event.is_a?(TransactionEvent)
207
+ if event.is_a?(TransactionEvent) || event.is_a?(Hash)
200
208
  spans_after = event.is_a?(TransactionEvent) ? event.spans.size : 0
201
209
  spans_delta = spans_before - spans_after
202
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
203
218
  else
204
219
  # Avoid serializing the event object in this case because we aren't sure what it is and what it contains
205
220
  log_debug(<<~MSG)
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sentry
4
- VERSION = "5.22.2"
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)
@@ -608,6 +609,11 @@ module Sentry
608
609
  def utc_now
609
610
  Time.now.utc
610
611
  end
612
+
613
+ # @!visibility private
614
+ def dependency_installed?(name)
615
+ Object.const_defined?(name)
616
+ end
611
617
  end
612
618
  end
613
619
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.22.2
4
+ version: 5.22.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-24 00:00:00.000000000 Z
10
+ date: 2025-02-06 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: concurrent-ruby
@@ -150,15 +150,15 @@ files:
150
150
  - lib/sentry/version.rb
151
151
  - sentry-ruby-core.gemspec
152
152
  - sentry-ruby.gemspec
153
- homepage: https://github.com/getsentry/sentry-ruby/tree/5.22.2/sentry-ruby
153
+ homepage: https://github.com/getsentry/sentry-ruby/tree/5.22.4/sentry-ruby
154
154
  licenses:
155
155
  - MIT
156
156
  metadata:
157
- homepage_uri: https://github.com/getsentry/sentry-ruby/tree/5.22.2/sentry-ruby
158
- source_code_uri: https://github.com/getsentry/sentry-ruby/tree/5.22.2/sentry-ruby
159
- changelog_uri: https://github.com/getsentry/sentry-ruby/blob/5.22.2/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
160
160
  bug_tracker_uri: https://github.com/getsentry/sentry-ruby/issues
161
- documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/5.22.2
161
+ documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/5.22.4
162
162
  rdoc_options: []
163
163
  require_paths:
164
164
  - lib