pub struct WorkflowTraceContext { /* private fields */ }Expand description
W3C Trace Context for distributed tracing across workflow steps.
Each WorkflowTraceContext carries a trace_id (32 lowercase hex chars)
and a span_id (16 lowercase hex chars). Use new_root
to start a new trace, child to create a child span, and
to_traceparent to emit the W3C header.
§Examples
use ironflow_core::trace_context::WorkflowTraceContext;
let ctx = WorkflowTraceContext::new_root();
assert_eq!(ctx.trace_id().len(), 32);
assert_eq!(ctx.span_id().len(), 16);
assert_eq!(ctx.to_traceparent().len(), 55); // 2 + 1 + 32 + 1 + 16 + 1 + 2Implementations§
Source§impl WorkflowTraceContext
impl WorkflowTraceContext
Sourcepub fn new_root() -> Self
pub fn new_root() -> Self
Create a new root trace context with a random trace-id and span-id.
The trace-id is derived from the current timestamp, process ID, and an atomic counter to ensure uniqueness without requiring a CSPRNG.
§Examples
use ironflow_core::trace_context::WorkflowTraceContext;
let ctx = WorkflowTraceContext::new_root();
assert_eq!(ctx.trace_id().len(), 32);
assert_eq!(ctx.span_id().len(), 16);Sourcepub fn from_workflow_run_id(run_id: &str) -> Self
pub fn from_workflow_run_id(run_id: &str) -> Self
Create a trace context derived from a workflow run ID.
The run_id is hashed (SHA-256) to produce a deterministic 32-hex
trace-id. This allows correlating all spans of a given workflow run
under a single trace. A fresh span-id is generated for this context.
§Examples
use ironflow_core::trace_context::WorkflowTraceContext;
let ctx = WorkflowTraceContext::from_workflow_run_id("run-abc-123");
assert_eq!(ctx.trace_id().len(), 32);
// Same run_id always produces the same trace_id.
let ctx2 = WorkflowTraceContext::from_workflow_run_id("run-abc-123");
assert_eq!(ctx.trace_id(), ctx2.trace_id());§Panics
Panics if run_id is empty.
Sourcepub fn child(&self) -> Self
pub fn child(&self) -> Self
Create a child context that shares this trace-id but has a new span-id.
Use this when a workflow step fans out to sub-steps: each child gets its own span-id while remaining part of the same trace.
§Examples
use ironflow_core::trace_context::WorkflowTraceContext;
let parent = WorkflowTraceContext::new_root();
let child = parent.child();
assert_eq!(child.trace_id(), parent.trace_id());
assert_ne!(child.span_id(), parent.span_id());Sourcepub fn to_traceparent(&self) -> String
pub fn to_traceparent(&self) -> String
Format as a W3C traceparent header value.
The output follows the format 00-{trace_id}-{span_id}-01, where
01 indicates the trace is sampled.
§Examples
use ironflow_core::trace_context::WorkflowTraceContext;
let ctx = WorkflowTraceContext::from_traceparent(
"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
).unwrap();
assert_eq!(
ctx.to_traceparent(),
"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
);Sourcepub fn from_traceparent(header: &str) -> Result<Self, TraceContextError>
pub fn from_traceparent(header: &str) -> Result<Self, TraceContextError>
Parse a W3C traceparent header into a WorkflowTraceContext.
Accepts any version field (not just "00"), but always emits
version "00" when calling to_traceparent.
Extra fields beyond the 4th are silently ignored.
§Errors
Returns TraceContextError if the header is malformed:
- Fewer than 4 dash-separated fields
- trace-id is not exactly 32 lowercase hex characters
- span-id is not exactly 16 lowercase hex characters
- trace-id or span-id is all zeros
§Examples
use ironflow_core::trace_context::WorkflowTraceContext;
let ctx = WorkflowTraceContext::from_traceparent(
"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
).unwrap();
assert_eq!(ctx.trace_id(), "4bf92f3577b34da6a3ce929d0e0e4736");
assert_eq!(ctx.span_id(), "00f067aa0ba902b7");Trait Implementations§
Source§impl Clone for WorkflowTraceContext
impl Clone for WorkflowTraceContext
Source§fn clone(&self) -> WorkflowTraceContext
fn clone(&self) -> WorkflowTraceContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WorkflowTraceContext
impl Debug for WorkflowTraceContext
Source§impl<'de> Deserialize<'de> for WorkflowTraceContext
impl<'de> Deserialize<'de> for WorkflowTraceContext
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for WorkflowTraceContext
impl Display for WorkflowTraceContext
impl Eq for WorkflowTraceContext
Source§impl PartialEq for WorkflowTraceContext
impl PartialEq for WorkflowTraceContext
Source§impl Serialize for WorkflowTraceContext
impl Serialize for WorkflowTraceContext
impl StructuralPartialEq for WorkflowTraceContext
Auto Trait Implementations§
impl Freeze for WorkflowTraceContext
impl RefUnwindSafe for WorkflowTraceContext
impl Send for WorkflowTraceContext
impl Sync for WorkflowTraceContext
impl Unpin for WorkflowTraceContext
impl UnsafeUnpin for WorkflowTraceContext
impl UnwindSafe for WorkflowTraceContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.