testotel

package
v19.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package testotel provides helpers for asserting on OpenTelemetry metrics in tests. A Recorder bundles an in-memory ManualReader with a MeterProvider, and the typed accessors collect the recorded data and return the data points of a named instrument, optionally filtered by an attribute subset. Callers keep full control over value assertions (ranges, NaN/Inf, exact counts); the helpers only do the deterministic plumbing of locating and filtering points.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GaugePoint

func GaugePoint[N int64 | float64](t testing.TB, r *Recorder, name string, attrs ...attribute.KeyValue) metricdata.DataPoint[N]

GaugePoint returns the single gauge data point whose attributes contain all of attrs, failing the test unless exactly one matches.

func GaugePoints

func GaugePoints[N int64 | float64](t testing.TB, r *Recorder, name string, attrs ...attribute.KeyValue) []metricdata.DataPoint[N]

GaugePoints returns all data points of the gauge named name whose attributes contain all of attrs. With no attrs it returns every point.

func HistogramPoint

func HistogramPoint[N int64 | float64](t testing.TB, r *Recorder, name string, attrs ...attribute.KeyValue) metricdata.HistogramDataPoint[N]

HistogramPoint returns the single histogram data point whose attributes contain all of attrs, failing the test unless exactly one matches.

func HistogramPoints

func HistogramPoints[N int64 | float64](t testing.TB, r *Recorder, name string, attrs ...attribute.KeyValue) []metricdata.HistogramDataPoint[N]

HistogramPoints returns all data points of the histogram named name whose attributes contain all of attrs. With no attrs it returns every point.

func SumPoint

func SumPoint[N int64 | float64](t testing.TB, r *Recorder, name string, attrs ...attribute.KeyValue) metricdata.DataPoint[N]

SumPoint returns the single sum data point whose attributes contain all of attrs, failing the test unless exactly one matches.

func SumPoints

func SumPoints[N int64 | float64](t testing.TB, r *Recorder, name string, attrs ...attribute.KeyValue) []metricdata.DataPoint[N]

SumPoints returns all data points of the sum named name whose attributes contain all of attrs. With no attrs it returns every point.

Types

type Recorder

type Recorder struct {
	Meter metric.Meter
	// contains filtered or unexported fields
}

Recorder is an in-memory metric pipeline for tests. Instrument the code under test with Meter, then query the recorded data through this package's accessors. TODO: the free standing functions operating on this type should be refactored as generic methods once Go supports that in Go 1.27.

func NewRecorder

func NewRecorder(t testing.TB) *Recorder

NewRecorder returns a Recorder backed by a ManualReader.

Jump to

Keyboard shortcuts

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