HTTPtrace to debug DNS/connect/TLS timing in production-like runs

12358
0

When an outbound call is slow, it’s not always the server—it can be DNS, connection reuse, or TLS handshakes. net/http/httptrace lets you instrument a single request and see exactly where time is going. I attach a trace to the request context and record timestamps for events like DNSStart, ConnectStart, and TLSHandshakeDone. The key is that this is meant for targeted debugging, not always-on instrumentation; logs can get noisy fast. But when you’re chasing a latency regression or a weird network issue in staging, this is invaluable. I also like to print whether the connection was reused and which remote address was selected. Pair this with your standard request ID and you can correlate client-side phases with server-side logs.