How to Add tracing to Async Rust Applications

Add tracing to async Rust applications by including the `tracing` crate in `Cargo.toml` and using the `#[tracing::instrument]` attribute on async functions to automatically log entry, exit, and duration.

How to Add tracing to Async Rust Applications

Add tracing to async Rust applications by including the tracing crate in Cargo.toml and using the #[tracing::instrument] attribute on async functions to automatically log entry, exit, and duration.

[dependencies]
tracing = "0.1"
tracing-subscriber = "0.3"
use tracing::{info, instrument};
use tracing_subscriber;

#[instrument]
async fn page_title(url: &str) -> Option<String> {
    info!("Fetching title for {}", url);
    // async logic here
    None
}

fn main() {
    tracing_subscriber::fmt::init();
    // run async runtime
}