Documentation
¶
Overview ¶
Package telemetry provides the common, service-agnostic metrics setup shared by every Go service in this repo: one Prometheus registry (via LabKit v2), an HTTP surface to expose it, and generic helpers for timing an operation into a histogram.
Index ¶
- func Init() (*metrics.Metrics, error)
- func NewUnregisteredDurationHistogram(name, help string) *prometheus.HistogramVec
- func Observe[T any](hist *prometheus.HistogramVec, operation string, fn func() (T, error)) (T, error)
- func ObserveErr(hist *prometheus.HistogramVec, operation string, fn func() error) error
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
Init builds a service's shared Prometheus registry (labkit v2). Call once per process, before any subsystem-specific Init and before serving traffic. Returns LabKit's *metrics.Metrics directly rather than a wrapper type, since it already exposes Registerer/Shutdown/Start/Gatherer.
func NewUnregisteredDurationHistogram ¶
func NewUnregisteredDurationHistogram(name, help string) *prometheus.HistogramVec
NewUnregisteredDurationHistogram returns a HistogramVec labeled "operation"/"status", the shape Observe/ObserveErr expect. Not registered with any registry — Prometheus silently no-ops Observe calls on an unregistered vec, so callers must register it themselves before use.
func Observe ¶
func Observe[T any](hist *prometheus.HistogramVec, operation string, fn func() (T, error)) (T, error)
Observe runs fn, recording its duration into hist under operation (e.g. "store.BatchUpsert") and a status of "ok" or "error" based on whether fn returned an error.
func ObserveErr ¶
func ObserveErr(hist *prometheus.HistogramVec, operation string, fn func() error) error
ObserveErr is Observe for operations that return only an error.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server exposes a *metrics.Metrics registry over HTTP (/-/metrics, /-/liveness, /-/readiness) via labkit v2's httpserver, adapting its non-blocking Start into a blocking Serve: service.ServiceManager tears down every other service the moment any one Serve() call returns, so a naive `return httpSrv.Start(ctx)` would kill the process seconds after boot. Its method set satisfies service.Service by structural typing alone, so this package never needs to import it.
func NewServer ¶
NewServer starts m's Go/process collectors and builds an HTTP server exposing m on addr. name identifies this server for logging; give each a distinct name if running more than one per process. Call Serve to listen.