middleware

package
v0.0.0-...-56b5c6d Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(logger log.Logger) func(next http.Handler) http.Handler

Logger returns a middleware to log HTTP requests.

func RequestID

func RequestID(h http.Handler) http.Handler

RequestID returns a middleware that sets a unique request id for each request.

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext returns the request id from context.

func Tracer

func Tracer(logger log.Logger, tracer trace.Tracer, name string) func(next http.Handler) http.Handler

Tracer returns an HTTP handler that injects the given tracer and starts a new server span. If any client span is fetched from the wire, we include that as our parent.

Types

type MetricsMiddleware

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

func NewMetricsMiddleware

func NewMetricsMiddleware(reg prometheus.Registerer) *MetricsMiddleware

NewMetricsMiddleware provides default MetricsMiddleware.

func (*MetricsMiddleware) NewHandler

func (ins *MetricsMiddleware) NewHandler(handlerName string) func(next http.Handler) http.Handler

NewHandler wraps the given HTTP handler for instrumentation. It registers four metric collectors (if not already done) and reports HTTP metrics to the (newly or already) registered collectors: http_requests_total (CounterVec), http_request_duration_seconds (Histogram), http_request_size_bytes (Summary), http_response_size_bytes (Summary). Each has a constant label named "handler" with the provided handlerName as value. http_requests_total is a metric vector partitioned by HTTP method (label name "method") and HTTP status code (label name "code").

Jump to

Keyboard shortcuts

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