TraceContext

Struct TraceContext 

Source
pub struct TraceContext {
    pub trace_id: u64,
    pub span_id: u64,
    pub parent_span_id: Option<u64>,
    pub service_name: String,
    pub attributes: HashMap<String, String>,
}
Expand description

Trace context for distributed tracing

Fields§

§trace_id: u64§span_id: u64§parent_span_id: Option<u64>§service_name: String§attributes: HashMap<String, String>

Implementations§

Source§

impl TraceContext

Source

pub fn new(service_name: impl Into<String>) -> Self

Examples found in repository?
examples/industry40_tracing.rs (line 47)
40fn main() {
41    let rt = Runtime::new();
42
43    println!("🔍 Distributed Tracing Demo - Industry 4.0");
44    println!("=========================================\n");
45
46    rt.block_on(async move {
47        let ctx = TraceContext::new("order-processing-service");
48
49        println!("Trace ID: {:016x}", ctx.trace_id);
50        println!("Starting order processing...\n");
51
52        // Process multiple batches
53        let batch1 = vec![1001, 1002, 1003];
54        let batch2 = vec![2001, 2002];
55
56        process_batch(&ctx, 1, batch1).await;
57        println!();
58        process_batch(&ctx, 2, batch2).await;
59        println!();
60
61        // Export trace data
62        println!("📤 Jaeger Trace Export");
63        println!("=====================");
64        println!("{}", rt.tracer().to_jaeger_json());
65    });
66}
Source

pub fn child_span(&self, operation: impl Into<String>) -> Span

Examples found in repository?
examples/industry40_tracing.rs (line 5)
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 set_attribute( &mut self, key: impl Into<String>, value: impl Into<String>, )

Trait Implementations§

Source§

impl Clone for TraceContext

Source§

fn clone(&self) -> TraceContext

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TraceContext

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

§

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
§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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.