Skip to content

Commit d22d280

Browse files
updating readme file for instrumentation-react-native-navigation
1 parent 560152a commit d22d280

File tree

1 file changed

+48
-2
lines changed
  • plugins/node/instrumentation-react-native-navigation

1 file changed

+48
-2
lines changed

plugins/node/instrumentation-react-native-navigation/README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ yarn add @opentelemetry/instrumentation-react-native-navigation @opentelemetry/a
1919

2020
## Usage
2121

22-
This package is designed to streamline your workflow by requiring minimal setup. To use this package, you only need to pass a reference and a optionally provider (the global one will be used by default)
22+
This package is designed to streamline your workflow by requiring minimal setup. To use this package, you only need to pass a reference and a optionally provider (the global one will be used by default).
23+
24+
### Expo Router / React Native Navigation
2325

2426
If you are using `expo-router` or `react-native/navigation` you need to wrap your entire application with the `NavigationTracker` component.
2527

@@ -30,7 +32,8 @@ import {NavigationTracker} from '@opentelemetry/instrumentation-react-native-nav
3032
import {useProvider} from "./test/hooks/useProvider";
3133

3234
const App: FC = () => {
33-
const navigationRef = useNavigationContainerRef(); // if you do not use `expo-router` the same hook is also available in `@react-navigation/native` since `expo-router` is built on top of it. Just make sure this ref is passed also to the navigation container at the root of your app (if not, the ref would be empty and you will get a console.warn message instead).
35+
// if you do not use `expo-router` the same hook is also available in `@react-navigation/native` since `expo-router` is built on top of it. Just make sure this ref is passed also to the navigation container at the root of your app (if not, the ref would be empty and you will get a console.warn message instead).
36+
const navigationRef = useNavigationContainerRef();
3437

3538
const provider = useProvider(); // the provider is something you need to configure and pass down as prop into the `NavigationTracker` component (this hook is not part of the package, it is just used here as a reference)
3639
// If your choice is not to pass any custom tracer provider, the <NavigationTracker /> component will use the global one.
@@ -61,6 +64,49 @@ const App: FC = () => {
6164
export default App;
6265
```
6366

67+
If you are using the `useNavigationContainerRef()` from the `@react-navigation/native` package please make sure you wrap what it returns into the proper shape of a reference (i.e `{ current: { <useNavigationContainerRef value> } }`), otherwise it won't work as expected and you will see the mentioned console.warn message insted (in case `debug` mode is enabled).
68+
69+
```javascript
70+
import {FC, useMemo} from 'react';
71+
import {Stack} from 'expo-router';
72+
import {useNavigationContainerRef} from '@react-navigation/native';
73+
import {NavigationTracker} from '@opentelemetry/instrumentation-react-native-navigation';
74+
import {useProvider} from "./test/hooks/useProvider";
75+
76+
const App: FC = () => {
77+
// Trick: if you inspect the source code of `useNavigationContainerRef` from `@react-navigation/native` you will see that it returns `navigation.current` instead of the entire shape of a reference.
78+
const navigationRefVal = useNavigationContainerRef();
79+
// We need here that entire shape, so we re-create it and pass it down into the `ref` prop for the `NavigationTracker` component.
80+
const navigationRef = useRef(navigationRefVal);
81+
82+
const provider = useProvider();
83+
84+
const config = useMemo(() => ({
85+
tracerOptions: {
86+
schemaUrl: "",
87+
},
88+
attributes: {
89+
"static.attribute.key": "static.attribute.value",
90+
"custom.attribute.key": "custom.attribute.value",
91+
},
92+
debug: false,
93+
}), []);
94+
95+
return (
96+
<NavigationTracker ref={navigationRef} provider={provider}>
97+
<Stack>
98+
<Stack.Screen name="(tabs)" options={{headerShown: false}} />
99+
<Stack.Screen name="+not-found" />
100+
</Stack>
101+
</NavigationTracker>
102+
);
103+
};
104+
105+
export default App;
106+
```
107+
108+
### Wix React Native Navigation
109+
64110
If you are using `wix/react-native-navigation` you are also able to track navigation changes by importing and implement the `NativeNavigationTracker` component. The purpose in here is to wrap the entire application with the exposed component.
65111

66112
```javascript

0 commit comments

Comments
 (0)