otelhttp

package
v0.0.0-...-1aa08c1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

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

type Filter func(*http.Request) bool

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

func FilterByHeaders(headers map[string]string) Filter

FilterByHeaders will omit instrumentation for requests that include any of the provided key-value pairs in their headers.

func FilterByPath

func FilterByPath(paths []string) Filter

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

func NewMonitor(opts ...Option) Monitor

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

func WithFilter(f Filter) Option

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

func WithTraceInHeader(h string) Option

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

type SpanNameFormatter func(r *http.Request) string

SpanNameFormatter allows to adjust how a given transaction is reported when handling an HTTP request on the client or server side.

Jump to

Keyboard shortcuts

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