From f0107c28e7ab2be4353e04b5e72ee9cda98956c1 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 18 Aug 2026 21:25:47 +0000 Subject: [PATCH] fix(telemetry): route every error report through one reporter that reaches both sinks (#15346) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary `captureException` reaches Sentry only. That is how `workspace_auth_gate_initialization_failure` — one of the two `error_type` values IR-105 is tracked by — fired in production while reading as **zero** on every Datadog dashboard. Only `bootstrap_auth_wait_timeout` dual-wrote, and it did so by hand at the call site. Adds `reportError(cause, { errorType, tags, context, level })` and migrates all seven call sites onto it. `error_type` lands as a Sentry tag and a RUM context field under the same name, so one query works against either console. ## Two further ways a report could go nowhere **Build-time flag defeated the runtime DSN.** `Sentry.init({ enabled: __SENTRY_ENABLED__ })` baked the flag from the *build machine's* `SENTRY_DSN`, but cloud resolves its DSN at runtime from remote config (`sentry_dsn`). A cloud build without the env var left every capture in the app inert no matter how valid the runtime DSN turned out to be. `enabled` now derives from the resolved DSN; the dead define is removed rather than left to rot. **Early-boot reports were dropped.** Datadog RUM initializes behind `initDatadogRum()`'s fire-and-forget dynamic import in `bootstrap.ts` while Sentry initializes in `main.ts`, so a failure raised before either sink existed went nowhere — precisely the failures that leave a user on the splash screen. Reports raised before a sink is live are now buffered (bounded at 25) and flushed once one comes up. `reportError` never throws: a failing error reporter must not become a second failure. ## Verification - `src/platform/telemetry/reportError.test.ts` — 8 cases: both-sink fan-out, degraded single-sink, buffer-then-flush, no double-replay, bounded buffer, non-`Error` normalization, `undefined` tag stripping, sink-throws containment. - Existing suites migrated off the `@sentry/vue` mock onto the `reportError` mock: `bootstrapStore`, `WorkspaceAuthGate`, `useWorkspaceBilling`. - `pnpm vitest run src/platform/telemetry/ src/platform/cloud/onboarding/auth.test.ts` — 391 passed. - `pnpm lint`, `pnpm typecheck`, `pnpm knip` clean. ## Regression risk Low-to-moderate. No behavior change at any call site beyond reaching a second sink. The `enabled` change means Sentry now activates in any non-dev build with a resolvable DSN — which is the intent, but it is the one line worth a close look. ## Follow-ups (not in this PR) - Boot chunks that 404 never execute JS at all, so no in-app reporter can see them. Needs an inline sentinel in `index.html`. - The `/` -> `/cloud/login` -> `/cloud/user-check` redirect loop emits neither `error_type` because auth succeeds on every lap. Needs its own instrumentation. --- global.d.ts | 1 - scripts/vite-define-shim.ts | 2 - src/App.vue | 24 ++- src/bootstrap.ts | 5 +- src/main.ts | 12 +- src/platform/cloud/onboarding/auth.ts | 42 ++--- src/platform/telemetry/reportError.test.ts | 167 ++++++++++++++++++ src/platform/telemetry/reportError.ts | 112 ++++++++++++ .../workspace/auth/WorkspaceAuthGate.test.ts | 16 +- .../workspace/auth/WorkspaceAuthGate.vue | 8 +- .../composables/useWorkspaceBilling.test.ts | 12 +- .../composables/useWorkspaceBilling.ts | 6 +- src/stores/bootstrapStore.test.ts | 26 +-- src/stores/bootstrapStore.ts | 15 +- vite.config.mts | 3 - vitest.setup.ts | 1 - 16 files changed, 349 insertions(+), 103 deletions(-) create mode 100644 src/platform/telemetry/reportError.test.ts create mode 100644 src/platform/telemetry/reportError.ts diff --git a/global.d.ts b/global.d.ts index 4336d060225..a7e26c5b458 100644 --- a/global.d.ts +++ b/global.d.ts @@ -1,6 +1,5 @@ declare const __COMFYUI_FRONTEND_VERSION__: string declare const __COMFYUI_FRONTEND_COMMIT__: string -declare const __SENTRY_ENABLED__: boolean declare const __SENTRY_DSN__: string declare const __ALGOLIA_APP_ID__: string declare const __ALGOLIA_API_KEY__: string diff --git a/scripts/vite-define-shim.ts b/scripts/vite-define-shim.ts index d588155787e..b5af322c9ef 100644 --- a/scripts/vite-define-shim.ts +++ b/scripts/vite-define-shim.ts @@ -5,7 +5,6 @@ type GlobalWithDefines = typeof globalThis & { __COMFYUI_FRONTEND_VERSION__: string - __SENTRY_ENABLED__: boolean __SENTRY_DSN__: string __ALGOLIA_APP_ID__: string __ALGOLIA_API_KEY__: string @@ -20,7 +19,6 @@ const globalWithDefines = globalThis as GlobalWithDefines // Set default values for Playwright test environment globalWithDefines.__COMFYUI_FRONTEND_VERSION__ = process.env.npm_package_version || '1.0.0' -globalWithDefines.__SENTRY_ENABLED__ = false globalWithDefines.__SENTRY_DSN__ = '' globalWithDefines.__ALGOLIA_APP_ID__ = '' globalWithDefines.__ALGOLIA_API_KEY__ = '' diff --git a/src/App.vue b/src/App.vue index acc8fdb237f..9848181076d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -5,13 +5,13 @@