|
1 | 1 | cfg_trace! {
|
2 | 2 | cfg_rt! {
|
3 |
| - use std::future::Future; |
4 |
| - use std::pin::Pin; |
5 |
| - use std::task::{Context, Poll}; |
6 |
| - use pin_project_lite::pin_project; |
7 |
| - |
8 |
| - use tracing::Span; |
9 |
| - |
10 |
| - pin_project! { |
11 |
| - /// A future that has been instrumented with a `tracing` span. |
12 |
| - #[derive(Debug, Clone)] |
13 |
| - pub(crate) struct Instrumented<T> { |
14 |
| - #[pin] |
15 |
| - inner: T, |
16 |
| - span: Span, |
17 |
| - } |
18 |
| - } |
19 |
| - |
20 |
| - impl<T: Future> Future for Instrumented<T> { |
21 |
| - type Output = T::Output; |
22 |
| - |
23 |
| - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
24 |
| - let this = self.project(); |
25 |
| - let _enter = this.span.enter(); |
26 |
| - this.inner.poll(cx) |
27 |
| - } |
28 |
| - } |
29 |
| - |
30 |
| - impl<T> Instrumented<T> { |
31 |
| - pub(crate) fn new(inner: T, span: Span) -> Self { |
32 |
| - Self { inner, span } |
33 |
| - } |
34 |
| - } |
| 3 | + pub(crate) use tracing::instrument::Instrumented; |
35 | 4 |
|
36 | 5 | #[inline]
|
| 6 | + #[cfg_attr(tokio_track_caller, track_caller)] |
37 | 7 | pub(crate) fn task<F>(task: F, kind: &'static str) -> Instrumented<F> {
|
| 8 | + use tracing::instrument::Instrument; |
| 9 | + #[cfg(tokio_track_caller)] |
| 10 | + let location = std::panic::Location::caller(); |
| 11 | + #[cfg(tokio_track_caller)] |
| 12 | + let span = tracing::trace_span!( |
| 13 | + target: "tokio::task", |
| 14 | + "task", |
| 15 | + %kind, |
| 16 | + spawn.location = %format_args!("{}:{}:{}", location.file(), location.line(), location.column()), |
| 17 | + ); |
| 18 | + #[cfg(not(tokio_track_caller))] |
38 | 19 | let span = tracing::trace_span!(
|
39 | 20 | target: "tokio::task",
|
40 | 21 | "task",
|
41 | 22 | %kind,
|
42 |
| - future = %std::any::type_name::<F>(), |
43 | 23 | );
|
44 |
| - Instrumented::new(task, span) |
| 24 | + task.instrument(span) |
45 | 25 | }
|
46 | 26 | }
|
47 | 27 | }
|
|
0 commit comments