Skip to content

Commit df55aba

Browse files
authored
refactor: run dns resolution in the same tracing-span as the caller (#134)
This makes it possible to trace the entire request, including DNS resolution. The use case for this is to be able to suppress specific requests from being traced in a situation where the request is used to transmit logs to a remote server. This would result in an infinite loop of logs being sent to the remote server. tokio-rs/tokio#6659 has more details.
1 parent 9fcc7f6 commit df55aba

File tree

1 file changed

+4
-2
lines changed
  • src/client/legacy/connect

1 file changed

+4
-2
lines changed

src/client/legacy/connect/dns.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::{fmt, io, vec};
3131

3232
use tokio::task::JoinHandle;
3333
use tower_service::Service;
34-
use tracing::debug;
34+
use tracing::{debug, debug_span};
3535

3636
pub(super) use self::sealed::Resolve;
3737

@@ -118,8 +118,10 @@ impl Service<Name> for GaiResolver {
118118
}
119119

120120
fn call(&mut self, name: Name) -> Self::Future {
121+
let span = debug_span!("resolve", host = %name.host).or_current();
121122
let blocking = tokio::task::spawn_blocking(move || {
122-
debug!("resolving host={:?}", name.host);
123+
let _enter = span.enter();
124+
debug!(host = name.host, "resolving");
123125
(&*name.host, 0)
124126
.to_socket_addrs()
125127
.map(|i| SocketAddrs { iter: i })

0 commit comments

Comments
 (0)