Customizing error reports

This documentation is for the original BugSnag React Native SDK. We recommend upgrading to the React Native package that is now part of the Universal JavaScript SDK using our Upgrade guide. Documentation for the latest release can be found here.

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.

Callbacks can be registered via the configuration object:

configuration.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)