Go's net/http/httptrace package, available since Go 1.7, exposes hooks for DNS resolution, TCP connection, TLS handshake, and response timing in outgoing HTTP requests. The post explains why the package uses context.Context rather than a Tracer interface, then walks through two practical implementations: a curl --trace-style CLI that prints per-phase timing breakdowns, and a reusable http.RoundTripper that automatically logs timings for every request. It also covers connection reuse detection via GotConnInfo, body-close timing with a wrapped ReadCloser, and how multiple ClientTrace instances compose rather than replace each other.
Table of contents
Why Context, Not an InterfaceBuilding a curl --traceBuilding a RoundTripperConnection ReuseConclusionSort: