telemetrytest

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package telemetrytest records the spans and metrics Nexus emits, so a test can assert on them without a Forge app.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertAbsent

func AssertAbsent(t testing.TB, rec *tracetest.SpanRecorder, value string)

AssertAbsent fails the test if value appears anywhere on any ended span: its name, an attribute, an event's name or attributes, or its status.

func Attrs

func Attrs(span sdktrace.ReadOnlySpan) map[string]string

Attrs returns every attribute on span as strings.

func Named

Named returns the ended spans called name, oldest first.

func Names

func Names(rec *tracetest.SpanRecorder) []string

Names lists the names of the ended spans, oldest first.

func One

One returns the one ended span called name and fails the test unless there is exactly one.

func Spans

func Spans(t testing.TB) *tracetest.SpanRecorder

Spans installs an in-memory tracer provider as the OTel global for the rest of the test and returns its recorder. The previous global comes back in t.Cleanup. Tests that call it must not run in parallel with each other.

Types

type Series

type Series struct {
	Name   string
	Unit   string
	Labels map[string]string
	// Value is a counter's total. Count and Sum are a histogram's.
	Value float64
	Count uint64
	Sum   float64
}

Series is one label set of one metric, as the sink recorded it.

type Sink

type Sink struct {
	gometrics.Metrics
	// contains filtered or unexported fields
}

Sink is a go-utils metrics sink that keeps every counter and histogram it hands out, so a test can read back names, units, labels and values. Only Counter and Histogram are implemented; anything else panics on the nil embedded interface.

func NewSink

func NewSink() *Sink

NewSink returns an empty sink.

func (*Sink) Counter

func (s *Sink) Counter(name string, opts ...gometrics.MetricOption) gometrics.Counter

Counter implements gometrics.MetricFactory.

func (*Sink) Find

func (s *Sink) Find(name string, want map[string]string) (Series, bool)

Find returns the series of name whose labels include every pair in want, and whether there was one.

func (*Sink) Histogram

func (s *Sink) Histogram(name string, opts ...gometrics.MetricOption) gometrics.Histogram

Histogram implements gometrics.MetricFactory.

func (*Sink) Names

func (s *Sink) Names() []string

Names lists every metric name the sink handed out, sorted.

func (*Sink) Series

func (s *Sink) Series(name string) []Series

Series returns every label set recorded under name, in a stable order.

Jump to

Keyboard shortcuts

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