Skip to main content

Module lean_telemetry

Module lean_telemetry 

Source
Expand description

Zero-allocation trace propagation, span-ID generation, and atomic RED counters.

§W3C Trace Context

parse_traceparent extracts an incoming traceparent header into a TraceCtx (trace ID + parent span ID). new_span_id / new_trace_id generate fresh identifiers for root spans and per-hop server spans.

§Counters

Two relaxed atomics track total and in-flight requests. The RequestGuard RAII type decrements in-flight on drop so the count stays accurate even when a handler panics.

Structs§

RequestGuard
RAII guard: increments in-flight on construction, decrements on drop.
TraceCtx

Functions§

hex_encode
Encode arbitrary bytes as a lowercase hex string.
new_span_id
Generate a fresh 64-bit span ID using monotonic time + sequential counter.
new_trace_id
Generate a fresh 128-bit trace ID (two independent 64-bit halves).
on_request_start
parse_traceparent
Parse a W3C traceparent header without heap allocation. Format: 00-<32 hex trace>-<16 hex span>-<2 hex flags> (55 bytes minimum).
snapshot
(total_requests, in_flight) – relaxed read, suitable for metrics endpoints.