feat: instrumented joinsets and other custom spawns#392
Conversation
noxware
left a comment
There was a problem hiding this comment.
Added some comments to help with the code review :)
| /// ``` | ||
| /// | ||
| /// [`TracedFuture<F>`]: crate::telemetry::TracedFuture | ||
| pub fn spawn_with<F, S>( |
There was a problem hiding this comment.
This is the new API, the root part of the PR.
|
|
||
| pin_project! { | ||
| /// Future wrapper that captures wake events for a known Tokio task. | ||
| pub(crate) struct WakeTracked<F> { |
There was a problem hiding this comment.
This is what used to be Traced (kinda).
| /// and uses it for task instrumentation. If the future is polled outside a | ||
| /// Tokio task context, it runs as a transparent passthrough without wake | ||
| /// tracking or task dumps. | ||
| pub struct TracedFuture<F> { |
There was a problem hiding this comment.
This is the concreate type of the spawn_with closure. It composes WakeTracked and TaskDumped (if enabled), without dynamic dispatching.
Note: It can also be called Traced<F> as the name is now free. Although we also have other explicit "traced" types like TracedRuntime. Opinons?
| } | ||
|
|
||
| pin_project! { | ||
| #[project = TracedFutureStateProj] |
There was a problem hiding this comment.
An explicit name is needed to pattern match the enum.
| #[pin] | ||
| inner: InstrumentedFuture<F>, | ||
| }, | ||
| Empty, |
There was a problem hiding this comment.
Empty is just used to transit the state safely.
There was a problem hiding this comment.
This file contains the auxiliar changes to make spawn_with work by exposing the TracedFuture type. It has the most important changes.
|
|
||
| type InstrumentedFuture<F> = WakeTracked<MaybeTaskDumped<F>>; | ||
|
|
||
| pin_project! { |
There was a problem hiding this comment.
We rely on pin projection to avoid writting unsafe code.
yulnr
left a comment
There was a problem hiding this comment.
Looks good to me! happy we could keep the instrumented flag an internal concern.
Leaving some minor comments
|
@yulnr It should be done now :) |
Current solution
Exposes a
handle.spawn_with(fut, |f: TracedFuture| { ... })to allow spawning instrumented/traced futures through custom spawn APIs (likeJoinSet::spawn).Example
For reviewers
Most important changes are at
recorder/mod.rsandtraced.rs.Other
Closes #301