From 5de9bd50795016c06cbd84f8f0fb7f40b7652d30 Mon Sep 17 00:00:00 2001 From: Hayden Stainsby Date: Tue, 5 Sep 2023 15:51:02 +0200 Subject: [PATCH] task: fix spawn_local source location for console The location of a spawned task, as shown in tokio console, is taken from the location set on the tracing span that instruments the task. For this location to work, there must be unbroken chain of functions instrumented with `#[track_caller]`. For `task::spawn_local`, there was a break in this chain and so the span contained the location of an internal function in tokio. This change adds the missing `#[track_caller]` attribute. It has been tested locally as automated tests would really need `tracing-mock` to be published so we can use it in the tokio tests. --- tokio/src/task/local.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tokio/src/task/local.rs b/tokio/src/task/local.rs index 59b68b8d2cf..11dfa274ee3 100644 --- a/tokio/src/task/local.rs +++ b/tokio/src/task/local.rs @@ -575,6 +575,7 @@ impl LocalSet { run_until.await } + #[track_caller] pub(in crate::task) fn spawn_named( &self, future: F,