trace

package
v1.26.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package trace extends the httptrace.ClientTrace and adds additional HTTPRequest hooks. A custom ClientTrace definition can be registered in the client.Client by the AndTrace method.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientTrace

type ClientTrace struct {
	httptrace.ClientTrace // native, low level trace
	// HTTPRequestStart is called when the request begins.
	// It is invoked one or more times, because it includes redirects and retries.
	HTTPRequestStart func(request *http.Request)
	// HTTPResponse is called when all headers and the HTTP status code are received.
	// The body stream have not been read yet!
	// It is invoked one or more times, because it includes redirects and retries.
	HTTPResponse func(response *http.Response, err error)
	// HTTPRequestDone is called when the request is completed and the response body is closed.
	// It is invoked one or more times, because it includes redirects and retries.
	HTTPRequestDone func(response *http.Response, send, received int64, err error)
	// RetryDelay is called before retry delay.
	RetryDelay func(attempt int, delay time.Duration)
	// BodyParseStart is called when the body parsing begins.
	BodyParseStart func(response *http.Response)
	// BodyParseDone is called when the body parsing completes.
	BodyParseDone func(response *http.Response, result any, err error, parseError error)
	// RequestProcessed is called when Client.Send method is done.
	// It is invoked only once after all redirects and retries.
	RequestProcessed func(result any, err error)
}

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

func (*ClientTrace) Compose

func (t *ClientTrace) Compose(old *ClientTrace)

Compose modifies t such that it respects the previously-registered hooks in old, subject to the composition policy requested in t.Compose. Copy of httptrace.compose.

type Factory

type Factory func(ctx context.Context, request request.HTTPRequest) (context.Context, *ClientTrace)

Factory creates ClientTrace hooks for a request.

func DumpTracer

func DumpTracer(wr io.Writer) Factory

DumpTracer dumps HTTP request and response to a writer. Output may contain unmasked tokens, do not use it in production!

func LogTracer

func LogTracer(wr io.Writer) Factory

Directories

Path Synopsis
Package otel provides OpenTelemetry tracing and metrics for HTTP client requests.
Package otel provides OpenTelemetry tracing and metrics for HTTP client requests.

Jump to

Keyboard shortcuts

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