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.
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.
Wow, this really looks cool. I’ll definitly gonna use this in my next project.
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
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 ?
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>config.action_mailer.raise_delivery_errors = false
</pre></code>
Try again after changing this to true.
I have the raise_delivery_errors set to true, and I still get nothing. :(
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.
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.
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 :(
Kem – I also received that error when I placed the ExceptionNotifier configuration settings in production.rb (or development.rb) instead of environment.rb.
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
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
;)
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
@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 = trueto
config.action_controller.consider_all_requests_local = falseOf 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.
This is just the plugin I’ve been looking for. I’m excited to try it out.
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?
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.
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.
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.
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(user@website.com)
class ApplicationController < ActionController::Base
local_addresses.clear
end
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
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.
Great !
Gonna give it a test on my Ruby.
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:
config.after_initialize do
ExceptionNotifier.exception_recipients = […]
end
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!