feat(api): add PostHog exception capture to the hosted ORB Worker path#8611
Conversation
Adds src/api/worker-posthog.ts, a parallel PostHog error-tracking sink for the hosted Worker alongside the existing @sentry/hono/cloudflare middleware. Uses posthog-node's own captureException() (already bundled here for src/mcp/telemetry.ts's MCP usage events) rather than a hand-built raw $exception payload -- PostHog's own docs warn that a manually constructed exception event's strict schema "fails in the vast majority of cases", and their Cloudflare Workers guide recommends installing posthog-node itself with flushAt:1/flushInterval:0 for exactly this edge lifecycle. Wired via Hono's documented c.error check after next() (not a try/catch): Hono's own default errorHandler converts a thrown exception into a response several dispatch levels below an outer middleware's next() call, so a plain try/catch there never sees it. WORKER_POSTHOG_API_KEY/HOST/ENVIRONMENT are separate from the dual- purpose POSTHOG_API_KEY (MCP telemetry + self-host #8287), mirroring WORKER_SENTRY_DSN's separation from self-host's SENTRY_DSN for the same cross-wire-avoidance reason. Redaction reuses src/selfhost/redaction- scrub.ts's primitives. Parallel-run alongside Sentry per the epic's gated decommission plan (#8298). Closes #8288
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8611 +/- ##
==========================================
- Coverage 92.55% 92.00% -0.56%
==========================================
Files 798 799 +1
Lines 79850 79887 +37
Branches 24120 24132 +12
==========================================
- Hits 73908 73500 -408
- Misses 4803 5311 +508
+ Partials 1139 1076 -63
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Tip ✅ LoopOver review result - approve/merge recommendedReview updated: 2026-07-25 07:54:02 UTC
Review summary Nits — 6 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionPartially addressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
Summary
src/api/worker-posthog.ts, a parallel PostHog error-tracking sink for the hosted ORB Worker alongside the existing@sentry/hono/cloudflaremiddleware insrc/api/routes.ts.posthog-node's owncaptureException()rather than a hand-built raw$exceptionHTTP payload — see the correction comment on PostHog error tracking for the hosted ORB Worker path (raw $exception, no SDK in the bundle) #8288 for why: PostHog's docs warn a manually constructed exception event's strict schema "fails in the vast majority of cases", and their own Cloudflare Workers guide recommends installingposthog-nodeitself for exactly this edge lifecycle. This Worker already bundlesposthog-nodeforsrc/mcp/telemetry.ts's MCP usage events (feat(mcp): add a typed PostHog wrapper module for src/mcp/server.ts (remote) #6235), so this adds zero new bundle weight.src/mcp/telemetry.ts's identical choice for the identical edge-lifecycle reason (flushAt: 1, flushInterval: 0, immediate send, no long-lived batching client that could be torn down mid-flush).c.errorcheck afternext(), not a try/catch — Hono's own defaulterrorHandler(installed even without an explicitapp.onError()) converts a thrown exception into a response several dispatch levels below an outer middleware'snext()call, so a plain try/catch there never sees it. Confirmed via a minimal repro before settling on this approach.WORKER_POSTHOG_API_KEY/WORKER_POSTHOG_HOST/WORKER_POSTHOG_ENVIRONMENTare separate from the dual-purposePOSTHOG_API_KEY(MCP telemetry + self-host PostHog error tracking for the ORB self-host server (swap the src/selfhost/sentry.ts sink; cron-monitor heartbeat design) #8287), mirroringWORKER_SENTRY_DSN's separation from self-host'sSENTRY_DSNfor the same cross-wire-avoidance reason (self-host'sserver.tscalls this same exportedworker.fetch).src/selfhost/redaction-scrub.ts's primitives (confirmed Workers-safe).Closes #8288
Test plan
npm run typecheckcleannpx vitest run test/unit/worker-posthog.test.ts— 25/25 passing, 100% line/branch coverage on the new modulenpm run test:workers(real Cloudflare Workers isolate) — 4/4 passing, including a new smoke test mirroring the existingWORKER_SENTRY_DSN-unset casenpm run test:coverage— full suite green (one pre-existing, unrelated failure confirmed present on main independent of this branch:mcp-cli-profiles.test.ts's changelog-JSON test, tracked separately)test:engine-parity,test:live-gate-parity,test:driver-parity, engine's own test suite,test:mcp-pack,test:miner-pack,test:engine-pack,test:ui-kit-pack,test:miner-deployment-docs-audit,rees:testall green