telemetry

package
v1.42.6 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init() (*metrics.Metrics, error)

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

func NewServer(ctx context.Context, m *metrics.Metrics, name, addr string) (*Server, error)

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.

func (*Server) Address

func (s *Server) Address() string

Address returns the configured address. Use ProbeAddr for the actual bound address once serving — they differ for an ephemeral port ("...:0").

func (*Server) Logger

func (s *Server) Logger() *logrus.Entry

func (*Server) Name

func (s *Server) Name() string

func (*Server) ProbeAddr

func (s *Server) ProbeAddr() string

func (*Server) Serve

func (s *Server) Serve() error

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown tears down both the HTTP server and the underlying metrics registry. If m is shared with another service, let this Server own Shutdown — it's the one exposing the registry externally.

Directories

Path Synopsis
Package grpctelemetry provides generic, Prometheus-native gRPC server metrics for any service in this repo.
Package grpctelemetry provides generic, Prometheus-native gRPC server metrics for any service in this repo.

Jump to

Keyboard shortcuts

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