Expand description
Distributed-trace context — Rust port of the Java TraceInfo +
LogContext/LogContextManager design (org.platformlambda.core).
Trace and span IDs follow the W3C Trace Context / OpenTelemetry format:
a 32-hex trace ID and a 16-hex span ID. Each traced function execution gets
its own span; the caller’s span travels on the envelope’s span_id
field and becomes the callee’s parent_span_id — producing a causal span
tree without any coupling between functions.
Java threads the context through a per-worker registry keyed by thread id —
deliberately avoiding the ThreadLocal / MDC pattern (an anti-pattern on a
virtual-thread runtime). The Rust analog of that per-task anchor is a
tokio task_local!: the route worker scopes the state around the
function invocation, so PostOffice (propagation, annotations, log
context) and the JSON logger (context block) read it from within the same
task, and it is torn down when the function returns. Work tokio::spawned
from inside a function does not inherit the context — the same boundary
Java has for Mono/Flux completions after the worker returns.
Structs§
- Trace
State - Per-execution trace state (Java
TraceInfo+LogContext, combined — one task-local anchor holds both the trace identity and the log context).
Constants§
- RESERVED_
KEYS - Reserved log-context token names (Java
LogContext.RESERVED_KEYS): these resolve live per log line and cannot be overridden viaPostOffice::update_context. - RESERVED_
OUTPUT_ KEYS - The output keys
PostOffice::update_contextrefuses — the reserved tokens’ names in both spellings (Java 4.12.13: the default template emits snake_case, older templates camelCase, and a developer key under either spelling would shadow the real trace context).
Functions§
- iso8601_
utc - ISO-8601 UTC timestamp with milliseconds (no external date dependency — civil-from-days per Howard Hinnant’s algorithm).
- iso8601_
utc_ now - ISO-8601 UTC timestamp with milliseconds for the current time.
- new_
span_ id - Mint a new 16-hex W3C/OpenTelemetry-compatible span ID
(Java:
String.format("%016x", UUID.randomUUID().getLeastSignificantBits())). - new_
trace_ id - Mint a new 32-hex W3C/OpenTelemetry-compatible trace ID.
- with_
current - Read the current trace state, if this task runs inside a trace bracket.