tracing-texray
is a tracing layer to introspect tracing spans and events in plain text. By examine
-ing
a specific span, a full tree will be dumped when that span exits. Example output:
```text loaddata 52ms ├────────────────────────────────┤ downloadresults{uri: www.crates.io} 11ms ├─────┤
URI resolved ┼ connected ┼ computestats 10ms ├─────┤ renderresponse 6ms ├──┤ ```
In cases where a more powerful solution like tracing-chrome is not required,
tracing-texray
gives enables getting a lightweight timeline of what happened when.
tracing-xray
combines two pieces: a global subscriber, and local span examination.
First, the layer must be installed globally: ```rust,norun use std::time::Duration; use tracingtexray::TeXRayLayer; use tracingsubscriber::{Registry, EnvFilter, layer::SubscriberExt}; fn main() { // Option A: Exclusively using tracingtexray: tracing_texray::init();
// Option B: install the layer in combination with other layers, eg. tracing_subscriber::fmt:
let subscriber = Registry::default()
.with(EnvFilter::try_from_default_env().expect("invalid env filter"))
.with(tracing_subscriber::fmt::layer())
.with(
TeXRayLayer::new()
// by default, all metadata fields will be printed. If this is too noisy,
// fitler only the fields you care about
.only_show_fields(&["name", "operation", "service"])
// only print spans longer than a certain duration
.min_duration(Duration::from_millis(100)),
);
tracing::subscriber::set_global_default(subscriber).unwrap();
} ```
Next, wrap any spans you want to track with examine
:
```rust
use tracing::infospan;
use tracingtexray::examine;
fn somewheredeepinmyprogram() {
examine(infospan!("doathing")).inscope(|| {
someotherfunction();
})
}
fn someotherfunction() { // ... } ```