← All notes

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

Sources

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

Permanent ID: iil:note:m99v944g

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.},
}

Markdown

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.

All artifact files (JSON index)

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.