sentry-ruby-core 4.6.1 → 4.6.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efdd71de2f9ada8f2c3bbffd41df8edfed7847c7b93390f2ce64a588094bc3d3
4
- data.tar.gz: bdb0b838f35d1fc87c85eb63caf23e48d8234819935f2c80721cc28ec2f53fc8
3
+ metadata.gz: 4440f6ad3a4fd52dc9bd94c15a64e239a6957aca9adc7a410e8bd787d124bcae
4
+ data.tar.gz: c6736aba5112331695e81adc496f3c6ee5581ae2ee419ba880c912eb20cedde9
5
5
  SHA512:
6
- metadata.gz: 232f4e625023091167191a733fc5366017eb2212e94ffe939d2b48a3a42956866df2f6b503f5d8103d7246df955f1a203776cccc6537bd5039059ba4832370e3
7
- data.tar.gz: 0cac44f1407e6fd6a93a8fb789b0acefc0f36c9bc33899b149567c0dee91d677b469e7099752361d9b2227d6d76a40db8e1234901f12aed3c8407e7c30470091
6
+ metadata.gz: e38a7ad731a84ee1886c341f8e6484c2019ad328b0a7c3bd93583d1f3056088f5f8e050bf0d0b764a5938c80ca7e704608aa2a107e6b9f915f76cb6dc701e1dc
7
+ data.tar.gz: fd137796bb363205ba78929c987b1cb1e3f7f494058e9fb8a31348ef29dd071994ec30a816b7de3befcdc018f91bc437cfade282fa65aa57952ac0e863580291
data/lib/sentry-ruby.rb CHANGED
@@ -36,15 +36,27 @@ module Sentry
36
36
 
37
37
  THREAD_LOCAL = :sentry_hub
38
38
 
39
- def self.sdk_meta
40
- META
41
- end
39
+ class << self
40
+ attr_accessor :background_worker
42
41
 
43
- def self.utc_now
44
- Time.now.utc
45
- end
42
+ ##### Patch Registration #####
43
+ #
44
+ def register_patch(&block)
45
+ registered_patches << block
46
+ end
46
47
 
47
- class << self
48
+ def apply_patches(config)
49
+ registered_patches.each do |patch|
50
+ patch.call(config)
51
+ end
52
+ end
53
+
54
+ def registered_patches
55
+ @registered_patches ||= []
56
+ end
57
+
58
+ ##### Integrations #####
59
+ #
48
60
  # Returns a hash that contains all the integrations that have been registered to the main SDK.
49
61
  def integrations
50
62
  @integrations ||= {}
@@ -55,32 +67,16 @@ module Sentry
55
67
  meta = { name: "sentry.ruby.#{name}", version: version }.freeze
56
68
  integrations[name.to_s] = meta
57
69
  end
58
- end
59
70
 
60
- class << self
71
+ ##### Method Delegation #####
72
+ #
61
73
  extend Forwardable
62
74
 
63
75
  def_delegators :get_current_client, :configuration, :send_event
64
76
  def_delegators :get_current_scope, :set_tags, :set_extras, :set_user, :set_context
65
77
 
66
- attr_accessor :background_worker
67
-
68
- @@registered_patches = []
69
-
70
- def register_patch(&block)
71
- registered_patches << block
72
- end
73
-
74
- def apply_patches(config)
75
- registered_patches.each do |patch|
76
- patch.call(config)
77
- end
78
- end
79
-
80
- def registered_patches
81
- @@registered_patches
82
- end
83
-
78
+ ##### Main APIs #####
79
+ #
84
80
  def init(&block)
85
81
  config = Configuration.new
86
82
  yield(config) if block_given?
@@ -100,8 +96,8 @@ module Sentry
100
96
  end
101
97
 
102
98
  # Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
103
- def add_breadcrumb(breadcrumb)
104
- get_current_hub&.add_breadcrumb(breadcrumb)
99
+ def add_breadcrumb(breadcrumb, **options)
100
+ get_current_hub&.add_breadcrumb(breadcrumb, **options)
105
101
  end
106
102
 
107
103
  # Returns the current active hub.
@@ -193,6 +189,9 @@ module Sentry
193
189
  get_current_hub&.last_event_id
194
190
  end
195
191
 
192
+
193
+ ##### Helpers #####
194
+ #
196
195
  def sys_command(command)
197
196
  result = `#{command} 2>&1` rescue nil
198
197
  return if result.nil? || result.empty? || ($CHILD_STATUS && $CHILD_STATUS.exitstatus != 0)
@@ -207,6 +206,14 @@ module Sentry
207
206
  def logger
208
207
  configuration.logger
209
208
  end
209
+
210
+ def sdk_meta
211
+ META
212
+ end
213
+
214
+ def utc_now
215
+ Time.now.utc
216
+ end
210
217
  end
211
218
  end
212
219
 
@@ -67,7 +67,7 @@ module Sentry
67
67
  type: severity >= 3 ? "error" : level
68
68
  )
69
69
 
70
- Sentry.add_breadcrumb(crumb)
70
+ Sentry.add_breadcrumb(crumb, hint: { severity: severity })
71
71
  end
72
72
  end
73
73
 
data/lib/sentry/client.rb CHANGED
@@ -26,7 +26,12 @@ module Sentry
26
26
  def capture_event(event, scope, hint = {})
27
27
  return unless configuration.sending_allowed?
28
28
 
29
- scope.apply_to_event(event, hint)
29
+ event = scope.apply_to_event(event, hint)
30
+
31
+ if event.nil?
32
+ log_info("Discarded event because one of the event processors returned nil")
33
+ return
34
+ end
30
35
 
31
36
  if async_block = configuration.async
32
37
  dispatch_async_event(async_block, event, hint)
@@ -89,7 +89,7 @@ module Sentry
89
89
  # You should probably append to this rather than overwrite it.
90
90
  attr_accessor :excluded_exceptions
91
91
 
92
- # Boolean to check nested exceptions when deciding if to exclude. Defaults to false
92
+ # Boolean to check nested exceptions when deciding if to exclude. Defaults to true
93
93
  attr_accessor :inspect_exception_causes_for_exclusion
94
94
  alias inspect_exception_causes_for_exclusion? inspect_exception_causes_for_exclusion
95
95
 
@@ -405,7 +405,7 @@ module Sentry
405
405
  def sample_allowed?
406
406
  return true if sample_rate == 1.0
407
407
 
408
- if Random::DEFAULT.rand >= sample_rate
408
+ if Random.rand >= sample_rate
409
409
  @errors << "Excluded by random sample"
410
410
  false
411
411
  else
@@ -1,3 +1,5 @@
1
+ return if Object.method_defined?(:deep_dup)
2
+
1
3
  require 'sentry/core_ext/object/duplicable'
2
4
 
3
5
  #########################################
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ return if Object.method_defined?(:duplicable?)
2
3
 
3
4
  #########################################
4
5
  # This file was copied from Rails 5.2 #
data/lib/sentry/dsn.rb CHANGED
@@ -37,7 +37,6 @@ module Sentry
37
37
  def server
38
38
  server = "#{scheme}://#{host}"
39
39
  server += ":#{port}" unless port == PORT_MAP[scheme]
40
- server += path
41
40
  server
42
41
  end
43
42
 
data/lib/sentry/event.rb CHANGED
@@ -9,7 +9,7 @@ require 'sentry/utils/request_id'
9
9
 
10
10
  module Sentry
11
11
  class Event
12
- ATTRIBUTES = %i(
12
+ SERIALIZEABLE_ATTRIBUTES = %i(
13
13
  event_id level timestamp
14
14
  release environment server_name modules
15
15
  message user tags contexts extra
@@ -17,9 +17,13 @@ module Sentry
17
17
  platform sdk type
18
18
  )
19
19
 
20
+ WRITER_ATTRIBUTES = SERIALIZEABLE_ATTRIBUTES - %i(type timestamp level)
21
+
20
22
  MAX_MESSAGE_SIZE_IN_BYTES = 1024 * 8
21
23
 
22
- attr_accessor(*ATTRIBUTES)
24
+ attr_writer(*WRITER_ATTRIBUTES)
25
+ attr_reader(*SERIALIZEABLE_ATTRIBUTES)
26
+
23
27
  attr_reader :configuration, :request, :exception, :threads
24
28
 
25
29
  def initialize(configuration:, integration_meta: nil, message: nil)
@@ -99,9 +103,6 @@ module Sentry
99
103
  end
100
104
  end
101
105
 
102
- def type
103
- end
104
-
105
106
  def to_hash
106
107
  data = serialize_attributes
107
108
  data[:breadcrumbs] = breadcrumbs.to_hash if breadcrumbs
@@ -139,7 +140,7 @@ module Sentry
139
140
  private
140
141
 
141
142
  def serialize_attributes
142
- self.class::ATTRIBUTES.each_with_object({}) do |att, memo|
143
+ self.class::SERIALIZEABLE_ATTRIBUTES.each_with_object({}) do |att, memo|
143
144
  if value = public_send(att)
144
145
  memo[att] = value
145
146
  end
data/lib/sentry/hub.rb CHANGED
@@ -144,6 +144,17 @@ module Sentry
144
144
  current_scope.add_breadcrumb(breadcrumb)
145
145
  end
146
146
 
147
+ # this doesn't do anything to the already initialized background worker
148
+ # but it temporarily disables dispatching events to it
149
+ def with_background_worker_disabled(&block)
150
+ original_background_worker_threads = configuration.background_worker_threads
151
+ configuration.background_worker_threads = 0
152
+
153
+ block.call
154
+ ensure
155
+ configuration.background_worker_threads = original_background_worker_threads
156
+ end
157
+
147
158
  private
148
159
 
149
160
  def current_layer
data/lib/sentry/rake.rb CHANGED
@@ -1,17 +1,31 @@
1
1
  require "rake"
2
2
  require "rake/task"
3
3
 
4
- module Rake
5
- class Application
6
- alias orig_display_error_messsage display_error_message
7
- def display_error_message(ex)
8
- Sentry.capture_exception(ex, hint: { background: false }) do |scope|
9
- task_name = top_level_tasks.join(' ')
10
- scope.set_transaction_name(task_name)
11
- scope.set_tag("rake_task", task_name)
12
- end if Sentry.initialized? && !Sentry.configuration.skip_rake_integration
4
+ module Sentry
5
+ module Rake
6
+ module Application
7
+ def display_error_message(ex)
8
+ Sentry.capture_exception(ex, hint: { background: false }) do |scope|
9
+ task_name = top_level_tasks.join(' ')
10
+ scope.set_transaction_name(task_name)
11
+ scope.set_tag("rake_task", task_name)
12
+ end if Sentry.initialized? && !Sentry.configuration.skip_rake_integration
13
13
 
14
- orig_display_error_messsage(ex)
14
+ super
15
+ end
16
+ end
17
+
18
+ module Task
19
+ def execute(args=nil)
20
+ return super unless Sentry.initialized? && Sentry.get_current_hub
21
+
22
+ Sentry.get_current_hub.with_background_worker_disabled do
23
+ super
24
+ end
25
+ end
15
26
  end
16
27
  end
17
28
  end
29
+
30
+ Rake::Application.prepend(Sentry::Rake::Application)
31
+ Rake::Task.prepend(Sentry::Rake::Task)
@@ -4,22 +4,27 @@ module Sentry
4
4
  class TransactionEvent < Event
5
5
  TYPE = "transaction"
6
6
 
7
- ATTRIBUTES = %i(
7
+ SERIALIZEABLE_ATTRIBUTES = %i(
8
8
  event_id level timestamp start_timestamp
9
9
  release environment server_name modules
10
10
  user tags contexts extra
11
11
  transaction platform sdk type
12
12
  )
13
13
 
14
- attr_accessor(*ATTRIBUTES)
14
+ WRITER_ATTRIBUTES = SERIALIZEABLE_ATTRIBUTES - %i(type timestamp start_timestamp level)
15
+
16
+ attr_writer(*WRITER_ATTRIBUTES)
17
+ attr_reader(*SERIALIZEABLE_ATTRIBUTES)
18
+
15
19
  attr_accessor :spans
16
20
 
17
- def start_timestamp=(time)
18
- @start_timestamp = time.is_a?(Time) ? time.to_f : time
21
+ def initialize(configuration:, integration_meta: nil, message: nil)
22
+ super
23
+ @type = TYPE
19
24
  end
20
25
 
21
- def type
22
- TYPE
26
+ def start_timestamp=(time)
27
+ @start_timestamp = time.is_a?(Time) ? time.to_f : time
23
28
  end
24
29
 
25
30
  def to_hash
@@ -2,7 +2,8 @@ module Sentry
2
2
  class Transport
3
3
  class Configuration
4
4
  attr_accessor :timeout, :open_timeout, :proxy, :ssl, :ssl_ca_file, :ssl_verification, :http_adapter, :faraday_builder,
5
- :transport_class, :encoding
5
+ :encoding
6
+ attr_reader :transport_class
6
7
 
7
8
  def initialize
8
9
  @ssl_verification = true
@@ -1,3 +1,3 @@
1
1
  module Sentry
2
- VERSION = "4.6.1"
2
+ VERSION = "4.6.5"
3
3
  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.6.1
4
+ version: 4.6.5
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-07-08 00:00:00.000000000 Z
11
+ date: 2021-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday