sentry-ruby-core 4.7.3 → 4.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -0
- data/Gemfile +6 -2
- data/README.md +7 -7
- data/bin/console +5 -1
- data/lib/sentry/background_worker.rb +30 -2
- data/lib/sentry/backtrace.rb +1 -0
- data/lib/sentry/breadcrumb/sentry_logger.rb +2 -0
- data/lib/sentry/breadcrumb.rb +2 -0
- data/lib/sentry/breadcrumb_buffer.rb +2 -0
- data/lib/sentry/client.rb +13 -1
- data/lib/sentry/configuration.rb +136 -112
- data/lib/sentry/core_ext/object/deep_dup.rb +2 -0
- data/lib/sentry/core_ext/object/duplicable.rb +1 -0
- data/lib/sentry/dsn.rb +2 -0
- data/lib/sentry/envelope.rb +26 -0
- data/lib/sentry/event.rb +5 -0
- data/lib/sentry/exceptions.rb +2 -0
- data/lib/sentry/hub.rb +7 -0
- data/lib/sentry/integrable.rb +2 -0
- data/lib/sentry/interface.rb +2 -0
- data/lib/sentry/interfaces/exception.rb +2 -0
- data/lib/sentry/interfaces/single_exception.rb +31 -0
- data/lib/sentry/interfaces/stacktrace.rb +10 -0
- data/lib/sentry/interfaces/stacktrace_builder.rb +2 -0
- data/lib/sentry/interfaces/threads.rb +2 -0
- data/lib/sentry/linecache.rb +3 -0
- data/lib/sentry/net/http.rb +3 -0
- data/lib/sentry/rack/capture_exceptions.rb +2 -0
- data/lib/sentry/rack.rb +2 -0
- data/lib/sentry/rake.rb +16 -6
- data/lib/sentry/release_detector.rb +39 -0
- data/lib/sentry/scope.rb +8 -4
- data/lib/sentry/span.rb +1 -0
- data/lib/sentry/transaction.rb +6 -1
- data/lib/sentry/transport/configuration.rb +2 -0
- data/lib/sentry/transport/dummy_transport.rb +2 -0
- data/lib/sentry/transport/http_transport.rb +6 -4
- data/lib/sentry/transport.rb +77 -19
- data/lib/sentry/utils/argument_checking_helper.rb +2 -0
- data/lib/sentry/utils/custom_inspection.rb +14 -0
- data/lib/sentry/utils/exception_cause_chain.rb +10 -10
- data/lib/sentry/utils/logging_helper.rb +2 -0
- data/lib/sentry/utils/real_ip.rb +2 -0
- data/lib/sentry/utils/request_id.rb +2 -0
- data/lib/sentry/version.rb +3 -1
- data/lib/sentry-ruby.rb +102 -28
- data/sentry-ruby.gemspec +1 -1
- metadata +6 -2
data/lib/sentry-ruby.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "English"
|
2
4
|
require "forwardable"
|
3
5
|
require "time"
|
@@ -37,46 +39,77 @@ module Sentry
|
|
37
39
|
THREAD_LOCAL = :sentry_hub
|
38
40
|
|
39
41
|
class << self
|
42
|
+
# @!visibility private
|
43
|
+
def exception_locals_tp
|
44
|
+
@exception_locals_tp ||= TracePoint.new(:raise) do |tp|
|
45
|
+
exception = tp.raised_exception
|
46
|
+
|
47
|
+
# don't collect locals again if the exception is re-raised
|
48
|
+
next if exception.instance_variable_get(:@sentry_locals)
|
49
|
+
next unless tp.binding
|
50
|
+
|
51
|
+
locals = tp.binding.local_variables.each_with_object({}) do |local, result|
|
52
|
+
result[local] = tp.binding.local_variable_get(local)
|
53
|
+
end
|
54
|
+
|
55
|
+
exception.instance_variable_set(:@sentry_locals, locals)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# @!attribute [rw] background_worker
|
60
|
+
# @return [BackgroundWorker]
|
40
61
|
attr_accessor :background_worker
|
41
62
|
|
42
63
|
##### Patch Registration #####
|
43
|
-
|
64
|
+
|
65
|
+
# @!visibility private
|
44
66
|
def register_patch(&block)
|
45
67
|
registered_patches << block
|
46
68
|
end
|
47
69
|
|
70
|
+
# @!visibility private
|
48
71
|
def apply_patches(config)
|
49
72
|
registered_patches.each do |patch|
|
50
73
|
patch.call(config)
|
51
74
|
end
|
52
75
|
end
|
53
76
|
|
77
|
+
# @!visibility private
|
54
78
|
def registered_patches
|
55
79
|
@registered_patches ||= []
|
56
80
|
end
|
57
81
|
|
58
82
|
##### Integrations #####
|
59
|
-
|
83
|
+
|
60
84
|
# Returns a hash that contains all the integrations that have been registered to the main SDK.
|
85
|
+
#
|
86
|
+
# @return [Hash{String=>Hash}]
|
61
87
|
def integrations
|
62
88
|
@integrations ||= {}
|
63
89
|
end
|
64
90
|
|
65
91
|
# Registers the SDK integration with its name and version.
|
92
|
+
#
|
93
|
+
# @param name [String] name of the integration
|
94
|
+
# @param version [String] version of the integration
|
66
95
|
def register_integration(name, version)
|
67
96
|
meta = { name: "sentry.ruby.#{name}", version: version }.freeze
|
68
97
|
integrations[name.to_s] = meta
|
69
98
|
end
|
70
99
|
|
71
100
|
##### Method Delegation #####
|
72
|
-
|
101
|
+
|
73
102
|
extend Forwardable
|
74
103
|
|
75
104
|
def_delegators :get_current_client, :configuration, :send_event
|
76
105
|
def_delegators :get_current_scope, :set_tags, :set_extras, :set_user, :set_context
|
77
106
|
|
78
107
|
##### Main APIs #####
|
108
|
+
|
109
|
+
# Initializes the SDK with given configuration.
|
79
110
|
#
|
111
|
+
# @yieldparam config [Configuration]
|
112
|
+
# @return [void]
|
80
113
|
def init(&block)
|
81
114
|
config = Configuration.new
|
82
115
|
yield(config) if block_given?
|
@@ -88,26 +121,46 @@ module Sentry
|
|
88
121
|
Thread.current.thread_variable_set(THREAD_LOCAL, hub)
|
89
122
|
@main_hub = hub
|
90
123
|
@background_worker = Sentry::BackgroundWorker.new(config)
|
124
|
+
|
125
|
+
if config.capture_exception_frame_locals
|
126
|
+
exception_locals_tp.enable
|
127
|
+
end
|
128
|
+
|
129
|
+
at_exit do
|
130
|
+
@background_worker.shutdown
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# Returns true if the SDK is initialized.
|
135
|
+
#
|
136
|
+
# @return [Boolean]
|
137
|
+
def initialized?
|
138
|
+
!!@main_hub
|
91
139
|
end
|
92
140
|
|
93
141
|
# Returns an uri for security policy reporting that's generated from the given DSN
|
94
142
|
# (To learn more about security policy reporting: https://docs.sentry.io/product/security-policy-reporting/)
|
95
143
|
#
|
96
144
|
# It returns nil if
|
145
|
+
# - The SDK is not initialized yet.
|
146
|
+
# - The DSN is not provided or is invalid.
|
97
147
|
#
|
98
|
-
#
|
99
|
-
# 2. The DSN is not provided or is invalid.
|
148
|
+
# @return [String, nil]
|
100
149
|
def csp_report_uri
|
101
150
|
return unless initialized?
|
102
151
|
configuration.csp_report_uri
|
103
152
|
end
|
104
153
|
|
105
154
|
# Returns the main thread's active hub.
|
155
|
+
#
|
156
|
+
# @return [Hub]
|
106
157
|
def get_main_hub
|
107
158
|
@main_hub
|
108
159
|
end
|
109
160
|
|
110
161
|
# Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
|
162
|
+
#
|
163
|
+
# @return [Breadcrumb, nil]
|
111
164
|
def add_breadcrumb(breadcrumb, **options)
|
112
165
|
get_current_hub&.add_breadcrumb(breadcrumb, **options)
|
113
166
|
end
|
@@ -115,6 +168,8 @@ module Sentry
|
|
115
168
|
# Returns the current active hub.
|
116
169
|
# If the current thread doesn't have an active hub, it will clone the main thread's active hub,
|
117
170
|
# stores it in the current thread, and then returns it.
|
171
|
+
#
|
172
|
+
# @return [Hub]
|
118
173
|
def get_current_hub
|
119
174
|
# we need to assign a hub to the current thread if it doesn't have one yet
|
120
175
|
#
|
@@ -125,85 +180,105 @@ module Sentry
|
|
125
180
|
end
|
126
181
|
|
127
182
|
# Returns the current active client.
|
183
|
+
# @return [Client, nil]
|
128
184
|
def get_current_client
|
129
185
|
get_current_hub&.current_client
|
130
186
|
end
|
131
187
|
|
132
188
|
# Returns the current active scope.
|
189
|
+
#
|
190
|
+
# @return [Scope, nil]
|
133
191
|
def get_current_scope
|
134
192
|
get_current_hub&.current_scope
|
135
193
|
end
|
136
194
|
|
137
195
|
# Clones the main thread's active hub and stores it to the current thread.
|
196
|
+
#
|
197
|
+
# @return [void]
|
138
198
|
def clone_hub_to_current_thread
|
139
199
|
Thread.current.thread_variable_set(THREAD_LOCAL, get_main_hub.clone)
|
140
200
|
end
|
141
201
|
|
142
202
|
# Takes a block and yields the current active scope.
|
143
203
|
#
|
144
|
-
#
|
145
|
-
#
|
146
|
-
#
|
147
|
-
#
|
204
|
+
# @example
|
205
|
+
# Sentry.configure_scope do |scope|
|
206
|
+
# scope.set_tags(foo: "bar")
|
207
|
+
# end
|
148
208
|
#
|
149
|
-
#
|
150
|
-
# ```
|
209
|
+
# Sentry.capture_message("test message") # this event will have tags { foo: "bar" }
|
151
210
|
#
|
211
|
+
# @yieldparam scope [Scope]
|
212
|
+
# @return [void]
|
152
213
|
def configure_scope(&block)
|
153
214
|
get_current_hub&.configure_scope(&block)
|
154
215
|
end
|
155
216
|
|
156
217
|
# Takes a block and yields a temporary scope.
|
157
218
|
# The temporary scope will inherit all the attributes from the current active scope and replace it to be the active
|
158
|
-
# scope inside the block.
|
219
|
+
# scope inside the block.
|
159
220
|
#
|
160
|
-
#
|
161
|
-
#
|
162
|
-
#
|
163
|
-
#
|
221
|
+
# @example
|
222
|
+
# Sentry.configure_scope do |scope|
|
223
|
+
# scope.set_tags(foo: "bar")
|
224
|
+
# end
|
164
225
|
#
|
165
|
-
#
|
226
|
+
# Sentry.capture_message("test message") # this event will have tags { foo: "bar" }
|
166
227
|
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
228
|
+
# Sentry.with_scope do |temp_scope|
|
229
|
+
# temp_scope.set_tags(foo: "baz")
|
230
|
+
# Sentry.capture_message("test message 2") # this event will have tags { foo: "baz" }
|
231
|
+
# end
|
171
232
|
#
|
172
|
-
#
|
173
|
-
# ```
|
233
|
+
# Sentry.capture_message("test message 3") # this event will have tags { foo: "bar" }
|
174
234
|
#
|
235
|
+
# @yieldparam scope [Scope]
|
236
|
+
# @return [void]
|
175
237
|
def with_scope(&block)
|
176
238
|
get_current_hub&.with_scope(&block)
|
177
239
|
end
|
178
240
|
|
179
241
|
# Takes an exception and reports it to Sentry via the currently active hub.
|
242
|
+
#
|
243
|
+
# @yieldparam scope [Scope]
|
244
|
+
# @return [Event, nil]
|
180
245
|
def capture_exception(exception, **options, &block)
|
181
246
|
get_current_hub&.capture_exception(exception, **options, &block)
|
182
247
|
end
|
183
248
|
|
184
249
|
# Takes a message string and reports it to Sentry via the currently active hub.
|
250
|
+
#
|
251
|
+
# @yieldparam scope [Scope]
|
252
|
+
# @return [Event, nil]
|
185
253
|
def capture_message(message, **options, &block)
|
186
254
|
get_current_hub&.capture_message(message, **options, &block)
|
187
255
|
end
|
188
256
|
|
189
257
|
# Takes an instance of Sentry::Event and dispatches it to the currently active hub.
|
258
|
+
#
|
259
|
+
# @return [Event, nil]
|
190
260
|
def capture_event(event)
|
191
261
|
get_current_hub&.capture_event(event)
|
192
262
|
end
|
193
263
|
|
194
264
|
# Takes or initializes a new Sentry::Transaction and makes a sampling decision for it.
|
265
|
+
#
|
266
|
+
# @return [Transaction, nil]
|
195
267
|
def start_transaction(**options)
|
196
268
|
get_current_hub&.start_transaction(**options)
|
197
269
|
end
|
198
270
|
|
199
271
|
# Returns the id of the lastly reported Sentry::Event.
|
272
|
+
#
|
273
|
+
# @return [String, nil]
|
200
274
|
def last_event_id
|
201
275
|
get_current_hub&.last_event_id
|
202
276
|
end
|
203
277
|
|
204
278
|
|
205
279
|
##### Helpers #####
|
206
|
-
|
280
|
+
|
281
|
+
# @!visibility private
|
207
282
|
def sys_command(command)
|
208
283
|
result = `#{command} 2>&1` rescue nil
|
209
284
|
return if result.nil? || result.empty? || ($CHILD_STATUS && $CHILD_STATUS.exitstatus != 0)
|
@@ -211,18 +286,17 @@ module Sentry
|
|
211
286
|
result.strip
|
212
287
|
end
|
213
288
|
|
214
|
-
|
215
|
-
!!@main_hub
|
216
|
-
end
|
217
|
-
|
289
|
+
# @!visibility private
|
218
290
|
def logger
|
219
291
|
configuration.logger
|
220
292
|
end
|
221
293
|
|
294
|
+
# @!visibility private
|
222
295
|
def sdk_meta
|
223
296
|
META
|
224
297
|
end
|
225
298
|
|
299
|
+
# @!visibility private
|
226
300
|
def utc_now
|
227
301
|
Time.now.utc
|
228
302
|
end
|
data/sentry-ruby.gemspec
CHANGED
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
|
19
19
|
|
20
20
|
spec.add_dependency "sentry-ruby-core", Sentry::VERSION
|
21
|
-
spec.add_dependency "faraday", "
|
21
|
+
spec.add_dependency "faraday", "~> 1.0"
|
22
22
|
spec.add_dependency "concurrent-ruby", '~> 1.0', '>= 1.0.2'
|
23
23
|
end
|
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: 4.
|
4
|
+
version: 4.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sentry Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -48,6 +48,7 @@ extra_rdoc_files:
|
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
50
|
- ".rspec"
|
51
|
+
- ".yardopts"
|
51
52
|
- CHANGELOG.md
|
52
53
|
- CODE_OF_CONDUCT.md
|
53
54
|
- Gemfile
|
@@ -68,6 +69,7 @@ files:
|
|
68
69
|
- lib/sentry/core_ext/object/deep_dup.rb
|
69
70
|
- lib/sentry/core_ext/object/duplicable.rb
|
70
71
|
- lib/sentry/dsn.rb
|
72
|
+
- lib/sentry/envelope.rb
|
71
73
|
- lib/sentry/event.rb
|
72
74
|
- lib/sentry/exceptions.rb
|
73
75
|
- lib/sentry/hub.rb
|
@@ -85,6 +87,7 @@ files:
|
|
85
87
|
- lib/sentry/rack.rb
|
86
88
|
- lib/sentry/rack/capture_exceptions.rb
|
87
89
|
- lib/sentry/rake.rb
|
90
|
+
- lib/sentry/release_detector.rb
|
88
91
|
- lib/sentry/scope.rb
|
89
92
|
- lib/sentry/span.rb
|
90
93
|
- lib/sentry/transaction.rb
|
@@ -94,6 +97,7 @@ files:
|
|
94
97
|
- lib/sentry/transport/dummy_transport.rb
|
95
98
|
- lib/sentry/transport/http_transport.rb
|
96
99
|
- lib/sentry/utils/argument_checking_helper.rb
|
100
|
+
- lib/sentry/utils/custom_inspection.rb
|
97
101
|
- lib/sentry/utils/exception_cause_chain.rb
|
98
102
|
- lib/sentry/utils/logging_helper.rb
|
99
103
|
- lib/sentry/utils/real_ip.rb
|