You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[instrument]asyncfntask1(){for i in0..10{info!(i,"hello from task 1");
tokio::time::sleep(Duration::from_millis(10)).await;}}
when launching two tasks like so:
let h = tokio::spawn(task1());let h2 = tokio::spawn(task1());
I cannot distinguish from the output which trace belongs to which task:
2022-09-07T08:26:45.644888Z INFO task1: tracing_testo: hello from task 1 i=7
2022-09-07T08:26:45.656212Z INFO task1: tracing_testo: hello from task 1 i=8
2022-09-07T08:26:45.656212Z INFO task1: tracing_testo: hello from task 1 i=8
2022-09-07T08:26:45.667520Z INFO task1: tracing_testo: hello from task 1 i=9
2022-09-07T08:26:45.667546Z INFO task1: tracing_testo: hello from task 1 i=9
So what I did is to add an UID field:
fnuid() -> u16{staticCNT:AtomicU16 = AtomicU16::new(0);CNT.fetch_add(1, std::sync::atomic::Ordering::Relaxed)}#[instrument(fields(uid=uid()))]asyncfntask1(){for i in0..10{info!(i,"hello from task 1");
tokio::time::sleep(Duration::from_millis(10)).await;}}
And now I see {uid=0} or {uid=1} that helps me to distiguish between tasks:
2022-09-07T08:28:52.761808Z INFO task1{uid=0}: tracing_testo: hello from task 1 i=8
2022-09-07T08:28:52.761809Z INFO task1{uid=1}: tracing_testo: hello from task 1 i=8
2022-09-07T08:28:52.773155Z INFO task1{uid=0}: tracing_testo: hello from task 1 i=9
2022-09-07T08:28:52.773130Z INFO task1{uid=1}: tracing_testo: hello from task 1 i=9
My question is: Is it the proper way of doing it? Did I miss some functionality from #[instrument] macro, or other place?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, I have an async function like this:
when launching two tasks like so:
I cannot distinguish from the output which trace belongs to which task:
So what I did is to add an UID field:
And now I see
{uid=0}
or{uid=1}
that helps me to distiguish between tasks:My question is: Is it the proper way of doing it? Did I miss some functionality from
#[instrument]
macro, or other place?Beta Was this translation helpful? Give feedback.
All reactions