sentry-ruby 5.16.1 → 5.17.3

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/Rakefile +1 -1
  4. data/lib/sentry/background_worker.rb +1 -1
  5. data/lib/sentry/backtrace.rb +7 -3
  6. data/lib/sentry/check_in_event.rb +1 -1
  7. data/lib/sentry/client.rb +42 -9
  8. data/lib/sentry/configuration.rb +19 -11
  9. data/lib/sentry/cron/monitor_schedule.rb +1 -1
  10. data/lib/sentry/dsn.rb +1 -1
  11. data/lib/sentry/envelope.rb +18 -1
  12. data/lib/sentry/error_event.rb +2 -2
  13. data/lib/sentry/event.rb +8 -8
  14. data/lib/sentry/hub.rb +1 -1
  15. data/lib/sentry/integrable.rb +4 -0
  16. data/lib/sentry/interface.rb +1 -0
  17. data/lib/sentry/interfaces/exception.rb +5 -3
  18. data/lib/sentry/interfaces/mechanism.rb +20 -0
  19. data/lib/sentry/interfaces/request.rb +2 -2
  20. data/lib/sentry/interfaces/single_exception.rb +6 -4
  21. data/lib/sentry/interfaces/stacktrace_builder.rb +8 -0
  22. data/lib/sentry/metrics/aggregator.rb +276 -0
  23. data/lib/sentry/metrics/configuration.rb +47 -0
  24. data/lib/sentry/metrics/counter_metric.rb +25 -0
  25. data/lib/sentry/metrics/distribution_metric.rb +25 -0
  26. data/lib/sentry/metrics/gauge_metric.rb +35 -0
  27. data/lib/sentry/metrics/local_aggregator.rb +53 -0
  28. data/lib/sentry/metrics/metric.rb +19 -0
  29. data/lib/sentry/metrics/set_metric.rb +28 -0
  30. data/lib/sentry/metrics/timing.rb +43 -0
  31. data/lib/sentry/metrics.rb +55 -0
  32. data/lib/sentry/propagation_context.rb +9 -8
  33. data/lib/sentry/puma.rb +1 -1
  34. data/lib/sentry/rack/capture_exceptions.rb +6 -1
  35. data/lib/sentry/rake.rb +3 -1
  36. data/lib/sentry/scope.rb +7 -2
  37. data/lib/sentry/session.rb +2 -2
  38. data/lib/sentry/session_flusher.rb +1 -6
  39. data/lib/sentry/span.rb +16 -2
  40. data/lib/sentry/transaction.rb +15 -14
  41. data/lib/sentry/transaction_event.rb +5 -0
  42. data/lib/sentry/transport/configuration.rb +0 -1
  43. data/lib/sentry/transport.rb +7 -21
  44. data/lib/sentry/utils/argument_checking_helper.rb +6 -0
  45. data/lib/sentry/utils/real_ip.rb +1 -1
  46. data/lib/sentry/utils/request_id.rb +1 -1
  47. data/lib/sentry/version.rb +1 -1
  48. data/lib/sentry-ruby.rb +15 -3
  49. data/sentry-ruby.gemspec +1 -0
  50. metadata +27 -2
@@ -0,0 +1,276 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sentry
4
+ module Metrics
5
+ class Aggregator
6
+ include LoggingHelper
7
+
8
+ FLUSH_INTERVAL = 5
9
+ ROLLUP_IN_SECONDS = 10
10
+
11
+ # this is how far removed from user code in the backtrace we are
12
+ # when we record code locations
13
+ DEFAULT_STACKLEVEL = 4
14
+
15
+ KEY_SANITIZATION_REGEX = /[^a-zA-Z0-9_\-.]+/
16
+ UNIT_SANITIZATION_REGEX = /[^a-zA-Z0-9_]+/
17
+ TAG_KEY_SANITIZATION_REGEX = /[^a-zA-Z0-9_\-.\/]+/
18
+
19
+ TAG_VALUE_SANITIZATION_MAP = {
20
+ "\n" => "\\n",
21
+ "\r" => "\\r",
22
+ "\t" => "\\t",
23
+ "\\" => "\\\\",
24
+ "|" => "\\u{7c}",
25
+ "," => "\\u{2c}"
26
+ }
27
+
28
+ METRIC_TYPES = {
29
+ c: CounterMetric,
30
+ d: DistributionMetric,
31
+ g: GaugeMetric,
32
+ s: SetMetric
33
+ }
34
+
35
+ # exposed only for testing
36
+ attr_reader :client, :thread, :buckets, :flush_shift, :code_locations
37
+
38
+ def initialize(configuration, client)
39
+ @client = client
40
+ @logger = configuration.logger
41
+ @before_emit = configuration.metrics.before_emit
42
+ @enable_code_locations = configuration.metrics.enable_code_locations
43
+ @stacktrace_builder = configuration.stacktrace_builder
44
+
45
+ @default_tags = {}
46
+ @default_tags['release'] = configuration.release if configuration.release
47
+ @default_tags['environment'] = configuration.environment if configuration.environment
48
+
49
+ @thread = nil
50
+ @exited = false
51
+ @mutex = Mutex.new
52
+
53
+ # a nested hash of timestamp -> bucket keys -> Metric instance
54
+ @buckets = {}
55
+
56
+ # the flush interval needs to be shifted once per startup to create jittering
57
+ @flush_shift = Random.rand * ROLLUP_IN_SECONDS
58
+
59
+ # a nested hash of timestamp (start of day) -> meta keys -> frame
60
+ @code_locations = {}
61
+ end
62
+
63
+ def add(type,
64
+ key,
65
+ value,
66
+ unit: 'none',
67
+ tags: {},
68
+ timestamp: nil,
69
+ stacklevel: nil)
70
+ return unless ensure_thread
71
+ return unless METRIC_TYPES.keys.include?(type)
72
+
73
+ updated_tags = get_updated_tags(tags)
74
+ return if @before_emit && !@before_emit.call(key, updated_tags)
75
+
76
+ timestamp ||= Sentry.utc_now
77
+
78
+ # this is integer division and thus takes the floor of the division
79
+ # and buckets into 10 second intervals
80
+ bucket_timestamp = (timestamp.to_i / ROLLUP_IN_SECONDS) * ROLLUP_IN_SECONDS
81
+
82
+ serialized_tags = serialize_tags(updated_tags)
83
+ bucket_key = [type, key, unit, serialized_tags]
84
+
85
+ added = @mutex.synchronize do
86
+ record_code_location(type, key, unit, timestamp, stacklevel: stacklevel) if @enable_code_locations
87
+ process_bucket(bucket_timestamp, bucket_key, type, value)
88
+ end
89
+
90
+ # for sets, we pass on if there was a new entry to the local gauge
91
+ local_value = type == :s ? added : value
92
+ process_span_aggregator(bucket_key, local_value)
93
+ end
94
+
95
+ def flush(force: false)
96
+ flushable_buckets = get_flushable_buckets!(force)
97
+ code_locations = get_code_locations!
98
+ return if flushable_buckets.empty? && code_locations.empty?
99
+
100
+ envelope = Envelope.new
101
+
102
+ unless flushable_buckets.empty?
103
+ payload = serialize_buckets(flushable_buckets)
104
+ envelope.add_item(
105
+ { type: 'statsd', length: payload.bytesize },
106
+ payload
107
+ )
108
+ end
109
+
110
+ unless code_locations.empty?
111
+ code_locations.each do |timestamp, locations|
112
+ payload = serialize_locations(timestamp, locations)
113
+ envelope.add_item(
114
+ { type: 'metric_meta', content_type: 'application/json' },
115
+ payload
116
+ )
117
+ end
118
+ end
119
+
120
+ @client.capture_envelope(envelope)
121
+ end
122
+
123
+ def kill
124
+ log_debug('[Metrics::Aggregator] killing thread')
125
+
126
+ @exited = true
127
+ @thread&.kill
128
+ end
129
+
130
+ private
131
+
132
+ def ensure_thread
133
+ return false if @exited
134
+ return true if @thread&.alive?
135
+
136
+ @thread = Thread.new do
137
+ loop do
138
+ # TODO-neel-metrics use event for force flush later
139
+ sleep(FLUSH_INTERVAL)
140
+ flush
141
+ end
142
+ end
143
+
144
+ true
145
+ rescue ThreadError
146
+ log_debug('[Metrics::Aggregator] thread creation failed')
147
+ @exited = true
148
+ false
149
+ end
150
+
151
+ # important to sort for key consistency
152
+ def serialize_tags(tags)
153
+ tags.flat_map do |k, v|
154
+ if v.is_a?(Array)
155
+ v.map { |x| [k.to_s, x.to_s] }
156
+ else
157
+ [[k.to_s, v.to_s]]
158
+ end
159
+ end.sort
160
+ end
161
+
162
+ def get_flushable_buckets!(force)
163
+ @mutex.synchronize do
164
+ flushable_buckets = {}
165
+
166
+ if force
167
+ flushable_buckets = @buckets
168
+ @buckets = {}
169
+ else
170
+ cutoff = Sentry.utc_now.to_i - ROLLUP_IN_SECONDS - @flush_shift
171
+ flushable_buckets = @buckets.select { |k, _| k <= cutoff }
172
+ @buckets.reject! { |k, _| k <= cutoff }
173
+ end
174
+
175
+ flushable_buckets
176
+ end
177
+ end
178
+
179
+ def get_code_locations!
180
+ @mutex.synchronize do
181
+ code_locations = @code_locations
182
+ @code_locations = {}
183
+ code_locations
184
+ end
185
+ end
186
+
187
+ # serialize buckets to statsd format
188
+ def serialize_buckets(buckets)
189
+ buckets.map do |timestamp, timestamp_buckets|
190
+ timestamp_buckets.map do |metric_key, metric|
191
+ type, key, unit, tags = metric_key
192
+ values = metric.serialize.join(':')
193
+ sanitized_tags = tags.map { |k, v| "#{sanitize_tag_key(k)}:#{sanitize_tag_value(v)}" }.join(',')
194
+
195
+ "#{sanitize_key(key)}@#{sanitize_unit(unit)}:#{values}|#{type}|\##{sanitized_tags}|T#{timestamp}"
196
+ end
197
+ end.flatten.join("\n")
198
+ end
199
+
200
+ def serialize_locations(timestamp, locations)
201
+ mapping = locations.map do |meta_key, location|
202
+ type, key, unit = meta_key
203
+ mri = "#{type}:#{sanitize_key(key)}@#{sanitize_unit(unit)}"
204
+
205
+ # note this needs to be an array but it really doesn't serve a purpose right now
206
+ [mri, [location.merge(type: 'location')]]
207
+ end.to_h
208
+
209
+ { timestamp: timestamp, mapping: mapping }
210
+ end
211
+
212
+ def sanitize_key(key)
213
+ key.gsub(KEY_SANITIZATION_REGEX, '_')
214
+ end
215
+
216
+ def sanitize_unit(unit)
217
+ unit.gsub(UNIT_SANITIZATION_REGEX, '')
218
+ end
219
+
220
+ def sanitize_tag_key(key)
221
+ key.gsub(TAG_KEY_SANITIZATION_REGEX, '')
222
+ end
223
+
224
+ def sanitize_tag_value(value)
225
+ value.chars.map { |c| TAG_VALUE_SANITIZATION_MAP[c] || c }.join
226
+ end
227
+
228
+ def get_transaction_name
229
+ scope = Sentry.get_current_scope
230
+ return nil unless scope && scope.transaction_name
231
+ return nil if scope.transaction_source_low_quality?
232
+
233
+ scope.transaction_name
234
+ end
235
+
236
+ def get_updated_tags(tags)
237
+ updated_tags = @default_tags.merge(tags)
238
+
239
+ transaction_name = get_transaction_name
240
+ updated_tags['transaction'] = transaction_name if transaction_name
241
+
242
+ updated_tags
243
+ end
244
+
245
+ def process_span_aggregator(key, value)
246
+ scope = Sentry.get_current_scope
247
+ return nil unless scope && scope.span
248
+ return nil if scope.transaction_source_low_quality?
249
+
250
+ scope.span.metrics_local_aggregator.add(key, value)
251
+ end
252
+
253
+ def process_bucket(timestamp, key, type, value)
254
+ @buckets[timestamp] ||= {}
255
+
256
+ if (metric = @buckets[timestamp][key])
257
+ old_weight = metric.weight
258
+ metric.add(value)
259
+ metric.weight - old_weight
260
+ else
261
+ metric = METRIC_TYPES[type].new(value)
262
+ @buckets[timestamp][key] = metric
263
+ metric.weight
264
+ end
265
+ end
266
+
267
+ def record_code_location(type, key, unit, timestamp, stacklevel: nil)
268
+ meta_key = [type, key, unit]
269
+ start_of_day = Time.utc(timestamp.year, timestamp.month, timestamp.day).to_i
270
+
271
+ @code_locations[start_of_day] ||= {}
272
+ @code_locations[start_of_day][meta_key] ||= @stacktrace_builder.metrics_code_location(caller[stacklevel || DEFAULT_STACKLEVEL])
273
+ end
274
+ end
275
+ end
276
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sentry
4
+ module Metrics
5
+ class Configuration
6
+ include ArgumentCheckingHelper
7
+
8
+ # Enable metrics usage.
9
+ # Starts a new {Sentry::Metrics::Aggregator} instance to aggregate metrics
10
+ # and a thread to aggregate flush every 5 seconds.
11
+ # @return [Boolean]
12
+ attr_accessor :enabled
13
+
14
+ # Enable code location reporting.
15
+ # Will be sent once per day.
16
+ # True by default.
17
+ # @return [Boolean]
18
+ attr_accessor :enable_code_locations
19
+
20
+ # Optional Proc, called before emitting a metric to the aggregator.
21
+ # Use it to filter keys (return false/nil) or update tags.
22
+ # Make sure to return true at the end.
23
+ #
24
+ # @example
25
+ # config.metrics.before_emit = lambda do |key, tags|
26
+ # return nil if key == 'foo'
27
+ # tags[:bar] = 42
28
+ # tags.delete(:baz)
29
+ # true
30
+ # end
31
+ #
32
+ # @return [Proc, nil]
33
+ attr_reader :before_emit
34
+
35
+ def initialize
36
+ @enabled = false
37
+ @enable_code_locations = true
38
+ end
39
+
40
+ def before_emit=(value)
41
+ check_callable!("metrics.before_emit", value)
42
+
43
+ @before_emit = value
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sentry
4
+ module Metrics
5
+ class CounterMetric < Metric
6
+ attr_reader :value
7
+
8
+ def initialize(value)
9
+ @value = value.to_f
10
+ end
11
+
12
+ def add(value)
13
+ @value += value.to_f
14
+ end
15
+
16
+ def serialize
17
+ [value]
18
+ end
19
+
20
+ def weight
21
+ 1
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sentry
4
+ module Metrics
5
+ class DistributionMetric < Metric
6
+ attr_reader :value
7
+
8
+ def initialize(value)
9
+ @value = [value.to_f]
10
+ end
11
+
12
+ def add(value)
13
+ @value << value.to_f
14
+ end
15
+
16
+ def serialize
17
+ value
18
+ end
19
+
20
+ def weight
21
+ value.size
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sentry
4
+ module Metrics
5
+ class GaugeMetric < Metric
6
+ attr_reader :last, :min, :max, :sum, :count
7
+
8
+ def initialize(value)
9
+ value = value.to_f
10
+ @last = value
11
+ @min = value
12
+ @max = value
13
+ @sum = value
14
+ @count = 1
15
+ end
16
+
17
+ def add(value)
18
+ value = value.to_f
19
+ @last = value
20
+ @min = [@min, value].min
21
+ @max = [@max, value].max
22
+ @sum += value
23
+ @count += 1
24
+ end
25
+
26
+ def serialize
27
+ [last, min, max, sum, count]
28
+ end
29
+
30
+ def weight
31
+ 5
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sentry
4
+ module Metrics
5
+ class LocalAggregator
6
+ # exposed only for testing
7
+ attr_reader :buckets
8
+
9
+ def initialize
10
+ @buckets = {}
11
+ end
12
+
13
+ def add(key, value)
14
+ if @buckets[key]
15
+ @buckets[key].add(value)
16
+ else
17
+ @buckets[key] = GaugeMetric.new(value)
18
+ end
19
+ end
20
+
21
+ def to_hash
22
+ return nil if @buckets.empty?
23
+
24
+ @buckets.map do |bucket_key, metric|
25
+ type, key, unit, tags = bucket_key
26
+
27
+ payload_key = "#{type}:#{key}@#{unit}"
28
+ payload_value = {
29
+ tags: deserialize_tags(tags),
30
+ min: metric.min,
31
+ max: metric.max,
32
+ count: metric.count,
33
+ sum: metric.sum
34
+ }
35
+
36
+ [payload_key, payload_value]
37
+ end.to_h
38
+ end
39
+
40
+ private
41
+
42
+ def deserialize_tags(tags)
43
+ tags.inject({}) do |h, tag|
44
+ k, v = tag
45
+ old = h[k]
46
+ # make it an array if key repeats
47
+ h[k] = old ? (old.is_a?(Array) ? old << v : [old, v]) : v
48
+ h
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sentry
4
+ module Metrics
5
+ class Metric
6
+ def add(value)
7
+ raise NotImplementedError
8
+ end
9
+
10
+ def serialize
11
+ raise NotImplementedError
12
+ end
13
+
14
+ def weight
15
+ raise NotImplementedError
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+ require 'zlib'
5
+
6
+ module Sentry
7
+ module Metrics
8
+ class SetMetric < Metric
9
+ attr_reader :value
10
+
11
+ def initialize(value)
12
+ @value = Set[value]
13
+ end
14
+
15
+ def add(value)
16
+ @value << value
17
+ end
18
+
19
+ def serialize
20
+ value.map { |x| x.is_a?(String) ? Zlib.crc32(x) : x.to_i }
21
+ end
22
+
23
+ def weight
24
+ value.size
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sentry
4
+ module Metrics
5
+ module Timing
6
+ class << self
7
+ def nanosecond
8
+ time = Sentry.utc_now
9
+ time.to_i * (10 ** 9) + time.nsec
10
+ end
11
+
12
+ def microsecond
13
+ time = Sentry.utc_now
14
+ time.to_i * (10 ** 6) + time.usec
15
+ end
16
+
17
+ def millisecond
18
+ Sentry.utc_now.to_i * (10 ** 3)
19
+ end
20
+
21
+ def second
22
+ Sentry.utc_now.to_i
23
+ end
24
+
25
+ def minute
26
+ Sentry.utc_now.to_i / 60.0
27
+ end
28
+
29
+ def hour
30
+ Sentry.utc_now.to_i / 3600.0
31
+ end
32
+
33
+ def day
34
+ Sentry.utc_now.to_i / (3600.0 * 24.0)
35
+ end
36
+
37
+ def week
38
+ Sentry.utc_now.to_i / (3600.0 * 24.0 * 7.0)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sentry/metrics/metric'
4
+ require 'sentry/metrics/counter_metric'
5
+ require 'sentry/metrics/distribution_metric'
6
+ require 'sentry/metrics/gauge_metric'
7
+ require 'sentry/metrics/set_metric'
8
+ require 'sentry/metrics/timing'
9
+ require 'sentry/metrics/aggregator'
10
+
11
+ module Sentry
12
+ module Metrics
13
+ DURATION_UNITS = %w[nanosecond microsecond millisecond second minute hour day week]
14
+ INFORMATION_UNITS = %w[bit byte kilobyte kibibyte megabyte mebibyte gigabyte gibibyte terabyte tebibyte petabyte pebibyte exabyte exbibyte]
15
+ FRACTIONAL_UNITS = %w[ratio percent]
16
+
17
+ OP_NAME = 'metric.timing'
18
+
19
+ class << self
20
+ def increment(key, value = 1.0, unit: 'none', tags: {}, timestamp: nil)
21
+ Sentry.metrics_aggregator&.add(:c, key, value, unit: unit, tags: tags, timestamp: timestamp)
22
+ end
23
+
24
+ def distribution(key, value, unit: 'none', tags: {}, timestamp: nil)
25
+ Sentry.metrics_aggregator&.add(:d, key, value, unit: unit, tags: tags, timestamp: timestamp)
26
+ end
27
+
28
+ def set(key, value, unit: 'none', tags: {}, timestamp: nil)
29
+ Sentry.metrics_aggregator&.add(:s, key, value, unit: unit, tags: tags, timestamp: timestamp)
30
+ end
31
+
32
+ def gauge(key, value, unit: 'none', tags: {}, timestamp: nil)
33
+ Sentry.metrics_aggregator&.add(:g, key, value, unit: unit, tags: tags, timestamp: timestamp)
34
+ end
35
+
36
+ def timing(key, unit: 'second', tags: {}, timestamp: nil, &block)
37
+ return unless block_given?
38
+ return yield unless DURATION_UNITS.include?(unit)
39
+
40
+ result, value = Sentry.with_child_span(op: OP_NAME, description: key) do |span|
41
+ tags.each { |k, v| span.set_tag(k, v.is_a?(Array) ? v.join(', ') : v.to_s) } if span
42
+
43
+ start = Timing.send(unit.to_sym)
44
+ result = yield
45
+ value = Timing.send(unit.to_sym) - start
46
+
47
+ [result, value]
48
+ end
49
+
50
+ Sentry.metrics_aggregator&.add(:d, key, value, unit: unit, tags: tags, timestamp: timestamp)
51
+ result
52
+ end
53
+ end
54
+ end
55
+ end
@@ -50,14 +50,15 @@ module Sentry
50
50
  if sentry_trace_data
51
51
  @trace_id, @parent_span_id, @parent_sampled = sentry_trace_data
52
52
 
53
- @baggage = if baggage_header && !baggage_header.empty?
54
- Baggage.from_incoming_header(baggage_header)
55
- else
56
- # If there's an incoming sentry-trace but no incoming baggage header,
57
- # for instance in traces coming from older SDKs,
58
- # baggage will be empty and frozen and won't be populated as head SDK.
59
- Baggage.new({})
60
- end
53
+ @baggage =
54
+ if baggage_header && !baggage_header.empty?
55
+ Baggage.from_incoming_header(baggage_header)
56
+ else
57
+ # If there's an incoming sentry-trace but no incoming baggage header,
58
+ # for instance in traces coming from older SDKs,
59
+ # baggage will be empty and frozen and won't be populated as head SDK.
60
+ Baggage.new({})
61
+ end
61
62
 
62
63
  @baggage.freeze!
63
64
  @incoming_trace = true
data/lib/sentry/puma.rb CHANGED
@@ -7,7 +7,7 @@ module Sentry
7
7
  module Server
8
8
  PUMA_4_AND_PRIOR = Gem::Version.new(::Puma::Const::PUMA_VERSION) < Gem::Version.new("5.0.0")
9
9
 
10
- def lowlevel_error(e, env, status=500)
10
+ def lowlevel_error(e, env, status = 500)
11
11
  result =
12
12
  if PUMA_4_AND_PRIOR
13
13
  super(e, env)
@@ -4,6 +4,7 @@ module Sentry
4
4
  module Rack
5
5
  class CaptureExceptions
6
6
  ERROR_EVENT_ID_KEY = "sentry.error_event_id"
7
+ MECHANISM_TYPE = "rack"
7
8
 
8
9
  def initialize(app)
9
10
  @app = app
@@ -56,7 +57,7 @@ module Sentry
56
57
  end
57
58
 
58
59
  def capture_exception(exception, env)
59
- Sentry.capture_exception(exception).tap do |event|
60
+ Sentry.capture_exception(exception, hint: { mechanism: mechanism }).tap do |event|
60
61
  env[ERROR_EVENT_ID_KEY] = event.event_id if event
61
62
  end
62
63
  end
@@ -74,6 +75,10 @@ module Sentry
74
75
  transaction.set_http_status(status_code)
75
76
  transaction.finish
76
77
  end
78
+
79
+ def mechanism
80
+ Sentry::Mechanism.new(type: MECHANISM_TYPE, handled: false)
81
+ end
77
82
  end
78
83
  end
79
84
  end
data/lib/sentry/rake.rb CHANGED
@@ -8,7 +8,9 @@ module Sentry
8
8
  module Application
9
9
  # @api private
10
10
  def display_error_message(ex)
11
- Sentry.capture_exception(ex) do |scope|
11
+ mechanism = Sentry::Mechanism.new(type: 'rake', handled: false)
12
+
13
+ Sentry.capture_exception(ex, hint: { mechanism: mechanism }) do |scope|
12
14
  task_name = top_level_tasks.join(' ')
13
15
  scope.set_transaction_name(task_name, source: :task)
14
16
  scope.set_tag("rake_task", task_name)