Concepts
Tracing
Request tracing in Legonode: trace id per request, tracer/traceStart callbacks, and correlating logs.
Tracing
Legonode can attach a trace id to every request so logs and spans can be correlated.
Trace id and logger
For each incoming request, Legonode creates:
ctx.trace.traceId: the request trace idctx.logger: a request-scoped logger that includes the trace id in bindings
So you can safely use ctx.logger.info(...) inside routes and middleware.
Enabling / disabling
Tracing is controlled by:
tracing: falseinlegonode.config.tsLEGONODE_SKIP_TRACING=1(ortrue) environment variable
Tracer hooks
If you configure these in legonode.config.ts, Legonode will call them around the request execution:
traceStart: called when the request span startstracer: called when the request span ends (with method, pathname, status, response size, etc.)
The default implementation logs a [datetime][traceId] method pathname line at start and end.