sentry-ruby 5.23.0 → 5.27.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +3 -1
  3. data/Gemfile +1 -3
  4. data/README.md +11 -6
  5. data/Rakefile +7 -11
  6. data/lib/sentry/background_worker.rb +2 -3
  7. data/lib/sentry/backpressure_monitor.rb +1 -1
  8. data/lib/sentry/breadcrumb.rb +5 -4
  9. data/lib/sentry/check_in_event.rb +2 -1
  10. data/lib/sentry/client.rb +84 -4
  11. data/lib/sentry/configuration.rb +63 -2
  12. data/lib/sentry/debug_structured_logger.rb +94 -0
  13. data/lib/sentry/dsn.rb +32 -0
  14. data/lib/sentry/envelope/item.rb +1 -1
  15. data/lib/sentry/event.rb +2 -1
  16. data/lib/sentry/hub.rb +13 -1
  17. data/lib/sentry/interfaces/request.rb +1 -1
  18. data/lib/sentry/log_event.rb +206 -0
  19. data/lib/sentry/log_event_buffer.rb +75 -0
  20. data/lib/sentry/metrics/aggregator.rb +1 -1
  21. data/lib/sentry/profiler.rb +3 -2
  22. data/lib/sentry/propagation_context.rb +59 -22
  23. data/lib/sentry/scope.rb +13 -3
  24. data/lib/sentry/session_flusher.rb +1 -1
  25. data/lib/sentry/span.rb +4 -3
  26. data/lib/sentry/std_lib_logger.rb +50 -0
  27. data/lib/sentry/structured_logger.rb +138 -0
  28. data/lib/sentry/test_helper.rb +29 -0
  29. data/lib/sentry/threaded_periodic_worker.rb +3 -3
  30. data/lib/sentry/transaction.rb +30 -8
  31. data/lib/sentry/transport/debug_transport.rb +70 -0
  32. data/lib/sentry/transport/dummy_transport.rb +1 -0
  33. data/lib/sentry/transport/http_transport.rb +9 -5
  34. data/lib/sentry/transport.rb +17 -8
  35. data/lib/sentry/utils/logging_helper.rb +10 -3
  36. data/lib/sentry/utils/sample_rand.rb +97 -0
  37. data/lib/sentry/utils/uuid.rb +13 -0
  38. data/lib/sentry/vernier/profiler.rb +3 -2
  39. data/lib/sentry/version.rb +1 -1
  40. data/lib/sentry-ruby.rb +67 -4
  41. metadata +17 -9
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"
@@ -54,6 +56,7 @@ module Sentry
54
56
 
55
57
  GLOBALS = %i[
56
58
  main_hub
59
+ logger
57
60
  session_flusher
58
61
  backpressure_monitor
59
62
  metrics_aggregator
@@ -138,7 +141,7 @@ module Sentry
138
141
  # @param version [String] version of the integration
139
142
  def register_integration(name, version)
140
143
  if initialized?
141
- logger.warn(LOGGER_PROGNAME) do
144
+ sdk_logger.warn(LOGGER_PROGNAME) do
142
145
  <<~MSG
143
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.
144
147
  MSG
@@ -238,6 +241,7 @@ module Sentry
238
241
  def init(&block)
239
242
  config = Configuration.new
240
243
  yield(config) if block_given?
244
+
241
245
  config.detect_release
242
246
  apply_patches(config)
243
247
  config.validate
@@ -489,6 +493,25 @@ module Sentry
489
493
  get_current_hub.capture_check_in(slug, status, **options)
490
494
  end
491
495
 
496
+ # Captures a log event and sends it to Sentry via the currently active hub.
497
+ # This is the underlying method used by the StructuredLogger class.
498
+ #
499
+ # @param message [String] the log message
500
+ # @param [Hash] options Extra log event options
501
+ # @option options [Symbol] level The log level (:trace, :debug, :info, :warn, :error, :fatal)
502
+ # @option options [Integer] severity The severity number according to the Sentry Logs Protocol
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
+
492
515
  # Takes or initializes a new Sentry::Transaction and makes a sampling decision for it.
493
516
  #
494
517
  # @return [Transaction, nil]
@@ -593,6 +616,45 @@ module Sentry
593
616
  get_current_hub.continue_trace(env, **options)
594
617
  end
595
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
+
596
658
  ##### Helpers #####
597
659
 
598
660
  # @!visibility private
@@ -604,8 +666,8 @@ module Sentry
604
666
  end
605
667
 
606
668
  # @!visibility private
607
- def logger
608
- configuration.logger
669
+ def sdk_logger
670
+ configuration.sdk_logger
609
671
  end
610
672
 
611
673
  # @!visibility private
@@ -632,3 +694,4 @@ require "sentry/puma"
632
694
  require "sentry/graphql"
633
695
  require "sentry/faraday"
634
696
  require "sentry/excon"
697
+ require "sentry/std_lib_logger"
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.23.0
4
+ version: 5.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-11 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: concurrent-ruby
@@ -48,8 +48,8 @@ email: accounts@sentry.io
48
48
  executables: []
49
49
  extensions: []
50
50
  extra_rdoc_files:
51
- - README.md
52
51
  - LICENSE.txt
52
+ - README.md
53
53
  files:
54
54
  - ".gitignore"
55
55
  - ".rspec"
@@ -80,6 +80,7 @@ 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
85
86
  - lib/sentry/envelope/item.rb
@@ -101,6 +102,8 @@ files:
101
102
  - lib/sentry/interfaces/stacktrace_builder.rb
102
103
  - lib/sentry/interfaces/threads.rb
103
104
  - lib/sentry/linecache.rb
105
+ - lib/sentry/log_event.rb
106
+ - lib/sentry/log_event_buffer.rb
104
107
  - lib/sentry/logger.rb
105
108
  - lib/sentry/metrics.rb
106
109
  - lib/sentry/metrics/aggregator.rb
@@ -127,12 +130,15 @@ files:
127
130
  - lib/sentry/session.rb
128
131
  - lib/sentry/session_flusher.rb
129
132
  - lib/sentry/span.rb
133
+ - lib/sentry/std_lib_logger.rb
134
+ - lib/sentry/structured_logger.rb
130
135
  - lib/sentry/test_helper.rb
131
136
  - lib/sentry/threaded_periodic_worker.rb
132
137
  - lib/sentry/transaction.rb
133
138
  - lib/sentry/transaction_event.rb
134
139
  - lib/sentry/transport.rb
135
140
  - lib/sentry/transport/configuration.rb
141
+ - lib/sentry/transport/debug_transport.rb
136
142
  - lib/sentry/transport/dummy_transport.rb
137
143
  - lib/sentry/transport/http_transport.rb
138
144
  - lib/sentry/transport/spotlight_transport.rb
@@ -145,20 +151,22 @@ files:
145
151
  - lib/sentry/utils/logging_helper.rb
146
152
  - lib/sentry/utils/real_ip.rb
147
153
  - lib/sentry/utils/request_id.rb
154
+ - lib/sentry/utils/sample_rand.rb
155
+ - lib/sentry/utils/uuid.rb
148
156
  - lib/sentry/vernier/output.rb
149
157
  - lib/sentry/vernier/profiler.rb
150
158
  - lib/sentry/version.rb
151
159
  - sentry-ruby-core.gemspec
152
160
  - sentry-ruby.gemspec
153
- homepage: https://github.com/getsentry/sentry-ruby/tree/5.23.0/sentry-ruby
161
+ homepage: https://github.com/getsentry/sentry-ruby/tree/5.27.0/sentry-ruby
154
162
  licenses:
155
163
  - MIT
156
164
  metadata:
157
- homepage_uri: https://github.com/getsentry/sentry-ruby/tree/5.23.0/sentry-ruby
158
- source_code_uri: https://github.com/getsentry/sentry-ruby/tree/5.23.0/sentry-ruby
159
- changelog_uri: https://github.com/getsentry/sentry-ruby/blob/5.23.0/CHANGELOG.md
165
+ homepage_uri: https://github.com/getsentry/sentry-ruby/tree/5.27.0/sentry-ruby
166
+ source_code_uri: https://github.com/getsentry/sentry-ruby/tree/5.27.0/sentry-ruby
167
+ changelog_uri: https://github.com/getsentry/sentry-ruby/blob/5.27.0/CHANGELOG.md
160
168
  bug_tracker_uri: https://github.com/getsentry/sentry-ruby/issues
161
- documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/5.23.0
169
+ documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/5.27.0
162
170
  rdoc_options: []
163
171
  require_paths:
164
172
  - lib
@@ -173,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
181
  - !ruby/object:Gem::Version
174
182
  version: '0'
175
183
  requirements: []
176
- rubygems_version: 3.6.2
184
+ rubygems_version: 3.6.9
177
185
  specification_version: 4
178
186
  summary: A gem that provides a client interface for the Sentry error logger
179
187
  test_files: []