tracing for structured logging and distributed tracing

Marcus Chen Jan 2026
1 tab
use tracing::{info, instrument};

#[instrument]
fn process_request(user_id: u64) {
    info!(user_id, "Processing request");
    // Work happens here
}

fn main() {
    tracing_subscriber::fmt::init();
    process_request(42);
}
1 file · rust Explain with highlit

The tracing crate is the modern standard for instrumentation in async Rust. It provides structured logging with spans (representing work) and events (point-in-time records). Spans can be nested, creating a tree that represents causality. I instrument functions with #[instrument], which auto-generates span entry/exit. Subscribers (like tracing-subscriber) format and output events. For distributed tracing, tracing-opentelemetry exports spans to Jaeger or Honeycomb. The key advantage over traditional logging is structured fields (info!(user_id = %id)), which are queryable in log aggregators. Tracing integrates seamlessly with tokio and axum, making it easy to add observability to async services. I use it in every production service.