Skip to content

Commit

Permalink
tracing: change span naming to new console convention (#4042)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
hawkw authored Aug 16, 2021
1 parent 5c19b5a commit d0305d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions tokio/src/runtime/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<F>(),
task.name = %name.unwrap_or_default(),
"fn" = %std::any::type_name::<F>(),
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::<F>(),
"fn" = %std::any::type_name::<F>(),
);
fut.instrument(span)
};
Expand Down
8 changes: 4 additions & 4 deletions tokio/src/util/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ cfg_trace! {
#[cfg(tokio_track_caller)]
let span = tracing::trace_span!(
target: "tokio::task",
"task",
"runtime.spawn",
%kind,
task.name = %name.unwrap_or_default(),
spawn.location = %format_args!("{}:{}:{}", location.file(), location.line(), location.column()),
task.name = %name.unwrap_or_default()
);
#[cfg(not(tokio_track_caller))]
let span = tracing::trace_span!(
target: "tokio::task",
"task",
"runtime.spawn",
%kind,
task.name = %name.unwrap_or_default()
task.name = %name.unwrap_or_default(),
);
task.instrument(span)
}
Expand Down

3 comments on commit d0305d5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'sync_mpsc'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: d0305d5 Previous: 5c19b5a Ratio
send_large 62514 ns/iter (± 7191) 29641 ns/iter (± 1204) 2.11

This comment was automatically generated by workflow using github-action-benchmark.

CC: @tokio-rs/maintainers

@hawkw
Copy link
Member Author

@hawkw hawkw commented on d0305d5 Aug 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I can't imagine any reason why this would impact the MPSC benchmark performance...this code is all cfg'd out entirely in the benchmarks, AFAIK?

@Darksonn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The benchmarks are really unstable and fail every four or five commits.

Please sign in to comment.