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
impl Span
Sourcepub fn set_attribute(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
)
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}Sourcepub fn add_event(&mut self, name: impl Into<String>)
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}pub fn add_event_with_attributes( &mut self, name: impl Into<String>, attributes: HashMap<String, String>, )
Sourcepub fn end(self) -> CompletedSpan
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}