Context Propagation
Trace context is propagated across service boundaries using W3C traceparent headers. The tracing-export feature enables this.
Injecting Context
Add trace context to outgoing HTTP requests:
1use orcher_monitoring::tracing::inject_context;2use reqwest::Client;34async fn call_external_service(data: &ServiceRequest) -> Result<ServiceResponse> {5 let client = Client::new();6 let mut headers = reqwest::header::HeaderMap::new();78 // Inject W3C traceparent header9 inject_context(&mut headers);1011 let response = client12 .post("https://api.example.com/process")13 .headers(headers)14 .json(data)15 .send()16 .await?;1718 Ok(response.json().await?)19}Extracting Context
Continue a trace from incoming HTTP requests:
1use orcher_monitoring::tracing::extract_context;23async fn handle_request(req: Request) -> Response {4 // Extract trace context from incoming headers5 let parent_context = extract_context(req.headers());67 let span = if let Some(ctx) = parent_context {8 tracing::info_span!("handle_request", otel.parent = ctx)9 } else {10 tracing::info_span!("handle_request")11 };1213 let _guard = span.enter();14 // All child spans inherit this trace context15 process_request(req).await16}Trace and Span IDs
Access the current trace/span IDs for correlation with logs and external systems:
1use orcher_monitoring::tracing::{current_trace_id, current_span_id};23let trace_id = current_trace_id(); // Option<String>4let span_id = current_span_id(); // Option<String>56tracing::info!(7 trace_id = ?trace_id,8 span_id = ?span_id,9 "Processing with trace correlation"10);Next Steps
- Best Practices — Sampling, visualization, and troubleshooting
- Creating Spans — Typed span helpers for workflows, tasks, storage, and workers
- Tracing Overview — Setup and exporter configuration