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
impl TraceContext
Sourcepub fn new(service_name: impl Into<String>) -> Self
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}Sourcepub fn child_span(&self, operation: impl Into<String>) -> Span
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}pub fn set_attribute( &mut self, key: impl Into<String>, value: impl Into<String>, )
Trait Implementations§
Source§impl Clone for TraceContext
impl Clone for TraceContext
Source§fn clone(&self) -> TraceContext
fn clone(&self) -> TraceContext
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TraceContext
impl RefUnwindSafe for TraceContext
impl Send for TraceContext
impl Sync for TraceContext
impl Unpin for TraceContext
impl UnwindSafe for TraceContext
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)