sentry-ruby 4.1.3 → 4.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 823d9f50e4335e2c08fa6a6afedac78e2c6243ea94a104db560870f0021c51c7
4
- data.tar.gz: 385143cfb2e2218afb9fca2bebe07a26bca02565cd525b32a1abdde38bcd53e0
3
+ metadata.gz: a99aa0cd23f84ac85fe92aeff13f70aabb29f8b4f7e5239b48806f66e9af5376
4
+ data.tar.gz: bb5c2b32b2086f913fd6e8f55566b9a6bb6331aae414922e65696e4eb87457fe
5
5
  SHA512:
6
- metadata.gz: 143855b2a274c65d17b72a60adbe8ff72b2d71ad316796d7899803d3bf28f4645cba7afa1518aabae592b0093ba51f5f3c41d755ce9674cd65b3da3363a5bb72
7
- data.tar.gz: a4b8fc9795553867da3b5d6c0eebd6f2d4198805c21f19a936149653ddac882b4db5cba46678f016982f3529314a95d5a23e9770173f53dbeb33ff7ba6a4b6c7
6
+ metadata.gz: 70c330fa68f5a42588f7dfa815b7e2276b508de5c3a606c058d37afff5ef3b50ba3c3071cbb51356fd859c97ca19ffdd95a986931e4f54b752ad2b11b352feae
7
+ data.tar.gz: 0d0dde39080876a24f52256c503778226ae53bf0a668ba55503ae6c76bb4d0731b1cb7c775029fd2ec258c5e4eacbcb679272d7dd9495831ac1f6b77d56124ff
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.1.4
4
+
5
+ - Fix headers serialization for sentry-ruby [#1197](https://github.com/getsentry/sentry-ruby/pull/1197) (by @moofkit)
6
+ - Support capturing "sentry-trace" header from the middleware [#1205](https://github.com/getsentry/sentry-ruby/pull/1205)
7
+ - Document public APIs on the Sentry module [#1208](https://github.com/getsentry/sentry-ruby/pull/1208)
8
+ - Check the argument type of capture_exception and capture_event helpers [#1209](https://github.com/getsentry/sentry-ruby/pull/1209)
9
+
3
10
  ## 4.1.3
4
11
 
5
12
  - rm reference to old constant (from Rails v2.2) [#1184](https://github.com/getsentry/sentry-ruby/pull/1184)
@@ -3,6 +3,7 @@ require "time"
3
3
 
4
4
  require "sentry/version"
5
5
  require "sentry/core_ext/object/deep_dup"
6
+ require "sentry/utils/argument_checking_helper"
6
7
  require "sentry/configuration"
7
8
  require "sentry/logger"
8
9
  require "sentry/event"
@@ -41,10 +42,12 @@ module Sentry
41
42
  end
42
43
 
43
44
  class << self
45
+ # Returns a hash that contains all the integrations that have been registered to the main SDK.
44
46
  def integrations
45
47
  @integrations ||= {}
46
48
  end
47
49
 
50
+ # Registers the SDK integration with its name and version.
48
51
  def register_integration(name, version)
49
52
  meta = { name: "sentry.ruby.#{name}", version: version }.freeze
50
53
  integrations[name.to_s] = meta
@@ -70,26 +73,19 @@ module Sentry
70
73
  @background_worker = Sentry::BackgroundWorker.new(config)
71
74
  end
72
75
 
73
- def initialized?
74
- !!@main_hub
75
- end
76
-
76
+ # Returns the main thread's active hub.
77
77
  def get_main_hub
78
78
  @main_hub
79
79
  end
80
80
 
81
- def logger
82
- configuration.logger
83
- end
84
-
85
- def add_breadcrumb(breadcrumb, &block)
86
- get_current_scope.breadcrumbs.record(breadcrumb, &block)
87
- end
88
-
89
- def get_current_client
90
- get_current_hub&.current_client
81
+ # Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
82
+ def add_breadcrumb(breadcrumb)
83
+ get_current_scope.breadcrumbs.record(breadcrumb)
91
84
  end
92
85
 
86
+ # Returns the current active hub.
87
+ # If the current thread doesn't have an active hub, it will clone the main thread's active hub,
88
+ # stores it in the current thread, and then returns it.
93
89
  def get_current_hub
94
90
  # we need to assign a hub to the current thread if it doesn't have one yet
95
91
  #
@@ -99,38 +95,79 @@ module Sentry
99
95
  Thread.current[THREAD_LOCAL] || clone_hub_to_current_thread
100
96
  end
101
97
 
102
- def clone_hub_to_current_thread
103
- Thread.current[THREAD_LOCAL] = get_main_hub.clone
98
+ # Returns the current active client.
99
+ def get_current_client
100
+ get_current_hub&.current_client
104
101
  end
105
102
 
103
+ # Returns the current active scope.
106
104
  def get_current_scope
107
105
  get_current_hub&.current_scope
108
106
  end
109
107
 
110
- def with_scope(&block)
111
- get_current_hub&.with_scope(&block)
108
+ # Clones the main thread's active hub and stores it to the current thread.
109
+ def clone_hub_to_current_thread
110
+ Thread.current[THREAD_LOCAL] = get_main_hub.clone
112
111
  end
113
112
 
113
+ # Takes a block and yields the current active scope.
114
+ #
115
+ # ```ruby
116
+ # Sentry.configure_scope do |scope|
117
+ # scope.set_tags(foo: "bar")
118
+ # end
119
+ #
120
+ # Sentry.capture_message("test message") # this event will have tags { foo: "bar" }
121
+ # ```
122
+ #
114
123
  def configure_scope(&block)
115
124
  get_current_hub&.configure_scope(&block)
116
125
  end
117
126
 
118
- def capture_event(event)
119
- get_current_hub&.capture_event(event)
127
+ # Takes a block and yields a temporary scope.
128
+ # The temporary scope will inherit all the attributes from the current active scope and replace it to be the active
129
+ # scope inside the block. For example:
130
+ #
131
+ # ```ruby
132
+ # Sentry.configure_scope do |scope|
133
+ # scope.set_tags(foo: "bar")
134
+ # end
135
+ #
136
+ # Sentry.capture_message("test message") # this event will have tags { foo: "bar" }
137
+ #
138
+ # Sentry.with_scope do |temp_scope|
139
+ # temp_scope.set_tags(foo: "baz")
140
+ # Sentry.capture_message("test message 2") # this event will have tags { foo: "baz" }
141
+ # end
142
+ #
143
+ # Sentry.capture_message("test message 3") # this event will have tags { foo: "bar" }
144
+ # ```
145
+ #
146
+ def with_scope(&block)
147
+ get_current_hub&.with_scope(&block)
120
148
  end
121
149
 
150
+ # Takes an exception and reports it to Sentry via the currently active hub.
122
151
  def capture_exception(exception, **options, &block)
123
152
  get_current_hub&.capture_exception(exception, **options, &block)
124
153
  end
125
154
 
155
+ # Takes a message string and reports it to Sentry via the currently active hub.
126
156
  def capture_message(message, **options, &block)
127
157
  get_current_hub&.capture_message(message, **options, &block)
128
158
  end
129
159
 
160
+ # Takes an instance of Sentry::Event and dispatches it to the currently active hub.
161
+ def capture_event(event)
162
+ get_current_hub&.capture_event(event)
163
+ end
164
+
165
+ # Takes or initializes a new Sentry::Transaction and makes a sampling decision for it.
130
166
  def start_transaction(**options)
131
167
  get_current_hub&.start_transaction(**options)
132
168
  end
133
169
 
170
+ # Returns the id of the lastly reported Sentry::Event.
134
171
  def last_event_id
135
172
  get_current_hub&.last_event_id
136
173
  end
@@ -141,5 +178,13 @@ module Sentry
141
178
 
142
179
  result.strip
143
180
  end
181
+
182
+ def initialized?
183
+ !!@main_hub
184
+ end
185
+
186
+ def logger
187
+ configuration.logger
188
+ end
144
189
  end
145
190
  end
@@ -3,6 +3,8 @@ require "sentry/client"
3
3
 
4
4
  module Sentry
5
5
  class Hub
6
+ include ArgumentCheckingHelper
7
+
6
8
  attr_reader :last_event_id
7
9
 
8
10
  def initialize(client, scope)
@@ -76,6 +78,8 @@ module Sentry
76
78
  def capture_exception(exception, **options, &block)
77
79
  return unless current_client
78
80
 
81
+ check_argument_type!(exception, ::Exception)
82
+
79
83
  options[:hint] ||= {}
80
84
  options[:hint][:exception] = exception
81
85
  event = current_client.event_from_exception(exception, options[:hint])
@@ -97,6 +101,8 @@ module Sentry
97
101
  def capture_event(event, **options, &block)
98
102
  return unless current_client
99
103
 
104
+ check_argument_type!(event, Sentry::Event)
105
+
100
106
  hint = options.delete(:hint) || {}
101
107
  scope = current_scope.dup
102
108
 
@@ -68,7 +68,6 @@ module Sentry
68
68
  env.each_with_object({}) do |(key, value), memo|
69
69
  begin
70
70
  key = key.to_s # rack env can contain symbols
71
- value = value.to_s
72
71
  next memo['X-Request-Id'] ||= Utils::RequestId.read_from(env) if Utils::RequestId::REQUEST_ID_HEADERS.include?(key)
73
72
  next if is_server_protocol?(key, value, env["SERVER_PROTOCOL"])
74
73
  next if is_skippable_header?(key)
@@ -76,7 +75,7 @@ module Sentry
76
75
  # Rack stores headers as HTTP_WHAT_EVER, we need What-Ever
77
76
  key = key.sub(/^HTTP_/, "")
78
77
  key = key.split('_').map(&:capitalize).join('-')
79
- memo[key] = value
78
+ memo[key] = value.to_s
80
79
  rescue StandardError => e
81
80
  # Rails adds objects to the Rack env that can sometimes raise exceptions
82
81
  # when `to_s` is called.
@@ -16,7 +16,13 @@ module Sentry
16
16
  scope.set_transaction_name(env["PATH_INFO"]) if env["PATH_INFO"]
17
17
  scope.set_rack_env(env)
18
18
 
19
- span = Sentry.start_transaction(name: scope.transaction_name, op: transaction_op)
19
+ span =
20
+ if sentry_trace = env["sentry-trace"]
21
+ Sentry::Transaction.from_sentry_trace(sentry_trace, name: scope.transaction_name, op: transaction_op)
22
+ else
23
+ Sentry.start_transaction(name: scope.transaction_name, op: transaction_op)
24
+ end
25
+
20
26
  scope.set_span(span)
21
27
 
22
28
  begin
@@ -3,6 +3,8 @@ require "etc"
3
3
 
4
4
  module Sentry
5
5
  class Scope
6
+ include ArgumentCheckingHelper
7
+
6
8
  ATTRIBUTES = [:transaction_names, :contexts, :extra, :tags, :user, :level, :breadcrumbs, :fingerprint, :event_processors, :rack_env, :span]
7
9
 
8
10
  attr_reader(*ATTRIBUTES)
@@ -168,12 +170,6 @@ module Sentry
168
170
 
169
171
  private
170
172
 
171
- def check_argument_type!(argument, expected_type)
172
- unless argument.is_a?(expected_type)
173
- raise ArgumentError, "expect the argument to be a #{expected_type}, got #{argument.class} (#{argument})"
174
- end
175
- end
176
-
177
173
  def set_default_value
178
174
  @breadcrumbs = BreadcrumbBuffer.new
179
175
  @contexts = { :os => self.class.os_context, :runtime => self.class.runtime_context }
@@ -69,6 +69,7 @@ module Sentry
69
69
  {
70
70
  trace_id: @trace_id,
71
71
  span_id: @span_id,
72
+ parent_span_id: @parent_span_id,
72
73
  description: @description,
73
74
  op: @op,
74
75
  status: @status
@@ -123,7 +123,7 @@ module Sentry
123
123
  @name = UNLABELD_NAME
124
124
  end
125
125
 
126
- return unless @sampled
126
+ return unless @sampled || @parent_sampled
127
127
 
128
128
  hub ||= Sentry.get_current_hub
129
129
  event = hub.current_client.event_from_transaction(self)
@@ -0,0 +1,11 @@
1
+ module Sentry
2
+ module ArgumentCheckingHelper
3
+ private
4
+
5
+ def check_argument_type!(argument, expected_type)
6
+ unless argument.is_a?(expected_type)
7
+ raise ArgumentError, "expect the argument to be a #{expected_type}, got #{argument.class} (#{argument.inspect})"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Sentry
2
- VERSION = "4.1.3"
2
+ VERSION = "4.1.4"
3
3
  end
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: 4.1.3
4
+ version: 4.1.4
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-01-11 00:00:00.000000000 Z
11
+ date: 2021-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -98,6 +98,7 @@ files:
98
98
  - lib/sentry/transport/configuration.rb
99
99
  - lib/sentry/transport/dummy_transport.rb
100
100
  - lib/sentry/transport/http_transport.rb
101
+ - lib/sentry/utils/argument_checking_helper.rb
101
102
  - lib/sentry/utils/exception_cause_chain.rb
102
103
  - lib/sentry/utils/real_ip.rb
103
104
  - lib/sentry/utils/request_id.rb