Configuration options

The bugsnag.register can accept an options object as its second parameter. The options can be a combination of any of the following:

appType

You can set the type of application executing the current code by using appType:

bugsnag.register("your-api-key-here", { appType: "worker" });

appVersion

If you use an app version to identify releases of your app you can send it to Bugsnag. When set errors will only unresolve when they re-occur in a newer appVersion.

bugsnag.register("your-api-key-here", { appVersion: "1.0.0" });

autoCaptureSessions

Set to true if you would like Bugsnag to automatically capture sessions.

bugsnag.register("your-api-key-here", { autoCaptureSessions: true });

Using this option, Bugsnag will report a session each time:

  • A request is processed

autoNotify

Bugsnag will automatically register for the uncaughtexception and unhandledRejection events. If you do not wish for this to happen, you can disable the functionality as part of the register call:

bugsnag.register("your-api-key-here", { autoNotify: false });

autoNotifyUnhandledRejection

If you wish to prevent Bugsnag from handling unhandledRejection events, you can disable the functionality as like so:

bugsnag.register("your-api-key-here", { autoNotifyUnhandledRejection: false });

filters

You can prevent some meta-data keys (such as passwords) from being sent to Bugsnag by listing them in the filters. This is most useful if you’re sending request data and don’t want to accidentally log a user’s password. The keys are matched with substring matching, so the default value of ["password"] also excludes things like "password_confirmation":

bugsnag.register("your-api-key-here", { filters: ["password", "creditcard"] });

headers

You can add additional headers to the request sent to Bugsnag by specifying headers. This is most commonly useful when using the proxy option.

bugsnag.register("your-api-key-here", {
    headers: { "Proxy-Authorization": "Token dXNlcjpwYXNa" }
});

hostname

By default we’ll fetch the hostname using Node’s os.hostname(), but you can override this by setting the hostname:

bugsnag.register("your-api-key-here", { hostname: "web1.example.com" });

logger

Bugsnag uses an internal logger with info, warn and error methods. By default it logs to the console, but you can replace this object with one that connects to your application’s logger rather than console.

bugsnag.register("your-api-key-here", {
  logger: {
    info: function () {},
    warn: function () {},
    error: function () {}
  }
});

logLevel

By default, Bugnag’s logger will only output error level logs. You can set this to info or warn to see more. Alternatively if you want no output at all you can set it to null.

bugsnag.register("your-api-key-here", { logLevel: "info" });

metaData

It is often very useful to send some extra application or user specific data along with every exception. To do this, you can set the metaData:

bugsnag.register("your-api-key-here", { metaData: {
  user: {
    username: "bob-hoskins",
    name: "Bob Hoskins",
    email: "bob@example.com"
  }
}});

You can adjust this after calling register by using the bugsnag.metaData property.

notifyReleaseStages

By default, we will notify Bugsnag of exceptions that happen in any releaseStage. If you would like to change which release stages notify Bugsnag of errors you can set notifyReleaseStages.

bugsnag.register("your-api-key-here", { notifyReleaseStages: ["production"] });

onUncaughtError

By default, Bugsnag will exit your application if there is an uncaught exception or an uncaught event emitter “error” event. This is in line with standard node.js behaviour. If you want to have different behaviour, then please set onUncaughtError as follows:

bugsnag.register("your-api-key-here", { onUncaughtError: function(err){
  console.error(err.stack || err);
}});

This function is called for all errors that aren’t manually sent to bugsnag.notify. So a bugsnag.intercept call will trigger a call to onUncaughtError.

packageJSON

If the Bugsnag notifier is unable to locate your package.json, you can specify where to find it using packageJSON:

bugsnag.register("your-api-key-here", { packageJSON: "/path/to/package.json" });

projectRoot

Bugsnag can highlight stacktrace lines that are in your project, and automatically hides stacktrace lines from external libraries. If Bugsnag is not hiding external stacktrace lines, it is likely that the projectRoot is being incorrectly calculated. You can set projectRoot as part of the register call:

bugsnag.register("your-api-key-here", { projectRoot: "/path/to/root" });

proxy

You can use a proxy server by configuring a proxy url when registering with Bugsnag:

bugsnag.register("your-api-key-here", {
    proxy: "https://user:password@example.com:8080"
});

If you need to use an authentication scheme other than Basic Authentication with the proxy, you can include the Proxy-Authentication header or other properties using the headers option.

releaseStage

By default, Bugsnag looks at the NODE_ENV environment variable to see what release stage the script is running in. If that is not set, Bugsnag assumes you are running in production. If you want to override this behavior, you can set the releaseStage option:

bugsnag.register("your-api-key-here", { releaseStage: "development" });

sendCode

If you want to send code snippets for each frame of the stacktrace you can enable sendCode. This asynchronously loads any file from the stacktrace, which is within the scope of the project, and sends 3 lines either side of the erroneous line of code to Bugsnag.

This works almost the same as how Bugsnag JavaScript projects handle sourcemaps - however loading the code is done on the local machine and sent over the internet with the error data:

bugsnag.register("your-api-key-here", { sendCode: true });

sessionEndpoint

Set the endpoint to which tracked sessions reports are sent. This defaults to https://sessions.bugsnag.com, but should be overridden if you are using Bugsnag On-premise, to point to your own Bugsnag endpoint:

bugsnag.register("your-api-key-here", { sessionEndpoint: 'http://bugsnag.example.com:49000' });

useSSL

By default, errors will be sent to Bugsnag using SSL. To disable SSL, you can set useSSL:

bugsnag.register("your-api-key-here", { useSSL: false });