sentry-ruby 5.22.4 → 5.26.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.
- checksums.yaml +4 -4
- data/.rspec +3 -1
- data/Gemfile +4 -3
- data/README.md +11 -6
- data/Rakefile +7 -11
- data/lib/sentry/background_worker.rb +2 -3
- data/lib/sentry/backpressure_monitor.rb +1 -1
- data/lib/sentry/backtrace.rb +1 -1
- data/lib/sentry/breadcrumb.rb +5 -4
- data/lib/sentry/check_in_event.rb +2 -1
- data/lib/sentry/client.rb +84 -4
- data/lib/sentry/configuration.rb +44 -2
- data/lib/sentry/envelope/item.rb +1 -1
- data/lib/sentry/event.rb +2 -1
- data/lib/sentry/hub.rb +41 -1
- data/lib/sentry/interfaces/request.rb +1 -1
- data/lib/sentry/linecache.rb +3 -3
- data/lib/sentry/log_event.rb +206 -0
- data/lib/sentry/log_event_buffer.rb +75 -0
- data/lib/sentry/metrics/aggregator.rb +1 -1
- data/lib/sentry/profiler.rb +3 -2
- data/lib/sentry/propagation_context.rb +4 -4
- data/lib/sentry/scope.rb +13 -3
- data/lib/sentry/session_flusher.rb +1 -1
- data/lib/sentry/span.rb +4 -3
- data/lib/sentry/std_lib_logger.rb +50 -0
- data/lib/sentry/structured_logger.rb +138 -0
- data/lib/sentry/test_helper.rb +20 -0
- data/lib/sentry/threaded_periodic_worker.rb +3 -3
- data/lib/sentry/transaction.rb +9 -9
- data/lib/sentry/transaction_event.rb +4 -1
- data/lib/sentry/transport/http_transport.rb +0 -1
- data/lib/sentry/transport.rb +16 -8
- data/lib/sentry/utils/http_tracing.rb +15 -1
- data/lib/sentry/utils/logging_helper.rb +10 -3
- data/lib/sentry/utils/uuid.rb +13 -0
- data/lib/sentry/vernier/profiler.rb +6 -4
- data/lib/sentry/version.rb +1 -1
- data/lib/sentry-ruby.rb +71 -4
- metadata +14 -9
data/lib/sentry/transaction.rb
CHANGED
@@ -45,9 +45,6 @@ module Sentry
|
|
45
45
|
# @deprecated Use Sentry.configuration instead.
|
46
46
|
attr_reader :configuration
|
47
47
|
|
48
|
-
# @deprecated Use Sentry.logger instead.
|
49
|
-
attr_reader :logger
|
50
|
-
|
51
48
|
# The effective sample rate at which this transaction was sampled.
|
52
49
|
# @return [Float, nil]
|
53
50
|
attr_reader :effective_sample_rate
|
@@ -78,14 +75,18 @@ module Sentry
|
|
78
75
|
@tracing_enabled = hub.configuration.tracing_enabled?
|
79
76
|
@traces_sampler = hub.configuration.traces_sampler
|
80
77
|
@traces_sample_rate = hub.configuration.traces_sample_rate
|
81
|
-
@
|
78
|
+
@sdk_logger = hub.configuration.sdk_logger
|
82
79
|
@release = hub.configuration.release
|
83
80
|
@environment = hub.configuration.environment
|
84
81
|
@dsn = hub.configuration.dsn
|
85
82
|
@effective_sample_rate = nil
|
86
83
|
@contexts = {}
|
87
84
|
@measurements = {}
|
88
|
-
|
85
|
+
|
86
|
+
unless @hub.profiler_running?
|
87
|
+
@profiler = @configuration.profiler_class.new(@configuration)
|
88
|
+
end
|
89
|
+
|
89
90
|
init_span_recorder
|
90
91
|
end
|
91
92
|
|
@@ -257,7 +258,7 @@ module Sentry
|
|
257
258
|
@name = UNLABELD_NAME
|
258
259
|
end
|
259
260
|
|
260
|
-
@
|
261
|
+
@hub.stop_profiler!(self)
|
261
262
|
|
262
263
|
if @sampled
|
263
264
|
event = hub.current_client.event_from_transaction(self)
|
@@ -299,6 +300,8 @@ module Sentry
|
|
299
300
|
# Start the profiler.
|
300
301
|
# @return [void]
|
301
302
|
def start_profiler!
|
303
|
+
return unless profiler
|
304
|
+
|
302
305
|
profiler.set_initial_sample_decision(sampled)
|
303
306
|
profiler.start
|
304
307
|
end
|
@@ -336,9 +339,6 @@ module Sentry
|
|
336
339
|
|
337
340
|
items["transaction"] = name unless source_low_quality?
|
338
341
|
|
339
|
-
user = @hub.current_scope&.user
|
340
|
-
items["user_segment"] = user["segment"] if user && user["segment"]
|
341
|
-
|
342
342
|
items.compact!
|
343
343
|
@baggage = Baggage.new(items, mutable: false)
|
344
344
|
end
|
@@ -59,8 +59,11 @@ module Sentry
|
|
59
59
|
|
60
60
|
private
|
61
61
|
|
62
|
+
EMPTY_PROFILE = {}.freeze
|
63
|
+
|
62
64
|
def populate_profile(transaction)
|
63
|
-
profile_hash = transaction.profiler
|
65
|
+
profile_hash = transaction.profiler&.to_hash || EMPTY_PROFILE
|
66
|
+
|
64
67
|
return if profile_hash.empty?
|
65
68
|
|
66
69
|
profile_hash.merge!(
|
data/lib/sentry/transport.rb
CHANGED
@@ -26,11 +26,8 @@ module Sentry
|
|
26
26
|
|
27
27
|
attr_reader :rate_limits, :discarded_events, :last_client_report_sent
|
28
28
|
|
29
|
-
# @deprecated Use Sentry.logger to retrieve the current logger instead.
|
30
|
-
attr_reader :logger
|
31
|
-
|
32
29
|
def initialize(configuration)
|
33
|
-
@
|
30
|
+
@sdk_logger = configuration.sdk_logger
|
34
31
|
@transport_configuration = configuration.transport
|
35
32
|
@dsn = configuration.dsn
|
36
33
|
@rate_limits = {}
|
@@ -133,10 +130,21 @@ module Sentry
|
|
133
130
|
|
134
131
|
envelope = Envelope.new(envelope_headers)
|
135
132
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
133
|
+
if event.is_a?(LogEvent)
|
134
|
+
envelope.add_item(
|
135
|
+
{
|
136
|
+
type: "log",
|
137
|
+
item_count: 1,
|
138
|
+
content_type: "application/vnd.sentry.items.log+json"
|
139
|
+
},
|
140
|
+
{ items: [event_payload] }
|
141
|
+
)
|
142
|
+
else
|
143
|
+
envelope.add_item(
|
144
|
+
{ type: item_type, content_type: "application/json" },
|
145
|
+
event_payload
|
146
|
+
)
|
147
|
+
end
|
140
148
|
|
141
149
|
if event.is_a?(TransactionEvent) && event.profile
|
142
150
|
envelope.add_item(
|
@@ -17,7 +17,7 @@ module Sentry
|
|
17
17
|
|
18
18
|
def record_sentry_breadcrumb(request_info, response_status)
|
19
19
|
crumb = Sentry::Breadcrumb.new(
|
20
|
-
level:
|
20
|
+
level: get_level(response_status),
|
21
21
|
category: self.class::BREADCRUMB_CATEGORY,
|
22
22
|
type: "info",
|
23
23
|
data: { status: response_status, **request_info }
|
@@ -55,6 +55,20 @@ module Sentry
|
|
55
55
|
"#{URI.encode_www_form_component(prefix)}=#{URI.encode_www_form_component(value)}"
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def get_level(status)
|
62
|
+
return :info unless status && status.is_a?(Integer)
|
63
|
+
|
64
|
+
if status >= 500
|
65
|
+
:error
|
66
|
+
elsif status >= 400
|
67
|
+
:warning
|
68
|
+
else
|
69
|
+
:info
|
70
|
+
end
|
71
|
+
end
|
58
72
|
end
|
59
73
|
end
|
60
74
|
end
|
@@ -1,22 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Sentry
|
4
|
+
# @private
|
4
5
|
module LoggingHelper
|
6
|
+
# @!visibility private
|
7
|
+
attr_reader :sdk_logger
|
8
|
+
|
9
|
+
# @!visibility private
|
5
10
|
def log_error(message, exception, debug: false)
|
6
11
|
message = "#{message}: #{exception.message}"
|
7
12
|
message += "\n#{exception.backtrace.join("\n")}" if debug
|
8
13
|
|
9
|
-
|
14
|
+
sdk_logger.error(LOGGER_PROGNAME) do
|
10
15
|
message
|
11
16
|
end
|
12
17
|
end
|
13
18
|
|
19
|
+
# @!visibility private
|
14
20
|
def log_debug(message)
|
15
|
-
|
21
|
+
sdk_logger.debug(LOGGER_PROGNAME) { message }
|
16
22
|
end
|
17
23
|
|
24
|
+
# @!visibility private
|
18
25
|
def log_warn(message)
|
19
|
-
|
26
|
+
sdk_logger.warn(LOGGER_PROGNAME) { message }
|
20
27
|
end
|
21
28
|
end
|
22
29
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require "securerandom"
|
4
4
|
require_relative "../profiler/helpers"
|
5
5
|
require_relative "output"
|
6
|
+
require "sentry/utils/uuid"
|
6
7
|
|
7
8
|
module Sentry
|
8
9
|
module Vernier
|
@@ -12,7 +13,7 @@ module Sentry
|
|
12
13
|
attr_reader :started, :event_id, :result
|
13
14
|
|
14
15
|
def initialize(configuration)
|
15
|
-
@event_id =
|
16
|
+
@event_id = Utils.uuid
|
16
17
|
|
17
18
|
@started = false
|
18
19
|
@sampled = nil
|
@@ -74,6 +75,7 @@ module Sentry
|
|
74
75
|
return unless @started
|
75
76
|
|
76
77
|
@result = ::Vernier.stop_profile
|
78
|
+
@started = false
|
77
79
|
|
78
80
|
log("Stopped")
|
79
81
|
rescue RuntimeError => e
|
@@ -89,20 +91,20 @@ module Sentry
|
|
89
91
|
end
|
90
92
|
|
91
93
|
def to_hash
|
92
|
-
return EMPTY_RESULT unless @started
|
93
|
-
|
94
94
|
unless @sampled
|
95
95
|
record_lost_event(:sample_rate)
|
96
96
|
return EMPTY_RESULT
|
97
97
|
end
|
98
98
|
|
99
|
+
return EMPTY_RESULT unless result
|
100
|
+
|
99
101
|
{ **profile_meta, profile: output.to_h }
|
100
102
|
end
|
101
103
|
|
102
104
|
private
|
103
105
|
|
104
106
|
def log(message)
|
105
|
-
Sentry.
|
107
|
+
Sentry.sdk_logger.debug(LOGGER_PROGNAME) { "[Profiler::Vernier] #{message}" }
|
106
108
|
end
|
107
109
|
|
108
110
|
def record_lost_event(reason)
|
data/lib/sentry/version.rb
CHANGED
data/lib/sentry-ruby.rb
CHANGED
@@ -11,7 +11,7 @@ require "sentry/utils/argument_checking_helper"
|
|
11
11
|
require "sentry/utils/encoding_helper"
|
12
12
|
require "sentry/utils/logging_helper"
|
13
13
|
require "sentry/configuration"
|
14
|
-
require "sentry/
|
14
|
+
require "sentry/structured_logger"
|
15
15
|
require "sentry/event"
|
16
16
|
require "sentry/error_event"
|
17
17
|
require "sentry/transaction_event"
|
@@ -52,6 +52,15 @@ module Sentry
|
|
52
52
|
|
53
53
|
MUTEX = Mutex.new
|
54
54
|
|
55
|
+
GLOBALS = %i[
|
56
|
+
main_hub
|
57
|
+
logger
|
58
|
+
session_flusher
|
59
|
+
backpressure_monitor
|
60
|
+
metrics_aggregator
|
61
|
+
exception_locals_tp
|
62
|
+
].freeze
|
63
|
+
|
55
64
|
class << self
|
56
65
|
# @!visibility private
|
57
66
|
def exception_locals_tp
|
@@ -130,7 +139,7 @@ module Sentry
|
|
130
139
|
# @param version [String] version of the integration
|
131
140
|
def register_integration(name, version)
|
132
141
|
if initialized?
|
133
|
-
|
142
|
+
sdk_logger.warn(LOGGER_PROGNAME) do
|
134
143
|
<<~MSG
|
135
144
|
Integration '#{name}' is loaded after the SDK is initialized, which can cause unexpected behavior. Please make sure all integrations are loaded before SDK initialization.
|
136
145
|
MSG
|
@@ -230,6 +239,7 @@ module Sentry
|
|
230
239
|
def init(&block)
|
231
240
|
config = Configuration.new
|
232
241
|
yield(config) if block_given?
|
242
|
+
|
233
243
|
config.detect_release
|
234
244
|
apply_patches(config)
|
235
245
|
config.validate
|
@@ -481,6 +491,25 @@ module Sentry
|
|
481
491
|
get_current_hub.capture_check_in(slug, status, **options)
|
482
492
|
end
|
483
493
|
|
494
|
+
# Captures a log event and sends it to Sentry via the currently active hub.
|
495
|
+
# This is the underlying method used by the StructuredLogger class.
|
496
|
+
#
|
497
|
+
# @param message [String] the log message
|
498
|
+
# @param [Hash] options Extra log event options
|
499
|
+
# @option options [Symbol] level The log level (:trace, :debug, :info, :warn, :error, :fatal)
|
500
|
+
# @option options [Integer] severity The severity number according to the Sentry Logs Protocol
|
501
|
+
# @option options [Hash] Additional attributes to include with the log
|
502
|
+
#
|
503
|
+
# @example Direct usage (prefer using Sentry.logger instead)
|
504
|
+
# Sentry.capture_log("User logged in", level: :info, user_id: 123)
|
505
|
+
#
|
506
|
+
# @see https://develop.sentry.dev/sdk/telemetry/logs/ Sentry SDK Telemetry Logs Protocol
|
507
|
+
# @return [LogEvent, nil] The created log event or nil if logging is disabled
|
508
|
+
def capture_log(message, **options)
|
509
|
+
return unless initialized?
|
510
|
+
get_current_hub.capture_log_event(message, **options)
|
511
|
+
end
|
512
|
+
|
484
513
|
# Takes or initializes a new Sentry::Transaction and makes a sampling decision for it.
|
485
514
|
#
|
486
515
|
# @return [Transaction, nil]
|
@@ -585,6 +614,43 @@ module Sentry
|
|
585
614
|
get_current_hub.continue_trace(env, **options)
|
586
615
|
end
|
587
616
|
|
617
|
+
# Returns the structured logger instance that implements Sentry's SDK telemetry logs protocol.
|
618
|
+
#
|
619
|
+
# This logger is only available when logs are enabled in the configuration.
|
620
|
+
#
|
621
|
+
# @example Enable logs in configuration
|
622
|
+
# Sentry.init do |config|
|
623
|
+
# config.dsn = "YOUR_DSN"
|
624
|
+
# config.enable_logs = true
|
625
|
+
# end
|
626
|
+
#
|
627
|
+
# @example Basic usage
|
628
|
+
# Sentry.logger.info("User logged in successfully", user_id: 123)
|
629
|
+
# Sentry.logger.error("Failed to process payment",
|
630
|
+
# transaction_id: "tx_123",
|
631
|
+
# error_code: "PAYMENT_FAILED"
|
632
|
+
# )
|
633
|
+
#
|
634
|
+
# @see https://develop.sentry.dev/sdk/telemetry/logs/ Sentry SDK Telemetry Logs Protocol
|
635
|
+
#
|
636
|
+
# @return [StructuredLogger, nil] The structured logger instance or nil if logs are disabled
|
637
|
+
def logger
|
638
|
+
@logger ||=
|
639
|
+
if configuration.enable_logs
|
640
|
+
# Initialize the public-facing Structured Logger if logs are enabled
|
641
|
+
# This creates a StructuredLogger instance that implements Sentry's SDK telemetry logs protocol
|
642
|
+
# @see https://develop.sentry.dev/sdk/telemetry/logs/
|
643
|
+
StructuredLogger.new(configuration)
|
644
|
+
else
|
645
|
+
warn <<~STR
|
646
|
+
[sentry] `Sentry.logger` will no longer be used as internal SDK logger when `enable_logs` feature is turned on.
|
647
|
+
Use Sentry.configuration.sdk_logger for SDK-specific logging needs."
|
648
|
+
STR
|
649
|
+
|
650
|
+
configuration.sdk_logger
|
651
|
+
end
|
652
|
+
end
|
653
|
+
|
588
654
|
##### Helpers #####
|
589
655
|
|
590
656
|
# @!visibility private
|
@@ -596,8 +662,8 @@ module Sentry
|
|
596
662
|
end
|
597
663
|
|
598
664
|
# @!visibility private
|
599
|
-
def
|
600
|
-
configuration.
|
665
|
+
def sdk_logger
|
666
|
+
configuration.sdk_logger
|
601
667
|
end
|
602
668
|
|
603
669
|
# @!visibility private
|
@@ -624,3 +690,4 @@ require "sentry/puma"
|
|
624
690
|
require "sentry/graphql"
|
625
691
|
require "sentry/faraday"
|
626
692
|
require "sentry/excon"
|
693
|
+
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.
|
4
|
+
version: 5.26.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sentry Team
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
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"
|
@@ -101,6 +101,8 @@ files:
|
|
101
101
|
- lib/sentry/interfaces/stacktrace_builder.rb
|
102
102
|
- lib/sentry/interfaces/threads.rb
|
103
103
|
- lib/sentry/linecache.rb
|
104
|
+
- lib/sentry/log_event.rb
|
105
|
+
- lib/sentry/log_event_buffer.rb
|
104
106
|
- lib/sentry/logger.rb
|
105
107
|
- lib/sentry/metrics.rb
|
106
108
|
- lib/sentry/metrics/aggregator.rb
|
@@ -127,6 +129,8 @@ files:
|
|
127
129
|
- lib/sentry/session.rb
|
128
130
|
- lib/sentry/session_flusher.rb
|
129
131
|
- lib/sentry/span.rb
|
132
|
+
- lib/sentry/std_lib_logger.rb
|
133
|
+
- lib/sentry/structured_logger.rb
|
130
134
|
- lib/sentry/test_helper.rb
|
131
135
|
- lib/sentry/threaded_periodic_worker.rb
|
132
136
|
- lib/sentry/transaction.rb
|
@@ -145,20 +149,21 @@ files:
|
|
145
149
|
- lib/sentry/utils/logging_helper.rb
|
146
150
|
- lib/sentry/utils/real_ip.rb
|
147
151
|
- lib/sentry/utils/request_id.rb
|
152
|
+
- lib/sentry/utils/uuid.rb
|
148
153
|
- lib/sentry/vernier/output.rb
|
149
154
|
- lib/sentry/vernier/profiler.rb
|
150
155
|
- lib/sentry/version.rb
|
151
156
|
- sentry-ruby-core.gemspec
|
152
157
|
- sentry-ruby.gemspec
|
153
|
-
homepage: https://github.com/getsentry/sentry-ruby/tree/5.
|
158
|
+
homepage: https://github.com/getsentry/sentry-ruby/tree/5.26.0/sentry-ruby
|
154
159
|
licenses:
|
155
160
|
- MIT
|
156
161
|
metadata:
|
157
|
-
homepage_uri: https://github.com/getsentry/sentry-ruby/tree/5.
|
158
|
-
source_code_uri: https://github.com/getsentry/sentry-ruby/tree/5.
|
159
|
-
changelog_uri: https://github.com/getsentry/sentry-ruby/blob/5.
|
162
|
+
homepage_uri: https://github.com/getsentry/sentry-ruby/tree/5.26.0/sentry-ruby
|
163
|
+
source_code_uri: https://github.com/getsentry/sentry-ruby/tree/5.26.0/sentry-ruby
|
164
|
+
changelog_uri: https://github.com/getsentry/sentry-ruby/blob/5.26.0/CHANGELOG.md
|
160
165
|
bug_tracker_uri: https://github.com/getsentry/sentry-ruby/issues
|
161
|
-
documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/5.
|
166
|
+
documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/5.26.0
|
162
167
|
rdoc_options: []
|
163
168
|
require_paths:
|
164
169
|
- lib
|
@@ -173,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
178
|
- !ruby/object:Gem::Version
|
174
179
|
version: '0'
|
175
180
|
requirements: []
|
176
|
-
rubygems_version: 3.6.
|
181
|
+
rubygems_version: 3.6.7
|
177
182
|
specification_version: 4
|
178
183
|
summary: A gem that provides a client interface for the Sentry error logger
|
179
184
|
test_files: []
|