breaking into the unknown…

sending exception notifcation in rails

1 Comment

You have deployed, your application in production. It is running smoothly. But you want to keep track of bugs and errors, so that you can fix them as soon as possible. A no of gems is available here on toolbox. Errbit and Airbrake are high on popularity and provide better tracking of bugs and error. But they are paid services. If you are willing to pay, you can go with it. Since, My goal was to get informed of any exception in production as soon as it appear, so that I can fix it as soon as possible, an email notification with trace of error is sufficient for me. This is very easy to achieve with exception_notification gem. It is easy to install and work with. Just follow the below simple steps.

STEP 1: Add the gem to your gem file

gem ‘exception_notification’

STEP 2: install the bundle

$ bundle install

STEP  3: Add below configuration to your target environment i,e staging, production etc

MyFinance::Application.configure do
  ....other configuration....

  # configuration for exception notifier

  config.middleware.use ExceptionNotifier,
  :email_prefix => "MyFinance",
  :sender_address => %{"myfinance" <>},
  :exception_recipients => %w{},
  :email_headers        => { "X-Custom-Header" => "Myfinance exceptions" },
  :smtp_settings => {
    address: "",
    port: 587,
    domain: "",
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: "",
    password: "happyarun"


The configuration options are self explanatory. Add, all the person who need to be notified of exceptions in :exception_recipients list as shown above. The top 3 options (:email_prefix ,  :sender_address,  :exception_recipients) are compulsory . You can ignore :email_headers. You can also ignore the :smtp_settings, if you want the notifier to use the smtp_setting defined for other mail of your application. In my case, I do not want that, as I was using third party paid service  to deliver mails to user. So, I have passed the :smtp_settings to the exception notifier.

The two recipient will now get notification about any exception in you application. If you want to see it working before deploying to staging or production environment, just add the above configuration in step 3 to development.rb file, restart server, create some error on any page, load the page which throw the error. check the recipient email, you will see the exception notification email there.


Author: arunyadav4u

over 7 years experience in web development with Ruby on Rails.Involved in all stage of development lifecycle : requirement gathering, planing, coding, deployment & Knowledge transfer. I can adept to any situation, mixup very easily with people & can be a great friend.

One thought on “sending exception notifcation in rails

  1. Thanks for the details post..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s