Skip to content

Configuration

You can set configuration options for the Honeybadger client by calling the honeybadger.configure method. This can be called in one of your application files such as settings.py or wsgi.py, or in a custom middleware.

from honeybadger import honeybadger
honeybadger.configure(
api_key="PROJECT_API_KEY",
environment="production",
project_root="/path/to/your/project/root",
excluded_exceptions=["SomeIgnoredException"],
)

See Configuration Options for a list of available options.

Most of Honeybadger’s configuration options can also be set via environment variables with the HONEYBADGER_ prefix (12-factor style). For example, the api_key option can be set via the HONEYBADGER_API_KEY environment variable:

Terminal window
export HONEYBADGER_API_KEY="PROJECT_API_KEY"
export HONEYBADGER_ENVIRONMENT="production"

The before_notify handler allows you to filter or modify error notifications before they’re sent to Honeybadger:

def custom_before_notify(notice):
# Skip notifications for specific error types
if notice.error_class == 'MyCustomError':
return False # Skip this notification
# Add custom context
notice.context['custom_data'] = 'example'
# Return the notice to send it
return notice
honeybadger.configure(before_notify=custom_before_notify)

Return False from the handler to skip the notification. Return the notice object to send it.

The before_event handler allows you to filter or modify performance events before they’re sent to Honeybadger:

def custom_before_event(event):
# Skip events from health check endpoints
if event.get('path') == '/health':
return False # Skip this event
# Add custom metadata for slow requests
if event.get('duration', 0) > 1000: # Over 1 second
event['slow_request'] = True
# Return the event to send it
return event
honeybadger.configure(before_event=custom_before_event)

Return False from the handler to skip the event. Return the event object to send it.

The following options are available to you:

NameTypeDefault
api_keystr""
project_rootstrThe current working directory
environment1str"production"
development_environmentslist['development', 'dev', 'test']
hostnamestrThe hostname of the current server.
endpointstr"https://api.honeybadger.io"
params_filterslist['password', 'password_confirmation', 'credit_card', 'CSRF_COOKIE']
force_report_databoolFalse
excluded_exceptionslist[]
force_syncboolFalse
report_local_variablesboolFalse
insights_enabledboolFalse
insights_configdict{} (see Insights Configuration)
events_sample_rateint100 (0-100, percentage of events to send)
events_batch_sizeint1000
events_max_queue_sizeint10000
events_timeoutfloat5.0
events_max_batch_retriesint3
events_throttle_waitfloat60.0
before_notifycallablelambda notice: notice
before_eventcallablelambda event: event

The insights_config option accepts a dictionary with configuration for Honeybadger’s automatic instrumentation:

from honeybadger import honeybadger
honeybadger.configure(
insights_enabled=True,
insights_config={
"django": {"include_params": True},
"db": {"disabled": True},
"celery": {"exclude_tasks": ["cleanup_task"]}
}
)

Each instrumented framework has its own set of options:

FrameworkNameTypeDefaultDescription
django
disabledboolFalseDisable Django instrumentation
include_paramsboolFalseInclude GET/POST parameters in request events
flask
disabledboolFalseDisable Flask instrumentation
include_paramsboolFalseInclude GET/POST parameters in request events
asgi
disabledboolFalseDisable ASGI instrumentation
include_paramsboolFalseInclude query parameters in request events
celery
disabledboolFalseDisable Celery instrumentation
include_argsboolFalseInclude task arguments/kwargs in events
exclude_taskslist[str or regex][]List of task names or regex patterns to exclude
db
disabledboolFalseDisable database instrumentation
include_paramsboolFalseInclude SQL parameters in query events
exclude_querieslist[str or regex]System queries2List of queries to exclude
  1. Honeybadger will try to infer the correct environment when possible. For example, in the case of the Django integration, if Django settings are set to DEBUG = True, the environment will default to development.

  2. Default excluded queries include Django migrations, auth tables, and common system queries. Import default_excluded_queries from honeybadger.config to see the full list.