sentry-ruby-core 5.1.0 → 5.1.1

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: e8b9d0c43497ccc151613d208b6e9a51489586a41cbb7849cbcfcd3e5795765f
4
- data.tar.gz: 79e7e9f621b2fe8bfc1c1dc292a16392e499925c13bdc1c31c3f8e05240f42e0
3
+ metadata.gz: bfc28e6f57d57de669447d555889196617f72ce09624b343cd284375021f60f5
4
+ data.tar.gz: 5a6af91521df30a18ac1d021b2e59cd9e871653f1325cf6d65346e6c1dc91d7e
5
5
  SHA512:
6
- metadata.gz: 3def5710a658f0365dbe11292f548aafcaf6d467d04abd5e0973035c5c3243307d49347b829ae0aa93d459c2bf4036813ec2a4589471c8da21d438318144c0aa
7
- data.tar.gz: 99eab89037a4e468c7bb257d33aaf85ec8830102aa233a9af4c5091c92d67726f4ffab47b3eeedba07f079b4b3600145458e9283274532b534824acd21236617
6
+ metadata.gz: fbe80e4c07f972d3babbf8c26c31cd97da84e91d77e86628a6931f35d7e66c83fb48461838d1a3e402361ee78dd9a3b6dfe849833f08a4573328d0eb4b5e66e1
7
+ data.tar.gz: 0f081f57f89207ece5279bd77fa89d311c3d516231421ccf60f4b9c232065a606d80eacc53ab460f12e087aa7b2fadfc4cdd4636863cb58261cc4e58a605ad2c
@@ -3,24 +3,47 @@
3
3
  module Sentry
4
4
  # @api private
5
5
  class Envelope
6
- def initialize(headers)
6
+ class Item
7
+ attr_accessor :headers, :payload
8
+
9
+ def initialize(headers, payload)
10
+ @headers = headers
11
+ @payload = payload
12
+ end
13
+
14
+ def type
15
+ @headers[:type] || 'event'
16
+ end
17
+
18
+ def to_s
19
+ <<~ITEM
20
+ #{JSON.generate(@headers)}
21
+ #{JSON.generate(@payload)}
22
+ ITEM
23
+ end
24
+ end
25
+
26
+ attr_accessor :headers, :items
27
+
28
+ def initialize(headers = {})
7
29
  @headers = headers
8
30
  @items = []
9
31
  end
10
32
 
11
33
  def add_item(headers, payload)
12
- @items << [headers, payload]
34
+ @items << Item.new(headers, payload)
13
35
  end
14
36
 
15
37
  def to_s
16
- payload = @items.map do |item_headers, item_payload|
17
- <<~ENVELOPE
18
- #{JSON.generate(item_headers)}
19
- #{JSON.generate(item_payload)}
20
- ENVELOPE
21
- end.join("\n")
22
-
23
- "#{JSON.generate(@headers)}\n#{payload}"
38
+ [JSON.generate(@headers), *@items.map(&:to_s)].join("\n")
39
+ end
40
+
41
+ def item_types
42
+ @items.map(&:type)
43
+ end
44
+
45
+ def event_id
46
+ @headers[:event_id]
24
47
  end
25
48
  end
26
49
  end
data/lib/sentry/hub.rb CHANGED
@@ -94,6 +94,8 @@ module Sentry
94
94
  def capture_exception(exception, **options, &block)
95
95
  check_argument_type!(exception, ::Exception)
96
96
 
97
+ return if Sentry.exception_captured?(exception)
98
+
97
99
  return unless current_client
98
100
 
99
101
  options[:hint] ||= {}
@@ -104,7 +106,7 @@ module Sentry
104
106
 
105
107
  capture_event(event, **options, &block).tap do
106
108
  # mark the exception as captured so we can use this information to avoid duplicated capturing
107
- exception.instance_variable_set(:@__sentry_captured, true)
109
+ exception.instance_variable_set(Sentry::CAPTURED_SIGNATURE, true)
108
110
  end
109
111
  end
110
112
 
data/lib/sentry/scope.rb CHANGED
@@ -173,7 +173,7 @@ module Sentry
173
173
  def set_contexts(contexts_hash)
174
174
  check_argument_type!(contexts_hash, Hash)
175
175
  @contexts.merge!(contexts_hash) do |key, old, new|
176
- new.merge(old)
176
+ old.merge(new)
177
177
  end
178
178
  end
179
179
 
@@ -46,23 +46,19 @@ module Sentry
46
46
  end
47
47
 
48
48
  def send_event(event)
49
- event_hash = event.to_hash
50
- item_type = get_item_type(event_hash)
49
+ envelope = envelope_from_event(event)
50
+ send_envelope(envelope)
51
51
 
52
- if is_rate_limited?(item_type)
53
- log_info("Envelope [#{item_type}] not sent: rate limiting")
54
- record_lost_event(:ratelimit_backoff, item_type)
55
-
56
- return
57
- end
58
-
59
- encoded_data = encode(event)
52
+ event
53
+ end
60
54
 
61
- return nil unless encoded_data
55
+ def send_envelope(envelope)
56
+ reject_rate_limited_items(envelope)
62
57
 
63
- send_data(encoded_data)
58
+ return if envelope.items.empty?
64
59
 
65
- event
60
+ log_info("[Transport] Sending envelope with items [#{envelope.item_types.join(', ')}] #{envelope.event_id} to Sentry")
61
+ send_data(envelope.to_s)
66
62
  end
67
63
 
68
64
  def is_rate_limited?(item_type)
@@ -106,7 +102,7 @@ module Sentry
106
102
  'Sentry ' + fields.map { |key, value| "#{key}=#{value}" }.join(', ')
107
103
  end
108
104
 
109
- def encode(event)
105
+ def envelope_from_event(event)
110
106
  # Convert to hash
111
107
  event_payload = event.to_hash
112
108
  event_id = event_payload[:event_id] || event_payload["event_id"]
@@ -129,9 +125,8 @@ module Sentry
129
125
  client_report_headers, client_report_payload = fetch_pending_client_report
130
126
  envelope.add_item(client_report_headers, client_report_payload) if client_report_headers
131
127
 
132
- log_info("Sending envelope [#{item_type}] #{event_id} to Sentry")
133
128
 
134
- envelope.to_s
129
+ envelope
135
130
  end
136
131
 
137
132
  def record_lost_event(reason, item_type)
@@ -173,6 +168,19 @@ module Sentry
173
168
 
174
169
  [item_header, item_payload]
175
170
  end
171
+
172
+ def reject_rate_limited_items(envelope)
173
+ envelope.items.reject! do |item|
174
+ if is_rate_limited?(item.type)
175
+ log_info("[Transport] Envelope item [#{item.type}] not sent: rate limiting")
176
+ record_lost_event(:ratelimit_backoff, item.type)
177
+
178
+ true
179
+ else
180
+ false
181
+ end
182
+ end
183
+ end
176
184
  end
177
185
  end
178
186
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sentry
4
- VERSION = "5.1.0"
4
+ VERSION = "5.1.1"
5
5
  end
data/lib/sentry-ruby.rb CHANGED
@@ -31,6 +31,8 @@ end
31
31
  module Sentry
32
32
  META = { "name" => "sentry.ruby", "version" => Sentry::VERSION }.freeze
33
33
 
34
+ CAPTURED_SIGNATURE = :@__sentry_captured
35
+
34
36
  LOGGER_PROGNAME = "sentry".freeze
35
37
 
36
38
  SENTRY_TRACE_HEADER_NAME = "sentry-trace".freeze
@@ -350,6 +352,13 @@ module Sentry
350
352
  get_current_hub.last_event_id
351
353
  end
352
354
 
355
+ # Checks if the exception object has been captured by the SDK.
356
+ #
357
+ # @return [Boolean]
358
+ def exception_captured?(exc)
359
+ return false unless initialized?
360
+ !!exc.instance_variable_get(CAPTURED_SIGNATURE)
361
+ end
353
362
 
354
363
  ##### Helpers #####
355
364
 
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.1.0
4
+ version: 5.1.1
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-02-10 00:00:00.000000000 Z
11
+ date: 2022-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby