Skip to main content

Module trace

Module trace 

Source
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§

TraceState
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 via PostOffice::update_context.
RESERVED_OUTPUT_KEYS
The output keys PostOffice::update_context refuses — 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.