middleware

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProfilingHTTPClient added in v0.2.0

func NewProfilingHTTPClient(profiler *profiling.Profiler) *http.Client

NewProfilingHTTPClient creates an HTTP client with profiling support

func TraceMiddleware added in v0.2.0

func TraceMiddleware(name string) func(http.Handler) http.Handler

TraceMiddleware wraps a handler with automatic tracing

func WithTracer added in v0.2.0

func WithTracer(ctx context.Context, tracer *RequestTracer) context.Context

WithTracer adds a tracer to the context

func Wrap

func Wrap(handler http.Handler, store store.Store, logRequestBody, logResponseBody bool, pathMatcher PathMatcher) http.Handler

Wrap wraps an http.Handler with the request visualization middleware

func WrapWithProfiling added in v0.2.0

func WrapWithProfiling(handler http.Handler, store store.Store, logRequestBody, logResponseBody bool, pathMatcher PathMatcher, profiler *profiling.Profiler) http.Handler

WrapWithProfiling wraps an http.Handler with request visualization and performance profiling

Types

type HTTPRoundTripper added in v0.2.0

type HTTPRoundTripper struct {
	Transport http.RoundTripper
	Profiler  *profiling.Profiler
}

HTTPRoundTripper is a profiling HTTP round tripper for outgoing requests

func (*HTTPRoundTripper) RoundTrip added in v0.2.0

func (rt *HTTPRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper with profiling

type OTelMiddleware added in v0.1.3

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

OTelMiddleware wraps an http.Handler with OpenTelemetry instrumentation

func NewOTelMiddleware added in v0.1.3

func NewOTelMiddleware(handler http.Handler, serviceName, serviceVersion string) *OTelMiddleware

NewOTelMiddleware creates a new OpenTelemetry middleware

func (*OTelMiddleware) ServeHTTP added in v0.1.3

func (m *OTelMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface

type PathMatcher

type PathMatcher interface {
	ShouldIgnorePath(path string) bool
}

PathMatcher defines an interface for checking if a path should be ignored

type ProfilingConfig added in v0.2.0

type ProfilingConfig struct {
	Enabled       bool
	ProfileType   profiling.ProfileType
	Threshold     time.Duration
	CaptureTraces bool
}

ProfilingConfig contains configuration for profiling middleware

type RequestTracer added in v0.2.0

type RequestTracer struct {
	RequestID string       `json:"request_id"`
	StartTime time.Time    `json:"start_time"`
	EndTime   time.Time    `json:"end_time"`
	Traces    []TraceEntry `json:"traces"`
	// contains filtered or unexported fields
}

RequestTracer tracks execution through middleware stack

func GetTracer added in v0.2.0

func GetTracer(ctx context.Context) *RequestTracer

GetTracer gets the tracer from context

func NewRequestTracer added in v0.2.0

func NewRequestTracer(requestID string) *RequestTracer

NewRequestTracer creates a new request tracer

func (*RequestTracer) Complete added in v0.2.0

func (rt *RequestTracer) Complete()

Complete marks the tracer as complete

func (*RequestTracer) EndTrace added in v0.2.0

func (rt *RequestTracer) EndTrace(err error)

EndTrace ends the current trace entry

func (*RequestTracer) GetStackTrace added in v0.2.0

func (rt *RequestTracer) GetStackTrace() string

GetStackTrace captures current goroutine stack

func (*RequestTracer) GetTraces added in v0.2.0

func (rt *RequestTracer) GetTraces() []TraceEntry

GetTraces returns all traces

func (*RequestTracer) RecordCustom added in v0.2.0

func (rt *RequestTracer) RecordCustom(name string, details interface{})

RecordCustom records a custom event

func (*RequestTracer) RecordHTTP added in v0.2.0

func (rt *RequestTracer) RecordHTTP(method, url string, duration time.Duration, status int, err error)

RecordHTTP records an HTTP call

func (*RequestTracer) RecordSQL added in v0.2.0

func (rt *RequestTracer) RecordSQL(query string, duration time.Duration, rows int, err error)

RecordSQL records a SQL query execution

func (*RequestTracer) StartTrace added in v0.2.0

func (rt *RequestTracer) StartTrace(name, traceType string, details interface{})

StartTrace starts a new trace entry

type TraceEntry added in v0.2.0

type TraceEntry struct {
	Name      string        `json:"name"`
	Type      string        `json:"type"` // "middleware", "handler", "sql", "http", "custom"
	StartTime time.Time     `json:"start_time"`
	EndTime   time.Time     `json:"end_time"`
	Duration  time.Duration `json:"duration"`
	Status    string        `json:"status"` // "running", "completed", "error"
	Error     string        `json:"error,omitempty"`
	Details   interface{}   `json:"details,omitempty"`
	Children  []TraceEntry  `json:"children,omitempty"`
}

TraceEntry represents a single trace entry in the middleware stack

Jump to

Keyboard shortcuts

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