sentry-raven 3.0.0 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.craft.yml +19 -0
  3. data/.scripts/bump-version.rb +5 -0
  4. data/{changelog.md → CHANGELOG.md} +174 -1
  5. data/Gemfile +24 -25
  6. data/Makefile +3 -0
  7. data/README.md +44 -16
  8. data/lib/raven/backtrace.rb +9 -5
  9. data/lib/raven/base.rb +7 -2
  10. data/lib/raven/breadcrumbs.rb +1 -1
  11. data/lib/raven/breadcrumbs/{activesupport.rb → active_support_logger.rb} +9 -3
  12. data/lib/raven/breadcrumbs/logger.rb +2 -92
  13. data/lib/raven/breadcrumbs/sentry_logger.rb +73 -0
  14. data/lib/raven/cli.rb +10 -21
  15. data/lib/raven/client.rb +9 -4
  16. data/lib/raven/configuration.rb +95 -10
  17. data/lib/raven/context.rb +13 -8
  18. data/lib/raven/core_ext/object/deep_dup.rb +57 -0
  19. data/lib/raven/core_ext/object/duplicable.rb +153 -0
  20. data/lib/raven/event.rb +31 -15
  21. data/lib/raven/helpers/deprecation_helper.rb +17 -0
  22. data/lib/raven/instance.rb +21 -5
  23. data/lib/raven/integrations/delayed_job.rb +15 -15
  24. data/lib/raven/integrations/rack-timeout.rb +7 -4
  25. data/lib/raven/integrations/rack.rb +8 -6
  26. data/lib/raven/integrations/rails.rb +13 -3
  27. data/lib/raven/integrations/rails/active_job.rb +6 -4
  28. data/lib/raven/integrations/rails/backtrace_cleaner.rb +29 -0
  29. data/lib/raven/integrations/rails/overrides/debug_exceptions_catcher.rb +2 -2
  30. data/lib/raven/integrations/sidekiq.rb +4 -78
  31. data/lib/raven/integrations/sidekiq/cleanup_middleware.rb +13 -0
  32. data/lib/raven/integrations/sidekiq/error_handler.rb +38 -0
  33. data/lib/raven/interface.rb +2 -2
  34. data/lib/raven/interfaces/stack_trace.rb +1 -1
  35. data/lib/raven/linecache.rb +5 -2
  36. data/lib/raven/logger.rb +3 -2
  37. data/lib/raven/processor/cookies.rb +16 -6
  38. data/lib/raven/processor/post_data.rb +2 -0
  39. data/lib/raven/processor/removecircularreferences.rb +3 -1
  40. data/lib/raven/processor/sanitizedata.rb +65 -17
  41. data/lib/raven/processor/utf8conversion.rb +2 -0
  42. data/lib/raven/transports.rb +4 -0
  43. data/lib/raven/transports/http.rb +7 -8
  44. data/lib/raven/utils/context_filter.rb +42 -0
  45. data/lib/raven/utils/exception_cause_chain.rb +1 -0
  46. data/lib/raven/utils/real_ip.rb +1 -1
  47. data/lib/raven/utils/request_id.rb +16 -0
  48. data/lib/raven/version.rb +2 -2
  49. data/lib/sentry-raven-without-integrations.rb +6 -1
  50. data/lib/sentry_raven_without_integrations.rb +1 -0
  51. data/sentry-raven.gemspec +7 -0
  52. metadata +22 -10
  53. data/.gitignore +0 -13
  54. data/.gitmodules +0 -0
  55. data/.rspec +0 -1
  56. data/.rubocop.yml +0 -74
  57. data/.travis.yml +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c812e5ab292c9f9351064bfc75f13bf3f6fff8ea1163a79a0e7da2e5efa9afb
4
- data.tar.gz: 2fb7356fa0b26ee6f8a09a8ab023a21dcee132aa75fd3d1d87fd5f528a1c3366
3
+ metadata.gz: 8c836de333d5f6013b562a5d189b6e775ca61965c7070a111b61d37402d318d1
4
+ data.tar.gz: b1923aeea7733a7e0d51fdc6e2f49b7dd046b5eaaba1067507229d0cc5262352
5
5
  SHA512:
6
- metadata.gz: b406e28322db6c9e96db35d108521f617c484cdef0367a6ea246709356d61b5917795289c3caf1cc7324f3228fba349a8b3f9a2b45aeaef0d01872848540db2a
7
- data.tar.gz: f079139a9cf52c7344d28d55eec1fc108c237c76c23df7880122e66851d858bce86da817887d5a83f35c9732c619328178bfdd6f8cb6742c84024f0445710fed
6
+ metadata.gz: 7ae04b49b38a134386b44e04675f47bbf9742ba1b39f84ac0c51a87b3852380c1b60d91a7a7c67e208a9415c75880559941ac343cb3378a8129259b4aeb63984
7
+ data.tar.gz: 0fd029cf50d3a54f98906cee4f1c4177282f91030239f093d53e3949bc37a533fd4557f6f932e5c22051416e92ff28a53da7fbc2a9086c83181538f8c81d6c83
data/.craft.yml ADDED
@@ -0,0 +1,19 @@
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-raven
8
+ statusProvider:
9
+ name: github
10
+ artifactProvider:
11
+ name: github
12
+ targets:
13
+ - name: gem
14
+ - name: github
15
+ tagPrefix: sentry-raven-v
16
+ - name: registry
17
+ type: sdk
18
+ config:
19
+ canonical: 'gem:sentry-raven'
@@ -0,0 +1,5 @@
1
+ file_name = "lib/raven/version.rb"
2
+
3
+ text = File.read(file_name)
4
+ new_contents = text.gsub(/VERSION = ".*"/, "VERSION = \"#{ARGV[1]}\"")
5
+ File.open(file_name, "w") {|file| file.puts new_contents }
@@ -1,3 +1,176 @@
1
+ # Changelog
2
+
3
+ ## 3.1.2
4
+
5
+ - Fix Delayed::Plugins::Raven when job raises exception [#1057](https://github.com/getsentry/sentry-ruby/pull/1057)
6
+ - Merge hash instead of replacing the original value in user_context [#1064](https://github.com/getsentry/sentry-ruby/pull/1064)
7
+ - Don't exclude ActionView::MissingTemplate error by default [#1092](https://github.com/getsentry/sentry-ruby/pull/1092)
8
+ - Fix typo: much -> must for Raven::Event [#1106](https://github.com/getsentry/sentry-ruby/pull/1106)
9
+ - Fix undefined local variable or method logger [#1143](https://github.com/getsentry/sentry-ruby/pull/1143)
10
+ - Fixes [#1110](https://github.com/getsentry/sentry-ruby/issues/1110)
11
+ - fix format headers for sentry-raven [#1198](https://github.com/getsentry/sentry-ruby/pull/1198)
12
+ - Print deprecation message after sentry-raven is installed [#1206](https://github.com/getsentry/sentry-ruby/pull/1206)
13
+
14
+ ## 3.1.1
15
+
16
+ **Feature**
17
+
18
+ - Add request id to headers if exists ([#1033](https://github.com/getsentry/sentry-ruby/pull/1033))
19
+
20
+ - Allow blocks on user_context ([#1023](https://github.com/getsentry/sentry-ruby/pull/1023))
21
+
22
+ - Enable configurable rack environment recorded parameters ([#860](https://github.com/getsentry/sentry-ruby/pull/860))
23
+
24
+ - Remove ActiveJob keys for both Sidekiq and DelayedJob ([#898](https://github.com/getsentry/sentry-ruby/pull/898))
25
+
26
+ **Fix**
27
+
28
+ - Remove circular dependency in transport/http.rb ([#1035](https://github.com/getsentry/sentry-ruby/pull/1035))
29
+
30
+ ## 3.1.0
31
+
32
+ **Feature**
33
+
34
+ - Exclude all 4xx Rails errors ([#1004](https://github.com/getsentry/raven-ruby/pull/1004))
35
+
36
+ See the full list [here](https://github.com/getsentry/raven-ruby/blob/master/lib/raven/configuration.rb#L198-L219)
37
+
38
+ - Add some error context in `transport_failure_callback` ([#1003](https://github.com/getsentry/raven-ruby/pull/1003))
39
+
40
+ Before:
41
+
42
+ ```ruby
43
+ config.transport_failure_callback = lambda { |event|
44
+ AdminMailer.email_admins("Oh god, it's on fire!", event).deliver_later
45
+ }
46
+ ```
47
+
48
+ After:
49
+
50
+ ```ruby
51
+ config.transport_failure_callback = lambda { |event, error|
52
+ AdminMailer.email_admins("Oh god, it's on fire because #{error.message}!", event).deliver_later
53
+ }
54
+ ```
55
+
56
+ - Support cleaning up exception backtrace with customized backtrace_cleaner ([#1011](https://github.com/getsentry/raven-ruby/pull/1011))
57
+
58
+ The new config `backtrace_cleanup_callback` takes a lambda/proc object (default is `nil`) and will be called with exception's backtrace
59
+
60
+ ```ruby
61
+ Raven.configure do |config|
62
+ config.backtrace_cleanup_callback = lambda do |backtrace|
63
+ Rails.backtrace_cleaner.clean(backtrace)
64
+ end
65
+ end
66
+ ```
67
+
68
+ 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.
69
+
70
+ The main reason to add this cleaner is to remove template methods from the trace, e.g.
71
+
72
+ ```
73
+ app/views/welcome/view_error.html.erb in _app_views_welcome_view_error_html_erb__2807287320172182514_65600 at line 1
74
+ ```
75
+
76
+ will become
77
+
78
+ ```
79
+ app/views/welcome/view_error.html.erb at line 1
80
+ ```
81
+
82
+ This can help Sentry group issues more accurately. See [#957](https://github.com/getsentry/raven-ruby/issues/957) for more information about this.
83
+
84
+ If you don't want this change, you can disable it with:
85
+
86
+ ```ruby
87
+ Raven.configure do |config|
88
+ config.backtrace_cleanup_callback = nil
89
+ end
90
+ ```
91
+
92
+
93
+ - Make dsn value accessable from config ([#1012](https://github.com/getsentry/raven-ruby/pull/1012))
94
+
95
+ You can now access the dsn value via `Raven.configuration.dsn`
96
+
97
+ **Deprecation**
98
+
99
+ - Deprecate dasherized filenames ([#1006](https://github.com/getsentry/raven-ruby/pull/1006))
100
+
101
+ If you're using
102
+
103
+ ```ruby
104
+ gem 'sentry-raven', require: 'sentry-raven-without-integrations'
105
+ # or
106
+ require "sentry-raven-without-integrations"
107
+ ```
108
+
109
+ you will start seeing deprecation warnings. Please change them into
110
+
111
+ ```ruby
112
+ gem 'sentry-raven', require: 'sentry_raven_without_integrations'
113
+ # or
114
+ require "sentry_raven_without_integrations"
115
+ ```
116
+
117
+ - Unify breadcrumb loggers activation ([#1016](https://github.com/getsentry/raven-ruby/pull/1016))
118
+
119
+ Currently, we activate our breadcrumb loggers differently:
120
+
121
+ ```ruby
122
+ require "raven/breadcrumbs/sentry_logger"
123
+ Raven.configuration.rails_activesupport_breadcrumbs = true
124
+ ```
125
+
126
+ It's not a nice user interface, so this PR adds a new configuration
127
+ option `breadcrumbs_logger` to improve this:
128
+
129
+ ```ruby
130
+ Raven.configuration.breadcrumbs_logger = :sentry_logger
131
+ Raven.configuration.breadcrumbs_logger = :active_support_logger
132
+ Raven.configuration.breadcrumbs_logger = [:sentry_logger, :active_support_logger]
133
+ ```
134
+
135
+ Please migrate to the new activation apporach, otherwise you'll see depraction warnings. And old ones will be dropped in version 4.0.
136
+
137
+ **Refactor**
138
+
139
+ - Accept non-string message in Event.from_exception ([#1005](https://github.com/getsentry/raven-ruby/pull/1005))
140
+ - Refactor event initialization ([#1010](https://github.com/getsentry/raven-ruby/pull/1010))
141
+ - Refactor sidekiq integration ([#1019](https://github.com/getsentry/raven-ruby/pull/1019))
142
+
143
+ **Fix**
144
+
145
+ - Replace sys_command usages in context.rb ([#1017](https://github.com/getsentry/raven-ruby/pull/1017))
146
+ - Fix merge error from rack-timeout raven_context on old releases ([#1007](https://github.com/getsentry/raven-ruby/pull/1007))
147
+ - Return value of `rescue_with_handler` when intercepting ActiveJob exceptions ([#1027](https://github.com/getsentry/raven-ruby/pull/1027))
148
+
149
+ ## 3.0.4
150
+
151
+ - fix: Don't log warning messages when it doesn't need to (#1000)
152
+ - fix: Revert "Refactor Raven::Client class" (#1002)
153
+
154
+ ## 3.0.3
155
+
156
+ - fix: Ensure Processor::Cookie can run after Processor::RemoveCircularReferences (#996)
157
+ - fix: Avoid mutating user passed in options (#994)
158
+ - fix: Fix/Refactor Raven::Cli (#989)
159
+ - ref: Refactor Raven::Client class (#995)
160
+ - It adds `Event#message_from_exception` and `Event#log_message` interfaces
161
+
162
+ ## 3.0.2
163
+
164
+ - fix: Add gem target for craft
165
+
166
+ ## 3.0.1
167
+
168
+ - fix: Improve SanitizeData processor (#984)
169
+ - fix: Masking cookies as key/pair instead of a single string (#983)
170
+ - fix: Transports classes' requiring issue (#986)
171
+ - fix: Frozen string issues (#977)
172
+ - feat: Officially support Rails 6 (#982)
173
+
1
174
  3.0.0
2
175
  ----
3
176
 
@@ -483,7 +656,7 @@ OTHER CHANGES:
483
656
  0.12.0
484
657
  ------
485
658
 
486
- - You can now give additional fields to the SanitizeData processor. Values matched are replaced by the string mask (*********). Full documentation (and how to use with Rails config.filter_parameters) [here](https://docs.getsentry.com/hosted/clients/ruby/config/). [jamescway, #232]
659
+ - You can now give additional fields to the SanitizeData processor. Values matched are replaced by the string mask (*********). Full documentation (and how to use with Rails config.filter_parameters) [here](https://docs.sentry.io/platforms/ruby/config/). [jamescway, #232]
487
660
  - An additional processor has been added, though it isn't turned on by default: RemoveStacktrace. Use it to remove stacktraces from exception reports. [nateberkopec, #233]
488
661
  - Dependency on `uuidtools` has been removed. [nateberkopec, #231]
489
662
 
data/Gemfile CHANGED
@@ -2,37 +2,36 @@ source "https://rubygems.org/"
2
2
 
3
3
  gemspec
4
4
 
5
- if ENV["RAILS_VERSION"] && (ENV["RAILS_VERSION"].to_i == 4)
6
- gem "rails", "< 5"
7
- gem "rspec-rails", "> 3"
8
- elsif ENV["RAILS_VERSION"] && (ENV["RAILS_VERSION"].to_i == 0)
9
- # no-op. No Rails.
10
- else
11
- gem "rails", "< 6"
12
- gem "rspec-rails", "> 3"
13
- end
5
+ rails_version = ENV["RAILS_VERSION"]
6
+ rails_version = "5.2" if rails_version.nil?
14
7
 
15
- if RUBY_VERSION < '2.0'
16
- gem "mime-types", "< 3.0.0"
17
- gem "nokogiri", "~> 1.6.8"
18
- gem "rack", "~> 1.6.8"
19
- gem "sidekiq", "< 3.2"
20
- gem "rack-timeout", "0.3.0"
21
- else
22
- gem "rack"
23
- gem "sidekiq"
24
- gem "rack-timeout"
8
+ if rails_version.to_f != 0
9
+ gem "rails", "~> #{rails_version}"
10
+ gem "rspec-rails", "~> 4.0"
25
11
  end
12
+
13
+ gem "delayed_job"
14
+ gem "sidekiq"
15
+
16
+ gem "rack"
17
+ gem "rack-timeout"
18
+
19
+ # TODO: Remove this if https://github.com/jruby/jruby/issues/6547 is addressed
20
+ gem "i18n", "<= 1.8.7"
21
+
26
22
  gem "pry"
27
- gem "pry-coolline"
28
23
  gem "benchmark-ips"
29
- gem "benchmark-ipsa" if RUBY_VERSION > '2.0'
24
+ gem "benchmark_driver"
25
+ gem "benchmark-ipsa"
26
+ gem "benchmark-memory"
30
27
  gem "ruby-prof", platform: :mri
31
28
  gem "rake", "> 12"
32
- gem "rubocop", "~> 0.41.1" # Last version that supported 1.9, upgrade to 0.50 after we drop 1.9
33
- gem "rspec", "> 3"
34
- gem "capybara" # rspec system tests
29
+ gem "rubocop", "~> 0.81.0"
30
+ gem "rspec", "~> 3.9.0"
31
+ gem "capybara", "~> 3.15.0" # rspec system tests
35
32
  gem "puma" # rspec system tests
36
33
 
37
34
  gem "timecop"
38
- gem "test-unit", platform: :mri if RUBY_VERSION > '2.2'
35
+ gem "test-unit"
36
+ gem "simplecov"
37
+ gem "codecov", "<= 0.2.12"
data/Makefile ADDED
@@ -0,0 +1,3 @@
1
+ build:
2
+ bundle install
3
+ gem build sentry-raven.gemspec
data/README.md CHANGED
@@ -7,8 +7,26 @@
7
7
 
8
8
  # Raven-Ruby, the Ruby Client for Sentry
9
9
 
10
+ ### 🚧 Migrating To The New SDK 🚧
11
+
12
+ We've released our new Ruby SDK, [sentry-ruby](https://github.com/getsentry/sentry-ruby/tree/master/sentry-ruby). Here are the benefits of migrating to it:
13
+
14
+ - **Unified Interfaces With Other SDKs:** The design of `sentry-raven` is outdated compared with our modern Sentry SDKs. If you also use other Sentry SDKs, such as Sentry's JavaScript SDK for your frontend application, you'll notice that their interfaces are quite different from the one provided for `sentry-raven`. The new `sentry-ruby` SDK provides a more consistent user experience across all different platforms.
15
+
16
+ - **Performance Monitoring:** The Sentry Ruby SDK includes [performance monitoring](https://docs.sentry.io/product/performance/), which you can enable if you haven't already as ([discussed here](https://docs.sentry.io/platforms/ruby/performance/)).
17
+
18
+ - **Future Support:** `sentry-raven` has entered maintenance mode, which means it won't receive any new feature supports or aggressive bug fixes.
19
+
20
+ - **Better Extensibility:** Unlike `sentry-raven`, `sentry-ruby` is built with extensibility in mind and will allow the community to build extensions for different integrations/features.
21
+
22
+ If you're interested in the migration, please also read our [migration guide](https://docs.sentry.io/platforms/ruby/migration/) for more information.
23
+
24
+ ---
25
+
26
+
10
27
  [![Gem Version](https://img.shields.io/gem/v/sentry-raven.svg)](https://rubygems.org/gems/sentry-raven)
11
- [![Build Status](https://img.shields.io/travis/getsentry/raven-ruby/master.svg)](https://travis-ci.org/getsentry/raven-ruby)
28
+ ![Build Status](https://github.com/getsentry/raven-ruby/workflows/Test/badge.svg)
29
+ [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master)
12
30
  [![Gem](https://img.shields.io/gem/dt/sentry-raven.svg)](https://rubygems.org/gems/sentry-raven/)
13
31
  [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=sentry-raven&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sentry-raven&package-manager=bundler&version-scheme=semver)
14
32
 
@@ -17,9 +35,10 @@
17
35
 
18
36
  The official Ruby-language client and integration layer for the [Sentry](https://github.com/getsentry/sentry) error reporting API.
19
37
 
38
+
20
39
  ## Requirements
21
40
 
22
- We test on Ruby 2.3, 2.4, 2.5, 2.6 and 2.7 at the latest patchlevel/teeny version. We also support JRuby 9.0. Our Rails integration works with Rails 4.2+ (including Rails 5).
41
+ We test on Ruby 2.3, 2.4, 2.5, 2.6 and 2.7 at the latest patchlevel/teeny version. We also support JRuby 9.0. Our Rails integration works with Rails 4.2+, including Rails 5 and Rails 6.
23
42
 
24
43
  ## Getting Started
25
44
 
@@ -29,7 +48,7 @@ We test on Ruby 2.3, 2.4, 2.5, 2.6 and 2.7 at the latest patchlevel/teeny versio
29
48
  gem "sentry-raven"
30
49
  ```
31
50
 
32
- ### Raven only runs when SENTRY_DSN is set
51
+ ### Raven only runs when Sentry DSN is set
33
52
 
34
53
  Raven 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!
35
54
 
@@ -38,7 +57,7 @@ Raven will capture and send exceptions to the Sentry server whenever its DSN is
38
57
  export SENTRY_DSN=http://public@example.com/project-id
39
58
  ```
40
59
  ```ruby
41
- # Or you can configure the client in the code (not recommended - keep your DSN secret!)
60
+ # Or you can configure the client in the code.
42
61
  Raven.configure do |config|
43
62
  config.dsn = 'http://public@example.com/project-id'
44
63
  end
@@ -48,11 +67,11 @@ end
48
67
 
49
68
  **Raven ignores some exceptions by default** - most of these are related to 404s or controller actions not being found. [For a complete list, see the `IGNORE_DEFAULT` constant](https://github.com/getsentry/raven-ruby/blob/master/lib/raven/configuration.rb).
50
69
 
51
- Raven doesn't report POST data or cookies by default. In addition, it will attempt to remove any obviously sensitive data, such as credit card or Social Security numbers. For more information about how Sentry processes your data, [check out the documentation on the `processors` config setting.](https://docs.getsentry.com/hosted/clients/ruby/config/)
70
+ Raven doesn't report POST data or cookies by default. In addition, it will attempt to remove any obviously sensitive data, such as credit card or Social Security numbers. For more information about how Sentry processes your data, [check out the documentation on the `processors` config setting.](https://docs.sentry.io/platforms/ruby/configuration/options/)
52
71
 
53
72
  ### Usage
54
73
 
55
- **If you use Rails, you're already done - no more configuration required!** Check [Integrations](https://docs.getsentry.com/hosted/clients/ruby/integrations/) for more details on other gems Sentry integrates with automatically.
74
+ **If you use Rails, you're already done - no more configuration required!** Check [Integrations](https://docs.sentry.io/platforms/ruby/configuration/integrations/) for more details on other gems Sentry integrates with automatically.
56
75
 
57
76
  Otherwise, Raven supports two methods of capturing exceptions:
58
77
 
@@ -104,29 +123,38 @@ end
104
123
  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.
105
124
 
106
125
  ```ruby
107
- config.transport_failure_callback = lambda { |event|
108
- AdminMailer.email_admins("Oh god, it's on fire!", event).deliver_later
126
+ config.transport_failure_callback = lambda { |event, error|
127
+ AdminMailer.email_admins("Oh god, it's on fire because #{error.message}!", event).deliver_later
109
128
  }
110
129
  ```
111
130
 
112
131
  #### Context
113
132
 
114
- Much of the usefulness of Sentry comes from additional context data with the events. Raven makes this very convenient by providing methods to set thread local context data that is then submitted automatically with all events.
115
-
116
- There are three primary methods for providing request context:
133
+ Much of the usefulness of Sentry comes from additional context data with the events. Raven makes this very convenient by providing methods to set thread local context data that is then submitted automatically with all events:
117
134
 
118
135
  ```ruby
119
- # bind the logged in user
120
136
  Raven.user_context email: 'foo@example.com'
121
137
 
122
- # tag the request with something interesting
123
138
  Raven.tags_context interesting: 'yes'
124
139
 
125
- # provide a bit of additional context
126
- Raven.extra_context happiness: 'very'
140
+ Raven.extra_context additional_info: 'foo'
141
+ ```
142
+
143
+ You can also use `tags_context` and `extra_context` to provide scoped information:
144
+
145
+ ```ruby
146
+ Raven.tags_context(interesting: 'yes') do
147
+ # the `interesting: 'yes'` tag will only present in the requests sent inside the block
148
+ Raven.capture_exception(exception)
149
+ end
150
+
151
+ Raven.extra_context(additional_info: 'foo') do
152
+ # same as above, the `additional_info` will only present in this request
153
+ Raven.capture_exception(exception)
154
+ end
127
155
  ```
128
156
 
129
- For more information, see [Context](https://docs.sentry.io/clients/ruby/context/).
157
+ For more information, see [Context](https://docs.sentry.io/platforms/ruby/enriching-events/context/).
130
158
 
131
159
  ## More Information
132
160
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ## Inspired by Rails' and Airbrake's backtrace parsers.
2
4
 
3
5
  module Raven
@@ -5,16 +7,16 @@ module Raven
5
7
  class Backtrace
6
8
  # Handles backtrace parsing line by line
7
9
  class Line
8
- RB_EXTENSION = ".rb".freeze
10
+ RB_EXTENSION = ".rb"
9
11
  # regexp (optional leading X: on windows, or JRuby9000 class-prefix)
10
12
  RUBY_INPUT_FORMAT = /
11
13
  ^ \s* (?: [a-zA-Z]: | uri:classloader: )? ([^:]+ | <.*>):
12
14
  (\d+)
13
15
  (?: :in \s `([^']+)')?$
14
- /x
16
+ /x.freeze
15
17
 
16
18
  # org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
17
- JAVA_INPUT_FORMAT = /^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)$/
19
+ JAVA_INPUT_FORMAT = /^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)$/.freeze
18
20
 
19
21
  # The file portion of the line (such as app/models/user.rb)
20
22
  attr_reader :file
@@ -74,7 +76,7 @@ module Raven
74
76
 
75
77
  def self.in_app_pattern
76
78
  @in_app_pattern ||= begin
77
- project_root = Raven.configuration.project_root && Raven.configuration.project_root.to_s
79
+ project_root = Raven.configuration.project_root&.to_s
78
80
  Regexp.new("^(#{project_root}/)?#{Raven.configuration.app_dirs_pattern || APP_DIRS_PATTERN}")
79
81
  end
80
82
  end
@@ -84,7 +86,7 @@ module Raven
84
86
  attr_writer :file, :number, :method, :module_name
85
87
  end
86
88
 
87
- APP_DIRS_PATTERN = /(bin|exe|app|config|lib|test)/
89
+ APP_DIRS_PATTERN = /(bin|exe|app|config|lib|test)/.freeze
88
90
 
89
91
  # holder for an Array of Backtrace::Line instances
90
92
  attr_reader :lines
@@ -92,6 +94,8 @@ module Raven
92
94
  def self.parse(backtrace, opts = {})
93
95
  ruby_lines = backtrace.is_a?(Array) ? backtrace : backtrace.split(/\n\s*/)
94
96
 
97
+ ruby_lines = opts[:configuration].backtrace_cleanup_callback.call(ruby_lines) if opts[:configuration]&.backtrace_cleanup_callback
98
+
95
99
  filters = opts[:filters] || []
96
100
  filtered_lines = ruby_lines.to_a.map do |line|
97
101
  filters.reduce(line) do |nested_line, proc|