telemetry

package
v0.27.265 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRequestLogger

func NewRequestLogger(
	handler http.Handler,
	granularity time.Duration,
	logger xlog.KeyValueLogger,
	opts ...Option) http.Handler

NewRequestLogger create a new RequestLogger handler, requests are chained to the supplied handler. The log includes the clock time to handle the request, with specified granularity (e.g. time.Millisecond). skippath parameter allows to specify a list of paths to not log.

func NewRequestMetrics

func NewRequestMetrics(h http.Handler) http.Handler

NewRequestMetrics creates a wrapper handler to produce metrics for each request

func ShouldSkip added in v0.24.0

func ShouldSkip(cfg []LoggerSkipPath, path, userAgent string) bool

ShouldSkip returns true if the logs should be skipped

Types

type LoggerSkipPath

type LoggerSkipPath struct {
	Path  string `json:"path,omitempty" yaml:"path,omitempty"`
	Agent string `json:"agent,omitempty" yaml:"agent,omitempty"`
}

LoggerSkipPath allows to skip a log for specified Path and Agent

type Option

type Option option

Option is an option that can be passed to New().

func WithLoggerSkipPaths

func WithLoggerSkipPaths(value []LoggerSkipPath) Option

WithLoggerSkipPaths is an Option allows to skip logs on path/agent match

type RequestLogger

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

RequestLogger is a http.Handler that logs requests and forwards them on down the chain.

func (*RequestLogger) ServeHTTP

func (l *RequestLogger) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface. We wrap the call to the real handler to collect info about the response, and then write out the log line

type ResponseCapture

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

ResponseCapture is a net/http.ResponseWriter that delegates everything to the contained delegate, but captures the status code and number of bytes written

func NewResponseCapture

func NewResponseCapture(w http.ResponseWriter) *ResponseCapture

NewResponseCapture returns a new ResponseCapture instance that delegates writes to the supplied ResponseWriter

func (*ResponseCapture) BodySize

func (r *ResponseCapture) BodySize() uint64

BodySize returns in bytes the total number of bytes written to the response body so far.

func (*ResponseCapture) Flush

func (r *ResponseCapture) Flush()

Flush sends any buffered data to the client.

func (*ResponseCapture) Header

func (r *ResponseCapture) Header() http.Header

Header returns the underlying writers Header instance

func (*ResponseCapture) StatusCode

func (r *ResponseCapture) StatusCode() int

StatusCode returns the http status set by the handler.

func (*ResponseCapture) Write

func (r *ResponseCapture) Write(data []byte) (int, error)

Write the supplied data to the response (tracking the number of bytes written as we go)

func (*ResponseCapture) WriteHeader

func (r *ResponseCapture) WriteHeader(sc int)

WriteHeader sets the HTTP status code of the response

Jump to

Keyboard shortcuts

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