Skip to content

Commit

Permalink
refactor: run dns resolution in the same tracing-span as the caller (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
joshka authored Aug 7, 2024
1 parent 9fcc7f6 commit df55aba
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/client/legacy/connect/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -118,8 +118,10 @@ impl Service<Name> 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 })
Expand Down

0 comments on commit df55aba

Please sign in to comment.