httptrace

package
v0.0.0-...-2556555 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package httptrace provides mechanisms to trace the events within HTTP client requests.

Its public types alias net/http/httptrace so contexts created by this package remain visible to net.Dialer, which uses a private standard-library context key for DNS and connection hooks.

Example
req, _ := http.NewRequest("GET", "http://example.com", nil)
trace := &httptrace.ClientTrace{
	GotConn: func(connInfo httptrace.GotConnInfo) {
		fmt.Printf("Got Conn: %+v\n", connInfo)
	},
	DNSDone: func(dnsInfo httptrace.DNSDoneInfo) {
		fmt.Printf("DNS Info: %+v\n", dnsInfo)
	},
}
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
_, err := http.DefaultTransport.RoundTrip(req)
if err != nil {
	log.Fatal(err)
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithClientTrace

func WithClientTrace(ctx context.Context, trace *ClientTrace) context.Context

WithClientTrace returns a context carrying trace in addition to any trace already registered with ctx.

Types

type ClientTrace

type ClientTrace = stdhttptrace.ClientTrace

ClientTrace is a set of hooks to run at various stages of an outgoing HTTP request.

func ContextClientTrace

func ContextClientTrace(ctx context.Context) *ClientTrace

ContextClientTrace returns the ClientTrace associated with ctx, if any.

type DNSDoneInfo

type DNSDoneInfo = stdhttptrace.DNSDoneInfo

DNSDoneInfo contains information about the results of a DNS lookup.

type DNSStartInfo

type DNSStartInfo = stdhttptrace.DNSStartInfo

DNSStartInfo contains information about a DNS request.

type GotConnInfo

type GotConnInfo = stdhttptrace.GotConnInfo

GotConnInfo contains information about a connection obtained by a client.

type WroteRequestInfo

type WroteRequestInfo = stdhttptrace.WroteRequestInfo

WroteRequestInfo contains information provided to ClientTrace.WroteRequest.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL