Repository navigation
Instrument application with PostHog - #38
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe576a9eb1
ℹ️ 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".
SSE responses return before tools run, so awaiting flush in finally both delayed the response and ran too early to send tool events. Flush once the stream ends, under waitUntil. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Written by Claude on behalf of Adrian. Suggested squash-merge message: |
The repo had no tests, so CI could not catch regressions in the PostHog capture sites or the flush timing on /mcp. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
PostHog setup report
PostHog is set up for this Cloudflare Worker MCP server with guarded server-side capture, MCP tool analytics, exception autocapture, and a starter dashboard. Compilation and scoped lint checks passed; no event delivery was exercised or observed during this run.
Installed and initialized
posthog-nodeat^5.68.2and@posthog/mcpat exact version1.1.0; both are recorded inpackage.jsonandpackage-lock.json.src/posthog.ts, which exposes the guardedgetPostHog(env)client accessor. It readsPOSTHOG_API_KEYandPOSTHOG_HOST, uses exception autocapture, and is configured for short-lived Worker delivery (flushAt: 1,flushInterval: 0, 2-second timeout, and no retries).src/index.tsinitializes the shared client and performs a caught per-request flush after/mcphandling, so analytics failures do not affect MCP responses..env.exampledocumentsPOSTHOG_API_KEYandPOSTHOG_HOST; both are configured locally in the ignored.env. Production deployment still requires both as Cloudflare Worker environment bindings.Events instrumented
These custom events are captured only after their associated tool handler completes successfully. They are personless and use aggregate, non-identifying properties; runtime capture has not been confirmed.
trip_routing_completedsrc/tools/tripgo.tslocation_search_completedsrc/tools/tripgo.tsdepartures_retrievedsrc/tools/tripgo.tsIdentification
User identification was deliberately skipped. This publicly reachable MCP Worker has no authentication boundary, user model, session-to-user mapping, or verified stable caller ID. MCP session IDs, shared API keys, request headers, IP addresses, and derived values were not used as substitute distinct IDs.
Follow-up issue — analytics cannot be attributed to users: Until the application provides an authoritative authenticated user primary key, events and errors remain un-identified and cannot support person-level analysis. If authentication is added, wire the verified primary key at the request boundary using posthog-node request-scoped context; do not use email as the distinct ID.
Error tracking
Exception autocapture is enabled centrally through
enableExceptionAutocapture: trueinsrc/posthog.ts, and the client is initialized bysrc/index.ts. No duplicate global handlers or manual$exceptionevents were added. Compatibility with the configured Cloudflare Workernodejs_compatruntime was type-checked, but an exception was not intentionally triggered or observed arriving in PostHog.MCP analytics
The single Cloudflare Streamable HTTP MCP server at
/mcpinsrc/index.tsis instrumented with@posthog/mcpimmediately afterMcpServerconstruction and before tool registration. It emits$mcp_tool_calland the package’s default MCP analytics properties for registered tool calls. The wrapper is guarded when PostHog configuration is absent, and request completion flushes are caught.No distinct ID is supplied because the server has no trustworthy authenticated caller identity. No other MCP servers were identified. Event delivery is unconfirmed because the Worker was not run during this integration.
AI Observability
Not configured: no production LLM provider, model gateway, agent framework, or Cloudflare AI runtime call path exists in this Worker. The observed outbound calls are TripGo REST requests only. No AI Observability package or wrapper was added, and privacy mode is not applicable.
Logs
Not configured: this is a Cloudflare Worker isolate, and the available Node OTLP/
NodeSDKlog-export approach is not documented as compatible with that runtime. Existing console output remains unexported. Adding the Node-only exporter would risk Worker runtime incompatibility. If a Worker-compatible PostHog logging path becomes available, use a dedicated exporter-only logger with purpose-written, non-sensitive log lines rather than exporting existing root/console output.Starter analytics dashboard
Created Analytics basics (wizard) with four 30-day daily-trend views: MCP tool calls, trip routing completions, location-search completions, and departures retrieved. The dashboard is ready to populate once the deployed Worker emits events; no governed metric definitions currently exist for these telemetry measures.
Verification and build conflict
Verified:
npm cicompleted successfully with 205 packages and zero vulnerabilities.npm run type-checkpassed before and after final formatting.package.json,src/index.ts,src/posthog.ts,src/tools/tripgo.ts, and.posthog-wizard-cache/.posthog-events.json.Unconfirmed:
$mcp_tool_call, or exception was observed arriving in PostHog.Build conflict in full: scoped format verification remains incomplete because Biome reports pre-existing whole-file spacing drift in
package.json,src/index.ts, andsrc/tools/tripgo.ts. Broad reformatting was intentionally avoided; the integration-createdsrc/posthog.tsand event-contract JSON pass formatting.Next steps
POSTHOG_API_KEYandPOSTHOG_HOSTas production Cloudflare Worker bindings, then deploy the Worker.tripgo-locationstool.$mcp_tool_calland the applicable custom completion event appear in the starter dashboard.Before you merge
package.jsonat the scripts declaration.src/tools/tripgo.ts.POSTHOG_API_KEYandPOSTHOG_HOSTin every Cloudflare Worker deployment environment, not only local.env. Review.env.exampleat the two PostHog variable declarations and thegetPostHog(env)configuration reads insrc/posthog.ts.tripgo-locations; confirm a$mcp_tool_callevent appears in PostHog. Review theinstrument(server, posthog)call insrc/index.tsand the/mcprequest handler flush.trip_routing_completed,location_search_completed, anddepartures_retrievedcapture calls insrc/tools/tripgo.ts.enableExceptionAutocapture: trueinsrc/posthog.ts.