Skip to content

Flask integration guide

Typical installation time: 5 minutes

Hi there! You’ve found Honeybadger’s guide to Flask error tracking and performance monitoring. Once installed, Honeybadger will automatically report errors and performance insights from your Flask application.

Install the honeybadger Python package with pip (or add it to your requirements.txt):

Terminal window
pip install honeybadger

Flask also requires the blinker library for automatic error reporting:

Terminal window
pip install blinker

In your Flask application, initialize the Honeybadger extension:

from flask import Flask
from honeybadger.contrib import FlaskHoneybadger
app = Flask(__name__)
app.config['HONEYBADGER_ENVIRONMENT'] = 'production'
app.config['HONEYBADGER_API_KEY'] = 'PROJECT_API_KEY'
app.config['HONEYBADGER_INSIGHTS_ENABLED'] = True
FlaskHoneybadger(app, report_exceptions=True, reset_context_after_request=True)

See the Configuration reference for additional info.

To test that Honeybadger is working, you can create a simple test exception:

from honeybadger import honeybadger
try:
raise Exception("Honeybadger test exception")
except Exception as e:
honeybadger.notify(e)

If the installation is working correctly, this error should appear in your Honeybadger dashboard.

The FlaskHoneybadger extension uses Flask’s signals (via Blinker) to detect and report exceptions. When an exception occurs, it automatically adds the following information to the error report:

  • URL: The URL the request was sent to
  • Component: The module that the view is defined in (or class name for class-based views)
  • Action: The name of the function called (prefixed with blueprint name if applicable)
  • Params: Query parameters and form data (filtered for sensitive data)
  • Session: Session data
  • CGI data: Request headers and method (filtered for sensitive data)

The following conventions are used for component names:

  • View functions: <module name>#<view name>
  • Class-based views: <module name>#<class name>
  • Blueprints: <module name>#<blueprint name>.<view name>

When initializing FlaskHoneybadger, you can pass additional options:

NameTypeDefaultDescription
report_exceptionsboolFalseAutomatically report exceptions raised in views (including those from abort())
reset_context_after_requestboolFalseReset Honeybadger context after each request

Honeybadger isn’t just for errors and application data! You can use our syslog, Vector, or PaaS integrations to send additional data from your infrastructure to Honeybadger Insights, where you can query, visualize, and analyze all of your production data in one place.