raygun4ruby 3.2.6 → 4.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +48 -0
- data/.gitignore +22 -21
- data/.rspec +1 -1
- data/Appraisals +19 -0
- data/CHANGELOG.md +169 -133
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +424 -420
- data/Rakefile +32 -27
- data/examples/sinatras_raygun.rb +17 -17
- data/gemfiles/rails_6.gemfile +9 -0
- data/gemfiles/rails_7.gemfile +10 -0
- data/gemfiles/rails_7_sidekiq_6.gemfile +10 -0
- data/lib/generators/raygun/install_generator.rb +26 -26
- data/lib/raygun/affected_user.rb +59 -59
- data/lib/raygun/breadcrumbs/breadcrumb.rb +34 -34
- data/lib/raygun/breadcrumbs/store.rb +86 -86
- data/lib/raygun/breadcrumbs.rb +34 -34
- data/lib/raygun/client.rb +313 -308
- data/lib/raygun/configuration.rb +197 -194
- data/lib/raygun/demo_exception.rb +22 -22
- data/lib/raygun/error.rb +10 -10
- data/lib/raygun/error_subscriber.rb +21 -0
- data/lib/raygun/javascript_tracker.rb +42 -42
- data/lib/raygun/middleware/breadcrumbs_store_initializer.rb +19 -19
- data/lib/raygun/middleware/javascript_exception_tracking.rb +40 -32
- data/lib/raygun/middleware/rack_exception_interceptor.rb +18 -18
- data/lib/raygun/middleware/rails_insert_affected_user.rb +26 -26
- data/lib/raygun/railtie.rb +47 -39
- data/lib/raygun/services/apply_whitelist_filter_to_payload.rb +27 -27
- data/lib/raygun/sidekiq.rb +51 -71
- data/lib/raygun/version.rb +3 -3
- data/lib/raygun.rb +197 -179
- data/lib/raygun4ruby.rb +1 -1
- data/lib/resque/failure/raygun.rb +25 -25
- data/lib/tasks/raygun.tasks +7 -7
- data/raygun4ruby.gemspec +43 -45
- data/spec/features/javascript_spec.rb +48 -48
- data/spec/rails_applications/6.1.4/Gemfile +56 -0
- data/spec/{dummy/README.rdoc → rails_applications/6.1.4/README.md} +24 -28
- data/spec/{dummy → rails_applications/6.1.4}/Rakefile +6 -6
- data/spec/rails_applications/6.1.4/app/assets/config/manifest.js +2 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/assets/images/.keep +0 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/assets/stylesheets/application.css +15 -15
- data/spec/rails_applications/6.1.4/app/channels/application_cable/channel.rb +4 -0
- data/spec/rails_applications/6.1.4/app/channels/application_cable/connection.rb +4 -0
- data/spec/rails_applications/6.1.4/app/controllers/application_controller.rb +2 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/controllers/concerns/.keep +0 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/controllers/home_controller.rb +4 -4
- data/spec/{dummy → rails_applications/6.1.4}/app/helpers/application_helper.rb +2 -2
- data/spec/rails_applications/6.1.4/app/javascript/channels/consumer.js +6 -0
- data/spec/rails_applications/6.1.4/app/javascript/channels/index.js +5 -0
- data/spec/rails_applications/6.1.4/app/javascript/packs/application.js +13 -0
- data/spec/rails_applications/6.1.4/app/jobs/application_job.rb +7 -0
- data/spec/rails_applications/6.1.4/app/mailers/application_mailer.rb +4 -0
- data/spec/rails_applications/6.1.4/app/models/application_record.rb +3 -0
- data/spec/{dummy/app/mailers → rails_applications/6.1.4/app/models/concerns}/.keep +0 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/views/home/index.html.erb +3 -3
- data/spec/{dummy → rails_applications/6.1.4}/app/views/home/index.json.erb +1 -1
- data/spec/rails_applications/6.1.4/app/views/layouts/application.html.erb +13 -0
- data/spec/rails_applications/6.1.4/app/views/layouts/mailer.html.erb +13 -0
- data/spec/rails_applications/6.1.4/app/views/layouts/mailer.text.erb +1 -0
- data/spec/rails_applications/6.1.4/bin/rails +5 -0
- data/spec/rails_applications/6.1.4/bin/rake +5 -0
- data/spec/rails_applications/6.1.4/bin/setup +36 -0
- data/spec/rails_applications/6.1.4/bin/spring +14 -0
- data/spec/rails_applications/6.1.4/bin/yarn +17 -0
- data/spec/rails_applications/6.1.4/config/application.rb +22 -0
- data/spec/rails_applications/6.1.4/config/boot.rb +3 -0
- data/spec/rails_applications/6.1.4/config/cable.yml +10 -0
- data/spec/rails_applications/6.1.4/config/credentials.yml.enc +1 -0
- data/spec/{dummy → rails_applications/6.1.4}/config/database.yml +25 -25
- data/spec/{dummy → rails_applications/6.1.4}/config/environment.rb +5 -5
- data/spec/rails_applications/6.1.4/config/environments/development.rb +76 -0
- data/spec/rails_applications/6.1.4/config/environments/production.rb +120 -0
- data/spec/rails_applications/6.1.4/config/environments/test.rb +60 -0
- data/spec/rails_applications/6.1.4/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/rails_applications/6.1.4/config/initializers/assets.rb +14 -0
- data/spec/rails_applications/6.1.4/config/initializers/backtrace_silencers.rb +8 -0
- data/spec/rails_applications/6.1.4/config/initializers/content_security_policy.rb +30 -0
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/cookies_serializer.rb +5 -3
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/filter_parameter_logging.rb +6 -4
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/inflections.rb +16 -16
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/mime_types.rb +4 -4
- data/spec/rails_applications/6.1.4/config/initializers/permissions_policy.rb +11 -0
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/wrap_parameters.rb +14 -14
- data/spec/{dummy → rails_applications/6.1.4}/config/locales/en.yml +33 -23
- data/spec/rails_applications/6.1.4/config/master.key +1 -0
- data/spec/rails_applications/6.1.4/config/puma.rb +43 -0
- data/spec/rails_applications/6.1.4/config/routes.rb +4 -0
- data/spec/rails_applications/6.1.4/config/spring.rb +6 -0
- data/spec/rails_applications/6.1.4/config/storage.yml +34 -0
- data/spec/{dummy → rails_applications/6.1.4}/config.ru +6 -4
- data/spec/rails_applications/6.1.4/db/seeds.rb +7 -0
- data/spec/{dummy → rails_applications/6.1.4}/db/test.sqlite3 +0 -0
- data/spec/{dummy/app/models → rails_applications/6.1.4/lib/assets}/.keep +0 -0
- data/spec/{dummy/app/models/concerns → rails_applications/6.1.4/lib/tasks}/.keep +0 -0
- data/spec/rails_applications/6.1.4/package.json +11 -0
- data/spec/{dummy → rails_applications/6.1.4}/public/404.html +67 -67
- data/spec/{dummy → rails_applications/6.1.4}/public/422.html +67 -67
- data/spec/{dummy → rails_applications/6.1.4}/public/500.html +66 -66
- data/spec/{dummy/lib/assets/.keep → rails_applications/6.1.4/public/apple-touch-icon-precomposed.png} +0 -0
- data/spec/{dummy/lib/tasks/.keep → rails_applications/6.1.4/public/apple-touch-icon.png} +0 -0
- data/spec/{dummy → rails_applications/6.1.4}/public/favicon.ico +0 -0
- data/spec/rails_applications/6.1.4/public/robots.txt +1 -0
- data/spec/{dummy/log → rails_applications/6.1.4/storage}/.keep +0 -0
- data/spec/rails_applications/7.1.3/.dockerignore +37 -0
- data/spec/rails_applications/7.1.3/.gitattributes +9 -0
- data/spec/rails_applications/7.1.3/.gitignore +35 -0
- data/spec/rails_applications/7.1.3/.ruby-version +1 -0
- data/spec/rails_applications/7.1.3/Dockerfile +62 -0
- data/spec/rails_applications/7.1.3/Gemfile +67 -0
- data/spec/rails_applications/7.1.3/README.md +24 -0
- data/spec/rails_applications/7.1.3/Rakefile +6 -0
- data/spec/rails_applications/7.1.3/app/assets/config/manifest.js +4 -0
- data/spec/{dummy/test/controllers → rails_applications/7.1.3/app/assets/images}/.keep +0 -0
- data/spec/rails_applications/7.1.3/app/assets/stylesheets/application.css +15 -0
- data/spec/rails_applications/7.1.3/app/channels/application_cable/channel.rb +4 -0
- data/spec/rails_applications/7.1.3/app/channels/application_cable/connection.rb +4 -0
- data/spec/rails_applications/7.1.3/app/controllers/application_controller.rb +2 -0
- data/spec/{dummy/test/fixtures → rails_applications/7.1.3/app/controllers/concerns}/.keep +0 -0
- data/spec/rails_applications/7.1.3/app/controllers/home_controller.rb +2 -0
- data/spec/rails_applications/7.1.3/app/helpers/application_helper.rb +2 -0
- data/spec/rails_applications/7.1.3/app/helpers/home_helper.rb +2 -0
- data/spec/rails_applications/7.1.3/app/javascript/application.js +3 -0
- data/spec/rails_applications/7.1.3/app/javascript/controllers/application.js +9 -0
- data/spec/rails_applications/7.1.3/app/javascript/controllers/hello_controller.js +7 -0
- data/spec/rails_applications/7.1.3/app/javascript/controllers/index.js +11 -0
- data/spec/rails_applications/7.1.3/app/jobs/application_job.rb +7 -0
- data/spec/rails_applications/7.1.3/app/mailers/application_mailer.rb +4 -0
- data/spec/rails_applications/7.1.3/app/models/application_record.rb +3 -0
- data/spec/{dummy/test/helpers → rails_applications/7.1.3/app/models/concerns}/.keep +0 -0
- data/spec/rails_applications/7.1.3/app/views/home/index.html.erb +3 -0
- data/spec/rails_applications/7.1.3/app/views/home/index.json.erb +1 -0
- data/spec/rails_applications/7.1.3/app/views/layouts/application.html.erb +16 -0
- data/spec/rails_applications/7.1.3/app/views/layouts/mailer.html.erb +13 -0
- data/spec/rails_applications/7.1.3/app/views/layouts/mailer.text.erb +1 -0
- data/spec/rails_applications/7.1.3/bin/bundle +109 -0
- data/spec/rails_applications/7.1.3/bin/docker-entrypoint +8 -0
- data/spec/rails_applications/7.1.3/bin/importmap +4 -0
- data/spec/rails_applications/7.1.3/bin/rails +4 -0
- data/spec/rails_applications/7.1.3/bin/rake +4 -0
- data/spec/rails_applications/7.1.3/bin/setup +33 -0
- data/spec/rails_applications/7.1.3/config/application.rb +27 -0
- data/spec/rails_applications/7.1.3/config/boot.rb +4 -0
- data/spec/rails_applications/7.1.3/config/cable.yml +11 -0
- data/spec/rails_applications/7.1.3/config/credentials.yml.enc +1 -0
- data/spec/rails_applications/7.1.3/config/database.yml +25 -0
- data/spec/rails_applications/7.1.3/config/environment.rb +5 -0
- data/spec/rails_applications/7.1.3/config/environments/development.rb +76 -0
- data/spec/rails_applications/7.1.3/config/environments/production.rb +97 -0
- data/spec/rails_applications/7.1.3/config/environments/test.rb +64 -0
- data/spec/rails_applications/7.1.3/config/importmap.rb +7 -0
- data/spec/rails_applications/7.1.3/config/initializers/assets.rb +12 -0
- data/spec/rails_applications/7.1.3/config/initializers/content_security_policy.rb +25 -0
- data/spec/rails_applications/7.1.3/config/initializers/filter_parameter_logging.rb +8 -0
- data/spec/rails_applications/7.1.3/config/initializers/inflections.rb +16 -0
- data/spec/rails_applications/7.1.3/config/initializers/permissions_policy.rb +13 -0
- data/spec/rails_applications/7.1.3/config/locales/en.yml +31 -0
- data/spec/rails_applications/7.1.3/config/puma.rb +35 -0
- data/spec/rails_applications/7.1.3/config/routes.rb +11 -0
- data/spec/rails_applications/7.1.3/config/storage.yml +34 -0
- data/spec/rails_applications/7.1.3/config.ru +6 -0
- data/spec/rails_applications/7.1.3/db/seeds.rb +9 -0
- data/spec/{dummy/test/integration → rails_applications/7.1.3/lib/assets}/.keep +0 -0
- data/spec/{dummy/test/mailers → rails_applications/7.1.3/lib/tasks}/.keep +0 -0
- data/spec/rails_applications/7.1.3/public/404.html +67 -0
- data/spec/rails_applications/7.1.3/public/422.html +67 -0
- data/spec/rails_applications/7.1.3/public/500.html +66 -0
- data/spec/{dummy/test/models/.keep → rails_applications/7.1.3/public/apple-touch-icon-precomposed.png} +0 -0
- data/spec/{dummy/vendor/assets/javascripts/.keep → rails_applications/7.1.3/public/apple-touch-icon.png} +0 -0
- data/spec/{dummy/vendor/assets/stylesheets/.keep → rails_applications/7.1.3/public/favicon.ico} +0 -0
- data/spec/rails_applications/7.1.3/public/robots.txt +1 -0
- data/spec/rails_applications/7.1.3/storage/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/application_system_test_case.rb +5 -0
- data/spec/rails_applications/7.1.3/test/channels/application_cable/connection_test.rb +13 -0
- data/spec/rails_applications/7.1.3/test/controllers/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/controllers/home_controller_test.rb +7 -0
- data/spec/rails_applications/7.1.3/test/fixtures/files/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/helpers/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/integration/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/mailers/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/models/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/system/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/test_helper.rb +15 -0
- data/spec/rails_applications/7.1.3/vendor/.keep +0 -0
- data/spec/rails_applications/7.1.3/vendor/javascript/.keep +0 -0
- data/spec/rails_helper.rb +8 -4
- data/spec/raygun/breadcrumbs/breadcrumb_spec.rb +171 -171
- data/spec/raygun/breadcrumbs/store_spec.rb +170 -170
- data/spec/services/apply_whitelist_filter_to_payload_spec.rb +251 -251
- data/spec/spec_helper.rb +24 -24
- data/spec/support/fake_logger.rb +17 -17
- data/test/integration/client_test.rb +19 -19
- data/test/rails_helper.rb +6 -0
- data/test/test_helper.rb +76 -72
- data/test/unit/affected_user_test.rb +136 -136
- data/test/unit/client_test.rb +812 -812
- data/test/unit/configuration_test.rb +202 -206
- data/test/unit/error_subscriber_test.rb +43 -0
- data/test/unit/raygun_test.rb +106 -25
- data/test/unit/resque_failure_test.rb +27 -24
- data/test/unit/sidekiq_failure_test.rb +42 -32
- metadata +186 -125
- data/.travis.yml +0 -20
- data/spec/dummy/.gitignore +0 -17
- data/spec/dummy/Gemfile +0 -47
- data/spec/dummy/app/assets/config/manifest.js +0 -3
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -9
- data/spec/dummy/bin/rake +0 -9
- data/spec/dummy/bin/setup +0 -29
- data/spec/dummy/bin/spring +0 -17
- data/spec/dummy/config/application.rb +0 -26
- data/spec/dummy/config/boot.rb +0 -3
- data/spec/dummy/config/environments/development.rb +0 -41
- data/spec/dummy/config/environments/production.rb +0 -79
- data/spec/dummy/config/environments/test.rb +0 -42
- data/spec/dummy/config/initializers/assets.rb +0 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/to_time_preserves_timezone.rb +0 -10
- data/spec/dummy/config/routes.rb +0 -58
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/db/seeds.rb +0 -7
- data/spec/dummy/public/robots.txt +0 -5
- data/spec/dummy/test/test_helper.rb +0 -10
- data/spec/raygun/raygun_spec.rb +0 -47
data/README.md
CHANGED
@@ -1,420 +1,424 @@
|
|
1
|
-
# Raygun 4 Ruby
|
2
|
-
|
3
|
-
This is the Ruby adapter for the Raygun error reporter, https://raygun.com.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
Raygun
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
```ruby
|
124
|
-
def some_method
|
125
|
-
Raygun.record_breadcrumb(
|
126
|
-
message: "<log message goes here>",
|
127
|
-
category: "some category to group them by, maybe authentication or external-apis for example",
|
128
|
-
level: :info, # or debug or warning etc, you can configure what level will get sent
|
129
|
-
metadata: {custom_data: 'can go here'},
|
130
|
-
|
131
|
-
# You can also set the class the breadcrumb was logged from
|
132
|
-
# It will only be set automatically using the included module approach
|
133
|
-
# Method and line number will get added automatically
|
134
|
-
class_name: self.class.name
|
135
|
-
)
|
136
|
-
end
|
137
|
-
```
|
138
|
-
|
139
|
-
If you are using Sinatra or another rack framework you will need to include the Breadcrumbs middleware, this is used for storing the breadcrumbs during a request
|
140
|
-
`use Raygun::Middleware::BreadcrumbsStoreInitializer`
|
141
|
-
(this must be before you `use` the `Raygun::Middleware::RackExceptionInterceptor`)
|
142
|
-
|
143
|
-
If you are using a non web based Ruby application you will have to call `Raygun::Breadcrumbs::Store.initialize` during your applications boot process. The store is per thread, but I have not tested it in a multi threaded application.
|
144
|
-
|
145
|
-
### Filtering the payload
|
146
|
-
|
147
|
-
As an alternative to the above, you can also opt-in to the keys/values to be sent to Raygun by providing a specific whitelist of the keys you want to transmit.
|
148
|
-
|
149
|
-
This disables the blacklist filtering above (`filter_parameters`), and is applied to the entire payload (error, request, environment and custom data included), not just the request parameters.
|
150
|
-
|
151
|
-
In order to opt-in to this feature, set `filter_payload_with_whitelist` to `true`, and specify a shape of what keys you want (the default is below which is to allow everything through, this also means that the query parameters filtered out by default like password, creditcard etc will not be unless changed):
|
152
|
-
|
153
|
-
```ruby
|
154
|
-
Raygun.setup do |config|
|
155
|
-
config.api_key = "YOUR_RAYGUN_API_KEY"
|
156
|
-
config.filter_payload_with_whitelist = true
|
157
|
-
|
158
|
-
config.whitelist_payload_shape = {
|
159
|
-
machineName: true,
|
160
|
-
version: true,
|
161
|
-
error: true,
|
162
|
-
userCustomData: true,
|
163
|
-
tags: true,
|
164
|
-
request: {
|
165
|
-
hostName: true,
|
166
|
-
url: true,
|
167
|
-
httpMethod: true,
|
168
|
-
iPAddress: true,
|
169
|
-
queryString: true,
|
170
|
-
headers: true,
|
171
|
-
form: {}, # Set to empty hash so that it doesn't just filter out the whole thing, but instead filters out each individual param
|
172
|
-
rawData: true
|
173
|
-
}
|
174
|
-
}
|
175
|
-
end
|
176
|
-
```
|
177
|
-
|
178
|
-
Alternatively, provide a Proc to filter the payload using your own logic:
|
179
|
-
|
180
|
-
```ruby
|
181
|
-
Raygun.setup do |config|
|
182
|
-
config.api_key = "YOUR_RAYGUN_API_KEY"
|
183
|
-
config.filter_payload_with_whitelist = true
|
184
|
-
|
185
|
-
config.whitelist_payload_shape do |payload|
|
186
|
-
# Return the payload mutated into your desired form
|
187
|
-
payload
|
188
|
-
end
|
189
|
-
end
|
190
|
-
```
|
191
|
-
|
192
|
-
### Custom User Data
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
config.
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
config.
|
218
|
-
|
219
|
-
|
220
|
-
end
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
config.
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
ActionController::
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
config.
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
config.
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
config.
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
config.
|
346
|
-
|
347
|
-
|
348
|
-
end
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
user
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
1
|
+
# Raygun 4 Ruby ![Build Status](https://github.com/MindscapeHQ/raygun4ruby/actions/workflows/tests.yml/badge.svg) [![Gem Version](https://badge.fury.io/rb/raygun4ruby.svg)](https://badge.fury.io/rb/raygun4ruby)
|
2
|
+
|
3
|
+
This is the Ruby adapter for the Raygun error reporter, https://raygun.com.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add to your application's Gemfile:
|
8
|
+
|
9
|
+
$ bundle add raygun4ruby
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
Or, if you're not using Bundler, install the gem directly:
|
16
|
+
|
17
|
+
$ gem install raygun4ruby
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Rails 6+
|
22
|
+
|
23
|
+
Run:
|
24
|
+
|
25
|
+
rails g raygun:install YOUR_API_KEY_HERE
|
26
|
+
|
27
|
+
You can find your API key in the [Raygun app](https://app.raygun.com/) under "Application Settings".
|
28
|
+
|
29
|
+
You can then test your Raygun integration by running:
|
30
|
+
|
31
|
+
rails raygun:test
|
32
|
+
|
33
|
+
You should see an "ItWorksException" appear in your Raygun dashboard. You're ready to zap those errors! :zap:
|
34
|
+
|
35
|
+
The generator will create a file in `config/initializers` called "raygun.rb". If you need to do any further configuration or customization of Raygun, that's the place to do it!
|
36
|
+
|
37
|
+
By default the Rails integration is set to only report Exceptions in the `production` environment. To change this behaviour, set `config.enable_reporting` to something else in `config/initializers/raygun.rb`.
|
38
|
+
|
39
|
+
#### Version Support
|
40
|
+
|
41
|
+
Raygun4Ruby currently supports Rails 6 or later running on Ruby >= 3.0. If you're using an older version of Ruby or Rails please use an [older version of Raygun4Ruby](https://github.com/MindscapeHQ/raygun4ruby/releases)
|
42
|
+
|
43
|
+
### Sinatra
|
44
|
+
|
45
|
+
To enable exception tracking in Sinatra, just add configure Raygun and use the Rack middleware in your app:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'raygun4ruby'
|
49
|
+
Raygun.setup do |config|
|
50
|
+
config.api_key = "YOUR_API_KEY_HERE"
|
51
|
+
end
|
52
|
+
use Raygun::Middleware::RackExceptionInterceptor
|
53
|
+
```
|
54
|
+
|
55
|
+
### Standalone / Manual Exception Tracking
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
|
59
|
+
require 'rubygems'
|
60
|
+
require 'raygun4ruby'
|
61
|
+
|
62
|
+
Raygun.setup do |config|
|
63
|
+
config.api_key = "YOUR_RAYGUN_API_KEY"
|
64
|
+
config.filter_parameters = [ :password, :card_number, :cvv ] # don't forget to filter out sensitive parameters
|
65
|
+
config.enable_reporting = Rails.env.production? # true to send errors, false to not log
|
66
|
+
end
|
67
|
+
|
68
|
+
begin
|
69
|
+
# your lovely code here
|
70
|
+
rescue => e
|
71
|
+
Raygun.track_exception(e)
|
72
|
+
end
|
73
|
+
|
74
|
+
# You may also pass a user object as the third argument to allow affected customers, like so
|
75
|
+
begin
|
76
|
+
# your lovely code here
|
77
|
+
rescue => e
|
78
|
+
# The second argument is the request environment variables
|
79
|
+
Raygun.track_exception(e, {}, user)
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
You can also pass a Hash as the second parameter to `track_exception`. It should look like a [Rack Env Hash](https://github.com/rack/rack/blob/master/SPEC.rdoc#label-The+Environment)
|
84
|
+
|
85
|
+
### Customizing Parameter Filtering
|
86
|
+
|
87
|
+
If you'd like to customize how parameters are filtered, you can pass a `Proc` to `filter_parameters`. Raygun4Ruby will yield the params hash to the block, and the return value will be sent along with your error.
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
Raygun.setup do |config|
|
91
|
+
config.api_key = "YOUR_RAYGUN_API_KEY"
|
92
|
+
config.filter_parameters do |params|
|
93
|
+
params.slice("only", "a", "few", "keys") # note that Hash#slice is in ActiveSupport
|
94
|
+
end
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
### Recording Breadcrumbs
|
99
|
+
|
100
|
+
Breadcrumbs let you provide logging points in your code that will be collected and sent along with any exception sent to Raygun. This lets you have a better understanding of the events that happened in the system that lead up to the exception.
|
101
|
+
|
102
|
+
1. Include it as a module in your class
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
class SomeClass
|
106
|
+
include Raygun::Breadcrumbs
|
107
|
+
|
108
|
+
def some_method
|
109
|
+
record_breadcrumb(
|
110
|
+
message: "<log message goes here>",
|
111
|
+
category: "some category to group them by, maybe authentication or external-apis for example",
|
112
|
+
level: :info, # or debug or warning etc, you can configure what level will get sent
|
113
|
+
metadata: {custom_data: 'can go here'},
|
114
|
+
)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
119
|
+
This has the added benefit of recording the class the breadcrumb was recorded from automatically
|
120
|
+
|
121
|
+
2. Call the `record_breadcrumb` method manually
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
def some_method
|
125
|
+
Raygun.record_breadcrumb(
|
126
|
+
message: "<log message goes here>",
|
127
|
+
category: "some category to group them by, maybe authentication or external-apis for example",
|
128
|
+
level: :info, # or debug or warning etc, you can configure what level will get sent
|
129
|
+
metadata: {custom_data: 'can go here'},
|
130
|
+
|
131
|
+
# You can also set the class the breadcrumb was logged from
|
132
|
+
# It will only be set automatically using the included module approach
|
133
|
+
# Method and line number will get added automatically
|
134
|
+
class_name: self.class.name
|
135
|
+
)
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
139
|
+
If you are using Sinatra or another rack framework you will need to include the Breadcrumbs middleware, this is used for storing the breadcrumbs during a request
|
140
|
+
`use Raygun::Middleware::BreadcrumbsStoreInitializer`
|
141
|
+
(this must be before you `use` the `Raygun::Middleware::RackExceptionInterceptor`)
|
142
|
+
|
143
|
+
If you are using a non web based Ruby application you will have to call `Raygun::Breadcrumbs::Store.initialize` during your applications boot process. The store is per thread, but I have not tested it in a multi threaded application.
|
144
|
+
|
145
|
+
### Filtering the enire payload using a whitelist
|
146
|
+
|
147
|
+
As an alternative to the above, you can also opt-in to the keys/values to be sent to Raygun by providing a specific whitelist of the keys you want to transmit.
|
148
|
+
|
149
|
+
This disables the blacklist filtering above (`filter_parameters`), and is applied to the entire payload (error, request, environment and custom data included), not just the request parameters.
|
150
|
+
|
151
|
+
In order to opt-in to this feature, set `filter_payload_with_whitelist` to `true`, and specify a shape of what keys you want (the default is below which is to allow everything through, this also means that the query parameters filtered out by default like password, creditcard etc will not be unless changed):
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
Raygun.setup do |config|
|
155
|
+
config.api_key = "YOUR_RAYGUN_API_KEY"
|
156
|
+
config.filter_payload_with_whitelist = true
|
157
|
+
|
158
|
+
config.whitelist_payload_shape = {
|
159
|
+
machineName: true,
|
160
|
+
version: true,
|
161
|
+
error: true,
|
162
|
+
userCustomData: true,
|
163
|
+
tags: true,
|
164
|
+
request: {
|
165
|
+
hostName: true,
|
166
|
+
url: true,
|
167
|
+
httpMethod: true,
|
168
|
+
iPAddress: true,
|
169
|
+
queryString: true,
|
170
|
+
headers: true,
|
171
|
+
form: {}, # Set to empty hash so that it doesn't just filter out the whole thing, but instead filters out each individual param
|
172
|
+
rawData: true
|
173
|
+
}
|
174
|
+
}
|
175
|
+
end
|
176
|
+
```
|
177
|
+
|
178
|
+
Alternatively, provide a Proc to filter the payload using your own logic:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
Raygun.setup do |config|
|
182
|
+
config.api_key = "YOUR_RAYGUN_API_KEY"
|
183
|
+
config.filter_payload_with_whitelist = true
|
184
|
+
|
185
|
+
config.whitelist_payload_shape do |payload|
|
186
|
+
# Return the payload mutated into your desired form
|
187
|
+
payload
|
188
|
+
end
|
189
|
+
end
|
190
|
+
```
|
191
|
+
|
192
|
+
### Custom User Data
|
193
|
+
|
194
|
+
Custom data can be added to `track_exception` by passing a custom_data key in the second parameter hash.
|
195
|
+
|
196
|
+
```ruby
|
197
|
+
begin
|
198
|
+
# more lovely code
|
199
|
+
rescue Exception => e
|
200
|
+
Raygun.track_exception(e, custom_data: {my: 'custom data', goes: 'here'})
|
201
|
+
end
|
202
|
+
```
|
203
|
+
|
204
|
+
Custom data can also be specified globally either by setting `config.custom_data` to a hash
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
Raygun.setup do |config|
|
208
|
+
config.api_key = "YOUR_RAYGUN_API_KEY"
|
209
|
+
config.custom_data = {custom_data: 'goes here'}
|
210
|
+
end
|
211
|
+
```
|
212
|
+
|
213
|
+
or to a proc, which gets passed the exception and environment hash
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
Raygun.setup do |config|
|
217
|
+
config.api_key = "YOUR_RAYGUN_API_KEY"
|
218
|
+
config.custom_data do |e, env|
|
219
|
+
{message: e.message, server: env["SERVER_NAME"]}
|
220
|
+
end
|
221
|
+
end
|
222
|
+
```
|
223
|
+
|
224
|
+
### Ignoring Some Errors
|
225
|
+
|
226
|
+
You can ignore certain types of Exception using the `ignore` option in the setup block, like so:
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
Raygun.setup do |config|
|
230
|
+
config.api_key = "MY_SWEET_API_KEY"
|
231
|
+
config.ignore << ['MyApp::AnExceptionIDontCareAbout']
|
232
|
+
end
|
233
|
+
```
|
234
|
+
|
235
|
+
The following exceptions are ignored by default:
|
236
|
+
|
237
|
+
```
|
238
|
+
ActiveRecord::RecordNotFound
|
239
|
+
ActionController::RoutingError
|
240
|
+
ActionController::InvalidAuthenticityToken
|
241
|
+
ActionDispatch::ParamsParser::ParseError
|
242
|
+
CGI::Session::CookieStore::TamperedWithCookie
|
243
|
+
ActionController::UnknownAction
|
244
|
+
AbstractController::ActionNotFound
|
245
|
+
Mongoid::Errors::DocumentNotFound
|
246
|
+
```
|
247
|
+
|
248
|
+
[You can see this here](https://github.com/MindscapeHQ/raygun4ruby/blob/master/lib/raygun/configuration.rb#L90) and unignore them if needed by doing the following:
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
Raygun.setup do |config|
|
252
|
+
config.api_key = "MY_SWEET_API_KEY"
|
253
|
+
config.ignore.delete('ActionController::InvalidAuthenticityToken')
|
254
|
+
end
|
255
|
+
```
|
256
|
+
|
257
|
+
### Using a Proxy
|
258
|
+
|
259
|
+
You can pass proxy settings using the `proxy_settings` config option.
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
Raygun.setup do |config|
|
263
|
+
config.api_key = "MY_SWEET_API_KEY"
|
264
|
+
config.proxy_settings = { address: "localhost", port: 8888 }
|
265
|
+
end
|
266
|
+
```
|
267
|
+
|
268
|
+
### Affected Customers
|
269
|
+
|
270
|
+
Raygun can track how many customers have been affected by an error.
|
271
|
+
|
272
|
+
By default, Raygun looks for a method called `current_user` on your controller, and it will populate the customer's information based on a default method name mapping.
|
273
|
+
|
274
|
+
(e.g Raygun will call `email` to populate the customer's email, and `first_name` for the customer's first name)
|
275
|
+
|
276
|
+
You can inspect and customize this mapping using `config.affected_user_mapping`, like so:
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
Raygun.setup do |config|
|
280
|
+
config.api_key = "MY_SWEET_API_KEY"
|
281
|
+
config.affected_user_method = :my_current_user # `current_user` by default
|
282
|
+
# To augment the defaults with your unique methods you can do the following
|
283
|
+
config.affected_user_mapping = Raygun::AffectedUser::DEFAULT_MAPPING.merge({
|
284
|
+
identifier: :some_custom_unique_identifier,
|
285
|
+
# If you set the key to a proc it will be passed the user object and you can construct the value your self
|
286
|
+
full_name: ->(user) { "#{user.first_name} #{user.last_name}" }
|
287
|
+
})
|
288
|
+
end
|
289
|
+
```
|
290
|
+
|
291
|
+
To see the defaults check out [affected_user.rb](https://github.com/MindscapeHQ/raygun4ruby/tree/master/lib/raygun/affected_user.rb)
|
292
|
+
|
293
|
+
If you're using Rails, most authentication systems will have this method set and you should be good to go.
|
294
|
+
|
295
|
+
The count of unique affected customers will appear on the error group in the Raygun dashboard. If your customer has an `email` attribute, and that email has a Gravatar associated with that address, you will also see your customer's avatar.
|
296
|
+
|
297
|
+
If you wish to keep it anonymous, you could set this identifier to something like `SecureRandom.uuid` and store that in a cookie, like so:
|
298
|
+
|
299
|
+
```ruby
|
300
|
+
class ApplicationController < ActionController::Base
|
301
|
+
|
302
|
+
def raygun_user
|
303
|
+
cookies.permanent[:raygun_user_identifier] ||= SecureRandom.uuid
|
304
|
+
end
|
305
|
+
|
306
|
+
end
|
307
|
+
```
|
308
|
+
|
309
|
+
(Remember to set `affected_user_method` to `:raygun_user` in your config block...)
|
310
|
+
|
311
|
+
### Version Tracking
|
312
|
+
|
313
|
+
Raygun can attach the version of your application to its error reports. In your Raygun.setup block, set `version` to the current version of your app.
|
314
|
+
|
315
|
+
```ruby
|
316
|
+
Raygun.setup do |config|
|
317
|
+
config.version = "1.0.0.4" # you could also pull this from ENV or however you want to set it.
|
318
|
+
end
|
319
|
+
```
|
320
|
+
|
321
|
+
### Tags
|
322
|
+
|
323
|
+
Tags can be added to `track_exception` by passing a tags key in the second parameter hash.
|
324
|
+
|
325
|
+
```ruby
|
326
|
+
begin
|
327
|
+
# more lovely code
|
328
|
+
rescue Exception => e
|
329
|
+
Raygun.track_exception(e, tags: ['my', 'tags', 'go here'])
|
330
|
+
end
|
331
|
+
```
|
332
|
+
|
333
|
+
Tags can also be specified globally either by setting `config.tags` to an array
|
334
|
+
|
335
|
+
```ruby
|
336
|
+
Raygun.setup do |config|
|
337
|
+
config.tags = ['heroku']
|
338
|
+
end
|
339
|
+
```
|
340
|
+
|
341
|
+
or to a Proc, which gets passed the exception and environment hash. This proc _must_ return an array of strings
|
342
|
+
|
343
|
+
```ruby
|
344
|
+
Raygun.setup do |config|
|
345
|
+
config.api_key = "YOUR_RAYGUN_API_KEY"
|
346
|
+
config.tags do |e, env|
|
347
|
+
[env["SERVER_NAME"]]
|
348
|
+
end
|
349
|
+
end
|
350
|
+
```
|
351
|
+
|
352
|
+
### Background Jobs
|
353
|
+
|
354
|
+
#### Resque
|
355
|
+
|
356
|
+
Raygun4Ruby also includes a Resque failure backend. You should include it inside your Resque initializer (usually something like `config/initializers/load_resque.rb`)
|
357
|
+
|
358
|
+
```ruby
|
359
|
+
require 'resque/failure/multiple'
|
360
|
+
require 'resque/failure/raygun'
|
361
|
+
require 'resque/failure/redis'
|
362
|
+
|
363
|
+
Resque::Failure::Multiple.classes = [Resque::Failure::Redis, Resque::Failure::Raygun]
|
364
|
+
Resque::Failure.backend = Resque::Failure::Multiple
|
365
|
+
```
|
366
|
+
|
367
|
+
#### Sidekiq
|
368
|
+
|
369
|
+
Raygun4Ruby can track errors from Sidekiq (we test on 6+ but there's no reason it shouldn't work on older versions). All you need to do is add the line:
|
370
|
+
|
371
|
+
```ruby
|
372
|
+
require 'raygun/sidekiq'
|
373
|
+
```
|
374
|
+
|
375
|
+
Either in your Raygun initializer or wherever else takes your fancy :simple_smile:
|
376
|
+
|
377
|
+
##### Affected Customers in Sidekiq
|
378
|
+
|
379
|
+
To track affected customers, define a class method on your worker class that returns a user object.
|
380
|
+
Make sure the name of this method is the same as whatever you have defined as the `affected_user_method` in your Raygun configuration and that it returns an object that fits the mappings defined in `affected_user_mapping`
|
381
|
+
If you have not changed these, refer to [Affected customers](#affected-customers) for the defaults
|
382
|
+
|
383
|
+
```ruby
|
384
|
+
class FailingWorker
|
385
|
+
include Sidekiq::Worker
|
386
|
+
|
387
|
+
def perform(arg1, arg2)
|
388
|
+
end
|
389
|
+
|
390
|
+
# Your method must accept an array of arguments
|
391
|
+
# These will be the same as those passed to `perform`
|
392
|
+
def self.current_user(args)
|
393
|
+
arg1 = args[0]
|
394
|
+
arg2 = args[1]
|
395
|
+
|
396
|
+
user = User.find_by(name: arg1)
|
397
|
+
|
398
|
+
# Your method must return a user object
|
399
|
+
user
|
400
|
+
end
|
401
|
+
```
|
402
|
+
|
403
|
+
### Other Configuration options
|
404
|
+
|
405
|
+
For a complete list of configuration options see the [configuration.rb](https://github.com/MindscapeHQ/raygun4ruby/blob/master/lib/raygun/configuration.rb) file
|
406
|
+
|
407
|
+
## Found a bug?
|
408
|
+
|
409
|
+
Oops! Just let us know by opening an Issue on Github.
|
410
|
+
|
411
|
+
## Contributing
|
412
|
+
|
413
|
+
1. Fork the repo, and install dependencies (`bundle install`)
|
414
|
+
2. Create your feature branch and write your code (`git checkout -b my-new-feature`)
|
415
|
+
3. Write some tests, and make them pass (`bundle exec rake`)
|
416
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
417
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
418
|
+
6. Create a new Pull Request. Thank you! :sparkles:
|
419
|
+
|
420
|
+
## Building
|
421
|
+
|
422
|
+
1. Build the gem (`gem build raygun4ruby.gemspec`) - don't bother trying to build it on Windows,
|
423
|
+
the resulting Gem won't work.
|
424
|
+
2. Install the gem (`gem install raygun4ruby-VERSION.gem`)
|