sentry-ruby-core 4.2.0 → 4.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +63 -0
- data/Gemfile +1 -0
- data/README.md +39 -55
- data/lib/sentry-ruby.rb +7 -9
- data/lib/sentry/background_worker.rb +1 -0
- data/lib/sentry/breadcrumb/sentry_logger.rb +2 -1
- data/lib/sentry/breadcrumb_buffer.rb +3 -2
- data/lib/sentry/client.rb +47 -27
- data/lib/sentry/configuration.rb +16 -0
- data/lib/sentry/event.rb +28 -47
- data/lib/sentry/exceptions.rb +7 -0
- data/lib/sentry/hub.rb +12 -2
- data/lib/sentry/interfaces/exception.rb +19 -1
- data/lib/sentry/interfaces/request.rb +10 -10
- data/lib/sentry/interfaces/single_exception.rb +16 -4
- 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/rack/capture_exceptions.rb +18 -14
- data/lib/sentry/scope.rb +11 -6
- data/lib/sentry/span.rb +10 -2
- data/lib/sentry/transaction.rb +34 -36
- data/lib/sentry/transaction_event.rb +3 -1
- data/lib/sentry/transport.rb +10 -29
- data/lib/sentry/transport/configuration.rb +3 -1
- data/lib/sentry/transport/http_transport.rb +18 -2
- data/lib/sentry/utils/real_ip.rb +1 -1
- data/lib/sentry/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85c558cf77534e3d3fea7d30e417171302f485042b8a09b3a1114c714f1b17ec
|
4
|
+
data.tar.gz: d8077c3cfee56f1427d03770dc8d28e9920bbba4d97e14e983d3b7a5a949be95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cc8fa4030f678d6b2cd34d1c5752e4da6065527ed598e6f43a14ab6adcb44fbe4f104b99de9dd65d45995f726fc074bf3944891348ce4491a385ce22acfa493
|
7
|
+
data.tar.gz: 8fc20069fbddcb6dba3206ea8d7578c9da54f5a0812c0388e9e1afc983befcaaaa3d32390af78b6f3bee6294e997455dbcc807d7543380bc20740b314534dd7b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,68 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 4.3.2
|
4
|
+
|
5
|
+
- Correct type attribute's usages [#1354](https://github.com/getsentry/sentry-ruby/pull/1354)
|
6
|
+
- Fix sampling decision precedence [#1335](https://github.com/getsentry/sentry-ruby/pull/1335)
|
7
|
+
- Fix set_contexts [#1375](https://github.com/getsentry/sentry-ruby/pull/1375)
|
8
|
+
- Use thread variable instead of fiber variable to store the hub [#1380](https://github.com/getsentry/sentry-ruby/pull/1380)
|
9
|
+
- Fixes [#1374](https://github.com/getsentry/sentry-ruby/issues/1374)
|
10
|
+
- Fix Span/Transaction's nesting issue [#1382](https://github.com/getsentry/sentry-ruby/pull/1382)
|
11
|
+
- Fixes [#1372](https://github.com/getsentry/sentry-ruby/issues/1372)
|
12
|
+
|
13
|
+
## 4.3.1
|
14
|
+
|
15
|
+
- Add Sentry.set_context helper [#1337](https://github.com/getsentry/sentry-ruby/pull/1337)
|
16
|
+
- Fix handle the case where the logger messages is not of String type [#1341](https://github.com/getsentry/sentry-ruby/pull/1341)
|
17
|
+
- Don't report Sentry::ExternalError to Sentry [#1353](https://github.com/getsentry/sentry-ruby/pull/1353)
|
18
|
+
- Sentry.add_breadcrumb should call Hub#add_breadcrumb [#1358](https://github.com/getsentry/sentry-ruby/pull/1358)
|
19
|
+
- Fixes [#1357](https://github.com/getsentry/sentry-ruby/issues/1357)
|
20
|
+
|
21
|
+
## 4.3.0
|
22
|
+
|
23
|
+
### Features
|
24
|
+
|
25
|
+
- Allow configuring BreadcrumbBuffer's size limit [#1310](https://github.com/getsentry/sentry-ruby/pull/1310)
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# the SDK will only store 10 breadcrumbs (default is 100)
|
29
|
+
config.max_breadcrumbs = 10
|
30
|
+
```
|
31
|
+
|
32
|
+
- Compress event payload by default [#1314](https://github.com/getsentry/sentry-ruby/pull/1314)
|
33
|
+
|
34
|
+
### Refatorings
|
35
|
+
|
36
|
+
- Refactor interface construction [#1296](https://github.com/getsentry/sentry-ruby/pull/1296)
|
37
|
+
- Refactor tracing implementation [#1309](https://github.com/getsentry/sentry-ruby/pull/1309)
|
38
|
+
|
39
|
+
### Bug Fixes
|
40
|
+
- Improve SDK's error handling [#1298](https://github.com/getsentry/sentry-ruby/pull/1298)
|
41
|
+
- Fixes [#1246](https://github.com/getsentry/sentry-ruby/issues/1246) and [#1289](https://github.com/getsentry/sentry-ruby/issues/1289)
|
42
|
+
- Please read [#1290](https://github.com/getsentry/sentry-ruby/issues/1290) to see the full specification
|
43
|
+
- Treat query string as pii too [#1302](https://github.com/getsentry/sentry-ruby/pull/1302)
|
44
|
+
- Fixes [#1301](https://github.com/getsentry/sentry-ruby/issues/1301)
|
45
|
+
- Ignore sentry-trace when tracing is not enabled [#1308](https://github.com/getsentry/sentry-ruby/pull/1308)
|
46
|
+
- Fixes [#1307](https://github.com/getsentry/sentry-ruby/issues/1307)
|
47
|
+
- Return nil from logger methods instead of breadcrumb buffer [#1299](https://github.com/getsentry/sentry-ruby/pull/1299)
|
48
|
+
- Exceptions with nil message shouldn't cause issues [#1327](https://github.com/getsentry/sentry-ruby/pull/1327)
|
49
|
+
- Fixes [#1323](https://github.com/getsentry/sentry-ruby/issues/1323)
|
50
|
+
- Fix sampling decision with sentry-trace and add more tests [#1326](https://github.com/getsentry/sentry-ruby/pull/1326)
|
51
|
+
|
52
|
+
## 4.2.2
|
53
|
+
|
54
|
+
- Add thread_id to Exception interface [#1291](https://github.com/getsentry/sentry-ruby/pull/1291)
|
55
|
+
- always convert trusted proxies to string [#1288](https://github.com/getsentry/sentry-ruby/pull/1288)
|
56
|
+
- fixes [#1274](https://github.com/getsentry/sentry-ruby/issues/1274)
|
57
|
+
|
58
|
+
## 4.2.1
|
59
|
+
|
60
|
+
### Bug Fixes
|
61
|
+
|
62
|
+
- Ignore invalid values for sentry-trace header that don't match the required format [#1265](https://github.com/getsentry/sentry-ruby/pull/1265)
|
63
|
+
- Transaction created by `.from_sentry_trace` should inherit sampling decision [#1269](https://github.com/getsentry/sentry-ruby/pull/1269)
|
64
|
+
- Transaction's sample rate should accept any numeric value [#1278](https://github.com/getsentry/sentry-ruby/pull/1278)
|
65
|
+
|
3
66
|
## 4.2.0
|
4
67
|
|
5
68
|
### Features
|
data/Gemfile
CHANGED
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
|
-
|
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
|
|
29
|
-
We test on Ruby 2.4, 2.5, 2.6
|
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#
|
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
|
-
|
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
|
-
##
|
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,6 +3,7 @@ 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"
|
8
9
|
require "sentry/configuration"
|
@@ -26,9 +27,6 @@ require "sentry/background_worker"
|
|
26
27
|
end
|
27
28
|
|
28
29
|
module Sentry
|
29
|
-
class Error < StandardError
|
30
|
-
end
|
31
|
-
|
32
30
|
META = { "name" => "sentry.ruby", "version" => Sentry::VERSION }.freeze
|
33
31
|
|
34
32
|
LOGGER_PROGNAME = "sentry".freeze
|
@@ -60,7 +58,7 @@ module Sentry
|
|
60
58
|
extend Forwardable
|
61
59
|
|
62
60
|
def_delegators :get_current_client, :configuration, :send_event
|
63
|
-
def_delegators :get_current_scope, :set_tags, :set_extras, :set_user
|
61
|
+
def_delegators :get_current_scope, :set_tags, :set_extras, :set_user, :set_context
|
64
62
|
|
65
63
|
attr_accessor :background_worker
|
66
64
|
|
@@ -68,9 +66,9 @@ module Sentry
|
|
68
66
|
config = Configuration.new
|
69
67
|
yield(config) if block_given?
|
70
68
|
client = Client.new(config)
|
71
|
-
scope = Scope.new
|
69
|
+
scope = Scope.new(max_breadcrumbs: config.max_breadcrumbs)
|
72
70
|
hub = Hub.new(client, scope)
|
73
|
-
Thread.current
|
71
|
+
Thread.current.thread_variable_set(THREAD_LOCAL, hub)
|
74
72
|
@main_hub = hub
|
75
73
|
@background_worker = Sentry::BackgroundWorker.new(config)
|
76
74
|
end
|
@@ -82,7 +80,7 @@ module Sentry
|
|
82
80
|
|
83
81
|
# Takes an instance of Sentry::Breadcrumb and stores it to the current active scope.
|
84
82
|
def add_breadcrumb(breadcrumb)
|
85
|
-
|
83
|
+
get_current_hub&.add_breadcrumb(breadcrumb)
|
86
84
|
end
|
87
85
|
|
88
86
|
# Returns the current active hub.
|
@@ -94,7 +92,7 @@ module Sentry
|
|
94
92
|
# ideally, we should do this proactively whenever a new thread is created
|
95
93
|
# but it's impossible for the SDK to keep track every new thread
|
96
94
|
# so we need to use this rather passive way to make sure the app doesn't crash
|
97
|
-
Thread.current
|
95
|
+
Thread.current.thread_variable_get(THREAD_LOCAL) || clone_hub_to_current_thread
|
98
96
|
end
|
99
97
|
|
100
98
|
# Returns the current active client.
|
@@ -109,7 +107,7 @@ module Sentry
|
|
109
107
|
|
110
108
|
# Clones the main thread's active hub and stores it to the current thread.
|
111
109
|
def clone_hub_to_current_thread
|
112
|
-
Thread.current
|
110
|
+
Thread.current.thread_variable_set(THREAD_LOCAL, get_main_hub.clone)
|
113
111
|
end
|
114
112
|
|
115
113
|
# Takes a block and yields the current active scope.
|
@@ -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,11 @@ require "sentry/transport"
|
|
2
2
|
|
3
3
|
module Sentry
|
4
4
|
class Client
|
5
|
-
attr_reader :transport, :configuration
|
5
|
+
attr_reader :transport, :configuration, :logger
|
6
6
|
|
7
7
|
def initialize(configuration)
|
8
8
|
@configuration = configuration
|
9
|
+
@logger = configuration.logger
|
9
10
|
|
10
11
|
if transport_class = configuration.transport.transport_class
|
11
12
|
@transport = transport_class.new(configuration)
|
@@ -26,32 +27,17 @@ module Sentry
|
|
26
27
|
scope.apply_to_event(event, hint)
|
27
28
|
|
28
29
|
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
|
30
|
+
dispatch_async_event(async_block, event, hint)
|
31
|
+
elsif hint.fetch(:background, true)
|
32
|
+
dispatch_background_event(event, hint)
|
44
33
|
else
|
45
|
-
|
46
|
-
Sentry.background_worker.perform do
|
47
|
-
send_event(event, hint)
|
48
|
-
end
|
49
|
-
else
|
50
|
-
send_event(event, hint)
|
51
|
-
end
|
34
|
+
send_event(event, hint)
|
52
35
|
end
|
53
36
|
|
54
37
|
event
|
38
|
+
rescue => e
|
39
|
+
logger.error(LOGGER_PROGNAME) { "Event capturing failed: #{e.message}" }
|
40
|
+
nil
|
55
41
|
end
|
56
42
|
|
57
43
|
def event_from_exception(exception, hint = {})
|
@@ -85,16 +71,50 @@ module Sentry
|
|
85
71
|
|
86
72
|
def send_event(event, hint = nil)
|
87
73
|
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
74
|
|
90
|
-
if
|
91
|
-
configuration.
|
92
|
-
|
75
|
+
if event_type != TransactionEvent::TYPE && configuration.before_send
|
76
|
+
event = configuration.before_send.call(event, hint)
|
77
|
+
|
78
|
+
if event.nil?
|
79
|
+
logger.info(LOGGER_PROGNAME) { "Discarded event because before_send returned nil" }
|
80
|
+
return
|
81
|
+
end
|
93
82
|
end
|
94
83
|
|
95
84
|
transport.send_event(event)
|
96
85
|
|
97
86
|
event
|
87
|
+
rescue => e
|
88
|
+
loggable_event_type = (event_type || "event").capitalize
|
89
|
+
logger.error(LOGGER_PROGNAME) { "#{loggable_event_type} sending failed: #{e.message}" }
|
90
|
+
logger.error(LOGGER_PROGNAME) { "Unreported #{loggable_event_type}: #{Event.get_log_message(event.to_hash)}" }
|
91
|
+
raise
|
98
92
|
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def dispatch_background_event(event, hint)
|
97
|
+
Sentry.background_worker.perform do
|
98
|
+
send_event(event, hint)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def dispatch_async_event(async_block, event, hint)
|
103
|
+
# We have to convert to a JSON-like hash, because background job
|
104
|
+
# processors (esp ActiveJob) may not like weird types in the event hash
|
105
|
+
event_hash = event.to_json_compatible
|
106
|
+
|
107
|
+
if async_block.arity == 2
|
108
|
+
hint = JSON.parse(JSON.generate(hint))
|
109
|
+
async_block.call(event_hash, hint)
|
110
|
+
else
|
111
|
+
async_block.call(event_hash)
|
112
|
+
end
|
113
|
+
rescue => e
|
114
|
+
loggable_event_type = event_hash["type"] || "event"
|
115
|
+
logger.error(LOGGER_PROGNAME) { "Async #{loggable_event_type} sending failed: #{e.message}" }
|
116
|
+
send_event(event, hint)
|
117
|
+
end
|
118
|
+
|
99
119
|
end
|
100
120
|
end
|