sentry-ruby 5.24.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 724630875bf8195cd594f3e761794886520b8eb95c13bf9a82642cdaf6f3ea94
4
- data.tar.gz: c086418c80e60b60d1e099701fdb6b9ae1a9136bd464213dd9ff9cc17c582b75
3
+ metadata.gz: eb03eb536d1060c3a097a1ff3726ae71c8ffbd0012580d75c491665e054ac7c1
4
+ data.tar.gz: 65df577369b281f3e1d1d9335e78786a800947c2014b35608d88c863458f24ca
5
5
  SHA512:
6
- metadata.gz: f8db6e3259785a16378f1a2f43f4dbb6e82be7f7eed84ba8f6a7ab8f1dc0f8ae4989a1d9fad5022361d756e0d8fd80d3cf16b6444933f10380e112e54afeaec1
7
- data.tar.gz: 86ad04ab139eb703950d206a1a2a029f42da4fdf43896a342fa961ec8f7cd607de27270b49ec4ba7a635e2d34018387990e1a56d26287af39bf2708aee004a23
6
+ metadata.gz: b4e398e02a8fe619afc8982760c290a168785c4557dca30767fbeb039032d7907135e84d0598a5ac90b7b1cfb8413ceda83ebe4647702ba5c10c613ff0543574
7
+ data.tar.gz: 285a3e0f650a41bcb6cc4539f48c7efcb9bc3442f31c76f301089c4672e6d9c790f407dd9d53db4e216df4eacd9be019b5bc46e453437fa1614aa48555541c9a
data/.rspec CHANGED
@@ -1,2 +1,4 @@
1
- --format documentation
1
+ --require spec_helper
2
+ --format progress
2
3
  --color
4
+ --order rand
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
- | [![Gem Version](https://img.shields.io/gem/v/sentry-ruby?label=sentry-ruby)](https://rubygems.org/gems/sentry-ruby) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_ruby_test.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_ruby_test.yml) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-ruby) |
19
- | [![Gem Version](https://img.shields.io/gem/v/sentry-rails?label=sentry-rails)](https://rubygems.org/gems/sentry-rails) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_rails_test.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_rails_test.yml) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-rails) |
20
- | [![Gem Version](https://img.shields.io/gem/v/sentry-sidekiq?label=sentry-sidekiq)](https://rubygems.org/gems/sentry-sidekiq) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_sidekiq_test.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_sidekiq_test.yml) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-sidekiq) |
21
- | [![Gem Version](https://img.shields.io/gem/v/sentry-delayed_job?label=sentry-delayed_job)](https://rubygems.org/gems/sentry-delayed_job) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_delayed_job_test.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_delayed_job_test.yml) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-delayed_job) |
22
- | [![Gem Version](https://img.shields.io/gem/v/sentry-resque?label=sentry-resque)](https://rubygems.org/gems/sentry-resque) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_resque_test.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_resque_test.yml) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-resque) |
23
- | [![Gem Version](https://img.shields.io/gem/v/sentry-opentelemetry?label=sentry-opentelemetry)](https://rubygems.org/gems/sentry-opentelemetry) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_opentelemetry_test.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_opentelemetry_test.yml) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-opentelemetry) |
18
+ | [![Gem Version](https://img.shields.io/gem/v/sentry-ruby?label=sentry-ruby)](https://rubygems.org/gems/sentry-ruby) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [![codecov](https://codecov.io/gh/getsentry/sentry-ruby/graph/badge.svg?token=ZePzrpZFP6&component=sentry-ruby)](https://codecov.io/gh/getsentry/sentry-ruby) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-ruby) |
19
+ | [![Gem Version](https://img.shields.io/gem/v/sentry-rails?label=sentry-rails)](https://rubygems.org/gems/sentry-rails) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [![codecov](https://codecov.io/gh/getsentry/sentry-ruby/graph/badge.svg?token=ZePzrpZFP6&component=sentry-rails)](https://codecov.io/gh/getsentry/sentry-ruby) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-rails) |
20
+ | [![Gem Version](https://img.shields.io/gem/v/sentry-sidekiq?label=sentry-sidekiq)](https://rubygems.org/gems/sentry-sidekiq) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [![codecov](https://codecov.io/gh/getsentry/sentry-ruby/graph/badge.svg?token=ZePzrpZFP6&component=sentry-sidekiq)](https://codecov.io/gh/getsentry/sentry-ruby) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-sidekiq) |
21
+ | [![Gem Version](https://img.shields.io/gem/v/sentry-delayed_job?label=sentry-delayed_job)](https://rubygems.org/gems/sentry-delayed_job) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [![codecov](https://codecov.io/gh/getsentry/sentry-ruby/graph/badge.svg?token=ZePzrpZFP6&component=sentry-delayed_job)](https://codecov.io/gh/getsentry/sentry-ruby) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-delayed_job) |
22
+ | [![Gem Version](https://img.shields.io/gem/v/sentry-resque?label=sentry-resque)](https://rubygems.org/gems/sentry-resque) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [![codecov](https://codecov.io/gh/getsentry/sentry-ruby/graph/badge.svg?token=ZePzrpZFP6&component=sentry-resque)](https://codecov.io/gh/getsentry/sentry-ruby) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](https://www.rubydoc.info/gems/sentry-resque) |
23
+ | [![Gem Version](https://img.shields.io/gem/v/sentry-opentelemetry?label=sentry-opentelemetry)](https://rubygems.org/gems/sentry-opentelemetry) | [![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml/badge.svg)](https://github.com/getsentry/sentry-ruby/actions/workflows/tests.yml) | [![codecov](https://codecov.io/gh/getsentry/sentry-ruby/graph/badge.svg?token=ZePzrpZFP6&component=sentry-opentelemetry)](https://codecov.io/gh/getsentry/sentry-ruby) | [![API doc](https://img.shields.io/badge/API%20doc-rubydoc.info-blue)](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
@@ -6,17 +6,13 @@ CLOBBER.include "pkg"
6
6
  require "bundler/gem_helper"
7
7
  Bundler::GemHelper.install_tasks(name: "sentry-ruby")
8
8
 
9
- require "rspec/core/rake_task"
9
+ require_relative "../lib/sentry/test/rake_tasks"
10
10
 
11
- RSpec::Core::RakeTask.new(:spec).tap do |task|
12
- task.rspec_opts = "--order rand"
13
- task.exclude_pattern = "spec/isolated/**/*_spec.rb"
14
- end
11
+ ISOLATED_SPECS = "spec/isolated/**/*_spec.rb"
15
12
 
16
- task :isolated_specs do
17
- Dir["spec/isolated/*"].each do |file|
18
- sh "bundle exec rspec #{file}"
19
- end
20
- end
13
+ Sentry::Test::RakeTasks.define_spec_tasks(
14
+ isolated_specs_pattern: ISOLATED_SPECS,
15
+ spec_exclude_pattern: ISOLATED_SPECS
16
+ )
21
17
 
22
- task default: [:spec, :isolated_specs]
18
+ task default: [:spec, :"spec:isolated"]
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
@@ -41,7 +42,9 @@ module Sentry
41
42
 
42
43
  @spotlight_transport = SpotlightTransport.new(configuration) if configuration.spotlight
43
44
 
44
- @log_event_buffer = LogEventBuffer.new(configuration, self).start
45
+ if configuration.enable_logs
46
+ @log_event_buffer = LogEventBuffer.new(configuration, self).start
47
+ end
45
48
  end
46
49
 
47
50
  # Applies the given scope's data to the event and sends it to Sentry.
@@ -113,7 +116,7 @@ module Sentry
113
116
  def flush
114
117
  transport.flush if configuration.sending_to_dsn_allowed?
115
118
  spotlight_transport.flush if spotlight_transport
116
- @log_event_buffer.flush
119
+ @log_event_buffer&.flush
117
120
  end
118
121
 
119
122
  # Initializes an Event object with the given exception. Returns `nil` if the exception's class is excluded from reporting.
@@ -194,12 +197,7 @@ module Sentry
194
197
 
195
198
  attributes = options.reject { |k, _| k == :level || k == :severity }
196
199
 
197
- LogEvent.new(
198
- level: level,
199
- body: message,
200
- timestamp: Time.now.to_f,
201
- attributes: attributes
202
- )
200
+ LogEvent.new(level: level, body: message, attributes: attributes)
203
201
  end
204
202
 
205
203
  # Initializes an Event object with the given Transaction object.
@@ -272,6 +270,53 @@ module Sentry
272
270
  raise
273
271
  end
274
272
 
273
+ # Send an envelope with batched logs
274
+ # @param log_events [Array<LogEvent>] the log events to be sent
275
+ # @api private
276
+ # @return [void]
277
+ def send_logs(log_events)
278
+ envelope = Envelope.new(
279
+ event_id: Sentry::Utils.uuid,
280
+ sent_at: Sentry.utc_now.iso8601,
281
+ dsn: configuration.dsn,
282
+ sdk: Sentry.sdk_meta
283
+ )
284
+
285
+ discarded_count = 0
286
+ envelope_items = []
287
+
288
+ if configuration.before_send_log
289
+ log_events.each do |log_event|
290
+ processed_log_event = configuration.before_send_log.call(log_event)
291
+
292
+ if processed_log_event
293
+ envelope_items << processed_log_event.to_hash
294
+ else
295
+ discarded_count += 1
296
+ end
297
+ end
298
+
299
+ envelope_items
300
+ else
301
+ envelope_items = log_events.map(&:to_hash)
302
+ end
303
+
304
+ envelope.add_item(
305
+ {
306
+ type: "log",
307
+ item_count: envelope_items.size,
308
+ content_type: "application/vnd.sentry.items.log+json"
309
+ },
310
+ { items: envelope_items }
311
+ )
312
+
313
+ send_envelope(envelope)
314
+
315
+ unless discarded_count.zero?
316
+ transport.record_lost_event(:before_send, "log_item", num: discarded_count)
317
+ end
318
+ end
319
+
275
320
  # Send an envelope directly to Sentry.
276
321
  # @param envelope [Envelope] the envelope to be sent.
277
322
  # @return [void]
@@ -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
@@ -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 < Event
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
- def initialize(configuration: Sentry.configuration, **options)
37
- super(configuration: configuration)
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
- @contexts = DEFAULT_CONTEXT
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 = :"serialize_#{name}"
94
+ serializer = SERIALIZERS[name]
57
95
 
58
- if respond_to?(serializer, true)
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
- Time.parse(timestamp).to_f
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 = attributes.each_with_object({}) do |(key, value), memo|
101
- memo[key] = attribute_hash(value)
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
- case value
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.send_envelope(to_envelope)
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 unless event.is_a?(LogEvent)
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
- event.dynamic_sampling_context ||= span.get_dynamic_sampling_context
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
- event.dynamic_sampling_context ||= propagation_context.get_dynamic_sampling_context
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
@@ -262,7 +262,7 @@ module Sentry
262
262
 
263
263
 
264
264
  # Sets the span's status.
265
- # @param satus [String] status of the span.
265
+ # @param status [String] status of the span.
266
266
  def set_status(status)
267
267
  @status = status
268
268
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sentry
4
+ # Ruby Logger support Add commentMore actions
5
+ # intercepts any logger instance and send the log to Sentry too.
6
+ module StdLibLogger
7
+ SEVERITY_MAP = {
8
+ 0 => :debug,
9
+ 1 => :info,
10
+ 2 => :warn,
11
+ 3 => :error,
12
+ 4 => :fatal
13
+ }.freeze
14
+
15
+ def add(severity, message = nil, progname = nil, &block)
16
+ result = super
17
+
18
+ return unless Sentry.initialized? && Sentry.get_current_hub
19
+
20
+ # exclude sentry SDK logs -- to prevent recursive log action,
21
+ # do not process internal logs again
22
+ if message.nil? && progname != Sentry::Logger::PROGNAME
23
+
24
+ # handle different nature of Ruby Logger class:
25
+ # inspo from Sentry::Breadcrumb::SentryLogger
26
+ if block_given?
27
+ message = yield
28
+ else
29
+ message = progname
30
+ end
31
+
32
+ message = message.to_s.strip
33
+
34
+ if !message.nil? && message != Sentry::Logger::PROGNAME && method = SEVERITY_MAP[severity]
35
+ Sentry.logger.send(method, message)
36
+ end
37
+ end
38
+
39
+ result
40
+ end
41
+ end
42
+ end
43
+
44
+ Sentry.register_patch(:logger) do |config|
45
+ if config.enable_logs
46
+ ::Logger.prepend(Sentry::StdLibLogger)
47
+ else
48
+ config.sdk_logger.warn(":logger patch enabled but `enable_logs` is turned off - skipping applying patch")
49
+ end
50
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sentry
4
- VERSION = "5.24.0"
4
+ VERSION = "5.26.0"
5
5
  end
data/lib/sentry-ruby.rb CHANGED
@@ -690,3 +690,4 @@ require "sentry/puma"
690
690
  require "sentry/graphql"
691
691
  require "sentry/faraday"
692
692
  require "sentry/excon"
693
+ require "sentry/std_lib_logger"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.24.0
4
+ version: 5.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
@@ -129,6 +129,7 @@ files:
129
129
  - lib/sentry/session.rb
130
130
  - lib/sentry/session_flusher.rb
131
131
  - lib/sentry/span.rb
132
+ - lib/sentry/std_lib_logger.rb
132
133
  - lib/sentry/structured_logger.rb
133
134
  - lib/sentry/test_helper.rb
134
135
  - lib/sentry/threaded_periodic_worker.rb
@@ -154,15 +155,15 @@ files:
154
155
  - lib/sentry/version.rb
155
156
  - sentry-ruby-core.gemspec
156
157
  - sentry-ruby.gemspec
157
- homepage: https://github.com/getsentry/sentry-ruby/tree/5.24.0/sentry-ruby
158
+ homepage: https://github.com/getsentry/sentry-ruby/tree/5.26.0/sentry-ruby
158
159
  licenses:
159
160
  - MIT
160
161
  metadata:
161
- homepage_uri: https://github.com/getsentry/sentry-ruby/tree/5.24.0/sentry-ruby
162
- source_code_uri: https://github.com/getsentry/sentry-ruby/tree/5.24.0/sentry-ruby
163
- changelog_uri: https://github.com/getsentry/sentry-ruby/blob/5.24.0/CHANGELOG.md
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
164
165
  bug_tracker_uri: https://github.com/getsentry/sentry-ruby/issues
165
- documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/5.24.0
166
+ documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/5.26.0
166
167
  rdoc_options: []
167
168
  require_paths:
168
169
  - lib