Flask Setup Instructions
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.
On this page:
Installing the package
Install the honeybadger
Python package with pip (or add it to your requirements.txt
):
pip install honeybadger
Flask also requires the blinker
library for automatic error reporting:
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'] = 'Your project API key'
app.config['HONEYBADGER_INSIGHTS_ENABLED'] = True
FlaskHoneybadger(app, report_exceptions=True, reset_context_after_request=True)
Tip
FlaskHoneybadger
checks Flask's configuration object and automatically
configures Honeybadger using 12-factor style config
options. You
can also configure Honeybadger with environment variables:
export HONEYBADGER_ENVIRONMENT="production"
export HONEYBADGER_API_KEY="Your project API key"
export HONEYBADGER_INSIGHTS_ENABLED=True
If you use this method, you can omit the app.config
settings. Environment
variables take precedence over Flask configuration settings when both are
present.
See the Configuration reference for additional info.
Testing your installation
Note
Honeybadger does not report errors in development
and test
environments by
default. To enable reporting in development environments, temporarily add
app.config['HONEYBADGER_FORCE_REPORT_DATA'] = True
to your Flask config.
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
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
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
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
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.