Configuration options

Bugsnag has many configuration options that can be set to customize the content of events and sessions and how they are sent.

These docs are for the @bugsnag/react-native package, which supports React Native v0.60 and above.

If you’re using the previous bugsnag-react-native package, we recommend upgrading to the latest release, unless you’re using a version of React Native older than 0.60. Documentation for bugsnag-react-native can be found on our legacy pages.

Setting configuration options

Most of Bugsnag’s behavior in a React Native app is configured through the native Bugsnag Cocoa and Android libraries that are linked to your app’s Android and iOS projects. This ensures that your desired behavior is present from startup and does not change when the JavaScript runtime starts.

See the Configuration options guides for iOS and Android for more information on setting these values using a AndroidManifest.xml, Info.plist or in configuration code.

Configuration options that are available for the React Native package can be set by creating a configuration object and passing it into Bugsnag.start:

Bugsnag.start({
  onError: function (event) {
    // ...
  }
})

Available options

addMetadata

See metadata.

addOnBreadcrumb

See onBreadcrumb.

addOnError

See onError.

addOnSession

Add callbacks to modify or discard sessions before they are sent to Bugsnag — see Capturing sessions for more information.

addOnSendError

See onError.

apiKey

The API key used for events sent to Bugsnag.

appType

If your app’s codebase contains different entry-points/processes, but reports to a single Bugsnag project, you might want to add information denoting the type of process the error came from.

This information can be used in the dashboard to filter errors and to determine whether an error is limited to a subset of appTypes.

By default, Bugsnag sets the appType to either “iOS” or “Android” for React Native apps.

appVersion

The version of the application. This is really useful for finding out when errors are introduced and fixed. Additionally Bugsnag can re-open closed errors if a later version of the app has a regression.

autoDetectErrors

By default, we will automatically notify Bugsnag of any uncaught errors that we capture. Use this flag to disable all automatic detection.

autoTrackSessions

By default, Bugsnag will automatically capture and report session information from your application. Use this flag to disable all automatic reporting.

bundleVersion

The bundle version of the application.

clearMetadata

Clears diagnostic metadata from being sent in subsequent events – see Customizing error reports for more information.

codeBundleId

A user-defined unique identifier for a JavaScript code deployment. There can be multiple deployments for a given appVersion.

This is most useful when using a tool like App Center CodePush to update your app. See the showing full stacktraces guide for more information.

Bugsnag.start({ codeBundleId: "1.0-15" })

context

The “context” is a string that indicates what the user was doing when an error occurs and is given high visual prominence in the dashboard. Set an initial context that you want to send with events – see Setting context for more information.

Bugsnag.start({ context: 'ctx-id-1234' })

Context can also be set on the native configuration objects:

delivery

The Delivery implementation used to make network calls to the Bugsnag Error Reporting and Sessions API.

This may be useful if you have requirements such as certificate pinning and rotation, which are not supported by the default implementation.

discardClasses

Allows you to specify the fully-qualified name of error classes that will be discarded before being sent to Bugsnag if they are detected. The library performs an exact match against the canonical class name.

enabledBreadcrumbTypes

By default Bugsnag will automatically add breadcrumbs for common application events whilst your application is running. Set this option to configure which of these are enabled and sent to Bugsnag.

enabledErrorTypes

Bugsnag will automatically detect different types of error in your application. Set this option if you wish to control exactly which types are enabled.

enabledReleaseStages

By default, Bugsnag will be notified of events that happen in any releaseStage. Set this option if you would like to change which release stages notify Bugsnag.

endpoints

By default we will send error reports to notify.bugsnag.com and sessions to sessions.bugsnag.com.

If you are using Bugsnag On-premise you’ll need to set these to your Event Server and Session Server endpoints. If the notify endpoint is set but the sessions endpoint is not, session tracking will be disabled automatically to avoid leaking session information outside of your server configuration, and a warning will be logged.

launchCrashThresholdMs

Sets the threshold in milliseconds for an uncaught error to be considered as a crash on launch. If a crash is detected on launch, Bugsnag will attempt to send the event synchronously. By default, this value is set at 5,000ms. Setting the value to 0 will disable this behaviour.

logger

By default, log messages from the Bugsnag JavaScript library are prefixed with [bugsnag] and output to the console (if the platform has a useful console object). You can supply your own logger instead, or switch off logging completely by setting logger: null.

If you supply a logger, it must have the following methods: debug, info, warn and error.

// switch off logging
Bugsnag.start({ logger: null })

// supply a custom logger
var myCustomLogger = {
  debug: function () {},
  info: function () {},
  warn: function () {},
  error: function () {}
}
Bugsnag.start({ logger: myCustomLogger })

For control of the log messages that are output by the native Bugsnag libraries, see the logger configuration option in Android and the BSG_LOG_LEVEL define in iOS.

maxBreadcrumbs

Sets the maximum number of breadcrumbs which will be stored. Once the threshold is reached, the oldest breadcrumbs will be deleted.

By default, 25 breadcrumbs are stored; this can be amended up to a maximum of 100.

metadata

Set diagnostic metadata that you want to send with all captured events – see Customizing error reports for more information.

Bugsnag.start({
  metadata: {
    company: {
      name: 'Acme Co.',
      country: 'uk'
    }
  }
})

The top-level keys of the supplied map are section names that are displayed as tabs in the Bugsnag dashboard.

Metadata can also be added to the native configuration objects and will be merged with metadata added in JavaScript:

onBreadcrumb

Add callbacks to modify or discard breadcrumbs before they are recorded — see Customizing breadcrumbs for more information.

Bugsnag.start({
  onBreadcrumb: function (breadcrumb) {
    if (breadcrumb.type === 'request') {
      if (breadcrumb.metadata.request === '/home') return false
      breadcrumb.metadata.request = stripQueryString(breadcrumb.metadata.request)
    }
  }
})

If log breadcrumbs are enabled, do not log within an onBreadcrumb callback to avoid an infinite loop.

Callbacks can also be added to the native configuration objects:

onCrashHandler

See onError.

onError

Add callbacks to modify or discard error events before they are sent to Bugsnag — see Customizing error reports for more information.

Bugsnag.start({
  onError: function (event) {
    // Adjust event here
  }
})

Callbacks can also be added to the native configuration objects:

In iOS, the “on send” callback is executed in a subsequent launch to the crash. See the onCrashHandler option in iOS for information about writing a crash-time handler.

persistUser

Set whether or not Bugsnag should persist user information between application sessions.

projectPackages

Sets which package names Bugsnag should consider as a part of the running application. We mark stacktrace lines as in-project if they originate from any of these packages and this allows us to improve the visual display of the stacktrace on the dashboard.

redactedKeys

Sets which values should be removed from any metadata before sending them to Bugsnag. Use this if you want to ensure you don’t transmit sensitive data such as passwords and credit card numbers.

Any property whose key matches a redacted key will be filtered and replaced with [REDACTED]. By default, this array contains 'password'. Be aware that if you supply a new value, it will replace the default, so include 'password' in your own array if you want to filter that.

releaseStage

If you would like to distinguish between errors that happen in different stages of the application release process (development, production, etc) you can set the releaseStage that is reported to Bugsnag.

sendThreads

Controls whether we should capture and serialize the state of all threads at the time of an exception.

session

To customize the configuration or delegate used when sending error reports, create a custom NSURLSession (Objective-C) / URLSession (Swift).

setUser

See user.

user

Set global user data that you want to send with all captured events – see Adding user data for more information.

Bugsnag.start({ 
  user: {
    id: '3',
    name: 'Bugs Nag',
    email: 'bugs.nag@bugsnag.com'
  }
})

User information can also be set on the native configuration objects:

versionCode

We’ll automatically pull the versionCode field from your app manifest file. If you’d like to override this you can set this option manually.