sentry-ruby-core 4.1.5.pre.beta.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.craft.yml +33 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +125 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +258 -0
- data/Rakefile +13 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/sentry-ruby.rb +191 -0
- data/lib/sentry/background_worker.rb +37 -0
- data/lib/sentry/backtrace.rb +126 -0
- data/lib/sentry/benchmarks/benchmark_transport.rb +14 -0
- data/lib/sentry/breadcrumb.rb +25 -0
- data/lib/sentry/breadcrumb/sentry_logger.rb +87 -0
- data/lib/sentry/breadcrumb_buffer.rb +47 -0
- data/lib/sentry/client.rb +96 -0
- data/lib/sentry/configuration.rb +396 -0
- data/lib/sentry/core_ext/object/deep_dup.rb +57 -0
- data/lib/sentry/core_ext/object/duplicable.rb +153 -0
- data/lib/sentry/dsn.rb +48 -0
- data/lib/sentry/event.rb +173 -0
- data/lib/sentry/hub.rb +143 -0
- data/lib/sentry/integrable.rb +24 -0
- data/lib/sentry/interface.rb +22 -0
- data/lib/sentry/interfaces/exception.rb +11 -0
- data/lib/sentry/interfaces/request.rb +113 -0
- data/lib/sentry/interfaces/single_exception.rb +14 -0
- data/lib/sentry/interfaces/stacktrace.rb +90 -0
- data/lib/sentry/linecache.rb +44 -0
- data/lib/sentry/logger.rb +20 -0
- data/lib/sentry/rack.rb +4 -0
- data/lib/sentry/rack/capture_exceptions.rb +68 -0
- data/lib/sentry/rack/deprecations.rb +19 -0
- data/lib/sentry/rake.rb +17 -0
- data/lib/sentry/scope.rb +210 -0
- data/lib/sentry/span.rb +133 -0
- data/lib/sentry/transaction.rb +157 -0
- data/lib/sentry/transaction_event.rb +29 -0
- data/lib/sentry/transport.rb +88 -0
- data/lib/sentry/transport/configuration.rb +21 -0
- data/lib/sentry/transport/dummy_transport.rb +14 -0
- data/lib/sentry/transport/http_transport.rb +62 -0
- data/lib/sentry/utils/argument_checking_helper.rb +11 -0
- data/lib/sentry/utils/exception_cause_chain.rb +20 -0
- data/lib/sentry/utils/real_ip.rb +70 -0
- data/lib/sentry/utils/request_id.rb +16 -0
- data/lib/sentry/version.rb +3 -0
- data/sentry-ruby-core.gemspec +27 -0
- data/sentry-ruby.gemspec +23 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a01d1d363871eb0f9e438a50aadc4f0ec8ec55dd87a9d925cf9aab9fe7feb33b
|
4
|
+
data.tar.gz: f1d0fac64b253006be7080b3b2c787d09d236cf9d96376d3640e4664bda12c1b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7b584b6e632a6bf9405c4c4ca19f9c9b5f0ac0b85557ea07dec866a6c45b5c4225cc337b68226050802c318a28dd1344dd2278af984f1246012801c671a2f9a5
|
7
|
+
data.tar.gz: aec1b41e3032d46c875a9a1236ac6fa29947da68900c3cab3427cd624ce3d78c6ad3cdf4885f9544f6b85377723af7e69f11d017966b162a01a3367c7107ed13
|
data/.craft.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
minVersion: '0.13.2'
|
2
|
+
github:
|
3
|
+
owner: getsentry
|
4
|
+
repo: sentry-ruby
|
5
|
+
changelogPolicy: simple
|
6
|
+
preReleaseCommand: ruby ../.scripts/bump-version.rb
|
7
|
+
releaseBranchPrefix: release-sentry-ruby
|
8
|
+
statusProvider:
|
9
|
+
name: github
|
10
|
+
artifactProvider:
|
11
|
+
name: github
|
12
|
+
targets:
|
13
|
+
- name: gem
|
14
|
+
onlyIfPresent: /^sentry-ruby$/
|
15
|
+
- name: github
|
16
|
+
onlyIfPresent: /^sentry-ruby$/
|
17
|
+
tagPrefix: sentry-ruby-v
|
18
|
+
- name: registry
|
19
|
+
onlyIfPresent: /^sentry-ruby$/
|
20
|
+
type: sdk
|
21
|
+
config:
|
22
|
+
canonical: 'gem:sentry-ruby'
|
23
|
+
|
24
|
+
- name: gem
|
25
|
+
onlyIfPresent: /^sentry-ruby-core$/
|
26
|
+
- name: github
|
27
|
+
onlyIfPresent: /^sentry-ruby-core$/
|
28
|
+
tagPrefix: sentry-ruby-v
|
29
|
+
- name: registry
|
30
|
+
onlyIfPresent: /^sentry-ruby-core$/
|
31
|
+
type: sdk
|
32
|
+
config:
|
33
|
+
canonical: 'gem:sentry-ruby-core'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 4.1.5-beta.0
|
4
|
+
|
5
|
+
- Event message and exception message should have a size limit [#1221](https://github.com/getsentry/sentry-ruby/pull/1221)
|
6
|
+
- Add sentry-ruby-core as a more flexible option [#1226](https://github.com/getsentry/sentry-ruby/pull/1226)
|
7
|
+
|
8
|
+
## 4.1.4
|
9
|
+
|
10
|
+
- Fix headers serialization for sentry-ruby [#1197](https://github.com/getsentry/sentry-ruby/pull/1197) (by @moofkit)
|
11
|
+
- Support capturing "sentry-trace" header from the middleware [#1205](https://github.com/getsentry/sentry-ruby/pull/1205)
|
12
|
+
- Document public APIs on the Sentry module [#1208](https://github.com/getsentry/sentry-ruby/pull/1208)
|
13
|
+
- Check the argument type of capture_exception and capture_event helpers [#1209](https://github.com/getsentry/sentry-ruby/pull/1209)
|
14
|
+
|
15
|
+
## 4.1.3
|
16
|
+
|
17
|
+
- rm reference to old constant (from Rails v2.2) [#1184](https://github.com/getsentry/sentry-ruby/pull/1184)
|
18
|
+
- Use copied env in events [#1186](https://github.com/getsentry/sentry-ruby/pull/1186)
|
19
|
+
- Fixes [#1183](https://github.com/getsentry/sentry-ruby/issues/1183)
|
20
|
+
- Refactor RequestInterface [#1187](https://github.com/getsentry/sentry-ruby/pull/1187)
|
21
|
+
- Supply event hint to async callback when possible [#1189](https://github.com/getsentry/sentry-ruby/pull/1189)
|
22
|
+
- Fixes [#1188](https://github.com/getsentry/sentry-ruby/issues/1188)
|
23
|
+
- Refactor stacktrace parsing and increase test coverage [#1190](https://github.com/getsentry/sentry-ruby/pull/1190)
|
24
|
+
- Sentry.send_event should also take a hint [#1192](https://github.com/getsentry/sentry-ruby/pull/1192)
|
25
|
+
|
26
|
+
## 4.1.2
|
27
|
+
|
28
|
+
- before_send callback shouldn't be applied to transaction events [#1167](https://github.com/getsentry/sentry-ruby/pull/1167)
|
29
|
+
- Transaction improvements [#1170](https://github.com/getsentry/sentry-ruby/pull/1170)
|
30
|
+
- Support Ruby 3 [#1172](https://github.com/getsentry/sentry-ruby/pull/1172)
|
31
|
+
- Add Integrable module [#1177](https://github.com/getsentry/sentry-ruby/pull/1177)
|
32
|
+
|
33
|
+
## 4.1.1
|
34
|
+
|
35
|
+
- Fix NoMethodError when sending is not allowed [#1161](https://github.com/getsentry/sentry-ruby/pull/1161)
|
36
|
+
- Add notification for users who still use deprecated middlewares [#1160](https://github.com/getsentry/sentry-ruby/pull/1160)
|
37
|
+
- Improve top-level api safety [#1162](https://github.com/getsentry/sentry-ruby/pull/1162)
|
38
|
+
|
39
|
+
## 4.1.0
|
40
|
+
|
41
|
+
- Separate rack integration [#1138](https://github.com/getsentry/sentry-ruby/pull/1138)
|
42
|
+
- Fixes [#1136](https://github.com/getsentry/sentry-ruby/pull/1136)
|
43
|
+
- Fix event sampling [#1144](https://github.com/getsentry/sentry-ruby/pull/1144)
|
44
|
+
- Merge & rename 2 Rack middlewares [#1147](https://github.com/getsentry/sentry-ruby/pull/1147)
|
45
|
+
- Fixes [#1153](https://github.com/getsentry/sentry-ruby/pull/1153)
|
46
|
+
- Removed `Sentry::Rack::Tracing` middleware and renamed `Sentry::Rack::CaptureException` to `Sentry::Rack::CaptureExceptions`.
|
47
|
+
- Deep-copy spans [#1148](https://github.com/getsentry/sentry-ruby/pull/1148)
|
48
|
+
- Move span recorder related code from Span to Transaction [#1149](https://github.com/getsentry/sentry-ruby/pull/1149)
|
49
|
+
- Check SDK initialization before running integrations [#1151](https://github.com/getsentry/sentry-ruby/pull/1151)
|
50
|
+
- Fixes [#1145](https://github.com/getsentry/sentry-ruby/pull/1145)
|
51
|
+
- Refactor transport [#1154](https://github.com/getsentry/sentry-ruby/pull/1154)
|
52
|
+
- Implement non-blocking event sending [#1155](https://github.com/getsentry/sentry-ruby/pull/1155)
|
53
|
+
- Added `background_worker_threads` configuration option.
|
54
|
+
|
55
|
+
### Noticeable Changes
|
56
|
+
|
57
|
+
#### Middleware Changes
|
58
|
+
|
59
|
+
`Sentry::Rack::Tracing` is now removed. And `Sentry::Rack::CaptureException` has been renamed to `Sentry::Rack::CaptureExceptions`.
|
60
|
+
|
61
|
+
#### Events Are Sent Asynchronously
|
62
|
+
|
63
|
+
`sentry-ruby` now sends events asynchronously by default. The functionality works like this:
|
64
|
+
|
65
|
+
1. When the SDK is initialized, a `Sentry::BackgroundWorker` will be initialized too.
|
66
|
+
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.
|
67
|
+
3. The worker will have a number of threads. And the one of the idle threads will pick the job and call `Client#send_event`.
|
68
|
+
- If all the threads are busy, new jobs will be put into a queue, which has a limit of 30.
|
69
|
+
- If the queue size is exceeded, new events will be dropped.
|
70
|
+
|
71
|
+
However, if you still prefer to use your own async approach, that's totally fine. If you have `config.async` set, the worker won't initialize a thread pool and won't be used either.
|
72
|
+
|
73
|
+
This functionality also introduces a new `background_worker_threads` config option. It allows you to decide how many threads should the worker hold. By default, the value will be the number of the processors your machine has. For example, if your machine has 4 processors, the value would be 4.
|
74
|
+
|
75
|
+
Of course, you can always override the value to fit your use cases, like
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
config.background_worker_threads = 5 # the worker will have 5 threads for sending events
|
79
|
+
```
|
80
|
+
|
81
|
+
You can also disable this new non-blocking behaviour by giving a `0` value:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
config.background_worker_threads = 0 # all events will be sent synchronously
|
85
|
+
```
|
86
|
+
|
87
|
+
## 4.0.1
|
88
|
+
|
89
|
+
- Add rake integration: [1137](https://github.com/getsentry/sentry-ruby/pull/1137)
|
90
|
+
- Make Event's interfaces accessible: [1135](https://github.com/getsentry/sentry-ruby/pull/1135)
|
91
|
+
- ActiveSupportLogger should only record events that has a started time: [1132](https://github.com/getsentry/sentry-ruby/pull/1132)
|
92
|
+
|
93
|
+
## 4.0.0
|
94
|
+
|
95
|
+
- Only documents update for the official release and no API/feature changes.
|
96
|
+
|
97
|
+
## 0.3.0
|
98
|
+
|
99
|
+
- Major API changes: [1123](https://github.com/getsentry/sentry-ruby/pull/1123)
|
100
|
+
- Support event hint: [1122](https://github.com/getsentry/sentry-ruby/pull/1122)
|
101
|
+
- Add request-id tag to events: [1120](https://github.com/getsentry/sentry-ruby/pull/1120) (by @tvec)
|
102
|
+
|
103
|
+
## 0.2.0
|
104
|
+
|
105
|
+
- Multiple fixes and refactorings
|
106
|
+
- Tracing support
|
107
|
+
|
108
|
+
## 0.1.3
|
109
|
+
|
110
|
+
Fix require reference
|
111
|
+
|
112
|
+
## 0.1.2
|
113
|
+
|
114
|
+
- Fix: Fix async callback [1098](https://github.com/getsentry/sentry-ruby/pull/1098)
|
115
|
+
- Refactor: Some code cleanup [1100](https://github.com/getsentry/sentry-ruby/pull/1100)
|
116
|
+
- Refactor: Remove Event options [1101](https://github.com/getsentry/sentry-ruby/pull/1101)
|
117
|
+
|
118
|
+
## 0.1.1
|
119
|
+
|
120
|
+
- Feature: Allow passing custom scope to Hub#capture* helpers [1086](https://github.com/getsentry/sentry-ruby/pull/1086)
|
121
|
+
|
122
|
+
## 0.1.0
|
123
|
+
|
124
|
+
First version
|
125
|
+
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at stan001212@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gem "sentry-ruby-core", path: "./"
|
4
|
+
gem "sentry-ruby", path: "./"
|
5
|
+
|
6
|
+
gem "rake", "~> 12.0"
|
7
|
+
gem "rspec", "~> 3.0"
|
8
|
+
gem "codecov", "0.2.12"
|
9
|
+
|
10
|
+
gem "pry"
|
11
|
+
gem "rack" unless ENV["WITHOUT_RACK"] == "1"
|
12
|
+
|
13
|
+
gem "benchmark-ips"
|
14
|
+
gem "benchmark_driver"
|
15
|
+
gem "benchmark-ipsa"
|
16
|
+
gem "benchmark-memory"
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 st0012
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
<p align="center">
|
2
|
+
<a href="https://sentry.io" target="_blank" align="center">
|
3
|
+
<img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
|
4
|
+
</a>
|
5
|
+
<br>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
# sentry-ruby, the Ruby Client for Sentry
|
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).**
|
11
|
+
|
12
|
+
---
|
13
|
+
|
14
|
+
|
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
|
+
|
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
|
+
|
24
|
+
The official Ruby-language client and integration layer for the [Sentry](https://github.com/getsentry/sentry) error reporting API.
|
25
|
+
|
26
|
+
|
27
|
+
## Requirements
|
28
|
+
|
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.
|
30
|
+
|
31
|
+
## Migrate From sentry-raven
|
32
|
+
|
33
|
+
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/).
|
34
|
+
|
35
|
+
## Getting Started
|
36
|
+
|
37
|
+
### Install
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
gem "sentry-ruby"
|
41
|
+
```
|
42
|
+
|
43
|
+
and depends on the integrations you want to have, you might also want to install these:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
gem "sentry-rails"
|
47
|
+
gem "sentry-sidekiq"
|
48
|
+
# and mores to come in the future!
|
49
|
+
```
|
50
|
+
|
51
|
+
### Sentry only runs when Sentry DSN is set
|
52
|
+
|
53
|
+
Sentry will capture and send exceptions to the Sentry server whenever its DSN is set. This makes environment-based configuration easy - if you don't want to send errors in a certain environment, just don't set the DSN in that environment!
|
54
|
+
|
55
|
+
```bash
|
56
|
+
# Set your SENTRY_DSN environment variable.
|
57
|
+
export SENTRY_DSN=http://public@example.com/project-id
|
58
|
+
```
|
59
|
+
```ruby
|
60
|
+
# Or you can configure the client in the code.
|
61
|
+
Sentry.init do |config|
|
62
|
+
config.dsn = 'http://public@example.com/project-id'
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
### Sentry doesn't report some kinds of data by default
|
67
|
+
|
68
|
+
**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
|
+
|
70
|
+
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:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
Sentry.init do |config|
|
74
|
+
# other configs
|
75
|
+
config.send_default_pii = true
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
### Performance Monitoring
|
80
|
+
|
81
|
+
You can activate performance monitoring by enabling traces sampling:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
Sentry.init do |config|
|
85
|
+
# set a uniform sample rate between 0.0 and 1.0
|
86
|
+
config.traces_sample_rate = 0.2
|
87
|
+
|
88
|
+
# or control sampling dynamically
|
89
|
+
config.traces_sampler = lambda do |sampling_context|
|
90
|
+
# sampling_context[:transaction_context] contains the information about the transaction
|
91
|
+
# sampling_context[:parent_sampled] contains the transaction's parent's sample decision
|
92
|
+
true # return value can be a boolean or a float between 0.0 and 1.0
|
93
|
+
end
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
To learn more about performance monitoring, please visit the [official documentation](https://docs.sentry.io/platforms/ruby/performance).
|
98
|
+
|
99
|
+
### Usage
|
100
|
+
|
101
|
+
`sentry-ruby` has a default integration with `Rack`, so you only need to use the middleware in your application like:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
require 'sentry-ruby'
|
105
|
+
|
106
|
+
Sentry.init do |config|
|
107
|
+
config.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0'
|
108
|
+
|
109
|
+
# To activate performance monitoring, set one of these options.
|
110
|
+
# We recommend adjusting the value in production:
|
111
|
+
config.traces_sample_rate = 0.5
|
112
|
+
# or
|
113
|
+
config.traces_sampler = lambda do |context|
|
114
|
+
true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
use Sentry::Rack::CaptureExceptions
|
119
|
+
```
|
120
|
+
|
121
|
+
Otherwise, Sentry you can always use the capture helpers manually
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
Sentry.capture_message("hello world!")
|
125
|
+
|
126
|
+
begin
|
127
|
+
1 / 0
|
128
|
+
rescue ZeroDivisionError => exception
|
129
|
+
Sentry.capture_exception(exception)
|
130
|
+
end
|
131
|
+
```
|
132
|
+
|
133
|
+
We also provide integrations with popular frameworks/libraries with the related extensions:
|
134
|
+
|
135
|
+
- [sentry-rails](https://github.com/getsentry/sentry-ruby/tree/master/sentry-rails)
|
136
|
+
- [sentry-sidekiq](https://github.com/getsentry/sentry-ruby/tree/master/sentry-sidekiq)
|
137
|
+
|
138
|
+
### More configuration
|
139
|
+
|
140
|
+
You're all set - but there's a few more settings you may want to know about too!
|
141
|
+
|
142
|
+
#### Blocking v.s. Non-blocking
|
143
|
+
|
144
|
+
**Before version 4.1.0**, `sentry-ruby` sends every event immediately. But it can be configured to send asynchronously:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
config.async = lambda { |event, hint|
|
148
|
+
Thread.new { Sentry.send_event(event, hint) }
|
149
|
+
}
|
150
|
+
```
|
151
|
+
|
152
|
+
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.
|
153
|
+
|
154
|
+
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.
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
config.async = lambda { |event, hint| SentryJob.perform_later(event, hint) }
|
158
|
+
|
159
|
+
class SentryJob < ActiveJob::Base
|
160
|
+
queue_as :default
|
161
|
+
|
162
|
+
def perform(event, hint)
|
163
|
+
Sentry.send_event(event, hint)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
```
|
167
|
+
|
168
|
+
|
169
|
+
**After version 4.1.0**, `sentry-ruby` sends events asynchronously by default. The functionality works like this:
|
170
|
+
|
171
|
+
1. When the SDK is initialized, a `Sentry::BackgroundWorker` will be initialized too.
|
172
|
+
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.
|
173
|
+
3. The worker will have a number of threads. And the one of the idle threads will pick the job and call `Client#send_event`.
|
174
|
+
- If all the threads are busy, new jobs will be put into a queue, which has a limit of 30.
|
175
|
+
- If the queue size is exceeded, new events will be dropped.
|
176
|
+
|
177
|
+
However, if you still prefer to use your own async approach, that's totally fine. If you have `config.async` set, the worker won't initialize a thread pool and won't be used either.
|
178
|
+
|
179
|
+
##### About `Sentry::BackgroundWorker`
|
180
|
+
|
181
|
+
- The worker is built on top of the [concurrent-ruby](https://github.com/ruby-concurrency/concurrent-ruby) gem's [ThreadPoolExecutor](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ThreadPoolExecutor.html), which is also used by Rails ActiveJob's async adapter. This should minimize the risk of messing up client applications with our own thread pool implementaion.
|
182
|
+
|
183
|
+
This functionality also introduces a new `background_worker_threads` config option. It allows you to decide how many threads should the worker hold. By default, the value will be the number of the processors your machine has. For example, if your machine has 4 processors, the value would be 4.
|
184
|
+
|
185
|
+
Of course, you can always override the value to fit your use cases, like
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
config.background_worker_threads = 5 # the worker will have 5 threads for sending events
|
189
|
+
```
|
190
|
+
|
191
|
+
You can also disable this new non-blocking behaviour by giving a `0` value:
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
config.background_worker_threads = 0 # all events will be sent synchronously
|
195
|
+
```
|
196
|
+
|
197
|
+
If you want to send a particular event immediately, you can use event hints to do it:
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
Sentry.capture_message("send me now!", hint: { background: false })
|
201
|
+
```
|
202
|
+
|
203
|
+
#### Contexts
|
204
|
+
|
205
|
+
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:
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
Sentry.configure_scope do |scope|
|
209
|
+
scope.set_user(id: 1, email: "test@example.com")
|
210
|
+
|
211
|
+
scope.set_tag(:tag, "foo")
|
212
|
+
scope.set_tags(tag_1: "foo", tag_2: "bar")
|
213
|
+
|
214
|
+
scope.set_extra(:order_number, 1234)
|
215
|
+
scope.set_extras(order_number: 1234, tickets_count: 4)
|
216
|
+
end
|
217
|
+
|
218
|
+
Sentry.capture_exception(exception) # the event will carry all those information now
|
219
|
+
```
|
220
|
+
|
221
|
+
Or use top-level setters
|
222
|
+
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
Sentry.set_user(id: 1, email: "test@example.com")
|
226
|
+
Sentry.set_tags(tag_1: "foo", tag_2: "bar")
|
227
|
+
Sentry.set_extras(order_number: 1234, tickets_count: 4)
|
228
|
+
```
|
229
|
+
|
230
|
+
Or build up a temporary scope for local information:
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
Sentry.configure_scope do |scope|
|
234
|
+
scope.set_tags(tag_1: "foo")
|
235
|
+
end
|
236
|
+
|
237
|
+
Sentry.with_scope do |scope|
|
238
|
+
scope.set_tags(tag_1: "bar", tag_2: "baz")
|
239
|
+
|
240
|
+
Sentry.capture_message("message") # this event will have 2 tags: tag_1 => "bar" and tag_2 => "baz"
|
241
|
+
end
|
242
|
+
|
243
|
+
Sentry.capture_message("another message") # this event will have 1 tag: tag_1 => "foo"
|
244
|
+
```
|
245
|
+
|
246
|
+
Of course, you can always assign the information on a per-event basis:
|
247
|
+
|
248
|
+
```ruby
|
249
|
+
Sentry.capture_exception(exception, tags: {foo: "bar"})
|
250
|
+
```
|
251
|
+
|
252
|
+
## More Information
|
253
|
+
|
254
|
+
* [Documentation](https://docs.sentry.io/platforms/ruby/)
|
255
|
+
* [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues)
|
256
|
+
* [Forum](https://forum.sentry.io/)
|
257
|
+
- [Discord](https://discord.gg/ez5KZN7)
|
258
|
+
|