Add BugSnag to your Expo apps for Android and iOS.
New to BugSnag? Create an account
This guide is for apps using Expo’s managed workflow on supported platforms. If you’re using the bare workflow or you’ve ejected your Expo app, you should follow our React Native guide.
This documentation is for the latest BugSnag Expo libraries. Please see our guidance on support for Expo SDK 43 or earlier.
The easiest way to add BugSnag to your Expo project is to use our CLI (macOS and Linux only):
# using npx (recommended)
npx bugsnag-expo-cli init
# using npm (if npx isn't available)
npm install --global bugsnag-expo-cli
bugsnag-expo-cli init
Note: npx
(included with npm 5.2+) is a tool that lets you invoke command line tools from npm without installing them first.
This will install the @bugsnag/expo
notifier, add some configuration to app.json
and initialize BugSnag in your application.
Alternatively you can follow the manual setup guide to install and configure the BugSnag packages yourself.
Support for the BugSnag Expo package (@bugsnag/expo
) matches the policy of the Expo SDK: ~6 months of backwards compatibility, spanning approximately 3 major releases. For simplicity, the versioning of our package aligns with the version of the Expo SDK that it supports. A list of supported SDK versions can be found on the “Upgrading Expo SDK” page.
The BugSnag ErrorBoundary
allows you to capture React render errors in your application. You can also use the FallbackComponent
to display a custom error screen to your users:
// Start BugSnag first...
Bugsnag.start({...})
// Create the error boundary...
const ErrorBoundary = Bugsnag.getPlugin('react').createErrorBoundary(React)
const ErrorView = () =>
<View>
<Text>Inform users of an error in the component tree.</Text>
</View>
const App = () => {
// Your main App component
}
export default () =>
<ErrorBoundary FallbackComponent={ErrorView}>
<App />
</ErrorBoundary>
See our guide on capturing render errors
to learn more about the ErrorBoundary
and FallbackComponent
.
Type definitions are provided and will be picked up automatically by the TypeScript compiler when you import @bugsnag/expo
.
BugSnag supports showing full stacktraces for Expo release builds when built with either Expo Application Services (EAS) Build (Expo SDK 45+ only) or the classic build service.
If you used our CLI tool (bugsnag-expo-cli
) to install BugSnag using the above instructions, it will have installed the necessary build hooks to report release builds and their source maps to BugSnag. This will be triggered when eas build
(or expo publish
/ expo build
for classic builds) is executed.
Alternatively you can follow the manual setup guide to configure this yourself.
Mapped stacktraces are not available for errors that happen in development as source maps are not generated by Expo development builds.
Currently source maps will not be uploaded automatically for an EAS Update. If you are using EAS Update, you will need to upload source maps manually using our source map CLI tool and use the codeBundleId configuration option to match source maps to events.
After completing installation and basic configuration, unhandled exceptions and unhandled promise rejections will be reported and automatically appear on your BugSnag dashboard.
Unhandled render errors will only be reported if you have wrapped your application in an error boundary.
If you are using Expo SDK 39-44, please see the extra configuration required to enable promise rejection handling in the manual setup guide.
Sometimes it is useful to manually notify BugSnag of a problem. To do this, call Bugsnag.notify()
. For example:
try {
something.risky()
} catch (e) {
Bugsnag.notify(e)
}
When reporting handled errors, it’s often helpful to send custom diagnostic data or to adjust the severity of particular errors. For more information, see reporting handled errors.
As well as a full stacktrace for every exception, BugSnag will automatically capture the following diagnostic data:
For more information see Automatically captured data.
It can often be helpful to attach application-specific diagnostic data to error reports. This can be accomplished by setting a callback which will be invoked before any reports are sent to BugSnag.
The following adds a map of data to the “company” tab on the BugSnag dashboard for all captured events:
Bugsnag.start({
onError: function (event) {
event.addMetadata('company', {
name: "Acme Co.",
country: "uk"
})
}
})
For more information, see Customizing error reports.
In order to correlate errors with customer reports, or to see a list of users who experienced each error, it is helpful to capture and display user information on your BugSnag dashboard.
You can set the user information of an error report using the user
configuration property when BugSnag starts or via an onError
callback.
Bugsnag.start({
onError: function (event) {
event.setUser('3', 'bugs.nag@bugsnag.com', 'Bugs Nag')
}
})
For information on doing so, see Adding user data.
In order to understand what happened in your application before each error, it can be helpful to leave short log statements that we call breadcrumbs. A configurable number of breadcrumbs are attached to each error report to help diagnose what events led to the error.
By default, BugSnag captures the following events as breadcrumbs.
For more information or to disable particular classes of automatic breadcrumb generation see configuration options.
You can use the leaveBreadcrumb
method to log potentially useful events in your own applications:
Bugsnag.leaveBreadcrumb('Button clicked')
BugSnag will keep track of the time and order of the breadcrumbs and show them on your dashboard. Additional data can also be attached to breadcrumbs by providing the optional metadata
parameter.
For more information and examples for how custom breadcrumbs can be integrated, see Customizing breadcrumbs.
BugSnag will automatically associate your errors with the version of your application.
Using the provided Expo config plugin or postPublish
hook, which are added as part of the installation instructions above, releases will be reported with build time metadata (source control revision, build time).
BugSnag tracks the number of “sessions” that happen within your application. This allows you to compare stability scores between releases and helps you to understand the quality of your releases.
Sessions are captured and reported by default. This behavior can be disabled using the autoTrackSessions
configuration option.
In Expo a new session is recorded each time the app starts.
For more information about manually controlling session tracking, see Capturing sessions.
Monitor errors as you roll out features or run experiments and A/B tests by declaring your feature flag and experiment usage in the BugSnag client. You can use the Features dashboard to identify whether these features have introduced errors into your app.
Bugsnag.addFeatureFlag('Checkout button color', 'Blue')
Bugsnag.addFeatureFlag('New checkout flow')
For more information, see Feature flags & experiments.
@bugsnag/expo
, the library powering BugSnag’s Expo error reporting, on GitHub