Documentation
¶
Overview ¶
Package observability provides lightweight metrics collection and runtime profiling helpers using only the Go standard library.
Index ¶
- func StartPprof(ctx context.Context, addr string) error
- type Collector
- func (c *Collector) CounterValue(name string, tags ...string) int64
- func (c *Collector) IncCounter(name string, tags ...string)
- func (c *Collector) LatencyCount(name string, tags ...string) int64
- func (c *Collector) RecordError(name string)
- func (c *Collector) RecordLatency(name string, d time.Duration, tags ...string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StartPprof ¶
StartPprof starts an HTTP server on addr exposing net/http/pprof endpoints. The server shuts down gracefully when ctx is cancelled. An empty addr is a no-op and returns nil immediately.
Security note: pprof endpoints can expose sensitive process state. In particular, /debug/pprof/cmdline prints the full process command line, which may include secrets passed as CLI flags, and CPU/profile endpoints can be used for remote DoS. Callers should bind to a loopback address (e.g., 127.0.0.1:0) unless access from remote hosts is explicitly required.
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector implements api.MetricsCollector with mutex-protected maps. It is safe for concurrent use.
func NewCollector ¶
func NewCollector() *Collector
NewCollector creates a new Collector with initialized storage.
func (*Collector) CounterValue ¶
CounterValue returns the current value of a counter for testing.
func (*Collector) IncCounter ¶
IncCounter increments a counter metric identified by name and optional tags. Tags are provided as alternating key/value pairs; an odd number of tags is tolerated by treating the final value as empty.
func (*Collector) LatencyCount ¶
LatencyCount returns the number of recorded latency observations for testing.
func (*Collector) RecordError ¶
RecordError increments the error counter name + ".errors".
func (*Collector) RecordLatency ¶
RecordLatency records a latency observation for the named metric and tags. Observations are kept in a sliding window capped at maxLatencyObservations per metric key. The backing array is reallocated when the window slides so discarded observations can be garbage collected.