Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: run dns resolution in the same tracing-span as the caller #134

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::env;
use http_body_util::Empty;
use hyper::Request;
use hyper_util::client::legacy::{connect::HttpConnector, Client};
use tracing::{info_span, Instrument};

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -28,7 +29,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.uri(url)
.body(Empty::<bytes::Bytes>::new())?;

let resp = client.request(req).await?;
let span = info_span!("request", uri = %req.uri());
let resp = client.request(req).instrument(span).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove this too?

I agree it's useful when debugging, but I worry it distracts from the initial usage of someone just wanting to get the client working.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


eprintln!("{:?} {:?}", resp.version(), resp.status());
eprintln!("{:#?}", resp.headers());
Expand Down
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