Skip to content

Commit

Permalink
feat: [IOPLT-306] Setup the Sentry performance monitoring and navigat…
Browse files Browse the repository at this point in the history
…ion tracing (#6114)

## Short description
This PR aims to setup sentry performance monitoring on the app

## List of changes proposed in this pull request
- Changes on Sentry initialization

## How to test
Check navigation events are properly sent to sentry

---------

Co-authored-by: Andrea <[email protected]>
  • Loading branch information
CrisTofani and Vangaorth authored Oct 5, 2024
1 parent 10a5a92 commit 57ec77b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
setNativeExceptionHandler
} from "react-native-exception-handler";

import { App } from "./ts/App";
import App from "./ts/App";
import { mixpanel } from "./ts/mixpanel";
import { name as appName } from "./app.json";

Expand Down
21 changes: 19 additions & 2 deletions ts/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { LightModalProvider } from "./components/ui/LightModal";
import { sentryDsn } from "./config";
import { isDevEnv } from "./utils/environment";

export const routingInstrumentation = Sentry.reactNavigationIntegration({
enableTimeToInitialDisplay: true
});

const removeUserFromEvent = (event: ErrorEvent | TransactionEvent) => {
// console.log(JSON.stringify(event));
// Modify or drop the event here
Expand All @@ -37,7 +41,12 @@ Sentry.init({
beforeSendTransaction(event) {
return removeUserFromEvent(event);
},
integrations: integrations => [
...integrations,
new Sentry.ReactNativeTracing({ routingInstrumentation })
],
enabled: !isDevEnv,
tracesSampleRate: 0.3,
sampleRate: 0.3
});

Expand All @@ -49,7 +58,7 @@ export type AppDispatch = typeof store.dispatch;
* Main component of the application
* @constructor
*/
export const App = (): JSX.Element => (
const App = (): JSX.Element => (
<GestureHandlerRootView style={{ flex: 1 }}>
<SafeAreaProvider>
<IODSExperimentalContextProvider>
Expand All @@ -59,7 +68,9 @@ export const App = (): JSX.Element => (
<PersistGate loading={undefined} persistor={persistor}>
<BottomSheetModalProvider>
<LightModalProvider>
<RootContainer />
<RootContainer
routingInstumentation={routingInstrumentation}
/>
</LightModalProvider>
</BottomSheetModalProvider>
</PersistGate>
Expand All @@ -70,3 +81,9 @@ export const App = (): JSX.Element => (
</SafeAreaProvider>
</GestureHandlerRootView>
);

/**
* We wrap the main app component with the sentry utility function to handle
* the Performance monitoring
*/
export default Sentry.wrap(App);
10 changes: 8 additions & 2 deletions ts/RootContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Platform,
StatusBar
} from "react-native";
import { ReactNavigationInstrumentation } from "@sentry/react-native";
import SplashScreen from "react-native-splash-screen";
import { connect } from "react-redux";
import configurePushNotifications from "./features/pushNotifications/utils/configurePushNotification";
Expand All @@ -29,7 +30,10 @@ import {
import { GlobalState } from "./store/reducers/types";
import customVariables from "./theme/variables";

type Props = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps;
type Props = ReturnType<typeof mapStateToProps> &
typeof mapDispatchToProps & {
routingInstumentation: ReactNavigationInstrumentation;
};

/**
* The main container of the application with:
Expand Down Expand Up @@ -99,7 +103,9 @@ class RootContainer extends React.PureComponent<Props> {
/>
{Platform.OS === "android" && <FlagSecureComponent />}

<IONavigationContainer />
<IONavigationContainer
routingInstrumentation={this.props.routingInstumentation}
/>

{/* When debug mode is enabled, the following information
is displayed:
Expand Down
20 changes: 17 additions & 3 deletions ts/navigation/AppStackNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "@react-navigation/native";
import React, { useRef } from "react";
import { View } from "react-native";
import { ReactNavigationInstrumentation } from "@sentry/react-native";
import { useStoredExperimentalDesign } from "../common/context/DSExperimentalContext";
import LoadingSpinnerOverlay from "../components/LoadingSpinnerOverlay";
import { cgnLinkingOptions } from "../features/bonus/cgn/navigation/navigator";
Expand Down Expand Up @@ -79,7 +80,11 @@ export const AppStackNavigator = (): React.ReactElement => {
return <AuthenticatedStackNavigator />;
};

const InnerNavigationContainer = (props: { children: React.ReactElement }) => {
type InnerNavigationContainerProps = React.PropsWithChildren<{
routingInstrumentation?: ReactNavigationInstrumentation;
}>;

const InnerNavigationContainer = (props: InnerNavigationContainerProps) => {
const routeNameRef = useRef<string>();
const dispatch = useIODispatch();
const store = useIOStore();
Expand Down Expand Up @@ -164,6 +169,11 @@ const InnerNavigationContainer = (props: { children: React.ReactElement }) => {
linking={linking}
fallback={<LoadingSpinnerOverlay isLoading={true} />}
onReady={() => {
if (props.routingInstrumentation) {
props.routingInstrumentation.registerNavigationContainer(
navigationRef
);
}
NavigationService.setNavigationReady();
routeNameRef.current = navigationRef.current?.getCurrentRoute()?.name;
}}
Expand All @@ -189,8 +199,12 @@ const InnerNavigationContainer = (props: { children: React.ReactElement }) => {
* Wraps the NavigationContainer with the AppStackNavigator (Root navigator of the app)
* @constructor
*/
export const IONavigationContainer = () => (
<InnerNavigationContainer>
export const IONavigationContainer = ({
routingInstrumentation
}: {
routingInstrumentation: ReactNavigationInstrumentation;
}) => (
<InnerNavigationContainer routingInstrumentation={routingInstrumentation}>
<AppStackNavigator />
</InnerNavigationContainer>
);
Expand Down

0 comments on commit 57ec77b

Please sign in to comment.