telemetry

package
v1.98.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package telemetry provides the common, service-agnostic observability setup shared by every Go service in this repo: one Prometheus registry (via LabKit v2), an HTTP surface to expose it, generic helpers for timing an operation into a histogram, and the tracer (see tracing.go).

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 InitTracing added in v1.47.0

func InitTracing(ctx context.Context) (*trace.Tracer, func(context.Context) error, error)

InitTracing builds the process-wide tracer from GITLAB_TRACING. Call once per process and defer the returned shutdown, which flushes the span batcher.

Tracing is off when GITLAB_TRACING is absent or unparseable, avoiding an export to a localhost collector that isn't there: https://gitlab.com/gitlab-org/labkit/-/work_items/137. A nil *trace.Tracer signals disabled; shutdown is always safe to call.

Do not pass an explicit trace.Config: an unset SampleRate means never sample, and GITLAB_TRACING's sampler_param won't fill it in.

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.

func RegisterBuildInfo added in v1.71.0

func RegisterBuildInfo(reg prometheus.Registerer, version, commit string) error

RegisterBuildInfo registers iam_build_info, always 1, with the build version and commit on its labels.

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.
Package httptelemetry provides generic, Prometheus-native HTTP server metrics for any service in this repo.
Package httptelemetry provides generic, Prometheus-native HTTP 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