Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultClient ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.