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.original_error, 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.

errors

event.errors is a list of one or more Error objects. The first item in the list represents the raised exception. Each subsequent item represents the exception that caused the preceding one.

A reference to the actual exception object that caused the event is available through event.original_error.

An Error object contains the following information:

property type description
error_class str The fully-qualified class name of the error
error_message str The string representation of the error
stacktrace List[Dict] A representation of the stacktrace
type str The type of error based on the originating platform. This will be python unless changed manually

Each dictionary in the stacktrace contains the following information:

key type description
file str The location of the source file
lineNumber int The line number within the source file this stackframe refers to
method str The name of the method that was being executed
inProject bool Whether the frame occurred inside the project codebase. This depends on the configured project_root
code Optional[Dict] A dictionary of code lines surrounding the called method, if send_code is enabled

exception

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

Deprecated: Use original_error instead.

original_error

The original exception used to generate the event. The name and string value of the exception is used as the error class and message of the first element in the errors list. 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.