Documentation
¶
Overview ¶
Package leakwatch detects goroutine leaks using the Go 1.27+ runtime leak profile.
The public API is intentionally small. Create a Watcher, start it, and optionally expose debug endpoints for human-readable leak attribution.
watcher := leakwatch.New(leakwatch.WithInterval(5 * time.Minute)) watcher.Start(context.Background())
Index ¶
- type Option
- func WithHTTPClient(client *http.Client) Option
- func WithHTTPTimeout(d time.Duration) Option
- func WithHistoryCapacity(n int) Option
- func WithInterval(d time.Duration) Option
- func WithJitter(d time.Duration) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMaxProfileBytes(n int64) Option
- func WithPProfURL(url string) Option
- func WithSampleGate(gate collector.SampleGate) Option
- type Watcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*config)
Option configures a Watcher.
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client used to fetch pprof profiles.
func WithHTTPTimeout ¶
WithHTTPTimeout sets the timeout for the default pprof HTTP client. Ignored when WithHTTPClient is also set.
func WithHistoryCapacity ¶
WithHistoryCapacity sets the number of observations retained in memory.
func WithInterval ¶
WithInterval sets the sampling interval.
func WithJitter ¶
WithJitter sets random jitter applied before each sample.
func WithLogger ¶
WithLogger sets the logger used for sample failures and watcher lifecycle events.
func WithMaxProfileBytes ¶
WithMaxProfileBytes sets the maximum pprof response body size.
func WithPProfURL ¶
WithPProfURL sets the pprof goroutine leak endpoint for the default collector.
func WithSampleGate ¶
func WithSampleGate(gate collector.SampleGate) Option
WithSampleGate sets a gate that can skip individual samples.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher samples goroutine leak profiles on a schedule and maintains leak state.
func (*Watcher) LastSampleError ¶
LastSampleError returns the most recent sample failure, if any.
func (*Watcher) Observations ¶
func (w *Watcher) Observations() []domain.Observation
Observations returns the retained observation history.
func (*Watcher) ServeDebug ¶
func (w *Watcher) ServeDebug(path string, opts ...httpexport.RegisterOption) error
ServeDebug registers leak debug handlers on http.DefaultServeMux at path. Pass httpexport.WithMiddleware to add auth or other protection before exposing stack traces on a shared HTTP server.