httpclient

package
v1.72.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package httpclient provides an instrumented HTTP client with the addition of the traceID header and logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the default HTTP client functionalities and adds logging and instrumentation capabilities.

func New

func New(opts ...Option) *Client

New creates a new HTTP client instance.

func (*Client) Do

func (c *Client) Do(r *http.Request) (*http.Response, error)

Do performs the HTTP request with added trace ID, logging and metrics.

type InstrumentRoundTripper

type InstrumentRoundTripper func(next http.RoundTripper) http.RoundTripper

InstrumentRoundTripper is an alias for a RoundTripper function.

type Option

type Option func(c *Client)

Option is the interface that allows to set client options.

func WithComponent

func WithComponent(name string) Option

WithComponent sets the component name to be used in logs.

func WithLogPrefix

func WithLogPrefix(prefix string) Option

WithLogPrefix specifies a string prefix to be added to each log field name in the Do method.

func WithRedactFn

func WithRedactFn(fn RedactFn) Option

WithRedactFn set the function used to redact HTTP request and response dumps in the logs.

func WithRoundTripper

func WithRoundTripper(fn InstrumentRoundTripper) Option

WithRoundTripper wraps the HTTP client Transport with the specified RoundTripper function.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout overrides the default client timeout.

func WithTraceIDHeaderName

func WithTraceIDHeaderName(name string) Option

WithTraceIDHeaderName sets the trace id header name.

type RedactFn

type RedactFn func(s string) string

RedactFn is an alias for a redact function.

Jump to

Keyboard shortcuts

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