livery_instrument_trace (livery v0.2.0)
View SourceTracing middleware powered by the instrument library.
Opens one server span per request, attaches OpenTelemetry HTTP
server semantic attributes (method, status, route, scheme,
protocol, peer), and propagates W3C traceparent/tracestate
context extracted from the inbound headers.
State: #{tracer => binary() | atom()} (defaults to
<<"livery">>).
The span is kind => server and gets these attributes:
http.request.methodurl.pathurl.schemenetwork.protocol.name(http/1.1/http/2/http/3)server.addressclient.addressuser_agent.originalhttp.response.status_code(set after the handler returns)
Errors from the handler are recorded on the span via
instrument_tracer:record_exception/2 and re-raised so the
request process's own crash handling still runs.
Correlating logs with traces
Call install_logger/0 once at boot to add the instrument
logger filter. It enriches every logger event emitted while a
span is active (so, inside this middleware) with trace_id,
span_id, and trace_flags in the event metadata. Stack this
middleware outside livery_access_log and the access-log lines
carry the same ids as the request's span.
Summary
Functions
Install the instrument logger filter so log events carry the
active span's trace_id/span_id. Call once at application
start. Idempotent.
install_logger/0 with explicit instrument_logger options.
Remove the instrument logger filter installed by install_logger/0.
Functions
-spec call(livery_req:req(), livery_middleware:next(), map()) -> livery_resp:resp().
-spec install_logger() -> ok | {error, term()}.
Install the instrument logger filter so log events carry the
active span's trace_id/span_id. Call once at application
start. Idempotent.
install_logger/0 with explicit instrument_logger options.
-spec uninstall_logger() -> ok.
Remove the instrument logger filter installed by install_logger/0.