Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tokio Console

tokio-console is a diagnostics and debugging tool for async Rust programs. It provides a TUI to inspect the state of async tasks and resources in a running tokio runtime.

Elfo integrates with tokio-console by naming all tasks that run actors or spawned by elfo::task::spawn_blocking() or elfo::task::Builder: tokio-console screenshot

Firstly, add console-subscriber to dependencies and enable the tokio-tracing feature of elfo:

[dependencies]
elfo = { version = "0.2", features = ["tokio-tracing"] }
console-subscriber = "0.5.0"

Secondly, we need manually initialize the tracing subscriber instead of letting elfo do it for us:

let (blueprint, scope_filter, capture_layer) = elfo::batteries::logger::new();

tracing_subscriber::registry()
    .with(console_subscriber::spawn())
    .with(capture_layer.with_filter(scope_filter))
    .init();

loggers.mount(blueprint);

Finally, compile with --cfg tokio_unstable to opt into tokio’s unstable task instrumentation:

RUSTFLAGS='--cfg tokio_unstable' cargo run

That’s all! Now we can run tokio-console to run the TUI and connect to our application.

Check this example for a complete code sample.