Skip to content
Merged
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ FB_PROJECT_ID=YOUR_PROJECT_ID
GITHUB_TOKEN=YOUR_TOKEN
OPENAI_API_KEY=YOUR_TOKEN

SENTRY_DSN=https://7b463fb4d4402d342d1166d929a62f4e@o4510228013121536.ingest.us.sentry.io/4510228107427840
Comment thread
mateuuszzzzz marked this conversation as resolved.
Resolved
SENTRY_AUTH_TOKEN=SENTRY_AUTH_TOKEN
SENTRY_ALLOW_FAILURE=true
1 change: 0 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ PUSHER_APP_KEY=268df511a204fbb60884
USE_WEB_PROXY=false
ENVIRONMENT=production
SEND_CRASH_REPORTS=true

FB_API_KEY=AIzaSyBrLKgCuo6Vem6Xi5RPokdumssW8HaWBow
FB_APP_ID=1:1008697809946:web:08de4ecb7656b7235445a3
FB_PROJECT_ID=expensify-mobile-app
1 change: 1 addition & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,7 @@ const CONST = {
BREADCRUMB_CATEGORY_MFA: 'mfa',
BREADCRUMB_CATEGORY_3DS_NAVIGATION: '3ds.navigation',
BREADCRUMB_CATEGORY_3DS_AUTHORIZE: '3ds.authorize',
BREADCRUMB_CATEGORY_BOOTSPLASH_FLOW: 'bootsplash.flow',
BREADCRUMB_CATEGORY_MODULE_INIT: 'module.init',
BREADCRUMB_CATEGORY_SCRIPT_LOAD: 'script.load',
BREADCRUMB_MEMORY_PERIODIC: 'Periodic memory check',
Expand Down
35 changes: 21 additions & 14 deletions src/Expensify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import NavigationRoot from './libs/Navigation/NavigationRoot';
import NetworkConnection from './libs/NetworkConnection';
import PushNotification from './libs/Notification/PushNotification';
import {endSpan, getSpan, startSpan} from './libs/telemetry/activeSpans';
import type {BootsplashGateStatus} from './libs/telemetry/bootsplashTelemetry';
import {startBootsplashMonitor} from './libs/telemetry/bootsplashTelemetry';
import {cleanupMemoryTrackingTelemetry, initializeMemoryTrackingTelemetry} from './libs/telemetry/TelemetrySynchronizer';
import Visibility from './libs/Visibility';
import ONYXKEYS from './ONYXKEYS';
Expand Down Expand Up @@ -138,6 +140,22 @@ function Expensify() {
const shouldInit = isNavigationReady && hasAttemptedToOpenPublicRoom && !!preferredLocale;
const shouldHideSplash = shouldInit && (CONFIG.IS_HYBRID_APP ? isSplashReadyToBeHidden : isSplashVisible);

// We store this in a ref to get the latest values in BootsplashMonitor callback
const gateStatusRef = useRef<BootsplashGateStatus | null>(null);
gateStatusRef.current = {
splashScreenState,
isOnyxMigrated,
isCheckingPublicRoom,
hasAttemptedToOpenPublicRoom,
isNavigationReady,
preferredLocale,
shouldInit,
shouldHideSplash,
isAuthenticated,
updateRequired,
lastVisitedPath,
};

useEffect(() => {
if (!shouldHideSplash) {
return;
Expand Down Expand Up @@ -205,21 +223,10 @@ function Expensify() {
}, []);

useEffect(() => {
setTimeout(() => {
const appState = AppState.currentState;
Log.info('[BootSplash] splash screen status', false, {appState, splashScreenState});

if (splashScreenState === CONST.BOOT_SPLASH_STATE.VISIBLE) {
const propsToLog = {
isCheckingPublicRoom,
updateRequired,
isAuthenticated,
lastVisitedPath,
};
Log.alert('[BootSplash] splash screen is still visible', {propsToLog}, false);
}
}, 30 * 1000);
return startBootsplashMonitor(gateStatusRef);
}, []);

useEffect(() => {
// Run any Onyx schema migrations and then continue loading the main app
migrateOnyx().then(() => {
// In case of a crash that led to disconnection, we want to remove all the push notifications.
Expand Down
6 changes: 6 additions & 0 deletions src/HybridAppHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type HybridAppSettings from './libs/actions/HybridApp/types';
import {setupNewDotAfterTransitionFromOldDot} from './libs/actions/Session';
import Log from './libs/Log';
import {endSpan, startSpan} from './libs/telemetry/activeSpans';
import {addBootsplashBreadcrumb} from './libs/telemetry/bootsplashTelemetry';
import ONYXKEYS from './ONYXKEYS';
import {useSplashScreenActions, useSplashScreenState} from './SplashScreenStateContext';
import isLoadingOnyxValue from './types/utils/isLoadingOnyxValue';
Expand All @@ -23,6 +24,7 @@ function HybridAppHandler() {

setupNewDotAfterTransitionFromOldDot(hybridAppSettings, tryNewDot).then(() => {
if (splashScreenState !== CONST.BOOT_SPLASH_STATE.VISIBLE) {
addBootsplashBreadcrumb('HybridAppHandler: Splash no longer VISIBLE, skipping state transition', {splashScreenState});
return;
}

Expand All @@ -42,13 +44,17 @@ function HybridAppHandler() {
return;
}

addBootsplashBreadcrumb('HybridAppHandler: Requesting settings');
getHybridAppSettings().then((hybridAppSettings: HybridAppSettings | null) => {
if (!hybridAppSettings) {
// Native method can send non-null value only once per NewDot lifecycle. It prevents issues with multiple initializations during reloads on debug builds.
Log.info('[HybridApp] `getHybridAppSettings` called more than once during single NewDot lifecycle. Skipping initialization.');
addBootsplashBreadcrumb('HybridAppHandler: null settings, skipping');
return;
}

addBootsplashBreadcrumb('HybridAppHandler: Settings received', {loggedOutFromOldDot: String(!!hybridAppSettings.hybridApp.loggedOutFromOldDot)});

if (hybridAppSettings.hybridApp.loggedOutFromOldDot) {
startSpan(CONST.TELEMETRY.SPAN_OD_ND_TRANSITION_LOGGED_OUT, {
name: CONST.TELEMETRY.SPAN_OD_ND_TRANSITION_LOGGED_OUT,
Expand Down
10 changes: 8 additions & 2 deletions src/SplashScreenStateContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useContext, useEffect, useState} from 'react';
import type {ValueOf} from 'type-fest';
import CONST from './CONST';
import {addBootsplashBreadcrumb} from './libs/telemetry/bootsplashTelemetry';
import type ChildrenProps from './types/utils/ChildrenProps';

type SplashScreenState = ValueOf<typeof CONST.BOOT_SPLASH_STATE>;
Expand All @@ -10,7 +11,7 @@ type SplashScreenStateContextType = {
};

type SplashScreenActionsContextType = {
setSplashScreenState: React.Dispatch<React.SetStateAction<SplashScreenState>>;
setSplashScreenState: (state: SplashScreenState) => void;
};

const SplashScreenStateContext = React.createContext<SplashScreenStateContextType>({
Expand All @@ -28,7 +29,12 @@ function loadPostSplashScreenModules() {
}

function SplashScreenStateContextProvider({children}: ChildrenProps) {
const [splashScreenState, setSplashScreenState] = useState<SplashScreenState>(CONST.BOOT_SPLASH_STATE.VISIBLE);
const [splashScreenState, setSplashScreenStateRaw] = useState<SplashScreenState>(CONST.BOOT_SPLASH_STATE.VISIBLE);

const setSplashScreenState = (state: SplashScreenState) => {
addBootsplashBreadcrumb(`splashScreenState changed to ${state}`);
setSplashScreenStateRaw(state);
};

// Load post-splash-screen modules when the splash screen is hidden
useEffect(() => {
Expand Down
54 changes: 54 additions & 0 deletions src/libs/telemetry/bootsplashTelemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type {SeverityLevel} from '@sentry/react-native';
import * as Sentry from '@sentry/react-native';
import type React from 'react';
import {AppState} from 'react-native';
import Log from '@libs/Log';
import CONST from '@src/CONST';
import type Locale from '@src/types/onyx/Locale';

function addBootsplashBreadcrumb(message: string, data?: Record<string, string>, level: SeverityLevel = 'info'): void {
Sentry.addBreadcrumb({
category: CONST.TELEMETRY.BREADCRUMB_CATEGORY_BOOTSPLASH_FLOW,
message,
level,
data,
});
}

type BootsplashGateStatus = {
splashScreenState: string;
isOnyxMigrated: boolean;
isCheckingPublicRoom: boolean;
hasAttemptedToOpenPublicRoom: boolean;
isNavigationReady: boolean;
preferredLocale: Locale | undefined;
shouldInit: boolean;
shouldHideSplash: boolean;
isAuthenticated: boolean;
updateRequired: boolean | undefined;
lastVisitedPath: string | undefined;
};

function startBootsplashMonitor(gateStatusRef: React.RefObject<BootsplashGateStatus | null>): () => void {
const intervalId = setInterval(() => {
const currentGateStatus = gateStatusRef.current;
const appState = AppState.currentState;
Log.info('[BootSplash] splash screen status', false, {appState, splashScreenState: currentGateStatus?.splashScreenState});

if (currentGateStatus?.splashScreenState !== CONST.BOOT_SPLASH_STATE.VISIBLE) {
clearInterval(intervalId);
return;
}

Sentry.captureMessage('[BootSplash] splash screen is still visible', {
level: 'warning',
extra: {...currentGateStatus, appState},
fingerprint: ['bootsplash-stuck'],
});
}, 10_000);

return () => clearInterval(intervalId);
}

export {addBootsplashBreadcrumb, startBootsplashMonitor};
export type {BootsplashGateStatus};
3 changes: 3 additions & 0 deletions src/setup/telemetry/setupSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ function setupSentry(): void {
beforeSendTransaction: processBeforeSendTransactions,
enableLogs: true,
beforeSendLog: processBeforeSendLogs,
// In HybridApp, native SDK is initialized early in Application.onCreate (Android) and
// AppDelegate (iOS) to capture breadcrumbs during native startup before JS loads.
autoInitializeNativeSdk: !CONFIG.IS_HYBRID_APP,
});

Sentry.setTag(CONST.TELEMETRY.TAGS.BUILD_TYPE, CONFIG.IS_HYBRID_APP ? CONST.TELEMETRY.BUILD_TYPE_HYBRID_APP : CONST.TELEMETRY.BUILD_TYPE_STANDALONE);
Expand Down
Loading