From 82e4d350f5981fe54801961eb793d48cdc037901 Mon Sep 17 00:00:00 2001 From: "posthog[bot]" <206114724+posthog[bot]@users.noreply.github.com> Date: Fri, 3 Jul 2026 19:19:24 +0000 Subject: [PATCH] fix(analytics): only autocapture exceptions in production builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The module-level posthog-node client set `enableExceptionAutocapture: true` unconditionally. That installs a process-wide exception handler that scoops up any exception in the process — including ones from dev/test runs. A vitest suite that deliberately exercises a caught JSON.parse ended up surfacing as a spurious `$exception` issue in our own error tracking (handled: true, random per-process anonymous IDs, $lib: posthog-node). Gate the flag on IS_PRODUCTION_BUILD so dev/CI processes no longer hijack the exception handler. Dev/CI runs still send their normally-tagged analytics; they just stop autocapturing unrelated throws. Generated-By: PostHog Code Task-Id: c233e4a5-da14-495e-8fa8-48fb77f3f077 --- src/utils/analytics.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/utils/analytics.ts b/src/utils/analytics.ts index b49c855e..73d26327 100644 --- a/src/utils/analytics.ts +++ b/src/utils/analytics.ts @@ -66,7 +66,15 @@ export class Analytics { host: ANALYTICS_HOST_URL, flushAt: 1, flushInterval: 0, - enableExceptionAutocapture: true, + // Only autocapture exceptions in published builds. The posthog-node + // client installs a process-wide handler that scoops up *any* exception + // in the process — in dev/test runs that includes unrelated throws (e.g. + // a vitest suite deliberately exercising a caught JSON.parse), which then + // surface as spurious issues in our own error tracking. Dev/CI runs still + // send their tagged analytics; they just don't hijack the process's + // exception handler. tsdown inlines IS_PRODUCTION_BUILD to `true` only in + // published builds. + enableExceptionAutocapture: IS_PRODUCTION_BUILD, before_send: (event) => { if (!event) return event; if (Object.keys(this.groups).length > 0) {