Skip to content

Commit 8f384b3

Browse files
Add @sentry/react-native/playground (#4916)
* feat(wizard): Add Wizard component and integrate into Expo sample app * add mock data, fix visuals * Add light style and open in browser button * add better error examples, animate sentaur * use playground naming, add hoc for easy access * fix lint * update assets to avoid inclusion when playground is not in use * move examples to a standalone file * Add sentry/react-native/playground export and tests * fix lint and snaps * add changelog * fix message * removed comment --------- Co-authored-by: lucas <[email protected]>
1 parent c352c30 commit 8f384b3

File tree

20 files changed

+2154
-64
lines changed

20 files changed

+2154
-64
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@
88
99
## Unreleased
1010

11+
### Features
12+
13+
- Introducing `@sentry/react-native/playground` ([#4916](https://github.com/getsentry/sentry-react-native/pull/4916))
14+
15+
The new `withSentryPlayground` component allows developers to verify
16+
that the SDK is properly configured and reports errors as expected.
17+
18+
```jsx
19+
import * as Sentry from '@sentry/react-native';
20+
import { withSentryPlayground } from '@sentry/react-native/playground';
21+
22+
function App() {
23+
return <View>...</View>;
24+
}
25+
26+
export default withSentryPlayground(
27+
Sentry.wrap(App)
28+
);
29+
```
30+
1131
### Fixes
1232

1333
- User set by `Sentry.setUser` is prefilled in Feedback Widget ([#4901](https://github.com/getsentry/sentry-react-native/pull/4901))

packages/core/.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module.exports = {
1919
'metro.d.ts',
2020
'plugin/build/**/*',
2121
'expo.d.ts',
22+
'playground.js',
23+
'playground.d.ts',
2224
],
2325
overrides: [
2426
{

packages/core/playground.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './dist/js/playground';

packages/core/playground.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './dist/js/playground';
209 KB
Loading
212 KB
Loading
464 KB
Loading

packages/core/react-native.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ module.exports = {
44
ios: {},
55
android: {
66
packageInstance: 'new RNSentryPackage()',
7-
packageImportPath: 'import io.sentry.react.RNSentryPackage;'
8-
}
9-
}
10-
}
7+
packageImportPath: 'import io.sentry.react.RNSentryPackage;',
8+
},
9+
},
10+
},
1111
};

packages/core/src/js/playground/animations.tsx

Lines changed: 8 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { captureException } from '@sentry/core';
2+
3+
import { NATIVE } from '../wrapper';
4+
5+
// This is a placeholder to match the example code with what Sentry SDK users would see.
6+
const Sentry = {
7+
captureException,
8+
nativeCrash: (): void => {
9+
NATIVE.nativeCrash();
10+
},
11+
};
12+
13+
/**
14+
* Example of error handling with Sentry integration.
15+
*/
16+
export const tryCatchExample = (): void => {
17+
try {
18+
// If you see the line below highlighted the source maps are working correctly.
19+
throw new Error('This is a test caught error.');
20+
} catch (e) {
21+
Sentry.captureException(e);
22+
}
23+
};
24+
25+
/**
26+
* Example of an uncaught error causing a crash from JS.
27+
*/
28+
export const uncaughtErrorExample = (): void => {
29+
// If you see the line below highlighted the source maps are working correctly.
30+
throw new Error('This is a test uncaught error.');
31+
};
32+
33+
/**
34+
* Example of a native crash.
35+
*/
36+
export const nativeCrashExample = (): void => {
37+
Sentry.nativeCrash();
38+
};

0 commit comments

Comments
 (0)