httpclient

package
v0.0.0-...-f0d0f3b Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: ISC Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultClient

func DefaultClient(options ...Option) *http.Client

DefaultClient returns a new http.Client with similar default values to http.Client, but with a non-shared Transport, idle connections disabled, and keepalives disabled.

func DefaultPooledClient

func DefaultPooledClient(options ...Option) *http.Client

DefaultPooledClient returns a new http.Client with similar default values to http.Client, but with a shared Transport. Do not use this function for transient clients as it can leak file descriptors over time. Only use this for clients that will be re-used for the same host(s).

func DefaultPooledTransport

func DefaultPooledTransport(options ...Option) http.RoundTripper

DefaultPooledTransport returns a new http.Transport with similar default values to http.DefaultTransport. Do not use this for transient transports as it can leak file descriptors over time. Only use this for transports that will be re-used for the same host(s).

func DefaultTransport

func DefaultTransport(options ...Option) http.RoundTripper

DefaultTransport returns a new http.Transport with similar default values to http.DefaultTransport, but with idle connections and keepalives disabled.

Types

type Option

type Option func(o *Options)

Option defines a function signature for configuring options within the httpclient package.

func WithLogger

func WithLogger(l *log.Logger) Option

WithLogger is an option setter for specifying a logger for HTTP telemetry and error logging.

func WithRegisterer

func WithRegisterer(r prometheus.Registerer) Option

WithRegisterer sets a custom Prometheus registerer for metrics.

func WithTLSConfig

func WithTLSConfig(c *tls.Config) Option

WithTLSConfig is an option setter for setting TLS configurations on HTTP transports.

func WithTracerProvider

func WithTracerProvider(tp trace.TracerProvider) Option

WithTracerProvider configures OpenTelemetry tracing with the provided tracer provider.

type Options

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

Options holds configurable options for http transports used within the package. This includes logging, metrics, and TLS configurations.

type TelemetryRoundTripper

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

TelemetryRoundTripper is an http.RoundTripper that wraps another http.RoundTripper to add telemetry capabilities. It logs requests, measures request latency, and counts requests using specified telemetry tools.

func NewTelemetryRoundTripper

func NewTelemetryRoundTripper(
	next http.RoundTripper,
	logger *log.Logger,
	tp trace.TracerProvider,
	registerer prometheus.Registerer,
) *TelemetryRoundTripper

NewTelemetryRoundTripper creates a new TelemetryRoundTripper with the provided next RoundTripper, logger, and metric meter. It initializes and registers telemetry instruments for counting requests and measuring request latency. It uses fallbacks for the logger and meter if nil references are provided.

func (*TelemetryRoundTripper) RoundTrip

func (rt *TelemetryRoundTripper) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction and records telemetry data including metrics and traces. It logs the request details, measures the request latency, and counts the request based on the response status. It sanitizes URLs to exclude query parameters and fragments for logging and tracing.

Jump to

Keyboard shortcuts

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