diff --git a/admin/src/lib/observability.ts b/admin/src/lib/observability.ts index 97b6619f3..71c30d3fc 100644 --- a/admin/src/lib/observability.ts +++ b/admin/src/lib/observability.ts @@ -53,8 +53,10 @@ let identity: Identity = null; let awaiting = 0; let removeEarlyHandlers: (() => void) | null = null; -// REPORTS_ERRORS is whether a configured backend receives captureException; without one the console is the only record. -export const REPORTS_ERRORS = (Boolean(POSTHOG_KEY) && POSTHOG_ERROR_TRACKING) || Boolean(SENTRY_DSN); +// reportsErrors is whether a configured backend receives captureException; without one the console is the only record. +export function reportsErrors(): boolean { + return (Boolean(POSTHOG_KEY) && POSTHOG_ERROR_TRACKING) || Boolean(SENTRY_DSN); +} // initErrorReporting is called once, before the app renders. The name is // historical: on PostHog it is also what starts analytics and session replay, diff --git a/admin/src/main.tsx b/admin/src/main.tsx index 3ccd04045..316908600 100644 --- a/admin/src/main.tsx +++ b/admin/src/main.tsx @@ -16,7 +16,7 @@ import "@fontsource/inter/500.css"; import "@fontsource/inter/600.css"; import { ReauthCancelledError, SessionExpiredError } from "@/lib/api/client"; -import { captureException, initErrorReporting, REPORTS_ERRORS } from "@/lib/observability"; +import { captureException, initErrorReporting, reportsErrors } from "@/lib/observability"; import { reportFailure } from "@/lib/api/reportFailure"; import { Toaster } from "@/components/ui/sonner"; @@ -223,12 +223,12 @@ initErrorReporting(); // A caught error is reported by reportRouteError below; React's console copy would report it twice. const logCaught = (error: unknown, info: { componentStack?: string }) => { - if (import.meta.env.DEV || !REPORTS_ERRORS) console.error(error, info.componentStack); + if (import.meta.env.DEV || !reportsErrors()) console.error(error, info.componentStack); }; // The one report for every route's render, loader and action errors, including routes with no errorElement. const reportRouteError = (error: unknown) => { - if (import.meta.env.DEV || !REPORTS_ERRORS) console.error(error); + if (import.meta.env.DEV || !reportsErrors()) console.error(error); // A lapsed session is the sign-in screen's job, and a closed confirm prompt is a choice. if (error instanceof SessionExpiredError || error instanceof ReauthCancelledError) return; captureException(error); diff --git a/web/src/components/layout/ErrorBoundary.tsx b/web/src/components/layout/ErrorBoundary.tsx index b3d6d76be..8f61a5408 100644 --- a/web/src/components/layout/ErrorBoundary.tsx +++ b/web/src/components/layout/ErrorBoundary.tsx @@ -12,7 +12,7 @@ import React from "react"; import { useLocation, useRouter } from "@tanstack/react-router"; import { AlertTriangleIcon, RefreshCcwIcon } from "lucide-react"; -import { captureException, REPORTS_ERRORS } from "@/lib/observability"; +import { captureException, reportsErrors } from "@/lib/observability"; import { SENTRY_RELEASE } from "@/lib/information"; import { canReloadForStaleChunk, isModuleLoadError, reloadForStaleChunk } from "@/lib/moduleLoadError"; @@ -52,7 +52,7 @@ export class ErrorBoundary extends React.Component { // SDK only when it had put itself there, which a bundled one does not. captureException(error); // Reported just above; console capture would file the same error again. - if (import.meta.env.DEV || !REPORTS_ERRORS) console.error("[ErrorBoundary]", error, info?.componentStack); + if (import.meta.env.DEV || !reportsErrors()) console.error("[ErrorBoundary]", error, info?.componentStack); } reset = () => { diff --git a/web/src/lib/observability.ts b/web/src/lib/observability.ts index 5ffca1edc..64b1c444c 100644 --- a/web/src/lib/observability.ts +++ b/web/src/lib/observability.ts @@ -53,8 +53,10 @@ let identity: Identity = null; let awaiting = 0; let removeEarlyHandlers: (() => void) | null = null; -// REPORTS_ERRORS is whether a configured backend receives captureException; without one the console is the only record. -export const REPORTS_ERRORS = (Boolean(POSTHOG_KEY) && POSTHOG_ERROR_TRACKING) || Boolean(SENTRY_DSN); +// reportsErrors is whether a configured backend receives captureException; without one the console is the only record. +export function reportsErrors(): boolean { + return (Boolean(POSTHOG_KEY) && POSTHOG_ERROR_TRACKING) || Boolean(SENTRY_DSN); +} // initErrorReporting is called once, before the app renders. export function initErrorReporting(): void { diff --git a/web/src/main.tsx b/web/src/main.tsx index 7d464ba85..37616d6a4 100644 --- a/web/src/main.tsx +++ b/web/src/main.tsx @@ -8,7 +8,7 @@ import { ReactQueryDevtools } from "@tanstack/react-query-devtools" import { RouterProvider } from "@tanstack/react-router"; import { Toaster } from '@/components/ui/toaster'; -import { initErrorReporting, REPORTS_ERRORS } from "@/lib/observability"; +import { initErrorReporting, reportsErrors } from "@/lib/observability"; import { initProductAnalytics } from "@/lib/productAnalytics"; import { installDomMutationGuard } from "@/lib/domGuard"; import { queryClient } from "@/lib/queryClient"; @@ -24,7 +24,7 @@ initProductAnalytics(); // A caught error is reported by the boundary that caught it; React's console copy would report it twice. const logCaught = (error: unknown, info: { componentStack?: string }) => { - if (import.meta.env.DEV || !REPORTS_ERRORS) console.error(error, info.componentStack) + if (import.meta.env.DEV || !reportsErrors()) console.error(error, info.componentStack) } const rootEl = document.getElementById('root')!