summaryrefslogtreecommitdiffstats
path: root/tokio/src/util/trace.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/src/util/trace.rs')
-rw-r--r--tokio/src/util/trace.rs48
1 files changed, 14 insertions, 34 deletions
diff --git a/tokio/src/util/trace.rs b/tokio/src/util/trace.rs
index 18956a36..96a9db91 100644
--- a/tokio/src/util/trace.rs
+++ b/tokio/src/util/trace.rs
@@ -1,47 +1,27 @@
cfg_trace! {
cfg_rt! {
- use std::future::Future;
- use std::pin::Pin;
- use std::task::{Context, Poll};
- use pin_project_lite::pin_project;
-
- use tracing::Span;
-
- 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 }
- }
- }
+ pub(crate) use tracing::instrument::Instrumented;
#[inline]
+ #[cfg_attr(tokio_track_caller, track_caller)]
pub(crate) fn task<F>(task: F, kind: &'static str) -> Instrumented<F> {
+ use tracing::instrument::Instrument;
+ #[cfg(tokio_track_caller)]
+ let location = std::panic::Location::caller();
+ #[cfg(tokio_track_caller)]
+ let span = tracing::trace_span!(
+ target: "tokio::task",
+ "task",
+ %kind,
+ spawn.location = %format_args!("{}:{}:{}", location.file(), location.line(), location.column()),
+ );
+ #[cfg(not(tokio_track_caller))]
let span = tracing::trace_span!(
target: "tokio::task",
"task",
%kind,
- future = %std::any::type_name::<F>(),
);
- Instrumented::new(task, span)
+ task.instrument(span)
}
}
}