Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tokio: add tracing to Runtime::spawn_blocking #3004

Closed
wants to merge 2 commits into from

Conversation

bahildebrand
Copy link

Move the tracing span that was in task::spawn_blocking to
runtime::spawn_blocking. This gives both calls tracing since
task::spawn_blocking only calls runtime::spawn_checking.

Fixes: #2998

Motivation

Per #2998 runtime::spawn_blocking does not have tracing in the same manner that task::spawn_blocking does.

Solution

Since task::spawn_blocking only calls runtime::spawn_blocking, the tracing call is simply moved up to runtime to add tracing for both.

Move the tracing span that was in task::spawn_blocking to
runtime::spawn_blocking. This gives both calls tracing since
task::spawn_blocking only calls runtime::spawn_checking.

Fixes: tokio-rs#2998
@Darksonn Darksonn added A-tokio Area: The main tokio crate C-maintenance Category: PRs that clean code up or issues documenting cleanup. M-runtime Module: tokio/runtime labels Oct 20, 2020
#[cfg(feature = "tracing")]
let f = {
let span = tracing::trace_span!(
target: "tokio::task",
"task",
kind = %"blocking",
function = %std::any::type_name::<F>(),
);
move || {
let _g = span.enter();
f()
}
};
crate::runtime::spawn_blocking(f)
Copy link
Contributor

Choose a reason for hiding this comment

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

This code compiled before we even added Runtime::spawn_blocking to the codebase, so it cannot be true that it just calls that function.

Copy link
Contributor

Choose a reason for hiding this comment

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

crate::runtime::spawn_blocking is a reexport for crate::runtime::blocking::pool::spawn_blocking which is basically crate::task::spawn_blocking, yes. It's not crate::runtime::Runtime::spawn_blocking

Copy link
Contributor

Choose a reason for hiding this comment

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

crate::runtime::Runtime::spawn_blocking is basically a copy of crate::runtime::blocking::pool::spawn_blocking, except the former is already inside a Runtime, so it uses its internal handle, whilst the latter gets the current handle and uses it.
We could avoid the duplication by implementing this on Handle directly.

Moving the tracing integration around isn't the right call here though. We should either copy it or move that into Handle

Copy link
Author

Choose a reason for hiding this comment

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

Looks like I got confused by all the instances of spawn_blocking. I'll dig into this again tonight with the suggestions. Thank you for the review.

Keruspe added a commit to Keruspe/tokio that referenced this pull request Oct 21, 2020
Move common code and tracing integration into Handle

Fixes tokio-rs#2998
Closes tokio-rs#3004

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
Keruspe added a commit to Keruspe/tokio that referenced this pull request Oct 21, 2020
Move common code and tracing integration into Handle

Fixes tokio-rs#2998
Closes tokio-rs#3004

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
Darksonn pushed a commit that referenced this pull request Oct 21, 2020
Move common code and tracing integration into Handle

Fixes #2998
Closes #3004

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-maintenance Category: PRs that clean code up or issues documenting cleanup. M-runtime Module: tokio/runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tracing spans to Runtime::spawn_blocking
3 participants