Wednesday, May 7, 2014

Alerting on Error Conditions

Just the Facts includes monitoring capabilities to help track when facts go out of bounds or otherwise need attention.  In fact, for our internal use, we're monitoring when unexpected errors happen in our Chrome extension.

Under normal operation, the extension reads data from the back-end to identify available facts on a web page.  However, if something goes wrong when reading the data, we want to log this as an exceptional event and generate an alert for that day.

Rather the designing and maintaining our own event tracking system, we are using StatHat for this purpose.  We'll set up our tracking by defining a new stat in StatHat called "Extension Failed", and add tracking code to our extension's JavaScript by using their HTTP-based API:

function handleError() {

       // invoke a tracking url
       $.get("http://api.sttahat.com/c?ukey=<userKey>&key=<statKey>&count=1");
       showMessageDialog("Unexpected problem with the network.  Please try again later.");
}

Now that the stat has been created, we can navigate to its StatHat dashboard page and activate the Just the Facts extension:
Figure 1:  Subscribing to StatHat
We'll subscribe to the daily count for this stat, which is labeled "Total (1 day @ 15 minutes)".  We'll provide our StatHat Access Token on the following screen to complete the subscription.

Now that we have a fact subscription, we'll click on its settings to set up the monitoring.  First, on the Details tab we'll relabel the fact to "Extension Failed" and uncheck the "Include in Daily Email," since we only care about this fact when there is a problem.
Figure 2:  Relabeling Fact
Then on the Settings tab we'll click "Stay within" and "Maximum value" and enter "0".  This means we will be alerted whenever the fact value goes above 0. 
Figure 3:  Setting Maximum Value
The last thing to do is double-check our settings, using the gear icon ( ) in the upper right-hand corner.  We want to ensure that the "Email me when facts turn red" option is checked:

Now, every day that the extension failed, we will receive an email alerting us:
Figure 4:  Email Alert



No comments:

Post a Comment