How to use tokio tracing for async debugging

Enable tokio tracing by adding the tracing crate, initializing the subscriber in main, and using the instrument macro on async functions.

Enable tracing by adding the tracing and tracing-subscriber crates to your Cargo.toml and initializing the subscriber in main before running async tasks.

[dependencies]
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
tracing = "0.1"
tracing-subscriber = "0.3"
use tracing_subscriber;

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt::init();
    // Your async code here
}

Add #[tracing::instrument] to async functions to automatically log entry, exit, and arguments.