From df55abac42d0cc1e1577f771d8a1fc91f4bcd0dd Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Wed, 7 Aug 2024 08:17:50 -0700 Subject: [PATCH] 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. https://github.com/tokio-rs/tokio/issues/6659 has more details. --- src/client/legacy/connect/dns.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/client/legacy/connect/dns.rs b/src/client/legacy/connect/dns.rs index e26b96c..fa6f74d 100644 --- a/src/client/legacy/connect/dns.rs +++ b/src/client/legacy/connect/dns.rs @@ -31,7 +31,7 @@ use std::{fmt, io, vec}; use tokio::task::JoinHandle; use tower_service::Service; -use tracing::debug; +use tracing::{debug, debug_span}; pub(super) use self::sealed::Resolve; @@ -118,8 +118,10 @@ impl Service for GaiResolver { } fn call(&mut self, name: Name) -> Self::Future { + let span = debug_span!("resolve", host = %name.host).or_current(); let blocking = tokio::task::spawn_blocking(move || { - debug!("resolving host={:?}", name.host); + let _enter = span.enter(); + debug!(host = name.host, "resolving"); (&*name.host, 0) .to_socket_addrs() .map(|i| SocketAddrs { iter: i })