Implement richer Prometheus metrics for requests and latency
Description
GET /api/v1/metrics in src/index.ts only exposes two gauges (stableroute_pairs_total, stableroute_paused). The request-timing middleware already measures per-request duration but discards it after logging. This issue records request counts and latency so operators can graph traffic and tail latency from the existing /metrics endpoint.
Requirements and context
- Repository scope:
StableRoute-Org/Stableroute-backend only.
- Add
stableroute_http_requests_total{method,status} counter and stableroute_http_request_duration_seconds histogram (or summary) populated by the existing res.on("finish") timing hook.
- Add counters for rate-limited (
429) and paused (503) responses.
- Keep the Prometheus text exposition format (
text/plain; version=0.0.4).
- Avoid unbounded label cardinality — bucket
path to route templates, not raw paths.
Suggested execution
- Fork the repo and create a branch
git checkout -b feature/observability-11-metrics-expansion
- Implement changes
- Write code in:
src/index.ts — extend the timing middleware to update in-memory metric registries and the /metrics serializer.
- Write comprehensive tests in:
src/__tests__/index.test.ts — make requests, then assert the counters/histogram lines appear with correct labels.
- Add documentation: list metric names in
README.md.
- Add TSDoc on the metric helpers.
- Validate security: ensure metrics expose no secrets or raw IPs.
- Test and commit
Test and commit
- Run
npm run build, npm run lint, and npm test.
- Cover edge cases: 2xx, 4xx, 429, 503 increments; histogram bucket presence.
- Paste full
npm test output in the PR.
Example commit message
feat(observability): expose request counters and latency histogram
Guidelines
- Minimum 95 percent test coverage for impacted code.
- Clear, reviewer-focused documentation.
- Timeframe: 96 hours.
Community & contribution rewards
- 💬 Join the StableRoute community on Discord for questions, reviews, and faster merges: https://discord.gg/37aCpusvx
- ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.
Implement richer Prometheus metrics for requests and latency
Description
GET /api/v1/metricsinsrc/index.tsonly exposes two gauges (stableroute_pairs_total,stableroute_paused). The request-timing middleware already measures per-request duration but discards it after logging. This issue records request counts and latency so operators can graph traffic and tail latency from the existing/metricsendpoint.Requirements and context
StableRoute-Org/Stableroute-backendonly.stableroute_http_requests_total{method,status}counter andstableroute_http_request_duration_secondshistogram (or summary) populated by the existingres.on("finish")timing hook.429) and paused (503) responses.text/plain; version=0.0.4).pathto route templates, not raw paths.Suggested execution
git checkout -b feature/observability-11-metrics-expansionsrc/index.ts— extend the timing middleware to update in-memory metric registries and the/metricsserializer.src/__tests__/index.test.ts— make requests, then assert the counters/histogram lines appear with correct labels.README.md.Test and commit
npm run build,npm run lint, andnpm test.npm testoutput in the PR.Example commit message
feat(observability): expose request counters and latency histogramGuidelines
Community & contribution rewards