[claude] API observability — structured logging + /api/metrics endpoint (#57) #87
Reference in New Issue
Block a user
Delete Branch "claude/issue-57"
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?
Fixes #57
Summary
Adds full API observability to the server with no external dependencies:
lib/logger.ts) — JSON log lines withtimestamp,level,component,message, and optional context fields.LOG_LEVELenv var controls verbosity (debug/info/warn/error)lib/histogram.ts) — In-memory ring buffer (1000 samples/bucket) tracking p50/p95 per route keylib/request-counters.ts) — In-memory counters for total requests, by-status breakdown, 4xx/5xx error countsmiddlewares/request-id.ts) — AssignsX-Request-Idheader (reuses upstream or generates UUID), echoed in responsemiddlewares/response-time.ts) — Records duration into histogram and counters, emits structuredrequestlog line per responselib/metrics.ts) — Queries DB for job counts by state, invoice conversion rate, total sats earned; merges with in-memory latency and HTTP counter dataGET /api/metrics(routes/metrics.ts) — Returns fullMetricsSnapshotJSON including uptime, http counters, jobs by state, invoice stats, earnings, and p50/p95 latency per routeGET /api/healthzextended (routes/health.ts) — Now returns{ status, uptime_s, jobs_total }(non-breaking addition)jobs.ts,demo.ts,health.ts,agent.ts,lnbits.ts,rate-limiter.ts