sentry-ruby 5.18.2 → 5.28.1

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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +3 -1
  3. data/Gemfile +9 -3
  4. data/README.md +12 -7
  5. data/Rakefile +9 -11
  6. data/bin/console +1 -0
  7. data/lib/sentry/attachment.rb +40 -0
  8. data/lib/sentry/background_worker.rb +2 -3
  9. data/lib/sentry/backpressure_monitor.rb +1 -1
  10. data/lib/sentry/backtrace.rb +7 -8
  11. data/lib/sentry/baggage.rb +7 -7
  12. data/lib/sentry/breadcrumb/sentry_logger.rb +6 -6
  13. data/lib/sentry/breadcrumb.rb +5 -4
  14. data/lib/sentry/check_in_event.rb +5 -4
  15. data/lib/sentry/client.rb +121 -19
  16. data/lib/sentry/configuration.rb +207 -38
  17. data/lib/sentry/core_ext/object/deep_dup.rb +1 -1
  18. data/lib/sentry/cron/monitor_check_ins.rb +6 -4
  19. data/lib/sentry/cron/monitor_config.rb +1 -1
  20. data/lib/sentry/debug_structured_logger.rb +94 -0
  21. data/lib/sentry/dsn.rb +35 -3
  22. data/lib/sentry/envelope/item.rb +88 -0
  23. data/lib/sentry/envelope.rb +2 -85
  24. data/lib/sentry/event.rb +13 -8
  25. data/lib/sentry/excon/middleware.rb +77 -0
  26. data/lib/sentry/excon.rb +10 -0
  27. data/lib/sentry/faraday.rb +77 -0
  28. data/lib/sentry/graphql.rb +1 -1
  29. data/lib/sentry/hub.rb +57 -4
  30. data/lib/sentry/interfaces/mechanism.rb +1 -1
  31. data/lib/sentry/interfaces/request.rb +6 -6
  32. data/lib/sentry/interfaces/single_exception.rb +3 -3
  33. data/lib/sentry/interfaces/stacktrace.rb +3 -1
  34. data/lib/sentry/interfaces/stacktrace_builder.rb +15 -2
  35. data/lib/sentry/linecache.rb +3 -3
  36. data/lib/sentry/log_event.rb +219 -0
  37. data/lib/sentry/log_event_buffer.rb +75 -0
  38. data/lib/sentry/logger.rb +1 -1
  39. data/lib/sentry/metrics/aggregator.rb +13 -13
  40. data/lib/sentry/metrics/configuration.rb +12 -2
  41. data/lib/sentry/metrics/set_metric.rb +2 -2
  42. data/lib/sentry/metrics/timing.rb +8 -0
  43. data/lib/sentry/metrics.rb +27 -15
  44. data/lib/sentry/net/http.rb +17 -38
  45. data/lib/sentry/profiler/helpers.rb +46 -0
  46. data/lib/sentry/profiler.rb +27 -57
  47. data/lib/sentry/propagation_context.rb +60 -23
  48. data/lib/sentry/rack/capture_exceptions.rb +2 -2
  49. data/lib/sentry/rack.rb +2 -2
  50. data/lib/sentry/rake.rb +2 -2
  51. data/lib/sentry/release_detector.rb +4 -4
  52. data/lib/sentry/rspec.rb +91 -0
  53. data/lib/sentry/scope.rb +27 -2
  54. data/lib/sentry/session_flusher.rb +10 -6
  55. data/lib/sentry/span.rb +17 -4
  56. data/lib/sentry/std_lib_logger.rb +55 -0
  57. data/lib/sentry/structured_logger.rb +138 -0
  58. data/lib/sentry/test_helper.rb +45 -1
  59. data/lib/sentry/threaded_periodic_worker.rb +3 -3
  60. data/lib/sentry/transaction.rb +41 -13
  61. data/lib/sentry/transaction_event.rb +5 -3
  62. data/lib/sentry/transport/debug_transport.rb +70 -0
  63. data/lib/sentry/transport/dummy_transport.rb +1 -0
  64. data/lib/sentry/transport/http_transport.rb +21 -18
  65. data/lib/sentry/transport.rb +26 -11
  66. data/lib/sentry/utils/env_helper.rb +21 -0
  67. data/lib/sentry/utils/http_tracing.rb +74 -0
  68. data/lib/sentry/utils/logging_helper.rb +10 -3
  69. data/lib/sentry/utils/real_ip.rb +1 -1
  70. data/lib/sentry/utils/sample_rand.rb +97 -0
  71. data/lib/sentry/utils/uuid.rb +13 -0
  72. data/lib/sentry/vernier/output.rb +89 -0
  73. data/lib/sentry/vernier/profiler.rb +132 -0
  74. data/lib/sentry/version.rb +1 -1
  75. data/lib/sentry-ruby.rb +106 -12
  76. data/sentry-ruby-core.gemspec +3 -1
  77. data/sentry-ruby.gemspec +4 -2
  78. metadata +28 -12
data/lib/sentry-ruby.rb CHANGED
@@ -10,8 +10,10 @@ require "sentry/core_ext/object/deep_dup"
10
10
  require "sentry/utils/argument_checking_helper"
11
11
  require "sentry/utils/encoding_helper"
12
12
  require "sentry/utils/logging_helper"
13
+ require "sentry/utils/sample_rand"
13
14
  require "sentry/configuration"
14
- require "sentry/logger"
15
+ require "sentry/structured_logger"
16
+ require "sentry/debug_structured_logger"
15
17
  require "sentry/event"
16
18
  require "sentry/error_event"
17
19
  require "sentry/transaction_event"
@@ -25,6 +27,7 @@ require "sentry/session_flusher"
25
27
  require "sentry/backpressure_monitor"
26
28
  require "sentry/cron/monitor_check_ins"
27
29
  require "sentry/metrics"
30
+ require "sentry/vernier/profiler"
28
31
 
29
32
  [
30
33
  "sentry/rake",
@@ -41,14 +44,25 @@ module Sentry
41
44
 
42
45
  CAPTURED_SIGNATURE = :@__sentry_captured
43
46
 
44
- LOGGER_PROGNAME = "sentry".freeze
47
+ LOGGER_PROGNAME = "sentry"
45
48
 
46
- SENTRY_TRACE_HEADER_NAME = "sentry-trace".freeze
49
+ SENTRY_TRACE_HEADER_NAME = "sentry-trace"
47
50
 
48
- BAGGAGE_HEADER_NAME = "baggage".freeze
51
+ BAGGAGE_HEADER_NAME = "baggage"
49
52
 
50
53
  THREAD_LOCAL = :sentry_hub
51
54
 
55
+ MUTEX = Mutex.new
56
+
57
+ GLOBALS = %i[
58
+ main_hub
59
+ logger
60
+ session_flusher
61
+ backpressure_monitor
62
+ metrics_aggregator
63
+ exception_locals_tp
64
+ ].freeze
65
+
52
66
  class << self
53
67
  # @!visibility private
54
68
  def exception_locals_tp
@@ -127,7 +141,7 @@ module Sentry
127
141
  # @param version [String] version of the integration
128
142
  def register_integration(name, version)
129
143
  if initialized?
130
- logger.warn(LOGGER_PROGNAME) do
144
+ sdk_logger.warn(LOGGER_PROGNAME) do
131
145
  <<~MSG
132
146
  Integration '#{name}' is loaded after the SDK is initialized, which can cause unexpected behavior. Please make sure all integrations are loaded before SDK initialization.
133
147
  MSG
@@ -211,6 +225,13 @@ module Sentry
211
225
  get_current_scope.set_context(*args)
212
226
  end
213
227
 
228
+ # @!method add_attachment
229
+ # @!macro add_attachment
230
+ def add_attachment(**opts)
231
+ return unless initialized?
232
+ get_current_scope.add_attachment(**opts)
233
+ end
234
+
214
235
  ##### Main APIs #####
215
236
 
216
237
  # Initializes the SDK with given configuration.
@@ -218,10 +239,11 @@ module Sentry
218
239
  # @yieldparam config [Configuration]
219
240
  # @return [void]
220
241
  def init(&block)
221
- config = Configuration.new
222
- yield(config) if block_given?
242
+ config = Configuration.new(&block)
243
+
223
244
  config.detect_release
224
245
  apply_patches(config)
246
+ config.validate
225
247
  client = Client.new(config)
226
248
  scope = Scope.new(max_breadcrumbs: config.max_breadcrumbs)
227
249
  hub = Hub.new(client, scope)
@@ -267,8 +289,10 @@ module Sentry
267
289
 
268
290
  @background_worker.shutdown
269
291
 
270
- @main_hub = nil
271
- Thread.current.thread_variable_set(THREAD_LOCAL, nil)
292
+ MUTEX.synchronize do
293
+ @main_hub = nil
294
+ Thread.current.thread_variable_set(THREAD_LOCAL, nil)
295
+ end
272
296
  end
273
297
 
274
298
  # Returns true if the SDK is initialized.
@@ -295,6 +319,9 @@ module Sentry
295
319
  #
296
320
  # @return [Hub]
297
321
  def get_main_hub
322
+ MUTEX.synchronize { @main_hub }
323
+ rescue ThreadError
324
+ # In some rare cases this may be called in a trap context so we need to handle it gracefully
298
325
  @main_hub
299
326
  end
300
327
 
@@ -465,6 +492,26 @@ module Sentry
465
492
  get_current_hub.capture_check_in(slug, status, **options)
466
493
  end
467
494
 
495
+ # Captures a log event and sends it to Sentry via the currently active hub.
496
+ # This is the underlying method used by the StructuredLogger class.
497
+ #
498
+ # @param message [String] the log message
499
+ # @param [Hash] options Extra log event options
500
+ # @option options [Symbol] level The log level (:trace, :debug, :info, :warn, :error, :fatal)
501
+ # @option options [Integer] severity The severity number according to the Sentry Logs Protocol
502
+ # @option options [String] origin The origin of the log event (e.g., "auto.db.rails", "manual")
503
+ # @option options [Hash] Additional attributes to include with the log
504
+ #
505
+ # @example Direct usage (prefer using Sentry.logger instead)
506
+ # Sentry.capture_log("User logged in", level: :info, user_id: 123)
507
+ #
508
+ # @see https://develop.sentry.dev/sdk/telemetry/logs/ Sentry SDK Telemetry Logs Protocol
509
+ # @return [LogEvent, nil] The created log event or nil if logging is disabled
510
+ def capture_log(message, **options)
511
+ return unless initialized?
512
+ get_current_hub.capture_log_event(message, **options)
513
+ end
514
+
468
515
  # Takes or initializes a new Sentry::Transaction and makes a sampling decision for it.
469
516
  #
470
517
  # @return [Transaction, nil]
@@ -556,7 +603,7 @@ module Sentry
556
603
  #
557
604
  # @return [String]
558
605
  def get_trace_propagation_meta
559
- return '' unless initialized?
606
+ return "" unless initialized?
560
607
  get_current_hub.get_trace_propagation_meta
561
608
  end
562
609
 
@@ -569,6 +616,45 @@ module Sentry
569
616
  get_current_hub.continue_trace(env, **options)
570
617
  end
571
618
 
619
+ # Returns the structured logger instance that implements Sentry's SDK telemetry logs protocol.
620
+ #
621
+ # This logger is only available when logs are enabled in the configuration.
622
+ #
623
+ # @example Enable logs in configuration
624
+ # Sentry.init do |config|
625
+ # config.dsn = "YOUR_DSN"
626
+ # config.enable_logs = true
627
+ # end
628
+ #
629
+ # @example Basic usage
630
+ # Sentry.logger.info("User logged in successfully", user_id: 123)
631
+ # Sentry.logger.error("Failed to process payment",
632
+ # transaction_id: "tx_123",
633
+ # error_code: "PAYMENT_FAILED"
634
+ # )
635
+ #
636
+ # @see https://develop.sentry.dev/sdk/telemetry/logs/ Sentry SDK Telemetry Logs Protocol
637
+ #
638
+ # @return [StructuredLogger, nil] The structured logger instance or nil if logs are disabled
639
+ def logger
640
+ @logger ||=
641
+ if configuration.enable_logs
642
+ # Initialize the public-facing Structured Logger if logs are enabled
643
+ # Use configured structured logger class or default to StructuredLogger
644
+ # @see https://develop.sentry.dev/sdk/telemetry/logs/
645
+ configuration.structured_logging.logger_class.new(configuration)
646
+ else
647
+ warn <<~STR
648
+ [sentry] `Sentry.logger` will no longer be used as internal SDK logger when `enable_logs` feature is turned on.
649
+ Use Sentry.configuration.sdk_logger for SDK-specific logging needs."
650
+
651
+ Caller: #{caller.first}
652
+ STR
653
+
654
+ configuration.sdk_logger
655
+ end
656
+ end
657
+
572
658
  ##### Helpers #####
573
659
 
574
660
  # @!visibility private
@@ -580,8 +666,8 @@ module Sentry
580
666
  end
581
667
 
582
668
  # @!visibility private
583
- def logger
584
- configuration.logger
669
+ def sdk_logger
670
+ configuration.sdk_logger
585
671
  end
586
672
 
587
673
  # @!visibility private
@@ -593,6 +679,11 @@ module Sentry
593
679
  def utc_now
594
680
  Time.now.utc
595
681
  end
682
+
683
+ # @!visibility private
684
+ def dependency_installed?(name)
685
+ Object.const_defined?(name)
686
+ end
596
687
  end
597
688
  end
598
689
 
@@ -601,3 +692,6 @@ require "sentry/net/http"
601
692
  require "sentry/redis"
602
693
  require "sentry/puma"
603
694
  require "sentry/graphql"
695
+ require "sentry/faraday"
696
+ require "sentry/excon"
697
+ require "sentry/std_lib_logger"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "lib/sentry/version"
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -12,7 +14,7 @@ Gem::Specification.new do |spec|
12
14
  spec.platform = Gem::Platform::RUBY
13
15
  spec.required_ruby_version = '>= 2.4'
14
16
  spec.extra_rdoc_files = ["README.md", "LICENSE.txt"]
15
- spec.files = `git ls-files | grep -Ev '^(spec|benchmarks|examples)'`.split("\n")
17
+ spec.files = `git ls-files | grep -Ev '^(spec|benchmarks|examples|\.rubocop\.yml)'`.split("\n")
16
18
 
17
19
  spec.metadata["homepage_uri"] = spec.homepage
18
20
  spec.metadata["source_code_uri"] = spec.homepage
data/sentry-ruby.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "lib/sentry/version"
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -11,7 +13,7 @@ Gem::Specification.new do |spec|
11
13
  spec.platform = Gem::Platform::RUBY
12
14
  spec.required_ruby_version = '>= 2.4'
13
15
  spec.extra_rdoc_files = ["README.md", "LICENSE.txt"]
14
- spec.files = `git ls-files | grep -Ev '^(spec|benchmarks|examples)'`.split("\n")
16
+ spec.files = `git ls-files | grep -Ev '^(spec|benchmarks|examples|\.rubocop\.yml)'`.split("\n")
15
17
 
16
18
  github_root_uri = 'https://github.com/getsentry/sentry-ruby'
17
19
  spec.homepage = "#{github_root_uri}/tree/#{spec.version}/#{spec.name}"
@@ -26,6 +28,6 @@ Gem::Specification.new do |spec|
26
28
 
27
29
  spec.require_paths = ["lib"]
28
30
 
29
- spec.add_dependency "concurrent-ruby", '~> 1.0', '>= 1.0.2'
31
+ spec.add_dependency "concurrent-ruby", "~> 1.0", ">= 1.0.2"
30
32
  spec.add_dependency "bigdecimal"
31
33
  end
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.18.2
4
+ version: 5.28.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-07-23 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: concurrent-ruby
@@ -49,8 +48,8 @@ email: accounts@sentry.io
49
48
  executables: []
50
49
  extensions: []
51
50
  extra_rdoc_files:
52
- - README.md
53
51
  - LICENSE.txt
52
+ - README.md
54
53
  files:
55
54
  - ".gitignore"
56
55
  - ".rspec"
@@ -64,6 +63,7 @@ files:
64
63
  - bin/console
65
64
  - bin/setup
66
65
  - lib/sentry-ruby.rb
66
+ - lib/sentry/attachment.rb
67
67
  - lib/sentry/background_worker.rb
68
68
  - lib/sentry/backpressure_monitor.rb
69
69
  - lib/sentry/backtrace.rb
@@ -80,11 +80,16 @@ files:
80
80
  - lib/sentry/cron/monitor_check_ins.rb
81
81
  - lib/sentry/cron/monitor_config.rb
82
82
  - lib/sentry/cron/monitor_schedule.rb
83
+ - lib/sentry/debug_structured_logger.rb
83
84
  - lib/sentry/dsn.rb
84
85
  - lib/sentry/envelope.rb
86
+ - lib/sentry/envelope/item.rb
85
87
  - lib/sentry/error_event.rb
86
88
  - lib/sentry/event.rb
87
89
  - lib/sentry/exceptions.rb
90
+ - lib/sentry/excon.rb
91
+ - lib/sentry/excon/middleware.rb
92
+ - lib/sentry/faraday.rb
88
93
  - lib/sentry/graphql.rb
89
94
  - lib/sentry/hub.rb
90
95
  - lib/sentry/integrable.rb
@@ -97,6 +102,8 @@ files:
97
102
  - lib/sentry/interfaces/stacktrace_builder.rb
98
103
  - lib/sentry/interfaces/threads.rb
99
104
  - lib/sentry/linecache.rb
105
+ - lib/sentry/log_event.rb
106
+ - lib/sentry/log_event_buffer.rb
100
107
  - lib/sentry/logger.rb
101
108
  - lib/sentry/metrics.rb
102
109
  - lib/sentry/metrics/aggregator.rb
@@ -110,6 +117,7 @@ files:
110
117
  - lib/sentry/metrics/timing.rb
111
118
  - lib/sentry/net/http.rb
112
119
  - lib/sentry/profiler.rb
120
+ - lib/sentry/profiler/helpers.rb
113
121
  - lib/sentry/propagation_context.rb
114
122
  - lib/sentry/puma.rb
115
123
  - lib/sentry/rack.rb
@@ -117,39 +125,48 @@ files:
117
125
  - lib/sentry/rake.rb
118
126
  - lib/sentry/redis.rb
119
127
  - lib/sentry/release_detector.rb
128
+ - lib/sentry/rspec.rb
120
129
  - lib/sentry/scope.rb
121
130
  - lib/sentry/session.rb
122
131
  - lib/sentry/session_flusher.rb
123
132
  - lib/sentry/span.rb
133
+ - lib/sentry/std_lib_logger.rb
134
+ - lib/sentry/structured_logger.rb
124
135
  - lib/sentry/test_helper.rb
125
136
  - lib/sentry/threaded_periodic_worker.rb
126
137
  - lib/sentry/transaction.rb
127
138
  - lib/sentry/transaction_event.rb
128
139
  - lib/sentry/transport.rb
129
140
  - lib/sentry/transport/configuration.rb
141
+ - lib/sentry/transport/debug_transport.rb
130
142
  - lib/sentry/transport/dummy_transport.rb
131
143
  - lib/sentry/transport/http_transport.rb
132
144
  - lib/sentry/transport/spotlight_transport.rb
133
145
  - lib/sentry/utils/argument_checking_helper.rb
134
146
  - lib/sentry/utils/custom_inspection.rb
135
147
  - lib/sentry/utils/encoding_helper.rb
148
+ - lib/sentry/utils/env_helper.rb
136
149
  - lib/sentry/utils/exception_cause_chain.rb
150
+ - lib/sentry/utils/http_tracing.rb
137
151
  - lib/sentry/utils/logging_helper.rb
138
152
  - lib/sentry/utils/real_ip.rb
139
153
  - lib/sentry/utils/request_id.rb
154
+ - lib/sentry/utils/sample_rand.rb
155
+ - lib/sentry/utils/uuid.rb
156
+ - lib/sentry/vernier/output.rb
157
+ - lib/sentry/vernier/profiler.rb
140
158
  - lib/sentry/version.rb
141
159
  - sentry-ruby-core.gemspec
142
160
  - sentry-ruby.gemspec
143
- homepage: https://github.com/getsentry/sentry-ruby/tree/5.18.2/sentry-ruby
161
+ homepage: https://github.com/getsentry/sentry-ruby/tree/5.28.1/sentry-ruby
144
162
  licenses:
145
163
  - MIT
146
164
  metadata:
147
- homepage_uri: https://github.com/getsentry/sentry-ruby/tree/5.18.2/sentry-ruby
148
- source_code_uri: https://github.com/getsentry/sentry-ruby/tree/5.18.2/sentry-ruby
149
- changelog_uri: https://github.com/getsentry/sentry-ruby/blob/5.18.2/CHANGELOG.md
165
+ homepage_uri: https://github.com/getsentry/sentry-ruby/tree/5.28.1/sentry-ruby
166
+ source_code_uri: https://github.com/getsentry/sentry-ruby/tree/5.28.1/sentry-ruby
167
+ changelog_uri: https://github.com/getsentry/sentry-ruby/blob/5.28.1/CHANGELOG.md
150
168
  bug_tracker_uri: https://github.com/getsentry/sentry-ruby/issues
151
- documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/5.18.2
152
- post_install_message:
169
+ documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/5.28.1
153
170
  rdoc_options: []
154
171
  require_paths:
155
172
  - lib
@@ -164,8 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
181
  - !ruby/object:Gem::Version
165
182
  version: '0'
166
183
  requirements: []
167
- rubygems_version: 3.5.11
168
- signing_key:
184
+ rubygems_version: 3.6.9
169
185
  specification_version: 4
170
186
  summary: A gem that provides a client interface for the Sentry error logger
171
187
  test_files: []