exception_notification 3.0.1 → 4.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +9 -0
- data/Appraisals +11 -0
- data/CHANGELOG.rdoc +21 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +49 -7
- data/README.md +417 -184
- data/Rakefile +4 -2
- data/examples/sinatra/Gemfile +8 -0
- data/examples/sinatra/Gemfile.lock +95 -0
- data/examples/sinatra/Procfile +2 -0
- data/examples/sinatra/README.md +11 -0
- data/examples/sinatra/config.ru +3 -0
- data/examples/sinatra/sinatra_app.rb +28 -0
- data/exception_notification.gemspec +10 -4
- data/gemfiles/rails3_1.gemfile +7 -0
- data/gemfiles/rails3_2.gemfile +7 -0
- data/gemfiles/rails4_0.gemfile +7 -0
- data/lib/exception_notification.rb +10 -0
- data/lib/exception_notification/rack.rb +45 -0
- data/lib/exception_notification/rails.rb +8 -0
- data/lib/exception_notification/resque.rb +24 -0
- data/lib/exception_notification/sidekiq.rb +22 -0
- data/lib/exception_notifier.rb +89 -61
- data/lib/exception_notifier/campfire_notifier.rb +2 -7
- data/lib/exception_notifier/email_notifier.rb +181 -0
- data/lib/exception_notifier/notifier.rb +9 -178
- data/lib/exception_notifier/views/exception_notifier/_backtrace.html.erb +3 -1
- data/lib/exception_notifier/views/exception_notifier/_data.html.erb +6 -1
- data/lib/exception_notifier/views/exception_notifier/_environment.html.erb +16 -6
- data/lib/exception_notifier/views/exception_notifier/_environment.text.erb +1 -1
- data/lib/exception_notifier/views/exception_notifier/_request.html.erb +24 -5
- data/lib/exception_notifier/views/exception_notifier/_request.text.erb +2 -0
- data/lib/exception_notifier/views/exception_notifier/_session.html.erb +10 -2
- data/lib/exception_notifier/views/exception_notifier/_session.text.erb +1 -1
- data/lib/exception_notifier/views/exception_notifier/_title.html.erb +3 -3
- data/lib/exception_notifier/views/exception_notifier/background_exception_notification.html.erb +38 -11
- data/lib/exception_notifier/views/exception_notifier/background_exception_notification.text.erb +0 -1
- data/lib/exception_notifier/views/exception_notifier/exception_notification.html.erb +39 -21
- data/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb +0 -1
- data/lib/exception_notifier/webhook_notifier.rb +21 -0
- data/lib/generators/exception_notification/install_generator.rb +15 -0
- data/lib/generators/exception_notification/templates/exception_notification.rb +47 -0
- data/test/dummy/Gemfile +2 -1
- data/test/dummy/Gemfile.lock +79 -78
- data/test/dummy/config/environment.rb +9 -7
- data/test/dummy/test/functional/posts_controller_test.rb +22 -37
- data/test/{campfire_test.rb → exception_notifier/campfire_notifier_test.rb} +4 -4
- data/test/exception_notifier/email_notifier_test.rb +144 -0
- data/test/exception_notifier/webhook_notifier_test.rb +41 -0
- data/test/exception_notifier_test.rb +101 -0
- data/test/test_helper.rb +4 -1
- metadata +136 -18
- data/test/background_exception_notification_test.rb +0 -82
- data/test/exception_notification_test.rb +0 -73
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
== 4.0.0
|
2
|
+
|
3
|
+
* enhancements
|
4
|
+
* Be able to override delivery_method (by @jweslley)
|
5
|
+
* Add logger to log when notifications cannot be shiped (by @jweslley)
|
6
|
+
* Add Rails generator to create an initializer file (by @jweslley)
|
7
|
+
* Add rails engine (by @jweslley)
|
8
|
+
* Add sidekiq support (by @jweslley)
|
9
|
+
* Add resque support (by @jweslley)
|
10
|
+
* Better style for html views (by @jweslley)
|
11
|
+
* Support customizable Mailer class (by @Bishop)
|
12
|
+
* Turn ExceptionNotification Rails agnostic (by @jweslley)
|
13
|
+
* Support custom ignore exceptions for background notifications (by @jweslley)
|
14
|
+
* Be able to implement custom notifiers (by @jweslley)
|
15
|
+
* Add Webhook notifier (by @jweslley)
|
16
|
+
* Rails 4 compatible
|
17
|
+
|
18
|
+
* bug fixes
|
19
|
+
* Don't error if Rails isn't defined. (by @dpogue)
|
20
|
+
* Fix call to #normalize_digits (by @ghiculescu)
|
21
|
+
|
1
22
|
== 3.0.1
|
2
23
|
|
3
24
|
* enhancements
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -3,9 +3,10 @@ PATH
|
|
3
3
|
specs:
|
4
4
|
exception_notification (3.0.1)
|
5
5
|
actionmailer (>= 3.0.4)
|
6
|
+
activesupport (>= 3.0.4)
|
6
7
|
|
7
8
|
GEM
|
8
|
-
remote:
|
9
|
+
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
11
|
actionmailer (3.2.6)
|
11
12
|
actionpack (= 3.2.6)
|
@@ -34,17 +35,33 @@ GEM
|
|
34
35
|
activesupport (3.2.6)
|
35
36
|
i18n (~> 0.6)
|
36
37
|
multi_json (~> 1.0)
|
38
|
+
appraisal (0.5.2)
|
39
|
+
bundler
|
40
|
+
rake
|
37
41
|
arel (3.0.2)
|
38
42
|
builder (3.0.0)
|
43
|
+
celluloid (0.14.0)
|
44
|
+
timers (>= 1.0.0)
|
45
|
+
colorize (0.5.8)
|
46
|
+
connection_pool (1.0.0)
|
47
|
+
coveralls (0.6.5)
|
48
|
+
colorize
|
49
|
+
multi_json (~> 1.3)
|
50
|
+
rest-client
|
51
|
+
simplecov (>= 0.7)
|
52
|
+
thor
|
39
53
|
erubis (2.7.0)
|
40
|
-
eventmachine (1.0.
|
41
|
-
faraday (0.8.
|
54
|
+
eventmachine (1.0.3)
|
55
|
+
faraday (0.8.7)
|
42
56
|
multipart-post (~> 1.1)
|
43
|
-
faraday_middleware (0.
|
57
|
+
faraday_middleware (0.9.0)
|
44
58
|
faraday (>= 0.7.4, < 0.9)
|
45
59
|
hashie (1.2.0)
|
46
60
|
hike (1.2.1)
|
47
61
|
http_parser.rb (0.5.3)
|
62
|
+
httparty (0.10.2)
|
63
|
+
multi_json (~> 1.0)
|
64
|
+
multi_xml (>= 0.5.2)
|
48
65
|
i18n (0.6.0)
|
49
66
|
journey (1.0.4)
|
50
67
|
json (1.7.3)
|
@@ -54,10 +71,11 @@ GEM
|
|
54
71
|
treetop (~> 1.4.8)
|
55
72
|
metaclass (0.0.1)
|
56
73
|
mime-types (1.19)
|
57
|
-
mocha (0.
|
74
|
+
mocha (0.13.3)
|
58
75
|
metaclass (~> 0.0.1)
|
59
76
|
multi_json (1.3.6)
|
60
|
-
|
77
|
+
multi_xml (0.5.3)
|
78
|
+
multipart-post (1.2.0)
|
61
79
|
polyglot (0.3.3)
|
62
80
|
rack (1.4.1)
|
63
81
|
rack-cache (1.2)
|
@@ -84,7 +102,25 @@ GEM
|
|
84
102
|
rake (0.9.2.2)
|
85
103
|
rdoc (3.12)
|
86
104
|
json (~> 1.4)
|
105
|
+
redis (3.0.4)
|
106
|
+
redis-namespace (1.3.0)
|
107
|
+
redis (~> 3.0.0)
|
108
|
+
resque (1.2.3)
|
109
|
+
redis
|
110
|
+
redis-namespace
|
111
|
+
rest-client (1.6.7)
|
112
|
+
mime-types (>= 1.16)
|
113
|
+
sidekiq (2.12.0)
|
114
|
+
celluloid (>= 0.14.0)
|
115
|
+
connection_pool (>= 1.0.0)
|
116
|
+
json
|
117
|
+
redis (>= 3.0)
|
118
|
+
redis-namespace
|
87
119
|
simple_oauth (0.1.9)
|
120
|
+
simplecov (0.7.1)
|
121
|
+
multi_json (~> 1.0)
|
122
|
+
simplecov-html (~> 0.7.1)
|
123
|
+
simplecov-html (0.7.1)
|
88
124
|
sprockets (2.1.3)
|
89
125
|
hike (~> 1.2)
|
90
126
|
rack (~> 1.0)
|
@@ -92,6 +128,7 @@ GEM
|
|
92
128
|
sqlite3 (1.3.6)
|
93
129
|
thor (0.15.4)
|
94
130
|
tilt (1.3.3)
|
131
|
+
timers (1.1.0)
|
95
132
|
tinder (1.9.1)
|
96
133
|
eventmachine (>= 0.12.0, < 2)
|
97
134
|
faraday (~> 0.8)
|
@@ -115,8 +152,13 @@ PLATFORMS
|
|
115
152
|
ruby
|
116
153
|
|
117
154
|
DEPENDENCIES
|
155
|
+
appraisal
|
156
|
+
coveralls (~> 0.6.5)
|
118
157
|
exception_notification!
|
119
|
-
|
158
|
+
httparty (~> 0.10.2)
|
159
|
+
mocha (>= 0.13.0)
|
120
160
|
rails (>= 3.0.4)
|
161
|
+
resque (~> 1.2.0)
|
162
|
+
sidekiq (~> 2.0)
|
121
163
|
sqlite3 (>= 1.3.4)
|
122
164
|
tinder (~> 1.8)
|
data/README.md
CHANGED
@@ -1,77 +1,112 @@
|
|
1
|
-
Exception
|
2
|
-
====
|
1
|
+
# Exception Notification
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
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)
|
7
|
+
![project status](http://stillmaintained.com/smartinez87/exception_notification.png)
|
7
8
|
|
8
|
-
|
9
|
-
environment, and also gives a backtrace of the exception.
|
9
|
+
**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.**
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
-
|
12
|
+
|
13
|
+
The Exception Notification gem provides a set of [notifiers](#notifiers) for sending notifications when errors occur in a Rack/Rails application.
|
14
|
+
|
15
|
+
The built-in notifiers can deliver notifications by [email](#email-notifier), [campfire rooms](#campfire-notifier) or via [webhooks](#webhook-notifier).
|
16
|
+
|
17
|
+
|
18
|
+
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.
|
13
19
|
|
14
20
|
[Follow us on Twitter](https://twitter.com/exception_notif) to get updates and notices about new releases.
|
15
21
|
|
16
|
-
Installation
|
17
|
-
---
|
18
22
|
|
19
|
-
|
20
|
-
|
23
|
+
## Requirements
|
24
|
+
|
25
|
+
* Ruby 1.9.3 or greater
|
26
|
+
* Rails 3.1 or greater, Sinatra or another Rack-based application.
|
27
|
+
|
28
|
+
For previous releases, please checkout [this](#versions).
|
29
|
+
|
30
|
+
|
31
|
+
## Getting Started
|
32
|
+
|
33
|
+
Add the following line to your application's Gemfile:
|
21
34
|
|
22
35
|
```ruby
|
23
36
|
gem 'exception_notification'
|
24
37
|
```
|
25
38
|
|
26
|
-
As of Rails 3 ExceptionNotification is used as a rack middleware,
|
27
|
-
configure its options on your config.ru file, or in the environment you
|
28
|
-
want it to run. In most cases you would want ExceptionNotification to
|
29
|
-
run on production. You can make it work by
|
39
|
+
As of Rails 3 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`:
|
30
40
|
|
31
41
|
```ruby
|
32
|
-
Whatever::Application.config.middleware.use
|
33
|
-
:
|
34
|
-
|
35
|
-
|
42
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
43
|
+
:email => {
|
44
|
+
:email_prefix => "[Whatever] ",
|
45
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
46
|
+
:exception_recipients => %w{exceptions@example.com}
|
47
|
+
}
|
36
48
|
```
|
37
49
|
|
38
|
-
|
39
|
-
---
|
50
|
+
> **Note**: In order delivery notifications by email make sure you have [ActionMailer configured](#actionmailer-configuration).
|
40
51
|
|
41
|
-
Additionally, ExceptionNotification supports sending notifications to
|
42
|
-
your Campfire room.
|
43
52
|
|
44
|
-
|
45
|
-
to your `Gemfile`:
|
53
|
+
In order to use ExceptionNotification with Sinatra, please take a look in the [example application](https://github.com/smartinez87/exception_notification/tree/master/examples/sinatra).
|
46
54
|
|
47
|
-
```ruby
|
48
|
-
gem 'tinder'
|
49
|
-
```
|
50
55
|
|
51
|
-
|
52
|
-
|
56
|
+
## Notifiers
|
57
|
+
|
58
|
+
ExceptionNotification relies on notifiers to deliver notifications when errors occur in your applications. By default, three notifiers are available: [email notifier](#email-notifier), [campfire notifier](#campfire-notifier) and [webhook notifier](#webhook-notifier). But, you also can easily implement your own [custom notifier](#custom-notifier).
|
59
|
+
|
60
|
+
|
61
|
+
## Email notifier
|
62
|
+
|
63
|
+
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.
|
64
|
+
|
65
|
+
After an exception notification has been delivered the rack environment variable 'exception_notifier.delivered' will be set to true.
|
66
|
+
|
67
|
+
### ActionMailer configuration
|
68
|
+
|
69
|
+
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`:
|
53
70
|
|
54
71
|
```ruby
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
72
|
+
config.action_mailer.delivery_method = :sendmail
|
73
|
+
# Defaults to:
|
74
|
+
# config.action_mailer.sendmail_settings = {
|
75
|
+
# :location => '/usr/sbin/sendmail',
|
76
|
+
# :arguments => '-i -t'
|
77
|
+
# }
|
78
|
+
config.action_mailer.perform_deliveries = true
|
79
|
+
config.action_mailer.raise_delivery_errors = true
|
60
80
|
```
|
61
81
|
|
62
|
-
|
63
|
-
[here](https://github.com/collectiveidea/tinder/blob/master/lib/tinder/campfire.rb#L17).
|
82
|
+
### Options
|
64
83
|
|
65
|
-
|
66
|
-
---
|
84
|
+
#### sender_address
|
67
85
|
|
68
|
-
|
86
|
+
*String, default: %("Exception Notifier" <exception.notifier@example.com>)*
|
69
87
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
88
|
+
Who the message is from.
|
89
|
+
|
90
|
+
|
91
|
+
#### exception_recipients
|
92
|
+
|
93
|
+
*String/Array of strings, default: []*
|
94
|
+
|
95
|
+
Who the message is destined for, can be a string of addresses, or an array of addresses.
|
96
|
+
|
97
|
+
|
98
|
+
#### email_prefix
|
99
|
+
|
100
|
+
*String, default: [ERROR]*
|
101
|
+
|
102
|
+
The subject's prefix of the message.
|
103
|
+
|
104
|
+
|
105
|
+
#### sections
|
106
|
+
|
107
|
+
*Array of strings, default: %w(request session environment backtrace)*
|
108
|
+
|
109
|
+
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:
|
75
110
|
|
76
111
|
```ruby
|
77
112
|
@kontroller # the controller that caused the error
|
@@ -82,27 +117,22 @@ access to the following variables:
|
|
82
117
|
@sections # the array of sections to include in the email
|
83
118
|
```
|
84
119
|
|
85
|
-
|
86
|
-
|
87
|
-
You can reorder the sections, or exclude sections completely, by altering the
|
88
|
-
ExceptionNotifier.sections variable. You can even add new sections that
|
89
|
-
describe application-specific data--just add the section's name to the list
|
90
|
-
(wherever you'd like), and define the corresponding partial.
|
120
|
+
You can reorder the sections, or exclude sections completely, by using `sections` option. You can even add new sections that
|
121
|
+
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:
|
91
122
|
|
92
123
|
```ruby
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
124
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
125
|
+
:email => {
|
126
|
+
:email_prefix => "[Whatever] ",
|
127
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
128
|
+
:exception_recipients => %w{exceptions@example.com},
|
129
|
+
:sections => %w{my_section1 my_section2}
|
130
|
+
}
|
99
131
|
```
|
100
132
|
|
101
|
-
Place your custom sections under `./app/views/exception_notifier/` with the suffix `.text.erb`, e.g.
|
102
|
-
`./app/views/exception_notifier/_my_section1.text.erb`.
|
133
|
+
Place your custom sections under `./app/views/exception_notifier/` with the suffix `.text.erb`, e.g. `./app/views/exception_notifier/_my_section1.text.erb`.
|
103
134
|
|
104
|
-
If your new section requires information that isn't available by default, make sure
|
105
|
-
it is made available to the email using the exception_data macro:
|
135
|
+
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:
|
106
136
|
|
107
137
|
```ruby
|
108
138
|
class ApplicationController < ActionController::Base
|
@@ -119,151 +149,355 @@ class ApplicationController < ActionController::Base
|
|
119
149
|
end
|
120
150
|
```
|
121
151
|
|
122
|
-
In the above case,
|
123
|
-
|
124
|
-
|
152
|
+
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.
|
153
|
+
|
154
|
+
|
155
|
+
#### background_sections
|
156
|
+
|
157
|
+
*Array of strings, default: %w(backtrace data)*
|
158
|
+
|
159
|
+
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:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
163
|
+
:email => {
|
164
|
+
:email_prefix => "[Whatever] ",
|
165
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
166
|
+
:exception_recipients => %w{exceptions@example.com},
|
167
|
+
:background_sections => %w{my_section1 my_section2 backtrace data}
|
168
|
+
}
|
169
|
+
```
|
170
|
+
|
171
|
+
|
172
|
+
#### email_headers
|
125
173
|
|
126
|
-
|
174
|
+
*Hash os strings, default: {}*
|
175
|
+
|
176
|
+
Additionally, you may want to set customized headers on the outcoming emails. To do so, simply use the `:email_headers` option:
|
127
177
|
|
128
178
|
```ruby
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
179
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
180
|
+
:email => {
|
181
|
+
:email_prefix => "[Whatever] ",
|
182
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
183
|
+
:exception_recipients => %w{exceptions@example.com},
|
184
|
+
:email_headers => { "X-Custom-Header" => "foobar" }
|
185
|
+
}
|
135
186
|
```
|
136
187
|
|
137
|
-
By default, the backtrace and data sections are included in background
|
138
|
-
notifications.
|
139
188
|
|
140
|
-
|
189
|
+
#### verbose_subject
|
190
|
+
|
191
|
+
*Boolean, default: true*
|
192
|
+
|
193
|
+
If enabled, include the exception message in the subject. Use `:verbose_subject => false` to exclude it.
|
194
|
+
|
141
195
|
|
142
|
-
|
143
|
-
ExceptionNotifier avoid sending notifications for those specified.
|
144
|
-
There are three ways of specifying which exceptions to ignore:
|
196
|
+
#### normalize_subject
|
145
197
|
|
146
|
-
|
198
|
+
*Boolean, default: false*
|
147
199
|
|
148
|
-
|
200
|
+
If enabled, remove numbers from subject so they thread as a single one. Use `:normalize_subject => true` to enable it.
|
149
201
|
|
150
|
-
- `:ignore_if` - Custom (i.e. ignore exceptions that satisfy some condition)
|
151
202
|
|
152
|
-
|
203
|
+
#### email_format
|
153
204
|
|
154
|
-
*
|
205
|
+
*Symbol, default: :text*
|
155
206
|
|
156
|
-
|
157
|
-
|
207
|
+
By default, ExceptionNotification sends emails in plain text, in order to sends multipart notifications (aka HTML emails) use `:email_format => :html`.
|
208
|
+
|
209
|
+
|
210
|
+
#### delivery_method
|
211
|
+
|
212
|
+
*Symbol, default: :smtp*
|
213
|
+
|
214
|
+
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:
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
218
|
+
:email => {
|
219
|
+
:email_prefix => "[Whatever] ",
|
220
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
221
|
+
:exception_recipients => %w{exceptions@example.com},
|
222
|
+
:delivery_method => :postmark,
|
223
|
+
:postmark_settings => {
|
224
|
+
:api_key => ENV["POSTMARK_API_KEY"]
|
225
|
+
}
|
226
|
+
}
|
227
|
+
```
|
228
|
+
|
229
|
+
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:
|
158
230
|
|
159
231
|
```ruby
|
160
|
-
Whatever::Application.config.middleware.use
|
161
|
-
:
|
162
|
-
|
163
|
-
|
164
|
-
|
232
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
233
|
+
:email => {
|
234
|
+
:email_prefix => "[Whatever] ",
|
235
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
236
|
+
:exception_recipients => %w{exceptions@example.com},
|
237
|
+
:delivery_method => :stmp,
|
238
|
+
:smtp_settings => {
|
239
|
+
:user_name => "bob",
|
240
|
+
:password => "password",
|
241
|
+
}
|
242
|
+
}
|
165
243
|
```
|
166
244
|
|
167
|
-
The above will make ExceptionNotifier ignore a *TemplateError*
|
168
|
-
exception, plus the ones ignored by default.
|
169
|
-
By default, ExceptionNotifier ignores _ActiveRecord::RecordNotFound_,
|
170
|
-
_AbstractController::ActionNotFound_ and
|
171
|
-
_ActionController::RountingError_.
|
172
245
|
|
173
|
-
|
246
|
+
#### mailer_parent
|
174
247
|
|
175
|
-
|
176
|
-
|
248
|
+
*String, default: ActionMailer::Base*
|
249
|
+
|
250
|
+
The parent mailer which ExceptionNotification mailer inherit from.
|
251
|
+
|
252
|
+
|
253
|
+
## Campfire notifier
|
254
|
+
|
255
|
+
This notifier sends notifications to your Campfire room.
|
256
|
+
|
257
|
+
### Usage
|
258
|
+
|
259
|
+
Just add the [tinder](https://github.com/collectiveidea/tinder) gem to your `Gemfile`:
|
177
260
|
|
178
261
|
```ruby
|
179
|
-
|
180
|
-
:email_prefix => "[Whatever] ",
|
181
|
-
:sender_address => %{"notifier" <notifier@example.com>},
|
182
|
-
:exception_recipients => %w{exceptions@example.com},
|
183
|
-
:ignore_crawlers => %w{Googlebot bingbot}
|
262
|
+
gem 'tinder'
|
184
263
|
```
|
185
264
|
|
186
|
-
|
265
|
+
To configure it, you need to set the `subdomain`, `token` and `room_name` options, like this:
|
266
|
+
|
267
|
+
```ruby
|
268
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
269
|
+
:email => {
|
270
|
+
:email_prefix => "[Whatever] ",
|
271
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
272
|
+
:exception_recipients => %w{exceptions@example.com}
|
273
|
+
},
|
274
|
+
:campfire => {
|
275
|
+
:subdomain => 'my_subdomain',
|
276
|
+
:token => 'my_token',
|
277
|
+
:room_name => 'my_room'
|
278
|
+
}
|
279
|
+
```
|
280
|
+
|
281
|
+
### Options
|
282
|
+
|
283
|
+
#### subdomain
|
284
|
+
|
285
|
+
*String, required*
|
286
|
+
|
287
|
+
Your subdomain at Campfire.
|
288
|
+
|
289
|
+
#### room_name
|
290
|
+
|
291
|
+
*String, required*
|
292
|
+
|
293
|
+
The Campfire room where the notifications must be published to.
|
294
|
+
|
295
|
+
#### token
|
187
296
|
|
188
|
-
*
|
297
|
+
*String, required*
|
189
298
|
|
190
|
-
|
299
|
+
The API token to allow access to your Campfire account.
|
300
|
+
|
301
|
+
|
302
|
+
For more options to set Campfire, like _ssl_, check [here](https://github.com/collectiveidea/tinder/blob/master/lib/tinder/campfire.rb#L17).
|
303
|
+
|
304
|
+
|
305
|
+
## Webhook notifier
|
306
|
+
|
307
|
+
This notifier ships notifications over the HTTP protocol.
|
308
|
+
|
309
|
+
### Usage
|
310
|
+
|
311
|
+
Just add the [HTTParty](https://github.com/jnunemaker/httparty) gem to your `Gemfile`:
|
312
|
+
|
313
|
+
```ruby
|
314
|
+
gem 'httparty'
|
315
|
+
```
|
316
|
+
|
317
|
+
To configure it, you need to set the `url` option, like this:
|
191
318
|
|
192
319
|
```ruby
|
193
|
-
Whatever::Application.config.middleware.use
|
194
|
-
:
|
195
|
-
|
196
|
-
|
197
|
-
|
320
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
321
|
+
:email => {
|
322
|
+
:email_prefix => "[Whatever] ",
|
323
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
324
|
+
:exception_recipients => %w{exceptions@example.com}
|
325
|
+
},
|
326
|
+
:webhook => {
|
327
|
+
:url => 'http://domain.com:5555/hubot/path'
|
328
|
+
}
|
198
329
|
```
|
199
330
|
|
200
|
-
|
201
|
-
avoid or not sending the notification.
|
331
|
+
By default, the WebhookNotifier will call the URLs using the POST method. But, you can change this using the `http_method` option.
|
202
332
|
|
203
|
-
|
333
|
+
```ruby
|
334
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
335
|
+
:email => {
|
336
|
+
:email_prefix => "[Whatever] ",
|
337
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
338
|
+
:exception_recipients => %w{exceptions@example.com}
|
339
|
+
},
|
340
|
+
:webhook => {
|
341
|
+
:url => 'http://domain.com:5555/hubot/path',
|
342
|
+
:http_method => :get
|
343
|
+
}
|
344
|
+
```
|
204
345
|
|
205
|
-
|
206
|
-
emails. To do so, simply use the _:email_headers_ option:
|
346
|
+
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:
|
207
347
|
|
208
348
|
```ruby
|
209
|
-
Whatever::Application.config.middleware.use
|
210
|
-
:
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
349
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
350
|
+
:email => {
|
351
|
+
:email_prefix => "[Whatever] ",
|
352
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
353
|
+
:exception_recipients => %w{exceptions@example.com}
|
354
|
+
},
|
355
|
+
:webhook => {
|
356
|
+
:url => 'http://domain.com:5555/hubot/path',
|
357
|
+
:basic_auth => {
|
358
|
+
:username => 'alice',
|
359
|
+
:password => 'password'
|
360
|
+
}
|
361
|
+
}
|
215
362
|
```
|
216
363
|
|
217
|
-
|
364
|
+
For more HTTParty options, check out the [documentation](https://github.com/jnunemaker/httparty).
|
365
|
+
|
366
|
+
|
367
|
+
## Custom notifier
|
368
|
+
|
369
|
+
Simply put, notifiers are objects which respond to `#call(exception, options)` method. Thus, a lambda can be used as a notifier as follow:
|
370
|
+
|
371
|
+
```ruby
|
372
|
+
ExceptionNotifier.add_notifier :custom_notifier_name,
|
373
|
+
->(exception, options) { puts "Something goes wrong: #{exception.message}"}
|
374
|
+
```
|
375
|
+
|
376
|
+
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.
|
377
|
+
|
378
|
+
### Example
|
379
|
+
|
380
|
+
Define the custom notifier:
|
381
|
+
|
382
|
+
```ruby
|
383
|
+
module ExceptionNotifier
|
384
|
+
class SimpleNotifier
|
385
|
+
def initialize(options)
|
386
|
+
# do something with the options...
|
387
|
+
end
|
388
|
+
|
389
|
+
def call(exception, options={})
|
390
|
+
# send the notification
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
394
|
+
```
|
395
|
+
|
396
|
+
Using it:
|
397
|
+
|
398
|
+
```ruby
|
399
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
400
|
+
:email => {
|
401
|
+
:email_prefix => "[Whatever] ",
|
402
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
403
|
+
:exception_recipients => %w{exceptions@example.com}
|
404
|
+
},
|
405
|
+
:simple => {
|
406
|
+
# simple notifier options
|
407
|
+
}
|
408
|
+
```
|
409
|
+
|
410
|
+
|
411
|
+
## Ignore Exceptions
|
218
412
|
|
219
|
-
You can
|
220
|
-
Use _:verbose_subject => false_ to exclude it.
|
413
|
+
You can choose to ignore certain exceptions, which will make ExceptionNotification avoid sending notifications for those specified. There are three ways of specifying which exceptions to ignore:
|
221
414
|
|
222
|
-
|
415
|
+
* `:ignore_exceptions` - By exception class (i.e. ignore RecordNotFound ones)
|
223
416
|
|
224
|
-
|
225
|
-
This is disabled by default.
|
226
|
-
Use _:normalize_subject => true_ to enable it.
|
417
|
+
* `:ignore_crawlers` - From crawler (i.e. ignore ones originated by Googlebot)
|
227
418
|
|
228
|
-
|
419
|
+
* `:ignore_if` - Custom (i.e. ignore exceptions that satisfy some condition)
|
229
420
|
|
230
|
-
You may want to send multipart notifications instead of just plain text, which ExceptionNotification sends by default.
|
231
|
-
You can do so by adding this to the configuration: _:email_format => :html_.
|
232
421
|
|
422
|
+
### :ignore_exceptions
|
233
423
|
|
234
|
-
|
235
|
-
---
|
424
|
+
*Array of strings, default: %w{ActiveRecord::RecordNotFound AbstractController::ActionNotFound ActionController::RoutingError}*
|
236
425
|
|
237
|
-
|
238
|
-
|
239
|
-
|
426
|
+
Ignore specified exception types. To achieve that, you should use the `:ignore_exceptions` option, like this:
|
427
|
+
|
428
|
+
```ruby
|
429
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
430
|
+
:ignore_exceptions => ['ActionView::TemplateError'] + ExceptionNotifier.ignored_exceptions,
|
431
|
+
:email => {
|
432
|
+
:email_prefix => "[Whatever] ",
|
433
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
434
|
+
:exception_recipients => %w{exceptions@example.com}
|
435
|
+
}
|
436
|
+
```
|
437
|
+
|
438
|
+
The above will make ExceptionNotifier ignore a *TemplateError* exception, plus the ones ignored by default.
|
439
|
+
|
440
|
+
### :ignore_crawlers
|
441
|
+
|
442
|
+
*Array of strings, default: []*
|
443
|
+
|
444
|
+
In some cases you may want to avoid getting notifications from exceptions made by crawlers. To prevent sending those unwanted notifications, use the `:ignore_crawlers` option like this:
|
445
|
+
|
446
|
+
```ruby
|
447
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
448
|
+
:ignore_crawlers => %w{Googlebot bingbot},
|
449
|
+
:email => {
|
450
|
+
:email_prefix => "[Whatever] ",
|
451
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
452
|
+
:exception_recipients => %w{exceptions@example.com}
|
453
|
+
}
|
454
|
+
```
|
455
|
+
|
456
|
+
### :ignore_if
|
457
|
+
|
458
|
+
*Lambda, default: nil*
|
459
|
+
|
460
|
+
Last but not least, you can ignore exceptions based on a condition. Take a look:
|
461
|
+
|
462
|
+
```ruby
|
463
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
464
|
+
:ignore_if => ->(env, exception) { exception.message =~ /^Couldn't find Page with ID=/ },
|
465
|
+
:email => {
|
466
|
+
:email_prefix => "[Whatever] ",
|
467
|
+
:sender_address => %{"notifier" <notifier@example.com>},
|
468
|
+
:exception_recipients => %w{exceptions@example.com},
|
469
|
+
}
|
470
|
+
```
|
471
|
+
|
472
|
+
You can make use of both the environment and the exception inside the lambda to decide wether to avoid or not sending the notification.
|
473
|
+
|
474
|
+
|
475
|
+
## Background Notifications
|
476
|
+
|
477
|
+
If you want to send notifications from a background process like DelayedJob, you should use the `notify_exception` method like this:
|
240
478
|
|
241
479
|
```ruby
|
242
480
|
begin
|
243
481
|
some code...
|
244
482
|
rescue => e
|
245
|
-
ExceptionNotifier
|
483
|
+
ExceptionNotifier.notify_exception(e)
|
246
484
|
end
|
247
485
|
```
|
248
486
|
|
249
|
-
You can include information about the background process that created
|
250
|
-
the error by including a data parameter:
|
487
|
+
You can include information about the background process that created the error by including a data parameter:
|
251
488
|
|
252
489
|
```ruby
|
253
490
|
begin
|
254
491
|
some code...
|
255
492
|
rescue => exception
|
256
|
-
ExceptionNotifier
|
257
|
-
:data => {:worker => worker.to_s, :queue => queue, :payload => payload})
|
493
|
+
ExceptionNotifier.notify_exception(exception,
|
494
|
+
:data => {:worker => worker.to_s, :queue => queue, :payload => payload})
|
258
495
|
end
|
259
496
|
```
|
260
497
|
|
498
|
+
### Manually notify of exception
|
261
499
|
|
262
|
-
|
263
|
-
---
|
264
|
-
|
265
|
-
If your controller action manually handles an error, the notifier will never be
|
266
|
-
run. To manually notify of an error you can do something like the following:
|
500
|
+
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:
|
267
501
|
|
268
502
|
```ruby
|
269
503
|
rescue_from Exception, :with => :server_error
|
@@ -271,69 +505,68 @@ rescue_from Exception, :with => :server_error
|
|
271
505
|
def server_error(exception)
|
272
506
|
# Whatever code that handles the exception
|
273
507
|
|
274
|
-
ExceptionNotifier
|
275
|
-
:data => {:message => "was doing something wrong"})
|
508
|
+
ExceptionNotifier.notify_exception(exception,
|
509
|
+
:env => request.env, :data => {:message => "was doing something wrong"})
|
276
510
|
end
|
277
511
|
```
|
278
512
|
|
279
|
-
Notification
|
280
|
-
---
|
281
513
|
|
282
|
-
|
283
|
-
'exception_notifier.delivered' will be set to `true`.
|
514
|
+
## Extras
|
284
515
|
|
516
|
+
### Rails
|
285
517
|
|
286
|
-
|
287
|
-
---
|
518
|
+
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:
|
288
519
|
|
289
|
-
|
520
|
+
rails g exception_notification:install
|
290
521
|
|
291
|
-
|
292
|
-
Whatever::Application.config.middleware.use ExceptionNotifier,
|
293
|
-
:email_prefix => "[Whatever] ",
|
294
|
-
:sender_address => %{"notifier" <notifier@example.com>},
|
295
|
-
:exception_recipients => %w{exceptions@example.com},
|
296
|
-
:smtp_settings => {
|
297
|
-
:user_name => "bob",
|
298
|
-
:password => "password",
|
299
|
-
}
|
300
|
-
```
|
522
|
+
This command generates an initialize file (`config/initializers/exception_notification.rb`) where you can customize your configurations.
|
301
523
|
|
302
|
-
Versions
|
303
|
-
---
|
304
524
|
|
305
|
-
|
525
|
+
### Resque/Sidekiq
|
306
526
|
|
307
|
-
|
527
|
+
Instead of manually calling background notifications foreach job/worker, you can configure ExceptionNotification to do this automatically. For this, run:
|
528
|
+
|
529
|
+
rails g exception_notification:install --resque
|
308
530
|
|
309
|
-
|
531
|
+
or
|
310
532
|
|
311
|
-
|
533
|
+
rails g exception_notification:install --sidekiq
|
312
534
|
|
313
|
-
<a href="http://github.com/smartinez87/exception_notification/tree/v2.6.0">http://github.com/smartinez87/exception_notification/tree/v2.6.0</a>
|
314
535
|
|
315
|
-
|
536
|
+
## Versions
|
316
537
|
|
317
|
-
|
538
|
+
For v3.0.1, see this tag:
|
539
|
+
|
540
|
+
http://github.com/smartinez87/exception_notification/tree/v3.0.1
|
541
|
+
|
542
|
+
For v3.0.0, see this tag:
|
543
|
+
|
544
|
+
http://github.com/smartinez87/exception_notification/tree/v3.0.0
|
545
|
+
|
546
|
+
For v2.6.1, see this tag:
|
547
|
+
|
548
|
+
http://github.com/smartinez87/exception_notification/tree/v2.6.1
|
318
549
|
|
319
550
|
For previous releases, visit:
|
320
551
|
|
321
|
-
|
552
|
+
https://github.com/smartinez87/exception_notification/tags
|
322
553
|
|
323
554
|
If you are running Rails 2.3 then see the branch for that:
|
324
555
|
|
325
|
-
|
556
|
+
http://github.com/smartinez87/exception_notification/tree/2-3-stable
|
326
557
|
|
327
558
|
If you are running pre-rack Rails then see this tag:
|
328
559
|
|
329
|
-
|
560
|
+
http://github.com/smartinez87/exception_notification/tree/pre-2-3
|
561
|
+
|
330
562
|
|
331
|
-
Support and tickets
|
332
|
-
---
|
563
|
+
## Support and tickets
|
333
564
|
|
334
565
|
Here's the list of [issues](https://github.com/smartinez87/exception_notification/issues) we're currently working on.
|
335
566
|
|
336
|
-
To contribute, please read first the [Contributing
|
337
|
-
|
567
|
+
To contribute, please read first the [Contributing Guide](https://github.com/smartinez87/exception_notification/blob/master/CONTRIBUTING.md).
|
568
|
+
|
569
|
+
|
570
|
+
## License
|
338
571
|
|
339
|
-
Copyright (c) 2005 Jamis Buck, released under the MIT license
|
572
|
+
Copyright (c) 2005 Jamis Buck, released under the [MIT license](http://www.opensource.org/licenses/MIT).
|