Skip to content

feat: add optional posthog monitoring - #1386

Closed
cblanc wants to merge 3 commits into
mainfrom
postghog
Closed

cblanc wants to merge 3 commits into
mainfrom
postghog

Conversation

@cblanc

@cblanc cblanc commented Jul 24, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Adds optional PostHog monitoring middleware, enabled by POSTHOG_API_KEY (and optional POSTHOG_HOST); disabled entirely when unset, mirroring the optional Prometheus setup
  • Captures one anonymous api_request event per request with normalized path (e.g. /postcodes/:postcode), method, status and duration - reuses the Prometheus normalizePath so raw URLs (queried postcodes) stay out of analytics and event cardinality stays low
  • Telemetry failures are swallowed so they never surface in API responses; SIGTERM flushes buffered events before exit

Test plan

  • pnpm test test/posthog.integration.ts - covers no-op without key, client construction, event shape, path normalisation and shutdown flush
  • pnpm build
  • Manual: set POSTHOG_API_KEY + POSTHOG_HOST, start the server, hit /postcodes/foo and confirm an api_request event arrives in PostHog

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

cblanc added 3 commits July 24, 2026 07:59
Posthog monitoring (next commit) reports the same normalized
paths as the prometheus metrics.
Enabled by POSTHOG_API_KEY (and optional POSTHOG_HOST). Captures an
api_request event per request with normalized path, method, status and
duration. Uses anonymous events (no person profiles) and normalized
paths only, keeping queried postcodes out of analytics and event
cardinality low. Client errors are swallowed so telemetry never
surfaces in API responses; SIGTERM flushes buffered events.
Verifies no client is created without an API key, event shape and
path normalisation with one, and shutdown flushing.
@cblanc cblanc closed this Jul 24, 2026
@cblanc
cblanc deleted the postghog branch July 24, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant