Exception Notifier - Ruby on Rails plugin

written August 31 2006 by
Kommen
tagged with
, ,
23 Comments so far. Go, post one!
Installing Mongrel on OS X Next
Migrations in Ruby on Rails
State of Web Development 2006
Install Mongrel on Ubuntu 6.06 Dapper
Parse natural language date/time strings in Ruby with Chronic

Yesterday I came over Exception Notifier.

I found it really useful because it is really easy to install and you can instantly react to Application Errors. Your customers don’t have to notify you because you get a bunch of information to track the error via email.

3 easy steps are necessary to set up Exception Notifier:

1. Install the exception_notification plugin:
ruby script/plugin install exception_notification

2. Configure exception_notification:
Add following line to your config/environment.rb file:


ExceptionNotifier.exception_recipients = %w(youremailaddress.com)@

3. Tell the Exception Notifier for which controller it shoud send exception notifications to you.
In this example it will send notifications for all exceptions:

1 class ApplicationController < ActionController::Base
2     include ExceptionNotifiable 
3 end

Thats it! Now you will be notified when an error rises.

NOTE: If your server can’t send mails, you have to configure your Rails app for sending mails!
See here in section “Configuration”.

For advanced configuration read here.

By the way, “soaked and soaped” is our new blog.

23 Comments

Make our day bright and participate!
Permalink to this comment { Jeroen van Doorn }
on September 05 2006 (about 09:18 AM)

Wow, this really looks cool. I’ll definitly gonna use this in my next project.

Permalink to this comment { Yeah wow but it does not work }
on November 01 2006 (about 22:14 PM)

I installed your plugin and configured, aslo a have configured my ActionMailer::Base.server_settings in config/environment.r, but still do not send any messages on errors. My others notifications works fine.
What yet I need to get this works

Permalink to this comment { Bug? not bug ? }
on January 15 2007 (about 21:06 PM)

Dieter Komendera forgot to tell us that, this plugin works only for production not developmen.
Its a bug ?. I would like to have this work for develpment too .. I do not know How you guys ?

Permalink to this comment { Kommen }
on January 15 2007 (about 21:14 PM)

It should also work in development mode (But I havn’t tried it actually). Maybe you have an error but it doesn’t get displayed in development mode because of this line in the development.rb in config/environments:

<pre>

  1. Don’t care if the mailer can’t send
    config.action_mailer.raise_delivery_errors = false
    </pre></code>

Try again after changing this to true.

Permalink to this comment { Micah }
on January 20 2007 (about 16:43 PM)

I have the raise_delivery_errors set to true, and I still get nothing. :(

Permalink to this comment { Micah }
on January 20 2007 (about 17:03 PM)

I looked a little closer and found that indeed, it is configured to only work in production environments, or at least on a production server.

The method where exceptions are caught and e-mailed is rescue_action_in_public, which is documented here: http://api.rubyonrails.org/classes/ActionController/Rescue.html#M000087

As far as I can tell, this is never called when debugging locally.

Permalink to this comment { Rugger }
on February 01 2007 (about 17:31 PM)

I think you need to set config.action_controller.consider_all_requests_local to false. You will no longer get debugging information in your browser, though.

Permalink to this comment { Kem Mason }
on February 16 2007 (about 03:19 AM)

I followed the instructions, but I get the following error:
/usr/lib64/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:266:in `load_missing_constant’: uninitialized constant ExceptionNotifier (NameError)

not sure what the problem is :(

Permalink to this comment { Dan }
on February 22 2007 (about 17:29 PM)

Kem – I also received that error when I placed the ExceptionNotifier configuration settings in production.rb (or development.rb) instead of environment.rb.

Permalink to this comment { Kem Mason }
on March 04 2007 (about 23:44 PM)

figured out my problem Dan — you need to put the configuration settings at the bottom of the environment.rb file — could probably also do a #require.

what I’ve got at this point, to allow different recipients in different environments is:

#this line goes in the individual .rb file (production.rb / development.rb)
$exception_recipients = %w(root@localhost)

#then the following line in the environment.rb file
ExceptionNotifier.exception_recipients = $exception_recipients

Permalink to this comment { reader }
on March 22 2007 (about 22:48 PM)

boys. do you read the infos about what you are using?
a simple readme file clears all.

http://dev.rubyonrails.org/browser/plugins/exception_notification/README

… Email notifications will only occur when the IP address is determined not to be local….
… if you wanted “127.0.0.1” to NOT be considered local…

=> local_addresses.clear

btw: (checked in by minam, 1 year ago)

just my cent

;)

Permalink to this comment { Paulnva }
on July 17 2007 (about 23:24 PM)

have installed the exception_notification plugin, and it works fine

when system is deployed to production. and I have not problems
deploying to dev, and not test environments. However, when I try to do
a deploy_with_migrations, I get the uninitialized constant
ApplicationController::ExceptionNotifiable error.

There must be something ‘special’ about the test env, but I haven’t
seen anything to tell me to set env any differently. I really don’t
want notifications in test, but don’t want to disable for the other
environments.

So, I don’t have a rails test environment.

Thanks for any help.

Cheers,
Paul

Permalink to this comment { Jason }
on August 01 2007 (about 07:55 AM)

@reader, although the README does say you can use local_addresses.clear, it doesn’t work. The method that does the sending never gets hit.

The solution that worked for me (getting mail in dev mode) was to edit the development.rb to change
config.action_controller.consider_all_requests_local = true
to
config.action_controller.consider_all_requests_local = false

Of course that’s only for testing the email. I changed it back once I knew the plugin was working so I can see some debug info in my browser.

Permalink to this comment { Brian McQuay }
on August 08 2007 (about 19:39 PM)

This is just the plugin I’ve been looking for. I’m excited to try it out.

Permalink to this comment { Brian }
on August 23 2007 (about 05:46 AM)

I set
config.action_controller.consider_all_requests_local=true
config.action_mailer.raise_delivery_errors = true
in my development environment.

I set up the recipient in environment.rb

in my controller,
raise IndexError, ‘test’

I am not seeing any action mailer delivery error(which I should).

what’s wrong?

Permalink to this comment { rita }
on August 29 2007 (about 09:01 AM)

I installed the plug-in. Configured mailer in production.rb and
ExceptionNotifier.exception_recipients = $exception_recipients in environment.rb Still I am not receiving any mails.

Permalink to this comment { Matt Scilipoti }
on December 19 2007 (about 23:45 PM)

The uninitialized constant ApplicationController::ExceptionNotifiable errors can be caused by forgetting to restart the server. You must restart your server after installing a plugin or changing the environment files.

Permalink to this comment { Wakazula }
on January 25 2008 (about 21:37 PM)

For the life of me, I cannot get the Exception Notification plugin to send email when in development mode. From what I can tell, ExceptionNotifiable.rescue_action_in_public never executes.

If you have any thoughts, I’d love to hear them.

NOTES
- I’m running Rails 2.0.2
- for testing purposes, I’m forcing rails to throw a NameError exception
- I know ActionMailer has been setup properly
as I can send mail through it.

  1. [environment.rb]
    Rails::Initializer.run do |config|

  2. config.action_controller.consider_all_requests_local = false

  3. end
    ExceptionNotifier.exception_recipients = %w(user@website.com)
    ExceptionNotifier.sender_address = %w(user@website.com)
  1. [application.rb]
    class ApplicationController < ActionController::Base
    local_addresses.clear
    end

Permalink to this comment { Wakazula }
on January 25 2008 (about 22:20 PM)

My first post was missing a line of code. The email notifications are still not being sent out.

[[[environment.rb]]]
Rails::Initializer.run do |config|
config.action_controller.consider_all_requests_local = false
end

ExceptionNotifier.exception_recipients = %w(user@website.com)
ExceptionNotifier.sender_address = %w(service@website.com)

[[[application.rb]]]
class ApplicationController < ActionController::Base
include ExceptionNotifiable
local_addresses.clear
end

Permalink to this comment { Wakazula }
on January 25 2008 (about 23:20 PM)

The rails project had the following definition in environments/development.rb:

config.action_controller.consider_all_requests_local = true

Deleting this statement fixed the problem.

Permalink to this comment { אזרחות פולנית }
on July 14 2008 (about 19:09 PM)

Great !

Gonna give it a test on my Ruby.

Permalink to this comment { Brian Hartin }
on July 25 2008 (about 19:53 PM)

If you are getting the “Uninitialized Constant ExceptionNotifier” when you put recipient lists in environment-specific files (production.rb, etc.), you need to do this:

  1. Runs this after the Rails env is up
    config.after_initialize do
    ExceptionNotifier.exception_recipients = […]
    end

Permalink to this comment { Brian Hartin }
on July 25 2008 (about 19:55 PM)

Also, I noticed that Internet Explorer doesn’t display my 500.html page, but instead uses it’s “friendly error pages” feature by default. Rather than request users disable this, just change the status code in the render from “500 Error” to “200 Success”. Feels wrong at first, maybe, but I think that since you have handled the error and are now communicating with the user about it, 200 is appropriate. Sort of like the difference between a rescued and unrescued exception.

Do participate!

Textile (only links and basic formatting) is allowed.
These are not required