sentry-ruby-core 4.2.2 → 4.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.craft.yml +4 -3
- data/CHANGELOG.md +111 -0
- data/Gemfile +4 -0
- data/README.md +20 -22
- data/lib/sentry-ruby.rb +9 -9
- data/lib/sentry/background_worker.rb +8 -4
- data/lib/sentry/breadcrumb/sentry_logger.rb +2 -1
- data/lib/sentry/breadcrumb_buffer.rb +3 -2
- data/lib/sentry/client.rb +50 -27
- data/lib/sentry/configuration.rb +27 -11
- data/lib/sentry/event.rb +28 -48
- data/lib/sentry/exceptions.rb +7 -0
- data/lib/sentry/hub.rb +17 -3
- data/lib/sentry/interfaces/exception.rb +19 -1
- data/lib/sentry/interfaces/request.rb +10 -10
- data/lib/sentry/interfaces/single_exception.rb +16 -5
- data/lib/sentry/interfaces/stacktrace.rb +9 -26
- data/lib/sentry/interfaces/stacktrace_builder.rb +50 -0
- data/lib/sentry/interfaces/threads.rb +9 -3
- data/lib/sentry/net/http.rb +87 -0
- data/lib/sentry/rack/capture_exceptions.rb +18 -11
- data/lib/sentry/scope.rb +12 -6
- data/lib/sentry/span.rb +21 -4
- data/lib/sentry/transaction.rb +53 -42
- data/lib/sentry/transaction_event.rb +3 -1
- data/lib/sentry/transport.rb +57 -26
- data/lib/sentry/transport/configuration.rb +3 -1
- data/lib/sentry/transport/http_transport.rb +92 -6
- data/lib/sentry/utils/logging_helper.rb +24 -0
- data/lib/sentry/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6ec50e2aac42f99230cb5a3f78970b057535aae4d31b1dd94e18b0fdf8995be
|
4
|
+
data.tar.gz: 162dc5844575766403454816354ec4b93ac0c05950c44251963fdcbea685f8e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bed995802c6f5b4c628071283aacd5f9804ec1a963202fb2cf63170bc5c3bf75a16dcebc64520aa5b209bbef6042765456df9ff012512b66ba95261553732d1b
|
7
|
+
data.tar.gz: da726d263583d1db7f5c163cfb5c4e947e3cd4145e512229f37ca8e2a416c62b2284a1a465d26af1155be12ccaf053e93ec74968aff415cca544ff71140e8038
|
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,116 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 4.4.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
|
+
- Disable tracing if events are not allowed to be sent [#1421](https://github.com/getsentry/sentry-ruby/pull/1421)
|
64
|
+
|
65
|
+
## 4.3.2
|
66
|
+
|
67
|
+
- Correct type attribute's usages [#1354](https://github.com/getsentry/sentry-ruby/pull/1354)
|
68
|
+
- Fix sampling decision precedence [#1335](https://github.com/getsentry/sentry-ruby/pull/1335)
|
69
|
+
- Fix set_contexts [#1375](https://github.com/getsentry/sentry-ruby/pull/1375)
|
70
|
+
- Use thread variable instead of fiber variable to store the hub [#1380](https://github.com/getsentry/sentry-ruby/pull/1380)
|
71
|
+
- Fixes [#1374](https://github.com/getsentry/sentry-ruby/issues/1374)
|
72
|
+
- Fix Span/Transaction's nesting issue [#1382](https://github.com/getsentry/sentry-ruby/pull/1382)
|
73
|
+
- Fixes [#1372](https://github.com/getsentry/sentry-ruby/issues/1372)
|
74
|
+
|
75
|
+
## 4.3.1
|
76
|
+
|
77
|
+
- Add Sentry.set_context helper [#1337](https://github.com/getsentry/sentry-ruby/pull/1337)
|
78
|
+
- Fix handle the case where the logger messages is not of String type [#1341](https://github.com/getsentry/sentry-ruby/pull/1341)
|
79
|
+
- Don't report Sentry::ExternalError to Sentry [#1353](https://github.com/getsentry/sentry-ruby/pull/1353)
|
80
|
+
- Sentry.add_breadcrumb should call Hub#add_breadcrumb [#1358](https://github.com/getsentry/sentry-ruby/pull/1358)
|
81
|
+
- Fixes [#1357](https://github.com/getsentry/sentry-ruby/issues/1357)
|
82
|
+
|
83
|
+
## 4.3.0
|
84
|
+
|
85
|
+
### Features
|
86
|
+
|
87
|
+
- Allow configuring BreadcrumbBuffer's size limit [#1310](https://github.com/getsentry/sentry-ruby/pull/1310)
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
# the SDK will only store 10 breadcrumbs (default is 100)
|
91
|
+
config.max_breadcrumbs = 10
|
92
|
+
```
|
93
|
+
|
94
|
+
- Compress event payload by default [#1314](https://github.com/getsentry/sentry-ruby/pull/1314)
|
95
|
+
|
96
|
+
### Refatorings
|
97
|
+
|
98
|
+
- Refactor interface construction [#1296](https://github.com/getsentry/sentry-ruby/pull/1296)
|
99
|
+
- Refactor tracing implementation [#1309](https://github.com/getsentry/sentry-ruby/pull/1309)
|
100
|
+
|
101
|
+
### Bug Fixes
|
102
|
+
- Improve SDK's error handling [#1298](https://github.com/getsentry/sentry-ruby/pull/1298)
|
103
|
+
- Fixes [#1246](https://github.com/getsentry/sentry-ruby/issues/1246) and [#1289](https://github.com/getsentry/sentry-ruby/issues/1289)
|
104
|
+
- Please read [#1290](https://github.com/getsentry/sentry-ruby/issues/1290) to see the full specification
|
105
|
+
- Treat query string as pii too [#1302](https://github.com/getsentry/sentry-ruby/pull/1302)
|
106
|
+
- Fixes [#1301](https://github.com/getsentry/sentry-ruby/issues/1301)
|
107
|
+
- Ignore sentry-trace when tracing is not enabled [#1308](https://github.com/getsentry/sentry-ruby/pull/1308)
|
108
|
+
- Fixes [#1307](https://github.com/getsentry/sentry-ruby/issues/1307)
|
109
|
+
- Return nil from logger methods instead of breadcrumb buffer [#1299](https://github.com/getsentry/sentry-ruby/pull/1299)
|
110
|
+
- Exceptions with nil message shouldn't cause issues [#1327](https://github.com/getsentry/sentry-ruby/pull/1327)
|
111
|
+
- Fixes [#1323](https://github.com/getsentry/sentry-ruby/issues/1323)
|
112
|
+
- Fix sampling decision with sentry-trace and add more tests [#1326](https://github.com/getsentry/sentry-ruby/pull/1326)
|
113
|
+
|
3
114
|
## 4.2.2
|
4
115
|
|
5
116
|
- Add thread_id to Exception interface [#1291](https://github.com/getsentry/sentry-ruby/pull/1291)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,27 +2,29 @@
|
|
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
|
-
|
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
|
-
|
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
|
-
|
23
|
+
## Migrate From sentry-raven
|
23
24
|
|
24
|
-
The
|
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
|
|
@@ -30,10 +32,6 @@ We test on Ruby 2.4, 2.5, 2.6, 2.7, and 3.0 at the latest patchlevel/teeny versi
|
|
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
|
@@ -68,7 +66,7 @@ end
|
|
68
66
|
|
69
67
|
### Sentry doesn't report some kinds of data by default
|
70
68
|
|
71
|
-
**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#
|
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)
|
72
70
|
|
73
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:
|
74
72
|
|
@@ -243,10 +241,10 @@ Of course, you can always assign the information on a per-event basis:
|
|
243
241
|
Sentry.capture_exception(exception, tags: {foo: "bar"})
|
244
242
|
```
|
245
243
|
|
246
|
-
##
|
247
|
-
|
248
|
-
* [Documentation](https://docs.sentry.io/platforms/ruby/)
|
249
|
-
* [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues)
|
250
|
-
* [Forum](https://forum.sentry.io/)
|
251
|
-
- [Discord](https://discord.gg/ez5KZN7)
|
244
|
+
## Resources
|
252
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
|
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
|
-
|
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
|
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
|
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
|
-
|
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
|
-
|
18
|
+
log_debug("config.async is set, BackgroundWorker is disabled")
|
15
19
|
Concurrent::ImmediateExecutor.new
|
16
20
|
elsif @number_of_threads == 0
|
17
|
-
|
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
|
-
|
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
|
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 =
|
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)
|
data/lib/sentry/client.rb
CHANGED
@@ -2,10 +2,13 @@ require "sentry/transport"
|
|
2
2
|
|
3
3
|
module Sentry
|
4
4
|
class Client
|
5
|
-
|
5
|
+
include LoggingHelper
|
6
|
+
|
7
|
+
attr_reader :transport, :configuration, :logger
|
6
8
|
|
7
9
|
def initialize(configuration)
|
8
10
|
@configuration = configuration
|
11
|
+
@logger = configuration.logger
|
9
12
|
|
10
13
|
if transport_class = configuration.transport.transport_class
|
11
14
|
@transport = transport_class.new(configuration)
|
@@ -26,32 +29,17 @@ module Sentry
|
|
26
29
|
scope.apply_to_event(event, hint)
|
27
30
|
|
28
31
|
if async_block = configuration.async
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
event_hash = event.to_json_compatible
|
33
|
-
|
34
|
-
if async_block.arity == 2
|
35
|
-
hint = JSON.parse(JSON.generate(hint))
|
36
|
-
async_block.call(event_hash, hint)
|
37
|
-
else
|
38
|
-
async_block.call(event_hash)
|
39
|
-
end
|
40
|
-
rescue => e
|
41
|
-
configuration.logger.error(LOGGER_PROGNAME) { "async event sending failed: #{e.message}" }
|
42
|
-
send_event(event, hint)
|
43
|
-
end
|
32
|
+
dispatch_async_event(async_block, event, hint)
|
33
|
+
elsif hint.fetch(:background, true)
|
34
|
+
dispatch_background_event(event, hint)
|
44
35
|
else
|
45
|
-
|
46
|
-
Sentry.background_worker.perform do
|
47
|
-
send_event(event, hint)
|
48
|
-
end
|
49
|
-
else
|
50
|
-
send_event(event, hint)
|
51
|
-
end
|
36
|
+
send_event(event, hint)
|
52
37
|
end
|
53
38
|
|
54
39
|
event
|
40
|
+
rescue => e
|
41
|
+
log_error("Event capturing failed", e, debug: configuration.debug)
|
42
|
+
nil
|
55
43
|
end
|
56
44
|
|
57
45
|
def event_from_exception(exception, hint = {})
|
@@ -85,16 +73,51 @@ module Sentry
|
|
85
73
|
|
86
74
|
def send_event(event, hint = nil)
|
87
75
|
event_type = event.is_a?(Event) ? event.type : event["type"]
|
88
|
-
event = configuration.before_send.call(event, hint) if configuration.before_send && event_type == "event"
|
89
76
|
|
90
|
-
if
|
91
|
-
configuration.
|
92
|
-
|
77
|
+
if event_type != TransactionEvent::TYPE && configuration.before_send
|
78
|
+
event = configuration.before_send.call(event, hint)
|
79
|
+
|
80
|
+
if event.nil?
|
81
|
+
log_info("Discarded event because before_send returned nil")
|
82
|
+
return
|
83
|
+
end
|
93
84
|
end
|
94
85
|
|
95
86
|
transport.send_event(event)
|
96
87
|
|
97
88
|
event
|
89
|
+
rescue => e
|
90
|
+
loggable_event_type = (event_type || "event").capitalize
|
91
|
+
log_error("#{loggable_event_type} sending failed", e, debug: configuration.debug)
|
92
|
+
|
93
|
+
event_info = Event.get_log_message(event.to_hash)
|
94
|
+
log_info("Unreported #{loggable_event_type}: #{event_info}")
|
95
|
+
raise
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def dispatch_background_event(event, hint)
|
101
|
+
Sentry.background_worker.perform do
|
102
|
+
send_event(event, hint)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def dispatch_async_event(async_block, event, hint)
|
107
|
+
# We have to convert to a JSON-like hash, because background job
|
108
|
+
# processors (esp ActiveJob) may not like weird types in the event hash
|
109
|
+
event_hash = event.to_json_compatible
|
110
|
+
|
111
|
+
if async_block.arity == 2
|
112
|
+
hint = JSON.parse(JSON.generate(hint))
|
113
|
+
async_block.call(event_hash, hint)
|
114
|
+
else
|
115
|
+
async_block.call(event_hash)
|
116
|
+
end
|
117
|
+
rescue => e
|
118
|
+
loggable_event_type = event_hash["type"] || "event"
|
119
|
+
log_error("Async #{loggable_event_type} sending failed", e, debug: configuration.debug)
|
120
|
+
send_event(event, hint)
|
98
121
|
end
|
99
122
|
end
|
100
123
|
end
|