From cbba98cc9334ac0b3d0939ac39628840935ff799 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 16 Aug 2021 09:22:12 -0700 Subject: [PATCH 1/2] tracing: change span naming to new console convention Currently, the per-task spans generated by Tokio's `tracing` feature have the span name "task" and the target "tokio::task". This is because the console subscriber identified tasks by looking specifically for the "tokio::task" target. In tokio-rs/console#41, it was proposed that the console change to a more generic system for identifying the spans that correspond to tasks, to allow recording tasks belonging to multiple runtime crates (e.g. an application that uses Tokio for async tasks and Rayon for CPU-bound tasks). PR tokio-rs/console#68 changed the console to track any spans "runtime.spawn", regardless of target (so that the target can be used to identify the runtime a task came from), with "tokio::task/task" tracked for backwards-compatibility with the current release version of tokio. This branch changes Tokio's span naming to the new convention. I also rearranged a couple fields so that the task's kind field always comes before the name and spawn location, since it's likely to be the shortest, and renamed the `function` field on blocking tasks to `fn`, for brevity's sake. Signed-off-by: Eliza Weisman --- tokio/src/runtime/handle.rs | 12 ++++++------ tokio/src/util/trace.rs | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tokio/src/runtime/handle.rs b/tokio/src/runtime/handle.rs index ddc170a929d..46072f381d1 100644 --- a/tokio/src/runtime/handle.rs +++ b/tokio/src/runtime/handle.rs @@ -192,20 +192,20 @@ impl Handle { let location = std::panic::Location::caller(); #[cfg(tokio_track_caller)] let span = tracing::trace_span!( - target: "tokio::task", - "task", + target: "tokio::task::blocking", + "runtime.spawn", kind = %"blocking", - function = %std::any::type_name::(), task.name = %name.unwrap_or_default(), + "fn" = %std::any::type_name::(), spawn.location = %format_args!("{}:{}:{}", location.file(), location.line(), location.column()), ); #[cfg(not(tokio_track_caller))] let span = tracing::trace_span!( - target: "tokio::task", - "task", + target: "tokio::task::blocking", + "runtime.spawn", kind = %"blocking", task.name = %name.unwrap_or_default(), - function = %std::any::type_name::(), + "fn" = %std::any::type_name::(), ); fut.instrument(span) }; diff --git a/tokio/src/util/trace.rs b/tokio/src/util/trace.rs index c51a5a72bce..94daa83d8fc 100644 --- a/tokio/src/util/trace.rs +++ b/tokio/src/util/trace.rs @@ -11,15 +11,15 @@ cfg_trace! { #[cfg(tokio_track_caller)] let span = tracing::trace_span!( target: "tokio::task", - "task", + "runtime.spawn", %kind, - spawn.location = %format_args!("{}:{}:{}", location.file(), location.line(), location.column()), task.name = %name.unwrap_or_default() + spawn.location = %format_args!("{}:{}:{}", location.file(), location.line(), location.column()), ); #[cfg(not(tokio_track_caller))] let span = tracing::trace_span!( target: "tokio::task", - "task", + "runtime.spawn", %kind, task.name = %name.unwrap_or_default() ); From cc05a9cce1e433d4402aed70b09cf973f0112cec Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 16 Aug 2021 11:30:09 -0700 Subject: [PATCH 2/2] whoops forgot some commas Signed-off-by: Eliza Weisman --- tokio/src/util/trace.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tokio/src/util/trace.rs b/tokio/src/util/trace.rs index 94daa83d8fc..61c155c5b03 100644 --- a/tokio/src/util/trace.rs +++ b/tokio/src/util/trace.rs @@ -13,7 +13,7 @@ cfg_trace! { target: "tokio::task", "runtime.spawn", %kind, - task.name = %name.unwrap_or_default() + task.name = %name.unwrap_or_default(), spawn.location = %format_args!("{}:{}:{}", location.file(), location.line(), location.column()), ); #[cfg(not(tokio_track_caller))] @@ -21,7 +21,7 @@ cfg_trace! { target: "tokio::task", "runtime.spawn", %kind, - task.name = %name.unwrap_or_default() + task.name = %name.unwrap_or_default(), ); task.instrument(span) }