middleware

package
v2.36.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: MIT Imports: 11 Imported by: 0

README

Middleware Handler Tracing

Usage

Default middleware

Default handler tracing will create opentracing span for handler level without logging any traceID to console.

handlerTracing := middleware.NewHandlerTracing()

r := chi.NewRouter()
r.Use(handlerTracing)

// put your routings below

Enable tracing logger

Default handler tracing will create opentracing span for handler level and log its traceID to console.

handlerTracing := middleware.NewHandlerTracing(
    middleware.WithEnabledLog(true),
)

r := chi.NewRouter()
r.Use(handlerTracing)

// put your routings below

Example result:

Screen Shot 2020-12-11 at 17 11 43

Enable tracing logger by http status

Default handler tracing will create opentracing span for handler level, but only log traceID if its http status is equal above specified limit.

handlerTracing := middleware.NewHandlerTracing(
    middleware.WithEnabledLog(true),
    middleware.WithLimitLogHTTPStatus(http.StatusBadRequest), // this sample only print traceID log if htt status is >= 400
)

r := chi.NewRouter()
r.Use(handlerTracing)

// put your routings below

Example result:

Screen Shot 2020-12-11 at 17 14 36

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandlerTracing

func NewHandlerTracing(opts ...TracingOption) func(next http.Handler) http.Handler

NewHandlerTracing initializes opentracing context for handler level, via middleware

Types

type TracingOption

type TracingOption func(*tracingConfig)

TracingOption defines functional object for tracing option

func WithEnabledLog

func WithEnabledLog(toggle bool) TracingOption

WithEnabledLog will set traceID log toggle

func WithLimitLogHTTPStatus

func WithLimitLogHTTPStatus(httpStatus int) TracingOption

WithLimitLogHTTPStatus will set traceID logger if http status is equal above certain limit

Jump to

Keyboard shortcuts

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