Documentation
¶
Index ¶
- Constants
- func NewProfilingHTTPClient(profiler *profiling.Profiler) *http.Client
- func TraceMiddleware(name string) func(http.Handler) http.Handler
- func WithTracer(ctx context.Context, tracer *RequestTracer) context.Context
- func Wrap(handler http.Handler, st store.Store, logRequestBody, logResponseBody bool, ...) http.Handler
- func WrapWithLimits(handler http.Handler, st store.Store, logRequestBody, logResponseBody bool, ...) http.Handler
- func WrapWithProfiling(handler http.Handler, st store.Store, logRequestBody, logResponseBody bool, ...) http.Handler
- func WrapWithProfilingAndLimits(handler http.Handler, st store.Store, logRequestBody, logResponseBody bool, ...) http.Handler
- type HTTPRoundTripper
- type LogCollector
- type MiddlewareStackKey
- type PathMatcher
- type ProfilingConfig
- type RequestTracer
- func (rt *RequestTracer) Complete()
- func (rt *RequestTracer) EndTrace(err error)
- func (rt *RequestTracer) GetStackTrace() string
- func (rt *RequestTracer) GetTraces() []TraceEntry
- func (rt *RequestTracer) RecordCustom(name string, details interface{})
- func (rt *RequestTracer) RecordHTTP(method, url string, duration time.Duration, status int, err error)
- func (rt *RequestTracer) RecordSQL(query string, duration time.Duration, rows int, err error)
- func (rt *RequestTracer) StartTrace(name, traceType string, details interface{})
- type RouteTraceKey
- type TraceEntry
- type TracerContextKey
Constants ¶
const DefaultMaxBodyBytes = 1 << 20 // 1 MiB
DefaultMaxBodyBytes is the default cap for captured request/response body size. Bodies larger than this are truncated with a marker suffix to avoid unbounded memory growth.
Variables ¶
This section is empty.
Functions ¶
func NewProfilingHTTPClient ¶
NewProfilingHTTPClient creates an HTTP client with profiling support
func TraceMiddleware ¶
TraceMiddleware wraps a handler with automatic tracing
func WithTracer ¶
func WithTracer(ctx context.Context, tracer *RequestTracer) context.Context
WithTracer adds a tracer to the context
func Wrap ¶
func Wrap(handler http.Handler, st store.Store, logRequestBody, logResponseBody bool, pathMatcher PathMatcher) http.Handler
Wrap wraps an http.Handler with the request visualization middleware
func WrapWithLimits ¶
func WrapWithLimits(handler http.Handler, st store.Store, logRequestBody, logResponseBody bool, pathMatcher PathMatcher, maxBody int, sampleRate float64) http.Handler
WrapWithLimits is identical to Wrap but allows the caller to specify the maximum number of captured body bytes (per request and per response, <= 0 disables the cap) and the sampling rate (0..1; requests that lose the coin toss pass through uncaptured).
func WrapWithProfiling ¶
func WrapWithProfiling(handler http.Handler, st store.Store, logRequestBody, logResponseBody bool, pathMatcher PathMatcher, profiler *profiling.Profiler) http.Handler
WrapWithProfiling wraps an http.Handler with request visualization and performance profiling.
func WrapWithProfilingAndLimits ¶
func WrapWithProfilingAndLimits(handler http.Handler, st store.Store, logRequestBody, logResponseBody bool, pathMatcher PathMatcher, profiler *profiling.Profiler, maxBody int, sampleRate float64) http.Handler
WrapWithProfilingAndLimits is identical to WrapWithProfiling but exposes the captured-body size cap.
Types ¶
type HTTPRoundTripper ¶
type HTTPRoundTripper struct {
Transport http.RoundTripper
Profiler *profiling.Profiler
}
HTTPRoundTripper is a profiling HTTP round tripper for outgoing requests
type LogCollector ¶
type LogCollector struct {
// contains filtered or unexported fields
}
LogCollector accumulates log lines emitted during one request.
func LogCollectorFromContext ¶
func LogCollectorFromContext(ctx context.Context) *LogCollector
LogCollectorFromContext returns the request's collector, or nil when the context does not belong to a captured request.
func WithLogCollector ¶
func WithLogCollector(ctx context.Context) (context.Context, *LogCollector)
WithLogCollector attaches a fresh collector to ctx and returns both.
func (*LogCollector) Append ¶
func (c *LogCollector) Append(e store.LogEntry)
Append records one log line, dropping beyond the per-request cap.
func (*LogCollector) Snapshot ¶
func (c *LogCollector) Snapshot() []store.LogEntry
Snapshot returns the collected lines. A trailing marker entry reports how many lines were dropped, if any.
type MiddlewareStackKey ¶
type MiddlewareStackKey struct{}
MiddlewareStackKey is the context key user middleware can write to in order to surface custom middleware-stack information into the dashboard's "middleware trace" view. Expected value type: map[string]interface{} with a "stack" key whose value is []map[string]interface{}.
type PathMatcher ¶
PathMatcher defines an interface for checking if a path should be ignored
type ProfilingConfig ¶
type ProfilingConfig struct {
Enabled bool
ProfileType profiling.ProfileType
Threshold time.Duration
CaptureTraces bool
}
ProfilingConfig contains configuration for profiling middleware
type RequestTracer ¶
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 ¶
func GetTracer(ctx context.Context) *RequestTracer
GetTracer gets the tracer from context
func NewRequestTracer ¶
func NewRequestTracer(requestID string) *RequestTracer
NewRequestTracer creates a new request tracer
func (*RequestTracer) Complete ¶
func (rt *RequestTracer) Complete()
Complete marks the tracer as complete
func (*RequestTracer) EndTrace ¶
func (rt *RequestTracer) EndTrace(err error)
EndTrace ends the current trace entry
func (*RequestTracer) GetStackTrace ¶
func (rt *RequestTracer) GetStackTrace() string
GetStackTrace captures current goroutine stack
func (*RequestTracer) GetTraces ¶
func (rt *RequestTracer) GetTraces() []TraceEntry
GetTraces returns all traces
func (*RequestTracer) RecordCustom ¶
func (rt *RequestTracer) RecordCustom(name string, details interface{})
RecordCustom records a custom event
func (*RequestTracer) RecordHTTP ¶
func (rt *RequestTracer) RecordHTTP(method, url string, duration time.Duration, status int, err error)
RecordHTTP records an HTTP call
func (*RequestTracer) StartTrace ¶
func (rt *RequestTracer) StartTrace(name, traceType string, details interface{})
StartTrace starts a new trace entry
type RouteTraceKey ¶
type RouteTraceKey struct{}
RouteTraceKey is the context key user middleware can write to in order to attach a JSON-encoded route descriptor to the request log. Expected value type: string (JSON-encoded object).
type TraceEntry ¶
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
type TracerContextKey ¶
type TracerContextKey struct{}
TracerContextKey is the public context key used to attach a *RequestTracer to a request context. External packages (e.g. internal/profiling) read this key, so it must remain exported.