sentry-ruby-core 5.2.1 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/sentry/background_worker.rb +2 -1
- data/lib/sentry/client.rb +6 -5
- data/lib/sentry/error_event.rb +38 -0
- data/lib/sentry/event.rb +4 -29
- data/lib/sentry/hub.rb +1 -1
- data/lib/sentry/net/http.rb +3 -3
- data/lib/sentry/session_flusher.rb +1 -0
- data/lib/sentry/transaction_event.rb +4 -20
- data/lib/sentry/transport/http_transport.rb +15 -1
- data/lib/sentry/transport.rb +1 -6
- data/lib/sentry/version.rb +1 -1
- data/lib/sentry-ruby.rb +36 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03d233c6e1bd55ddc4044c7a23b6bc74047eec17a8c16d5f33f768065641259c
|
4
|
+
data.tar.gz: bec07f880bff192b6ef71aaefdf9dc9ff2ff072a539f94ed5c4fd0398ad1146a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3d90a9b888db8a396e260dccf5df3a38d4f153c9bc2b31b92fc206009553fec2d3d0fe47bb1a871b001372fcba8013fee4e16b60405588db4ce3984f56d675e
|
7
|
+
data.tar.gz: 2ae1db7dee78487fec06b1cb1c6fb2dfa77852ae20b0c28b6c2f0e0b964f728fdea40a8261495439ef6e193182a0f7dc3196dc1bd75368abcf2d78852310361a
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ If you're using `sentry-raven`, we recommend you to migrate to this new SDK. You
|
|
29
29
|
|
30
30
|
## Requirements
|
31
31
|
|
32
|
-
We test on Ruby 2.4, 2.5, 2.6, 2.7, and 3.
|
32
|
+
We test on Ruby 2.4, 2.5, 2.6, 2.7, 3.0, and 3.1 at the latest patchlevel/teeny version. We also support JRuby 9.0.
|
33
33
|
|
34
34
|
If you use self-hosted Sentry, please also make sure its version is above `20.6.0`.
|
35
35
|
|
@@ -29,7 +29,7 @@ module Sentry
|
|
29
29
|
log_debug("config.background_worker_threads is set to 0, all events will be sent synchronously")
|
30
30
|
Concurrent::ImmediateExecutor.new
|
31
31
|
else
|
32
|
-
log_debug("
|
32
|
+
log_debug("Initializing the background worker with #{@number_of_threads} threads")
|
33
33
|
|
34
34
|
executor = Concurrent::ThreadPoolExecutor.new(
|
35
35
|
min_threads: 0,
|
@@ -59,6 +59,7 @@ module Sentry
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def shutdown
|
62
|
+
log_debug("Shutting down background worker")
|
62
63
|
@shutdown_callback&.call
|
63
64
|
end
|
64
65
|
|
data/lib/sentry/client.rb
CHANGED
@@ -80,9 +80,10 @@ module Sentry
|
|
80
80
|
|
81
81
|
integration_meta = Sentry.integrations[hint[:integration]]
|
82
82
|
|
83
|
-
|
83
|
+
ErrorEvent.new(configuration: configuration, integration_meta: integration_meta).tap do |event|
|
84
84
|
event.add_exception_interface(exception)
|
85
85
|
event.add_threads_interface(crashed: true)
|
86
|
+
event.level = :error
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
@@ -94,8 +95,9 @@ module Sentry
|
|
94
95
|
return unless @configuration.sending_allowed?
|
95
96
|
|
96
97
|
integration_meta = Sentry.integrations[hint[:integration]]
|
97
|
-
event =
|
98
|
+
event = ErrorEvent.new(configuration: configuration, integration_meta: integration_meta, message: message)
|
98
99
|
event.add_threads_interface(backtrace: backtrace || caller)
|
100
|
+
event.level = :error
|
99
101
|
event
|
100
102
|
end
|
101
103
|
|
@@ -133,7 +135,7 @@ module Sentry
|
|
133
135
|
|
134
136
|
event
|
135
137
|
rescue => e
|
136
|
-
loggable_event_type =
|
138
|
+
loggable_event_type = event_type.capitalize
|
137
139
|
log_error("#{loggable_event_type} sending failed", e, debug: configuration.debug)
|
138
140
|
|
139
141
|
event_info = Event.get_log_message(event.to_hash)
|
@@ -174,8 +176,7 @@ module Sentry
|
|
174
176
|
async_block.call(event_hash)
|
175
177
|
end
|
176
178
|
rescue => e
|
177
|
-
|
178
|
-
log_error("Async #{loggable_event_type} sending failed", e, debug: configuration.debug)
|
179
|
+
log_error("Async #{event_hash["type"]} sending failed", e, debug: configuration.debug)
|
179
180
|
send_event(event, hint)
|
180
181
|
end
|
181
182
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sentry
|
4
|
+
# ErrorEvent represents error or normal message events.
|
5
|
+
class ErrorEvent < Event
|
6
|
+
# @return [ExceptionInterface]
|
7
|
+
attr_reader :exception
|
8
|
+
|
9
|
+
# @return [ThreadsInterface]
|
10
|
+
attr_reader :threads
|
11
|
+
|
12
|
+
# @return [Hash]
|
13
|
+
def to_hash
|
14
|
+
data = super
|
15
|
+
data[:threads] = threads.to_hash if threads
|
16
|
+
data[:exception] = exception.to_hash if exception
|
17
|
+
data
|
18
|
+
end
|
19
|
+
|
20
|
+
# @!visibility private
|
21
|
+
def add_threads_interface(backtrace: nil, **options)
|
22
|
+
@threads = ThreadsInterface.build(
|
23
|
+
backtrace: backtrace,
|
24
|
+
stacktrace_builder: @stacktrace_builder,
|
25
|
+
**options
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @!visibility private
|
30
|
+
def add_exception_interface(exception)
|
31
|
+
if exception.respond_to?(:sentry_context)
|
32
|
+
@extra.merge!(exception.sentry_context)
|
33
|
+
end
|
34
|
+
|
35
|
+
@exception = Sentry::ExceptionInterface.build(exception: exception, stacktrace_builder: @stacktrace_builder)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/sentry/event.rb
CHANGED
@@ -9,7 +9,10 @@ require 'sentry/utils/request_id'
|
|
9
9
|
require 'sentry/utils/custom_inspection'
|
10
10
|
|
11
11
|
module Sentry
|
12
|
+
# This is an abstract class that defines the shared attributes of an event.
|
13
|
+
# Please don't use it directly. The user-facing classes are its child classes.
|
12
14
|
class Event
|
15
|
+
TYPE = "event"
|
13
16
|
# These are readable attributes.
|
14
17
|
SERIALIZEABLE_ATTRIBUTES = %i(
|
15
18
|
event_id level timestamp
|
@@ -35,12 +38,6 @@ module Sentry
|
|
35
38
|
# @return [RequestInterface]
|
36
39
|
attr_reader :request
|
37
40
|
|
38
|
-
# @return [ExceptionInterface]
|
39
|
-
attr_reader :exception
|
40
|
-
|
41
|
-
# @return [ThreadsInterface]
|
42
|
-
attr_reader :threads
|
43
|
-
|
44
41
|
# @param configuration [Configuration]
|
45
42
|
# @param integration_meta [Hash, nil]
|
46
43
|
# @param message [String, nil]
|
@@ -49,6 +46,7 @@ module Sentry
|
|
49
46
|
@event_id = SecureRandom.uuid.delete("-")
|
50
47
|
@timestamp = Sentry.utc_now.iso8601
|
51
48
|
@platform = :ruby
|
49
|
+
@type = self.class::TYPE
|
52
50
|
@sdk = integration_meta || Sentry.sdk_meta
|
53
51
|
|
54
52
|
@user = {}
|
@@ -71,8 +69,6 @@ module Sentry
|
|
71
69
|
@rack_env_whitelist = configuration.rack_env_whitelist
|
72
70
|
|
73
71
|
@message = (message || "").byteslice(0..MAX_MESSAGE_SIZE_IN_BYTES)
|
74
|
-
|
75
|
-
self.level = :error
|
76
72
|
end
|
77
73
|
|
78
74
|
class << self
|
@@ -146,9 +142,6 @@ module Sentry
|
|
146
142
|
data = serialize_attributes
|
147
143
|
data[:breadcrumbs] = breadcrumbs.to_hash if breadcrumbs
|
148
144
|
data[:request] = request.to_hash if request
|
149
|
-
data[:exception] = exception.to_hash if exception
|
150
|
-
data[:threads] = threads.to_hash if threads
|
151
|
-
|
152
145
|
data
|
153
146
|
end
|
154
147
|
|
@@ -157,24 +150,6 @@ module Sentry
|
|
157
150
|
JSON.parse(JSON.generate(to_hash))
|
158
151
|
end
|
159
152
|
|
160
|
-
# @!visibility private
|
161
|
-
def add_threads_interface(backtrace: nil, **options)
|
162
|
-
@threads = ThreadsInterface.build(
|
163
|
-
backtrace: backtrace,
|
164
|
-
stacktrace_builder: @stacktrace_builder,
|
165
|
-
**options
|
166
|
-
)
|
167
|
-
end
|
168
|
-
|
169
|
-
# @!visibility private
|
170
|
-
def add_exception_interface(exception)
|
171
|
-
if exception.respond_to?(:sentry_context)
|
172
|
-
@extra.merge!(exception.sentry_context)
|
173
|
-
end
|
174
|
-
|
175
|
-
@exception = Sentry::ExceptionInterface.build(exception: exception, stacktrace_builder: @stacktrace_builder)
|
176
|
-
end
|
177
|
-
|
178
153
|
private
|
179
154
|
|
180
155
|
def add_request_interface(env)
|
data/lib/sentry/hub.rb
CHANGED
data/lib/sentry/net/http.rb
CHANGED
@@ -74,11 +74,11 @@ module Sentry
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def start_sentry_span
|
77
|
-
return unless Sentry.initialized? &&
|
77
|
+
return unless Sentry.initialized? && span = Sentry.get_current_scope.get_span
|
78
78
|
return if from_sentry_sdk?
|
79
|
-
return if
|
79
|
+
return if span.sampled == false
|
80
80
|
|
81
|
-
|
81
|
+
span.start_child(op: OP_NAME, start_timestamp: Sentry.utc_now.to_f)
|
82
82
|
end
|
83
83
|
|
84
84
|
def finish_sentry_span(sentry_span)
|
@@ -1,32 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Sentry
|
4
|
+
# TransactionEvent represents events that carry transaction data (type: "transaction").
|
4
5
|
class TransactionEvent < Event
|
5
6
|
TYPE = "transaction"
|
6
7
|
|
7
|
-
SERIALIZEABLE_ATTRIBUTES = %i(
|
8
|
-
event_id level timestamp start_timestamp
|
9
|
-
release environment server_name modules
|
10
|
-
user tags contexts extra
|
11
|
-
transaction platform sdk type
|
12
|
-
)
|
13
|
-
|
14
|
-
WRITER_ATTRIBUTES = SERIALIZEABLE_ATTRIBUTES - %i(type timestamp start_timestamp level)
|
15
|
-
|
16
|
-
attr_writer(*WRITER_ATTRIBUTES)
|
17
|
-
attr_reader(*SERIALIZEABLE_ATTRIBUTES)
|
18
|
-
|
19
8
|
# @return [<Array[Span]>]
|
20
9
|
attr_accessor :spans
|
21
10
|
|
22
|
-
# @
|
23
|
-
|
24
|
-
# @param message [String, nil]
|
25
|
-
def initialize(configuration:, integration_meta: nil, message: nil)
|
26
|
-
super
|
27
|
-
@type = TYPE
|
28
|
-
self.level = nil
|
29
|
-
end
|
11
|
+
# @return [Float, nil]
|
12
|
+
attr_reader :start_timestamp
|
30
13
|
|
31
14
|
# Sets the event's start_timestamp.
|
32
15
|
# @param time [Time, Float]
|
@@ -39,6 +22,7 @@ module Sentry
|
|
39
22
|
def to_hash
|
40
23
|
data = super
|
41
24
|
data[:spans] = @spans.map(&:to_hash) if @spans
|
25
|
+
data[:start_timestamp] = @start_timestamp
|
42
26
|
data
|
43
27
|
end
|
44
28
|
end
|
@@ -130,7 +130,7 @@ module Sentry
|
|
130
130
|
server = URI(@dsn.server)
|
131
131
|
|
132
132
|
connection =
|
133
|
-
if proxy = @transport_configuration.proxy
|
133
|
+
if proxy = normalize_proxy(@transport_configuration.proxy)
|
134
134
|
::Net::HTTP.new(server.hostname, server.port, proxy[:uri].hostname, proxy[:uri].port, proxy[:user], proxy[:password])
|
135
135
|
else
|
136
136
|
::Net::HTTP.new(server.hostname, server.port, nil)
|
@@ -148,6 +148,20 @@ module Sentry
|
|
148
148
|
connection
|
149
149
|
end
|
150
150
|
|
151
|
+
def normalize_proxy(proxy)
|
152
|
+
return proxy unless proxy
|
153
|
+
|
154
|
+
case proxy
|
155
|
+
when String
|
156
|
+
uri = URI(proxy)
|
157
|
+
{ uri: uri, user: uri.user, password: uri.password }
|
158
|
+
when URI
|
159
|
+
{ uri: proxy, user: proxy.user, password: proxy.password }
|
160
|
+
when Hash
|
161
|
+
proxy
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
151
165
|
def ssl_configuration
|
152
166
|
configuration = {
|
153
167
|
verify: @transport_configuration.ssl_verification,
|
data/lib/sentry/transport.rb
CHANGED
@@ -148,7 +148,7 @@ module Sentry
|
|
148
148
|
# Convert to hash
|
149
149
|
event_payload = event.to_hash
|
150
150
|
event_id = event_payload[:event_id] || event_payload["event_id"]
|
151
|
-
item_type =
|
151
|
+
item_type = event_payload[:type] || event_payload["type"]
|
152
152
|
|
153
153
|
envelope = Envelope.new(
|
154
154
|
{
|
@@ -174,16 +174,11 @@ module Sentry
|
|
174
174
|
return unless @send_client_reports
|
175
175
|
return unless CLIENT_REPORT_REASONS.include?(reason)
|
176
176
|
|
177
|
-
item_type ||= 'event'
|
178
177
|
@discarded_events[[reason, item_type]] += 1
|
179
178
|
end
|
180
179
|
|
181
180
|
private
|
182
181
|
|
183
|
-
def get_item_type(event_hash)
|
184
|
-
event_hash[:type] || event_hash["type"] || "event"
|
185
|
-
end
|
186
|
-
|
187
182
|
def fetch_pending_client_report
|
188
183
|
return nil unless @send_client_reports
|
189
184
|
return nil if @last_client_report_sent > Time.now - CLIENT_REPORT_INTERVAL
|
data/lib/sentry/version.rb
CHANGED
data/lib/sentry-ruby.rb
CHANGED
@@ -12,6 +12,7 @@ require "sentry/utils/logging_helper"
|
|
12
12
|
require "sentry/configuration"
|
13
13
|
require "sentry/logger"
|
14
14
|
require "sentry/event"
|
15
|
+
require "sentry/error_event"
|
15
16
|
require "sentry/transaction_event"
|
16
17
|
require "sentry/span"
|
17
18
|
require "sentry/transaction"
|
@@ -102,7 +103,7 @@ module Sentry
|
|
102
103
|
if initialized?
|
103
104
|
logger.warn(LOGGER_PROGNAME) do
|
104
105
|
<<~MSG
|
105
|
-
Integration '#{name}' is loaded after the SDK is initialized, which can cause
|
106
|
+
Integration '#{name}' is loaded after the SDK is initialized, which can cause unexpected behavior. Please make sure all integrations are loaded before SDK initialization.
|
106
107
|
MSG
|
107
108
|
end
|
108
109
|
end
|
@@ -384,6 +385,40 @@ module Sentry
|
|
384
385
|
get_current_hub.start_transaction(**options)
|
385
386
|
end
|
386
387
|
|
388
|
+
# Records the block's execution as a child of the current span.
|
389
|
+
# If the current scope doesn't have a span, the block would still be executed but the yield param will be nil.
|
390
|
+
# @param attributes [Hash] attributes for the child span.
|
391
|
+
# @yieldparam child_span [Span, nil]
|
392
|
+
# @return yield result
|
393
|
+
#
|
394
|
+
# @example
|
395
|
+
# Sentry.with_child_span(op: "my operation") do |child_span|
|
396
|
+
# child_span.set_data(operation_data)
|
397
|
+
# child_span.set_description(operation_detail)
|
398
|
+
# # result will be returned
|
399
|
+
# end
|
400
|
+
#
|
401
|
+
def with_child_span(**attributes, &block)
|
402
|
+
current_span = get_current_scope.get_span
|
403
|
+
|
404
|
+
if current_span
|
405
|
+
result = nil
|
406
|
+
|
407
|
+
begin
|
408
|
+
current_span.with_child_span(**attributes) do |child_span|
|
409
|
+
get_current_scope.set_span(child_span)
|
410
|
+
result = yield(child_span)
|
411
|
+
end
|
412
|
+
ensure
|
413
|
+
get_current_scope.set_span(current_span)
|
414
|
+
end
|
415
|
+
|
416
|
+
result
|
417
|
+
else
|
418
|
+
yield(nil)
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
387
422
|
# Returns the id of the lastly reported Sentry::Event.
|
388
423
|
#
|
389
424
|
# @return [String, nil]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentry-ruby-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sentry Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/sentry/core_ext/object/duplicable.rb
|
57
57
|
- lib/sentry/dsn.rb
|
58
58
|
- lib/sentry/envelope.rb
|
59
|
+
- lib/sentry/error_event.rb
|
59
60
|
- lib/sentry/event.rb
|
60
61
|
- lib/sentry/exceptions.rb
|
61
62
|
- lib/sentry/hub.rb
|