sentry-raven 3.0.4 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +32 -0
- data/.github/pull_request_template.md +16 -0
- data/.github/workflows/test.yml +5 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +6 -3
- data/CHANGELOG.md +118 -1
- data/CONTRIBUTING.md +71 -0
- data/README.md +2 -2
- data/lib/raven/backtrace.rb +2 -0
- data/lib/raven/base.rb +1 -0
- data/lib/raven/breadcrumbs/active_support_logger.rb +25 -0
- data/lib/raven/breadcrumbs/logger.rb +2 -92
- data/lib/raven/breadcrumbs/sentry_logger.rb +73 -0
- data/lib/raven/cli.rb +1 -1
- data/lib/raven/client.rb +1 -1
- data/lib/raven/configuration.rb +66 -4
- data/lib/raven/context.rb +13 -8
- data/lib/raven/event.rb +23 -13
- data/lib/raven/helpers/deprecation_helper.rb +17 -0
- data/lib/raven/instance.rb +3 -1
- data/lib/raven/integrations/rack-timeout.rb +5 -1
- data/lib/raven/integrations/rails.rb +12 -3
- data/lib/raven/integrations/rails/active_job.rb +2 -1
- data/lib/raven/integrations/rails/backtrace_cleaner.rb +29 -0
- data/lib/raven/integrations/sidekiq.rb +4 -78
- data/lib/raven/integrations/sidekiq/cleanup_middleware.rb +13 -0
- data/lib/raven/integrations/sidekiq/context_filter.rb +42 -0
- data/lib/raven/integrations/sidekiq/error_handler.rb +38 -0
- data/lib/raven/version.rb +1 -1
- data/lib/sentry-raven-without-integrations.rb +6 -1
- data/lib/sentry_raven_without_integrations.rb +1 -0
- metadata +13 -4
- data/CONTRIUTING.md +0 -26
- data/lib/raven/breadcrumbs/activesupport.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41350227e78833d91c3cbff3192b09d7bf3cec1b8560aeabf815ec5f6fcac156
|
4
|
+
data.tar.gz: a40cf7486907f4069c719584c63dcf36a34587702bcfee8a25e0ab5816cdf72f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d0c868e31eb523845681398cb7579022dc6635bf3cc2982ae55cd83f5b0eaf414988b9a7ba6f728d96c43518fd27895fd98a3e0960577c1f06e4bb333be3339
|
7
|
+
data.tar.gz: a9d232ad2858a142d01d52eaa854ca1daa9c7844353487ac2be6c97b9715e41c3c807d93fdd5662e44e5bf0443dffbeb67e0d1ad39d3563e4cf088e433b7be6c
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve
|
4
|
+
title: ''
|
5
|
+
labels: bug
|
6
|
+
assignees: st0012
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Describe the bug**
|
11
|
+
|
12
|
+
**To Reproduce**
|
13
|
+
|
14
|
+
**Expected behavior**
|
15
|
+
|
16
|
+
**Actual behavior**
|
17
|
+
|
18
|
+
**Environment**
|
19
|
+
- Ruby Version:
|
20
|
+
- SDK Version:
|
21
|
+
- Integration Versions (if any):
|
22
|
+
- e.g. Rails 6.0, Sidekiq 6.1.2
|
23
|
+
|
24
|
+
**Raven Config**
|
25
|
+
|
26
|
+
This is not necessary but could be helpful.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Raven.configure do |config|
|
30
|
+
# the config you're using, without DSN and other sensitive data
|
31
|
+
end
|
32
|
+
```
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Thanks for your Pull Request 🎉
|
2
|
+
|
3
|
+
**Please keep these instructions in mind so we can review it more efficiently:**
|
4
|
+
|
5
|
+
- Add the references of all the related issues/PRs in the description
|
6
|
+
- Whether it's a new feature or a bug fix, make sure they're covered by new test cases
|
7
|
+
- If this PR contains any refactoring work, please give it its own commit(s)
|
8
|
+
|
9
|
+
|
10
|
+
**Other Notes**
|
11
|
+
- We squash all commits before merging
|
12
|
+
- We generally review new PRs within a week
|
13
|
+
- If you have any question, you can ask for feedback in our [discord community](https://discord.gg/Ww9hbqr) first
|
14
|
+
|
15
|
+
## Description
|
16
|
+
Describe your changes:
|
data/.github/workflows/test.yml
CHANGED
@@ -43,6 +43,11 @@ jobs:
|
|
43
43
|
bundler: 1
|
44
44
|
ruby-version: ${{ matrix.ruby_version }}
|
45
45
|
|
46
|
+
- name: Start Redis
|
47
|
+
uses: supercharge/redis-github-action@1.1.0
|
48
|
+
with:
|
49
|
+
redis-version: 5
|
50
|
+
|
46
51
|
- name: Build with Rails ${{ matrix.rails_version }}
|
47
52
|
env:
|
48
53
|
RAILS_VERSION: ${{ matrix.rails_version }}
|
data/.rubocop.yml
CHANGED
@@ -7,7 +7,7 @@ AllCops:
|
|
7
7
|
- 'vendor/**/*'
|
8
8
|
|
9
9
|
Metrics/ClassLength:
|
10
|
-
Max:
|
10
|
+
Max: 350
|
11
11
|
CountComments: false
|
12
12
|
|
13
13
|
Metrics/AbcSize:
|
@@ -23,7 +23,7 @@ Metrics/PerceivedComplexity:
|
|
23
23
|
Max: 11
|
24
24
|
|
25
25
|
Metrics/MethodLength:
|
26
|
-
Max:
|
26
|
+
Max: 40
|
27
27
|
|
28
28
|
Style/SymbolArray:
|
29
29
|
Enabled: false
|
@@ -55,6 +55,9 @@ Style/CommentedKeyword:
|
|
55
55
|
Style/RescueModifier:
|
56
56
|
Enabled: false
|
57
57
|
|
58
|
+
Style/RegexpLiteral:
|
59
|
+
Enabled: false
|
60
|
+
|
58
61
|
Style/StringLiterals:
|
59
62
|
Enabled: false
|
60
63
|
|
@@ -75,7 +78,7 @@ Style/NumericLiterals:
|
|
75
78
|
- 'spec/raven/processors/sanitizedata_processor_spec.rb'
|
76
79
|
|
77
80
|
Style/HashSyntax:
|
78
|
-
|
81
|
+
Enabled: false
|
79
82
|
|
80
83
|
Style/IfUnlessModifier:
|
81
84
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,123 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## 3.1.0
|
4
|
+
|
5
|
+
**Feature**
|
6
|
+
|
7
|
+
- Exclude all 4xx Rails errors ([#1004](https://github.com/getsentry/raven-ruby/pull/1004))
|
8
|
+
|
9
|
+
See the full list [here](https://github.com/getsentry/raven-ruby/blob/master/lib/raven/configuration.rb#L198-L219)
|
10
|
+
|
11
|
+
- Add some error context in `transport_failure_callback` ([#1003](https://github.com/getsentry/raven-ruby/pull/1003))
|
12
|
+
|
13
|
+
Before:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
config.transport_failure_callback = lambda { |event|
|
17
|
+
AdminMailer.email_admins("Oh god, it's on fire!", event).deliver_later
|
18
|
+
}
|
19
|
+
```
|
20
|
+
|
21
|
+
After:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
config.transport_failure_callback = lambda { |event, error|
|
25
|
+
AdminMailer.email_admins("Oh god, it's on fire because #{error.message}!", event).deliver_later
|
26
|
+
}
|
27
|
+
```
|
28
|
+
|
29
|
+
- Support cleaning up exception backtrace with customized backtrace_cleaner ([#1011](https://github.com/getsentry/raven-ruby/pull/1011))
|
30
|
+
|
31
|
+
The new config `backtrace_cleanup_callback` takes a lambda/proc object (default is `nil`) and will be called with exception's backtrace
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
Raven.configure do |config|
|
35
|
+
config.backtrace_cleanup_callback = lambda do |backtrace|
|
36
|
+
Rails.backtrace_cleaner.clean(backtrace)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
And with the Rails integration, it'll automatically use a customized `Raven::Rails::BacktraceCleaner` to clean up exception's backtrace. It's basically Rails 6's [backtrace cleaner](https://github.com/rails/rails/blob/master/railties/lib/rails/backtrace_cleaner.rb) but without silencers.
|
42
|
+
|
43
|
+
The main reason to add this cleaner is to remove template methods from the trace, e.g.
|
44
|
+
|
45
|
+
```
|
46
|
+
app/views/welcome/view_error.html.erb in _app_views_welcome_view_error_html_erb__2807287320172182514_65600 at line 1
|
47
|
+
```
|
48
|
+
|
49
|
+
will become
|
50
|
+
|
51
|
+
```
|
52
|
+
app/views/welcome/view_error.html.erb at line 1
|
53
|
+
```
|
54
|
+
|
55
|
+
This can help Sentry group issues more accurately. See [#957](https://github.com/getsentry/raven-ruby/issues/957) for more information about this.
|
56
|
+
|
57
|
+
If you don't want this change, you can disable it with:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
Raven.configure do |config|
|
61
|
+
config.backtrace_cleanup_callback = nil
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
- Make dsn value accessable from config ([#1012](https://github.com/getsentry/raven-ruby/pull/1012))
|
67
|
+
|
68
|
+
You can now access the dsn value via `Raven.configuration.dsn`
|
69
|
+
|
70
|
+
**Deprecation**
|
71
|
+
|
72
|
+
- Deprecate dasherized filenames ([#1006](https://github.com/getsentry/raven-ruby/pull/1006))
|
73
|
+
|
74
|
+
If you're using
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
gem 'sentry-raven', require: 'sentry-raven-without-integrations'
|
78
|
+
# or
|
79
|
+
require "sentry-raven-without-integrations"
|
80
|
+
```
|
81
|
+
|
82
|
+
you will start seeing deprecation warnings. Please change them into
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
gem 'sentry-raven', require: 'sentry_raven_without_integrations'
|
86
|
+
# or
|
87
|
+
require "sentry_raven_without_integrations"
|
88
|
+
```
|
89
|
+
|
90
|
+
- Unify breadcrumb loggers activation ([#1016](https://github.com/getsentry/raven-ruby/pull/1016))
|
91
|
+
|
92
|
+
Currently, we activate our breadcrumb loggers differently:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
require "raven/breadcrumbs/sentry_logger"
|
96
|
+
Raven.configuration.rails_activesupport_breadcrumbs = true
|
97
|
+
```
|
98
|
+
|
99
|
+
It's not a nice user interface, so this PR adds a new configuration
|
100
|
+
option `breadcrumbs_logger` to improve this:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
Raven.configuration.breadcrumbs_logger = :sentry_logger
|
104
|
+
Raven.configuration.breadcrumbs_logger = :active_support_logger
|
105
|
+
Raven.configuration.breadcrumbs_logger = [:sentry_logger, :active_support_logger]
|
106
|
+
```
|
107
|
+
|
108
|
+
Please migrate to the new activation apporach, otherwise you'll see depraction warnings. And old ones will be dropped in version 4.0.
|
109
|
+
|
110
|
+
**Refactor**
|
111
|
+
|
112
|
+
- Accept non-string message in Event.from_exception ([#1005](https://github.com/getsentry/raven-ruby/pull/1005))
|
113
|
+
- Refactor event initialization ([#1010](https://github.com/getsentry/raven-ruby/pull/1010))
|
114
|
+
- Refactor sidekiq integration ([#1019](https://github.com/getsentry/raven-ruby/pull/1019))
|
115
|
+
|
116
|
+
**Fix**
|
117
|
+
|
118
|
+
- Replace sys_command usages in context.rb ([#1017](https://github.com/getsentry/raven-ruby/pull/1017))
|
119
|
+
- Fix merge error from rack-timeout raven_context on old releases ([#1007](https://github.com/getsentry/raven-ruby/pull/1007))
|
120
|
+
- Return value of `rescue_with_handler` when intercepting ActiveJob exceptions ([#1027](https://github.com/getsentry/raven-ruby/pull/1027))
|
4
121
|
|
5
122
|
## 3.0.4
|
6
123
|
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,71 @@
|
|
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
|
+
# Contributing
|
9
|
+
|
10
|
+
You can contribute this project in the following ways:
|
11
|
+
|
12
|
+
- File a [bug report] or propose a feature
|
13
|
+
- Open a PR for bug fixes or implementing requested features
|
14
|
+
- Give feedback to opened issues/pull requests
|
15
|
+
- Test the latest version - `gem 'sentry-raven', github: 'getsentry/raven-ruby'`
|
16
|
+
- Contribute documentation in the [document repo]
|
17
|
+
|
18
|
+
|
19
|
+
And if you have any questions, please feel free to reach out on [Discord].
|
20
|
+
|
21
|
+
|
22
|
+
[bug report]: https://github.com/getsentry/raven-ruby/issues/new?template=bug_report.md
|
23
|
+
[document repo]: https://github.com/getsentry/sentry-docs
|
24
|
+
[Discord]: https://discord.gg/Ww9hbqr
|
25
|
+
|
26
|
+
## How To Contribute
|
27
|
+
|
28
|
+
### Running Tests
|
29
|
+
|
30
|
+
#### RAILS_VERSION
|
31
|
+
|
32
|
+
Because this SDK supports multiple versions of Rails, or even without Rails, you might want to run your test against different versions of Rails.
|
33
|
+
|
34
|
+
You can do this by changing the `RAILS_VERSION` environment variable:
|
35
|
+
|
36
|
+
|
37
|
+
```
|
38
|
+
$ echo RAILS_VERSION=6.0
|
39
|
+
$ bundle update # this is necessary if you're switching between Rails versions
|
40
|
+
$ bundle exec rake
|
41
|
+
```
|
42
|
+
|
43
|
+
If not specified, it runs tests against `Rails 5.2`.
|
44
|
+
|
45
|
+
And if you don't want to run the Rails related test cases, you can use `RAILS_VERSION=0`
|
46
|
+
|
47
|
+
```
|
48
|
+
$ RAILS_VERSION=0 bundle exec rake # runs without Rails related test cases
|
49
|
+
```
|
50
|
+
|
51
|
+
### Testing Your Change Against Example Rails Apps
|
52
|
+
|
53
|
+
We have a few example apps for different Rails versions under the `/examples` folder. You can use them to perform an end-to-end testing on your changes (just remember to change the DSN to your project's).
|
54
|
+
|
55
|
+
At this moment, we recommend testing against the [Rails 6 example](https://github.com/getsentry/raven-ruby/tree/master/examples/rails-6.0) first. Please read its readme to see what kind of testing you can perform with it.
|
56
|
+
|
57
|
+
|
58
|
+
## Making a release
|
59
|
+
|
60
|
+
Install and use `craft`: https://github.com/getsentry/craft
|
61
|
+
|
62
|
+
Make sure the `CHANGELOG.md` is update and latest `master` contains all changes.
|
63
|
+
|
64
|
+
Run:
|
65
|
+
|
66
|
+
```bash
|
67
|
+
craft prepare x.x.x
|
68
|
+
```
|
69
|
+
|
70
|
+
Where `x.x.x` stands for the version you want to release.
|
71
|
+
Afterwards reach out to an employee of Sentry, they will cut a release by running the `publish` process of `craft`.
|
data/README.md
CHANGED
@@ -105,8 +105,8 @@ end
|
|
105
105
|
If Raven fails to send an event to Sentry for any reason (either the Sentry server has returned a 4XX or 5XX response), this Proc or lambda will be called.
|
106
106
|
|
107
107
|
```ruby
|
108
|
-
config.transport_failure_callback = lambda { |event|
|
109
|
-
AdminMailer.email_admins("Oh god, it's on fire!", event).deliver_later
|
108
|
+
config.transport_failure_callback = lambda { |event, error|
|
109
|
+
AdminMailer.email_admins("Oh god, it's on fire because #{error.message}!", event).deliver_later
|
110
110
|
}
|
111
111
|
```
|
112
112
|
|
data/lib/raven/backtrace.rb
CHANGED
@@ -94,6 +94,8 @@ module Raven
|
|
94
94
|
def self.parse(backtrace, opts = {})
|
95
95
|
ruby_lines = backtrace.is_a?(Array) ? backtrace : backtrace.split(/\n\s*/)
|
96
96
|
|
97
|
+
ruby_lines = opts[:configuration].backtrace_cleanup_callback.call(ruby_lines) if opts[:configuration]&.backtrace_cleanup_callback
|
98
|
+
|
97
99
|
filters = opts[:filters] || []
|
98
100
|
filtered_lines = ruby_lines.to_a.map do |line|
|
99
101
|
filters.reduce(line) do |nested_line, proc|
|
data/lib/raven/base.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Raven
|
2
|
+
module Breadcrumbs
|
3
|
+
module ActiveSupportLogger
|
4
|
+
class << self
|
5
|
+
def add(name, started, _finished, _unique_id, data)
|
6
|
+
Raven.breadcrumbs.record do |crumb|
|
7
|
+
crumb.data = data
|
8
|
+
crumb.category = name
|
9
|
+
crumb.timestamp = started.to_i
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def inject
|
14
|
+
@subscriber = ::ActiveSupport::Notifications.subscribe(/.*/) do |name, started, finished, unique_id, data|
|
15
|
+
add(name, started, finished, unique_id, data)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def detach
|
20
|
+
::ActiveSupport::Notifications.unsubscribe(@subscriber)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,93 +1,3 @@
|
|
1
|
-
|
1
|
+
DeprecationHelper.deprecate_old_breadcrumbs_configuration(:sentry_logger)
|
2
2
|
|
3
|
-
|
4
|
-
module BreadcrumbLogger
|
5
|
-
LEVELS = {
|
6
|
-
::Logger::DEBUG => 'debug',
|
7
|
-
::Logger::INFO => 'info',
|
8
|
-
::Logger::WARN => 'warn',
|
9
|
-
::Logger::ERROR => 'error',
|
10
|
-
::Logger::FATAL => 'fatal'
|
11
|
-
}.freeze
|
12
|
-
|
13
|
-
EXC_FORMAT = /^([a-zA-Z0-9]+)\:\s(.*)$/.freeze
|
14
|
-
|
15
|
-
def self.parse_exception(message)
|
16
|
-
lines = message.split(/\n\s*/)
|
17
|
-
# TODO: wat
|
18
|
-
return nil unless lines.length > 2
|
19
|
-
|
20
|
-
match = lines[0].match(EXC_FORMAT)
|
21
|
-
return nil unless match
|
22
|
-
|
23
|
-
_, type, value = match.to_a
|
24
|
-
[type, value]
|
25
|
-
end
|
26
|
-
|
27
|
-
def add(*args)
|
28
|
-
add_breadcrumb(*args)
|
29
|
-
super
|
30
|
-
end
|
31
|
-
|
32
|
-
def add_breadcrumb(severity, message = nil, progname = nil)
|
33
|
-
message = progname if message.nil? # see Ruby's Logger docs for why
|
34
|
-
return if ignored_logger?(progname)
|
35
|
-
return if message.nil? || message == ""
|
36
|
-
|
37
|
-
# some loggers will add leading/trailing space as they (incorrectly, mind you)
|
38
|
-
# think of logging as a shortcut to std{out,err}
|
39
|
-
message = message.to_s.strip
|
40
|
-
|
41
|
-
last_crumb = Raven.breadcrumbs.peek
|
42
|
-
# try to avoid dupes from logger broadcasts
|
43
|
-
if last_crumb.nil? || last_crumb.message != message
|
44
|
-
error = Raven::BreadcrumbLogger.parse_exception(message)
|
45
|
-
# TODO(dcramer): we need to filter out the "currently captured error"
|
46
|
-
if error
|
47
|
-
Raven.breadcrumbs.record do |crumb|
|
48
|
-
crumb.level = Raven::BreadcrumbLogger::LEVELS.fetch(severity, nil)
|
49
|
-
crumb.category = progname || 'error'
|
50
|
-
crumb.type = 'error'
|
51
|
-
crumb.data = {
|
52
|
-
:type => error[0],
|
53
|
-
:value => error[1]
|
54
|
-
}
|
55
|
-
end
|
56
|
-
else
|
57
|
-
Raven.breadcrumbs.record do |crumb|
|
58
|
-
crumb.level = Raven::BreadcrumbLogger::LEVELS.fetch(severity, nil)
|
59
|
-
crumb.category = progname || 'logger'
|
60
|
-
crumb.message = message
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def ignored_logger?(progname)
|
69
|
-
progname == "sentry" ||
|
70
|
-
Raven.configuration.exclude_loggers.include?(progname)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
module OldBreadcrumbLogger
|
74
|
-
def self.included(base)
|
75
|
-
base.class_eval do
|
76
|
-
include Raven::BreadcrumbLogger
|
77
|
-
alias_method :add_without_raven, :add
|
78
|
-
alias_method :add, :add_with_raven
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def add_with_raven(*args)
|
83
|
-
add_breadcrumb(*args)
|
84
|
-
add_without_raven(*args)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
Raven.safely_prepend(
|
90
|
-
"BreadcrumbLogger",
|
91
|
-
:from => Raven,
|
92
|
-
:to => ::Logger
|
93
|
-
)
|
3
|
+
require "raven/breadcrumbs/sentry_logger"
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Raven
|
4
|
+
module Breadcrumbs
|
5
|
+
module SentryLogger
|
6
|
+
LEVELS = {
|
7
|
+
::Logger::DEBUG => 'debug',
|
8
|
+
::Logger::INFO => 'info',
|
9
|
+
::Logger::WARN => 'warn',
|
10
|
+
::Logger::ERROR => 'error',
|
11
|
+
::Logger::FATAL => 'fatal'
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
def add(*args)
|
15
|
+
add_breadcrumb(*args)
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_breadcrumb(severity, message = nil, progname = nil)
|
20
|
+
message = progname if message.nil? # see Ruby's Logger docs for why
|
21
|
+
return if ignored_logger?(progname)
|
22
|
+
return if message.nil? || message == ""
|
23
|
+
|
24
|
+
# some loggers will add leading/trailing space as they (incorrectly, mind you)
|
25
|
+
# think of logging as a shortcut to std{out,err}
|
26
|
+
message = message.to_s.strip
|
27
|
+
|
28
|
+
last_crumb = Raven.breadcrumbs.peek
|
29
|
+
# try to avoid dupes from logger broadcasts
|
30
|
+
if last_crumb.nil? || last_crumb.message != message
|
31
|
+
Raven.breadcrumbs.record do |crumb|
|
32
|
+
crumb.level = Raven::Breadcrumbs::SentryLogger::LEVELS.fetch(severity, nil)
|
33
|
+
crumb.category = progname || 'logger'
|
34
|
+
crumb.message = message
|
35
|
+
crumb.type =
|
36
|
+
if severity >= 3
|
37
|
+
"error"
|
38
|
+
else
|
39
|
+
crumb.level
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def ignored_logger?(progname)
|
48
|
+
progname == "sentry" ||
|
49
|
+
Raven.configuration.exclude_loggers.include?(progname)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
module OldBreadcrumbsSentryLogger
|
53
|
+
def self.included(base)
|
54
|
+
base.class_eval do
|
55
|
+
include Raven::Breadcrumbs::SentryLogger
|
56
|
+
alias_method :add_without_raven, :add
|
57
|
+
alias_method :add, :add_with_raven
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_with_raven(*args)
|
62
|
+
add_breadcrumb(*args)
|
63
|
+
add_without_raven(*args)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
Raven.safely_prepend(
|
70
|
+
"Breadcrumbs::SentryLogger",
|
71
|
+
:from => Raven,
|
72
|
+
:to => ::Logger
|
73
|
+
)
|
data/lib/raven/cli.rb
CHANGED
data/lib/raven/client.rb
CHANGED
@@ -125,7 +125,7 @@ module Raven
|
|
125
125
|
configuration.logger.warn("Failed to submit event: #{get_log_message(event)}")
|
126
126
|
|
127
127
|
# configuration.transport_failure_callback can be false & nil
|
128
|
-
configuration.transport_failure_callback.call(event) if configuration.transport_failure_callback # rubocop:disable Style/SafeNavigation
|
128
|
+
configuration.transport_failure_callback.call(event, e) if configuration.transport_failure_callback # rubocop:disable Style/SafeNavigation
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
data/lib/raven/configuration.rb
CHANGED
@@ -12,6 +12,11 @@ module Raven
|
|
12
12
|
attr_reader :async
|
13
13
|
alias async? async
|
14
14
|
|
15
|
+
# An array of breadcrumbs loggers to be used. Available options are:
|
16
|
+
# - :sentry_logger
|
17
|
+
# - :active_support_logger
|
18
|
+
attr_reader :breadcrumbs_logger
|
19
|
+
|
15
20
|
# Number of lines of code context to capture, or nil for none
|
16
21
|
attr_accessor :context_lines
|
17
22
|
|
@@ -83,7 +88,7 @@ module Raven
|
|
83
88
|
attr_accessor :public_key
|
84
89
|
|
85
90
|
# Turns on ActiveSupport breadcrumbs integration
|
86
|
-
|
91
|
+
attr_reader :rails_activesupport_breadcrumbs
|
87
92
|
|
88
93
|
# Rails catches exceptions in the ActionDispatch::ShowExceptions or
|
89
94
|
# ActionDispatch::DebugExceptions middlewares, depending on the environment.
|
@@ -118,6 +123,19 @@ module Raven
|
|
118
123
|
# Otherwise, can be one of "http", "https", or "dummy"
|
119
124
|
attr_accessor :scheme
|
120
125
|
|
126
|
+
# a proc/lambda that takes an array of stack traces
|
127
|
+
# it'll be used to silence (reduce) backtrace of the exception
|
128
|
+
#
|
129
|
+
# for example:
|
130
|
+
#
|
131
|
+
# ```ruby
|
132
|
+
# Raven.configuration.backtrace_cleanup_callback = lambda do |backtrace|
|
133
|
+
# Rails.backtrace_cleaner.clean(backtrace)
|
134
|
+
# end
|
135
|
+
# ```
|
136
|
+
#
|
137
|
+
attr_accessor :backtrace_cleanup_callback
|
138
|
+
|
121
139
|
# Secret key for authentication with the Sentry server
|
122
140
|
# If you provide a DSN, this will be set automatically.
|
123
141
|
#
|
@@ -172,16 +190,32 @@ module Raven
|
|
172
190
|
# Errors object - an Array that contains error messages. See #
|
173
191
|
attr_reader :errors
|
174
192
|
|
193
|
+
# the dsn value, whether it's set via `config.dsn=` or `ENV["SENTRY_DSN"]`
|
194
|
+
attr_reader :dsn
|
195
|
+
|
196
|
+
# Most of these errors generate 4XX responses. In general, Sentry clients
|
197
|
+
# only automatically report 5xx responses.
|
175
198
|
IGNORE_DEFAULT = [
|
176
199
|
'AbstractController::ActionNotFound',
|
200
|
+
'ActionController::BadRequest',
|
177
201
|
'ActionController::InvalidAuthenticityToken',
|
202
|
+
'ActionController::InvalidCrossOriginRequest',
|
203
|
+
'ActionController::MethodNotAllowed',
|
204
|
+
'ActionController::NotImplemented',
|
205
|
+
'ActionController::ParameterMissing',
|
178
206
|
'ActionController::RoutingError',
|
179
207
|
'ActionController::UnknownAction',
|
208
|
+
'ActionController::UnknownFormat',
|
209
|
+
'ActionController::UnknownHttpMethod',
|
210
|
+
'ActionDispatch::Http::Parameters::ParseError',
|
211
|
+
'ActionView::MissingTemplate',
|
212
|
+
'ActiveJob::DeserializationError', # Can cause infinite loops
|
180
213
|
'ActiveRecord::RecordNotFound',
|
181
214
|
'CGI::Session::CookieStore::TamperedWithCookie',
|
182
215
|
'Mongoid::Errors::DocumentNotFound',
|
183
|
-
'
|
184
|
-
'
|
216
|
+
'Rack::QueryParser::InvalidParameterError',
|
217
|
+
'Rack::QueryParser::ParameterTypeError',
|
218
|
+
'Sinatra::NotFound'
|
185
219
|
].freeze
|
186
220
|
|
187
221
|
# Note the order - we have to remove circular references and bad characters
|
@@ -201,8 +235,11 @@ module Raven
|
|
201
235
|
LOG_PREFIX = "** [Raven] ".freeze
|
202
236
|
MODULE_SEPARATOR = "::".freeze
|
203
237
|
|
238
|
+
AVAILABLE_BREADCRUMBS_LOGGERS = [:sentry_logger, :active_support_logger].freeze
|
239
|
+
|
204
240
|
def initialize
|
205
241
|
self.async = false
|
242
|
+
self.breadcrumbs_logger = []
|
206
243
|
self.context_lines = 3
|
207
244
|
self.current_environment = current_environment_from_env
|
208
245
|
self.encoding = 'gzip'
|
@@ -215,7 +252,8 @@ module Raven
|
|
215
252
|
self.open_timeout = 1
|
216
253
|
self.processors = DEFAULT_PROCESSORS.dup
|
217
254
|
self.project_root = detect_project_root
|
218
|
-
|
255
|
+
@rails_activesupport_breadcrumbs = false
|
256
|
+
|
219
257
|
self.rails_report_rescued_exceptions = true
|
220
258
|
self.release = detect_release
|
221
259
|
self.sample_rate = 1.0
|
@@ -237,6 +275,8 @@ module Raven
|
|
237
275
|
def server=(value)
|
238
276
|
return if value.nil?
|
239
277
|
|
278
|
+
@dsn = value
|
279
|
+
|
240
280
|
uri = URI.parse(value)
|
241
281
|
uri_path = uri.path.split('/')
|
242
282
|
|
@@ -273,6 +313,23 @@ module Raven
|
|
273
313
|
@async = value
|
274
314
|
end
|
275
315
|
|
316
|
+
def breadcrumbs_logger=(logger)
|
317
|
+
loggers =
|
318
|
+
if logger.is_a?(Array)
|
319
|
+
logger
|
320
|
+
else
|
321
|
+
unless AVAILABLE_BREADCRUMBS_LOGGERS.include?(logger)
|
322
|
+
raise Raven::Error, "Unsupported breadcrumbs logger. Supported loggers: #{AVAILABLE_BREADCRUMBS_LOGGERS}"
|
323
|
+
end
|
324
|
+
|
325
|
+
Array(logger)
|
326
|
+
end
|
327
|
+
|
328
|
+
require "raven/breadcrumbs/sentry_logger" if loggers.include?(:sentry_logger)
|
329
|
+
|
330
|
+
@breadcrumbs_logger = logger
|
331
|
+
end
|
332
|
+
|
276
333
|
def transport_failure_callback=(value)
|
277
334
|
unless value == false || value.respond_to?(:call)
|
278
335
|
raise(ArgumentError, "transport_failure_callback must be callable (or false to disable)")
|
@@ -329,6 +386,11 @@ module Raven
|
|
329
386
|
Backtrace::Line.instance_variable_set(:@in_app_pattern, nil) # blow away cache
|
330
387
|
end
|
331
388
|
|
389
|
+
def rails_activesupport_breadcrumbs=(val)
|
390
|
+
DeprecationHelper.deprecate_old_breadcrumbs_configuration(:active_support_logger)
|
391
|
+
@rails_activesupport_breadcrumbs = val
|
392
|
+
end
|
393
|
+
|
332
394
|
def exception_class_allowed?(exc)
|
333
395
|
if exc.is_a?(Raven::Error)
|
334
396
|
# Try to prevent error reporting loops
|
data/lib/raven/context.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rbconfig'
|
2
|
+
require 'etc'
|
2
3
|
|
3
4
|
module Raven
|
4
5
|
class Context
|
@@ -24,18 +25,22 @@ module Raven
|
|
24
25
|
|
25
26
|
class << self
|
26
27
|
def os_context
|
27
|
-
@os_context ||=
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
@os_context ||=
|
29
|
+
begin
|
30
|
+
uname = Etc.uname
|
31
|
+
{
|
32
|
+
name: uname[:sysname] || RbConfig::CONFIG["host_os"],
|
33
|
+
version: uname[:version],
|
34
|
+
build: uname[:release],
|
35
|
+
kernel_version: uname[:version]
|
36
|
+
}
|
37
|
+
end
|
33
38
|
end
|
34
39
|
|
35
40
|
def runtime_context
|
36
41
|
@runtime_context ||= {
|
37
|
-
:
|
38
|
-
:
|
42
|
+
name: RbConfig::CONFIG["ruby_install_name"],
|
43
|
+
version: RUBY_DESCRIPTION || Raven.sys_command("ruby -v")
|
39
44
|
}
|
40
45
|
end
|
41
46
|
end
|
data/lib/raven/event.rb
CHANGED
@@ -8,6 +8,7 @@ module Raven
|
|
8
8
|
# See Sentry server default limits at
|
9
9
|
# https://github.com/getsentry/sentry/blob/master/src/sentry/conf/server.py
|
10
10
|
MAX_MESSAGE_SIZE_IN_BYTES = 1024 * 8
|
11
|
+
REQUIRED_OPTION_KEYS = [:configuration, :context, :breadcrumbs].freeze
|
11
12
|
|
12
13
|
SDK = { "name" => "raven-ruby", "version" => Raven::VERSION }.freeze
|
13
14
|
|
@@ -19,7 +20,7 @@ module Raven
|
|
19
20
|
|
20
21
|
attr_reader :level, :timestamp, :time_spent
|
21
22
|
|
22
|
-
def initialize(
|
23
|
+
def initialize(options)
|
23
24
|
# Set some simple default values
|
24
25
|
self.id = SecureRandom.uuid.delete("-")
|
25
26
|
self.timestamp = Time.now.utc
|
@@ -36,11 +37,17 @@ module Raven
|
|
36
37
|
self.runtime = {} # TODO: contexts
|
37
38
|
self.tags = {} # TODO: contexts
|
38
39
|
|
39
|
-
|
40
|
+
unless REQUIRED_OPTION_KEYS.all? { |key| options.key?(key) }
|
41
|
+
raise "you much provide configuration, context, and breadcrumbs when initializing a Raven::Event"
|
42
|
+
end
|
43
|
+
|
44
|
+
self.configuration = options[:configuration]
|
45
|
+
self.context = options[:context]
|
46
|
+
self.breadcrumbs = options[:breadcrumbs]
|
40
47
|
|
41
48
|
# Allow attributes to be set on the event at initialization
|
42
49
|
yield self if block_given?
|
43
|
-
|
50
|
+
options.each_pair { |key, val| public_send("#{key}=", val) unless val.nil? }
|
44
51
|
|
45
52
|
set_core_attributes_from_configuration
|
46
53
|
set_core_attributes_from_context
|
@@ -56,8 +63,7 @@ module Raven
|
|
56
63
|
end
|
57
64
|
options = Raven::Utils::DeepMergeHash.deep_merge(exception_context, options)
|
58
65
|
|
59
|
-
|
60
|
-
return unless configuration.exception_class_allowed?(exc)
|
66
|
+
return unless options[:configuration].exception_class_allowed?(exc)
|
61
67
|
|
62
68
|
new(options) do |evt|
|
63
69
|
evt.add_exception_interface(exc)
|
@@ -81,7 +87,17 @@ module Raven
|
|
81
87
|
end
|
82
88
|
|
83
89
|
def message=(args)
|
84
|
-
|
90
|
+
if args.is_a?(Array)
|
91
|
+
message, params = args[0], args[0..-1]
|
92
|
+
else
|
93
|
+
message = args
|
94
|
+
end
|
95
|
+
|
96
|
+
unless message.is_a?(String)
|
97
|
+
configuration.logger.debug("You're passing a non-string message")
|
98
|
+
message = message.to_s
|
99
|
+
end
|
100
|
+
|
85
101
|
interface(:message) do |int|
|
86
102
|
int.message = message.byteslice(0...MAX_MESSAGE_SIZE_IN_BYTES) # Messages limited to 10kb
|
87
103
|
int.params = params
|
@@ -159,7 +175,7 @@ module Raven
|
|
159
175
|
end
|
160
176
|
|
161
177
|
def stacktrace_interface_from(backtrace)
|
162
|
-
Backtrace.parse(backtrace).lines.reverse.each_with_object([]) do |line, memo|
|
178
|
+
Backtrace.parse(backtrace, { configuration: configuration }).lines.reverse.each_with_object([]) do |line, memo|
|
163
179
|
frame = StacktraceInterface::Frame.new
|
164
180
|
frame.abs_path = line.file if line.file
|
165
181
|
frame.function = line.method if line.method
|
@@ -186,12 +202,6 @@ module Raven
|
|
186
202
|
|
187
203
|
private
|
188
204
|
|
189
|
-
def copy_initial_state
|
190
|
-
self.configuration = Raven.configuration
|
191
|
-
self.breadcrumbs = Raven.breadcrumbs
|
192
|
-
self.context = Raven.context
|
193
|
-
end
|
194
|
-
|
195
205
|
def set_core_attributes_from_configuration
|
196
206
|
self.server_name ||= configuration.server_name
|
197
207
|
self.release ||= configuration.release
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DeprecationHelper
|
2
|
+
def self.deprecate_dasherized_filename(correct_filename)
|
3
|
+
warn "[Deprecation Warning] Dasherized filename \"#{correct_filename.gsub('_', '-')}\" is deprecated and will be removed in 4.0; use \"#{correct_filename}\" instead" # rubocop:disable Style/LineLength
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.deprecate_old_breadcrumbs_configuration(logger)
|
7
|
+
deprecated_usage =
|
8
|
+
if logger == :sentry_logger
|
9
|
+
"require \"raven/breadcrumbs/logger\""
|
10
|
+
else
|
11
|
+
"Raven.configuration.rails_activesupport_breadcrumbs = true"
|
12
|
+
end
|
13
|
+
recommended_usage = "Raven.configuration.breadcrumbs_logger = :#{logger}"
|
14
|
+
|
15
|
+
warn "[Deprecation Warning] The way you enable breadcrumbs logger (#{deprecated_usage}) is deprecated and will be removed in 4.0; use '#{recommended_usage}' instead" # rubocop:disable Style/LineLength
|
16
|
+
end
|
17
|
+
end
|
data/lib/raven/instance.rb
CHANGED
@@ -77,7 +77,7 @@ module Raven
|
|
77
77
|
# Send an event to the configured Sentry server
|
78
78
|
#
|
79
79
|
# @example
|
80
|
-
# evt = Raven::Event.new(:message => "An
|
80
|
+
# evt = Raven::Event.new(:message => "An errore)
|
81
81
|
# Raven.send_event(evt)
|
82
82
|
def send_event(event, hint = nil)
|
83
83
|
client.send_event(event, hint)
|
@@ -114,6 +114,8 @@ module Raven
|
|
114
114
|
options = options.deep_dup
|
115
115
|
options[:configuration] = configuration
|
116
116
|
options[:context] = context
|
117
|
+
options[:breadcrumbs] = breadcrumbs
|
118
|
+
|
117
119
|
if evt = Event.send("from_" + message_or_exc, obj, options)
|
118
120
|
yield evt if block_given?
|
119
121
|
if configuration.async?
|
@@ -10,7 +10,11 @@ module RackTimeoutExtensions
|
|
10
10
|
# Only rack-timeout 0.3.0+ provides the request environment, but we can't
|
11
11
|
# gate this based on a gem version constant because rack-timeout does
|
12
12
|
# not provide one.
|
13
|
-
|
13
|
+
if defined?(env)
|
14
|
+
{ :fingerprint => ["{{ default }}", env["REQUEST_URI"]] }
|
15
|
+
else
|
16
|
+
{}
|
17
|
+
end
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
@@ -5,6 +5,7 @@ module Raven
|
|
5
5
|
require 'raven/integrations/rails/overrides/streaming_reporter'
|
6
6
|
require 'raven/integrations/rails/controller_methods'
|
7
7
|
require 'raven/integrations/rails/controller_transaction'
|
8
|
+
require 'raven/integrations/rails/backtrace_cleaner'
|
8
9
|
require 'raven/integrations/rack'
|
9
10
|
|
10
11
|
initializer "raven.use_rack_middleware" do |app|
|
@@ -37,12 +38,20 @@ module Raven
|
|
37
38
|
|
38
39
|
config.before_initialize do
|
39
40
|
Raven.configuration.logger = ::Rails.logger
|
41
|
+
|
42
|
+
backtrace_cleaner = Raven::Rails::BacktraceCleaner.new
|
43
|
+
|
44
|
+
Raven.configuration.backtrace_cleanup_callback = lambda do |backtrace|
|
45
|
+
backtrace_cleaner.clean(backtrace)
|
46
|
+
end
|
40
47
|
end
|
41
48
|
|
42
49
|
config.after_initialize do
|
43
|
-
if Raven.configuration.
|
44
|
-
|
45
|
-
|
50
|
+
if Raven.configuration.breadcrumbs_logger.include?(:active_support_logger) ||
|
51
|
+
Raven.configuration.rails_activesupport_breadcrumbs
|
52
|
+
|
53
|
+
require 'raven/breadcrumbs/active_support_logger'
|
54
|
+
Raven::Breadcrumbs::ActiveSupportLogger.inject
|
46
55
|
end
|
47
56
|
|
48
57
|
if Raven.configuration.rails_report_rescued_exceptions
|
@@ -21,7 +21,8 @@ module Raven
|
|
21
21
|
def capture_and_reraise_with_sentry(job, block)
|
22
22
|
block.call
|
23
23
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
24
|
-
|
24
|
+
rescue_handler_result = rescue_with_handler(e)
|
25
|
+
return rescue_handler_result if rescue_handler_result
|
25
26
|
|
26
27
|
Raven.capture_exception(e, :extra => raven_context(job))
|
27
28
|
raise e
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "active_support/backtrace_cleaner"
|
2
|
+
require "active_support/core_ext/string/access"
|
3
|
+
|
4
|
+
module Raven
|
5
|
+
class Rails
|
6
|
+
class BacktraceCleaner < ActiveSupport::BacktraceCleaner
|
7
|
+
APP_DIRS_PATTERN = /\A(?:\.\/)?(?:app|config|lib|test|\(\w*\))/.freeze
|
8
|
+
RENDER_TEMPLATE_PATTERN = /:in `.*_\w+_{2,3}\d+_\d+'/.freeze
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
super
|
12
|
+
# we don't want any default silencers because they're too aggressive
|
13
|
+
remove_silencers!
|
14
|
+
|
15
|
+
@root = "#{Raven.configuration.project_root}/"
|
16
|
+
add_filter do |line|
|
17
|
+
line.start_with?(@root) ? line.from(@root.size) : line
|
18
|
+
end
|
19
|
+
add_filter do |line|
|
20
|
+
if line =~ RENDER_TEMPLATE_PATTERN
|
21
|
+
line.sub(RENDER_TEMPLATE_PATTERN, "")
|
22
|
+
else
|
23
|
+
line
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,87 +1,13 @@
|
|
1
1
|
require 'time'
|
2
2
|
require 'sidekiq'
|
3
|
-
|
4
|
-
|
5
|
-
class SidekiqCleanupMiddleware
|
6
|
-
def call(_worker, job, queue)
|
7
|
-
Raven.context.transaction.push "Sidekiq/#{job['class']}"
|
8
|
-
Raven.extra_context(:sidekiq => job.merge("queue" => queue))
|
9
|
-
yield
|
10
|
-
Context.clear!
|
11
|
-
BreadcrumbBuffer.clear!
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class SidekiqErrorHandler
|
16
|
-
ACTIVEJOB_RESERVED_PREFIX = "_aj_".freeze
|
17
|
-
HAS_GLOBALID = const_defined?('GlobalID')
|
18
|
-
|
19
|
-
def call(ex, context)
|
20
|
-
context = filter_context(context)
|
21
|
-
Raven.context.transaction.push transaction_from_context(context)
|
22
|
-
Raven.capture_exception(
|
23
|
-
ex,
|
24
|
-
:message => ex.message,
|
25
|
-
:extra => { :sidekiq => context }
|
26
|
-
)
|
27
|
-
Context.clear!
|
28
|
-
BreadcrumbBuffer.clear!
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
# Once an ActiveJob is queued, ActiveRecord references get serialized into
|
34
|
-
# some internal reserved keys, such as _aj_globalid.
|
35
|
-
#
|
36
|
-
# The problem is, if this job in turn gets queued back into ActiveJob with
|
37
|
-
# these magic reserved keys, ActiveJob will throw up and error. We want to
|
38
|
-
# capture these and mutate the keys so we can sanely report it.
|
39
|
-
def filter_context(context)
|
40
|
-
case context
|
41
|
-
when Array
|
42
|
-
context.map { |arg| filter_context(arg) }
|
43
|
-
when Hash
|
44
|
-
Hash[context.map { |key, value| filter_context_hash(key, value) }]
|
45
|
-
else
|
46
|
-
format_globalid(context)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def filter_context_hash(key, value)
|
51
|
-
(key = key[3..-1]) if key [0..3] == ACTIVEJOB_RESERVED_PREFIX
|
52
|
-
[key, filter_context(value)]
|
53
|
-
end
|
54
|
-
|
55
|
-
# this will change in the future:
|
56
|
-
# https://github.com/mperham/sidekiq/pull/3161
|
57
|
-
def transaction_from_context(context)
|
58
|
-
classname = (context["wrapped"] || context["class"] ||
|
59
|
-
(context[:job] && (context[:job]["wrapped"] || context[:job]["class"]))
|
60
|
-
)
|
61
|
-
if classname
|
62
|
-
"Sidekiq/#{classname}"
|
63
|
-
elsif context[:event]
|
64
|
-
"Sidekiq/#{context[:event]}"
|
65
|
-
else
|
66
|
-
"Sidekiq"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def format_globalid(context)
|
71
|
-
if HAS_GLOBALID && context.is_a?(GlobalID)
|
72
|
-
context.to_s
|
73
|
-
else
|
74
|
-
context
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
3
|
+
require 'raven/integrations/sidekiq/cleanup_middleware'
|
4
|
+
require 'raven/integrations/sidekiq/error_handler'
|
79
5
|
|
80
6
|
if Sidekiq::VERSION > '3'
|
81
7
|
Sidekiq.configure_server do |config|
|
82
|
-
config.error_handlers << Raven::
|
8
|
+
config.error_handlers << Raven::Sidekiq::ErrorHandler.new
|
83
9
|
config.server_middleware do |chain|
|
84
|
-
chain.add Raven::
|
10
|
+
chain.add Raven::Sidekiq::CleanupMiddleware
|
85
11
|
end
|
86
12
|
end
|
87
13
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Raven
|
2
|
+
module Sidekiq
|
3
|
+
class CleanupMiddleware
|
4
|
+
def call(_worker, job, queue)
|
5
|
+
Raven.context.transaction.push "Sidekiq/#{job['class']}"
|
6
|
+
Raven.extra_context(:sidekiq => job.merge("queue" => queue))
|
7
|
+
yield
|
8
|
+
Context.clear!
|
9
|
+
BreadcrumbBuffer.clear!
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Raven
|
2
|
+
module Sidekiq
|
3
|
+
module ContextFilter
|
4
|
+
class << self
|
5
|
+
ACTIVEJOB_RESERVED_PREFIX = "_aj_".freeze
|
6
|
+
HAS_GLOBALID = const_defined?('GlobalID')
|
7
|
+
|
8
|
+
# Once an ActiveJob is queued, ActiveRecord references get serialized into
|
9
|
+
# some internal reserved keys, such as _aj_globalid.
|
10
|
+
#
|
11
|
+
# The problem is, if this job in turn gets queued back into ActiveJob with
|
12
|
+
# these magic reserved keys, ActiveJob will throw up and error. We want to
|
13
|
+
# capture these and mutate the keys so we can sanely report it.
|
14
|
+
def filter_context(context)
|
15
|
+
case context
|
16
|
+
when Array
|
17
|
+
context.map { |arg| filter_context(arg) }
|
18
|
+
when Hash
|
19
|
+
Hash[context.map { |key, value| filter_context_hash(key, value) }]
|
20
|
+
else
|
21
|
+
format_globalid(context)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def filter_context_hash(key, value)
|
28
|
+
(key = key[3..-1]) if key [0..3] == ACTIVEJOB_RESERVED_PREFIX
|
29
|
+
[key, filter_context(value)]
|
30
|
+
end
|
31
|
+
|
32
|
+
def format_globalid(context)
|
33
|
+
if HAS_GLOBALID && context.is_a?(GlobalID)
|
34
|
+
context.to_s
|
35
|
+
else
|
36
|
+
context
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'raven/integrations/sidekiq/context_filter'
|
2
|
+
|
3
|
+
module Raven
|
4
|
+
module Sidekiq
|
5
|
+
class ErrorHandler
|
6
|
+
SIDEKIQ_NAME = "Sidekiq".freeze
|
7
|
+
|
8
|
+
def call(ex, context)
|
9
|
+
context = ContextFilter.filter_context(context)
|
10
|
+
Raven.context.transaction.push transaction_from_context(context)
|
11
|
+
Raven.capture_exception(
|
12
|
+
ex,
|
13
|
+
:message => ex.message,
|
14
|
+
:extra => { :sidekiq => context }
|
15
|
+
)
|
16
|
+
Context.clear!
|
17
|
+
BreadcrumbBuffer.clear!
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# this will change in the future:
|
23
|
+
# https://github.com/mperham/sidekiq/pull/3161
|
24
|
+
def transaction_from_context(context)
|
25
|
+
classname = (context["wrapped"] || context["class"] ||
|
26
|
+
(context[:job] && (context[:job]["wrapped"] || context[:job]["class"]))
|
27
|
+
)
|
28
|
+
if classname
|
29
|
+
"#{SIDEKIQ_NAME}/#{classname}"
|
30
|
+
elsif context[:event]
|
31
|
+
"#{SIDEKIQ_NAME}/#{context[:event]}"
|
32
|
+
else
|
33
|
+
SIDEKIQ_NAME
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/raven/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
require 'raven/base'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentry-raven
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sentry Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -34,6 +34,8 @@ extra_rdoc_files:
|
|
34
34
|
- LICENSE
|
35
35
|
files:
|
36
36
|
- ".craft.yml"
|
37
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
38
|
+
- ".github/pull_request_template.md"
|
37
39
|
- ".github/workflows/test.yml"
|
38
40
|
- ".github/workflows/zeus_upload.yml"
|
39
41
|
- ".gitignore"
|
@@ -42,7 +44,7 @@ files:
|
|
42
44
|
- ".rubocop.yml"
|
43
45
|
- ".scripts/bump-version.sh"
|
44
46
|
- CHANGELOG.md
|
45
|
-
-
|
47
|
+
- CONTRIBUTING.md
|
46
48
|
- Gemfile
|
47
49
|
- LICENSE
|
48
50
|
- README.md
|
@@ -52,8 +54,9 @@ files:
|
|
52
54
|
- lib/raven/backtrace.rb
|
53
55
|
- lib/raven/base.rb
|
54
56
|
- lib/raven/breadcrumbs.rb
|
55
|
-
- lib/raven/breadcrumbs/
|
57
|
+
- lib/raven/breadcrumbs/active_support_logger.rb
|
56
58
|
- lib/raven/breadcrumbs/logger.rb
|
59
|
+
- lib/raven/breadcrumbs/sentry_logger.rb
|
57
60
|
- lib/raven/cli.rb
|
58
61
|
- lib/raven/client.rb
|
59
62
|
- lib/raven/configuration.rb
|
@@ -61,12 +64,14 @@ files:
|
|
61
64
|
- lib/raven/core_ext/object/deep_dup.rb
|
62
65
|
- lib/raven/core_ext/object/duplicable.rb
|
63
66
|
- lib/raven/event.rb
|
67
|
+
- lib/raven/helpers/deprecation_helper.rb
|
64
68
|
- lib/raven/instance.rb
|
65
69
|
- lib/raven/integrations/delayed_job.rb
|
66
70
|
- lib/raven/integrations/rack-timeout.rb
|
67
71
|
- lib/raven/integrations/rack.rb
|
68
72
|
- lib/raven/integrations/rails.rb
|
69
73
|
- lib/raven/integrations/rails/active_job.rb
|
74
|
+
- lib/raven/integrations/rails/backtrace_cleaner.rb
|
70
75
|
- lib/raven/integrations/rails/controller_methods.rb
|
71
76
|
- lib/raven/integrations/rails/controller_transaction.rb
|
72
77
|
- lib/raven/integrations/rails/overrides/debug_exceptions_catcher.rb
|
@@ -74,6 +79,9 @@ files:
|
|
74
79
|
- lib/raven/integrations/railties.rb
|
75
80
|
- lib/raven/integrations/rake.rb
|
76
81
|
- lib/raven/integrations/sidekiq.rb
|
82
|
+
- lib/raven/integrations/sidekiq/cleanup_middleware.rb
|
83
|
+
- lib/raven/integrations/sidekiq/context_filter.rb
|
84
|
+
- lib/raven/integrations/sidekiq/error_handler.rb
|
77
85
|
- lib/raven/integrations/tasks.rb
|
78
86
|
- lib/raven/interface.rb
|
79
87
|
- lib/raven/interfaces/exception.rb
|
@@ -101,6 +109,7 @@ files:
|
|
101
109
|
- lib/raven/version.rb
|
102
110
|
- lib/sentry-raven-without-integrations.rb
|
103
111
|
- lib/sentry-raven.rb
|
112
|
+
- lib/sentry_raven_without_integrations.rb
|
104
113
|
- sentry-raven.gemspec
|
105
114
|
homepage: https://github.com/getsentry/raven-ruby
|
106
115
|
licenses:
|
data/CONTRIUTING.md
DELETED
@@ -1,26 +0,0 @@
|
|
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
|
-
# Contributing
|
9
|
-
|
10
|
-
We welcome suggested improvements and bug fixes in the form of pull requests. The guide below will help you get started, but if you have further questions, please feel free to reach out on [Discord](https://discord.gg/Ww9hbqr).
|
11
|
-
|
12
|
-
|
13
|
-
## Making a release
|
14
|
-
|
15
|
-
Install and use `craft`: https://github.com/getsentry/craft
|
16
|
-
|
17
|
-
Make sure the `CHANGELOG.md` is update and latest `master` contains all changes.
|
18
|
-
|
19
|
-
Run:
|
20
|
-
|
21
|
-
```bash
|
22
|
-
craft prepare x.x.x
|
23
|
-
```
|
24
|
-
|
25
|
-
Where `x.x.x` stands for the version you want to release.
|
26
|
-
Afterwards reach out to an employee of Sentry, they will cut a release by running the `publish` process of `craft`.
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Raven
|
2
|
-
module ActiveSupportBreadcrumbs
|
3
|
-
class << self
|
4
|
-
def add(name, started, _finished, _unique_id, data)
|
5
|
-
Raven.breadcrumbs.record do |crumb|
|
6
|
-
crumb.data = data
|
7
|
-
crumb.category = name
|
8
|
-
crumb.timestamp = started.to_i
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def inject
|
13
|
-
ActiveSupport::Notifications.subscribe(/.*/) do |name, started, finished, unique_id, data|
|
14
|
-
add(name, started, finished, unique_id, data)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|