sentry-ruby-core 4.2.1 → 4.4.0.pre.beta.0

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: b378de66aa7efcec9e63c6542a398a0f6a9a556081dd99f77ab45b1ba8afa298
4
- data.tar.gz: 7491b05d6b00b24d2160363c0ac345169fb4059e5fc51bfeeb9038ea91c30a3b
3
+ metadata.gz: cb17ca62057f29a255a7d725bd574775d840e987cbc3c067a9294b63311d26aa
4
+ data.tar.gz: 9268967f80f8406bbcf3bf2b0dc150567b3adc16d1c4b38fd8ef5df5a1559737
5
5
  SHA512:
6
- metadata.gz: 6ba47551dc4b3d5315df49e0e53877d92b8c5f9ce547e615e5b098cc0ca9729db8bafd4d6ca39977dcedb09c5066e7f7084aa5e3e3276e33445087f8d614e321
7
- data.tar.gz: 8b5eca42bad5ea2158c4aa68d93e5e6a3db7675be8da4d44fd5c7bf1f963f587cd06c462a893486a739628d1309f7c39e8418ca8b14de1fe241c8fa59587159e
6
+ metadata.gz: 3d57f757d5d7c36c24bf296fbb673c8afe20fb3fadc89c1a1f4046856188286f9db9c7fdd2b6c3d49e921a302f179f1c4acef4ac737b802cc0640e979eab0de8
7
+ data.tar.gz: e5900027bce05c31a9bd10ea6fb2f660deee1494e37545a0637ea89767353add86b39fc4dde07de0c4ac9fcadb2f2d2bc8441308d4f89396e5c5de124ed7f445
data/.craft.yml CHANGED
@@ -13,9 +13,6 @@ targets:
13
13
  # we always need to make sure sentry-ruby-core is present when pushing to any target
14
14
  - name: gem
15
15
  onlyIfPresent: /^sentry-ruby-core-\d.*\.gem$/
16
- - name: github
17
- onlyIfPresent: /^sentry-ruby-core-\d.*\.gem$/
18
- tagPrefix: sentry-ruby-v
19
16
  - name: registry
20
17
  onlyIfPresent: /^sentry-ruby-core-\d.*\.gem$/
21
18
  type: sdk
@@ -26,3 +23,7 @@ targets:
26
23
  type: sdk
27
24
  config:
28
25
  canonical: 'gem:sentry-ruby-core'
26
+ - name: github
27
+ onlyIfPresent: /^sentry-ruby-core-\d.*\.gem$/
28
+ tagPrefix: sentry-ruby-v
29
+ changelog: sentry-ruby/CHANGELOG.md
data/CHANGELOG.md CHANGED
@@ -1,5 +1,121 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.4.0-beta.0
4
+
5
+ ### Features
6
+
7
+ #### Support category-based rate limiting [#1336](https://github.com/getsentry/sentry-ruby/pull/1336)
8
+
9
+ Sentry rate limits different types of events. And when rate limiting is enabled, it sends back a `429` response to the SDK. Currently, the SDK would then raise an error like this:
10
+
11
+ ```
12
+ Unable to record event with remote Sentry server (Sentry::Error - the server responded with status 429
13
+ body: {"detail":"event rejected due to rate limit"}):
14
+ ```
15
+
16
+ This change improves the SDK's handling on such responses by:
17
+
18
+ - Not treating them as errors, so you don't see the noise anymore.
19
+ - Halting event sending for a while according to the duration provided in the response. And warns you with a message like:
20
+
21
+ ```
22
+ Envelope [event] not sent: Excluded by random sample
23
+ ```
24
+
25
+ #### Record request span from Net::HTTP library [#1381](https://github.com/getsentry/sentry-ruby/pull/1381)
26
+
27
+ Now any outgoing requests will be recorded as a tracing span. Example:
28
+
29
+ <img width="60%" alt="net:http span example" src="https://user-images.githubusercontent.com/5079556/115838944-c1279a80-a44c-11eb-8c67-dfd92bf68bbd.png">
30
+
31
+
32
+ #### Record breadcrumb for Net::HTTP requests [#1394](https://github.com/getsentry/sentry-ruby/pull/1394)
33
+
34
+ With the new `http_logger` breadcrumbs logger:
35
+
36
+ ```ruby
37
+ config.breadcrumbs_logger = [:http_logger]
38
+ ```
39
+
40
+ The SDK now records a new `net.http` breadcrumb whenever the user makes a request with the `Net::HTTP` library.
41
+
42
+ <img width="60%" alt="net http breadcrumb" src="https://user-images.githubusercontent.com/5079556/114298326-5f7c3d80-9ae8-11eb-9108-222384a7f1a2.png">
43
+
44
+ #### Support config.debug configuration option [#1400](https://github.com/getsentry/sentry-ruby/pull/1400)
45
+
46
+ It'll determine whether the SDK should run in the debugging mode. Default is `false`. When set to true, SDK errors will be logged with backtrace.
47
+
48
+ #### Add the third tracing state [#1402](https://github.com/getsentry/sentry-ruby/pull/1402)
49
+ - `rate == 0` - Tracing enabled. Rejects all locally created transactions but respects sentry-trace.
50
+ - `1 > rate > 0` - Tracing enabled. Samples locally created transactions with the rate and respects sentry-trace.
51
+ - `rate < 0` or `rate > 1` - Tracing disabled.
52
+
53
+ ### Refactorings
54
+
55
+ - Let Transaction constructor take an optional hub argument [#1384](https://github.com/getsentry/sentry-ruby/pull/1384)
56
+ - Introduce LoggingHelper [#1385](https://github.com/getsentry/sentry-ruby/pull/1385)
57
+ - Raise exception if a Transaction is initialized without a hub [#1391](https://github.com/getsentry/sentry-ruby/pull/1391)
58
+ - Make hub a required argument for Transaction constructor [#1401](https://github.com/getsentry/sentry-ruby/pull/1401)
59
+
60
+ ### Bug Fixes
61
+
62
+ - Check `Scope#set_context`'s value argument [#1415](https://github.com/getsentry/sentry-ruby/pull/1415)
63
+
64
+ ## 4.3.2
65
+
66
+ - Correct type attribute's usages [#1354](https://github.com/getsentry/sentry-ruby/pull/1354)
67
+ - Fix sampling decision precedence [#1335](https://github.com/getsentry/sentry-ruby/pull/1335)
68
+ - Fix set_contexts [#1375](https://github.com/getsentry/sentry-ruby/pull/1375)
69
+ - Use thread variable instead of fiber variable to store the hub [#1380](https://github.com/getsentry/sentry-ruby/pull/1380)
70
+ - Fixes [#1374](https://github.com/getsentry/sentry-ruby/issues/1374)
71
+ - Fix Span/Transaction's nesting issue [#1382](https://github.com/getsentry/sentry-ruby/pull/1382)
72
+ - Fixes [#1372](https://github.com/getsentry/sentry-ruby/issues/1372)
73
+
74
+ ## 4.3.1
75
+
76
+ - Add Sentry.set_context helper [#1337](https://github.com/getsentry/sentry-ruby/pull/1337)
77
+ - Fix handle the case where the logger messages is not of String type [#1341](https://github.com/getsentry/sentry-ruby/pull/1341)
78
+ - Don't report Sentry::ExternalError to Sentry [#1353](https://github.com/getsentry/sentry-ruby/pull/1353)
79
+ - Sentry.add_breadcrumb should call Hub#add_breadcrumb [#1358](https://github.com/getsentry/sentry-ruby/pull/1358)
80
+ - Fixes [#1357](https://github.com/getsentry/sentry-ruby/issues/1357)
81
+
82
+ ## 4.3.0
83
+
84
+ ### Features
85
+
86
+ - Allow configuring BreadcrumbBuffer's size limit [#1310](https://github.com/getsentry/sentry-ruby/pull/1310)
87
+
88
+ ```ruby
89
+ # the SDK will only store 10 breadcrumbs (default is 100)
90
+ config.max_breadcrumbs = 10
91
+ ```
92
+
93
+ - Compress event payload by default [#1314](https://github.com/getsentry/sentry-ruby/pull/1314)
94
+
95
+ ### Refatorings
96
+
97
+ - Refactor interface construction [#1296](https://github.com/getsentry/sentry-ruby/pull/1296)
98
+ - Refactor tracing implementation [#1309](https://github.com/getsentry/sentry-ruby/pull/1309)
99
+
100
+ ### Bug Fixes
101
+ - Improve SDK's error handling [#1298](https://github.com/getsentry/sentry-ruby/pull/1298)
102
+ - Fixes [#1246](https://github.com/getsentry/sentry-ruby/issues/1246) and [#1289](https://github.com/getsentry/sentry-ruby/issues/1289)
103
+ - Please read [#1290](https://github.com/getsentry/sentry-ruby/issues/1290) to see the full specification
104
+ - Treat query string as pii too [#1302](https://github.com/getsentry/sentry-ruby/pull/1302)
105
+ - Fixes [#1301](https://github.com/getsentry/sentry-ruby/issues/1301)
106
+ - Ignore sentry-trace when tracing is not enabled [#1308](https://github.com/getsentry/sentry-ruby/pull/1308)
107
+ - Fixes [#1307](https://github.com/getsentry/sentry-ruby/issues/1307)
108
+ - Return nil from logger methods instead of breadcrumb buffer [#1299](https://github.com/getsentry/sentry-ruby/pull/1299)
109
+ - Exceptions with nil message shouldn't cause issues [#1327](https://github.com/getsentry/sentry-ruby/pull/1327)
110
+ - Fixes [#1323](https://github.com/getsentry/sentry-ruby/issues/1323)
111
+ - Fix sampling decision with sentry-trace and add more tests [#1326](https://github.com/getsentry/sentry-ruby/pull/1326)
112
+
113
+ ## 4.2.2
114
+
115
+ - Add thread_id to Exception interface [#1291](https://github.com/getsentry/sentry-ruby/pull/1291)
116
+ - always convert trusted proxies to string [#1288](https://github.com/getsentry/sentry-ruby/pull/1288)
117
+ - fixes [#1274](https://github.com/getsentry/sentry-ruby/issues/1274)
118
+
3
119
  ## 4.2.1
4
120
 
5
121
  ### Bug Fixes
data/Gemfile CHANGED
@@ -8,7 +8,11 @@ gem "i18n", "<= 1.8.7"
8
8
 
9
9
  gem "rake", "~> 12.0"
10
10
  gem "rspec", "~> 3.0"
11
+ gem "rspec-retry"
12
+ gem "webmock"
13
+ gem "timecop"
11
14
  gem "codecov", "0.2.12"
15
+ gem "tapping_device"
12
16
 
13
17
  gem "pry"
14
18
  gem "rack" unless ENV["WITHOUT_RACK"] == "1"
data/README.md CHANGED
@@ -2,38 +2,36 @@
2
2
  <a href="https://sentry.io" target="_blank" align="center">
3
3
  <img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
4
4
  </a>
5
- <br>
5
+ <br />
6
6
  </p>
7
7
 
8
- # sentry-ruby, the Ruby Client for Sentry
8
+ _Bad software is everywhere, and we're tired of it. Sentry is on a mission to help developers write better software faster, so we can get back to enjoying technology. If you want to join us [<kbd>**Check out our open positions**</kbd>](https://sentry.io/careers/)_
9
9
 
10
- **The old `sentry-raven` client has entered maintenance mode and was moved to [here](https://github.com/getsentry/sentry-ruby/tree/master/sentry-raven).**
10
+ Sentry SDK for Ruby
11
+ ===========
11
12
 
12
- ---
13
+ | current version | build | coverage | downloads | semver stability |
14
+ | --- | ----- | -------- | --------- | ---------------- |
15
+ | [![Gem Version](https://img.shields.io/gem/v/sentry-ruby?label=sentry-ruby)](https://github.com/getsentry/sentry-ruby/blob/master/sentry-ruby/CHANGELOG.md) | ![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-ruby%20Test/badge.svg) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![Downloads](https://img.shields.io/gem/dt/sentry-ruby.svg)](https://rubygems.org/gems/sentry-ruby/) | [![SemVer stability](https://api.dependabot.com/badges/compatibility_score?dependency-name=sentry-ruby&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sentry-ruby&package-manager=bundler&version-scheme=semver) |
16
+ | [![Gem Version](https://img.shields.io/gem/v/sentry-rails?label=sentry-rails)](https://github.com/getsentry/sentry-ruby/blob/master/sentry-rails/CHANGELOG.md) | ![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-rails%20Test/badge.svg) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![Downloads](https://img.shields.io/gem/dt/sentry-rails.svg)](https://rubygems.org/gems/sentry-rails/) | [![SemVer stability](https://api.dependabot.com/badges/compatibility_score?dependency-name=sentry-rails&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sentry-rails&package-manager=bundler&version-scheme=semver) |
17
+ | [![Gem Version](https://img.shields.io/gem/v/sentry-sidekiq?label=sentry-sidekiq)](https://github.com/getsentry/sentry-ruby/blob/master/sentry-sidekiq/CHANGELOG.md) | ![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-sidekiq%20Test/badge.svg) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![Downloads](https://img.shields.io/gem/dt/sentry-sidekiq.svg)](https://rubygems.org/gems/sentry-sidekiq/) | [![SemVer stability](https://api.dependabot.com/badges/compatibility_score?dependency-name=sentry-sidekiq&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sentry-sidekiq&package-manager=bundler&version-scheme=semver) |
18
+ | [![Gem Version](https://img.shields.io/gem/v/sentry-delayed_job?label=sentry-delayed_job)](https://github.com/getsentry/sentry-ruby/blob/master/sentry-delayed_job/CHANGELOG.md) | ![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-delayed_job%20Test/badge.svg) | [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master) | [![Downloads](https://img.shields.io/gem/dt/sentry-delayed_job.svg)](https://rubygems.org/gems/sentry-delayed_job/) | [![SemVer stability](https://api.dependabot.com/badges/compatibility_score?dependency-name=sentry-delayed_job&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sentry-delayed_job&package-manager=bundler&version-scheme=semver) |
13
19
 
14
20
 
15
- [![Gem Version](https://img.shields.io/gem/v/sentry-ruby.svg)](https://rubygems.org/gems/sentry-ruby)
16
- ![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-ruby%20Test/badge.svg)
17
- [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master)
18
- [![Gem](https://img.shields.io/gem/dt/sentry-ruby.svg)](https://rubygems.org/gems/sentry-ruby/)
19
- [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=sentry-ruby&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sentry-ruby&package-manager=bundler&version-scheme=semver)
20
21
 
21
22
 
22
- [Documentation](https://docs.sentry.io/platforms/ruby/) | [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues) | [Forum](https://forum.sentry.io/) | IRC: irc.freenode.net, #sentry
23
+ ## Migrate From sentry-raven
23
24
 
24
- The official Ruby-language client and integration layer for the [Sentry](https://github.com/getsentry/sentry) error reporting API.
25
+ **The old `sentry-raven` client has entered maintenance mode and was moved to [here](https://github.com/getsentry/sentry-ruby/tree/master/sentry-raven).**
25
26
 
27
+ If you're using `sentry-raven`, we recommend you to migrate to this new SDK. You can find the benefits of migrating and how to do it in our [migration guide](https://docs.sentry.io/platforms/ruby/migration/).
26
28
 
27
29
  ## Requirements
28
30
 
29
- We test on Ruby 2.4, 2.5, 2.6 and 2.7 at the latest patchlevel/teeny version. We also support JRuby 9.0.
31
+ We test on Ruby 2.4, 2.5, 2.6, 2.7, and 3.0 at the latest patchlevel/teeny version. We also support JRuby 9.0.
30
32
 
31
33
  If you use self-hosted Sentry, please also make sure its version is above `20.6.0`.
32
34
 
33
- ## Migrate From sentry-raven
34
-
35
- If you're using `sentry-raven`, we recommend you to migrate to this new SDK. You can find the benefits of migrating and how to do it in our [migration guide](https://docs.sentry.io/platforms/ruby/migration/).
36
-
37
35
  ## Getting Started
38
36
 
39
37
  ### Install
@@ -47,6 +45,7 @@ and depends on the integrations you want to have, you might also want to install
47
45
  ```ruby
48
46
  gem "sentry-rails"
49
47
  gem "sentry-sidekiq"
48
+ gem "sentry-delayed_job"
50
49
  # and mores to come in the future!
51
50
  ```
52
51
 
@@ -67,7 +66,7 @@ end
67
66
 
68
67
  ### Sentry doesn't report some kinds of data by default
69
68
 
70
- **Sentry ignores some exceptions by default** - most of these are related to 404s parameter parsing errors. [For a complete list, see the `IGNORE_DEFAULT` constant](https://github.com/getsentry/sentry-ruby/blob/master/sentry-ruby/lib/sentry/configuration.rb#L118) and the integration gems' `IGNORE_DEFAULT`, like [`sentry-rails`'s](https://github.com/getsentry/sentry-ruby/blob/master/sentry-rails/lib/sentry/rails/configuration.rb#L12)
69
+ **Sentry ignores some exceptions by default** - most of these are related to 404s parameter parsing errors. [For a complete list, see the `IGNORE_DEFAULT` constant](https://github.com/getsentry/sentry-ruby/blob/master/sentry-ruby/lib/sentry/configuration.rb#L151) and the integration gems' `IGNORE_DEFAULT`, like [`sentry-rails`'s](https://github.com/getsentry/sentry-ruby/blob/master/sentry-rails/lib/sentry/rails/configuration.rb#L12)
71
70
 
72
71
  Sentry doesn't send personally identifiable information (pii) by default, such as request body, user ip or cookies. If you want those information to be sent, you can use the `send_default_pii` config option:
73
72
 
@@ -136,6 +135,7 @@ We also provide integrations with popular frameworks/libraries with the related
136
135
 
137
136
  - [sentry-rails](https://github.com/getsentry/sentry-ruby/tree/master/sentry-rails)
138
137
  - [sentry-sidekiq](https://github.com/getsentry/sentry-ruby/tree/master/sentry-sidekiq)
138
+ - [sentry-delayed_job](https://github.com/getsentry/sentry-ruby/tree/master/sentry-delayed_job)
139
139
 
140
140
  ### More configuration
141
141
 
@@ -143,38 +143,7 @@ You're all set - but there's a few more settings you may want to know about too!
143
143
 
144
144
  #### Blocking v.s. Non-blocking
145
145
 
146
- **Before version 4.1.0**, `sentry-ruby` sends every event immediately. But it can be configured to send asynchronously:
147
-
148
- ```ruby
149
- config.async = lambda { |event, hint|
150
- Thread.new { Sentry.send_event(event, hint) }
151
- }
152
- ```
153
-
154
- Using a thread to send events will be adequate for truly parallel Ruby platforms such as JRuby, though the benefit on MRI/CRuby will be limited. If the async callback raises an exception, Sentry will attempt to send synchronously.
155
-
156
- Note that the naive example implementation has a major drawback - it can create an infinite number of threads. We recommend creating a background job, using your background job processor, that will send Sentry notifications in the background.
157
-
158
- ```ruby
159
- config.async = lambda { |event, hint| SentryJob.perform_later(event, hint) }
160
-
161
- class SentryJob < ActiveJob::Base
162
- queue_as :default
163
- discard_on ActiveJob::DeserializationError # this will prevent infinite loop when there's an issue deserializing SentryJob
164
-
165
- def perform(event, hint)
166
- Sentry.send_event(event, hint)
167
- end
168
- end
169
- ```
170
-
171
- If you also use `sentry-rails`, you can directly use the job we defined for you:
172
-
173
- ```ruby
174
- config.async = lambda { |event, hint| Sentry::SendEventJob.perform_later(event, hint) }
175
- ```
176
-
177
- **After version 4.1.0**, `sentry-ruby` sends events asynchronously by default. The functionality works like this:
146
+ `sentry-ruby` sends events asynchronously by default. The functionality works like this:
178
147
 
179
148
  1. When the SDK is initialized, a `Sentry::BackgroundWorker` will be initialized too.
180
149
  2. When an event is passed to `Client#capture_event`, instead of sending it directly with `Client#send_event`, we'll let the worker do it.
@@ -208,6 +177,21 @@ If you want to send a particular event immediately, you can use event hints to d
208
177
  Sentry.capture_message("send me now!", hint: { background: false })
209
178
  ```
210
179
 
180
+ ##### `config.async`
181
+
182
+ You can also use `config.async` to send events with you own worker:
183
+
184
+ ```ruby
185
+ config.async = lambda { |event, hint| SentryJob.perform_later(event, hint) }
186
+ ```
187
+
188
+ And if you use `sentry-rails`, you can directly use the job we defined for you:
189
+
190
+ ```ruby
191
+ config.async = lambda { |event, hint| Sentry::SendEventJob.perform_later(event, hint) }
192
+ ```
193
+
194
+
211
195
  #### Contexts
212
196
 
213
197
  In sentry-ruby, every event will inherit their contextual data from the current scope. So you can enrich the event's data by configuring the current scope like:
@@ -257,10 +241,10 @@ Of course, you can always assign the information on a per-event basis:
257
241
  Sentry.capture_exception(exception, tags: {foo: "bar"})
258
242
  ```
259
243
 
260
- ## More Information
261
-
262
- * [Documentation](https://docs.sentry.io/platforms/ruby/)
263
- * [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues)
264
- * [Forum](https://forum.sentry.io/)
265
- - [Discord](https://discord.gg/ez5KZN7)
244
+ ## Resources
266
245
 
246
+ * [![Ruby docs](https://img.shields.io/badge/documentation-sentry.io-green.svg?label=ruby%20docs)](https://docs.sentry.io/platforms/ruby/)
247
+ * [![Forum](https://img.shields.io/badge/forum-sentry-green.svg)](https://forum.sentry.io/c/sdks)
248
+ * [![Discord Chat](https://img.shields.io/discord/621778831602221064?logo=discord&logoColor=ffffff&color=7389D8)](https://discord.gg/PXa5Apfe7K)
249
+ * [![Stack Overflow](https://img.shields.io/badge/stack%20overflow-sentry-green.svg)](https://stackoverflow.com/questions/tagged/sentry)
250
+ * [![Twitter Follow](https://img.shields.io/twitter/follow/getsentry?label=getsentry&style=social)](https://twitter.com/intent/follow?screen_name=getsentry)
data/lib/sentry-ruby.rb CHANGED
@@ -3,8 +3,11 @@ require "forwardable"
3
3
  require "time"
4
4
 
5
5
  require "sentry/version"
6
+ require "sentry/exceptions"
6
7
  require "sentry/core_ext/object/deep_dup"
7
8
  require "sentry/utils/argument_checking_helper"
9
+ require "sentry/utils/logging_helper"
10
+ require "sentry/net/http"
8
11
  require "sentry/configuration"
9
12
  require "sentry/logger"
10
13
  require "sentry/event"
@@ -26,9 +29,6 @@ require "sentry/background_worker"
26
29
  end
27
30
 
28
31
  module Sentry
29
- class Error < StandardError
30
- end
31
-
32
32
  META = { "name" => "sentry.ruby", "version" => Sentry::VERSION }.freeze
33
33
 
34
34
  LOGGER_PROGNAME = "sentry".freeze
@@ -60,7 +60,7 @@ module Sentry
60
60
  extend Forwardable
61
61
 
62
62
  def_delegators :get_current_client, :configuration, :send_event
63
- def_delegators :get_current_scope, :set_tags, :set_extras, :set_user
63
+ def_delegators :get_current_scope, :set_tags, :set_extras, :set_user, :set_context
64
64
 
65
65
  attr_accessor :background_worker
66
66
 
@@ -68,9 +68,9 @@ module Sentry
68
68
  config = Configuration.new
69
69
  yield(config) if block_given?
70
70
  client = Client.new(config)
71
- scope = Scope.new
71
+ scope = Scope.new(max_breadcrumbs: config.max_breadcrumbs)
72
72
  hub = Hub.new(client, scope)
73
- Thread.current[THREAD_LOCAL] = hub
73
+ Thread.current.thread_variable_set(THREAD_LOCAL, hub)
74
74
  @main_hub = hub
75
75
  @background_worker = Sentry::BackgroundWorker.new(config)
76
76
  end
@@ -82,7 +82,7 @@ module Sentry
82
82
 
83
83
  # Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
84
84
  def add_breadcrumb(breadcrumb)
85
- get_current_scope.breadcrumbs.record(breadcrumb)
85
+ get_current_hub&.add_breadcrumb(breadcrumb)
86
86
  end
87
87
 
88
88
  # Returns the current active hub.
@@ -94,7 +94,7 @@ module Sentry
94
94
  # ideally, we should do this proactively whenever a new thread is created
95
95
  # but it's impossible for the SDK to keep track every new thread
96
96
  # so we need to use this rather passive way to make sure the app doesn't crash
97
- Thread.current[THREAD_LOCAL] || clone_hub_to_current_thread
97
+ Thread.current.thread_variable_get(THREAD_LOCAL) || clone_hub_to_current_thread
98
98
  end
99
99
 
100
100
  # Returns the current active client.
@@ -109,7 +109,7 @@ module Sentry
109
109
 
110
110
  # Clones the main thread's active hub and stores it to the current thread.
111
111
  def clone_hub_to_current_thread
112
- Thread.current[THREAD_LOCAL] = get_main_hub.clone
112
+ Thread.current.thread_variable_set(THREAD_LOCAL, get_main_hub.clone)
113
113
  end
114
114
 
115
115
  # Takes a block and yields the current active scope.
@@ -1,23 +1,27 @@
1
1
  require "concurrent/executor/thread_pool_executor"
2
2
  require "concurrent/executor/immediate_executor"
3
+ require "concurrent/configuration"
3
4
 
4
5
  module Sentry
5
6
  class BackgroundWorker
6
- attr_reader :max_queue, :number_of_threads
7
+ include LoggingHelper
8
+
9
+ attr_reader :max_queue, :number_of_threads, :logger
7
10
 
8
11
  def initialize(configuration)
9
12
  @max_queue = 30
10
13
  @number_of_threads = configuration.background_worker_threads
14
+ @logger = configuration.logger
11
15
 
12
16
  @executor =
13
17
  if configuration.async
14
- configuration.logger.debug(LOGGER_PROGNAME) { "config.async is set, BackgroundWorker is disabled" }
18
+ log_debug("config.async is set, BackgroundWorker is disabled")
15
19
  Concurrent::ImmediateExecutor.new
16
20
  elsif @number_of_threads == 0
17
- configuration.logger.debug(LOGGER_PROGNAME) { "config.background_worker_threads is set to 0, all events will be sent synchronously" }
21
+ log_debug("config.background_worker_threads is set to 0, all events will be sent synchronously")
18
22
  Concurrent::ImmediateExecutor.new
19
23
  else
20
- configuration.logger.debug(LOGGER_PROGNAME) { "initialized a background worker with #{@number_of_threads} threads" }
24
+ log_debug("initialized a background worker with #{@number_of_threads} threads")
21
25
 
22
26
  Concurrent::ThreadPoolExecutor.new(
23
27
  min_threads: 0,
@@ -14,6 +14,7 @@ module Sentry
14
14
  def add(*args, &block)
15
15
  super
16
16
  add_breadcrumb(*args, &block)
17
+ nil
17
18
  end
18
19
 
19
20
  def add_breadcrumb(severity, message = nil, progname = nil)
@@ -49,7 +50,7 @@ module Sentry
49
50
  end
50
51
  end
51
52
 
52
- return if ignored_logger?(progname) || message.empty?
53
+ return if ignored_logger?(progname) || message == ""
53
54
 
54
55
  # some loggers will add leading/trailing space as they (incorrectly, mind you)
55
56
  # think of logging as a shortcut to std{out,err}
@@ -2,12 +2,13 @@ require "sentry/breadcrumb"
2
2
 
3
3
  module Sentry
4
4
  class BreadcrumbBuffer
5
+ DEFAULT_SIZE = 100
5
6
  include Enumerable
6
7
 
7
8
  attr_accessor :buffer
8
9
 
9
- def initialize(size = 100)
10
- @buffer = Array.new(size)
10
+ def initialize(size = nil)
11
+ @buffer = Array.new(size || DEFAULT_SIZE)
11
12
  end
12
13
 
13
14
  def record(crumb)