sentry-ruby-core 4.8.1 → 4.9.1
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 +2 -0
- data/README.md +2 -0
- data/lib/sentry/background_worker.rb +3 -1
- data/lib/sentry/backtrace.rb +1 -3
- data/lib/sentry/breadcrumb.rb +22 -3
- data/lib/sentry/breadcrumb_buffer.rb +14 -0
- data/lib/sentry/client.rb +35 -2
- data/lib/sentry/configuration.rb +86 -41
- data/lib/sentry/envelope.rb +1 -0
- data/lib/sentry/event.rb +54 -18
- data/lib/sentry/hub.rb +3 -0
- data/lib/sentry/interface.rb +1 -10
- data/lib/sentry/interfaces/exception.rb +11 -3
- data/lib/sentry/interfaces/request.rb +34 -18
- data/lib/sentry/interfaces/stacktrace.rb +4 -0
- data/lib/sentry/interfaces/stacktrace_builder.rb +37 -10
- data/lib/sentry/interfaces/threads.rb +10 -2
- data/lib/sentry/linecache.rb +1 -0
- data/lib/sentry/net/http.rb +50 -64
- data/lib/sentry/rake.rb +12 -2
- data/lib/sentry/release_detector.rb +1 -0
- data/lib/sentry/scope.rb +67 -1
- data/lib/sentry/span.rb +83 -8
- data/lib/sentry/transaction.rb +42 -9
- data/lib/sentry/transaction_event.rb +8 -0
- data/lib/sentry/transport.rb +4 -1
- data/lib/sentry/utils/logging_helper.rb +4 -4
- data/lib/sentry/version.rb +1 -1
- data/lib/sentry-ruby.rb +116 -29
- data/sentry-ruby.gemspec +1 -1
- metadata +3 -2
data/lib/sentry-ruby.rb
CHANGED
@@ -18,7 +18,6 @@ require "sentry/transaction"
|
|
18
18
|
require "sentry/hub"
|
19
19
|
require "sentry/background_worker"
|
20
20
|
|
21
|
-
|
22
21
|
[
|
23
22
|
"sentry/rake",
|
24
23
|
"sentry/rack",
|
@@ -39,6 +38,7 @@ module Sentry
|
|
39
38
|
THREAD_LOCAL = :sentry_hub
|
40
39
|
|
41
40
|
class << self
|
41
|
+
# @!visibility private
|
42
42
|
def exception_locals_tp
|
43
43
|
@exception_locals_tp ||= TracePoint.new(:raise) do |tp|
|
44
44
|
exception = tp.raised_exception
|
@@ -55,46 +55,100 @@ module Sentry
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
# @!attribute [rw] background_worker
|
59
|
+
# @return [BackgroundWorker]
|
58
60
|
attr_accessor :background_worker
|
59
61
|
|
60
62
|
##### Patch Registration #####
|
61
|
-
|
63
|
+
|
64
|
+
# @!visibility private
|
62
65
|
def register_patch(&block)
|
63
66
|
registered_patches << block
|
64
67
|
end
|
65
68
|
|
69
|
+
# @!visibility private
|
66
70
|
def apply_patches(config)
|
67
71
|
registered_patches.each do |patch|
|
68
72
|
patch.call(config)
|
69
73
|
end
|
70
74
|
end
|
71
75
|
|
76
|
+
# @!visibility private
|
72
77
|
def registered_patches
|
73
78
|
@registered_patches ||= []
|
74
79
|
end
|
75
80
|
|
76
81
|
##### Integrations #####
|
77
|
-
|
82
|
+
|
78
83
|
# Returns a hash that contains all the integrations that have been registered to the main SDK.
|
84
|
+
#
|
85
|
+
# @return [Hash{String=>Hash}]
|
79
86
|
def integrations
|
80
87
|
@integrations ||= {}
|
81
88
|
end
|
82
89
|
|
83
90
|
# Registers the SDK integration with its name and version.
|
91
|
+
#
|
92
|
+
# @param name [String] name of the integration
|
93
|
+
# @param version [String] version of the integration
|
84
94
|
def register_integration(name, version)
|
85
95
|
meta = { name: "sentry.ruby.#{name}", version: version }.freeze
|
86
96
|
integrations[name.to_s] = meta
|
87
97
|
end
|
88
98
|
|
89
99
|
##### Method Delegation #####
|
90
|
-
|
100
|
+
|
91
101
|
extend Forwardable
|
92
102
|
|
103
|
+
# @!macro [new] configuration
|
104
|
+
# The Configuration object that's used for configuring the client and its transport.
|
105
|
+
# @return [Configuration]
|
106
|
+
# @!macro [new] send_event
|
107
|
+
# Sends the event to Sentry.
|
108
|
+
# @param event [Event] the event to be sent.
|
109
|
+
# @param hint [Hash] the hint data that'll be passed to `before_send` callback.
|
110
|
+
# @return [Event]
|
111
|
+
|
112
|
+
# @!method configuration
|
113
|
+
# @!macro configuration
|
114
|
+
# @!method send_event
|
115
|
+
# @!macro send_event
|
93
116
|
def_delegators :get_current_client, :configuration, :send_event
|
117
|
+
|
118
|
+
# @!macro [new] set_extras
|
119
|
+
# Updates the scope's extras attribute by merging with the old value.
|
120
|
+
# @param extras [Hash]
|
121
|
+
# @return [Hash]
|
122
|
+
# @!macro [new] set_user
|
123
|
+
# Sets the scope's user attribute.
|
124
|
+
# @param user [Hash]
|
125
|
+
# @return [Hash]
|
126
|
+
# @!macro [new] set_context
|
127
|
+
# Adds a new key-value pair to current contexts.
|
128
|
+
# @param key [String, Symbol]
|
129
|
+
# @param value [Object]
|
130
|
+
# @return [Hash]
|
131
|
+
# @!macro [new] set_tags
|
132
|
+
# Updates the scope's tags attribute by merging with the old value.
|
133
|
+
# @param tags [Hash]
|
134
|
+
# @return [Hash]
|
135
|
+
|
136
|
+
# @!method set_tags
|
137
|
+
# @!macro set_tags
|
138
|
+
# @!method set_extras
|
139
|
+
# @!macro set_extras
|
140
|
+
# @!method set_user
|
141
|
+
# @!macro set_user
|
142
|
+
# @!method set_context
|
143
|
+
# @!macro set_context
|
94
144
|
def_delegators :get_current_scope, :set_tags, :set_extras, :set_user, :set_context
|
95
145
|
|
96
146
|
##### Main APIs #####
|
147
|
+
|
148
|
+
# Initializes the SDK with given configuration.
|
97
149
|
#
|
150
|
+
# @yieldparam config [Configuration]
|
151
|
+
# @return [void]
|
98
152
|
def init(&block)
|
99
153
|
config = Configuration.new
|
100
154
|
yield(config) if block_given?
|
@@ -116,24 +170,36 @@ module Sentry
|
|
116
170
|
end
|
117
171
|
end
|
118
172
|
|
173
|
+
# Returns true if the SDK is initialized.
|
174
|
+
#
|
175
|
+
# @return [Boolean]
|
176
|
+
def initialized?
|
177
|
+
!!@main_hub
|
178
|
+
end
|
179
|
+
|
119
180
|
# Returns an uri for security policy reporting that's generated from the given DSN
|
120
181
|
# (To learn more about security policy reporting: https://docs.sentry.io/product/security-policy-reporting/)
|
121
182
|
#
|
122
183
|
# It returns nil if
|
184
|
+
# - The SDK is not initialized yet.
|
185
|
+
# - The DSN is not provided or is invalid.
|
123
186
|
#
|
124
|
-
#
|
125
|
-
# 2. The DSN is not provided or is invalid.
|
187
|
+
# @return [String, nil]
|
126
188
|
def csp_report_uri
|
127
189
|
return unless initialized?
|
128
190
|
configuration.csp_report_uri
|
129
191
|
end
|
130
192
|
|
131
193
|
# Returns the main thread's active hub.
|
194
|
+
#
|
195
|
+
# @return [Hub]
|
132
196
|
def get_main_hub
|
133
197
|
@main_hub
|
134
198
|
end
|
135
199
|
|
136
200
|
# Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
|
201
|
+
#
|
202
|
+
# @return [Breadcrumb, nil]
|
137
203
|
def add_breadcrumb(breadcrumb, **options)
|
138
204
|
get_current_hub&.add_breadcrumb(breadcrumb, **options)
|
139
205
|
end
|
@@ -141,6 +207,8 @@ module Sentry
|
|
141
207
|
# Returns the current active hub.
|
142
208
|
# If the current thread doesn't have an active hub, it will clone the main thread's active hub,
|
143
209
|
# stores it in the current thread, and then returns it.
|
210
|
+
#
|
211
|
+
# @return [Hub]
|
144
212
|
def get_current_hub
|
145
213
|
# we need to assign a hub to the current thread if it doesn't have one yet
|
146
214
|
#
|
@@ -151,85 +219,105 @@ module Sentry
|
|
151
219
|
end
|
152
220
|
|
153
221
|
# Returns the current active client.
|
222
|
+
# @return [Client, nil]
|
154
223
|
def get_current_client
|
155
224
|
get_current_hub&.current_client
|
156
225
|
end
|
157
226
|
|
158
227
|
# Returns the current active scope.
|
228
|
+
#
|
229
|
+
# @return [Scope, nil]
|
159
230
|
def get_current_scope
|
160
231
|
get_current_hub&.current_scope
|
161
232
|
end
|
162
233
|
|
163
234
|
# Clones the main thread's active hub and stores it to the current thread.
|
235
|
+
#
|
236
|
+
# @return [void]
|
164
237
|
def clone_hub_to_current_thread
|
165
238
|
Thread.current.thread_variable_set(THREAD_LOCAL, get_main_hub.clone)
|
166
239
|
end
|
167
240
|
|
168
241
|
# Takes a block and yields the current active scope.
|
169
242
|
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
173
|
-
#
|
243
|
+
# @example
|
244
|
+
# Sentry.configure_scope do |scope|
|
245
|
+
# scope.set_tags(foo: "bar")
|
246
|
+
# end
|
174
247
|
#
|
175
|
-
#
|
176
|
-
# ```
|
248
|
+
# Sentry.capture_message("test message") # this event will have tags { foo: "bar" }
|
177
249
|
#
|
250
|
+
# @yieldparam scope [Scope]
|
251
|
+
# @return [void]
|
178
252
|
def configure_scope(&block)
|
179
253
|
get_current_hub&.configure_scope(&block)
|
180
254
|
end
|
181
255
|
|
182
256
|
# Takes a block and yields a temporary scope.
|
183
257
|
# The temporary scope will inherit all the attributes from the current active scope and replace it to be the active
|
184
|
-
# scope inside the block.
|
258
|
+
# scope inside the block.
|
185
259
|
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
#
|
260
|
+
# @example
|
261
|
+
# Sentry.configure_scope do |scope|
|
262
|
+
# scope.set_tags(foo: "bar")
|
263
|
+
# end
|
190
264
|
#
|
191
|
-
#
|
265
|
+
# Sentry.capture_message("test message") # this event will have tags { foo: "bar" }
|
192
266
|
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
267
|
+
# Sentry.with_scope do |temp_scope|
|
268
|
+
# temp_scope.set_tags(foo: "baz")
|
269
|
+
# Sentry.capture_message("test message 2") # this event will have tags { foo: "baz" }
|
270
|
+
# end
|
197
271
|
#
|
198
|
-
#
|
199
|
-
# ```
|
272
|
+
# Sentry.capture_message("test message 3") # this event will have tags { foo: "bar" }
|
200
273
|
#
|
274
|
+
# @yieldparam scope [Scope]
|
275
|
+
# @return [void]
|
201
276
|
def with_scope(&block)
|
202
277
|
get_current_hub&.with_scope(&block)
|
203
278
|
end
|
204
279
|
|
205
280
|
# Takes an exception and reports it to Sentry via the currently active hub.
|
281
|
+
#
|
282
|
+
# @yieldparam scope [Scope]
|
283
|
+
# @return [Event, nil]
|
206
284
|
def capture_exception(exception, **options, &block)
|
207
285
|
get_current_hub&.capture_exception(exception, **options, &block)
|
208
286
|
end
|
209
287
|
|
210
288
|
# Takes a message string and reports it to Sentry via the currently active hub.
|
289
|
+
#
|
290
|
+
# @yieldparam scope [Scope]
|
291
|
+
# @return [Event, nil]
|
211
292
|
def capture_message(message, **options, &block)
|
212
293
|
get_current_hub&.capture_message(message, **options, &block)
|
213
294
|
end
|
214
295
|
|
215
296
|
# Takes an instance of Sentry::Event and dispatches it to the currently active hub.
|
297
|
+
#
|
298
|
+
# @return [Event, nil]
|
216
299
|
def capture_event(event)
|
217
300
|
get_current_hub&.capture_event(event)
|
218
301
|
end
|
219
302
|
|
220
303
|
# Takes or initializes a new Sentry::Transaction and makes a sampling decision for it.
|
304
|
+
#
|
305
|
+
# @return [Transaction, nil]
|
221
306
|
def start_transaction(**options)
|
222
307
|
get_current_hub&.start_transaction(**options)
|
223
308
|
end
|
224
309
|
|
225
310
|
# Returns the id of the lastly reported Sentry::Event.
|
311
|
+
#
|
312
|
+
# @return [String, nil]
|
226
313
|
def last_event_id
|
227
314
|
get_current_hub&.last_event_id
|
228
315
|
end
|
229
316
|
|
230
317
|
|
231
318
|
##### Helpers #####
|
232
|
-
|
319
|
+
|
320
|
+
# @!visibility private
|
233
321
|
def sys_command(command)
|
234
322
|
result = `#{command} 2>&1` rescue nil
|
235
323
|
return if result.nil? || result.empty? || ($CHILD_STATUS && $CHILD_STATUS.exitstatus != 0)
|
@@ -237,18 +325,17 @@ module Sentry
|
|
237
325
|
result.strip
|
238
326
|
end
|
239
327
|
|
240
|
-
|
241
|
-
!!@main_hub
|
242
|
-
end
|
243
|
-
|
328
|
+
# @!visibility private
|
244
329
|
def logger
|
245
330
|
configuration.logger
|
246
331
|
end
|
247
332
|
|
333
|
+
# @!visibility private
|
248
334
|
def sdk_meta
|
249
335
|
META
|
250
336
|
end
|
251
337
|
|
338
|
+
# @!visibility private
|
252
339
|
def utc_now
|
253
340
|
Time.now.utc
|
254
341
|
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.9.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:
|
11
|
+
date: 2022-01-14 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
|