Skip to content

Commit

Permalink
task: add #[track_caller] to JoinSet/JoinMap (#4697)
Browse files Browse the repository at this point in the history
## Motivation

Currently, the various spawning methods on `tokio::task::JoinSet` and
`tokio_util::task::JoinMap` lack `#[track_caller]` attributes, so the
`tracing` spans generated for tasks spawned on `JoinSet`s/`JoinMap`s
will have the `JoinSet` spawning method as their spawn location, rather
than the user code that called that method.

## Solution

This PR fixes that by...adding a bunch of `#[track_caller]` attributes.

## Future Work

In the future, we may also want to consider adding additional data to
the task span indicating that the task is spawned on a `JoinSet`...

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw committed May 16, 2022
1 parent 454ac1c commit 052355f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tokio-util/src/task/join_map.rs
Expand Up @@ -285,6 +285,7 @@ where
/// This method panics if called outside of a Tokio runtime.
///
/// [`join_one`]: Self::join_one
#[track_caller]
pub fn spawn<F>(&mut self, key: K, task: F)
where
F: Future<Output = V>,
Expand All @@ -304,6 +305,7 @@ where
/// *not* return a cancelled [`JoinError`] for that task.
///
/// [`join_one`]: Self::join_one
#[track_caller]
pub fn spawn_on<F>(&mut self, key: K, task: F, handle: &Handle)
where
F: Future<Output = V>,
Expand All @@ -328,6 +330,7 @@ where
///
/// [`LocalSet`]: tokio::task::LocalSet
/// [`join_one`]: Self::join_one
#[track_caller]
pub fn spawn_local<F>(&mut self, key: K, task: F)
where
F: Future<Output = V>,
Expand All @@ -347,6 +350,7 @@ where
///
/// [`LocalSet`]: tokio::task::LocalSet
/// [`join_one`]: Self::join_one
#[track_caller]
pub fn spawn_local_on<F>(&mut self, key: K, task: F, local_set: &LocalSet)
where
F: Future<Output = V>,
Expand Down
4 changes: 4 additions & 0 deletions tokio/src/task/join_set.rs
Expand Up @@ -81,6 +81,7 @@ impl<T: 'static> JoinSet<T> {
/// This method panics if called outside of a Tokio runtime.
///
/// [`AbortHandle`]: crate::task::AbortHandle
#[track_caller]
pub fn spawn<F>(&mut self, task: F) -> AbortHandle
where
F: Future<Output = T>,
Expand All @@ -95,6 +96,7 @@ impl<T: 'static> JoinSet<T> {
/// cancel the task.
///
/// [`AbortHandle`]: crate::task::AbortHandle
#[track_caller]
pub fn spawn_on<F>(&mut self, task: F, handle: &Handle) -> AbortHandle
where
F: Future<Output = T>,
Expand All @@ -114,6 +116,7 @@ impl<T: 'static> JoinSet<T> {
///
/// [`LocalSet`]: crate::task::LocalSet
/// [`AbortHandle`]: crate::task::AbortHandle
#[track_caller]
pub fn spawn_local<F>(&mut self, task: F) -> AbortHandle
where
F: Future<Output = T>,
Expand All @@ -128,6 +131,7 @@ impl<T: 'static> JoinSet<T> {
///
/// [`LocalSet`]: crate::task::LocalSet
/// [`AbortHandle`]: crate::task::AbortHandle
#[track_caller]
pub fn spawn_local_on<F>(&mut self, task: F, local_set: &LocalSet) -> AbortHandle
where
F: Future<Output = T>,
Expand Down

0 comments on commit 052355f

Please sign in to comment.