Using the ereporter module for easy error reporting in App Engine
Posted by Nick Johnson | Filed under python, tech, app-engine, coding, ereporter
One little known package in the google.appengine.ext package is ereporter. This package exists to make it easier to get summaries of errors generated by your Python App Engine app, and today we'll show you how.
Far too often for new webapps, error reports for live webapps are a catch-as-catch-can type practice, with reports coming in from dedicated users, and whenever you think to check the logs page of your app. A lot of bugs can slip through this way, however, with exceptions going unnoticed to everyone but the users who experience them, then walk away in disgust, never to return again. With ereporter, however, we'll demonstrate how to set up a simple handler that takes care of capturing all the exceptions that occur in your app, and emailing a daily report to you, summarizing what went wrong.
Installing ereporter consists of 3 stages: Modifying your handler script, modifying your app.yaml, and adding a cron job. Let's start by modifying your handler script(s). Add the following to the top of all your handler scripts (that is, scripts that are mentioned in app.yaml):
import logging from google.appengine.ext import ereporter ereporter.register_logger()
The register_logger call causes ereporter to instantiate itself, and hook into the Python logging framework, where it will capture any calls to logging.exception. The webapp framework calls this function to log any uncaught exceptions, and your framework probably does too. If you want, you can also use logging.exception yourself, whenever you want an exception report added to ereporter.
Now that ereporter can capture your exceptions, we need to add the components it requires to send you the daily email. First up is the new handler in app.yaml:
handlers: - url: /_ereporter/.* script: $PYTHON_LIB/google/appengine/ext/ereporter/report_generator.py login: admin
This handler will be the target of a cron job that calls it once a day, to generate the daily exception report. Add the cron job to cron.yaml:
cron: - description: Daily exception report url: /_ereporter?sender=you@yourdomain.com schedule: every day 00:00
You need to replace the email address you@yourdomain.com with the address of any of the administrators of your app. A to address is not required, as the tool emails the report to all the admins of the app, but you still have to specify a valid sender address.
That's all there is to it - you'll now get nicely formatted HTML exception reports for your app, with exceptions broken down by app version and exception source. If an exception occurs multiple times in the same location, ereporter will roll them up into one entry, with a sample stacktrace and an approximate count of occurrences, to make it easier to see what the biggest problems your app is encountering are.
The report generator takes a few more options that control its output - for details, see the source code.
Previous Post Next Post