Skip to content

Commit e675f56

Browse files
committed
1 parent f8b9e12 commit e675f56

File tree

4 files changed

+8
-363
lines changed

4 files changed

+8
-363
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
exception_notification (4.6.0)
4+
exception_notification (4.6.1)
55
actionmailer (>= 5.2, < 9)
66
activesupport (>= 5.2, < 9)
77

README.md

Lines changed: 3 additions & 361 deletions
Original file line numberDiff line numberDiff line change
@@ -1,364 +1,6 @@
11
# Exception Notification
22

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)
3+
## This gem has moved to:
4+
## [https://github.com/kmcphillips/exception_notification](https://github.com/kmcphillips/exception_notification)
75

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-
10-
---
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](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-
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-
16-
[Follow us on Twitter](https://twitter.com/exception_notif) to get updates and notices about new releases.
17-
18-
## Requirements
19-
20-
* Ruby 2.5 or greater
21-
* Rails 5.2 or greater, Sinatra or another Rack-based application.
22-
23-
## Getting Started
24-
25-
Add the following line to your application's Gemfile:
26-
27-
```ruby
28-
gem 'exception_notification'
29-
```
30-
31-
### Rails
32-
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" <[email protected]>},
60-
exception_recipients: %w{[email protected]}
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:
69-
70-
```ruby
71-
Rails.application.config.middleware.use ExceptionNotification::Rack,
72-
email: {
73-
email_prefix: '[PREFIX] ',
74-
sender_address: %{"notifier" <[email protected]>},
75-
exception_recipients: %w{[email protected]}
76-
}
77-
```
78-
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-
83-
84-
### Rack/Sinatra
85-
86-
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).
87-
88-
### Custom Data, e.g. Current User
89-
90-
Save the current user in the `request` using a controller callback.
91-
92-
```ruby
93-
class ApplicationController < ActionController::Base
94-
before_action :prepare_exception_notifier
95-
96-
private
97-
98-
def prepare_exception_notifier
99-
request.env["exception_notifier.exception_data"] = {
100-
current_user: current_user
101-
}
102-
end
103-
end
104-
```
105-
106-
The current user will show up in your email, in a new section titled "Data".
107-
108-
```
109-
------------------------------- Data:
110-
111-
* data: {:current_user=>
112-
#<User:0x007ff03c0e5860
113-
id: 3,
114-
email: "[email protected]", # etc...
115-
```
116-
117-
For more control over the display of custom data, see "Email notifier ->
118-
Options -> sections" below.
119-
120-
## Notifiers
121-
122-
ExceptionNotification relies on notifiers to deliver notifications when errors occur in your applications. By default, 8 notifiers are available:
123-
124-
* [Datadog notifier](docs/notifiers/datadog.md)
125-
* [Email notifier](docs/notifiers/email.md)
126-
* [HipChat notifier](docs/notifiers/hipchat.md)
127-
* [IRC notifier](docs/notifiers/irc.md)
128-
* [Slack notifier](docs/notifiers/slack.md)
129-
* [Mattermost notifier](docs/notifiers/mattermost.md)
130-
* [Teams notifier](docs/notifiers/teams.md)
131-
* [Amazon SNS](docs/notifiers/sns.md)
132-
* [Google Chat notifier](docs/notifiers/google_chat.md)
133-
* [WebHook notifier](docs/notifiers/webhook.md)
134-
135-
But, you also can easily implement your own [custom notifier](docs/notifiers/custom.md).
136-
137-
## Error Grouping
138-
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`.
140-
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.
142-
143-
The following code shows the available options to configure error grouping:
144-
145-
```ruby
146-
Rails.application.config.middleware.use ExceptionNotification::Rack,
147-
ignore_exceptions: ['ActionView::TemplateError'] + ExceptionNotifier.ignored_exceptions,
148-
email: {
149-
email_prefix: '[PREFIX] ',
150-
sender_address: %{"notifier" <[email protected]>},
151-
exception_recipients: %w{[email protected]}
152-
},
153-
error_grouping: true,
154-
# error_grouping_period: 5.minutes, # the time before an error is regarded as fixed
155-
# error_grouping_cache: Rails.cache, # for other applications such as Sinatra, use one instance of ActiveSupport::Cache::Store
156-
#
157-
# notification_trigger: specify a callback to determine when a notification should be sent,
158-
# the callback will be invoked with two arguments:
159-
# exception: the exception raised
160-
# count: accumulated errors count for this exception
161-
#
162-
# notification_trigger: lambda { |exception, count| count % 10 == 0 }
163-
```
164-
165-
## Ignore Exceptions
166-
167-
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:
168-
169-
* `:ignore_exceptions` - By exception class (i.e. ignore RecordNotFound ones)
170-
171-
* `:ignore_crawlers` - From crawler (i.e. ignore ones originated by Googlebot)
172-
173-
* `:ignore_if` - Custom (i.e. ignore exceptions that satisfy some condition)
174-
175-
* `:ignore_notifer_if` - Custom (i.e. let each notifier ignore exceptions if by-notifier condition is satisfied)
176-
177-
178-
### :ignore_exceptions
179-
180-
*Array of strings, default: %w{ActiveRecord::RecordNotFound Mongoid::Errors::DocumentNotFound AbstractController::ActionNotFound ActionController::RoutingError ActionController::UnknownFormat}*
181-
182-
Ignore specified exception types. To achieve that, you should use the `:ignore_exceptions` option, like this:
183-
184-
```ruby
185-
Rails.application.config.middleware.use ExceptionNotification::Rack,
186-
ignore_exceptions: ['ActionView::TemplateError'] + ExceptionNotifier.ignored_exceptions,
187-
email: {
188-
email_prefix: '[PREFIX] ',
189-
sender_address: %{"notifier" <[email protected]>},
190-
exception_recipients: %w{[email protected]}
191-
}
192-
```
193-
194-
The above will make ExceptionNotifier ignore a *TemplateError* exception, plus the ones ignored by default.
195-
196-
### :ignore_crawlers
197-
198-
*Array of strings, default: []*
199-
200-
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:
201-
202-
```ruby
203-
Rails.application.config.middleware.use ExceptionNotification::Rack,
204-
ignore_crawlers: %w{Googlebot bingbot},
205-
email: {
206-
email_prefix: '[PREFIX] ',
207-
sender_address: %{"notifier" <[email protected]>},
208-
exception_recipients: %w{[email protected]}
209-
}
210-
```
211-
212-
### :ignore_if
213-
214-
*Lambda, default: nil*
215-
216-
You can ignore exceptions based on a condition. Take a look:
217-
218-
```ruby
219-
Rails.application.config.middleware.use ExceptionNotification::Rack,
220-
ignore_if: ->(env, exception) { exception.message =~ /^Couldn't find Page with ID=/ },
221-
email: {
222-
email_prefix: '[PREFIX] ',
223-
sender_address: %{"notifier" <[email protected]>},
224-
exception_recipients: %w{[email protected]},
225-
}
226-
```
227-
228-
You can make use of both the environment and the exception inside the lambda to decide wether to avoid or not sending the notification.
229-
230-
### :ignore_notifier_if
231-
232-
* Hash of Lambda, default: nil*
233-
234-
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.
235-
By setting below, each notifier will ignore exceptions when its corresponding condition is met.
236-
237-
```ruby
238-
Rails.application.config.middleware.use ExceptionNotification::Rack,
239-
ignore_notifier_if: {
240-
email: ->(env, exception) { !Rails.env.production? },
241-
slack: ->(env, exception) { exception.message =~ /^Couldn't find Page with ID=/ }
242-
},
243-
244-
email: {
245-
sender_address: %{"notifier" <[email protected]>},
246-
exception_recipients: %w{[email protected]}
247-
},
248-
slack: {
249-
webhook_url: '[Your webhook url]',
250-
channel: '#exceptions',
251-
}
252-
```
253-
254-
To customize each condition, you can make use of environment and the exception object inside the lambda.
255-
256-
## Rack X-Cascade Header
257-
258-
Some rack apps (Rails in particular) utilize the "X-Cascade" header to pass the request-handling responsibility to the next middleware in the stack.
259-
260-
Rails' routing middleware uses this strategy, rather than raising an exception, to handle routing errors (e.g. 404s); to be notified whenever a 404 occurs, set this option to "false."
261-
262-
### :ignore_cascade_pass
263-
264-
*Boolean, default: true*
265-
266-
Set to false to trigger notifications when another rack middleware sets the "X-Cascade" header to "pass."
267-
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.)
285-
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:
299-
300-
```ruby
301-
begin
302-
# some code...
303-
rescue => e
304-
ExceptionNotifier.notify_exception(e)
305-
end
306-
```
307-
308-
You can include information about the background process that created the error by including a `data` parameter:
309-
310-
```ruby
311-
begin
312-
# some code...
313-
rescue => e
314-
ExceptionNotifier.notify_exception(
315-
e,
316-
data: { worker: worker.to_s, queue: queue, payload: payload}
317-
)
318-
end
319-
```
320-
321-
### Resque/Sidekiq
322-
323-
Instead of manually calling background notifications for each job/worker, you can configure ExceptionNotification to do this automatically. For this, run:
324-
325-
rails g exception_notification:install --resque
326-
327-
or
328-
329-
rails g exception_notification:install --sidekiq
330-
331-
As above, make sure the gem is not listed solely under the `production` group, since this initializer will be loaded regardless of environment.
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-
352-
## Support and tickets
353-
354-
Here's the list of [issues](https://github.com/smartinez87/exception_notification/issues) we're currently working on.
355-
356-
To contribute, please read first the [Contributing Guide](https://github.com/smartinez87/exception_notification/blob/master/CONTRIBUTING.md).
357-
358-
## Code of Conduct
359-
360-
Everyone interacting in this project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow our [code of conduct](https://github.com/smartinez87/exception_notification/blob/master/CODE_OF_CONDUCT.md).
361-
362-
## License
363-
364-
Copyright (c) 2005 Jamis Buck, released under the [MIT license](http://www.opensource.org/licenses/MIT).
6+
All development and releases are now happening on that fork. The gem is actively being maintained and pushed to rubygems under the `exception_notification` gem name.

exception_notification.gemspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Gem::Specification.new do |s|
2020
s.test_files = `git ls-files -- test`.split("\n")
2121
s.require_path = 'lib'
2222

23+
s.post_install_message = "The `exception_notification` gem has moved.
24+
This repo is no longer maintained and all development should move to: https://github.com/kmcphillips/exception_notification"
25+
2326
s.add_dependency('actionmailer', '>= 5.2', '< 9')
2427
s.add_dependency('activesupport', '>= 5.2', '< 9')
2528

lib/exception_notification/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module ExceptionNotification
4-
VERSION = '4.6.0'
4+
VERSION = '4.6.1'
55
end

0 commit comments

Comments
 (0)