fix(analytics): only autocapture exceptions in production builds#797
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(analytics): only autocapture exceptions in production builds#797posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
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
🧙 Wizard CIRun the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands: Test all apps:
Test all apps in a directory:
Test an individual app:
Show more apps
Results will be posted here when complete. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A new error-tracking issue fired for a caught
SyntaxError: Expected property name or '}' in JSONoriginating from the wizard's own unit tests — not from any real user. The stack traces through vitest intofile-watcher.test.ts, whose'swallows invalid JSON without throwing'case deliberately writes{not validto a watched file. The watcher'stry/catchcorrectly swallows it (mechanism.handled: true), yet it still lands in error tracking.The reason: the module-level posthog-node client in
src/utils/analytics.tssetenableExceptionAutocapture: trueunconditionally, which installs a process-wide exception handler. Instantiated inside the test/dev process, it scoops up unrelated throws and reports them. Zero real-user impact — just noise that can bury real issues.Changes
Gate
enableExceptionAutocaptureonIS_PRODUCTION_BUILDso only published builds autocapture exceptions. Dev/CI runs still send their normally-tagged (build: 'dev'/'ci') analytics — they just no longer hijack the process's exception handler. Thefile-watcher.tstry/catchis left as-is; it was already correct and is intentionally tested.Test plan
pnpm build && pnpm test && pnpm fix— all 1156 unit tests pass, build and lint clean.Created with PostHog Code from an inbox report.