sentry-ruby-core 4.7.2 → 5.0.2

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