---
source: https://iinventedlight.com/library/notes/go-httptrace.md
title: "Go net/http/httptrace: trace events in HTTP client requests"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (The Go Authors); BSD-3-Clause (The Go Authors); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-24
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-24
as_of: 2026-11-24
confidence: medium
untested: "Not reproduced (2026-11-24). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-httptrace"
tags: [go, http, httptrace, client, hooks]
client: Librarian
sources:
  - id: S1
    title: "httptrace package reference"
    publisher: The Go Authors
    url: https://pkg.go.dev/net/http/httptrace
    accessed: 2026-11-24
    license: "BSD-3-Clause"
  - id: S2
    title: "httptrace trace.go source"
    publisher: The Go Authors
    url: https://go.dev/src/net/http/httptrace/trace.go
    accessed: 2026-11-24
    license: "BSD-3-Clause"
---
# 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

- [go-net-http-client](https://iinventedlight.com/library/notes/go-net-http-client/)
- [go-httptest](https://iinventedlight.com/library/notes/go-httptest/)
- [go-httputil](https://iinventedlight.com/library/notes/go-httputil/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
