testkit

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package testkit provides in-memory OTel harnesses for metric and trace assertions in unit tests. Wraps sdkmetric.ManualReader and sdktrace.SpanRecorder with a narrow set of helpers. Drop down to OTel's own test types when richer assertions are needed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExponentialHistogramPoint

type ExponentialHistogramPoint struct {
	Attributes map[string]string
	Count      uint64
	Sum        float64
	Scale      int32
	ZeroCount  uint64
}

ExponentialHistogramPoint is a lossy projection of a base-2 exponential histogram data point. Count/Sum/Scale/ZeroCount cover the common assertions; reach for metricdata.ExponentialHistogram[float64] directly for bucket-level detail.

type Float64Point

type Float64Point struct {
	Attributes map[string]string
	Value      float64
}

type HistogramPoint

type HistogramPoint struct {
	Attributes map[string]string
	Count      uint64
}

type Int64Point

type Int64Point struct {
	Attributes map[string]string
	Value      int64
}

type MetricsHarness

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

func NewMetricsHarness

func NewMetricsHarness(opts ...MetricsOption) *MetricsHarness

func (*MetricsHarness) Collect

func (*MetricsHarness) ExponentialHistogramPoints

func (h *MetricsHarness) ExponentialHistogramPoints(
	ctx context.Context,
	name string,
) ([]ExponentialHistogramPoint, error)

ExponentialHistogramPoints returns base-2 exponential histogram data points matching name. Only populated when the harness is configured with an exponential-histogram aggregation selector (see WithAggregationSelector).

func (*MetricsHarness) Float64Points

func (h *MetricsHarness) Float64Points(ctx context.Context, name string) ([]Float64Point, error)

Float64Points returns Sum[float64] data points (float64 counters and up/down counters) matching name.

func (*MetricsHarness) GaugeFloat64Points

func (h *MetricsHarness) GaugeFloat64Points(ctx context.Context, name string) ([]Float64Point, error)

GaugeFloat64Points returns Gauge[float64] data points matching name.

func (*MetricsHarness) GaugeInt64Points

func (h *MetricsHarness) GaugeInt64Points(ctx context.Context, name string) ([]Int64Point, error)

GaugeInt64Points returns Gauge[int64] data points matching name.

func (*MetricsHarness) HistogramPoints

func (h *MetricsHarness) HistogramPoints(ctx context.Context, name string) ([]HistogramPoint, error)

func (*MetricsHarness) Int64Points

func (h *MetricsHarness) Int64Points(ctx context.Context, name string) ([]Int64Point, error)

func (*MetricsHarness) MetricNames

func (h *MetricsHarness) MetricNames(ctx context.Context) ([]string, error)

func (*MetricsHarness) Provider

func (h *MetricsHarness) Provider() *sdkmetric.MeterProvider

func (*MetricsHarness) Shutdown

func (h *MetricsHarness) Shutdown(ctx context.Context) error

type MetricsOption

type MetricsOption func(*metricsConfig)

MetricsOption tunes NewMetricsHarness.

func WithAggregationSelector

func WithAggregationSelector(s sdkmetric.AggregationSelector) MetricsOption

WithAggregationSelector wires a custom aggregation selector into the harness. Use when unit-testing SDK behavior against the same selector that the application uses in production (e.g., the exponential-histogram default from the histograms package).

type SpanSummary

type SpanSummary struct {
	Name       string
	Attributes map[string]string
	Events     []string
	TraceID    string
}

type TracesHarness

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

func NewTracesHarness

func NewTracesHarness() *TracesHarness

func (*TracesHarness) Ended

func (h *TracesHarness) Ended() []sdktrace.ReadOnlySpan

func (*TracesHarness) Provider

func (h *TracesHarness) Provider() *sdktrace.TracerProvider

func (*TracesHarness) Shutdown

func (h *TracesHarness) Shutdown(ctx context.Context) error

func (*TracesHarness) Summaries

func (h *TracesHarness) Summaries() []SpanSummary

Jump to

Keyboard shortcuts

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