as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
Ring
AWS
Documentation
Support
Contact Us
My Cases
Get Started
Design and Develop
Publish
Reference
Support

Sentry

Sentry is an error tracking and performance monitoring platform that helps you solve problems and continuously learn about your apps. The @amazon-devices/sentry__react-native library implements the React Native SDK for Sentry on the Vega platform.

During this phase, some of the Sentry features aren't setup for Vega. You can post questions or report issues on the Vega Developer Forums.

Installation

  1. Add the JavaScript library dependency in the package.json file.

     dependencies: {
         "@sentry/react-native": "npm:@amazon-devices/sentry__react-native@~1.0.10"
     }
    
  2. Install dependencies using the npm install command.

Examples

Initialize Sentry on the top-level of you app.

To initialize Sentry use the Sentry.init({...}) method. The only required parameter is the dsn, short for Data Source Name. Find the dsn from the Sentry project's settings page.


import * as Sentry from '@sentry/react-native';
import React from 'react';
import {View, Button, Text} from 'react-native';

// init Sentry somewhere top-level outside of component
Sentry.init({
  // set environment variable SENTRY_DSN to your project's dsn
  // or inline your DSN here
  dsn: process.env.SENTRY_DSN,
});

export function App() {
  const captureMessage = () => {
    // send message directly to Sentry
    Sentry.captureMessage('SentryAppDemo message');
  };

  const captureException = () => {
    // capture exception and send it to Sentry
    Sentry.captureException(new Error('SentryAppDemo error'));
  };

  return (
    <View
      style={{
        backgroundColor: '#181a1b',
        padding: 32,
        flex: 1,
        flexDirection: 'column',
        gap: 16,
      }}>
      <Text style={{fontSize: 32, color: 'white'}}>Sentry App Demo</Text>
      <View style={{width: '25%'}}>
        <Button onPress={captureMessage} title="Capture Message" />
      </View>
      <View style={{width: '25%'}}>
        <Button onPress={captureException} title="Capture Exception" />
      </View>
    </View>
  );
}

Copied to clipboard.

After initializing Sentry, all uncaught exceptions are found automatically and reported by Sentry. You don't need to send events manually.

You can also add extra information to the Sentry events using Sentry.setContext() or Sentry.setUser(), as shown in the following example.


import * as Sentry from '@sentry/react-native';
import React from 'react';
import {View, Button, Text} from 'react-native';

// init Sentry somewhere top-level outside of component
Sentry.init({
  // set environment variable SENTRY_DSN to your project's dsn
  // or inline your DSN here
  dsn: 'process.env.SENTRY_DSN',
});

export function App() {
  const setContext = () => {
    // add custom data to Sentry events
    Sentry.setContext('ExampleContext', {
      category: 'ExampleCategory',
      message: 'ExampleMessage',
      level: 'info',
    });
  };

  const throwError = () => {
    // throw error without catching - Sentry will report this for us
    throw new Error('SentryAppDemo uncaught error');
  };

  return (
    <View
      style={{
        backgroundColor: '#181a1b',
        padding: 32,
        flex: 1,
        flexDirection: 'column',
        gap: 16,
      }}>
      <Text style={{fontSize: 32, color: 'white'}}>Sentry App Demo</Text>
      <View style={{width: '25%'}}>
        <Button onPress={setContext} title="Set Context" />
      </View>
      <View style={{width: '25%'}}>
        <Button onPress={throwError} title="Throw Error" />
      </View>
    </View>
  );
}

Copied to clipboard.

API reference

  • Sentry.init(options: ReactNativeOptions) - Initializes Sentry. After calling it, all errors get reported by Sentry. If your application crashes or throws uncaught exception before the call to Sentry.init(), the error won't be caught by Sentry.
  • Sentry.nativeCrash() - Triggers the native crash, tested, and verified to work on Vega devices and simulator.
  • Sentry.setUser(user: User) - Sets user data (for example, username, email) that is included in Sentry events.
  • Sentry.setContext(contextKey: string, contextData: Object) - Sets custom data to be added under the passed contextKey that is included in Sentry events.
  • Sentry.flush() - Wait for all Sentry events to be sent.
  • Sentry.captureMessage(message: string) - Captures a message event and sends it to Sentry.
  • Sentry.captureException(exception: Error) - Captures an exception event and sends it to Sentry.

Additional configurations

Add readable stack traces to Sentry errors

After the app is built, you need to notify Sentry about the app release name, version, and dist number and send sourcemaps of the JavaScript bundle and debug files. This ensures that Sentry catches events and correctly maps the information with readable stack traces.

After building the app, the folder structure might look like this:

├── sentrydemoapp
│   ├── build
│   │   ├── lib
│   │   │   ├── rn-bundles
│   │   │   │   ├── Debug #use the path for debug build
│   │   │   │   ├── Release #use the path for release build
│   │   ├── x86_64-release
│   │   │   ├── debug #use the path for app meant for simulator for x86 machines
│   │   ├── armv7-release
│   │   │   ├── debug #use the path for app meant for Fire TV Stick
│   │   ├── aarch64-release
│   │   │   ├── debug #use the path for app meant for simulator for M-series machines
  1. In the Sentry initialization, create a release version and a dist version. Define $SENTRY_RELEASE_VERSION (for example, my-kepler-project@2.3.12) and $SENTRY_DIST_NUMBER (for example 52). See Sentry official docs for more information.
     Sentry.init({
       release: process.env.SENTRY_RELEASE_VERSION,
       dist: process.env.SENTRY_DIST_NUMBER,
     });
    
  2. Add Sentry Metro Serializer to metro.config.js and rebuild the application.

     ...
     const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');
     ...
    
     const sentryMetroSerializer = createSentryMetroSerializer()
    
     const config = {
       serializer: {
         customSerializer(entryPoint, preModules, graph, options) {
           return sentryMetroSerializer(entryPoint, preModules, graph, options)
         },
       },
     };
    
     module.exports = mergeConfig(getDefaultConfig(__dirname), config);
    
  3. Install sentry-cli. See Sentry official docs for more information.
     curl -sL https://sentry.io/get-cli/ | sh
    
  4. Create a new Sentry release. You need to pass the previously defined $SENTRY_RELEASE_VERSION. See Sentry official docs for more information.
     sentry-cli releases new $SENTRY_RELEASE_VERSION
    
  5. Upload source maps for JavaScript symbolication. Note that sentry-wizard is not yet supported. See Sentry official docs for more information.
     # inside Vega app directory
     # BUILD_TYPE is either Debug or Release
     # --release and --dist flags are optional when using Debug IDs
     sentry-cli sourcemaps upload "build/lib/rn-bundles/$BUILD_TYPE" --release "$SENTRY_RELEASE_VERSION" --dist "$SENTRY_DIST_NUMBER"
    

After sending the information to Sentry, you receive precise information regarding where errors occur in your app.

Implementation details

Known issues and limitations

Sentry offline support isn't working on Vega.

API Current Behaviour
Sentry.addBreadcrumb() Does not perform any actions
Sentry.init(options: ReactNativeOptions) Certain options are not supported. See the following table of ReactNativeOptions.

Sentry.init() is missing options.

Sentry.init Option Current Behaviour
options.enableNativeCrashHandling Cannot be disabled at the moment
options.sessionTrackingIntervalMillis Not supported
options.enableNdk NDK only works on Android
options.enableNdkScopeSync NDK only works on Android
options.attachThreads Android-only option
options.sendDefaultPii Android-only option
options.enableAutoPerformanceTracing performance monitoring is not working
options.enableWatchdogTerminationTracking iOS only option
options.enableAppHangTracking iOS-only option
options.appHangTimeoutInterval iOS-only option
options.attachScreenshot Not supported
options.attachViewHierarchy Not supported

Supported versions

Package Version Based On @amazon-devices/react-native-kepler version
1.0.0 5.15.2 2.x.x

For information on additional libraries, see Supported Third-Party Libraries and Services.


Last updated: Sep 30, 2025