Span

Struct Span 

Source
pub struct Span {
    pub trace_id: u64,
    pub span_id: u64,
    pub parent_span_id: Option<u64>,
    pub operation: String,
    pub start_time: Instant,
    pub end_time: Option<Instant>,
    pub attributes: HashMap<String, String>,
    pub events: Vec<SpanEvent>,
}
Expand description

A span representing a unit of work

Fields§

§trace_id: u64§span_id: u64§parent_span_id: Option<u64>§operation: String§start_time: Instant§end_time: Option<Instant>§attributes: HashMap<String, String>§events: Vec<SpanEvent>

Implementations§

Source§

impl Span

Source

pub fn set_attribute( &mut self, key: impl Into<String>, value: impl Into<String>, )

Examples found in repository?
examples/industry40_tracing.rs (line 6)
4async fn process_order(ctx: &TraceContext, order_id: u64) {
5    let mut span = ctx.child_span("process_order");
6    span.set_attribute("order_id", order_id.to_string());
7    span.add_event("order_received");
8
9    // Simulate order validation
10    avx_async::sleep(Duration::from_millis(50)).await;
11    span.add_event("order_validated");
12
13    // Simulate payment processing
14    avx_async::sleep(Duration::from_millis(100)).await;
15    span.add_event("payment_processed");
16
17    // Simulate fulfillment
18    avx_async::sleep(Duration::from_millis(75)).await;
19    span.add_event("order_fulfilled");
20
21    println!("✅ Order {} processed", order_id);
22
23    let completed_span = span.end();
24    println!("   {}", completed_span);
25}
26
27async fn process_batch(ctx: &TraceContext, batch_id: u64, orders: Vec<u64>) {
28    let mut span = ctx.child_span(format!("process_batch_{}", batch_id));
29    span.set_attribute("batch_id", batch_id.to_string());
30    span.set_attribute("order_count", orders.len().to_string());
31
32    for order_id in orders {
33        process_order(ctx, order_id).await;
34    }
35
36    let completed_span = span.end();
37    println!("📦 Batch {} completed: {}", batch_id, completed_span);
38}
Source

pub fn add_event(&mut self, name: impl Into<String>)

Examples found in repository?
examples/industry40_tracing.rs (line 7)
4async fn process_order(ctx: &TraceContext, order_id: u64) {
5    let mut span = ctx.child_span("process_order");
6    span.set_attribute("order_id", order_id.to_string());
7    span.add_event("order_received");
8
9    // Simulate order validation
10    avx_async::sleep(Duration::from_millis(50)).await;
11    span.add_event("order_validated");
12
13    // Simulate payment processing
14    avx_async::sleep(Duration::from_millis(100)).await;
15    span.add_event("payment_processed");
16
17    // Simulate fulfillment
18    avx_async::sleep(Duration::from_millis(75)).await;
19    span.add_event("order_fulfilled");
20
21    println!("✅ Order {} processed", order_id);
22
23    let completed_span = span.end();
24    println!("   {}", completed_span);
25}
Source

pub fn add_event_with_attributes( &mut self, name: impl Into<String>, attributes: HashMap<String, String>, )

Source

pub fn end(self) -> CompletedSpan

Examples found in repository?
examples/industry40_tracing.rs (line 23)
4async fn process_order(ctx: &TraceContext, order_id: u64) {
5    let mut span = ctx.child_span("process_order");
6    span.set_attribute("order_id", order_id.to_string());
7    span.add_event("order_received");
8
9    // Simulate order validation
10    avx_async::sleep(Duration::from_millis(50)).await;
11    span.add_event("order_validated");
12
13    // Simulate payment processing
14    avx_async::sleep(Duration::from_millis(100)).await;
15    span.add_event("payment_processed");
16
17    // Simulate fulfillment
18    avx_async::sleep(Duration::from_millis(75)).await;
19    span.add_event("order_fulfilled");
20
21    println!("✅ Order {} processed", order_id);
22
23    let completed_span = span.end();
24    println!("   {}", completed_span);
25}
26
27async fn process_batch(ctx: &TraceContext, batch_id: u64, orders: Vec<u64>) {
28    let mut span = ctx.child_span(format!("process_batch_{}", batch_id));
29    span.set_attribute("batch_id", batch_id.to_string());
30    span.set_attribute("order_count", orders.len().to_string());
31
32    for order_id in orders {
33        process_order(ctx, order_id).await;
34    }
35
36    let completed_span = span.end();
37    println!("📦 Batch {} completed: {}", batch_id, completed_span);
38}

Trait Implementations§

Source§

impl Debug for Span

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Span

§

impl RefUnwindSafe for Span

§

impl Send for Span

§

impl Sync for Span

§

impl Unpin for Span

§

impl UnwindSafe for Span

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.