observability

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package observability provides lightweight metrics collection and runtime profiling helpers using only the Go standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartPprof

func StartPprof(ctx context.Context, addr string) error

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

func (c *Collector) CounterValue(name string, tags ...string) int64

CounterValue returns the current value of a counter for testing.

func (*Collector) IncCounter

func (c *Collector) IncCounter(name string, tags ...string)

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

func (c *Collector) LatencyCount(name string, tags ...string) int64

LatencyCount returns the number of recorded latency observations for testing.

func (*Collector) RecordError

func (c *Collector) RecordError(name string)

RecordError increments the error counter name + ".errors".

func (*Collector) RecordLatency

func (c *Collector) RecordLatency(name string, d time.Duration, tags ...string)

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.

Jump to

Keyboard shortcuts

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