RUST-2032 track task spawn location for tokio instrumentation #1201
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The tracing instrumentation present in tokio (which feeds into
tokio-console) tracks the spawning location of each task. This can be
useful in understanding what each task is doing, especially if the tasks
aren't named (which is a
tokio_unstable
feature so not usually presentin published crates).
The location tracking isn't as useful when tasks are spawned from some
central location like the
mongodb
crate does, because all tasks havethe same spawn location. However, since the instrumentation uses the
panic:Location
to determine the spawn location, the#[track_caller]
attribute macro can be used to ensure that the actual location is picked
up instead of the common one.
A side effect of using the
#[track_caller]
attribute is that thesingle line output in the case of a panic (when
RUST_BACKTRACE
isn'tset) will point to the callsite in the code, and not the common site -
although this is often desirable anyway.
This change adds
#[track_caller]
to thepub(crate)
functioncrate::runtime::spawn
as well as the methodAsyncJoinHandle::spawn
.