http

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTransport

NewTransport returns an http.RoundTripper instrumented with OpenTelemetry. It wraps the provided base RoundTripper with otelhttp using the configured telemetry facade's tracer provider, meter provider, and propagator.

If telemetry is nil, no instrumentation is applied. In that case, http.DefaultTransport is returned when base is nil; otherwise the provided base RoundTripper is returned.

func Telemetry

func Telemetry(opts ...Option) http.Middleware

Telemetry creates HTTP server telemetry middleware that instruments incoming requests with tracing and metrics. The optional opts parameters allow customizing the server configuration (such as span naming and enabling or disabling instrumentation). It returns an http.Middleware that propagates context, records spans and metrics when telemetry is enabled, and otherwise transparently passes requests through when telemetry is disabled or not initialized.

The underlying handler is resolved lazily on the first request. The application configures middleware before booting providers, so the telemetry facade is not yet available when Telemetry is called; resolving eagerly would permanently capture a disabled handler.

Types

type Filter

type Filter func(ctx http.Context) bool

Filter determines whether a specific request should be traced. Return true to trace the request, or false to exclude it.

type MiddlewareHandler

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

func (*MiddlewareHandler) Handle

func (r *MiddlewareHandler) Handle(ctx http.Context)

func (*MiddlewareHandler) Signature

func (r *MiddlewareHandler) Signature() string

type Option

type Option func(*ServerConfig)

Option applies configuration to the server instrumentation.

func WithFilter

func WithFilter(f Filter) Option

func WithMetricAttributes

func WithMetricAttributes(attrs ...attribute.KeyValue) Option

func WithSpanNameFormatter

func WithSpanNameFormatter(f SpanNameFormatter) Option

type ServerConfig

type ServerConfig struct {
	Enabled           bool                 `json:"enabled"`
	ExcludedPaths     []string             `json:"excluded_paths"`
	ExcludedMethods   []string             `json:"excluded_methods"`
	Filters           []Filter             `json:"-"`
	SpanNameFormatter SpanNameFormatter    `json:"-"`
	MetricAttributes  []attribute.KeyValue `json:"-"`
}

ServerConfig maps to "telemetry.instrumentation.http_server".

type SpanNameFormatter

type SpanNameFormatter func(route string, ctx http.Context) string

SpanNameFormatter allows customizing the span name.

Jump to

Keyboard shortcuts

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