Documentation ¶
Overview ¶
Package otelhttp provide utilities to instrument HTTP clients and servers based on Go's net/http package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Filter ¶
Filter is a predicate used to determine whether a given http.request should be traced. A Filter must return true if the request should be traced.
func FilterByHeaders ¶
FilterByHeaders will omit instrumentation for requests that include any of the provided key-value pairs in their headers.
func FilterByPath ¶
FilterByPath will omit instrumentation for requests that match any of the provided paths.
type Monitor ¶
type Monitor interface { // Client provides an HTTP client interface with automatic instrumentation // of requests. Client(base http.RoundTripper) http.Client // Handler adds instrumentation to the provided HTTP handler using the // `operation` value provided as the span name. Handler(operation string, handler http.Handler) http.Handler // HandlerFunc adds instrumentation to the provided HTTP handler function // using the `operation` value provided as the span name. HandlerFunc(operation string, fn http.HandlerFunc) http.Handler // ServerMiddleware provides a mechanism to easily instrument an HTTP // handler and automatically collect observability information for all // handled requests. Order is important when using middleware, try to // load observability support as early as possible. ServerMiddleware() func(http.Handler) http.Handler }
Monitor provide easy-to-use instrumentation primitives for HTTP clients and servers.
func NewMonitor ¶
NewMonitor returns a ready to use monitor instance that can be used to easily instrument HTTP clients and servers.
type Option ¶
type Option func(mon *httpMonitor)
Option elements provide a functional-style mechanism to adjust the HTTP monitor behavior.
func WithFilter ¶
WithFilter adds a filter function to the monitor. If any filter indicates to exclude a request then the request will not be traced. All filters must allow a request to be traced for a Span to be created. If no filters are provided then all requests are traced. Filters will be invoked for each processed request, it is advised to make them simple and fast.
func WithNetworkEvents ¶
func WithNetworkEvents() Option
WithNetworkEvents instructs the monitor to collect read and write network events. These events are discarded by default.
func WithSpanNameFormatter ¶
func WithSpanNameFormatter(nf SpanNameFormatter) Option
WithSpanNameFormatter allows to adjust how spans are reported.
func WithTraceInHeader ¶
WithTraceInHeader allows to set a custom header to report the transaction ID. The server will use this header to report the trace ID to the client.
type SpanNameFormatter ¶
SpanNameFormatter allows to adjust how a given transaction is reported when handling an HTTP request on the client or server side.