-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
task: add Tracing instrumentation to spawned tasks #2655
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2f03820
task: instrument spawned tasks with tracing
hawkw 4239548
examples: add tracing to chat example
hawkw a190eae
task: add spans to local and blocking tasks
hawkw d4e4aef
examples: don't need enter/exit,
hawkw bd4068e
fixup local and blocking spans
hawkw 5136e1f
examples: just use FULL
hawkw 7b40188
examples: document tracing setup
hawkw 093398c
hide cfgs from mainline code where practical
hawkw 468ed2d
fix dead code with some feature combinations
hawkw e4f421f
fix comment
hawkw 59fec64
turns out localset requires rt-core *and* rt-util
hawkw f749552
remove unstable flag
hawkw ba638df
remove reference to unstable flag in examples
hawkw d4391cd
Merge branch 'eliza/trace-spawns' of github.com:tokio-rs/tokio into e…
hawkw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
cfg_trace! { | ||
cfg_rt_core! { | ||
use std::future::Future; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
use pin_project_lite::pin_project; | ||
|
||
use tracing::Span; | ||
|
||
hawkw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pin_project! { | ||
/// A future that has been instrumented with a `tracing` span. | ||
#[derive(Debug, Clone)] | ||
pub(crate) struct Instrumented<T> { | ||
#[pin] | ||
inner: T, | ||
span: Span, | ||
} | ||
} | ||
|
||
impl<T: Future> Future for Instrumented<T> { | ||
type Output = T::Output; | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let this = self.project(); | ||
let _enter = this.span.enter(); | ||
this.inner.poll(cx) | ||
} | ||
} | ||
|
||
impl<T> Instrumented<T> { | ||
pub(crate) fn new(inner: T, span: Span) -> Self { | ||
Self { inner, span } | ||
} | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn task<F>(task: F, kind: &'static str) -> Instrumented<F> { | ||
let span = tracing::trace_span!( | ||
target: "tokio::task", | ||
"task", | ||
%kind, | ||
future = %std::any::type_name::<F>(), | ||
); | ||
Instrumented::new(task, span) | ||
} | ||
} | ||
} | ||
|
||
cfg_not_trace! { | ||
cfg_rt_core! { | ||
#[inline] | ||
pub(crate) fn task<F>(task: F, _: &'static str) -> F { | ||
// nop | ||
task | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.