exception_notification 4.3.0 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +5 -5
  2. data/Appraisals +4 -2
  3. data/CHANGELOG.rdoc +47 -0
  4. data/CONTRIBUTING.md +18 -0
  5. data/Gemfile +3 -1
  6. data/README.md +97 -945
  7. data/Rakefile +4 -2
  8. data/docs/notifiers/campfire.md +50 -0
  9. data/docs/notifiers/custom.md +42 -0
  10. data/docs/notifiers/datadog.md +51 -0
  11. data/docs/notifiers/email.md +195 -0
  12. data/docs/notifiers/google_chat.md +31 -0
  13. data/docs/notifiers/hipchat.md +66 -0
  14. data/docs/notifiers/irc.md +97 -0
  15. data/docs/notifiers/mattermost.md +115 -0
  16. data/docs/notifiers/slack.md +161 -0
  17. data/docs/notifiers/sns.md +37 -0
  18. data/docs/notifiers/teams.md +54 -0
  19. data/docs/notifiers/webhook.md +60 -0
  20. data/examples/sample_app.rb +56 -0
  21. data/examples/sinatra/Gemfile +8 -6
  22. data/examples/sinatra/config.ru +3 -1
  23. data/examples/sinatra/sinatra_app.rb +19 -11
  24. data/exception_notification.gemspec +30 -24
  25. data/gemfiles/{rails4_0.gemfile → rails5_2.gemfile} +2 -2
  26. data/gemfiles/{rails4_1.gemfile → rails6_0.gemfile} +2 -2
  27. data/gemfiles/{rails4_2.gemfile → rails6_1.gemfile} +2 -2
  28. data/gemfiles/{rails5_0.gemfile → rails7_0.gemfile} +2 -2
  29. data/lib/exception_notification/rack.rb +28 -30
  30. data/lib/exception_notification/rails.rb +2 -0
  31. data/lib/exception_notification/resque.rb +10 -10
  32. data/lib/exception_notification/sidekiq.rb +10 -12
  33. data/lib/exception_notification/version.rb +5 -0
  34. data/lib/exception_notification.rb +3 -0
  35. data/lib/exception_notifier/base_notifier.rb +10 -5
  36. data/lib/exception_notifier/datadog_notifier.rb +156 -0
  37. data/lib/exception_notifier/email_notifier.rb +73 -88
  38. data/lib/exception_notifier/google_chat_notifier.rb +27 -119
  39. data/lib/exception_notifier/hipchat_notifier.rb +13 -12
  40. data/lib/exception_notifier/irc_notifier.rb +36 -33
  41. data/lib/exception_notifier/mattermost_notifier.rb +54 -137
  42. data/lib/exception_notifier/modules/backtrace_cleaner.rb +2 -2
  43. data/lib/exception_notifier/modules/error_grouping.rb +24 -13
  44. data/lib/exception_notifier/modules/formatter.rb +125 -0
  45. data/lib/exception_notifier/notifier.rb +9 -6
  46. data/lib/exception_notifier/slack_notifier.rb +65 -40
  47. data/lib/exception_notifier/sns_notifier.rb +23 -13
  48. data/lib/exception_notifier/teams_notifier.rb +67 -46
  49. data/lib/exception_notifier/views/exception_notifier/_backtrace.html.erb +1 -1
  50. data/lib/exception_notifier/views/exception_notifier/_environment.text.erb +1 -1
  51. data/lib/exception_notifier/views/exception_notifier/_request.text.erb +1 -1
  52. data/lib/exception_notifier/views/exception_notifier/exception_notification.html.erb +2 -2
  53. data/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb +2 -2
  54. data/lib/exception_notifier/webhook_notifier.rb +17 -14
  55. data/lib/exception_notifier.rb +65 -10
  56. data/lib/generators/exception_notification/install_generator.rb +11 -5
  57. data/lib/generators/exception_notification/templates/{exception_notification.rb → exception_notification.rb.erb} +13 -11
  58. data/test/exception_notification/rack_test.rb +75 -13
  59. data/test/exception_notification/resque_test.rb +54 -0
  60. data/test/exception_notifier/datadog_notifier_test.rb +153 -0
  61. data/test/exception_notifier/email_notifier_test.rb +275 -153
  62. data/test/exception_notifier/google_chat_notifier_test.rb +158 -101
  63. data/test/exception_notifier/hipchat_notifier_test.rb +84 -81
  64. data/test/exception_notifier/irc_notifier_test.rb +36 -34
  65. data/test/exception_notifier/mattermost_notifier_test.rb +213 -67
  66. data/test/exception_notifier/modules/error_grouping_test.rb +41 -40
  67. data/test/exception_notifier/modules/formatter_test.rb +152 -0
  68. data/test/exception_notifier/sidekiq_test.rb +9 -17
  69. data/test/exception_notifier/slack_notifier_test.rb +66 -63
  70. data/test/exception_notifier/sns_notifier_test.rb +84 -32
  71. data/test/exception_notifier/teams_notifier_test.rb +25 -26
  72. data/test/exception_notifier/webhook_notifier_test.rb +52 -48
  73. data/test/exception_notifier_test.rb +150 -41
  74. data/test/support/exception_notifier_helper.rb +14 -0
  75. data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.html.erb +0 -0
  76. data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.text.erb +0 -0
  77. data/test/{dummy/app → support}/views/exception_notifier/_new_section.html.erb +0 -0
  78. data/test/{dummy/app → support}/views/exception_notifier/_new_section.text.erb +0 -0
  79. data/test/test_helper.rb +14 -13
  80. metadata +134 -175
  81. data/gemfiles/rails5_1.gemfile +0 -7
  82. data/lib/exception_notifier/campfire_notifier.rb +0 -40
  83. data/test/dummy/.gitignore +0 -4
  84. data/test/dummy/Rakefile +0 -7
  85. data/test/dummy/app/controllers/application_controller.rb +0 -3
  86. data/test/dummy/app/controllers/posts_controller.rb +0 -30
  87. data/test/dummy/app/helpers/application_helper.rb +0 -2
  88. data/test/dummy/app/helpers/posts_helper.rb +0 -2
  89. data/test/dummy/app/models/post.rb +0 -2
  90. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  91. data/test/dummy/app/views/posts/_form.html.erb +0 -0
  92. data/test/dummy/app/views/posts/new.html.erb +0 -0
  93. data/test/dummy/app/views/posts/show.html.erb +0 -0
  94. data/test/dummy/config/application.rb +0 -42
  95. data/test/dummy/config/boot.rb +0 -6
  96. data/test/dummy/config/database.yml +0 -22
  97. data/test/dummy/config/environment.rb +0 -17
  98. data/test/dummy/config/environments/development.rb +0 -25
  99. data/test/dummy/config/environments/production.rb +0 -50
  100. data/test/dummy/config/environments/test.rb +0 -35
  101. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  102. data/test/dummy/config/initializers/inflections.rb +0 -10
  103. data/test/dummy/config/initializers/mime_types.rb +0 -5
  104. data/test/dummy/config/initializers/secret_token.rb +0 -8
  105. data/test/dummy/config/initializers/session_store.rb +0 -8
  106. data/test/dummy/config/locales/en.yml +0 -5
  107. data/test/dummy/config/routes.rb +0 -3
  108. data/test/dummy/config.ru +0 -4
  109. data/test/dummy/db/migrate/20110729022608_create_posts.rb +0 -15
  110. data/test/dummy/db/schema.rb +0 -24
  111. data/test/dummy/db/seeds.rb +0 -7
  112. data/test/dummy/lib/tasks/.gitkeep +0 -0
  113. data/test/dummy/public/404.html +0 -26
  114. data/test/dummy/public/422.html +0 -26
  115. data/test/dummy/public/500.html +0 -26
  116. data/test/dummy/public/favicon.ico +0 -0
  117. data/test/dummy/public/images/rails.png +0 -0
  118. data/test/dummy/public/index.html +0 -239
  119. data/test/dummy/public/javascripts/application.js +0 -2
  120. data/test/dummy/public/javascripts/controls.js +0 -965
  121. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  122. data/test/dummy/public/javascripts/effects.js +0 -1123
  123. data/test/dummy/public/javascripts/prototype.js +0 -6001
  124. data/test/dummy/public/javascripts/rails.js +0 -191
  125. data/test/dummy/public/robots.txt +0 -5
  126. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  127. data/test/dummy/public/stylesheets/scaffold.css +0 -56
  128. data/test/dummy/script/rails +0 -6
  129. data/test/dummy/test/functional/posts_controller_test.rb +0 -237
  130. data/test/dummy/test/test_helper.rb +0 -7
  131. data/test/exception_notifier/campfire_notifier_test.rb +0 -120
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Exception Notification
2
2
 
3
- [![Gem Version](https://fury-badge.herokuapp.com/rb/exception_notification.png)](http://badge.fury.io/rb/exception_notification)
4
- [![Travis](https://api.travis-ci.org/smartinez87/exception_notification.png)](http://travis-ci.org/smartinez87/exception_notification)
5
- [![Coverage Status](https://coveralls.io/repos/smartinez87/exception_notification/badge.png?branch=master)](https://coveralls.io/r/smartinez87/exception_notification)
6
- [![Code Climate](https://codeclimate.com/github/smartinez87/exception_notification.png)](https://codeclimate.com/github/smartinez87/exception_notification)
3
+ [![Gem Version](https://badge.fury.io/rb/exception_notification.svg)](https://badge.fury.io/rb/exception_notification)
4
+ [![Build Status](https://github.com/smartinez87/exception_notification/actions/workflows/main.yml/badge.svg)](https://github.com/smartinez87/exception_notification/actions/workflows/main.yml)
5
+ [![Coverage Status](https://coveralls.io/repos/github/smartinez87/exception_notification/badge.svg?branch=master)](https://coveralls.io/github/smartinez87/exception_notification?branch=master)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/78a9a12be00a6d305136/maintainability)](https://codeclimate.com/github/smartinez87/exception_notification/maintainability)
7
7
 
8
8
  **THIS README IS FOR THE MASTER BRANCH AND REFLECTS THE WORK CURRENTLY EXISTING ON THE MASTER BRANCH. IF YOU ARE WISHING TO USE A NON-MASTER BRANCH OF EXCEPTION NOTIFICATION, PLEASE CONSULT THAT BRANCH'S README AND NOT THIS ONE.**
9
9
 
10
10
  ---
11
11
 
12
- The Exception Notification gem provides a set of [notifiers](#notifiers) for sending notifications when errors occur in a Rack/Rails application. The built-in notifiers can deliver notifications by [email](#email-notifier), [Campfire](#campfire-notifier), [HipChat](#hipchat-notifier), [Slack](#slack-notifier), [Mattermost](#mattermost-notifier), [Teams](#teams-notifier), [IRC](#irc-notifier), [Amazon SNS](#amazon-sns-notifier), [Google Chat](#google-chat-notifier) or via custom [WebHooks](#webhook-notifier).
12
+ The Exception Notification gem provides a set of [notifiers](#notifiers) for sending notifications when errors occur in a Rack/Rails application. The built-in notifiers can deliver notifications by [email](docs/notifiers/email.md), [HipChat](docs/notifiers/hipchat.md), [Slack](docs/notifiers/slack.md), [Mattermost](docs/notifiers/mattermost.md), [Teams](docs/notifiers/teams.md), [IRC](docs/notifiers/irc.md), [Amazon SNS](docs/notifiers/sns.md), [Google Chat](docs/notifiers/google_chat.md), [Datadog](docs/notifiers/datadog.md) or via custom [WebHooks](docs/notifiers/webhook.md).
13
13
 
14
14
  There's a great [Railscast about Exception Notification](http://railscasts.com/episodes/104-exception-notifications-revised) you can see that may help you getting started.
15
15
 
@@ -17,10 +17,8 @@ There's a great [Railscast about Exception Notification](http://railscasts.com/e
17
17
 
18
18
  ## Requirements
19
19
 
20
- * Ruby 2.0 or greater
21
- * Rails 4.0 or greater, Sinatra or another Rack-based application.
22
-
23
- For previous releases, please checkout [this](#versions).
20
+ * Ruby 2.5 or greater
21
+ * Rails 5.2 or greater, Sinatra or another Rack-based application.
24
22
 
25
23
  ## Getting Started
26
24
 
@@ -36,15 +34,14 @@ ExceptionNotification is used as a rack middleware, or in the environment you wa
36
34
 
37
35
  ```ruby
38
36
  Rails.application.config.middleware.use ExceptionNotification::Rack,
39
- :email => {
40
- :deliver_with => :deliver, # Rails >= 4.2.1 do not need this option since it defaults to :deliver_now
41
- :email_prefix => "[PREFIX] ",
42
- :sender_address => %{"notifier" <notifier@example.com>},
43
- :exception_recipients => %w{exceptions@example.com}
37
+ email: {
38
+ email_prefix: '[PREFIX] ',
39
+ sender_address: %{"notifier" <notifier@example.com>},
40
+ exception_recipients: %w{exceptions@example.com}
44
41
  }
45
42
  ```
46
43
 
47
- **Note**: In order to enable delivery notifications by email make sure you have [ActionMailer configured](#actionmailer-configuration).
44
+ **Note**: In order to enable delivery notifications by email make sure you have [ActionMailer configured](docs/notifiers/email.md#actionmailer-configuration).
48
45
 
49
46
  ### Rack/Sinatra
50
47
 
@@ -57,10 +54,12 @@ Save the current user in the `request` using a controller callback.
57
54
  ```ruby
58
55
  class ApplicationController < ActionController::Base
59
56
  before_action :prepare_exception_notifier
57
+
60
58
  private
59
+
61
60
  def prepare_exception_notifier
62
61
  request.env["exception_notifier.exception_data"] = {
63
- :current_user => current_user
62
+ current_user: current_user
64
63
  }
65
64
  end
66
65
  end
@@ -82,902 +81,47 @@ Options -> sections" below.
82
81
 
83
82
  ## Notifiers
84
83
 
85
- ExceptionNotification relies on notifiers to deliver notifications when errors occur in your applications. By default, 7 notifiers are available:
86
-
87
- * [Campfire notifier](#campfire-notifier)
88
- * [Email notifier](#email-notifier)
89
- * [HipChat notifier](#hipchat-notifier)
90
- * [IRC notifier](#irc-notifier)
91
- * [Slack notifier](#slack-notifier)
92
- * [Mattermost notifier](#mattermost-notifier)
93
- * [Teams notifier](#teams-notifier)
94
- * [Amazon SNS](#amazon-sns-notifier)
95
- * [Google Chat notifier](#google-chat-notifier)
96
- * [WebHook notifier](#webhook-notifier)
97
-
98
- But, you also can easily implement your own [custom notifier](#custom-notifier).
99
-
100
- ### Campfire notifier
101
-
102
- This notifier sends notifications to your Campfire room.
103
-
104
- #### Usage
105
-
106
- Just add the [tinder](https://github.com/collectiveidea/tinder) gem to your `Gemfile`:
107
-
108
- ```ruby
109
- gem 'tinder'
110
- ```
111
-
112
- To configure it, you need to set the `subdomain`, `token` and `room_name` options, like this:
113
-
114
- ```ruby
115
- Rails.application.config.middleware.use ExceptionNotification::Rack,
116
- :email => {
117
- :email_prefix => "[PREFIX] ",
118
- :sender_address => %{"notifier" <notifier@example.com>},
119
- :exception_recipients => %w{exceptions@example.com}
120
- },
121
- :campfire => {
122
- :subdomain => 'my_subdomain',
123
- :token => 'my_token',
124
- :room_name => 'my_room'
125
- }
126
- ```
127
-
128
- #### Options
129
-
130
- ##### subdomain
131
-
132
- *String, required*
133
-
134
- Your subdomain at Campfire.
135
-
136
- ##### room_name
137
-
138
- *String, required*
139
-
140
- The Campfire room where the notifications must be published to.
141
-
142
- ##### token
143
-
144
- *String, required*
145
-
146
- The API token to allow access to your Campfire account.
147
-
148
-
149
- For more options to set Campfire, like _ssl_, check [here](https://github.com/collectiveidea/tinder/blob/master/lib/tinder/campfire.rb#L17).
150
-
151
- ### Email notifier
152
-
153
- The Email notifier sends notifications by email. The notifications/emails sent includes information about the current request, session, and environment, and also gives a backtrace of the exception.
154
-
155
- After an exception notification has been delivered the rack environment variable `exception_notifier.delivered` will be set to true.
156
-
157
- #### ActionMailer configuration
158
-
159
- For the email to be sent, there must be a default ActionMailer `delivery_method` setting configured. If you do not have one, you can use the following code (assuming your app server machine has `sendmail`). Depending on the environment you want ExceptionNotification to run in, put the following code in your `config/environments/production.rb` and/or `config/environments/development.rb`:
160
-
161
- ```ruby
162
- config.action_mailer.delivery_method = :sendmail
163
- # Defaults to:
164
- # config.action_mailer.sendmail_settings = {
165
- # :location => '/usr/sbin/sendmail',
166
- # :arguments => '-i -t'
167
- # }
168
- config.action_mailer.perform_deliveries = true
169
- config.action_mailer.raise_delivery_errors = true
170
- ```
171
-
172
- #### Options
173
-
174
- ##### sender_address
175
-
176
- *String, default: %("Exception Notifier" <exception.notifier@example.com>)*
177
-
178
- Who the message is from.
179
-
180
- ##### exception_recipients
181
-
182
- *String/Array of strings/Proc, default: []*
183
-
184
- Who the message is destined for, can be a string of addresses, an array of addresses, or it can be a proc that returns a string of addresses or an array of addresses. The proc will be evaluated when the mail is sent.
185
-
186
- ##### email_prefix
187
-
188
- *String, default: [ERROR]*
189
-
190
- The subject's prefix of the message.
191
-
192
- ##### sections
193
-
194
- *Array of strings, default: %w(request session environment backtrace)*
195
-
196
- By default, the notification email includes four parts: request, session, environment, and backtrace (in that order). You can customize how each of those sections are rendered by placing a partial named for that part in your `app/views/exception_notifier` directory (e.g., `_session.rhtml`). Each partial has access to the following variables:
197
-
198
- ```ruby
199
- @kontroller # the controller that caused the error
200
- @request # the current request object
201
- @exception # the exception that was raised
202
- @backtrace # a sanitized version of the exception's backtrace
203
- @data # a hash of optional data values that were passed to the notifier
204
- @sections # the array of sections to include in the email
205
- ```
206
-
207
- You can reorder the sections, or exclude sections completely, by using `sections` option. You can even add new sections that
208
- describe application-specific data--just add the section's name to the list (wherever you'd like), and define the corresponding partial. Like the following example with two new added sections:
209
-
210
- ```ruby
211
- Rails.application.config.middleware.use ExceptionNotification::Rack,
212
- :email => {
213
- :email_prefix => "[PREFIX] ",
214
- :sender_address => %{"notifier" <notifier@example.com>},
215
- :exception_recipients => %w{exceptions@example.com},
216
- :sections => %w{my_section1 my_section2}
217
- }
218
- ```
219
-
220
- Place your custom sections under `./app/views/exception_notifier/` with the suffix `.text.erb`, e.g. `./app/views/exception_notifier/_my_section1.text.erb`.
221
-
222
- If your new section requires information that isn't available by default, make sure it is made available to the email using the `exception_data` macro:
223
-
224
- ```ruby
225
- class ApplicationController < ActionController::Base
226
- before_action :log_additional_data
227
- ...
228
- protected
229
- def log_additional_data
230
- request.env["exception_notifier.exception_data"] = {
231
- :document => @document,
232
- :person => @person
233
- }
234
- end
235
- ...
236
- end
237
- ```
238
-
239
- In the above case, `@document` and `@person` would be made available to the email renderer, allowing your new section(s) to access and display them. See the existing sections defined by the plugin for examples of how to write your own.
240
-
241
- ##### background_sections
242
-
243
- *Array of strings, default: %w(backtrace data)*
244
-
245
- When using [background notifications](#background-notifications) some variables are not available in the views, like `@kontroller` and `@request`. Thus, you may want to include different sections for background notifications:
246
-
247
- ```ruby
248
- Rails.application.config.middleware.use ExceptionNotification::Rack,
249
- :email => {
250
- :email_prefix => "[PREFIX] ",
251
- :sender_address => %{"notifier" <notifier@example.com>},
252
- :exception_recipients => %w{exceptions@example.com},
253
- :background_sections => %w{my_section1 my_section2 backtrace data}
254
- }
255
- ```
256
-
257
- ##### email_headers
258
-
259
- *Hash of strings, default: {}*
260
-
261
- Additionally, you may want to set customized headers on the outcoming emails. To do so, simply use the `:email_headers` option:
262
-
263
- ```ruby
264
- Rails.application.config.middleware.use ExceptionNotification::Rack,
265
- :email => {
266
- :email_prefix => "[PREFIX] ",
267
- :sender_address => %{"notifier" <notifier@example.com>},
268
- :exception_recipients => %w{exceptions@example.com},
269
- :email_headers => { "X-Custom-Header" => "foobar" }
270
- }
271
- ```
272
-
273
- ##### verbose_subject
274
-
275
- *Boolean, default: true*
276
-
277
- If enabled, include the exception message in the subject. Use `:verbose_subject => false` to exclude it.
278
-
279
- ##### normalize_subject
280
-
281
- *Boolean, default: false*
282
-
283
- If enabled, remove numbers from subject so they thread as a single one. Use `:normalize_subject => true` to enable it.
284
-
285
- ##### include_controller_and_action_names_in_subject
286
-
287
- *Boolean, default: true*
288
-
289
- If enabled, include the controller and action names in the subject. Use `:include_controller_and_action_names_in_subject => false` to exclude them.
290
-
291
- ##### email_format
292
-
293
- *Symbol, default: :text*
294
-
295
- By default, ExceptionNotification sends emails in plain text, in order to sends multipart notifications (aka HTML emails) use `:email_format => :html`.
296
-
297
- ##### delivery_method
298
-
299
- *Symbol, default: :smtp*
300
-
301
- By default, ExceptionNotification sends emails using the ActionMailer configuration of the application. In order to send emails by another delivery method, use the `delivery_method` option:
302
-
303
- ```ruby
304
- Rails.application.config.middleware.use ExceptionNotification::Rack,
305
- :email => {
306
- :email_prefix => "[PREFIX] ",
307
- :sender_address => %{"notifier" <notifier@example.com>},
308
- :exception_recipients => %w{exceptions@example.com},
309
- :delivery_method => :postmark,
310
- :postmark_settings => {
311
- :api_key => ENV["POSTMARK_API_KEY"]
312
- }
313
- }
314
- ```
315
-
316
- Besides the `delivery_method` option, you also can customize the mailer settings by passing a hash under an option named `DELIVERY_METHOD_settings`. Thus, you can use override specific SMTP settings for notifications using:
317
-
318
- ```ruby
319
- Rails.application.config.middleware.use ExceptionNotification::Rack,
320
- :email => {
321
- :email_prefix => "[PREFIX] ",
322
- :sender_address => %{"notifier" <notifier@example.com>},
323
- :exception_recipients => %w{exceptions@example.com},
324
- :delivery_method => :smtp,
325
- :smtp_settings => {
326
- :user_name => "bob",
327
- :password => "password",
328
- }
329
- }
330
- ```
331
-
332
- A complete list of `smtp_settings` options can be found in the [ActionMailer Configuration documentation](http://api.rubyonrails.org/classes/ActionMailer/Base.html#class-ActionMailer::Base-label-Configuration+options).
333
-
334
- ##### mailer_parent
335
-
336
- *String, default: ActionMailer::Base*
337
-
338
- The parent mailer which ExceptionNotification mailer inherit from.
339
-
340
- ##### deliver_with
341
-
342
- *Symbol, default: :deliver_now
343
-
344
- The method name to send emalis using ActionMailer.
345
-
346
- ### HipChat notifier
347
-
348
- This notifier sends notifications to your Hipchat room.
349
-
350
- #### Usage
351
-
352
- Just add the [hipchat](https://github.com/hipchat/hipchat-rb) gem to your `Gemfile`:
353
-
354
- ```ruby
355
- gem 'hipchat'
356
- ```
357
-
358
- To configure it, you need to set the `token` and `room_name` options, like this:
359
-
360
- ```ruby
361
- Rails.application.config.middleware.use ExceptionNotification::Rack,
362
- :email => {
363
- :email_prefix => "[PREFIX] ",
364
- :sender_address => %{"notifier" <notifier@example.com>},
365
- :exception_recipients => %w{exceptions@example.com}
366
- },
367
- :hipchat => {
368
- :api_token => 'my_token',
369
- :room_name => 'my_room'
370
- }
371
- ```
372
-
373
- #### Options
374
-
375
- ##### room_name
376
-
377
- *String, required*
378
-
379
- The HipChat room where the notifications must be published to.
380
-
381
- ##### api_token
382
-
383
- *String, required*
384
-
385
- The API token to allow access to your HipChat account.
386
-
387
- ##### notify
388
-
389
- *Boolean, optional*
390
-
391
- Notify users. Default : false.
392
-
393
- ##### color
394
-
395
- *String, optional*
396
-
397
- Color of the message. Default : 'red'.
398
-
399
- ##### from
400
-
401
- *String, optional, maximum length : 15*
402
-
403
- Message will appear from this nickname. Default : 'Exception'.
404
-
405
- ##### server_url
406
-
407
- *String, optional*
408
-
409
- Custom Server URL for self-hosted, Enterprise HipChat Server
410
-
411
- For all options & possible values see [Hipchat API](https://www.hipchat.com/docs/api/method/rooms/message).
412
-
413
- ### IRC notifier
414
-
415
- This notifier sends notifications to an IRC channel using the carrier-pigeon gem.
416
-
417
- #### Usage
418
-
419
- Just add the [carrier-pigeon](https://github.com/portertech/carrier-pigeon) gem to your `Gemfile`:
420
-
421
- ```ruby
422
- gem 'carrier-pigeon'
423
- ```
424
-
425
- To configure it, you need to set at least the 'domain' option, like this:
426
-
427
- ```ruby
428
- Rails.application.config.middleware.use ExceptionNotification::Rack,
429
- :email => {
430
- :email_prefix => "[PREFIX] ",
431
- :sender_address => %{"notifier" <notifier@example.com>},
432
- :exception_recipients => %w{exceptions@example.com}
433
- },
434
- :irc => {
435
- :domain => 'irc.example.com'
436
- }
437
- ```
438
-
439
- There are several other options, which are described below. For example, to use ssl and a password, add a prefix, post to the '#log' channel, and include recipients in the message (so that they will be notified), your configuration might look like this:
440
-
441
- ```ruby
442
- Rails.application.config.middleware.use ExceptionNotification::Rack,
443
- :irc => {
444
- :domain => 'irc.example.com',
445
- :nick => 'BadNewsBot',
446
- :password => 'secret',
447
- :port => 6697,
448
- :channel => '#log',
449
- :ssl => true,
450
- :prefix => '[Exception Notification]',
451
- :recipients => ['peter', 'michael', 'samir']
452
- }
453
-
454
- ```
455
-
456
- #### Options
457
-
458
- ##### domain
459
-
460
- *String, required*
461
-
462
- The domain name of your IRC server.
463
-
464
- ##### nick
465
-
466
- *String, optional*
467
-
468
- The message will appear from this nick. Default : 'ExceptionNotifierBot'.
469
-
470
- ##### password
471
-
472
- *String, optional*
473
-
474
- Password for your IRC server.
475
-
476
- ##### port
477
-
478
- *String, optional*
479
-
480
- Port your IRC server is listening on. Default : 6667.
481
-
482
- ##### channel
483
-
484
- *String, optional*
485
-
486
- Message will appear in this channel. Default : '#log'.
487
-
488
- ##### notice
489
-
490
- *Boolean, optional*
491
-
492
- Send a notice. Default : false.
493
-
494
- ##### ssl
495
-
496
- *Boolean, optional*
497
-
498
- Whether to use SSL. Default : false.
499
-
500
- ##### join
501
-
502
- *Boolean, optional*
503
-
504
- Join a channel. Default : false.
505
-
506
- ##### recipients
507
-
508
- *Array of strings, optional*
509
-
510
- Nicks to include in the message. Default: []
511
-
512
- ### Slack notifier
513
-
514
- This notifier sends notifications to a slack channel using the slack-notifier gem.
515
-
516
- #### Usage
517
-
518
- Just add the [slack-notifier](https://github.com/stevenosloan/slack-notifier) gem to your `Gemfile`:
519
-
520
- ```ruby
521
- gem 'slack-notifier'
522
- ```
523
-
524
- To configure it, you need to set at least the 'webhook_url' option, like this:
525
-
526
- ```ruby
527
- Rails.application.config.middleware.use ExceptionNotification::Rack,
528
- :email => {
529
- :email_prefix => "[PREFIX] ",
530
- :sender_address => %{"notifier" <notifier@example.com>},
531
- :exception_recipients => %w{exceptions@example.com}
532
- },
533
- :slack => {
534
- :webhook_url => "[Your webhook url]",
535
- :channel => "#exceptions",
536
- :additional_parameters => {
537
- :icon_url => "http://image.jpg",
538
- :mrkdwn => true
539
- }
540
- }
541
- ```
542
-
543
- The slack notification will include any data saved under `env["exception_notifier.exception_data"]`.
544
-
545
- An example of how to send the server name to Slack in Rails (put this code in application_controller.rb):
546
-
547
- ```ruby
548
- before_action :set_notification
549
-
550
- def set_notification
551
- request.env['exception_notifier.exception_data'] = {"server" => request.env['SERVER_NAME']}
552
- # can be any key-value pairs
553
- end
554
- ```
555
-
556
- If you find this too verbose, you can determine to exclude certain information by doing the following:
557
-
558
- ```ruby
559
- Rails.application.config.middleware.use ExceptionNotification::Rack,
560
- :slack => {
561
- :webhook_url => "[Your webhook url]",
562
- :channel => "#exceptions",
563
- :additional_parameters => {
564
- :icon_url => "http://image.jpg",
565
- :mrkdwn => true
566
- },
567
- :ignore_data_if => lambda {|key, value|
568
- "#{key}" == 'key_to_ignore' || value.is_a?(ClassToBeIgnored)
569
- }
570
- }
571
- ```
572
-
573
- Any evaluation to `true` will cause the key / value pair not be be sent along to Slack.
574
-
575
- #### Options
576
-
577
- ##### webhook_url
578
-
579
- *String, required*
580
-
581
- The Incoming WebHook URL on slack.
582
-
583
- ##### channel
584
-
585
- *String, optional*
586
-
587
- Message will appear in this channel. Defaults to the channel you set as such on slack.
588
-
589
- ##### username
590
-
591
- *String, optional*
592
-
593
- Username of the bot. Defaults to the name you set as such on slack
594
-
595
- ##### custom_hook
596
-
597
- *String, optional*
598
-
599
- Custom hook name. See [slack-notifier](https://github.com/stevenosloan/slack-notifier#custom-hook-name) for
600
- more information. Default: 'incoming-webhook'
601
-
602
- ##### additional_parameters
603
-
604
- *Hash of strings, optional*
605
-
606
- Contains additional payload for a message (e.g avatar, attachments, etc). See [slack-notifier](https://github.com/stevenosloan/slack-notifier#additional-parameters) for more information.. Default: '{}'
607
-
608
- ##### additional_fields
609
-
610
- *Array of Hashes, optional*
611
-
612
- Contains additional fields that will be added to the attachement. See [Slack documentation](https://api.slack.com/docs/message-attachments).
613
-
614
- ### Mattermost notifier
615
-
616
- Post notification in a mattermost channel via [incoming webhook](http://docs.mattermost.com/developer/webhooks-incoming.html)
617
-
618
- Just add the [HTTParty](https://github.com/jnunemaker/httparty) gem to your `Gemfile`:
619
-
620
- ```ruby
621
- gem 'httparty'
622
- ```
623
-
624
- To configure it, you **need** to set the `webhook_url` option.
625
- You can also specify an other channel with `channel` option.
626
-
627
- ```ruby
628
- Rails.application.config.middleware.use ExceptionNotification::Rack,
629
- :email => {
630
- :email_prefix => "[PREFIX] ",
631
- :sender_address => %{"notifier" <notifier@example.com>},
632
- :exception_recipients => %w{exceptions@example.com}
633
- },
634
- :mattermost => {
635
- :webhook_url => 'http://your-mattermost.com/hooks/blablabla',
636
- :channel => 'my-channel'
637
- }
638
- ```
639
-
640
- If you are using Github or Gitlab for issues tracking, you can specify `git_url` as follow to add a *Create issue* link in you notification.
641
- By default this will use your Rails application name to match the git repository. If yours differ you can specify `app_name`.
642
-
643
-
644
- ```ruby
645
- Rails.application.config.middleware.use ExceptionNotification::Rack,
646
- :email => {
647
- :email_prefix => "[PREFIX] ",
648
- :sender_address => %{"notifier" <notifier@example.com>},
649
- :exception_recipients => %w{exceptions@example.com}
650
- },
651
- :mattermost => {
652
- :webhook_url => 'http://your-mattermost.com/hooks/blablabla',
653
- :git_url => 'github.com/aschen'
654
- }
655
- ```
656
-
657
- You can also specify the bot name and avatar with `username` and `avatar` options.
658
-
659
- ```ruby
660
- Rails.application.config.middleware.use ExceptionNotification::Rack,
661
- :email => {
662
- :email_prefix => "[PREFIX] ",
663
- :sender_address => %{"notifier" <notifier@example.com>},
664
- :exception_recipients => %w{exceptions@example.com}
665
- },
666
- :mattermost => {
667
- :webhook_url => 'http://your-mattermost.com/hooks/blablabla',
668
- :avatar => 'http://example.com/your-image.png',
669
- :username => 'Fail bot'
670
- }
671
- ```
672
-
673
- Finally since the notifier use HTTParty, you can include all HTTParty options, like basic_auth for example.
674
-
675
- ```ruby
676
- Rails.application.config.middleware.use ExceptionNotification::Rack,
677
- :email => {
678
- :email_prefix => "[PREFIX] ",
679
- :sender_address => %{"notifier" <notifier@example.com>},
680
- :exception_recipients => %w{exceptions@example.com}
681
- },
682
- :mattermost => {
683
- :webhook_url => 'http://your-mattermost.com/hooks/blablabla',
684
- :basic_auth => {
685
- :username => 'clara',
686
- :password => 'password'
687
- }
688
- }
689
- ```
690
-
691
- #### Options
692
-
693
- ##### webhook_url
694
-
695
- *String, required*
696
-
697
- The Incoming WebHook URL on mattermost.
698
-
699
- ##### channel
700
-
701
- *String, optional*
702
-
703
- Message will appear in this channel. Defaults to the channel you set as such on mattermost.
704
-
705
- ##### username
706
-
707
- *String, optional*
708
-
709
- Username of the bot. Defaults to "Incoming Webhook"
710
-
711
- ##### avatar
712
-
713
- *String, optional*
714
-
715
- Avatar of the bot. Defaults to incoming webhook icon.
716
-
717
- ##### git_url
718
-
719
- *String, optional*
720
-
721
- Url of your gitlab or github with your organisation name for issue creation link (Eg: `github.com/aschen`). Defaults to nil and don't add link to the notification.
722
-
723
- ##### app_name
84
+ ExceptionNotification relies on notifiers to deliver notifications when errors occur in your applications. By default, 8 notifiers are available:
724
85
 
725
- *String, optional*
86
+ * [Datadog notifier](docs/notifiers/datadog.md)
87
+ * [Email notifier](docs/notifiers/email.md)
88
+ * [HipChat notifier](docs/notifiers/hipchat.md)
89
+ * [IRC notifier](docs/notifiers/irc.md)
90
+ * [Slack notifier](docs/notifiers/slack.md)
91
+ * [Mattermost notifier](docs/notifiers/mattermost.md)
92
+ * [Teams notifier](docs/notifiers/teams.md)
93
+ * [Amazon SNS](docs/notifiers/sns.md)
94
+ * [Google Chat notifier](docs/notifiers/google_chat.md)
95
+ * [WebHook notifier](docs/notifiers/webhook.md)
726
96
 
727
- Your application name used for issue creation link. Defaults to ``` Rails.application.class.parent_name.underscore```.
728
-
729
- ### Google Chat Notifier
730
-
731
- Post notifications in a Google Chats channel via [incoming webhook](https://developers.google.com/hangouts/chat/how-tos/webhooks)
732
-
733
- Add the [HTTParty](https://github.com/jnunemaker/httparty) gem to your `Gemfile`:
734
-
735
- ```ruby
736
- gem 'httparty'
737
- ```
738
-
739
- To configure it, you **need** to set the `webhook_url` option.
740
-
741
- ```ruby
742
- Rails.application.config.middleware.use ExceptionNotification::Rack,
743
- :google_chat => {
744
- :webhook_url => 'https://chat.googleapis.com/v1/spaces/XXXXXXXX/messages?key=YYYYYYYYYYYYY&token=ZZZZZZZZZZZZ'
745
- }
746
- ```
747
-
748
- ##### webhook_url
749
-
750
- *String, required*
751
-
752
- The Incoming WebHook URL on Google Chats.
753
-
754
- ##### app_name
755
-
756
- *String, optional*
757
-
758
- Your application name, shown in the notification. Defaults to `Rails.application.class.parent_name.underscore`.
759
-
760
- ### Amazon SNS Notifier
761
-
762
- Notify all exceptions Amazon - Simple Notification Service: [SNS](https://aws.amazon.com/sns/).
763
-
764
- #### Usage
765
-
766
- Add the [aws-sdk-sns](https://github.com/aws/aws-sdk-ruby/tree/master/gems/aws-sdk-sns) gem to your `Gemfile`:
767
-
768
- ```ruby
769
- gem 'aws-sdk-sns', '~> 1.5'
770
- ```
771
-
772
- To configure it, you **need** to set 3 required options for aws: `region`, `access_key_id` and `secret_access_key`, and one more option for sns: `topic_arn`.
773
-
774
- ```ruby
775
- Rails.application.config.middleware.use ExceptionNotification::Rack,
776
- sns: {
777
- region: 'us-east-x',
778
- access_key_id: 'access_key_id',
779
- secret_access_key: 'secret_access_key',
780
- topic_arn: 'arn:aws:sns:us-east-x:XXXX:my-topic'
781
- }
782
- ```
783
-
784
- ##### sns_prefix
785
- *String, optional *
786
-
787
- Prefix in the notification subject, by default: "[Error]"
788
-
789
- ##### backtrace_lines
790
- *Integer, optional *
791
-
792
- Number of backtrace lines to be displayed in the notification message. By default: 10
793
-
794
- #### Note:
795
- * You may need to update your previous `aws-sdk-*` gems in order to setup `aws-sdk-sns` correctly.
796
- * If you need any further information about the available regions or any other SNS related topic consider: [SNS faqs](https://aws.amazon.com/sns/faqs/)
797
-
798
- ### Teams notifier
799
-
800
- Post notification in a Microsoft Teams channel via [Incoming Webhook Connector](https://docs.microsoft.com/en-us/outlook/actionable-messages/actionable-messages-via-connectors)
801
- Just add the [HTTParty](https://github.com/jnunemaker/httparty) gem to your `Gemfile`:
802
-
803
- ```ruby
804
- gem 'httparty'
805
- ```
806
-
807
- To configure it, you **need** to set the `webhook_url` option.
808
- If you are using GitLab for issue tracking, you can specify `git_url` as follows to add a *Create issue* button in your notification.
809
- By default this will use your Rails application name to match the git repository. If yours differs, you can specify `app_name`.
810
- By that same notion, you may also set a `jira_url` to get a button that will send you to the New Issue screen in Jira.
811
-
812
- ```ruby
813
- Rails.application.config.middleware.use ExceptionNotification::Rack,
814
- :email => {
815
- :email_prefix => "[PREFIX] ",
816
- :sender_address => %{"notifier" <notifier@example.com>},
817
- :exception_recipients => %w{exceptions@example.com}
818
- },
819
- :teams => {
820
- :webhook_url => 'https://outlook.office.com/webhook/your-guid/IncomingWebhook/team-guid',
821
- :git_url => 'https://your-gitlab.com/Group/Project',
822
- :jira_url => 'https://your-jira.com'
823
- }
824
- ```
825
-
826
- #### Options
827
-
828
- ##### webhook_url
829
-
830
- *String, required*
831
-
832
- The Incoming WebHook URL on mattermost.
833
-
834
- ##### git_url
835
-
836
- *String, optional*
837
-
838
- Url of your gitlab or github with your organisation name for issue creation link (Eg: `github.com/aschen`). Defaults to nil and doesn't add link to the notification.
839
-
840
- ##### jira_url
841
-
842
- *String, optional*
843
-
844
- Url of your Jira instance, adds button for Create Issue screen. Defaults to nil and doesn't add a button to the card.
845
-
846
- ##### app_name
847
-
848
- *String, optional*
849
-
850
- Your application name used for git issue creation link. Defaults to `Rails.application.class.parent_name.underscore`.
851
-
852
- ### WebHook notifier
853
-
854
- This notifier ships notifications over the HTTP protocol.
855
-
856
- #### Usage
857
-
858
- Just add the [HTTParty](https://github.com/jnunemaker/httparty) gem to your `Gemfile`:
859
-
860
- ```ruby
861
- gem 'httparty'
862
- ```
863
-
864
- To configure it, you need to set the `url` option, like this:
865
-
866
- ```ruby
867
- Rails.application.config.middleware.use ExceptionNotification::Rack,
868
- :email => {
869
- :email_prefix => "[PREFIX] ",
870
- :sender_address => %{"notifier" <notifier@example.com>},
871
- :exception_recipients => %w{exceptions@example.com}
872
- },
873
- :webhook => {
874
- :url => 'http://domain.com:5555/hubot/path'
875
- }
876
- ```
877
-
878
- By default, the WebhookNotifier will call the URLs using the POST method. But, you can change this using the `http_method` option.
879
-
880
- ```ruby
881
- Rails.application.config.middleware.use ExceptionNotification::Rack,
882
- :email => {
883
- :email_prefix => "[PREFIX] ",
884
- :sender_address => %{"notifier" <notifier@example.com>},
885
- :exception_recipients => %w{exceptions@example.com}
886
- },
887
- :webhook => {
888
- :url => 'http://domain.com:5555/hubot/path',
889
- :http_method => :get
890
- }
891
- ```
892
-
893
- Besides the `url` and `http_method` options, all the other options are passed directly to HTTParty. Thus, if the HTTP server requires authentication, you can include the following options:
894
-
895
- ```ruby
896
- Rails.application.config.middleware.use ExceptionNotification::Rack,
897
- :email => {
898
- :email_prefix => "[PREFIX] ",
899
- :sender_address => %{"notifier" <notifier@example.com>},
900
- :exception_recipients => %w{exceptions@example.com}
901
- },
902
- :webhook => {
903
- :url => 'http://domain.com:5555/hubot/path',
904
- :basic_auth => {
905
- :username => 'alice',
906
- :password => 'password'
907
- }
908
- }
909
- ```
910
-
911
- For more HTTParty options, check out the [documentation](https://github.com/jnunemaker/httparty).
912
-
913
- ### Custom notifier
914
-
915
- Simply put, notifiers are objects which respond to `#call(exception, options)` method. Thus, a lambda can be used as a notifier as follow:
916
-
917
- ```ruby
918
- ExceptionNotifier.add_notifier :custom_notifier_name,
919
- ->(exception, options) { puts "Something goes wrong: #{exception.message}"}
920
- ```
921
-
922
- More advanced users or third-party framework developers, also can create notifiers to be shipped in gems and take advantage of ExceptionNotification's Notifier API to standardize the [various](https://github.com/airbrake/airbrake) [solutions](https://www.honeybadger.io) [out](http://www.exceptional.io) [there](https://bugsnag.com). For this, beyond the `#call(exception, options)` method, the notifier class MUST BE defined under the ExceptionNotifier namespace and its name sufixed by `Notifier`, e.g: ExceptionNotifier::SimpleNotifier.
923
-
924
- #### Example
925
-
926
- Define the custom notifier:
927
-
928
- ```ruby
929
- module ExceptionNotifier
930
- class SimpleNotifier
931
- def initialize(options)
932
- # do something with the options...
933
- end
934
-
935
- def call(exception, options={})
936
- # send the notification
937
- end
938
- end
939
- end
940
- ```
941
-
942
- Using it:
943
-
944
- ```ruby
945
- Rails.application.config.middleware.use ExceptionNotification::Rack,
946
- :email => {
947
- :email_prefix => "[PREFIX] ",
948
- :sender_address => %{"notifier" <notifier@example.com>},
949
- :exception_recipients => %w{exceptions@example.com}
950
- },
951
- :simple => {
952
- # simple notifier options
953
- }
954
- ```
97
+ But, you also can easily implement your own [custom notifier](docs/notifiers/custom.md).
955
98
 
956
99
  ## Error Grouping
957
- In general, exception notification will send every notification when an error occured, which may result in a problem: if your site has a high throughput and an same error raised frequently, you will receive too many notifications during a short period time, your mail box may be full of thousands of exception mails or even your mail server will be slow. To prevent this, you can choose to error errors by using `:error_grouping` option and set it to `true`.
958
100
 
959
- Error grouping has a default formula `log2(errors_count)` to determine if it is needed to send the notification based on the accumulated errors count for specified exception, this makes the notifier only send notification when count is: 1, 2, 4, 8, 16, 32, 64, 128, ... (2**n). You can use `:notification_trigger` to override this default formula.
101
+ 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
+
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.
960
104
 
961
- The below shows options used to enable error grouping:
105
+ The following code shows the available options to configure error grouping:
962
106
 
963
107
  ```ruby
964
108
  Rails.application.config.middleware.use ExceptionNotification::Rack,
965
- :ignore_exceptions => ['ActionView::TemplateError'] + ExceptionNotifier.ignored_exceptions,
966
- :email => {
967
- :email_prefix => "[PREFIX] ",
968
- :sender_address => %{"notifier" <notifier@example.com>},
969
- :exception_recipients => %w{exceptions@example.com}
109
+ ignore_exceptions: ['ActionView::TemplateError'] + ExceptionNotifier.ignored_exceptions,
110
+ email: {
111
+ email_prefix: '[PREFIX] ',
112
+ sender_address: %{"notifier" <notifier@example.com>},
113
+ exception_recipients: %w{exceptions@example.com}
970
114
  },
971
- :error_grouping => true,
972
- # :error_grouping_period => 5.minutes, # the time before an error is regarded as fixed
973
- # :error_grouping_cache => Rails.cache, # for other applications such as Sinatra, use one instance of ActiveSupport::Cache::Store
115
+ error_grouping: true,
116
+ # error_grouping_period: 5.minutes, # the time before an error is regarded as fixed
117
+ # error_grouping_cache: Rails.cache, # for other applications such as Sinatra, use one instance of ActiveSupport::Cache::Store
974
118
  #
975
119
  # notification_trigger: specify a callback to determine when a notification should be sent,
976
120
  # the callback will be invoked with two arguments:
977
121
  # exception: the exception raised
978
122
  # count: accumulated errors count for this exception
979
123
  #
980
- # :notification_trigger => lambda { |exception, count| count % 10 == 0 }
124
+ # notification_trigger: lambda { |exception, count| count % 10 == 0 }
981
125
  ```
982
126
 
983
127
  ## Ignore Exceptions
@@ -990,6 +134,8 @@ You can choose to ignore certain exceptions, which will make ExceptionNotificati
990
134
 
991
135
  * `:ignore_if` - Custom (i.e. ignore exceptions that satisfy some condition)
992
136
 
137
+ * `:ignore_notifer_if` - Custom (i.e. let each notifier ignore exceptions if by-notifier condition is satisfied)
138
+
993
139
 
994
140
  ### :ignore_exceptions
995
141
 
@@ -999,12 +145,12 @@ Ignore specified exception types. To achieve that, you should use the `:ignore_e
999
145
 
1000
146
  ```ruby
1001
147
  Rails.application.config.middleware.use ExceptionNotification::Rack,
1002
- :ignore_exceptions => ['ActionView::TemplateError'] + ExceptionNotifier.ignored_exceptions,
1003
- :email => {
1004
- :email_prefix => "[PREFIX] ",
1005
- :sender_address => %{"notifier" <notifier@example.com>},
1006
- :exception_recipients => %w{exceptions@example.com}
1007
- }
148
+ ignore_exceptions: ['ActionView::TemplateError'] + ExceptionNotifier.ignored_exceptions,
149
+ email: {
150
+ email_prefix: '[PREFIX] ',
151
+ sender_address: %{"notifier" <notifier@example.com>},
152
+ exception_recipients: %w{exceptions@example.com}
153
+ }
1008
154
  ```
1009
155
 
1010
156
  The above will make ExceptionNotifier ignore a *TemplateError* exception, plus the ones ignored by default.
@@ -1017,32 +163,58 @@ In some cases you may want to avoid getting notifications from exceptions made b
1017
163
 
1018
164
  ```ruby
1019
165
  Rails.application.config.middleware.use ExceptionNotification::Rack,
1020
- :ignore_crawlers => %w{Googlebot bingbot},
1021
- :email => {
1022
- :email_prefix => "[PREFIX] ",
1023
- :sender_address => %{"notifier" <notifier@example.com>},
1024
- :exception_recipients => %w{exceptions@example.com}
1025
- }
166
+ ignore_crawlers: %w{Googlebot bingbot},
167
+ email: {
168
+ email_prefix: '[PREFIX] ',
169
+ sender_address: %{"notifier" <notifier@example.com>},
170
+ exception_recipients: %w{exceptions@example.com}
171
+ }
1026
172
  ```
1027
173
 
1028
174
  ### :ignore_if
1029
175
 
1030
176
  *Lambda, default: nil*
1031
177
 
1032
- Last but not least, you can ignore exceptions based on a condition. Take a look:
178
+ You can ignore exceptions based on a condition. Take a look:
1033
179
 
1034
180
  ```ruby
1035
181
  Rails.application.config.middleware.use ExceptionNotification::Rack,
1036
- :ignore_if => ->(env, exception) { exception.message =~ /^Couldn't find Page with ID=/ },
1037
- :email => {
1038
- :email_prefix => "[PREFIX] ",
1039
- :sender_address => %{"notifier" <notifier@example.com>},
1040
- :exception_recipients => %w{exceptions@example.com},
1041
- }
182
+ ignore_if: ->(env, exception) { exception.message =~ /^Couldn't find Page with ID=/ },
183
+ email: {
184
+ email_prefix: '[PREFIX] ',
185
+ sender_address: %{"notifier" <notifier@example.com>},
186
+ exception_recipients: %w{exceptions@example.com},
187
+ }
1042
188
  ```
1043
189
 
1044
190
  You can make use of both the environment and the exception inside the lambda to decide wether to avoid or not sending the notification.
1045
191
 
192
+ ### :ignore_notifier_if
193
+
194
+ * Hash of Lambda, default: nil*
195
+
196
+ In case you want a notifier to ignore certain exceptions, but don't want other notifiers to skip them, you can set by-notifier ignore options.
197
+ By setting below, each notifier will ignore exceptions when its corresponding condition is met.
198
+
199
+ ```ruby
200
+ Rails.application.config.middleware.use ExceptionNotification::Rack,
201
+ ignore_notifier_if: {
202
+ email: ->(env, exception) { !Rails.env.production? },
203
+ slack: ->(env, exception) { exception.message =~ /^Couldn't find Page with ID=/ }
204
+ }
205
+
206
+ email: {
207
+ sender_address: %{"notifier" <notifier@example.com>},
208
+ exception_recipients: %w{exceptions@example.com}
209
+ },
210
+ slack: {
211
+ webhook_url: '[Your webhook url]',
212
+ channel: '#exceptions',
213
+ }
214
+ ```
215
+
216
+ To customize each condition, you can make use of environment and the exception object inside the lambda.
217
+
1046
218
  ## Rack X-Cascade Header
1047
219
 
1048
220
  Some rack apps (Rails in particular) utilize the "X-Cascade" header to pass the request-handling responsibility to the next middleware in the stack.
@@ -1072,9 +244,11 @@ You can include information about the background process that created the error
1072
244
  ```ruby
1073
245
  begin
1074
246
  some code...
1075
- rescue => exception
1076
- ExceptionNotifier.notify_exception(exception,
1077
- :data => {:worker => worker.to_s, :queue => queue, :payload => payload})
247
+ rescue => e
248
+ ExceptionNotifier.notify_exception(
249
+ e,
250
+ data: { worker: worker.to_s, queue: queue, payload: payload}
251
+ )
1078
252
  end
1079
253
  ```
1080
254
 
@@ -1083,17 +257,18 @@ end
1083
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:
1084
258
 
1085
259
  ```ruby
1086
- rescue_from Exception, :with => :server_error
260
+ rescue_from Exception, with: :server_error
1087
261
 
1088
262
  def server_error(exception)
1089
263
  # Whatever code that handles the exception
1090
264
 
1091
- ExceptionNotifier.notify_exception(exception,
1092
- :env => request.env, :data => {:message => "was doing something wrong"})
265
+ ExceptionNotifier.notify_exception(
266
+ exception,
267
+ env: request.env, data: { message: 'was doing something wrong' }
268
+ )
1093
269
  end
1094
270
  ```
1095
271
 
1096
-
1097
272
  ## Extras
1098
273
 
1099
274
  ### Rails
@@ -1118,29 +293,6 @@ or
1118
293
 
1119
294
  As above, make sure the gem is not listed solely under the `production` group, since this initializer will be loaded regardless of environment.
1120
295
 
1121
- ## Versions
1122
-
1123
- For v4.2.1, see this tag:
1124
-
1125
- http://github.com/smartinez87/exception_notification/tree/v4.2.1
1126
-
1127
- For v4.2.0, see this tag:
1128
-
1129
- http://github.com/smartinez87/exception_notification/tree/v4.2.0
1130
-
1131
- For previous releases, visit:
1132
-
1133
- https://github.com/smartinez87/exception_notification/tags
1134
-
1135
- If you are running Rails 2.3 then see the branch for that:
1136
-
1137
- http://github.com/smartinez87/exception_notification/tree/2-3-stable
1138
-
1139
- If you are running pre-rack Rails then see this tag:
1140
-
1141
- http://github.com/smartinez87/exception_notification/tree/pre-2-3
1142
-
1143
-
1144
296
  ## Support and tickets
1145
297
 
1146
298
  Here's the list of [issues](https://github.com/smartinez87/exception_notification/issues) we're currently working on.