-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
nested.rs
52 lines (42 loc) · 1.13 KB
/
nested.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::sync::Arc;
use tokio::task;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
use tracing_subscriber::prelude::*;
// initialize an underlying `Registry`
let registry = Arc::new(tracing_subscriber::registry());
// spawn the console server in the background,
// returning a `Layer`:
let console_layer = console_subscriber::spawn(registry.clone());
registry
.with(console_layer)
.with(tracing_subscriber::filter::filter_fn(|_| true))
.init();
task::Builder::default()
.name("main-task")
.spawn(async move {
foo().await;
})
.await?;
Ok(())
}
#[tracing::instrument]
async fn foo() {
println!("{}", tracing::Span::current().metadata().unwrap().name());
bar().await
}
#[tracing::instrument]
async fn bar() {
println!(" {}", tracing::Span::current().metadata().unwrap().name());
baz().await
}
#[tracing::instrument]
async fn baz() {
println!(
" {}",
tracing::Span::current().metadata().unwrap().name()
);
loop {
task::yield_now().await;
}
}