exception_notification 4.5.0 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f671fa31cec6dbf437c5e31ab10136a00f3ef5450fc13d9de2887296390451ba
4
- data.tar.gz: 20f146f16e31e91c456cb08f5598b2714dec47ef1efc41741c7cfea761a8176f
3
+ metadata.gz: 658719ace4734ac45fc34d877614b17324e4fca5691c5dcd62a7d6bbec8f74a8
4
+ data.tar.gz: 53504d3ff146af281d3667679cec36e8ebb4b55bfa6d916a0e83293bad13f7e9
5
5
  SHA512:
6
- metadata.gz: a3c4f84bef2faccc2a66306349b983843a1542895d13e8cb141e50e8c610dc525087f8f86fc4c40654140e128c5378b224851c888086b0b32a6cb4753011717e
7
- data.tar.gz: 5aa30cabeb47f39f89d13c904bdd36da33bf7a598cdb24f14ff6882e90826e3985b1bfb19c55a250bdfc3edae343ec56a72887a5bdbd195bbe4251738a65d1b2
6
+ metadata.gz: 3377beb7f90ebb7a083384c87c20662766a1e4c4cd900d2c6010c82708acb1b16e61922fb5b0c8cdda0fd6c00fac6b92b867672498363a3e513898cc2417ed60
7
+ data.tar.gz: 6aaab695d7f2836993685b1c98ec43aeb204996ee9ba3edb606787e5c5332f63b8a9d165ef821d0525d44ba6a82612ac55a6c9d2b5c874e8d582e9f7e6ef49bf
data/Gemfile.lock ADDED
@@ -0,0 +1,352 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ exception_notification (4.6.0)
5
+ actionmailer (>= 5.2, < 9)
6
+ activesupport (>= 5.2, < 9)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (8.0.2)
12
+ actionpack (= 8.0.2)
13
+ activesupport (= 8.0.2)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ zeitwerk (~> 2.6)
17
+ actionmailbox (8.0.2)
18
+ actionpack (= 8.0.2)
19
+ activejob (= 8.0.2)
20
+ activerecord (= 8.0.2)
21
+ activestorage (= 8.0.2)
22
+ activesupport (= 8.0.2)
23
+ mail (>= 2.8.0)
24
+ actionmailer (8.0.2)
25
+ actionpack (= 8.0.2)
26
+ actionview (= 8.0.2)
27
+ activejob (= 8.0.2)
28
+ activesupport (= 8.0.2)
29
+ mail (>= 2.8.0)
30
+ rails-dom-testing (~> 2.2)
31
+ actionpack (8.0.2)
32
+ actionview (= 8.0.2)
33
+ activesupport (= 8.0.2)
34
+ nokogiri (>= 1.8.5)
35
+ rack (>= 2.2.4)
36
+ rack-session (>= 1.0.1)
37
+ rack-test (>= 0.6.3)
38
+ rails-dom-testing (~> 2.2)
39
+ rails-html-sanitizer (~> 1.6)
40
+ useragent (~> 0.16)
41
+ actiontext (8.0.2)
42
+ actionpack (= 8.0.2)
43
+ activerecord (= 8.0.2)
44
+ activestorage (= 8.0.2)
45
+ activesupport (= 8.0.2)
46
+ globalid (>= 0.6.0)
47
+ nokogiri (>= 1.8.5)
48
+ actionview (8.0.2)
49
+ activesupport (= 8.0.2)
50
+ builder (~> 3.1)
51
+ erubi (~> 1.11)
52
+ rails-dom-testing (~> 2.2)
53
+ rails-html-sanitizer (~> 1.6)
54
+ activejob (8.0.2)
55
+ activesupport (= 8.0.2)
56
+ globalid (>= 0.3.6)
57
+ activemodel (8.0.2)
58
+ activesupport (= 8.0.2)
59
+ activerecord (8.0.2)
60
+ activemodel (= 8.0.2)
61
+ activesupport (= 8.0.2)
62
+ timeout (>= 0.4.0)
63
+ activestorage (8.0.2)
64
+ actionpack (= 8.0.2)
65
+ activejob (= 8.0.2)
66
+ activerecord (= 8.0.2)
67
+ activesupport (= 8.0.2)
68
+ marcel (~> 1.0)
69
+ activesupport (8.0.2)
70
+ base64
71
+ benchmark (>= 0.3)
72
+ bigdecimal
73
+ concurrent-ruby (~> 1.0, >= 1.3.1)
74
+ connection_pool (>= 2.2.5)
75
+ drb
76
+ i18n (>= 1.6, < 2)
77
+ logger (>= 1.4.2)
78
+ minitest (>= 5.1)
79
+ securerandom (>= 0.3)
80
+ tzinfo (~> 2.0, >= 2.0.5)
81
+ uri (>= 0.13.1)
82
+ addressable (2.8.7)
83
+ public_suffix (>= 2.0.2, < 7.0)
84
+ appraisal (2.2.0)
85
+ bundler
86
+ rake
87
+ thor (>= 0.14.0)
88
+ ast (2.4.3)
89
+ aws-eventstream (1.3.2)
90
+ aws-partitions (1.1070.0)
91
+ aws-sdk-core (3.220.1)
92
+ aws-eventstream (~> 1, >= 1.3.0)
93
+ aws-partitions (~> 1, >= 1.992.0)
94
+ aws-sigv4 (~> 1.9)
95
+ base64
96
+ jmespath (~> 1, >= 1.6.1)
97
+ aws-sdk-sns (1.97.0)
98
+ aws-sdk-core (~> 3, >= 3.216.0)
99
+ aws-sigv4 (~> 1.5)
100
+ aws-sigv4 (1.11.0)
101
+ aws-eventstream (~> 1, >= 1.0.2)
102
+ base64 (0.2.0)
103
+ benchmark (0.4.0)
104
+ bigdecimal (3.1.9)
105
+ builder (3.3.0)
106
+ carrier-pigeon (0.7.0)
107
+ addressable
108
+ concurrent-ruby (1.3.5)
109
+ connection_pool (2.5.0)
110
+ coveralls (0.8.23)
111
+ json (>= 1.8, < 3)
112
+ simplecov (~> 0.16.1)
113
+ term-ansicolor (~> 1.3)
114
+ thor (>= 0.19.4, < 2.0)
115
+ tins (~> 1.6)
116
+ crass (1.0.6)
117
+ date (3.4.1)
118
+ docile (1.4.1)
119
+ dogapi (1.45.0)
120
+ multi_json
121
+ drb (2.2.1)
122
+ erubi (1.13.1)
123
+ globalid (1.2.1)
124
+ activesupport (>= 6.1)
125
+ hipchat (1.6.0)
126
+ httparty
127
+ mimemagic
128
+ httparty (0.10.2)
129
+ multi_json (~> 1.0)
130
+ multi_xml (>= 0.5.2)
131
+ i18n (1.14.7)
132
+ concurrent-ruby (~> 1.0)
133
+ io-console (0.8.0)
134
+ irb (1.15.1)
135
+ pp (>= 0.6.0)
136
+ rdoc (>= 4.0.0)
137
+ reline (>= 0.4.2)
138
+ jmespath (1.6.2)
139
+ json (2.10.2)
140
+ language_server-protocol (3.17.0.4)
141
+ lint_roller (1.1.0)
142
+ logger (1.6.6)
143
+ loofah (2.24.0)
144
+ crass (~> 1.0.2)
145
+ nokogiri (>= 1.12.0)
146
+ mail (2.8.1)
147
+ mini_mime (>= 0.1.1)
148
+ net-imap
149
+ net-pop
150
+ net-smtp
151
+ marcel (1.0.4)
152
+ mimemagic (0.4.3)
153
+ nokogiri (~> 1)
154
+ rake
155
+ mini_mime (1.1.5)
156
+ minitest (5.25.5)
157
+ mocha (2.7.1)
158
+ ruby2_keywords (>= 0.0.5)
159
+ mock_redis (0.19.0)
160
+ multi_json (1.15.0)
161
+ multi_xml (0.7.1)
162
+ bigdecimal (~> 3.1)
163
+ mustermann (3.0.3)
164
+ ruby2_keywords (~> 0.0.1)
165
+ net-imap (0.5.6)
166
+ date
167
+ net-protocol
168
+ net-pop (0.1.2)
169
+ net-protocol
170
+ net-protocol (0.2.2)
171
+ timeout
172
+ net-smtp (0.5.1)
173
+ net-protocol
174
+ nio4r (2.7.4)
175
+ nokogiri (1.18.5-aarch64-linux-gnu)
176
+ racc (~> 1.4)
177
+ nokogiri (1.18.5-aarch64-linux-musl)
178
+ racc (~> 1.4)
179
+ nokogiri (1.18.5-arm-linux-gnu)
180
+ racc (~> 1.4)
181
+ nokogiri (1.18.5-arm-linux-musl)
182
+ racc (~> 1.4)
183
+ nokogiri (1.18.5-arm64-darwin)
184
+ racc (~> 1.4)
185
+ nokogiri (1.18.5-x86_64-darwin)
186
+ racc (~> 1.4)
187
+ nokogiri (1.18.5-x86_64-linux-gnu)
188
+ racc (~> 1.4)
189
+ nokogiri (1.18.5-x86_64-linux-musl)
190
+ racc (~> 1.4)
191
+ parallel (1.26.3)
192
+ parser (3.3.7.2)
193
+ ast (~> 2.4.1)
194
+ racc
195
+ pp (0.6.2)
196
+ prettyprint
197
+ prettyprint (0.2.0)
198
+ psych (5.2.3)
199
+ date
200
+ stringio
201
+ public_suffix (6.0.1)
202
+ racc (1.8.1)
203
+ rack (3.1.12)
204
+ rack-protection (4.1.1)
205
+ base64 (>= 0.1.0)
206
+ logger (>= 1.6.0)
207
+ rack (>= 3.0.0, < 4)
208
+ rack-session (2.1.0)
209
+ base64 (>= 0.1.0)
210
+ rack (>= 3.0.0)
211
+ rack-test (2.2.0)
212
+ rack (>= 1.3)
213
+ rackup (2.2.1)
214
+ rack (>= 3)
215
+ rails (8.0.2)
216
+ actioncable (= 8.0.2)
217
+ actionmailbox (= 8.0.2)
218
+ actionmailer (= 8.0.2)
219
+ actionpack (= 8.0.2)
220
+ actiontext (= 8.0.2)
221
+ actionview (= 8.0.2)
222
+ activejob (= 8.0.2)
223
+ activemodel (= 8.0.2)
224
+ activerecord (= 8.0.2)
225
+ activestorage (= 8.0.2)
226
+ activesupport (= 8.0.2)
227
+ bundler (>= 1.15.0)
228
+ railties (= 8.0.2)
229
+ rails-dom-testing (2.2.0)
230
+ activesupport (>= 5.0.0)
231
+ minitest
232
+ nokogiri (>= 1.6)
233
+ rails-html-sanitizer (1.6.2)
234
+ loofah (~> 2.21)
235
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
236
+ railties (8.0.2)
237
+ actionpack (= 8.0.2)
238
+ activesupport (= 8.0.2)
239
+ irb (~> 1.13)
240
+ rackup (>= 1.0.0)
241
+ rake (>= 12.2)
242
+ thor (~> 1.0, >= 1.2.2)
243
+ zeitwerk (~> 2.6)
244
+ rainbow (3.1.1)
245
+ rake (13.2.1)
246
+ rdoc (6.12.0)
247
+ psych (>= 4.0.0)
248
+ redis (1.0.7)
249
+ redis-client (0.24.0)
250
+ connection_pool
251
+ redis-namespace (0.4.4)
252
+ redis (~> 1.0.0)
253
+ regexp_parser (2.10.0)
254
+ reline (0.6.0)
255
+ io-console (~> 0.5)
256
+ resque (1.8.5)
257
+ redis (~> 1.0.0)
258
+ redis-namespace (~> 0.4.0)
259
+ sinatra (>= 0.9.2)
260
+ vegas (~> 0.1.2)
261
+ rubocop (1.74.0)
262
+ json (~> 2.3)
263
+ language_server-protocol (~> 3.17.0.2)
264
+ lint_roller (~> 1.1.0)
265
+ parallel (~> 1.10)
266
+ parser (>= 3.3.0.2)
267
+ rainbow (>= 2.2.2, < 4.0)
268
+ regexp_parser (>= 2.9.3, < 3.0)
269
+ rubocop-ast (>= 1.38.0, < 2.0)
270
+ ruby-progressbar (~> 1.7)
271
+ unicode-display_width (>= 2.4.0, < 4.0)
272
+ rubocop-ast (1.41.0)
273
+ parser (>= 3.3.7.2)
274
+ ruby-progressbar (1.13.0)
275
+ ruby2_keywords (0.0.5)
276
+ securerandom (0.4.1)
277
+ sidekiq (8.0.1)
278
+ connection_pool (>= 2.5.0)
279
+ json (>= 2.9.0)
280
+ logger (>= 1.6.2)
281
+ rack (>= 3.1.0)
282
+ redis-client (>= 0.23.2)
283
+ simplecov (0.16.1)
284
+ docile (~> 1.1)
285
+ json (>= 1.8, < 3)
286
+ simplecov-html (~> 0.10.0)
287
+ simplecov-html (0.10.2)
288
+ sinatra (4.1.1)
289
+ logger (>= 1.6.0)
290
+ mustermann (~> 3.0)
291
+ rack (>= 3.0.0, < 4)
292
+ rack-protection (= 4.1.1)
293
+ rack-session (>= 2.0.0, < 3)
294
+ tilt (~> 2.0)
295
+ slack-notifier (2.4.0)
296
+ stringio (3.1.5)
297
+ sync (0.5.0)
298
+ term-ansicolor (1.11.2)
299
+ tins (~> 1.0)
300
+ thor (1.3.2)
301
+ tilt (2.6.0)
302
+ timecop (0.9.10)
303
+ timeout (0.4.3)
304
+ tins (1.38.0)
305
+ bigdecimal
306
+ sync
307
+ tzinfo (2.0.6)
308
+ concurrent-ruby (~> 1.0)
309
+ unicode-display_width (3.1.4)
310
+ unicode-emoji (~> 4.0, >= 4.0.4)
311
+ unicode-emoji (4.0.4)
312
+ uri (1.0.3)
313
+ useragent (0.16.11)
314
+ vegas (0.1.11)
315
+ rack (>= 1.0.0)
316
+ websocket-driver (0.7.7)
317
+ base64
318
+ websocket-extensions (>= 0.1.0)
319
+ websocket-extensions (0.1.5)
320
+ zeitwerk (2.7.2)
321
+
322
+ PLATFORMS
323
+ aarch64-linux-gnu
324
+ aarch64-linux-musl
325
+ arm-linux-gnu
326
+ arm-linux-musl
327
+ arm64-darwin
328
+ x86_64-darwin
329
+ x86_64-linux-gnu
330
+ x86_64-linux-musl
331
+
332
+ DEPENDENCIES
333
+ appraisal (~> 2.2.0)
334
+ aws-sdk-sns (~> 1)
335
+ carrier-pigeon (>= 0.7.0)
336
+ coveralls (~> 0.8.2)
337
+ dogapi (>= 1.23.0)
338
+ exception_notification!
339
+ hipchat (>= 1.0.0)
340
+ httparty (~> 0.10.2)
341
+ mocha (>= 0.13.0)
342
+ mock_redis (~> 0.19.0)
343
+ net-smtp
344
+ rails (>= 5.2, < 9)
345
+ resque (~> 1.8.0)
346
+ rubocop
347
+ sidekiq (>= 5.0.4)
348
+ slack-notifier (>= 1.0.0)
349
+ timecop (~> 0.9.0)
350
+
351
+ BUNDLED WITH
352
+ 2.6.3
data/README.md CHANGED
@@ -30,7 +30,42 @@ gem 'exception_notification'
30
30
 
31
31
  ### Rails
32
32
 
33
- ExceptionNotification is used as a rack middleware, or in the environment you want it to run. In most cases you would want ExceptionNotification to run on production. Thus, you can make it work by putting the following lines in your `config/environments/production.rb`:
33
+ In order to install ExceptionNotification as an [engine](https://api.rubyonrails.org/classes/Rails/Engine.html), just run the following command from the terminal:
34
+
35
+ rails g exception_notification:install
36
+
37
+ This generates an initializer file, `config/initializers/exception_notification.rb` with some default configuration, which you should modify as needed.
38
+
39
+ Make sure the gem is not listed solely under the `production` group in your `Gemfile`, since this initializer will be loaded regardless of environment. If you want it to only be enabled in production, you can add this to your configuration:
40
+
41
+ ```ruby
42
+ config.ignore_if do |exception, options|
43
+ not Rails.env.production?
44
+ end
45
+ ```
46
+
47
+ The generated initializer file will include this require:
48
+ ```ruby
49
+ require 'exception_notification/rails'
50
+ ```
51
+
52
+ which automatically adds the ExceptionNotification middleware to the Rails middleware stack. This middleware is what watches for unhandled exceptions from your Rails app (except for [background jobs](#background-jobs)) and notifies you when they occur.
53
+
54
+ The generated file adds an `email` notifier:
55
+
56
+ ```ruby
57
+ config.add_notifier :email, {
58
+ email_prefix: '[ERROR] ',
59
+ sender_address: %{"Notifier" <notifier@example.com>},
60
+ exception_recipients: %w{exceptions@example.com}
61
+ }
62
+ ```
63
+
64
+ **Note**: In order to enable delivery notifications by email, make sure you have [ActionMailer configured](docs/notifiers/email.md#actionmailer-configuration).
65
+
66
+ #### Adding middleware manually
67
+
68
+ Alternatively, if for some reason you don't want to `require 'exception_notification/rails'`, you can manually add the middleware, like this:
34
69
 
35
70
  ```ruby
36
71
  Rails.application.config.middleware.use ExceptionNotification::Rack,
@@ -41,7 +76,10 @@ Rails.application.config.middleware.use ExceptionNotification::Rack,
41
76
  }
42
77
  ```
43
78
 
44
- **Note**: In order to enable delivery notifications by email make sure you have [ActionMailer configured](docs/notifiers/email.md#actionmailer-configuration).
79
+ This is the older way of configuring ExceptionNotification (which prior to version 4 was the _only_ way to configure it), and is still the way used in some of the examples.
80
+
81
+ Options passed to the `ExceptionNotification::Rack` middleware in this way are translated to the equivalent configuration options for the `ExceptionNotification.configure` of configuring (compare to the [Rails](#rails) example above).
82
+
45
83
 
46
84
  ### Rack/Sinatra
47
85
 
@@ -100,7 +138,7 @@ But, you also can easily implement your own [custom notifier](docs/notifiers/cus
100
138
 
101
139
  In general, ExceptionNotification will send a notification when every error occurs, which may result in a problem: if your site has a high throughput and a particular error is raised frequently, you will receive too many notifications. During a short period of time, your mail box may be filled with thousands of exception mails, or your mail server may even become slow. To prevent this, you can choose to group errors by setting the `:error_grouping` option to `true`.
102
140
 
103
- Error grouping uses a default formula of `log2(errors_count)` to determine whether to send the notification, based on the accumulated error count for each specific exception. This makes the notifier only send a notification when the count is: 1, 2, 4, 8, 16, 32, 64, 128, ..., (2**n). You can use `:notification_trigger` to override this default formula.
141
+ Error grouping uses a default formula of `Math.log2(errors_count)` to determine whether to send the notification, based on the accumulated error count for each specific exception. This makes the notifier only send a notification when the count is: 1, 2, 4, 8, 16, 32, 64, 128, ..., (2**n). You can use `:notification_trigger` to override this default formula.
104
142
 
105
143
  The following code shows the available options to configure error grouping:
106
144
 
@@ -201,7 +239,7 @@ Rails.application.config.middleware.use ExceptionNotification::Rack,
201
239
  ignore_notifier_if: {
202
240
  email: ->(env, exception) { !Rails.env.production? },
203
241
  slack: ->(env, exception) { exception.message =~ /^Couldn't find Page with ID=/ }
204
- }
242
+ },
205
243
 
206
244
  email: {
207
245
  sender_address: %{"notifier" <notifier@example.com>},
@@ -227,23 +265,51 @@ Rails' routing middleware uses this strategy, rather than raising an exception,
227
265
 
228
266
  Set to false to trigger notifications when another rack middleware sets the "X-Cascade" header to "pass."
229
267
 
230
- ## Background Notifications
268
+ ## Background Jobs
269
+
270
+ The ExceptionNotification middleware can only detect notifications that occur during web requests (controller actions). If you have any Ruby code that gets run _outside_ of a normal web request (hereafter referred to as a "background job" or "background process"), exceptions must be detected a different way (the middleware won't even be running in this context).
271
+
272
+ Examples of background jobs include jobs triggered from a cron file or from a queue.
273
+
274
+ ExceptionNotificatior can be configured to automatically notify of exceptions occurring in most common types of Rails background jobs such as [rake tasks](#rake-tasks). Additionally, it provides optional integrations for some 3rd-party libraries such as [Resque and Sidekiq](#resquesidekiq). And of course you can manually trigger a notification if no integration is provided.
275
+
276
+ ### Rails runner
277
+
278
+ To enable exception notification for your runner commands, add this line to your `config/application.rb` _below_ the `Bundler.require` line (ensuring that `exception_notification` and `rails` gems will have already been required):
279
+
280
+ ```ruby
281
+ require 'exception_notification/rails'
282
+ ```
283
+
284
+ (Requiring it from an initializer is too late, because this depends on the `runner` callback, and that will have already been fired _before_ any initializers run.)
231
285
 
232
- If you want to send notifications from a background process like DelayedJob, you should use the `notify_exception` method like this:
286
+ ### Rake tasks
287
+
288
+ If you've already added `require 'exception_notification/rails'` to your `config/application.rb` as described [above](#rails-runner), then there's nothing further you need to do. (That Engine has a `rake_tasks` callback which automatically requires the file below.)
289
+
290
+ Alternatively, you can add this line to your `config/initializers/exception_notification.rb`:
291
+
292
+ ```ruby
293
+ require 'exception_notification/rake'
294
+ ```
295
+
296
+ ### Manually notify of exceptions
297
+
298
+ If you want to manually send a notifications from a background process that is not _automatically_ handled by ExceptionNotification, then you need to manually call the `notify_exception` method like this:
233
299
 
234
300
  ```ruby
235
301
  begin
236
- some code...
302
+ # some code...
237
303
  rescue => e
238
304
  ExceptionNotifier.notify_exception(e)
239
305
  end
240
306
  ```
241
307
 
242
- You can include information about the background process that created the error by including a data parameter:
308
+ You can include information about the background process that created the error by including a `data` parameter:
243
309
 
244
310
  ```ruby
245
311
  begin
246
- some code...
312
+ # some code...
247
313
  rescue => e
248
314
  ExceptionNotifier.notify_exception(
249
315
  e,
@@ -252,38 +318,9 @@ rescue => e
252
318
  end
253
319
  ```
254
320
 
255
- ### Manually notify of exception
256
-
257
- If your controller action manually handles an error, the notifier will never be run. To manually notify of an error you can do something like the following:
258
-
259
- ```ruby
260
- rescue_from Exception, with: :server_error
261
-
262
- def server_error(exception)
263
- # Whatever code that handles the exception
264
-
265
- ExceptionNotifier.notify_exception(
266
- exception,
267
- env: request.env, data: { message: 'was doing something wrong' }
268
- )
269
- end
270
- ```
271
-
272
- ## Extras
273
-
274
- ### Rails
275
-
276
- Since his first version, ExceptionNotification was just a simple rack middleware. But, the version 4.0.0 introduced the option to use it as a Rails engine. In order to use ExceptionNotification as an engine, just run the following command from the terminal:
277
-
278
- rails g exception_notification:install
279
-
280
- This command generates an initialize file (`config/initializers/exception_notification.rb`) where you can customize your configurations.
281
-
282
- Make sure the gem is not listed solely under the `production` group, since this initializer will be loaded regardless of environment.
283
-
284
321
  ### Resque/Sidekiq
285
322
 
286
- Instead of manually calling background notifications foreach job/worker, you can configure ExceptionNotification to do this automatically. For this, run:
323
+ Instead of manually calling background notifications for each job/worker, you can configure ExceptionNotification to do this automatically. For this, run:
287
324
 
288
325
  rails g exception_notification:install --resque
289
326
 
@@ -293,6 +330,25 @@ or
293
330
 
294
331
  As above, make sure the gem is not listed solely under the `production` group, since this initializer will be loaded regardless of environment.
295
332
 
333
+ ## Manually notify of exceptions from `rescue_from` handler
334
+
335
+ If your controller rescues and handles an error, the middleware won't be able to see that there was an exception, and the notifier will never be run. To manually notify of an error after rescuing it, you can do something like the following:
336
+
337
+ ```ruby
338
+ class SomeController < ApplicationController
339
+ rescue_from Exception, with: :server_error
340
+
341
+ def server_error(exception)
342
+ # Whatever code that handles the exception
343
+
344
+ ExceptionNotifier.notify_exception(
345
+ exception,
346
+ env: request.env, data: { message: 'was doing something wrong' }
347
+ )
348
+ end
349
+ end
350
+ ```
351
+
296
352
  ## Support and tickets
297
353
 
298
354
  Here's the list of [issues](https://github.com/smartinez87/exception_notification/issues) we're currently working on.
@@ -21,7 +21,6 @@ Rails.application.config.middleware.use ExceptionNotification::Rack,
21
21
  },
22
22
  slack: {
23
23
  webhook_url: '[Your webhook url]',
24
- channel: '#exceptions',
25
24
  additional_parameters: {
26
25
  icon_url: 'http://image.jpg',
27
26
  mrkdwn: true
@@ -129,12 +128,6 @@ ExceptionNotifier.notify_exception(
129
128
 
130
129
  The Incoming WebHook URL on slack.
131
130
 
132
- ##### channel
133
-
134
- *String, optional*
135
-
136
- Message will appear in this channel. Defaults to the channel you set as such on slack.
137
-
138
131
  ##### username
139
132
 
140
133
  *String, optional*
@@ -6,22 +6,22 @@ Gem::Specification.new do |s|
6
6
  s.name = 'exception_notification'
7
7
  s.version = ExceptionNotification::VERSION
8
8
  s.authors = ['Jamis Buck', 'Josh Peek']
9
- s.date = '2022-01-20'
10
9
  s.summary = 'Exception notification for Rails apps'
11
10
  s.homepage = 'https://smartinez87.github.io/exception_notification/'
12
11
  s.email = 'smartinez87@gmail.com'
13
12
  s.license = 'MIT'
13
+ s.metadata = { 'changelog_uri' => 'https://github.com/smartinez87/exception_notification/blob/master/CHANGELOG.rdoc' }
14
14
 
15
15
  s.required_ruby_version = '>= 2.3'
16
16
  s.required_rubygems_version = '>= 1.8.11'
17
17
 
18
- s.files = `git ls-files`.split("\n")
18
+ s.files = `git ls-files | grep -v '^examples'`.split("\n")
19
19
  s.files -= `git ls-files -- .??*`.split("\n")
20
20
  s.test_files = `git ls-files -- test`.split("\n")
21
21
  s.require_path = 'lib'
22
22
 
23
- s.add_dependency('actionmailer', '>= 5.2', '< 8')
24
- s.add_dependency('activesupport', '>= 5.2', '< 8')
23
+ s.add_dependency('actionmailer', '>= 5.2', '< 9')
24
+ s.add_dependency('activesupport', '>= 5.2', '< 9')
25
25
 
26
26
  s.add_development_dependency 'appraisal', '~> 2.2.0'
27
27
  s.add_development_dependency 'aws-sdk-sns', '~> 1'
@@ -33,9 +33,9 @@ Gem::Specification.new do |s|
33
33
  s.add_development_dependency 'mocha', '>= 0.13.0'
34
34
  s.add_development_dependency 'mock_redis', '~> 0.19.0'
35
35
  s.add_development_dependency 'net-smtp'
36
- s.add_development_dependency 'rails', '>= 5.2', '< 8'
36
+ s.add_development_dependency 'rails', '>= 5.2', '< 9'
37
37
  s.add_development_dependency 'resque', '~> 1.8.0'
38
- s.add_development_dependency 'rubocop', '0.78.0'
38
+ s.add_development_dependency 'rubocop'
39
39
  s.add_development_dependency 'sidekiq', '>= 5.0.4'
40
40
  s.add_development_dependency 'slack-notifier', '>= 1.0.0'
41
41
  s.add_development_dependency 'timecop', '~> 0.9.0'
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ExceptionNotification
4
+ module Rails
5
+ class RunnerTie
6
+ # Registers an at_exit callback, which checks if there was an exception. This is a pretty
7
+ # crude way to detect exceptions from runner commands, but Rails doesn't provide a better API.
8
+ #
9
+ # This should only be called from a runner callback in your Rails config; otherwise you may
10
+ # register the at_exit callback in more places than you need or want it.
11
+ def call
12
+ at_exit do
13
+ exception = $ERROR_INFO
14
+ if exception && !exception.is_a?(SystemExit)
15
+ ExceptionNotifier.notify_exception(exception, data: data_for_exception_notifier(exception))
16
+ end
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def data_for_exception_notifier(exception = nil)
23
+ data = {}
24
+ data[:error_class] = exception.class.name if exception
25
+ data[:error_message] = exception.message if exception
26
+
27
+ data
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Warning: This must be required after rails but before initializers have been run. If you require
4
+ # it from config/initializers/exception_notification.rb, then the rails and rake_task callbacks
5
+ # registered here will have no effect, because Rails will have already invoked all registered rails
6
+ # and rake_tasks handlers.
7
+
3
8
  module ExceptionNotification
4
9
  class Engine < ::Rails::Engine
5
10
  config.exception_notification = ExceptionNotifier
@@ -7,5 +12,16 @@ module ExceptionNotification
7
12
  config.exception_notification.error_grouping_cache = Rails.cache
8
13
 
9
14
  config.app_middleware.use ExceptionNotification::Rack
15
+
16
+ rake_tasks do
17
+ # Report exceptions occurring in Rake tasks.
18
+ require 'exception_notification/rake'
19
+ end
20
+
21
+ runner do
22
+ # Report exceptions occurring in runner commands.
23
+ require 'exception_notification/rails/runner_tie'
24
+ Rails::RunnerTie.new.call
25
+ end
10
26
  end
11
27
  end