sentry-ruby-core 5.24.0 → 5.25.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/README.md +11 -6
- data/Rakefile +5 -6
- data/lib/sentry/client.rb +49 -6
- data/lib/sentry/configuration.rb +10 -0
- data/lib/sentry/log_event.rb +70 -23
- data/lib/sentry/log_event_buffer.rb +1 -23
- data/lib/sentry/scope.rb +14 -4
- data/lib/sentry/span.rb +1 -1
- data/lib/sentry/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 893c349e407be28a6cff343d0fd46e9bd398879faae1cae8baf43b7da6e53667
|
4
|
+
data.tar.gz: 00efb1f46016d1db1756ff6ccdd15ae0af27d48278c5d1cec4a302a3805e80c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c41f116d7724304a3d39350d8d6636bfe6f03e40feff724b89e30436bb5c79269f6486ebe0fe1ee0d4722a0ad33c6b19e1579bf35c66faace7b1f963cc45204
|
7
|
+
data.tar.gz: 2c3b81765ea431073d60c41c289204d3bfae2ad7b6754147ef80414bd40c6ecd11d79a4efbf4af3fd148439840205f6f0ca6756a40c349553d370e545d4b0d62
|
data/.rspec
CHANGED
data/README.md
CHANGED
@@ -15,12 +15,12 @@ Sentry SDK for Ruby
|
|
15
15
|
|
16
16
|
| Current version | Build | Coverage | API doc |
|
17
17
|
| ---------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
|
18
|
-
| [](https://rubygems.org/gems/sentry-ruby) | [](https://rubygems.org/gems/sentry-rails) | [](https://rubygems.org/gems/sentry-sidekiq) | [](https://rubygems.org/gems/sentry-delayed_job) | [](https://rubygems.org/gems/sentry-resque) | [](https://rubygems.org/gems/sentry-opentelemetry) | [](https://rubygems.org/gems/sentry-ruby) | [](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [](https://codecov.io/gh/getsentry/sentry-ruby) | [](https://www.rubydoc.info/gems/sentry-ruby) |
|
19
|
+
| [](https://rubygems.org/gems/sentry-rails) | [](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [](https://codecov.io/gh/getsentry/sentry-ruby) | [](https://www.rubydoc.info/gems/sentry-rails) |
|
20
|
+
| [](https://rubygems.org/gems/sentry-sidekiq) | [](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [](https://codecov.io/gh/getsentry/sentry-ruby) | [](https://www.rubydoc.info/gems/sentry-sidekiq) |
|
21
|
+
| [](https://rubygems.org/gems/sentry-delayed_job) | [](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [](https://codecov.io/gh/getsentry/sentry-ruby) | [](https://www.rubydoc.info/gems/sentry-delayed_job) |
|
22
|
+
| [](https://rubygems.org/gems/sentry-resque) | [](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [](https://codecov.io/gh/getsentry/sentry-ruby) | [](https://www.rubydoc.info/gems/sentry-resque) |
|
23
|
+
| [](https://rubygems.org/gems/sentry-opentelemetry) | [](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [](https://codecov.io/gh/getsentry/sentry-ruby) | [](https://www.rubydoc.info/gems/sentry-opentelemetry) |
|
24
24
|
|
25
25
|
|
26
26
|
|
@@ -59,6 +59,8 @@ gem "sentry-opentelemetry"
|
|
59
59
|
|
60
60
|
You need to use Sentry.init to initialize and configure your SDK:
|
61
61
|
```ruby
|
62
|
+
require "sentry-ruby"
|
63
|
+
|
62
64
|
Sentry.init do |config|
|
63
65
|
config.dsn = "MY_DSN"
|
64
66
|
end
|
@@ -116,3 +118,6 @@ Thanks to everyone who has contributed to this project so far.
|
|
116
118
|
<a href="https://github.com/getsentry/sentry-ruby/graphs/contributors">
|
117
119
|
<img src="https://contributors-img.web.app/image?repo=getsentry/sentry-ruby" />
|
118
120
|
</a>
|
121
|
+
|
122
|
+
> [!WARNING]
|
123
|
+
> Example and sample code in sentry-rails/examples and sentry-rails/spec/dummy is unmaintained. Sample code may contain security vulnerabilities, should never be used in production, and exists only for illustrative purposes.
|
data/Rakefile
CHANGED
@@ -8,15 +8,14 @@ Bundler::GemHelper.install_tasks(name: "sentry-ruby")
|
|
8
8
|
|
9
9
|
require "rspec/core/rake_task"
|
10
10
|
|
11
|
+
ISOLATED_SPECS = "spec/isolated/**/*_spec.rb"
|
12
|
+
|
11
13
|
RSpec::Core::RakeTask.new(:spec).tap do |task|
|
12
|
-
task.
|
13
|
-
task.exclude_pattern = "spec/isolated/**/*_spec.rb"
|
14
|
+
task.exclude_pattern = ISOLATED_SPECS
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
sh "bundle exec rspec #{file}"
|
19
|
-
end
|
17
|
+
RSpec::Core::RakeTask.new(:isolated_specs).tap do |task|
|
18
|
+
task.pattern = ISOLATED_SPECS
|
20
19
|
end
|
21
20
|
|
22
21
|
task default: [:spec, :isolated_specs]
|
data/lib/sentry/client.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "sentry/transport"
|
4
4
|
require "sentry/log_event"
|
5
5
|
require "sentry/log_event_buffer"
|
6
|
+
require "sentry/utils/uuid"
|
6
7
|
|
7
8
|
module Sentry
|
8
9
|
class Client
|
@@ -194,12 +195,7 @@ module Sentry
|
|
194
195
|
|
195
196
|
attributes = options.reject { |k, _| k == :level || k == :severity }
|
196
197
|
|
197
|
-
LogEvent.new(
|
198
|
-
level: level,
|
199
|
-
body: message,
|
200
|
-
timestamp: Time.now.to_f,
|
201
|
-
attributes: attributes
|
202
|
-
)
|
198
|
+
LogEvent.new(level: level, body: message, attributes: attributes)
|
203
199
|
end
|
204
200
|
|
205
201
|
# Initializes an Event object with the given Transaction object.
|
@@ -272,6 +268,53 @@ module Sentry
|
|
272
268
|
raise
|
273
269
|
end
|
274
270
|
|
271
|
+
# Send an envelope with batched logs
|
272
|
+
# @param log_events [Array<LogEvent>] the log events to be sent
|
273
|
+
# @api private
|
274
|
+
# @return [void]
|
275
|
+
def send_logs(log_events)
|
276
|
+
envelope = Envelope.new(
|
277
|
+
event_id: Sentry::Utils.uuid,
|
278
|
+
sent_at: Sentry.utc_now.iso8601,
|
279
|
+
dsn: configuration.dsn,
|
280
|
+
sdk: Sentry.sdk_meta
|
281
|
+
)
|
282
|
+
|
283
|
+
discarded_count = 0
|
284
|
+
envelope_items = []
|
285
|
+
|
286
|
+
if configuration.before_send_log
|
287
|
+
log_events.each do |log_event|
|
288
|
+
processed_log_event = configuration.before_send_log.call(log_event)
|
289
|
+
|
290
|
+
if processed_log_event
|
291
|
+
envelope_items << processed_log_event.to_hash
|
292
|
+
else
|
293
|
+
discarded_count += 1
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
envelope_items
|
298
|
+
else
|
299
|
+
envelope_items = log_events.map(&:to_hash)
|
300
|
+
end
|
301
|
+
|
302
|
+
envelope.add_item(
|
303
|
+
{
|
304
|
+
type: "log",
|
305
|
+
item_count: envelope_items.size,
|
306
|
+
content_type: "application/vnd.sentry.items.log+json"
|
307
|
+
},
|
308
|
+
{ items: envelope_items }
|
309
|
+
)
|
310
|
+
|
311
|
+
send_envelope(envelope)
|
312
|
+
|
313
|
+
unless discarded_count.zero?
|
314
|
+
transport.record_lost_event(:before_send, "log_item", num: discarded_count)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
275
318
|
# Send an envelope directly to Sentry.
|
276
319
|
# @param envelope [Envelope] the envelope to be sent.
|
277
320
|
# @return [void]
|
data/lib/sentry/configuration.rb
CHANGED
@@ -101,6 +101,15 @@ module Sentry
|
|
101
101
|
# @return [Proc]
|
102
102
|
attr_reader :before_send_transaction
|
103
103
|
|
104
|
+
# Optional Proc, called before sending an event to the server
|
105
|
+
# @example
|
106
|
+
# config.before_send_log = lambda do |log|
|
107
|
+
# log.attributes["sentry"] = true
|
108
|
+
# log
|
109
|
+
# end
|
110
|
+
# @return [Proc]
|
111
|
+
attr_accessor :before_send_log
|
112
|
+
|
104
113
|
# An array of breadcrumbs loggers to be used. Available options are:
|
105
114
|
# - :sentry_logger
|
106
115
|
# - :http_logger
|
@@ -465,6 +474,7 @@ module Sentry
|
|
465
474
|
|
466
475
|
self.before_send = nil
|
467
476
|
self.before_send_transaction = nil
|
477
|
+
self.before_send_log = nil
|
468
478
|
self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT
|
469
479
|
self.traces_sampler = nil
|
470
480
|
self.enable_tracing = nil
|
data/lib/sentry/log_event.rb
CHANGED
@@ -4,19 +4,22 @@ module Sentry
|
|
4
4
|
# Event type that represents a log entry with its attributes
|
5
5
|
#
|
6
6
|
# @see https://develop.sentry.dev/sdk/telemetry/logs/#log-envelope-item-payload
|
7
|
-
class LogEvent
|
7
|
+
class LogEvent
|
8
8
|
TYPE = "log"
|
9
9
|
|
10
10
|
DEFAULT_PARAMETERS = [].freeze
|
11
11
|
DEFAULT_ATTRIBUTES = {}.freeze
|
12
|
-
DEFAULT_CONTEXT = {}.freeze
|
13
12
|
|
14
13
|
SERIALIZEABLE_ATTRIBUTES = %i[
|
15
14
|
level
|
16
15
|
body
|
17
16
|
timestamp
|
17
|
+
environment
|
18
|
+
release
|
19
|
+
server_name
|
18
20
|
trace_id
|
19
21
|
attributes
|
22
|
+
contexts
|
20
23
|
]
|
21
24
|
|
22
25
|
SENTRY_ATTRIBUTES = {
|
@@ -29,19 +32,54 @@ module Sentry
|
|
29
32
|
"sentry.message.template" => :template
|
30
33
|
}
|
31
34
|
|
35
|
+
USER_ATTRIBUTES = {
|
36
|
+
"user.id" => :user_id,
|
37
|
+
"user.name" => :user_username,
|
38
|
+
"user.email" => :user_email
|
39
|
+
}
|
40
|
+
|
32
41
|
LEVELS = %i[trace debug info warn error fatal].freeze
|
33
42
|
|
34
|
-
attr_accessor :level, :body, :template, :attributes
|
43
|
+
attr_accessor :level, :body, :template, :attributes, :user
|
35
44
|
|
36
|
-
|
37
|
-
|
45
|
+
attr_reader :configuration, *SERIALIZEABLE_ATTRIBUTES
|
46
|
+
|
47
|
+
SERIALIZERS = %i[
|
48
|
+
attributes
|
49
|
+
body
|
50
|
+
level
|
51
|
+
parent_span_id
|
52
|
+
sdk_name
|
53
|
+
sdk_version
|
54
|
+
timestamp
|
55
|
+
trace_id
|
56
|
+
user_id
|
57
|
+
user_username
|
58
|
+
user_email
|
59
|
+
].map { |name| [name, :"serialize_#{name}"] }.to_h
|
60
|
+
|
61
|
+
VALUE_TYPES = Hash.new("string").merge!({
|
62
|
+
TrueClass => "boolean",
|
63
|
+
FalseClass => "boolean",
|
64
|
+
Integer => "integer",
|
65
|
+
Float => "double"
|
66
|
+
}).freeze
|
67
|
+
|
68
|
+
TOKEN_REGEXP = /%\{(\w+)\}/
|
38
69
|
|
70
|
+
def initialize(configuration: Sentry.configuration, **options)
|
71
|
+
@configuration = configuration
|
39
72
|
@type = TYPE
|
73
|
+
@server_name = configuration.server_name
|
74
|
+
@environment = configuration.environment
|
75
|
+
@release = configuration.release
|
76
|
+
@timestamp = Sentry.utc_now
|
40
77
|
@level = options.fetch(:level)
|
41
78
|
@body = options[:body]
|
42
79
|
@template = @body if is_template?
|
43
80
|
@attributes = options[:attributes] || DEFAULT_ATTRIBUTES
|
44
|
-
@
|
81
|
+
@user = options[:user] || {}
|
82
|
+
@contexts = {}
|
45
83
|
end
|
46
84
|
|
47
85
|
def to_hash
|
@@ -53,9 +91,9 @@ module Sentry
|
|
53
91
|
private
|
54
92
|
|
55
93
|
def serialize(name)
|
56
|
-
serializer =
|
94
|
+
serializer = SERIALIZERS[name]
|
57
95
|
|
58
|
-
if
|
96
|
+
if serializer
|
59
97
|
__send__(serializer)
|
60
98
|
else
|
61
99
|
public_send(name)
|
@@ -75,7 +113,7 @@ module Sentry
|
|
75
113
|
end
|
76
114
|
|
77
115
|
def serialize_timestamp
|
78
|
-
|
116
|
+
timestamp.to_f
|
79
117
|
end
|
80
118
|
|
81
119
|
def serialize_trace_id
|
@@ -96,9 +134,23 @@ module Sentry
|
|
96
134
|
end
|
97
135
|
end
|
98
136
|
|
137
|
+
def serialize_user_id
|
138
|
+
user[:id]
|
139
|
+
end
|
140
|
+
|
141
|
+
def serialize_user_username
|
142
|
+
user[:username]
|
143
|
+
end
|
144
|
+
|
145
|
+
def serialize_user_email
|
146
|
+
user[:email]
|
147
|
+
end
|
148
|
+
|
99
149
|
def serialize_attributes
|
100
|
-
hash =
|
101
|
-
|
150
|
+
hash = {}
|
151
|
+
|
152
|
+
attributes.each do |key, value|
|
153
|
+
hash[key] = attribute_hash(value)
|
102
154
|
end
|
103
155
|
|
104
156
|
SENTRY_ATTRIBUTES.each do |key, name|
|
@@ -107,6 +159,12 @@ module Sentry
|
|
107
159
|
end
|
108
160
|
end
|
109
161
|
|
162
|
+
USER_ATTRIBUTES.each do |key, name|
|
163
|
+
if (value = serialize(name))
|
164
|
+
hash[key] = value
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
110
168
|
hash
|
111
169
|
end
|
112
170
|
|
@@ -115,16 +173,7 @@ module Sentry
|
|
115
173
|
end
|
116
174
|
|
117
175
|
def value_type(value)
|
118
|
-
|
119
|
-
when Integer
|
120
|
-
"integer"
|
121
|
-
when TrueClass, FalseClass
|
122
|
-
"boolean"
|
123
|
-
when Float
|
124
|
-
"double"
|
125
|
-
else
|
126
|
-
"string"
|
127
|
-
end
|
176
|
+
VALUE_TYPES[value.class]
|
128
177
|
end
|
129
178
|
|
130
179
|
def parameters
|
@@ -146,8 +195,6 @@ module Sentry
|
|
146
195
|
end
|
147
196
|
end
|
148
197
|
|
149
|
-
TOKEN_REGEXP = /%\{(\w+)\}/
|
150
|
-
|
151
198
|
def template_tokens
|
152
199
|
@template_tokens ||= body.scan(TOKEN_REGEXP).flatten.map(&:to_sym)
|
153
200
|
end
|
@@ -21,8 +21,6 @@ module Sentry
|
|
21
21
|
@client = client
|
22
22
|
@pending_events = []
|
23
23
|
@max_events = configuration.max_log_events || DEFAULT_MAX_EVENTS
|
24
|
-
@dsn = configuration.dsn
|
25
|
-
@sdk = Sentry.sdk_meta
|
26
24
|
@mutex = Mutex.new
|
27
25
|
|
28
26
|
log_debug("[Logging] Initialized buffer with max_events=#{@max_events}, flush_interval=#{FLUSH_INTERVAL}s")
|
@@ -70,28 +68,8 @@ module Sentry
|
|
70
68
|
private
|
71
69
|
|
72
70
|
def send_events
|
73
|
-
@client.
|
71
|
+
@client.send_logs(@pending_events)
|
74
72
|
@pending_events.clear
|
75
73
|
end
|
76
|
-
|
77
|
-
def to_envelope
|
78
|
-
envelope = Envelope.new(
|
79
|
-
event_id: SecureRandom.uuid.delete("-"),
|
80
|
-
sent_at: Sentry.utc_now.iso8601,
|
81
|
-
dsn: @dsn,
|
82
|
-
sdk: @sdk
|
83
|
-
)
|
84
|
-
|
85
|
-
envelope.add_item(
|
86
|
-
{
|
87
|
-
type: "log",
|
88
|
-
item_count: size,
|
89
|
-
content_type: "application/vnd.sentry.items.log+json"
|
90
|
-
},
|
91
|
-
{ items: @pending_events.map(&:to_hash) }
|
92
|
-
)
|
93
|
-
|
94
|
-
envelope
|
95
|
-
end
|
96
74
|
end
|
97
75
|
end
|
data/lib/sentry/scope.rb
CHANGED
@@ -46,7 +46,7 @@ module Sentry
|
|
46
46
|
# @param hint [Hash] the hint data that'll be passed to event processors.
|
47
47
|
# @return [Event]
|
48
48
|
def apply_to_event(event, hint = nil)
|
49
|
-
unless event.is_a?(CheckInEvent)
|
49
|
+
unless event.is_a?(CheckInEvent) || event.is_a?(LogEvent)
|
50
50
|
event.tags = tags.merge(event.tags)
|
51
51
|
event.user = user.merge(event.user)
|
52
52
|
event.extra = extra.merge(event.extra)
|
@@ -54,18 +54,28 @@ module Sentry
|
|
54
54
|
event.transaction = transaction_name if transaction_name
|
55
55
|
event.transaction_info = { source: transaction_source } if transaction_source
|
56
56
|
event.fingerprint = fingerprint
|
57
|
-
event.level = level
|
57
|
+
event.level = level
|
58
58
|
event.breadcrumbs = breadcrumbs
|
59
59
|
event.rack_env = rack_env if rack_env
|
60
60
|
event.attachments = attachments
|
61
61
|
end
|
62
62
|
|
63
|
+
if event.is_a?(LogEvent)
|
64
|
+
event.user = user.merge(event.user)
|
65
|
+
end
|
66
|
+
|
63
67
|
if span
|
64
68
|
event.contexts[:trace] ||= span.get_trace_context
|
65
|
-
|
69
|
+
|
70
|
+
if event.respond_to?(:dynamic_sampling_context)
|
71
|
+
event.dynamic_sampling_context ||= span.get_dynamic_sampling_context
|
72
|
+
end
|
66
73
|
else
|
67
74
|
event.contexts[:trace] ||= propagation_context.get_trace_context
|
68
|
-
|
75
|
+
|
76
|
+
if event.respond_to?(:dynamic_sampling_context)
|
77
|
+
event.dynamic_sampling_context ||= propagation_context.get_dynamic_sampling_context
|
78
|
+
end
|
69
79
|
end
|
70
80
|
|
71
81
|
all_event_processors = self.class.global_event_processors + @event_processors
|
data/lib/sentry/span.rb
CHANGED
data/lib/sentry/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sentry Team
|
@@ -15,14 +15,14 @@ dependencies:
|
|
15
15
|
requirements:
|
16
16
|
- - '='
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: 5.
|
18
|
+
version: 5.25.0
|
19
19
|
type: :runtime
|
20
20
|
prerelease: false
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
22
22
|
requirements:
|
23
23
|
- - '='
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version: 5.
|
25
|
+
version: 5.25.0
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: concurrent-ruby
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|