feat: add /metrics endpoint with Prometheus-format metrics #34

Closed
pook wants to merge 1 commit from feature/prometheus-metrics into main
Owner

Summary

  • Installs prom-client and adds a GET /metrics endpoint returning valid Prometheus text format
  • Tracks HTTP request count by method/route/status, request duration histogram (50ms–30s buckets), document generation count by type, and active connections gauge
  • Includes default Node.js metrics (memory, CPU, event loop lag)
  • /metrics route is mounted before all middleware so it bypasses rate limiting, CORS, disclaimer headers
  • Route path normalization collapses UUIDs/numeric IDs to :id to keep label cardinality low

Files changed

  • packages/api/package.json — added prom-client dependency
  • packages/api/src/services/metrics.ts — metric definitions and registry
  • packages/api/src/middleware/metrics.ts — request instrumentation middleware
  • packages/api/src/routes/metrics.ts — GET /metrics endpoint
  • packages/api/src/index.ts — wiring
  • packages/api/src/routes/generate.ts — privacy doc generation counter
  • packages/api/src/routes/generate-tos.ts — ToS doc generation counter

Test plan

  • curl localhost:3100/metrics returns text/plain with Prometheus format
  • Make API calls, verify http_requests_total counter increments
  • Generate a document, verify document_generations_total increments with correct type label
  • Verify histogram buckets cover 0.05s to 30s
  • Verify /metrics endpoint is not affected by other middleware

🤖 Generated with Claude Code

Closes #31

## Summary - Installs `prom-client` and adds a `GET /metrics` endpoint returning valid Prometheus text format - Tracks HTTP request count by method/route/status, request duration histogram (50ms–30s buckets), document generation count by type, and active connections gauge - Includes default Node.js metrics (memory, CPU, event loop lag) - `/metrics` route is mounted before all middleware so it bypasses rate limiting, CORS, disclaimer headers - Route path normalization collapses UUIDs/numeric IDs to `:id` to keep label cardinality low ## Files changed - `packages/api/package.json` — added `prom-client` dependency - `packages/api/src/services/metrics.ts` — metric definitions and registry - `packages/api/src/middleware/metrics.ts` — request instrumentation middleware - `packages/api/src/routes/metrics.ts` — GET /metrics endpoint - `packages/api/src/index.ts` — wiring - `packages/api/src/routes/generate.ts` — privacy doc generation counter - `packages/api/src/routes/generate-tos.ts` — ToS doc generation counter ## Test plan - [ ] `curl localhost:3100/metrics` returns `text/plain` with Prometheus format - [ ] Make API calls, verify `http_requests_total` counter increments - [ ] Generate a document, verify `document_generations_total` increments with correct type label - [ ] Verify histogram buckets cover 0.05s to 30s - [ ] Verify `/metrics` endpoint is not affected by other middleware 🤖 Generated with [Claude Code](https://claude.com/claude-code) Closes #31
Adds prom-client for production observability:
- HTTP request counter by method/route/status
- Request duration histogram (50ms-30s buckets)
- Document generation counter by type
- Active connections gauge
- Default Node.js metrics (memory, CPU, event loop lag)
- /metrics endpoint mounted before middleware to bypass rate limiting

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
Owner

Review notes (agent-bot):

  • Issue link: Added Closes #31 to the PR description. ✓
  • Route path normalization (collapsing UUIDs to :id) is important for keeping Prometheus label cardinality manageable — good call.
  • Mounting /metrics before all middleware to bypass rate limiting and CORS is correct for scrape endpoints.
  • Consider adding basic auth or IP allowlisting on /metrics in production to prevent exposing internal metrics publicly.
  • 50ms–30s histogram buckets seem reasonable for an API with LLM calls behind it.
**Review notes (agent-bot):** - Issue link: Added `Closes #31` to the PR description. ✓ - Route path normalization (collapsing UUIDs to `:id`) is important for keeping Prometheus label cardinality manageable — good call. - Mounting `/metrics` before all middleware to bypass rate limiting and CORS is correct for scrape endpoints. - Consider adding basic auth or IP allowlisting on `/metrics` in production to prevent exposing internal metrics publicly. - 50ms–30s histogram buckets seem reasonable for an API with LLM calls behind it.
Author
Owner

Closed 2026-04-10 during pipeline triage.

Merge conflicts with current main were blocking the CEO agent's backlog view. The compliancebot repo had ~60 open PRs and 141 open agent-task issues. CEO couldn't see progress and kept duplicating work due to a git-push race in agent-worker (now fixed — runId threaded through dispatch pipeline for unique branch names).

Reopen / resubmit against current main if the work is still relevant. Shim /shim/ceo route now injects open issues + PRs into the CEO prompt and refuses dispatch when backlog exceeds 20.

Closed 2026-04-10 during pipeline triage. Merge conflicts with current main were blocking the CEO agent's backlog view. The compliancebot repo had ~60 open PRs and 141 open agent-task issues. CEO couldn't see progress and kept duplicating work due to a git-push race in agent-worker (now fixed — runId threaded through dispatch pipeline for unique branch names). Reopen / resubmit against current main if the work is still relevant. Shim `/shim/ceo` route now injects open issues + PRs into the CEO prompt and refuses dispatch when backlog exceeds 20.
pook closed this pull request 2026-04-10 15:08:23 -04:00

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pook/compliancebot!34
No description provided.