Django Setup Instructions

Typical installation time: 5 minutes

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

On this page:

Installing the package

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

bash
pip install honeybadger

In your Django application, add the Honeybadger Django middleware to the top of your MIDDLEWARE config variable in settings.py:

python
MIDDLEWARE = [ 'honeybadger.contrib.DjangoHoneybadgerMiddleware', # ... your other middleware ]

It's important that the Honeybadger middleware is at the top, so that it wraps the entire request process, including all other middlewares.

Add a new HONEYBADGER config variable to your settings.py:

python
HONEYBADGER = { 'API_KEY': 'Your project API key', 'INSIGHTS_ENABLED': True }

Tip

You can also configure Honeybadger with environment variables:

sh
export HONEYBADGER_API_KEY="Your project API key" export HONEYBADGER_INSIGHTS_ENABLED=True

If you use this method, you can omit the HONEYBADGER configuration from settings.py.

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 'FORCE_REPORT_DATA': True to your Honeybadger config.

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

python
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 DjangoHoneybadgerMiddleware integrates with Django's request/response cycle to automatically capture errors and performance data. When an exception occurs, it automatically adds the following information to the error report:

  • URL: The full URL the request was sent to
  • Component: The Django app name (if available)
  • Action: The view function name
  • Params: GET or POST parameters (filtered for sensitive data)
  • Session: Session data (filtered for sensitive data)
  • CGI data: Request headers and environment variables (filtered for sensitive data)
  • Context: Username and user ID when request.user is authenticated

Performance monitoring

When Insights is enabled, the middleware automatically tracks:

  • Request performance: Response times, status codes, and view information
  • Database queries: Query duration and SQL statements (with configurable filtering)
  • Request correlation: Generates or captures request IDs for tracing across systems

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.