Hello guys, I am using Sentry on React Native, recently I am trying to configure Sentry correctly with CodePush so it shows the error stack correctly on the dashboard. Now I face a new issue which is calling Sentry.wrap before Sentry.init because I am waiting for the CodePush data to be available. Also note that Hermes is enabled.
Any recommendations on how to fix this?
import "@/helpers/IgnoreWarnings";
import { StyleSheet } from "react-native";
import React, { useRef } from "react";
import "react-native-gesture-handler";
import AppNavigation from "@/navigations/AppNavigation";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { NavigationContainer } from '@react-navigation/native';
import { withIAPContext } from "react-native-iap";
import codePush from "react-native-code-push";
import * as Sentry from '@sentry/react-native';
import Config from 'react-native-config';
const routingInstrumentation = new Sentry.ReactNavigationInstrumentation();
const sentrySampleRate = __DEV__ ? 0 : 0.25;
const enableTrace = __DEV__ ? false : true;
const enabled = __DEV__ ? false : true;
const sentryConfig: Sentry.ReactNativeOptions = {
enabled,
dsn: Config.SENTRY_DSN,
enableTracing: enableTrace,
tracesSampleRate: sentrySampleRate,
integrations: [
new Sentry.ReactNativeTracing({
routingInstrumentation,
}),
],
_experiments: {
profilesSampleRate: sentrySampleRate,
},
};
codePush.getUpdateMetadata().then((update) => {
if (update) {
Sentry.init({
...sentryConfig,
release: `${update.appVersion}+codepush:${update.label}`,
dist: update.label,
});
} else {
Sentry.init({
...sentryConfig,
});
}
});
let App = () => {
const navigation = useRef<any>();
return (
<GestureHandlerRootView style={styles.main}>
<NavigationContainer
ref={navigation}
onReady={() => {
routingInstrumentation.registerNavigationContainer(navigation);
}}>
<AppNavigation />
</NavigationContainer>
</GestureHandlerRootView>
);
};
codePush.sync(
{},
() => { },
() => { },
() => { },
).catch(console.error);
export default codePush(Sentry.wrap(withIAPContext(App)));
const styles = StyleSheet.create({
main: {
flex: 1,
},
});