Skip to content

fix(shared): stop capturing exceptions from development hosts - #809

Open
posthog[bot] wants to merge 2 commits into
developfrom
posthog-self-driving/fixshared-stop-capturing-exceptions-f24e61
Open

fix(shared): stop capturing exceptions from development hosts#809
posthog[bot] wants to merge 2 commits into
developfrom
posthog-self-driving/fixshared-stop-capturing-exceptions-f24e61

Conversation

@posthog

@posthog posthog Bot commented Sep 8, 2026

Copy link
Copy Markdown

Summary

  • Who it costs: local QA runs — not users. initializePostHog enabled capture_exceptions with no environment gate, so every localhost session published $exception events into the shared production project and could mint a fresh issue on the triage surface.
  • The mechanism: a new before_send filter, dropDevelopmentHostExceptions, drops $exception events raised on a development host. It reads the host from the event's $current_url and falls back to the live window.location. Production hosts (www.greengoods.app) and non-exception events pass through unchanged.
  • Why before_send, not a build gate: the existing before_send chain and its tests are the natural home; the filter is per-event and also catches a production build served on localhost, which import.meta.env.DEV would miss.
  • No user impact and no behavior change in production: capture_exceptions stays enabled; only development-host exceptions stop being sent.

Filter order (first match wins, drops early):

-    before_send: [restoreExceptionTopLevelProps, dropExtensionExceptions],
+    before_send: [
+      dropDevelopmentHostExceptions,
+      restoreExceptionTopLevelProps,
+      dropExtensionExceptions,
+    ],

Validation

  • bun run test passes — 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 lint passes — Biome format and oxlint clean on the changed files; source and test typecheck clean.
Agent context

Considered gating capture_exceptions on import.meta.env.DEV at init. Rejected because a per-event before_send filter 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.

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
@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
green-goods Ready Ready Preview Sep 8, 2026 4:54am UTC
green-goods-admin Building Building Preview Sep 8, 2026 4:54am UTC
green-goods-design Building Building Preview Sep 8, 2026 4:54am UTC
2 Skipped Deployments
Project Deployment Actions Updated
green-goods-docs Skipped Skipped Sep 8, 2026 4:54am UTC
green-goods-qa Skipped Skipped Sep 8, 2026 4:54am UTC

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +48 to +53
normalized === "localhost" ||
normalized.endsWith(".localhost") ||
normalized === "127.0.0.1" ||
normalized === "0.0.0.0" ||
normalized === "::1" ||
normalized === "[::1]"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants