1 cfg_trace! { 2 cfg_rt! { 3 pub(crate) use tracing::instrument::Instrumented; 4 5 #[inline] 6 #[cfg_attr(tokio_track_caller, track_caller)] 7 pub(crate) fn task<F>(task: F, kind: &'static str, name: Option<&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 "runtime.spawn", 15 %kind, 16 task.name = %name.unwrap_or_default(), 17 loc.file = location.file(), 18 loc.line = location.line(), 19 loc.col = location.column(), 20 ); 21 #[cfg(not(tokio_track_caller))] 22 let span = tracing::trace_span!( 23 target: "tokio::task", 24 "runtime.spawn", 25 %kind, 26 task.name = %name.unwrap_or_default(), 27 ); 28 task.instrument(span) 29 } 30 } 31 } 32 cfg_time! { 33 #[cfg_attr(tokio_track_caller, track_caller)] 34 pub(crate) fn caller_location() -> Option<&'static std::panic::Location<'static>> { 35 #[cfg(all(tokio_track_caller, tokio_unstable, feature = "tracing"))] 36 return Some(std::panic::Location::caller()); 37 #[cfg(not(all(tokio_track_caller, tokio_unstable, feature = "tracing")))] 38 None 39 } 40 } 41 42 cfg_not_trace! { 43 cfg_rt! { 44 #[inline] 45 pub(crate) fn task<F>(task: F, _: &'static str, _name: Option<&str>) -> F { 46 // nop 47 task 48 } 49 } 50 } 51