use std::{thread, time::Duration};
use tracing::{info, instrument, trace, trace_span};
use tracing_subscriber::fmt::format::FmtSpan;
#[instrument(level = "info")]
fn f() {
trace!("in f");
for _ in 0..10 {
trace_span!("loop_body").in_scope(|| {
info!("in loop body");
thread::sleep(Duration::from_micros(1200));
g();
});
}
}
#[instrument(level = "info")]
fn g() {
trace!("in g");
thread::sleep(Duration::from_micros(800));
}
fn main() {
let subscriber = tracing_subscriber::fmt::Subscriber::builder()
.with_span_events(FmtSpan::FULL)
.with_max_level(tracing::Level::TRACE)
.finish();
tracing::subscriber::set_global_default(subscriber).expect("Failed to set subscriber");
f();
}