API observability — structured logging + /api/metrics endpoint #42

Open
opened 2026-03-19 18:52:15 +00:00 by replit · 0 comments
Owner

Why

No metrics or structured logs means operators can't know throughput, invoice conversion rate, or latency without reading raw console output.

Acceptance criteria

  • Thin logger utility emitting JSON lines with: timestamp, level, component, message, optional context (jobId, route, duration_ms); replaces all ad-hoc console.log calls in routes and services
  • Response-time middleware records per-route duration into an in-memory p50/p95 histogram; logs a structured line on every response
  • MetricsService: queries DB for job counts by state, computes invoice conversion rate, reads latency histograms
  • GET /api/metrics: returns JSON snapshot — total jobs, jobs by state, conversion rate, p50/p95 latency (eval + work phases), total sats earned, uptime_s
  • GET /api/healthz extended (non-breaking): adds uptime_s and jobs_total fields
  • Demo endpoint and rate limiter emit structured hit/429 log lines
  • No external telemetry service required

Out of scope

  • Prometheus scrape format
  • Alerting or dashboards
  • Session metrics

Relevant files

  • artifacts/api-server/src/index.ts
  • artifacts/api-server/src/routes/jobs.ts
  • artifacts/api-server/src/routes/health.ts
  • artifacts/api-server/src/lib/agent.ts
  • artifacts/api-server/src/middlewares/

Delegate

@hermes

## Why No metrics or structured logs means operators can't know throughput, invoice conversion rate, or latency without reading raw console output. ## Acceptance criteria - [ ] Thin logger utility emitting JSON lines with: timestamp, level, component, message, optional context (jobId, route, duration_ms); replaces all ad-hoc `console.log` calls in routes and services - [ ] Response-time middleware records per-route duration into an in-memory p50/p95 histogram; logs a structured line on every response - [ ] `MetricsService`: queries DB for job counts by state, computes invoice conversion rate, reads latency histograms - [ ] `GET /api/metrics`: returns JSON snapshot — total jobs, jobs by state, conversion rate, p50/p95 latency (eval + work phases), total sats earned, uptime_s - [ ] `GET /api/healthz` extended (non-breaking): adds `uptime_s` and `jobs_total` fields - [ ] Demo endpoint and rate limiter emit structured hit/429 log lines - [ ] No external telemetry service required ## Out of scope - Prometheus scrape format - Alerting or dashboards - Session metrics ## Relevant files - `artifacts/api-server/src/index.ts` - `artifacts/api-server/src/routes/jobs.ts` - `artifacts/api-server/src/routes/health.ts` - `artifacts/api-server/src/lib/agent.ts` - `artifacts/api-server/src/middlewares/` ## Delegate `@hermes`
replit added the apienhancementhermesbackend labels 2026-03-19 18:52:16 +00:00
gemini was assigned by Rockachopa 2026-03-22 23:38:11 +00:00
This repo is archived. You cannot comment on issues.