telemetrytest

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package telemetrytest records the spans and metrics grove's drivers emit, so a driver test can assert on them without a Forge app.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attr

func Attr(span sdktrace.ReadOnlySpan, key string) (string, bool)

Attr returns the value of key on span as a string, and whether it was set.

func AttrMap

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

AttrMap returns every attribute on span as strings.

func Ended

Ended returns the ended spans the recorder saw from grove's tracer, oldest first, skipping the test's own parent spans.

func HasAttr

func HasAttr(span sdktrace.ReadOnlySpan, key attribute.Key) bool

HasAttr reports whether span carries key at all.

func Parent

func Parent(ctx context.Context) (context.Context, trace.Span)

Parent starts a span to stand in for the request or job a query runs under. Grove only starts a span when the context already has one.

func SQLDB

func SQLDB(t testing.TB, fail func(query string) error) *sql.DB

SQLDB returns a *sql.DB backed by an in-memory driver, for testing a grove driver's telemetry without a server. fail decides each statement's outcome: return nil for success, or the error the database should report. A query returns one row with one int64 column, unless fail returns sql.ErrNoRows, in which case it returns none.

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 Metrics

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

Metrics is a go-utils metrics sink that keeps every histogram series in memory. Only Histogram is implemented; anything else panics, because grove never calls it.

func NewMetrics

func NewMetrics() *Metrics

NewMetrics returns an empty sink.

func (*Metrics) Histogram

func (m *Metrics) Histogram(name string, opts ...gometrics.MetricOption) gometrics.Histogram

Histogram returns the series for name and the labels in opts, creating it the first time.

func (*Metrics) Series

func (m *Metrics) Series(name string) []Series

Series returns every label set recorded under name, sorted by labels.

type Series

type Series struct {
	Name    string
	Unit    string
	Buckets []float64
	Labels  map[string]string
	Count   uint64
}

Series is one label set of a recorded histogram.

Jump to

Keyboard shortcuts

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