Repository navigation
Revert "chore(ai-gateway): remove Cloudflare analytics (#6084)" - #7071
Conversation
This reverts commit 3fbc18a. The gateway handlers have since moved to packages/web-shared, so the restored API metrics module lives in packages/web-shared/src/lib/ai-gateway/o11y and the emit calls are re-applied in the shared llm-proxy, embeddings, and audio-transcriptions handlers. The route files stay thin facades.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (4 files)
Note: the previously reported un-cleared drain-timer finding in Previous Review Summaries (2 snapshots, latest commit 576d403)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 576d403)Status: No Issues Found | Recommendation: Merge Files Reviewed (4 files)
Previous review (commit f9d27e6)Status: 1 Issue Found | Recommendation: Address before merge Executive SummaryThis revert faithfully restores the removed API-metrics path (the new Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (11 files)
Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0 Review guidance: REVIEW.md from base branch |
Reverts #6084.
Notes
git revertdid not apply cleanly: since #6084 the gateway routes became thin facades (#6737) and the handler logic moved topackages/web-shared(#6806). This restores the same behavior in the new layout:api-metrics.server.tsand its test underpackages/web-shared/src/lib/ai-gateway/o11y/(web-shared runtime code may only import from web-shared).emitApiMetricsForResponsecalls in the sharedllm-proxy,embeddings, andaudio-transcriptionshandlers.toolsAvailable/toolsUsedon the successfulsendUpstreamAttemptresult.emitApiMetrics; the local copy is removed.apps/web/src/app/api/openrouter/stay unchanged.Additions beyond the revert
/api/gateway/typesafe/v1/systemone) now emits API metrics too. Its body is read as JSON, so it reports known values through a newemitGatewayApiMetricshelper instead of cloning and draining the response (a clone would keep the upstream open after the 402 path cancels it)./api/fim/completions) and edit (/api/edit/completions) completions now emit API metrics. They call Mistral and Inception directly, so these metrics are the only provider health signal for those paths.userByokreflects whether a BYOK key was actually used.setTimeoutper chunk (review feedback).Verification
pnpm --filter @kilocode/web-shared typecheckpasses.api-metrics.server.test.ts,typesafe/handler.test.ts,fim-completions.test.ts, andedit-completions.test.tspass locally; remaining tests left to CI.