Skip to main content

Module trace_context

Module trace_context 

Source
Expand description

W3C Trace Context propagation for workflow distributed tracing.

Provides WorkflowTraceContext to generate and parse W3C traceparent headers, enabling correlation between Ironflow workflow spans and downstream service spans (LLM providers, MCP servers, etc.).

The traceparent header follows the W3C Trace Context format:

00-{trace_id}-{span_id}-{trace_flags}
 |     |          |          |
 |     |          |          +-- 2 hex (01 = sampled)
 |     |          +-- 16 hex (8 bytes)
 |     +-- 32 hex (16 bytes)
 +-- version (always "00")

§Examples

use ironflow_core::trace_context::WorkflowTraceContext;

// Create a root context and emit the traceparent header.
let root = WorkflowTraceContext::new_root();
let header = root.to_traceparent();
assert!(header.starts_with("00-"));

// Derive a child span (preserves trace_id, new span_id).
let child = root.child();
assert_eq!(child.trace_id(), root.trace_id());
assert_ne!(child.span_id(), root.span_id());

// Parse an incoming traceparent header.
let parsed = WorkflowTraceContext::from_traceparent(&header).unwrap();
assert_eq!(parsed.trace_id(), root.trace_id());

Structs§

WorkflowTraceContext
W3C Trace Context for distributed tracing across workflow steps.

Enums§

TraceContextError
Errors that can occur when parsing a traceparent header.