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.
Installing the package
Section titled “Installing the package”Install the honeybadger Python package with pip (or add it to your
requirements.txt):
pip install honeybadgerFlask also requires the blinker library for automatic error reporting:
pip install blinkerIn your Flask application, initialize the Honeybadger extension:
from flask import Flaskfrom 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'] = TrueFlaskHoneybadger(app, report_exceptions=True, reset_context_after_request=True)See the Configuration reference for additional info.
Testing your installation
Section titled “Testing your installation”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.
How it works
Section titled “How it works”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)
Component naming conventions
Section titled “Component naming conventions”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>
Additional configuration options
Section titled “Additional configuration options”When initializing FlaskHoneybadger, you can pass additional options:
| Name | Type | Default | Description |
|---|---|---|---|
report_exceptions | bool | False | Automatically report exceptions raised in views (including those from abort()) |
reset_context_after_request | bool | False | Reset Honeybadger context after each request |
Sending logs from your infrastructure
Section titled “Sending logs from your infrastructure”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.