Repository navigation
feat(metrics): add opt-in Prometheus /metrics endpoint for tool calls - #910
adityawaghamare wants to merge 1 commit into
Conversation
- Closes HelpCode-ai#854 - Files: packages/backend/src/common/metrics.ts, packages/backend/src/main.ts Signed-off-by: Aditya Waghamare <adityawaghamare7620@gmail.com>
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
keysersoft
left a comment
There was a problem hiding this comment.
Thanks for picking this up, but it can't go in like this.
main.ts lost 231 lines: the dotenv loading, the Sentry and tracing imports that have to come first, helmet, cookie-parser, the startup secrets check, the validation pipe and a lot more. It's the same thing that happened to app-sidebar.tsx in #848, the file got replaced with a shorter version instead of edited. The backend would boot without most of its security setup. Please start main.ts again from main and only add the few lines that start and stop the listener after app.listen().
Also missing compared to #854:
- prom-client isn't in packages/backend/package.json, so this doesn't compile in CI
- recordToolCall is never called from logToolCall() in dynamic-mcp-tools.ts, so the counters would never move
- the Cloud rules (no listener without METRICS_TOKEN, no tool/connector labels) and the token check need tests in src/common/metrics.spec.ts
- the docs section and the env vars in docs/deployment.md
One more thing on process: #854 wasn't assigned to you, and we go one issue at a time in the challenge. Since #848 is basically done, I'm fine with #854 being your next one, so go ahead here. But please don't post solution summaries on issues you haven't been given (#853, #846), a short "I'd like to work on this" is all we need.
Summary
Adds an opt-in Prometheus metrics endpoint (
/metrics) usingprom-clienton a separate HTTP listener whenMETRICS_ENABLED=true, supporting self-hosted and Cloud environments securely.Changes
packages/backend/src/common/metrics.tsfacade implementingprom-clientmetrics collector, default metrics, tool call tracking, and secure HTTP listener with timing-safe token authentication.packages/backend/src/main.tsto initialize and close the metrics HTTP server based on environment configuration.Verification
npm testorjest packages/backend/src/common/metrics.spec.tsCloses #854