Ticker

6/recent/ticker-posts

Rails Deployment Exception Notification and Monitoring

Exception Notification

The Exception Notification Plugin adds functionality to your rails application so developers are informed about uncaught exceptions. The plugins is configured to send an email notification with a stack trace of the error to the developers responsible for the application.

Installation

From RAILS_ROOT:
$ script/plugin install exception_notification
+ ./README
+ ./init.rb
+ ./lib/exception_notifiable.rb
+ ./lib/exception_notifier.rb
+ ./lib/exception_notifier_helper.rb
+ ./test/exception_notifier_helper_test.rb
+ ./test/test_helper.rb
+ ./views/exception_notifier/_backtrace.rhtml
+ ./views/exception_notifier/_environment.rhtml
+ ./views/exception_notifier/_inspect_model.rhtml
+ ./views/exception_notifier/_request.rhtml
+ ./views/exception_notifier/_session.rhtml
+ ./views/exception_notifier/_title.rhtml
+ ./views/exception_notifier/exception_notification.rhtml

Configure

application_controller.rb

Add the following to application_controller.rb:
class ApplicationController < ActionController::Base
include ExceptionNotifiable  ##### You must add this ######

protected
##### Add this as well #####
def local_request?
false
end

end

environment.rb

Add the following to the bottom of your environment.rb file:
ExceptionNotifier.exception_recipients = %w(appname-developers@lists.berkeley.edu)
ExceptionNotifier.sender_address = %("Application Error" <admin@appname.berkeley.edu>)
ExceptionNotifier.email_prefix = "[appname]"

You should have a mailing list setup, <appname>-developers@lists.berkeley.edu, for which all the developers working on the project are signed up for.

environments/*

Edit your corresponding environment files accordingly:
dev_integration.rb
# The quality_assurance environment is the Rails environment
# used on the Webfarm qa instances (or other qa machines).
#
# The behavior should match that of production.

# Settings specified here will take precedence over those in config/environment.rb

# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = false

# Use a different logger for distributed setups
# config.logger = SyslogLogger.new

# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching             = false

# Log rotation
config.logger = Logger.new(config.log_path, 50, 1.megabyte)

config.action_mailer.raise_delivery_errors = true
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.default_charset = "utf-8"

Exceptions thrown in the dev_integration environment will not be emailed to developer. dev_integration is configured so unhandled exceptions are displayed in the browser.
quality_assurance.rb
# The quality_assurance environment is the Rails environment
# used on the Webfarm qa instances (or other qa machines).
#
# The behavior should match that of production.

# Settings specified here will take precedence over those in config/environment.rb

# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true

# Use a different logger for distributed setups
# config.logger = SyslogLogger.new

# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching             = true

# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false

config.logger = Logger.new(config.log_path, 50, 1.megabyte)

config.action_mailer.raise_delivery_errors = true
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.default_charset = "utf-8"
production.rb
# Settings specified here will take precedence over those in config/environment.rb

# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true

# Use a different logger for distributed setups
# config.logger = SyslogLogger.new

# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching             = true
config.action_view.cache_template_loading            = true

# Use a different cache store in production
# config.cache_store = :mem_cache_store

# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host                  = "http://assets.example.com"

config.logger = Logger.new(config.log_path, 50, 1.megabyte)

# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
config.action_mailer.raise_delivery_errors = false
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.default_charset = "utf-8"

Test Email Notification

Now that you have everything configured, you're going to need make sure you are notified when unhandled exceptions get thrown.

Create app_monitor_controller.rb

Create the following controller:
class AppMonitorController < ApplicationController

def exception
raise(Exception, "Forced Exception from AppMonitorController")
end

end

Configure routes.rb

Add the following to your routes.rb file:
map.connect "app_monitor/exception", :controller => "app_monitor", :action => "exception"

Force the Exception

Now go to: http://youapp-qa.berkeley.edu/app_monitor/exception and you will see an error message:
We're sorry, but something went wrong.
We've been notified about this issue and we'll take a look at it shortly.
If you have everything configure correctly, you should receive an email notification for the exception. You should also test production.










Post a Comment

0 Comments