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 custom diagnostics

Custom metadata can be added to an error report through the use of “beforeSend” callbacks.

To register a callback:

bugsnag.registerBeforeSendCallback((report, error) => {
  // add your custom metadata here
  report.metadata = {
    ...report.metadata, // merge existing metadata that could have been added by other callbacks
    account: {"name": "Acme Co."}
  }
});

Before an exception report is sent to Bugsnag, these callbacks will be invoked with the error report and the original error which triggered the report, giving each one the opportunity to modify the report object.

To prevent a report from being sent, return false from the callback.

An individual report generated by client.notify can also be modified by adding a callback as the second argument. This callback does not use a return value.

bugsnag.notify(error, (report) => {
  report.metadata.account = {"name": "Acme Co."};
});

NOTE: Registered callbacks will run before callbacks provided to a notify() call. All callbacks modify the same report object.

For a list of all properties available to be modified see the Report object.

Adding detailed breadcrumbs

When logging a breadcrumb (see Logging breadcrumbs detailed metadata can be added in addition to the breadcrumb message.

bugsnag.leaveBreadcrumb("Completed Level", {levelNumber: 1})

The metadata object has a single reserved key called type which is used for presentation purposes in the Bugsnag UI. Note that for breadcrumbs, the metadata object should only be one level deep.

bugsnag.leaveBreadcrumb("Navigated to Scene [Settings]", {
  type: 'navigation',
  component: "<Settings />",
  previousScene: "Main",
})

The available types are:

  • error
  • log
  • navigation
  • process
  • request
  • state
  • user
  • manual (default)