import { useEffect } from "react"; import { Platform } from "react-native"; import { telemetry } from "./telemetry"; const runtimeFlagsTelemetry = telemetry.scope("runtime.flags"); import { startAppLifecycleCrashSentinel, stopAppLifecycleCrashSentinel, } from "./appLifecycleCrashSentinel"; type AppLifecycleObservabilityOptions = { nativeScreensMode: string; rootTabSceneMode: string; }; /** * Installs app-wide runtime diagnostics once at the root of the application. * The navigation and provider tree only supplies the runtime mode values. */ export function useAppLifecycleObservability({ nativeScreensMode, rootTabSceneMode, }: AppLifecycleObservabilityOptions) { useEffect(() => { const platform = Platform.OS; telemetry.tag("native_screens_mode", nativeScreensMode); telemetry.tag("root_tab_scene_mode", rootTabSceneMode); telemetry.context("runtime_navigation_flags", { platform, nativeScreensMode, rootTabSceneMode, }); runtimeFlagsTelemetry.breadcrumb({ message: "runtime navigation flags applied", data: { platform, nativeScreensMode, rootTabSceneMode, }, }); void startAppLifecycleCrashSentinel({ nativeScreensMode }); return () => { stopAppLifecycleCrashSentinel(); }; }, [nativeScreensMode, rootTabSceneMode]); }