diff --git a/Cargo.toml b/Cargo.toml index e4883e6d..5d831f2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,6 +55,7 @@ full = [ "http1", "http2", "tokio", + "tracing", ] client = ["hyper/client", "dep:tracing", "dep:futures-channel", "dep:tower-service"] @@ -71,6 +72,8 @@ http2 = ["hyper/http2"] tokio = ["dep:tokio", "tokio/net", "tokio/rt", "tokio/time"] +tracing = ["dep:tracing"] + # internal features used in CI __internal_happy_eyeballs_tests = [] diff --git a/src/rt/tokio.rs b/src/rt/tokio.rs index e5f2eab7..57e3c372 100644 --- a/src/rt/tokio.rs +++ b/src/rt/tokio.rs @@ -10,6 +10,9 @@ use std::{ use hyper::rt::{Executor, Sleep, Timer}; use pin_project_lite::pin_project; +#[cfg(feature = "tracing")] +use tracing::instrument::Instrument; + /// Future executor that utilises `tokio` threads. #[non_exhaustive] #[derive(Default, Debug, Clone)] @@ -49,6 +52,10 @@ where Fut::Output: Send + 'static, { fn execute(&self, fut: Fut) { + #[cfg(feature = "tracing")] + tokio::spawn(fut.in_current_span()); + + #[cfg(not(feature = "tracing"))] tokio::spawn(fut); } }