sentry-ruby 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/sentry-ruby.rb +8 -2
- data/lib/sentry/breadcrumb.rb +7 -7
- data/lib/sentry/breadcrumb/sentry_logger.rb +10 -12
- data/lib/sentry/breadcrumb_buffer.rb +2 -5
- data/lib/sentry/client.rb +7 -7
- data/lib/sentry/configuration.rb +13 -38
- data/lib/sentry/event.rb +5 -1
- data/lib/sentry/hub.rb +6 -1
- data/lib/sentry/interfaces/request.rb +1 -10
- data/lib/sentry/scope.rb +3 -3
- data/lib/sentry/span.rb +9 -0
- data/lib/sentry/utils/request_id.rb +16 -0
- data/lib/sentry/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de5539f70eb6f49164765e4e13416bef15f8b697349f2d2e71f63ac57916f325
|
4
|
+
data.tar.gz: 89121fce3fb31be7fe783599ee204ab86354f70a870ce775c79e4a33f6141e13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca35ae1d033f68fcebfe2c3e9e4b91fa2784a56261423a1bc5e5c7550b6304eb63963bf4273b22e924db27e1287f256e712b7e74781d866e71bae288308e13ae
|
7
|
+
data.tar.gz: e5853d409d5bbbb4b60ecee8c1edc3c6de91971b39938c03a19895ce790246cc234e5441d848aaba745ccc90cc4bbd3f1df4eb3108c18ea68736dab41f2ca93f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.3.0
|
4
|
+
|
5
|
+
- Major API changes: [1123](https://github.com/getsentry/sentry-ruby/pull/1123)
|
6
|
+
- Support event hint: [1122](https://github.com/getsentry/sentry-ruby/pull/1122)
|
7
|
+
- Add request-id tag to events: [1120](https://github.com/getsentry/sentry-ruby/pull/1120) (by @tvec)
|
8
|
+
|
3
9
|
## 0.2.0
|
4
10
|
|
5
11
|
- Multiple fixes and refactorings
|
data/lib/sentry-ruby.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
1
3
|
require "sentry/version"
|
2
4
|
require "sentry/core_ext/object/deep_dup"
|
3
5
|
require "sentry/configuration"
|
@@ -28,6 +30,10 @@ module Sentry
|
|
28
30
|
end
|
29
31
|
|
30
32
|
class << self
|
33
|
+
extend Forwardable
|
34
|
+
|
35
|
+
def_delegators :get_current_scope, :set_tags, :set_extras, :set_user
|
36
|
+
|
31
37
|
def init(&block)
|
32
38
|
config = Configuration.new
|
33
39
|
yield(config)
|
@@ -46,8 +52,8 @@ module Sentry
|
|
46
52
|
configuration.logger
|
47
53
|
end
|
48
54
|
|
49
|
-
def
|
50
|
-
get_current_scope.breadcrumbs
|
55
|
+
def add_breadcrumb(breadcrumb, &block)
|
56
|
+
get_current_scope.breadcrumbs.record(breadcrumb, &block)
|
51
57
|
end
|
52
58
|
|
53
59
|
def configuration
|
data/lib/sentry/breadcrumb.rb
CHANGED
@@ -2,13 +2,13 @@ module Sentry
|
|
2
2
|
class Breadcrumb
|
3
3
|
attr_accessor :category, :data, :message, :level, :timestamp, :type
|
4
4
|
|
5
|
-
def initialize
|
6
|
-
@category =
|
7
|
-
@data = {}
|
8
|
-
@level =
|
9
|
-
@message =
|
10
|
-
@timestamp = Sentry.utc_now.to_i
|
11
|
-
@type =
|
5
|
+
def initialize(category: nil, data: nil, message: nil, timestamp: nil, level: nil, type: nil)
|
6
|
+
@category = category
|
7
|
+
@data = data || {}
|
8
|
+
@level = level
|
9
|
+
@message = message
|
10
|
+
@timestamp = timestamp || Sentry.utc_now.to_i
|
11
|
+
@type = type
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_hash
|
@@ -58,17 +58,15 @@ module Sentry
|
|
58
58
|
last_crumb = current_breadcrumbs.peek
|
59
59
|
# try to avoid dupes from logger broadcasts
|
60
60
|
if last_crumb.nil? || last_crumb.message != message
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
61
|
+
level = Sentry::Breadcrumb::SentryLogger::LEVELS.fetch(severity, nil)
|
62
|
+
crumb = Sentry::Breadcrumb.new(
|
63
|
+
level: level,
|
64
|
+
category: category,
|
65
|
+
message: message,
|
66
|
+
type: severity >= 3 ? "error" : level
|
67
|
+
)
|
68
|
+
|
69
|
+
Sentry.add_breadcrumb(crumb)
|
72
70
|
end
|
73
71
|
end
|
74
72
|
|
@@ -80,7 +78,7 @@ module Sentry
|
|
80
78
|
end
|
81
79
|
|
82
80
|
def current_breadcrumbs
|
83
|
-
Sentry.breadcrumbs
|
81
|
+
Sentry.get_current_scope.breadcrumbs
|
84
82
|
end
|
85
83
|
end
|
86
84
|
end
|
@@ -10,11 +10,8 @@ module Sentry
|
|
10
10
|
@buffer = Array.new(size)
|
11
11
|
end
|
12
12
|
|
13
|
-
def record(crumb
|
14
|
-
if block_given?
|
15
|
-
crumb = Breadcrumb.new if crumb.nil?
|
16
|
-
yield(crumb)
|
17
|
-
end
|
13
|
+
def record(crumb)
|
14
|
+
yield(crumb) if block_given?
|
18
15
|
@buffer.slice!(0)
|
19
16
|
@buffer << crumb
|
20
17
|
end
|
data/lib/sentry/client.rb
CHANGED
@@ -20,8 +20,8 @@ module Sentry
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def capture_event(event, scope)
|
24
|
-
scope.apply_to_event(event)
|
23
|
+
def capture_event(event, scope, hint = nil)
|
24
|
+
scope.apply_to_event(event, hint)
|
25
25
|
|
26
26
|
if configuration.async?
|
27
27
|
begin
|
@@ -30,10 +30,10 @@ module Sentry
|
|
30
30
|
configuration.async.call(event.to_json_compatible)
|
31
31
|
rescue => e
|
32
32
|
configuration.logger.error(LOGGER_PROGNAME) { "async event sending failed: #{e.message}" }
|
33
|
-
send_event(event)
|
33
|
+
send_event(event, hint)
|
34
34
|
end
|
35
35
|
else
|
36
|
-
send_event(event)
|
36
|
+
send_event(event, hint)
|
37
37
|
end
|
38
38
|
|
39
39
|
event
|
@@ -63,10 +63,10 @@ module Sentry
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
def send_event(event)
|
67
|
-
return false unless configuration.sending_allowed?
|
66
|
+
def send_event(event, hint = nil)
|
67
|
+
return false unless configuration.sending_allowed?
|
68
68
|
|
69
|
-
event = configuration.before_send.call(event) if configuration.before_send
|
69
|
+
event = configuration.before_send.call(event, hint) if configuration.before_send
|
70
70
|
if event.nil?
|
71
71
|
configuration.logger.info(LOGGER_PROGNAME) { "Discarded event because before_send returned nil" }
|
72
72
|
return
|
data/lib/sentry/configuration.rb
CHANGED
@@ -46,13 +46,13 @@ module Sentry
|
|
46
46
|
attr_accessor :context_lines
|
47
47
|
|
48
48
|
# RACK_ENV by default.
|
49
|
-
attr_reader :
|
49
|
+
attr_reader :environment
|
50
50
|
|
51
51
|
# the dsn value, whether it's set via `config.dsn=` or `ENV["SENTRY_DSN"]`
|
52
52
|
attr_reader :dsn
|
53
53
|
|
54
|
-
# Whitelist of
|
55
|
-
attr_accessor :
|
54
|
+
# Whitelist of enabled_environments that will send notifications to Sentry. Array of Strings.
|
55
|
+
attr_accessor :enabled_environments
|
56
56
|
|
57
57
|
# Logger 'progname's to exclude from breadcrumbs
|
58
58
|
attr_accessor :exclude_loggers
|
@@ -101,12 +101,6 @@ module Sentry
|
|
101
101
|
|
102
102
|
attr_accessor :server_name
|
103
103
|
|
104
|
-
# Provide a configurable callback to determine event capture.
|
105
|
-
# Note that the object passed into the block will be a String (messages) or
|
106
|
-
# an exception.
|
107
|
-
# e.g. lambda { |exc_or_msg| exc_or_msg.some_attr == false }
|
108
|
-
attr_reader :should_capture
|
109
|
-
|
110
104
|
# Return a Transport::Configuration object for transport-related configurations.
|
111
105
|
attr_reader :transport
|
112
106
|
|
@@ -154,8 +148,8 @@ module Sentry
|
|
154
148
|
self.async = false
|
155
149
|
self.breadcrumbs_logger = []
|
156
150
|
self.context_lines = 3
|
157
|
-
self.
|
158
|
-
self.
|
151
|
+
self.environment = environment_from_env
|
152
|
+
self.enabled_environments = []
|
159
153
|
self.exclude_loggers = []
|
160
154
|
self.excluded_exceptions = IGNORE_DEFAULT.dup
|
161
155
|
self.inspect_exception_causes_for_exclusion = false
|
@@ -169,7 +163,6 @@ module Sentry
|
|
169
163
|
self.send_default_pii = false
|
170
164
|
self.dsn = ENV['SENTRY_DSN']
|
171
165
|
self.server_name = server_name_from_env
|
172
|
-
self.should_capture = false
|
173
166
|
|
174
167
|
self.before_send = false
|
175
168
|
self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT
|
@@ -213,14 +206,6 @@ module Sentry
|
|
213
206
|
@breadcrumbs_logger = logger
|
214
207
|
end
|
215
208
|
|
216
|
-
def should_capture=(value)
|
217
|
-
unless value == false || value.respond_to?(:call)
|
218
|
-
raise ArgumentError, "should_capture must be callable (or false to disable)"
|
219
|
-
end
|
220
|
-
|
221
|
-
@should_capture = value
|
222
|
-
end
|
223
|
-
|
224
209
|
def before_send=(value)
|
225
210
|
unless value == false || value.respond_to?(:call)
|
226
211
|
raise ArgumentError, "before_send must be callable (or false to disable)"
|
@@ -229,20 +214,17 @@ module Sentry
|
|
229
214
|
@before_send = value
|
230
215
|
end
|
231
216
|
|
232
|
-
def
|
233
|
-
@
|
217
|
+
def environment=(environment)
|
218
|
+
@environment = environment.to_s
|
234
219
|
end
|
235
220
|
|
236
|
-
def
|
221
|
+
def sending_allowed?
|
237
222
|
@errors = []
|
238
223
|
|
239
224
|
valid? &&
|
240
|
-
|
241
|
-
capture_allowed_by_callback?(message_or_exc) &&
|
225
|
+
capture_in_environment? &&
|
242
226
|
sample_allowed?
|
243
227
|
end
|
244
|
-
# If we cannot capture, we cannot send.
|
245
|
-
alias sending_allowed? capture_allowed?
|
246
228
|
|
247
229
|
def error_messages
|
248
230
|
@errors = [@errors[0]] + @errors[1..-1].map(&:downcase) # fix case of all but first
|
@@ -267,7 +249,7 @@ module Sentry
|
|
267
249
|
end
|
268
250
|
|
269
251
|
def enabled_in_current_env?
|
270
|
-
|
252
|
+
enabled_environments.empty? || enabled_environments.include?(environment)
|
271
253
|
end
|
272
254
|
|
273
255
|
def tracing_enabled?
|
@@ -353,17 +335,10 @@ module Sentry
|
|
353
335
|
ENV['SENTRY_RELEASE']
|
354
336
|
end
|
355
337
|
|
356
|
-
def
|
338
|
+
def capture_in_environment?
|
357
339
|
return true if enabled_in_current_env?
|
358
340
|
|
359
|
-
@errors << "Not configured to send/capture in environment '#{
|
360
|
-
false
|
361
|
-
end
|
362
|
-
|
363
|
-
def capture_allowed_by_callback?(message_or_exc)
|
364
|
-
return true if !should_capture || message_or_exc.nil? || should_capture.call(message_or_exc)
|
365
|
-
|
366
|
-
@errors << "should_capture returned false"
|
341
|
+
@errors << "Not configured to send/capture in environment '#{environment}'"
|
367
342
|
false
|
368
343
|
end
|
369
344
|
|
@@ -394,7 +369,7 @@ module Sentry
|
|
394
369
|
Socket.gethostbyname(hostname).first rescue server_name
|
395
370
|
end
|
396
371
|
|
397
|
-
def
|
372
|
+
def environment_from_env
|
398
373
|
ENV['SENTRY_CURRENT_ENV'] || ENV['SENTRY_ENVIRONMENT'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
|
399
374
|
end
|
400
375
|
|
data/lib/sentry/event.rb
CHANGED
@@ -5,6 +5,7 @@ require 'securerandom'
|
|
5
5
|
require 'sentry/interface'
|
6
6
|
require 'sentry/backtrace'
|
7
7
|
require 'sentry/utils/real_ip'
|
8
|
+
require 'sentry/utils/request_id'
|
8
9
|
|
9
10
|
module Sentry
|
10
11
|
class Event
|
@@ -37,7 +38,7 @@ module Sentry
|
|
37
38
|
@fingerprint = []
|
38
39
|
|
39
40
|
@server_name = configuration.server_name
|
40
|
-
@environment = configuration.
|
41
|
+
@environment = configuration.environment
|
41
42
|
@release = configuration.release
|
42
43
|
@modules = configuration.gem_specs if configuration.send_modules
|
43
44
|
|
@@ -82,6 +83,9 @@ module Sentry
|
|
82
83
|
if configuration.send_default_pii && ip = calculate_real_ip_from_rack(env.dup)
|
83
84
|
user[:ip_address] = ip
|
84
85
|
end
|
86
|
+
if request_id = Utils::RequestId.read_from(env)
|
87
|
+
tags[:request_id] = request_id
|
88
|
+
end
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
data/lib/sentry/hub.rb
CHANGED
@@ -80,12 +80,16 @@ module Sentry
|
|
80
80
|
|
81
81
|
return unless event
|
82
82
|
|
83
|
+
options[:hint] ||= {}
|
84
|
+
options[:hint] = options[:hint].merge(exception: exception)
|
83
85
|
capture_event(event, **options, &block)
|
84
86
|
end
|
85
87
|
|
86
88
|
def capture_message(message, **options, &block)
|
87
89
|
return unless current_client
|
88
90
|
|
91
|
+
options[:hint] ||= {}
|
92
|
+
options[:hint] = options[:hint].merge(message: message)
|
89
93
|
event = current_client.event_from_message(message)
|
90
94
|
capture_event(event, **options, &block)
|
91
95
|
end
|
@@ -93,6 +97,7 @@ module Sentry
|
|
93
97
|
def capture_event(event, **options, &block)
|
94
98
|
return unless current_client
|
95
99
|
|
100
|
+
hint = options.delete(:hint)
|
96
101
|
scope = current_scope.dup
|
97
102
|
|
98
103
|
if block
|
@@ -103,7 +108,7 @@ module Sentry
|
|
103
108
|
scope.update_from_options(**options)
|
104
109
|
end
|
105
110
|
|
106
|
-
event = current_client.capture_event(event, scope)
|
111
|
+
event = current_client.capture_event(event, scope, hint)
|
107
112
|
|
108
113
|
@last_event_id = event.event_id
|
109
114
|
event
|
@@ -39,15 +39,6 @@ module Sentry
|
|
39
39
|
|
40
40
|
private
|
41
41
|
|
42
|
-
# Request ID based on ActionDispatch::RequestId
|
43
|
-
def read_request_id_from(env_hash)
|
44
|
-
REQUEST_ID_HEADERS.each do |key|
|
45
|
-
request_id = env_hash[key]
|
46
|
-
return request_id if request_id
|
47
|
-
end
|
48
|
-
nil
|
49
|
-
end
|
50
|
-
|
51
42
|
# See Sentry server default limits at
|
52
43
|
# https://github.com/getsentry/sentry/blob/master/src/sentry/conf/server.py
|
53
44
|
def read_data_from(request)
|
@@ -67,7 +58,7 @@ module Sentry
|
|
67
58
|
begin
|
68
59
|
key = key.to_s # rack env can contain symbols
|
69
60
|
value = value.to_s
|
70
|
-
next memo['X-Request-Id'] ||=
|
61
|
+
next memo['X-Request-Id'] ||= Utils::RequestId.read_from(env_hash) if Utils::RequestId::REQUEST_ID_HEADERS.include?(key)
|
71
62
|
next unless key.upcase == key # Non-upper case stuff isn't either
|
72
63
|
|
73
64
|
# Rack adds in an incorrect HTTP_VERSION key, which causes downstream
|
data/lib/sentry/scope.rb
CHANGED
@@ -15,7 +15,7 @@ module Sentry
|
|
15
15
|
set_default_value
|
16
16
|
end
|
17
17
|
|
18
|
-
def apply_to_event(event)
|
18
|
+
def apply_to_event(event, hint = nil)
|
19
19
|
event.tags = tags.merge(event.tags)
|
20
20
|
event.user = user.merge(event.user)
|
21
21
|
event.extra = extra.merge(event.extra)
|
@@ -26,14 +26,14 @@ module Sentry
|
|
26
26
|
end
|
27
27
|
|
28
28
|
event.fingerprint = fingerprint
|
29
|
-
event.level
|
29
|
+
event.level = level
|
30
30
|
event.transaction = transaction_names.last
|
31
31
|
event.breadcrumbs = breadcrumbs
|
32
32
|
event.rack_env = rack_env
|
33
33
|
|
34
34
|
unless @event_processors.empty?
|
35
35
|
@event_processors.each do |processor_block|
|
36
|
-
event = processor_block.call(event)
|
36
|
+
event = processor_block.call(event, hint)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
data/lib/sentry/span.rb
CHANGED
@@ -45,6 +45,7 @@ module Sentry
|
|
45
45
|
return if @timestamp
|
46
46
|
|
47
47
|
@timestamp = Sentry.utc_now.to_f
|
48
|
+
self
|
48
49
|
end
|
49
50
|
|
50
51
|
def to_sentry_trace
|
@@ -91,6 +92,14 @@ module Sentry
|
|
91
92
|
child_span
|
92
93
|
end
|
93
94
|
|
95
|
+
def with_child_span(**options, &block)
|
96
|
+
child_span = start_child(**options)
|
97
|
+
|
98
|
+
yield(child_span)
|
99
|
+
|
100
|
+
child_span.finish
|
101
|
+
end
|
102
|
+
|
94
103
|
def set_op(op)
|
95
104
|
@op = op
|
96
105
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Sentry
|
2
|
+
module Utils
|
3
|
+
module RequestId
|
4
|
+
REQUEST_ID_HEADERS = %w(action_dispatch.request_id HTTP_X_REQUEST_ID).freeze
|
5
|
+
|
6
|
+
# Request ID based on ActionDispatch::RequestId
|
7
|
+
def self.read_from(env_hash)
|
8
|
+
REQUEST_ID_HEADERS.each do |key|
|
9
|
+
request_id = env_hash[key]
|
10
|
+
return request_id if request_id
|
11
|
+
end
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/sentry/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentry-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sentry Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/sentry/transport/state.rb
|
79
79
|
- lib/sentry/utils/exception_cause_chain.rb
|
80
80
|
- lib/sentry/utils/real_ip.rb
|
81
|
+
- lib/sentry/utils/request_id.rb
|
81
82
|
- lib/sentry/version.rb
|
82
83
|
- sentry-ruby.gemspec
|
83
84
|
homepage: https://github.com/getsentry/raven-ruby
|