Expand description
Procedural macros for instrumenting Rust functions with tracing spans.
This crate provides #[span_fn] and #[log_fn] attribute macros that automatically
inject instrumentation into functions. These macros are the primary way to instrument
async code in micromegas.
§Quick Start
ⓘ
use micromegas_tracing::prelude::*;
#[span_fn]
async fn fetch_user(id: u64) -> User {
// This async function is automatically instrumented
database.get_user(id).await
}
#[span_fn]
fn compute_hash(data: &[u8]) -> Hash {
// Sync functions work too
hasher.hash(data)
}§Why use #[span_fn]?
The #[span_fn] macro solves a fundamental challenge in async Rust: tracking execution
time across .await points. When an async function awaits, it yields control and may
resume on a different thread. #[span_fn] wraps your async code in an InstrumentedFuture
that correctly tracks wall-clock time even across these suspension points.
For sync functions, it creates a scope-based span that measures the function’s execution.
§Import
These macros are re-exported through the tracing prelude:
ⓘ
use micromegas_tracing::prelude::*;