Skip to content

fix: suppress PostHog telemetry errors behind corporate proxies#264

Merged
rhuanbarreto merged 1 commit into
mainfrom
fix/posthog-telemetry-proxy-and-error-suppression
May 4, 2026
Merged

fix: suppress PostHog telemetry errors behind corporate proxies#264
rhuanbarreto merged 1 commit into
mainfrom
fix/posthog-telemetry-proxy-and-error-suppression

Conversation

@rhuanbarreto

Copy link
Copy Markdown
Contributor

Summary

  • Route PostHog ingest through managed proxy at n.archgate.dev instead of eu.i.posthog.com — better reputation with corporate proxies and ad-blockers
  • Disable PostHog SDK auto-flush timer (flushInterval: 0) — the 10s timer fires mid-command and the SDK's logFlushError() dumps ugly PostHogFetchNetworkError / SELF_SIGNED_CERT_IN_CHAIN stack traces to stderr
  • Wrap the SDK's fetch with error handling that silently catches TLS/network failures, reports them to Sentry (source: "posthog-fetch"), and returns a synthetic 200 so the queue drains without retrying

Context

A user behind a corporate proxy with SSL inspection hit this during archgate init:

PostHogFetchNetworkError: Network error while fetching PostHog
error: self signed certificate in certificate chain
  path: "https://eu.i.posthog.com/batch/"

The PostHog SDK's internal logFlushError() calls console.error() before swallowing the error, so our existing try-catch around client.shutdown() couldn't prevent the output. The auto-flush timer compounded the issue by firing independently mid-command.

Test plan

  • bun run validate passes (lint, typecheck, format, 690 tests, 23/23 ADR rules, build)
  • Verify n.archgate.dev CNAME is live and resolving to PostHog proxy infrastructure
  • Confirm Sentry receives posthog-fetch errors when fetch fails (check Sentry dashboard after deploying)

Users behind corporate proxies with SSL inspection get ugly
PostHogFetchNetworkError stack traces dumped to stderr during
`archgate init`. Telemetry must never affect CLI behavior or output.

Three changes:

1. Route PostHog ingest through managed proxy at n.archgate.dev
   instead of eu.i.posthog.com — better reputation with corporate
   proxies and ad-blockers.

2. Set flushInterval: 0 to disable the SDK's automatic 10s flush
   timer. The CLI is a short-lived process; we flush explicitly via
   client.shutdown() before exit. The timer was the primary source
   of unhandled console.error output mid-command.

3. Wrap fetch with error handling that silently catches TLS/network
   failures, reports them to Sentry for visibility, and returns a
   synthetic 200 so the SDK drains its queue without retrying into
   the same broken network path.

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying archgate-cli with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8dccf51
Status: ✅  Deploy successful!
Preview URL: https://56fe1630.archgate-cli.pages.dev
Branch Preview URL: https://fix-posthog-telemetry-proxy.archgate-cli.pages.dev

View logs

@rhuanbarreto rhuanbarreto merged commit f130487 into main May 4, 2026
10 checks passed
@rhuanbarreto rhuanbarreto deleted the fix/posthog-telemetry-proxy-and-error-suppression branch May 4, 2026 19:37
@archgatebot archgatebot Bot mentioned this pull request May 4, 2026
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.

1 participant