Skip to content

Commit 0303c8e

Browse files
author
Lalit Sharma
committed
feat: refactor Sentry initialization for improved configuration handling
1 parent 47e6045 commit 0303c8e

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

apps/mobile/src/App.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { useEffect } from "react";
2-
import { SafeAreaProvider } from "react-native-safe-area-context";
3-
import * as Speech from "expo-speech";
4-
import * as SplashScreen from "expo-splash-screen";
51
import * as Sentry from "@sentry/react-native";
62
import { addNotificationReceivedListener } from "expo-notifications/build/NotificationsEmitter";
3+
import * as Speech from "expo-speech";
4+
import * as SplashScreen from "expo-splash-screen";
5+
import { useEffect } from "react";
6+
import { SafeAreaProvider } from "react-native-safe-area-context";
77

88
import ErrorBoundary from "./components/ErrorBoundary";
99
import RootNavigator from "./navigation/RootNavigator";
@@ -12,10 +12,16 @@ import { AppStateProvider } from "./state/appState";
1212

1313
SplashScreen.preventAutoHideAsync();
1414

15-
Sentry.init({
16-
dsn: "__YOUR_SENTRY_DSN__",
17-
enabled: !__DEV__,
18-
});
15+
const sentryDsn = "__YOUR_SENTRY_DSN__".trim();
16+
const isValidSentryDsn = /^https?:\/\/.+/.test(sentryDsn);
17+
const isSentryEnabled = !__DEV__ && isValidSentryDsn;
18+
19+
if (isSentryEnabled) {
20+
Sentry.init({
21+
dsn: sentryDsn,
22+
enabled: true,
23+
});
24+
}
1925

2026
function AppInner() {
2127
useEffect(() => {
@@ -51,10 +57,12 @@ function AppInner() {
5157
);
5258
}
5359

54-
export default Sentry.wrap(function App() {
60+
function App() {
5561
return (
5662
<ErrorBoundary>
5763
<AppInner />
5864
</ErrorBoundary>
5965
);
60-
});
66+
}
67+
68+
export default isSentryEnabled ? Sentry.wrap(App) : App;

0 commit comments

Comments
 (0)