-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
tracing: instrument task wakers #3836
Conversation
|
||
cfg_trace! { | ||
mod trace; | ||
pub(crate) use trace::InstrumentedFuture as Future; |
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 rename was mostly for convenience in all the other modules. But it could be that people find it too confusing, in which case I'll ditch the rename and just make the name change in all the other places.
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.
Does this change the public API of spawn methods to use a different trait, or is it only internal? I can't really tell.
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.
No it doesn't. And I checked in a playground, since the trait is pub(crate)
the compiler will error if the bounds were used on a pub
function.
b639684
to
1d40aee
Compare
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 is great, thanks for working on this! i commented on a few things that might be worth considering, but this looks good to me as-is!
if let Some(id) = $harness.id() { | ||
tracing::trace!( | ||
target: "tokio::task", | ||
op = %$op, |
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.
i can see why this is a potential use-case for custom event names...we should definitely consider adding the option to override event names upstream, so that we can use custom names here rather than a field value...but, again, this is fine for now.
cfg_trace! { | ||
macro_rules! trace { | ||
($harness:expr, $op:expr) => { | ||
if let Some(id) = $harness.id() { |
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.
it looks like the intention here is to avoid emitting the event if the task is not being tracked? i wonder if we actually want to do this inside of the tracing event macro, to handle cases where the event is disabled by one of tracing's filtering fast paths. e.g., if the user compiles tracing with one of the "static_max_level_xxx" feature flags, the event macro will be completely empty and won't compile to any code, but we'll still dereference the trailer and check if it has a task ID.
this is probably an unnecessary microoptimzation, though, and we could do it later --- moving it inside the macro will be much easier when tokio-rs/tracing#1393 is published, anyway.
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.
Yea, I'd really want to be to check tracing if the event would be emitted, and check if the ID is Some
, in the same if
statement. I don't want to emit an event if we're not tracking the task either.
Co-authored-by: Eliza Weisman <[email protected]>
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 fine to me! thanks.
Motivation
In support of tokio-rs/console#37, we want to understand when a specific task's waker has been interacted with, such as when it is awoken, or if it's forgotten (not cloned), etc.
Solution
When the
tracing
feature is enabled, a super trait ofFuture
(InstrumentedFuture
) is implemented forInstrumented<F>
that allows grabbing the task's ID (well, its span ID), and stores that in the raw task trailer. The waker vtable then emits events and includes that ID.