Possible to instrument async such that the span only exits after future is completed? #3200
Replies: 1 comment
-
I don't think this is really possible because the span must be exited on the same thread as it was entered. When you If you know you'll be on the same thread and you don't need you let span = tracing::info_span!("span").entered();
tokio::task::yield_now().await;
drop(span); I think the best way to achieve what you want is for the subscriber exporting your data to only report first enter (or creation of the span) and last exit (or when the span is closed). |
Beta Was this translation helpful? Give feedback.
-
Based on this documentation, it seems like the only correct way to instrument async code is using the
Instrument
trait or the#[instrument]
attribute macro.When I do this and view my traces in the Tracy profiler, a single
async fn
will be split across many "zones", making it hard to use any of the aggregation features. I understand this happens because in reality theasync fn
is a future that is being polled many times before completing, and each of those corresponds to an enter/exit of the span.I am wondering if it would be possible for tracing to have an alternative way of instrumenting a future such that it only exits once the future has completed (and will not be polled again).
Beta Was this translation helpful? Give feedback.
All reactions