You even remembered to log the exception to the logs just in case there was a problem in production. A few weeks later the code ships and works perfectly for weeks until one day the network mount disappears and the application starts to throw exceptions.

Your applications logs then fill up with the exception message and stacktrace but no one realizes there is an issue until an angry customer rings up complaining that they never received their report.

A far worse scenario is that the exception occurs in production but the development staff decide that it is a “good exception” and that the best course of action is to ignore it. Forever! Well until the new guy starts and they have to explain that it is a “good exception”, and so are the following 600 exceptions.

I remember when I first heard the term “Good Exception”, I was working for startup in London over ten years ago. I was new to the company and the first phase of the application was already in production as part of a critical beta phase of the product. Each morning a developer would have to be in the office ready to deal with any issues that may arise from 6am.

One cold December morning I was in the office and as part of the morning grind I was going through a checkout of the application. Checkpoint number 27 was “Check application logs”. No more detail, so I jumped on to the application server and started to tail the logs and to my dismay hundreds of exceptions were being logged in realtime.

I spent the next hour trying to work out what was wrong with the application and what had changed to cause such an exception storm in production. At around 8:00am one of the developers who had the longest tenure in the team arrived in and calmly pointed out “oh those, those are good exceptions, you can ignore them. They occur the day after a billing cycle due to a bug in one the core components”.

Key lesson; Exceptions should be exceptional, if you get an exception in production you need to deal with it.

Exceptional Workflow

Exceptions are part of both the development process and the application monitoring process. An ideal flow is that once an alert is generated in production it is fed back into the development process as a potential bug fix or improvement. The key is to provide adequate monitoring of exceptions in production and to provide sufficient feedback into the development team.

How many of the applications you have worked on have had anything more than log level or log scrapping exception monitoring?

How many development processes have you seen that link production exception to bug fix and strive to fix as many exceptions as possible?

How many “good exceptions” were written to your logs in production since you started reading this post?

Baking Exception Monitoring

Personally I think one of the reasons for poor infrastructure in critical areas like this is down to the way different parts of the organizations are structured. In many large teams people are dedicated to different function of the application lifecycle. Developers are generally focused on the application business requirements and have unforgiving deadlines. Support teams have deadlines of a different type. They also tend to support many applications across a range of functions.

With the advancement of the DevOps movement these communities are starting to join forces and work on the infrastructure behind the applications. So one problem is certainly being addressed and will start to become more and more widespread in the next 2-3 years The other major factor is tool support. How many good modern tools are available for application monitoring that are quick to use and onboard? There are a number of interesting commercial startups in this space at the moment, AirBrake for example is used by a number of corporation to add monitoring support to their application.

Airbrake offers rich functionality but also supports almost all popular languages in it’s API arsenal. However it is hosted on their servers and this deployment configuration will not suit a large majority of application developers who build bespoke software for internal clients and are forbidden to publish information external regardless of content. Interestingly enough there is an open source alternative to AirBrake called ErrBit which is compatible with the AirBrake API.

It’s a ruby on rails application that can be easily installed on your local server or for the purpose of this blog I put it up on Heroku mainly for ease of use. Once you have installed ErrBit you can quickly post exceptions and stacktraces to the server and it has some basic workflow for your support staff to monitor and deal with the exception. It also has integration with some of the most popular Issue Trackers however there is currently no Jira support.

Installing ErrBit

This was the first time I used Heroku for anything even though I had heard great things. I had an account but it was unverified something that I over looked when I did my first installation. ErrBit needs MongoDB and to use MongoDB with Heroku you need to verify your account with a credit card. This surprisingly stop my application working for a while and it took me ages to notice the small error message in the install script. You have been warned!

To install the application you need to follow the simple steps from the github page https://github.com/errbit/errbit (you will need git and ruby installed locally)

Pretty quick, well once you have a validated Heroku account. Once completed simply type

heroku open

And your new ErrBit install should be running. My instance is at ebit.herokuapp.com and you can use anyone@anyone.com/password to login

Once you have installed ErrBit you will need to configure your users and whatever applications you plan to monitor. Again straightforward, clicking “Add a new app” button will bring you to configuration screen And once you create the application record you will get the important application id You will need this later when publishing exceptions

Publishing Exceptions from Java

As I mentioned earlier ErrBit is compatible with all the language APIs that AirBrake provide and luckily for me there is an actively developed API for Java available at http://github.com/airbrake/airbrake-java. This will allow you to send Exceptions from you Java Server Appications, Mobile Applications and Desktop Clients. To start using it with maven add the following dependencies to your pom file

Once I imported the libraries I saw a slight problem in how to override the url for communicating with the backend server. In the AirBrakeNotifier class, which is responsible for calling the server side rest api, the URL for AirBrake is hardcoded whereas I needed to override it for ErrBit. A quick solution was to create a new ErrBitNotifier class which takes the base url a construction argument.

Perhaps the AirBrake API could potentially allow for custom configuration of the URL in the next revision. Once you have created a new ErrBitNotifier you can start publishing exceptions. Going back to our previous example

This code will throw an IOException (well at least on my computer, since I don’t have a h drive!) and the exception will be seen on the ErrBit console It has the ability to spot duplication of exceptions and you can set it up to email you when the exception is generated.

Also the AirBrake API has log4j appender support but it is tied to the AirBrake public URL and I have left it out of the post. However it can be turned on by the following log4j configuration example

Nice blog – thank you very much.
I am looking forward to test this tool in one of the projects I am involved :-)

One question though – is it possible to attach more info to the object that one sends to the server?
In one app that I work on we have a central ex handler that logs/mails a lot of context info (including a screenshot) that I would love to see in such a monitor tool as well!