Structured logs and metrics
Observability helps explain system behavior using logs, metrics and traces. Structured logs carry named fields, metrics aggregate numerical measurements, and traces connect related operations. Log an allowlisted event schema, such as route template, status, duration and a synthetic request id. Exclude credentials, request bodies and sensitive identifiers by default. Metrics use bounded label values, such as method or status class, rather than request IDs or raw URLs. A histogram records counts in ranges; percentiles estimated from it depend on bucket layout. Use a monotonic clock for durations and distinguish error counts from request counts. The following examples are local log/metric models, not exported telemetry. Do not spread an entire request object into a log or make every customer ID a metric label. Redaction at output is a fallback, not an excuse to collect secrets. Sources: https://nodejs.org/download/release/v22.16.0/docs/api/perf_hooks.html.
Formal Syntax & Structure
console.log(JSON.stringify(record)); performance.now()Working Example
const request={id:'req-1',route:'/items/:id',status:200,durationMs:12,authorization:'synthetic-secret'};const {id,route,status,durationMs}=request;console.log(JSON.stringify({event:'request.complete',id,route,status,durationMs}));