Help us shape the future of Go! Take the 2026 Go Developer Survey

metrics

package
v9.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package metrics provides OpenTelemetry metrics with cardinality protection. Metrics flow out via OTLP push — there is no scrape endpoint.

Index

Constants

View Source
const MaxLabelCombinations = 1000

MaxLabelCombinations is the cardinality cap per metric.

Variables

View Source
var (
	DurationBuckets = []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60}
	ContentBuckets  = []float64{100, 500, 1000, 5000, 10000, 50000, 100000, 500000, 1000000}
)

Pre-configured histogram buckets.

Functions

This section is empty.

Types

type CounterVec

type CounterVec struct {
	// contains filtered or unexported fields
}

CounterVec wraps an OTel Float64Counter with cardinality protection.

func (*CounterVec) Add

func (c *CounterVec) Add(ctx context.Context, val float64, labelPairs ...string)

Add increments the counter with the given label pairs (key, value, key, value, ...).

type HistogramVec

type HistogramVec struct {
	// contains filtered or unexported fields
}

HistogramVec wraps an OTel Float64Histogram with cardinality protection.

func (*HistogramVec) Observe

func (h *HistogramVec) Observe(ctx context.Context, val float64, labelPairs ...string)

Observe records a value in the histogram with the given label pairs.

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder holds pre-registered metrics for a service.

func New

func New(prefix string, logger *slog.Logger) *Recorder

New creates a Recorder with the given metric prefix and optional logger. The prefix is used as the OTel meter name and prepended to metric names.

func (*Recorder) Counter

func (r *Recorder) Counter(name string) *CounterVec

Counter creates and registers a new counter with the given name.

func (*Recorder) Histogram

func (r *Recorder) Histogram(name string, buckets []float64) *HistogramVec

Histogram creates and registers a new histogram with the given name and buckets.

func (*Recorder) RecordRequest

func (r *Recorder) RecordRequest(ctx context.Context, method, status string, durationMs float64, contentLength float64)

RecordRequest increments request metrics with cardinality protection. The context is used for trace-metric correlation via OTel exemplars.

Jump to

Keyboard shortcuts

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