sentry-ruby-core 5.18.2 → 5.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/sentry/attachment.rb +40 -0
- data/lib/sentry/backtrace.rb +1 -3
- data/lib/sentry/baggage.rb +6 -6
- data/lib/sentry/breadcrumb/sentry_logger.rb +6 -6
- data/lib/sentry/check_in_event.rb +4 -4
- data/lib/sentry/client.rb +9 -9
- data/lib/sentry/configuration.rb +30 -18
- data/lib/sentry/core_ext/object/deep_dup.rb +1 -1
- data/lib/sentry/cron/monitor_check_ins.rb +1 -1
- data/lib/sentry/cron/monitor_config.rb +1 -1
- data/lib/sentry/dsn.rb +3 -3
- data/lib/sentry/envelope.rb +8 -8
- data/lib/sentry/event.rb +11 -7
- data/lib/sentry/faraday.rb +77 -0
- data/lib/sentry/graphql.rb +1 -1
- data/lib/sentry/hub.rb +8 -1
- data/lib/sentry/interfaces/mechanism.rb +1 -1
- data/lib/sentry/interfaces/request.rb +5 -5
- data/lib/sentry/interfaces/single_exception.rb +1 -1
- data/lib/sentry/interfaces/stacktrace.rb +3 -1
- data/lib/sentry/interfaces/stacktrace_builder.rb +15 -2
- data/lib/sentry/logger.rb +1 -1
- data/lib/sentry/metrics/aggregator.rb +12 -12
- data/lib/sentry/metrics/set_metric.rb +2 -2
- data/lib/sentry/metrics.rb +15 -15
- data/lib/sentry/net/http.rb +16 -38
- data/lib/sentry/profiler.rb +19 -20
- data/lib/sentry/propagation_context.rb +1 -1
- data/lib/sentry/rack/capture_exceptions.rb +1 -1
- data/lib/sentry/rack.rb +2 -2
- data/lib/sentry/rake.rb +2 -2
- data/lib/sentry/release_detector.rb +4 -4
- data/lib/sentry/scope.rb +15 -0
- data/lib/sentry/session_flusher.rb +1 -1
- data/lib/sentry/span.rb +8 -1
- data/lib/sentry/test_helper.rb +1 -1
- data/lib/sentry/transaction.rb +2 -2
- data/lib/sentry/transaction_event.rb +1 -1
- data/lib/sentry/transport/http_transport.rb +12 -12
- data/lib/sentry/transport.rb +10 -4
- data/lib/sentry/utils/env_helper.rb +21 -0
- data/lib/sentry/utils/http_tracing.rb +41 -0
- data/lib/sentry/utils/real_ip.rb +1 -1
- data/lib/sentry/version.rb +1 -1
- data/lib/sentry-ruby.rb +9 -1
- data/sentry-ruby.gemspec +1 -1
- metadata +9 -5
data/lib/sentry/transaction.rb
CHANGED
@@ -265,8 +265,8 @@ module Sentry
|
|
265
265
|
else
|
266
266
|
is_backpressure = Sentry.backpressure_monitor&.downsample_factor&.positive?
|
267
267
|
reason = is_backpressure ? :backpressure : :sample_rate
|
268
|
-
hub.current_client.transport.record_lost_event(reason,
|
269
|
-
hub.current_client.transport.record_lost_event(reason,
|
268
|
+
hub.current_client.transport.record_lost_event(reason, "transaction")
|
269
|
+
hub.current_client.transport.record_lost_event(reason, "span")
|
270
270
|
end
|
271
271
|
end
|
272
272
|
|
@@ -7,7 +7,7 @@ module Sentry
|
|
7
7
|
class HTTPTransport < Transport
|
8
8
|
GZIP_ENCODING = "gzip"
|
9
9
|
GZIP_THRESHOLD = 1024 * 30
|
10
|
-
CONTENT_TYPE =
|
10
|
+
CONTENT_TYPE = "application/x-sentry-envelope"
|
11
11
|
|
12
12
|
DEFAULT_DELAY = 60
|
13
13
|
RETRY_AFTER_HEADER = "retry-after"
|
@@ -38,13 +38,13 @@ module Sentry
|
|
38
38
|
end
|
39
39
|
|
40
40
|
headers = {
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
"Content-Type" => CONTENT_TYPE,
|
42
|
+
"Content-Encoding" => encoding,
|
43
|
+
"User-Agent" => USER_AGENT
|
44
44
|
}
|
45
45
|
|
46
46
|
auth_header = generate_auth_header
|
47
|
-
headers[
|
47
|
+
headers["X-Sentry-Auth"] = auth_header if auth_header
|
48
48
|
|
49
49
|
response = conn.start do |http|
|
50
50
|
request = ::Net::HTTP::Post.new(endpoint, headers)
|
@@ -60,7 +60,7 @@ module Sentry
|
|
60
60
|
else
|
61
61
|
error_info = "the server responded with status #{response.code}"
|
62
62
|
error_info += "\nbody: #{response.body}"
|
63
|
-
error_info += " Error in headers is: #{response['x-sentry-error']}" if response[
|
63
|
+
error_info += " Error in headers is: #{response['x-sentry-error']}" if response["x-sentry-error"]
|
64
64
|
|
65
65
|
raise Sentry::ExternalError, error_info
|
66
66
|
end
|
@@ -78,13 +78,13 @@ module Sentry
|
|
78
78
|
|
79
79
|
now = Sentry.utc_now.to_i
|
80
80
|
fields = {
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
"sentry_version" => PROTOCOL_VERSION,
|
82
|
+
"sentry_client" => USER_AGENT,
|
83
|
+
"sentry_timestamp" => now,
|
84
|
+
"sentry_key" => @dsn.public_key
|
85
85
|
}
|
86
|
-
fields[
|
87
|
-
|
86
|
+
fields["sentry_secret"] = @dsn.secret_key if @dsn.secret_key
|
87
|
+
"Sentry " + fields.map { |key, value| "#{key}=#{value}" }.join(", ")
|
88
88
|
end
|
89
89
|
|
90
90
|
def conn
|
data/lib/sentry/transport.rb
CHANGED
@@ -5,7 +5,7 @@ require "sentry/envelope"
|
|
5
5
|
|
6
6
|
module Sentry
|
7
7
|
class Transport
|
8
|
-
PROTOCOL_VERSION =
|
8
|
+
PROTOCOL_VERSION = "7"
|
9
9
|
USER_AGENT = "sentry-ruby/#{Sentry::VERSION}"
|
10
10
|
CLIENT_REPORT_INTERVAL = 30
|
11
11
|
|
@@ -134,17 +134,23 @@ module Sentry
|
|
134
134
|
envelope = Envelope.new(envelope_headers)
|
135
135
|
|
136
136
|
envelope.add_item(
|
137
|
-
{ type: item_type, content_type:
|
137
|
+
{ type: item_type, content_type: "application/json" },
|
138
138
|
event_payload
|
139
139
|
)
|
140
140
|
|
141
141
|
if event.is_a?(TransactionEvent) && event.profile
|
142
142
|
envelope.add_item(
|
143
|
-
{ type:
|
143
|
+
{ type: "profile", content_type: "application/json" },
|
144
144
|
event.profile
|
145
145
|
)
|
146
146
|
end
|
147
147
|
|
148
|
+
if event.is_a?(Event) && event.attachments.any?
|
149
|
+
event.attachments.each do |attachment|
|
150
|
+
envelope.add_item(attachment.to_envelope_headers, attachment.payload)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
148
154
|
client_report_headers, client_report_payload = fetch_pending_client_report
|
149
155
|
envelope.add_item(client_report_headers, client_report_payload) if client_report_headers
|
150
156
|
|
@@ -179,7 +185,7 @@ module Sentry
|
|
179
185
|
{ reason: reason, category: category, quantity: val }
|
180
186
|
end
|
181
187
|
|
182
|
-
item_header = { type:
|
188
|
+
item_header = { type: "client_report" }
|
183
189
|
item_payload = {
|
184
190
|
timestamp: Sentry.utc_now.iso8601,
|
185
191
|
discarded_events: discarded_events_hash
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sentry
|
4
|
+
module Utils
|
5
|
+
module EnvHelper
|
6
|
+
TRUTHY_ENV_VALUES = %w[t true yes y 1 on].freeze
|
7
|
+
FALSY_ENV_VALUES = %w[f false no n 0 off].freeze
|
8
|
+
|
9
|
+
def self.env_to_bool(value, strict: false)
|
10
|
+
value = value.to_s
|
11
|
+
normalized = value.downcase
|
12
|
+
|
13
|
+
return false if FALSY_ENV_VALUES.include?(normalized)
|
14
|
+
|
15
|
+
return true if TRUTHY_ENV_VALUES.include?(normalized)
|
16
|
+
|
17
|
+
strict ? nil : !(value.nil? || value.empty?)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sentry
|
4
|
+
module Utils
|
5
|
+
module HttpTracing
|
6
|
+
def set_span_info(sentry_span, request_info, response_status)
|
7
|
+
sentry_span.set_description("#{request_info[:method]} #{request_info[:url]}")
|
8
|
+
sentry_span.set_data(Span::DataConventions::URL, request_info[:url])
|
9
|
+
sentry_span.set_data(Span::DataConventions::HTTP_METHOD, request_info[:method])
|
10
|
+
sentry_span.set_data(Span::DataConventions::HTTP_QUERY, request_info[:query]) if request_info[:query]
|
11
|
+
sentry_span.set_data(Span::DataConventions::HTTP_STATUS_CODE, response_status)
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_propagation_headers(req)
|
15
|
+
Sentry.get_trace_propagation_headers&.each { |k, v| req[k] = v }
|
16
|
+
end
|
17
|
+
|
18
|
+
def record_sentry_breadcrumb(request_info, response_status)
|
19
|
+
crumb = Sentry::Breadcrumb.new(
|
20
|
+
level: :info,
|
21
|
+
category: self.class::BREADCRUMB_CATEGORY,
|
22
|
+
type: :info,
|
23
|
+
data: { status: response_status, **request_info }
|
24
|
+
)
|
25
|
+
|
26
|
+
Sentry.add_breadcrumb(crumb)
|
27
|
+
end
|
28
|
+
|
29
|
+
def record_sentry_breadcrumb?
|
30
|
+
Sentry.initialized? && Sentry.configuration.breadcrumbs_logger.include?(:http_logger)
|
31
|
+
end
|
32
|
+
|
33
|
+
def propagate_trace?(url)
|
34
|
+
url &&
|
35
|
+
Sentry.initialized? &&
|
36
|
+
Sentry.configuration.propagate_traces &&
|
37
|
+
Sentry.configuration.trace_propagation_targets.any? { |target| url.match?(target) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/sentry/utils/real_ip.rb
CHANGED
data/lib/sentry/version.rb
CHANGED
data/lib/sentry-ruby.rb
CHANGED
@@ -211,6 +211,13 @@ module Sentry
|
|
211
211
|
get_current_scope.set_context(*args)
|
212
212
|
end
|
213
213
|
|
214
|
+
# @!method add_attachment
|
215
|
+
# @!macro add_attachment
|
216
|
+
def add_attachment(**opts)
|
217
|
+
return unless initialized?
|
218
|
+
get_current_scope.add_attachment(**opts)
|
219
|
+
end
|
220
|
+
|
214
221
|
##### Main APIs #####
|
215
222
|
|
216
223
|
# Initializes the SDK with given configuration.
|
@@ -556,7 +563,7 @@ module Sentry
|
|
556
563
|
#
|
557
564
|
# @return [String]
|
558
565
|
def get_trace_propagation_meta
|
559
|
-
return
|
566
|
+
return "" unless initialized?
|
560
567
|
get_current_hub.get_trace_propagation_meta
|
561
568
|
end
|
562
569
|
|
@@ -601,3 +608,4 @@ require "sentry/net/http"
|
|
601
608
|
require "sentry/redis"
|
602
609
|
require "sentry/puma"
|
603
610
|
require "sentry/graphql"
|
611
|
+
require "sentry/faraday"
|
data/sentry-ruby.gemspec
CHANGED
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.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sentry Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sentry-ruby
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.
|
19
|
+
version: 5.20.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 5.
|
26
|
+
version: 5.20.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: concurrent-ruby
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- bin/console
|
59
59
|
- bin/setup
|
60
60
|
- lib/sentry-ruby.rb
|
61
|
+
- lib/sentry/attachment.rb
|
61
62
|
- lib/sentry/background_worker.rb
|
62
63
|
- lib/sentry/backpressure_monitor.rb
|
63
64
|
- lib/sentry/backtrace.rb
|
@@ -79,6 +80,7 @@ files:
|
|
79
80
|
- lib/sentry/error_event.rb
|
80
81
|
- lib/sentry/event.rb
|
81
82
|
- lib/sentry/exceptions.rb
|
83
|
+
- lib/sentry/faraday.rb
|
82
84
|
- lib/sentry/graphql.rb
|
83
85
|
- lib/sentry/hub.rb
|
84
86
|
- lib/sentry/integrable.rb
|
@@ -127,7 +129,9 @@ files:
|
|
127
129
|
- lib/sentry/utils/argument_checking_helper.rb
|
128
130
|
- lib/sentry/utils/custom_inspection.rb
|
129
131
|
- lib/sentry/utils/encoding_helper.rb
|
132
|
+
- lib/sentry/utils/env_helper.rb
|
130
133
|
- lib/sentry/utils/exception_cause_chain.rb
|
134
|
+
- lib/sentry/utils/http_tracing.rb
|
131
135
|
- lib/sentry/utils/logging_helper.rb
|
132
136
|
- lib/sentry/utils/real_ip.rb
|
133
137
|
- lib/sentry/utils/request_id.rb
|
@@ -156,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
160
|
- !ruby/object:Gem::Version
|
157
161
|
version: '0'
|
158
162
|
requirements: []
|
159
|
-
rubygems_version: 3.5.
|
163
|
+
rubygems_version: 3.5.16
|
160
164
|
signing_key:
|
161
165
|
specification_version: 4
|
162
166
|
summary: A gem that provides a client interface for the Sentry error logger
|