mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-11-01 18:19:43 +00:00
feat(mobile): add expo-observe update health tracking
Install expo-observe (56.0.29, matching the SDK 56 line) and configure its endpoint under expo.extra.eas.observe in app.json, alongside the existing EAS projectId. Leave dispatchInDebug and sampleRate at their defaults. Log an app_started custom event once per cold start from the root layout's existing "run once" startup effect, and install a global JS error handler that logs xprem_js_crash and then always delegates to whatever handler was previously registered, so existing Crashlytics reporting is unaffected. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6bc4e31719
commit
659cee76b6
4 files changed
+197
-21
No files matched your search
@@ -0,0 +1,66 @@
|
||||
// EAS Observe wrapper. Keeps expo-observe usage in one place and fails soft
|
||||
// so a metrics problem never blocks app startup or crash reporting.
|
||||
import { Observe } from "expo-observe";
|
||||
|
||||
type ErrorHandler = (error: unknown, isFatal: boolean) => void;
|
||||
|
||||
interface GlobalWithErrorUtils {
|
||||
ErrorUtils?: {
|
||||
getGlobalHandler(): ErrorHandler;
|
||||
setGlobalHandler(handler: ErrorHandler): void;
|
||||
};
|
||||
}
|
||||
|
||||
let appStartedLogged = false;
|
||||
|
||||
/**
|
||||
* Logs the `app_started` custom event once per process lifetime. Safe to call
|
||||
* more than once; only the first call has an effect.
|
||||
*/
|
||||
export function logAppStarted() {
|
||||
if (appStartedLogged) return;
|
||||
appStartedLogged = true;
|
||||
|
||||
try {
|
||||
Observe.logEvent("app_started");
|
||||
} catch (error) {
|
||||
console.warn("[Observe] Failed to log app_started:", error);
|
||||
}
|
||||
}
|
||||
|
||||
let globalErrorHandlerInstalled = false;
|
||||
|
||||
/**
|
||||
* Installs a global fatal JS error handler that records an `xprem_js_crash`
|
||||
* Observe event and then always delegates to whatever handler was previously
|
||||
* registered (RN's default redbox handler, or another handler such as
|
||||
* Crashlytics's, if one is installed first). Existing crash reporting is
|
||||
* never replaced, only observed.
|
||||
*/
|
||||
export function installObserveGlobalErrorHandler() {
|
||||
if (globalErrorHandlerInstalled) return;
|
||||
|
||||
const errorUtils = (global as GlobalWithErrorUtils).ErrorUtils;
|
||||
if (!errorUtils) {
|
||||
console.warn("[Observe] ErrorUtils is unavailable; xprem_js_crash will not be recorded.");
|
||||
return;
|
||||
}
|
||||
|
||||
globalErrorHandlerInstalled = true;
|
||||
const previousHandler = errorUtils.getGlobalHandler();
|
||||
|
||||
errorUtils.setGlobalHandler((error, isFatal) => {
|
||||
try {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
Observe.logEvent("xprem_js_crash", {
|
||||
severity: "fatal",
|
||||
body: message,
|
||||
attributes: { isFatal: Boolean(isFatal) },
|
||||
});
|
||||
} catch (observeError) {
|
||||
console.warn("[Observe] Failed to log xprem_js_crash:", observeError);
|
||||
}
|
||||
|
||||
previousHandler(error, isFatal);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user