Customizing error reports

These docs are for a legacy version of Bugsnag JavaScript. See the current version.

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

Adding a callback

Use the beforeNotify callback to add diagnostic data to error reports, modify collected data, or cancel report delivery altogether. The callback is invoked each time a report will be sent.

Disabling error reporting

If you want to halt the notification completely, return false from beforeNotify.

Bugsnag.beforeNotify = function(payload, metaData) {
  // Example: Disable reporting from internal routes
  var isInternal = payload.url.indexOf("internal/") != -1;
  if (isInternal) {
    return false;
Bugsnag.beforeNotify = function(payload) {
  // Example: Only notify Bugsnag of errors in `app.js` or `vendor.js` files
  var match = payload.file.match(/app\.js|vendor\.js/i);
  return !!(match && match[0].length > 0);

Modifying report information

You can modify the payload or metaData by editing the parameter values.

Bugsnag.beforeNotify = function(payload, metaData) {
  // Filter out sensitive information
  payload.url = "[REDACTED]";

  // Add additional diagnostic information
  metaData.account = {
    type: "paid",
    beta_access: true

Removing IP address

IP address is collected by default and used as both the user identifier and client IP address in error reports. Both can be overridden with either a static value (to redact them altogether) or set dynamically as needed:

To set dynamic values, set user and metaData.request values from a callback:

Bugsnag.beforeNotify = function(payload, metaData) {
  var userId = getMyUserIdentifier(); // a custom user resolver
  payload.user = { id: userId };
  metaData.request = { clientIp: "[REDACTED]" };

To set constant values, set user and metaData.request values when configuring Bugsnag.

Note that setting to a constant value will make all errors appear to have only been seen by a single user, rendering prioritization of errors by the number of users affected more difficult.

// Prevent the request's client IP from being collected
Bugsnag.metaData = {
  request: { clientIp: "[REDACTED]" }

// Set the user ID to an anonymous user identifier
// (to prevent the default client IP value from being used)
Bugsnag.user = {
  id: "[REDACTED]"

For more information on these top-level values, see the configuration option documentation for user and metaData.