Go net/http/httptrace: trace events in HTTP client requests
Answer: Package httptrace provides mechanisms to trace events within HTTP client requests.
Attaching hooks
WithClientTrace returns a new context based on the provided parent context.
Requests made with that context use the provided trace hooks.
Those hooks run in addition to any previous hooks registered on the parent.
Any hooks defined in the provided trace will be called first.
Connection events
GetConn is called before a connection is created or retrieved from an idle pool.
GotConn is called after a successful connection is obtained.
PutIdleConn is called when the connection is returned to the idle pool.
There is no hook for failure to obtain a connection; use the transport error instead.
See also
Claims
- id: C1 claim: Package httptrace traces events within HTTP client requests. source: S1 evidence: "mechanisms to trace the events within HTTP client requests"
- id: C2 claim: WithClientTrace returns a new context based on the parent context. source: S1 evidence: "WithClientTrace returns a new context based on the provided parent"
- id: C3 claim: Hooks in the provided trace will be called first. source: S1 evidence: "hooks defined in the provided trace will be called first"
- id: C4 claim: GetConn runs before a connection is created or retrieved from an idle pool. source: S2 evidence: "GetConn is called before a connection is created or"
Sources
- [S1] httptrace package reference. The Go Authors. https://pkg.go.dev/net/http/httptrace . License: BSD-3-Clause. Accessed 2026-11-24.
- [S2] httptrace trace.go source. The Go Authors. https://go.dev/src/net/http/httptrace/trace.go . License: BSD-3-Clause. Accessed 2026-11-24.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, httptrace package reference; The Go Authors, httptrace trace.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors, httptrace package reference; The Go Authors, httptrace trace.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go net/http/httptrace: trace events in HTTP client requests." iinventedlight Library, iil:note:m99v944g, version of 2026-11-24. https://iinventedlight.com/library/notes/go-httptrace/. License: CC-BY-4.0.
@misc{iil_note_m99v944g,
author = {{iinventedlight}},
title = {{Go net/http/httptrace: trace events in HTTP client requests}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/go-httptrace/},
note = {Permanent ID iil:note:m99v944g. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-httptrace.schema.json (schema; CC-BY-4.0)
- go-httptrace.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-httptrace.md.