Skip to content

Commit a188304

Browse files
liuhaozhanhawkw
andauthored
tracing: clarify span enter docs warning (#2010)
## Motivation It took me several reads to understand why holding a guard over an await was bad because my brain is naturally synchronous and could only think about `my_async_function` and `some_other_async_function` ## Solution Rather than just iterating "this is bad" use that opportunity to introduce why. Remind the user that this is being executed concurrently to other tasks Co-authored-by: Eliza Weisman <eliza@buoyant.io>
1 parent 71fb38c commit a188304

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tracing/src/span.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,13 @@ impl Span {
605605
/// async fn my_async_function() {
606606
/// let span = info_span!("my_async_function");
607607
///
608-
/// // THIS WILL RESULT IN INCORRECT TRACES
608+
/// // WARNING: This span will remain entered until this
609+
/// // guard is dropped...
609610
/// let _enter = span.enter();
610-
/// some_other_async_function().await;
611+
/// // ...but the `await` keyword may yield, causing the
612+
/// // runtime to switch to another task, while remaining in
613+
/// // this span!
614+
/// some_other_async_function().await
611615
///
612616
/// // ...
613617
/// }

0 commit comments

Comments
 (0)