[Backend] API Observability — structured logging + /api/metrics endpoint #57
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What & Why
The API server currently logs to console with no structure and has no metrics endpoint. Operators have no way to know throughput, invoice conversion rate, rejection rate, or latency without reading raw logs.
Done looks like
GET /api/metricsreturns a JSON document: total jobs created, jobs by state, invoice payment conversion rate, p50/p95 latency for eval and work phases, total sats earned, uptimeGET /api/healthzextended to include{ status: "ok", uptime_s, jobs_total }(non-breaking)Out of scope
Tasks
consoleorpino) emitting JSON lines with consistent fields (timestamp, level, component, message, optional context). Replace ad-hocconsole.logcalls across route and service files.MetricsServicequerying DB for job counts by state, computing conversion rates, reading in-memory latency histograms populated by route middleware.GET /api/metricsreturning aggregated snapshot; extendGET /api/healthzwith uptime and job count.Relevant files
artifacts/api-server/src/index.tsartifacts/api-server/src/routes/jobs.tsartifacts/api-server/src/routes/health.tsartifacts/api-server/src/lib/agent.tsartifacts/api-server/src/lib/lnbits.tsPR created: #87
All issue requirements implemented:
GET /api/metricsreturns uptime, HTTP counters, jobs by state, invoice conversion rate, p50/p95 latency per route, total sats earnedlib/logger.ts) withLOG_LEVELenv var filtering — adopted across all route and service filesrequest_id,method,path,status,duration_msX-Request-Idheader)GET /api/healthzextended withuptime_sandjobs_total(non-breaking)