The Rust tracing crate provides structured, async-aware instrumentation. Learn vocabulary for the #[instrument] macro, Subscriber trait, field sigils (% for Display, ? for Debug), EnvFilter/RUST_LOG configuration, Layer composition, and the tracing-opentelemetry bridge.
0 / 5 completed
1 / 5
A Rust developer adds #[tracing::instrument] to an async function. What does this macro do at the call site?
The #[tracing::instrument] macro generates code that creates a named span, records specified arguments as fields, and ensures the span is entered (and exited) for the entire function duration. For async functions, it correctly handles the fact that the future may be polled across multiple threads.
2 / 5
What is the purpose of tracing::Subscriber in the tracing ecosystem?
The Subscriber trait is the core extension point: implementations receive notifications when spans are created, entered, exited, and when events are recorded. tracing-subscriber provides the Registry and layered subscriber composition pattern, while formatters and exporters are implemented as Layers.
3 / 5
A developer uses tracing::info_span!("db_query", query = %sql). What does the % sigil before sql indicate?
The % sigil tells tracing to format the value using its Display trait implementation (fmt::Display). The ? sigil uses Debug formatting. Without a sigil, the value must implement the Value trait directly. This distinction matters for types that implement Display but not tracing::Value.
4 / 5
An engineer sees tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init() in a Tokio application. What does with_env_filter control?
EnvFilter reads the RUST_LOG environment variable (format: module=level, e.g., my_app=debug,tokio=warn) to filter which spans and events are processed. Spans that don't pass the filter are never created, making filtering zero-cost for disabled levels.
5 / 5
In the tracing ecosystem, what role does tracing-opentelemetry play?
tracing-opentelemetry implements a Layer that bridges the tracing ecosystem with OpenTelemetry. It converts tracing spans into opentelemetry spans, propagates W3C TraceContext headers, and exports data via any OTel exporter (OTLP, Jaeger, etc.). This allows Rust applications to use the ergonomic tracing API while emitting standard OTel data.