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 ¶
- func GaugePoint[N int64 | float64](t testing.TB, r *Recorder, name string, attrs ...attribute.KeyValue) metricdata.DataPoint[N]
- func GaugePoints[N int64 | float64](t testing.TB, r *Recorder, name string, attrs ...attribute.KeyValue) []metricdata.DataPoint[N]
- func HistogramPoint[N int64 | float64](t testing.TB, r *Recorder, name string, attrs ...attribute.KeyValue) metricdata.HistogramDataPoint[N]
- func HistogramPoints[N int64 | float64](t testing.TB, r *Recorder, name string, attrs ...attribute.KeyValue) []metricdata.HistogramDataPoint[N]
- func SumPoint[N int64 | float64](t testing.TB, r *Recorder, name string, attrs ...attribute.KeyValue) metricdata.DataPoint[N]
- func SumPoints[N int64 | float64](t testing.TB, r *Recorder, name string, attrs ...attribute.KeyValue) []metricdata.DataPoint[N]
- type Recorder
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.
Types ¶
type Recorder ¶
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 ¶
NewRecorder returns a Recorder backed by a ManualReader.