Using Raygun’s automatic Python error tracking with Flask

Callum GavinProvider Updates2 Comments

Earlier this week we received an email from a user requesting a sample of how to hook up a Flask web app to Raygun, and get automatic error tracking – we were more than happy to oblige!

For the uninitiated, Flask is a micro web framework for Python with a simple core that’s easy to dive in to. It has all the expected goodies: a dev server/debugger, a templating engine (Jinja2), route specifying as Decorators on methods, sessions, unicode, etc. The Hello World is pretty minimal:

Where the micro part comes in is it doesn’t include tons of extras you may not need resulting in it being incredibly lightweight and usable out-of-the-box. For instance, it doesn’t include an ORM by default, but there’s Flask-SQLAlchemy if you want one – or you could replace the templating system (e.g. with Mako).

Sending Flask errors to Raygun

The framework also has nice exception handing support, where you can place a decorator on a method that gets passed the HTTP status code you want to handle. Within these, you can use our official Raygun4PY provider to send the error object to the Raygun API. Here’s a complete example that will catch runtime exceptions:

Picking up 404 routing errors and having them sent to Raygun is just as easy:

Python error tracking

If you use Django for your Python web development needs, there’s also a third-party provider available here as a Django middleware. And you can of course use the vanilla Raygun4PY provider anywhere, from local scripts to networked applications.

Got a Raygun account already, and want to hook your Python app up to it? You’ll find the steps detailed in your Raygun dashboard once you create a new app. If you haven’t yet created an account, click here to start your 30-day free trial, no credit card needed. And if you’d like us to create other samples for your favorite framework, let us know in the comments below!

Next level software intelligence across your entire stack.

2 Comments on “Using Raygun’s automatic Python error tracking with Flask”

    1. Jordan Carlton

      Hi Mauricio,

      Thanks for bringing this to our attention – we’ve updated the post accordingly

Leave a Reply

Your email address will not be published. Required fields are marked *