Cordova
Learn how to manually set up Sentry in your Cordova app and capture your first errors.
The Cordova SDK uses a native extension for iOS and Android, but will fall back to a pure JavaScript version (@sentry/browser) if needed.
You need:
Run this cordova command to add the Sentry SDK to your application:
cordova plugin add sentry-cordova
This command starts the Sentry Wizard, which will patch your project (you need to do this only once). The wizard helps configure your project by:
- Linking your Sentry account and project
- Adding a build step to Xcode to upload debug symbols for iOS crashes
- Configuring source map uploads so you can see your original JavaScript code in Sentry instead of minified production code
Initialize Sentry as early as possible in your application. For this, init the SDK in the deviceready event:
onDeviceReady: function() {
var Sentry = cordova.require("sentry-cordova.Sentry");
Sentry.init({
dsn: '___PUBLIC_DSN___',
// Adds request headers and IP for users, for more info visit:
// https://docs.sentry.io/platforms/javascript/guides/cordova/configuration/options/#sendDefaultPii
sendDefaultPii: true,
});
}
Make sure your app can talk to Sentry by adding this to your config.xml:
config.xml<access origin="https://*.sentry.io" />
Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
throw new Error("My first Sentry error!");
Or, try a native crash:
Sentry.nativeCrash();
To view and resolve the recorded error, log in to sentry.io and select your project. Clicking the error's title opens a page where you can view detailed information and mark it as resolved.
At this point, you should have integrated Sentry into your Cordova application and should already be sending data to your Sentry project.
Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:
- Explore practical guides on what to monitor, log, track, and investigate after setup
- Continue to customize your configuration
- Learn how to upload debug symbols to make sure your native stack traces are readable
- Check our Ionic support guide
- Learn how to manually capture errors
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").