|
| 1 | +--- |
| 2 | +title: Playground |
| 3 | +sidebar_order: 10 |
| 4 | +description: "Use the Sentry Playground to verify your React Native SDK setup is working correctly." |
| 5 | +--- |
| 6 | + |
| 7 | +The Sentry Playground is an interactive testing utility that helps you verify your Sentry React Native SDK is properly configured and functioning. It provides a modal interface that allows you to trigger different types of errors during development to test SDK functionality. |
| 8 | + |
| 9 | +## Install |
| 10 | + |
| 11 | +The Playground is available as a separate export from the `@sentry/react-native` package: |
| 12 | + |
| 13 | +```javascript |
| 14 | +import { withSentryPlayground } from "@sentry/react-native/playground"; |
| 15 | +``` |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +Wrap your root component with `withSentryPlayground` to enable the Playground modal: |
| 20 | + |
| 21 | +```javascript {filename:App.js} |
| 22 | +import * as Sentry from "@sentry/react-native"; |
| 23 | +import { withSentryPlayground } from "@sentry/react-native/playground"; |
| 24 | + |
| 25 | +Sentry.init({ |
| 26 | + dsn: "___PUBLIC_DSN___", |
| 27 | +}); |
| 28 | + |
| 29 | +function App() { |
| 30 | + return <View>{/* Your app content */}</View>; |
| 31 | +} |
| 32 | + |
| 33 | +export default withSentryPlayground(Sentry.wrap(App)); |
| 34 | +``` |
| 35 | + |
| 36 | +### Link to Your Sentry Project |
| 37 | + |
| 38 | +You can optionally provide your `projectId` and `organizationSlug` to enable the "Open Sentry" button, which opens your Sentry issues stream directly in the browser: |
| 39 | + |
| 40 | +```javascript {filename:App.js} |
| 41 | +export default withSentryPlayground(Sentry.wrap(App), { |
| 42 | + projectId: "123456", |
| 43 | + organizationSlug: "my-org", |
| 44 | +}); |
| 45 | +``` |
| 46 | + |
| 47 | +You can find these values in your Sentry project settings or in your DSN URL. |
| 48 | + |
| 49 | +## Features |
| 50 | + |
| 51 | +When you launch your app with the Playground enabled, a modal appears with three test scenarios: |
| 52 | + |
| 53 | +### captureException() |
| 54 | + |
| 55 | +Tests manual error capture in a try-catch scenario. This verifies that `Sentry.captureException()` is working correctly. |
| 56 | + |
| 57 | +```javascript |
| 58 | +try { |
| 59 | + throw new Error("This is a test caught error."); |
| 60 | +} catch (e) { |
| 61 | + Sentry.captureException(e); |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### throw new Error() |
| 66 | + |
| 67 | +Tests automatic uncaught error handling. This verifies that the React Native Global Handler is properly catching and reporting uncaught JavaScript errors. |
| 68 | + |
| 69 | +```javascript |
| 70 | +throw new Error("This is a test uncaught error."); |
| 71 | +``` |
| 72 | + |
| 73 | +### Native Crash |
| 74 | + |
| 75 | +Tests native crash reporting by triggering a crash in the native layer (Java on Android, Objective-C/Swift on iOS). This verifies that native crash handling is properly configured. |
| 76 | + |
| 77 | +<Alert> |
| 78 | + |
| 79 | +Native crash testing is only available in release builds. It is disabled in: |
| 80 | +- Development mode (`__DEV__`) |
| 81 | +- Expo Go |
| 82 | +- Web builds |
| 83 | + |
| 84 | +To test native crashes, build your app in release mode. |
| 85 | + |
| 86 | +</Alert> |
| 87 | + |
| 88 | +## Removing the Playground |
| 89 | + |
| 90 | +Once you've verified your SDK setup is working correctly, remove the Playground wrapper before deploying to production: |
| 91 | + |
| 92 | +```javascript {filename:App.js} |
| 93 | +import * as Sentry from "@sentry/react-native"; |
| 94 | +// Remove this import |
| 95 | +// import { withSentryPlayground } from "@sentry/react-native/playground"; |
| 96 | + |
| 97 | +Sentry.init({ |
| 98 | + dsn: "___PUBLIC_DSN___", |
| 99 | +}); |
| 100 | + |
| 101 | +function App() { |
| 102 | + return <View>{/* Your app content */}</View>; |
| 103 | +} |
| 104 | + |
| 105 | +// Change this: |
| 106 | +// export default withSentryPlayground(Sentry.wrap(App)); |
| 107 | +// To this: |
| 108 | +export default Sentry.wrap(App); |
| 109 | +``` |
| 110 | + |
| 111 | +## Platform Support |
| 112 | + |
| 113 | +| Platform | Playground Available | Native Crash Test | |
| 114 | +| -------- | -------------------- | ----------------- | |
| 115 | +| iOS (Release) | Yes | Yes | |
| 116 | +| Android (Release) | Yes | Yes | |
| 117 | +| iOS (Debug) | Yes | No | |
| 118 | +| Android (Debug) | Yes | No | |
| 119 | +| Expo Go | Yes | No | |
| 120 | +| Web | No | No | |
0 commit comments