middleware

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 3 Imported by: 0

README

middleware

import "github.com/brpaz/lib-go/tracing/middleware"

Index

func Tracing

func Tracing(opts ...TracingOption) func(http.Handler) http.Handler

Tracing returns an OpenTelemetry HTTP middleware that creates a span per request.

type TracingOption

TracingOption configures the Tracing middleware.

type TracingOption func(*tracingConfig)

func WithExcludeFunc
func WithExcludeFunc(fn func(r *http.Request) bool) TracingOption

WithExcludeFunc excludes requests matching fn from tracing spans. Use it for prefix, glob or regex matching beyond the exact paths supported by WithExcludedRoutes.

func WithExcludedRoutes
func WithExcludedRoutes(routes ...string) TracingOption

WithExcludedRoutes excludes the given exact paths from tracing spans. By default, no paths are excluded.

func WithSpanNameFormatter
func WithSpanNameFormatter(fn func(r *http.Request) string) TracingOption

WithSpanNameFormatter sets a function to derive the span name from the request. This is useful to use the matched route pattern (e.g. from chi, gorilla/mux, etc.) so cardinality stays bounded in the collector.

By default, the span name is "<method> <path>".

Generated by gomarkdoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tracing

func Tracing(opts ...TracingOption) func(http.Handler) http.Handler

Tracing returns an OpenTelemetry HTTP middleware that creates a span per request.

Types

type TracingOption

type TracingOption func(*tracingConfig)

TracingOption configures the Tracing middleware.

func WithExcludeFunc

func WithExcludeFunc(fn func(r *http.Request) bool) TracingOption

WithExcludeFunc excludes requests matching fn from tracing spans. Use it for prefix, glob or regex matching beyond the exact paths supported by WithExcludedRoutes.

func WithExcludedRoutes

func WithExcludedRoutes(routes ...string) TracingOption

WithExcludedRoutes excludes the given exact paths from tracing spans. By default, no paths are excluded.

func WithSpanNameFormatter

func WithSpanNameFormatter(fn func(r *http.Request) string) TracingOption

WithSpanNameFormatter sets a function to derive the span name from the request. This is useful to use the matched route pattern (e.g. from chi, gorilla/mux, etc.) so cardinality stays bounded in the collector.

By default, the span name is "<method> <path>".

Jump to

Keyboard shortcuts

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