fix(shared): stop capturing exceptions from development hosts - #809
fix(shared): stop capturing exceptions from development hosts#809posthog[bot] wants to merge 2 commits into
Conversation
initializePostHog enabled capture_exceptions with no environment gate, so localhost QA sessions published $exception events into the shared production project and minted new issues in the triage surface. Add a before_send filter, dropDevelopmentHostExceptions, that drops $exception events whose host is a development host (localhost, loopback, .localhost). It reads the host from the event's $current_url and falls back to the live location. Production hosts and non-exception events pass through unchanged. Generated-By: PostHog Desktop Task-Id: 50684114-f876-4d3a-a211-9d0b58f42b10
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 216f53ffc9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| normalized === "localhost" || | ||
| normalized.endsWith(".localhost") || | ||
| normalized === "127.0.0.1" || | ||
| normalized === "0.0.0.0" || | ||
| normalized === "::1" || | ||
| normalized === "[::1]" |
There was a problem hiding this comment.
Filter exceptions from tunneled development hosts
When local QA has a PostHog key configured and uses the repository-supported bun run dev:tunnel or PM2 tunnel, the browser hostname is a generated *.trycloudflare.com domain (scripts/dev/tunnel.js:162-175), which misses every condition here, so its $exception events still reach the shared production project. This leaves the official mobile/device development path causing the telemetry pollution this change is intended to prevent; include the tunnel/dev-runtime signal in the filter and cover it with a regression test.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch. Fixed in 3d77a08: isDevelopmentHost now also matches *.trycloudflare.com, the quick-tunnel host that bun run dev:tunnel generates for mobile/device QA, plus a regression test. I kept the filter hostname-based rather than mixing in import.meta.env.DEV, since that flag is non-deterministic under vitest and would break the production-host test.
bun run dev:tunnel exposes the local dev server over a generated *.trycloudflare.com quick-tunnel host for mobile/device QA. That host missed every condition in isDevelopmentHost, so exceptions from the tunnel path still reached the shared production project. Add the tunnel suffix and a regression test. Generated-By: PostHog Desktop Task-Id: 50684114-f876-4d3a-a211-9d0b58f42b10
Summary
initializePostHogenabledcapture_exceptionswith no environment gate, so every localhost session published$exceptionevents into the shared production project and could mint a fresh issue on the triage surface.before_sendfilter,dropDevelopmentHostExceptions, drops$exceptionevents raised on a development host. It reads the host from the event's$current_urland falls back to the livewindow.location. Production hosts (www.greengoods.app) and non-exception events pass through unchanged.before_send, not a build gate: the existingbefore_sendchain and its tests are the natural home; the filter is per-event and also catches a production build served on localhost, whichimport.meta.env.DEVwould miss.capture_exceptionsstays enabled; only development-host exceptions stop being sent.Filter order (first match wins, drops early):
Validation
bun run testpasses — shared package suite (where the change lives) runs green; the 5 new filter tests cover localhost, loopback, production host, non-exception, and null.bun format && bun lintpasses — Biome format and oxlint clean on the changed files; source and test typecheck clean.Agent context
Considered gating
capture_exceptionsonimport.meta.env.DEVat init. Rejected because a per-eventbefore_sendfilter is more robust (also covers a production build served on localhost) and has a natural home in the existing filter-chain tests.Created with PostHog Desktop from this inbox report.