-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Conversation
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
#[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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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>
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>
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.