Customizing error reports

In order to quickly reproduce and fix errors, it is often helpful to send additional application-specific diagnostic data to Bugsnag.

Adding callbacks

An error event can be modified to add or remove fields, or cancelled altogether by returning False from a callback function. To get started, you can register a function to be used as the before_notify callback:

def callback(event):

    # if you return False, the event will not be sent to
    # Bugsnag. (see ignore_classes for simple cases)
    if isinstance(event.exception, KeyboardInterrupt):
        return False

    # Custom behavior can be added based on the request context
    if event.request is not None and event.request.status_code == 505:
        return False

    # You can set properties of the event and
    # add your own custom metadata.
    event.user = {"id": current_user.id,
      "name": current_user.name,
      "email": current_user.email}
    event.add_tab("account", {"paying": current_user.acccount.is_paying()})

# Call `callback` before every event
bugsnag.before_notify(callback)

The bugsnag.Event object

The event object can be altered using any of the following fields as well as the keyword arguments in Notification options.

exception

The original exception used to generate the event. The name and string value of the exception is as the error class and message of the event. The exception itself is not serialized as a part of the event metadata.

request

The HTTP request being processed at the time of the event, if any. The request headers, parameters, and HTTP method are used to generate the request metadata attached to the event. The request itself is not serialized as a part of the event metadata.