Skip to content

Commit 34bc100

Browse files
More of new interfaces
1 parent 85c1559 commit 34bc100

File tree

9 files changed

+103
-125
lines changed

9 files changed

+103
-125
lines changed

docs/platforms/react-native/profiling/index.mdx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ description: "Learn how to enable profiling in your app if it is not already set
44
sidebar_order: 5000
55
---
66

7-
<PlatformContent includePath="profiling/index/preface" />
87
<PlatformContent includePath="profiling/index/why-profiling" />
98

109
## Enable Tracing
@@ -14,6 +13,8 @@ Profiling depends on Sentry’s Tracing product being enabled beforehand. To ena
1413
```javascript
1514
Sentry.init({
1615
dsn: "___DSN___",
16+
// Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
17+
// We recommend adjusting this value in production.
1718
tracesSampleRate: 1.0,
1819
});
1920
```
@@ -24,7 +25,7 @@ Check out the <PlatformLink to="/tracing/">tracing setup documentation</Platform
2425

2526
<Note>
2627

27-
Profiling for React Native is available in beta in SDK versions `5.8.0` and above.
28+
Profiling for React Native is available in SDK versions `5.32.0` and above.
2829

2930
</Note>
3031

@@ -33,11 +34,11 @@ To enable profiling, set the `profilesSampleRate`:
3334
```javascript
3435
Sentry.init({
3536
dsn: "___DSN___",
37+
// Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
38+
// We recommend adjusting this value in production.
3639
tracesSampleRate: 1.0,
37-
_experiments: {
38-
// profilesSampleRate is relative to tracesSampleRate.
39-
// Here, we'll capture profiles for 100% of transactions.
40-
profilesSampleRate: 1.0,
41-
},
40+
// profilesSampleRate is relative to tracesSampleRate.
41+
// Here, we'll capture profiles for 100% of transactions.
42+
profilesSampleRate: 1.0,
4243
});
4344
```

docs/platforms/react-native/tracing/instrumentation/custom-navigation.mdx

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,33 @@ description: "Learn how to use Sentry's Generic Navigation instrumentation."
44
sidebar_order: 70
55
---
66

7-
Sentry's React Native SDK package ships with instrumentation for [React Navigation](/platforms/react-native/tracing/instrumentation/react-navigation/) and [React Native Navigation](/platforms/react-native/tracing/instrumentation/react-native-navigation/). This allows you to see the performance of your navigation transitions and the errors that occur during them.
7+
Sentry's React Native SDK package ships with instrumentation for [React Navigation](/platforms/react-native/tracing/instrumentation/react-navigation/) and [React Native Navigation](/platforms/react-native/tracing/instrumentation/react-native-navigation/) and [Expo Router](/platforms/react-native/tracing/instrumentation/expo-router/). This allows you to see the performance of your navigation transitions and the errors that occur during them.
88

9-
If you use a navigation library that we don't yet support, or have a custom routing solution, you can use the basic `RoutingInstrumentation`. This page will guide you through setting it up and configuring it to your needs.
9+
If you use a navigation library that we don't yet support, or have a custom routing solution, you can use `startIdleNavigationSpan` function to implement your own navigation integration. This page will guide you through setting it up and configuring it to your needs.
1010

11-
## Bare Bones
11+
```javascript {filename: customNavigationIntegration.js}
12+
import Sentry from '@sentry/react-native';
1213

13-
Every routing instrumentation revolves around one method:
14-
15-
`onRouteWillChange` (context: TransactionContext): Transaction | undefined
16-
17-
You need to ensure that this method is called **before** the route change occurs, and an `IdleTransaction` is created and set on the scope.
14+
const customNavigationIntegration = ({navigator}) => {
15+
navigator.registerRouteChangeListener((newRoute) => {
16+
Sentry.startIdleNavigationSpan({
17+
name: newRoute.name,
18+
op: 'navigation'
19+
})
20+
});
1821

19-
```javascript
20-
// Construct a new instrumentation instance. This is needed to communicate between the integration and React
21-
const routingInstrumentation = new Sentry.RoutingInstrumentation();
22+
return {
23+
name: "CustomNavigation",
24+
};
25+
};
2226

2327
Sentry.init({
24-
...
25-
integrations: [
26-
new Sentry.ReactNativeTracing({
27-
// Pass instrumentation to be used as `routingInstrumentation`
28-
routingInstrumentation,
29-
...
30-
}),
31-
],
32-
})
33-
34-
const App = () => {
35-
<SomeNavigationLibrary
36-
onRouteWillChange={(newRoute) => {
37-
// Call this before the route changes
38-
routingInstrumentation.onRouteWillChange({
39-
name: newRoute.name,
40-
op: 'navigation'
41-
})
42-
}}
43-
/>
44-
};
28+
dsn: '___PUBLIC_DSN___',
29+
// Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
30+
// We recommend adjusting this value in production.
31+
tracesSampleRate: 1.0,
32+
integrations: [customNavigationIntegration({navigator})],
33+
});
4534
```
4635

47-
## Custom Instrumentation
48-
49-
To create a custom routing instrumentation, look at how the `RoutingInstrumentation` class [is implemented](https://github.com/getsentry/sentry-react-native/blob/211ec081b6bf8d7d29541afe9d800040f61e3c4e/src/js/tracing/routingInstrumentation.ts). If you need an example of how to implement routing instrumentation, review the code of the existing official instrumentation such as [the one for React Navigation V4](https://github.com/getsentry/sentry-react-native/blob/211ec081b6bf8d7d29541afe9d800040f61e3c4e/src/js/tracing/reactnavigationv4.ts)
50-
51-
```javascript
52-
class CustomInstrumentation extends RoutingInstrumentation {
53-
constructor(navigator) {
54-
super();
55-
56-
this.navigator.registerRouteChangeListener(this.routeListener.bind(this));
57-
}
58-
59-
routeListener(newRoute) {
60-
// Again, ensure this is called BEFORE the route changes and BEFORE the route is mounted.
61-
this.onRouteWillChange({
62-
name: newRoute.name,
63-
op: "navigation",
64-
});
65-
}
66-
}
67-
```
36+
To lear more about the `Integration` lifecycle, see the [Integration API](/platforms/react-native/integrations/custom/).

docs/platforms/react-native/tracing/instrumentation/expo-router.mdx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,30 @@ Sentry's React Native SDK package ships with instrumentation for Expo Router. Th
1010

1111
The code snippet below shows how to initialize the instrumentation.
1212

13-
```javascript { filename: 'app/_layout.tsx' }
13+
```javascript {6-8, 15-16, 20-25} {filename: app/_layout.tsx}
1414
import React from 'react';
1515
import { Slot, useNavigationContainerRef } from 'expo-router';
16-
import Constants from 'expo-constants';
16+
import Constants, { ExecutionEnvironment.StoreClient } from 'expo-constants';
1717
import * as Sentry from '@sentry/react-native';
1818

19-
const routingInstrumentation = new Sentry.ReactNavigationInstrumentation({
20-
enableTimeToInitialDisplay: Constants.appOwnership !== 'expo', // Only in native builds, not in Expo Go.
19+
const navigationIntegration = Sentry.reactNavigationintegration({
20+
enableTimeToInitialDisplay: Constants.executionEnvironment === ExecutionEnvironment.StoreClient, // Only in native builds, not in Expo Go.
2121
});
2222

2323
Sentry.init({
2424
dsn: '___PUBLIC_DSN___',
25-
integrations: [
26-
new Sentry.ReactNativeTracing({
27-
routingInstrumentation,
28-
enableNativeFramesTracking: Constants.appOwnership !== 'expo', // Only in native builds, not in Expo Go.
29-
}),
30-
],
25+
// Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
26+
// We recommend adjusting this value in production.
27+
tracesSampleRate: 1.0,
28+
integrations: [navigationIntegration],
29+
enableNativeFramesTracking: Constants.executionEnvironment === ExecutionEnvironment.StoreClient, // Only in native builds, not in Expo Go.
3130
});
3231

3332
function RootLayout() {
3433
const ref = useNavigationContainerRef();
35-
3634
React.useEffect(() => {
3735
if (ref) {
38-
routingInstrumentation.registerNavigationContainer(ref);
36+
navigation.registerNavigationContainer(ref);
3937
}
4038
}, [ref]);
4139

@@ -50,19 +48,24 @@ export default Sentry.wrap(RootLayout);
5048
You can configure the instrumentation by passing an options object to the constructor:
5149

5250
```javascript
53-
new Sentry.ReactNavigationInstrumentation({
51+
Sentry.reactNavigationintegration({
5452
enableTimeToInitialDisplay: true, // default: false
5553
routeChangeTimeoutMs: 1000, // default: 1000
54+
ignoreEmptyBackNavigationTransactions: true, // default: true
5655
});
5756
```
5857

5958
### routeChangeTimeoutMs
6059

61-
This option specifies how long the instrumentation will wait for the route to mount after a change has been initiated before the transaction is discarded. The default value is 1000ms.
60+
This option specifies how long the instrumentation will wait for the route to mount after a change has been initiated before the transaction is discarded. The default value is `1_000`.
6261

6362
### enableTimeToInitialDisplay
6463

65-
This option will enable automatic measuring of the time to initial display for each route. To learn more see [Time to Initial Display](/platforms/react-native/tracing/instrumentation/time-to-display).
64+
This option will enable automatic measuring of the time to initial display for each route. To learn more see [Time to Initial Display](/platforms/react-native/tracing/instrumentation/time-to-display). The default value is `false`.
65+
66+
### ignoreEmptyBackNavigationTransactions
67+
68+
Does not sample transactions that are from routes that have been seen any more and don't have any spans. This removes a lot of the clutter as most back navigation transactions are now ignored. The default value is `true`.
6669

6770
## Notes
6871

docs/platforms/react-native/tracing/instrumentation/react-native-navigation.mdx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@ Sentry's React Native SDK package ships with instrumentation for [React Native N
1010

1111
You will need to pass the `Navigation` object imported from the library to initialize our routing instrumentation. It is recommended that you initialize our SDK and the routing instrumentation as early as possible in the lifecycle of your app; this would most likely be before the point where you initialize your screens.
1212

13-
```javascript {filename: index.js}
13+
```javascript {7-9} {filename: index.js}
1414
import * as Sentry from "@sentry/react-native";
1515
import { Navigation } from 'react-native-navigation';
1616

1717
Sentry.init({
18-
...
18+
dsn: "___PUBLIC_DSN___",
1919
integrations: [
20-
new Sentry.ReactNativeTracing({
21-
// Pass instrumentation to be used as `routingInstrumentation`
22-
routingInstrumentation: new Sentry.ReactNativeNavigationInstrumentation(
23-
Navigation,
24-
)
25-
// ...
20+
Sentry.reactNativeNavigationIntegration({
21+
navigation: Navigation,
2622
}),
2723
],
2824
})
@@ -33,11 +29,26 @@ Sentry.init({
3329
You can configure the instrumentation by passing an options object to the constructor:
3430

3531
```javascript
36-
new Sentry.ReactNativeNavigationInstrumentation({
37-
routeChangeTimeoutMs: 1000, // default: 1000
32+
Sentry.reactNativeNavigationIntegration({
33+
navigation: Navigation, // Navigation from `react-native-navigation`
34+
routeChangeTimeoutMs: 1_000, // default: 1_000
35+
enableTabsInstrumentation: true, // default: false
36+
ignoreEmptyBackNavigationTransactions: true, // default: true
3837
});
3938
```
4039

40+
### navigation
41+
42+
This option is required and should be the `Navigation` object imported from the navigation library.
43+
4144
### routeChangeTimeoutMs
4245

43-
This option specifies how long the instrumentation will wait for the route to mount after a change has been initiated before the transaction is discarded. The default value is 1000ms.
46+
This option specifies how long the instrumentation will wait for the route to mount after a change has been initiated before the transaction is discarded. The default value is `1_000`.
47+
48+
### enableTabsInstrumentation
49+
50+
Instrumentation will create a transaction on tab change. By default only navigation commands create transactions. The default value is `false`.
51+
52+
### ignoreEmptyBackNavigationTransactions
53+
54+
Does not sample transactions that are from routes that have been seen any more and don't have any spans. This removes a lot of the clutter as most back navigation transactions are now ignored. The default value is `true`.

docs/platforms/react-native/tracing/instrumentation/react-navigation.mdx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,28 @@ The code snippet below shows how to initialize the instrumentation.
1717
You can configure the instrumentation by passing an options object to the constructor:
1818

1919
```javascript
20-
new Sentry.ReactNavigationInstrumentation({
20+
Sentry.reactNavigationintegration({
2121
enableTimeToInitialDisplay: true, // default: false
22-
routeChangeTimeoutMs: 1000, // default: 1000
22+
routeChangeTimeoutMs: 1_000, // default: 1_000
23+
ignoreEmptyBackNavigationTransactions: true, // default: true
2324
});
2425
```
2526

2627
### routeChangeTimeoutMs
2728

28-
This option specifies how long the instrumentation will wait for the route to mount after a change has been initiated before the transaction is discarded. The default value is 1000ms.
29+
This option specifies how long the instrumentation will wait for the route to mount after a change has been initiated before the transaction is discarded. The default value is `1_000`.
2930

3031
### enableTimeToInitialDisplay
3132

32-
This option will enable automatic measuring of the time to initial display for each route. To learn more see [Time to Initial Display](/platforms/react-native/tracing/instrumentation/time-to-display).
33+
This option will enable automatic measuring of the time to initial display for each route. To learn more see [Time to Initial Display](/platforms/react-native/tracing/instrumentation/time-to-display). The default value is `false`.
34+
35+
### ignoreEmptyBackNavigationTransactions
36+
37+
Does not sample transactions that are from routes that have been seen any more and don't have any spans. This removes a lot of the clutter as most back navigation transactions are now ignored. The default value is `true`.
3338

3439
## Notes
3540

36-
- This instrumentation supports React Navigation version 5 and above. If you use React Navigation version 4, see the [instrumentation for React Navigation V4](/platforms/react-native/tracing/instrumentation/react-navigation-v4/).
41+
- This instrumentation supports React Navigation version 5 and above. Starting the SDK version 6 React Navigation 4 is not supported, please upgrade.
3742

3843
- The instrumentation creates a transaction on every route change including `goBack` navigations.
3944

docs/platforms/react-native/tracing/instrumentation/time-to-display.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ To automatically measure Time to Initial Display of React Navigation Screens, en
3030

3131
When the automatically captured Time to Initial Display doesn't meet your requirements, you can overwrite it by using `Sentry.TimeToInitialDisplay` component.
3232

33-
```jsx {tabTitle: <TimeToInitialDisplay />}
33+
```jsx {8} {tabTitle: <TimeToInitialDisplay />}
3434
import * as Sentry from "@sentry/react-native";
3535
import * as React from "react";
3636
import { View } from "react-native";
@@ -48,7 +48,7 @@ function MyComponent() {
4848

4949
To measure the time when a screen is fully displayed, you can use the `Sentry.TimeToFullDisplay` component.
5050

51-
```jsx {tabTitle: <TimeToFullDisplay />}
51+
```jsx {17} {tabTitle: <TimeToFullDisplay />}
5252
import * as Sentry from "@sentry/react-native";
5353
import { useState, useEffect } from "react";
5454
import { View, Text } from "react-native";

docs/platforms/react-native/tracing/instrumentation/user-interaction-instrumentation.mdx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@ Transaction names are composed from a combination of displayed screen names, (fo
2020

2121
UI instrumentation tracing is disabled by default, but you can enable it by setting the `enableUserInteractionTracing` options to `true` and wrapping your root component:
2222

23-
```javascript
23+
```javascript {3-3, 7-9}
2424
import * as Sentry from "@sentry/react-native";
2525

26+
const navigationIntegration = Sentry.reactNavigationIntegration(); // Or any other navigation integration
27+
2628
Sentry.init({
27-
// ...
28-
integrations: [
29-
new Sentry.ReactNativeTracing({
30-
enableUserInteractionTracing: true,
31-
routingInstrumentation,
32-
// ...
33-
}),
34-
],
29+
dsn: "___PUBLIC_DSN___",
30+
enableUserInteractionTracing: true,
31+
tracesSampleRate: 1.0,
32+
integrations: [navigationIntegration],
3533
});
3634

3735
const App = () => <View>Your App</View>;
@@ -41,7 +39,7 @@ export default Sentry.wrap(App);
4139

4240
The label by which UI elements are identified is set by the `labelName` option in `Sentry.wrap`. If no value is supplied, `sentry-label` will be used instead. If an element can't be identified, the transaction won't be captured.
4341

44-
```javascript
42+
```javascript {2-2}
4543
export default Sentry.wrap(App, {
4644
touchEventBoundaryProps: { labelName: "my-label" },
4745
});
@@ -62,7 +60,7 @@ To create UI transactions from React Native Gesture Handler, you need to wrap in
6260
Only [RNGH API v2](https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/gesture/) is supported.
6361
</Note>
6462

65-
```javascript
63+
```javascript {10-11}
6664
import React from "react";
6765
import { Gesture, GestureDetector } from "react-native-gesture-handler";
6866
import { sentryTraceGesture } from "@sentry/react-native";

0 commit comments

Comments
 (0)