Skip to main content

WorkflowTraceContext

Struct WorkflowTraceContext 

Source
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 + 2

Implementations§

Source§

impl WorkflowTraceContext

Source

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);
Source

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.

Source

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());
Source

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"
);
Source

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");
Source

pub fn trace_id(&self) -> &str

Return the trace-id (32 lowercase hex characters).

Source

pub fn span_id(&self) -> &str

Return the span-id (16 lowercase hex characters).

Trait Implementations§

Source§

impl Clone for WorkflowTraceContext

Source§

fn clone(&self) -> WorkflowTraceContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WorkflowTraceContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for WorkflowTraceContext

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for WorkflowTraceContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for WorkflowTraceContext

Source§

impl PartialEq for WorkflowTraceContext

Source§

fn eq(&self, other: &WorkflowTraceContext) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for WorkflowTraceContext

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for WorkflowTraceContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more