testutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package testutil provides in-memory exporters and helpers for testing code that uses metry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupTestMetrics

func SetupTestMetrics(t *testing.T) (*sdkmetric.ManualReader, metric.Meter)

SetupTestMetrics configures the global meter provider with a ManualReader so tests can collect metrics synchronously via reader.Collect. Registers cleanup on t. Returns the reader (for Collect and assertions) and the meter (for creating instruments).

Types

type InMemoryMetricExporter

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

InMemoryMetricExporter stores the count of Export calls for test assertions. It implements sdkmetric.Exporter so it can be used with metry.Init.

func NewInMemoryMetricExporter

func NewInMemoryMetricExporter() *InMemoryMetricExporter

NewInMemoryMetricExporter returns a new in-memory metric exporter.

func (*InMemoryMetricExporter) Aggregation

Aggregation implements sdkmetric.Exporter.

func (*InMemoryMetricExporter) Export

Export implements sdkmetric.Exporter and increments the export count.

func (*InMemoryMetricExporter) ForceFlush

ForceFlush implements sdkmetric.Exporter.

func (*InMemoryMetricExporter) GetMetrics

func (e *InMemoryMetricExporter) GetMetrics() int

GetMetrics returns the number of Export calls received.

func (*InMemoryMetricExporter) Len

func (e *InMemoryMetricExporter) Len() int

Len returns the number of Export calls received.

func (*InMemoryMetricExporter) MetricExporter

func (e *InMemoryMetricExporter) MetricExporter() *metry.MetricExporter

MetricExporter returns a metry.MetricExporter that sends metrics to this in-memory store.

func (*InMemoryMetricExporter) Reset

func (e *InMemoryMetricExporter) Reset()

Reset clears the export count.

func (*InMemoryMetricExporter) Shutdown

Shutdown implements sdkmetric.Exporter.

func (*InMemoryMetricExporter) Temporality

Temporality implements sdkmetric.Exporter.

type InMemoryTraceExporter

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

InMemoryTraceExporter stores spans in memory for test assertions.

func NewInMemoryTraceExporter

func NewInMemoryTraceExporter() *InMemoryTraceExporter

NewInMemoryTraceExporter returns a new in-memory trace exporter.

func SetupTestTracing

func SetupTestTracing(t *testing.T) *InMemoryTraceExporter

SetupTestTracing configures the global tracer with an in-memory exporter using a synchronous SimpleSpanProcessor so spans are available immediately for assertions. Registers cleanup on t. Returns the InMemoryTraceExporter for assertions.

func (*InMemoryTraceExporter) GetSpans

GetSpans returns a copy of the stored span stubs.

func (*InMemoryTraceExporter) Len

func (e *InMemoryTraceExporter) Len() int

Len returns the number of stored spans.

func (*InMemoryTraceExporter) Reset

func (e *InMemoryTraceExporter) Reset()

Reset clears all stored spans.

func (*InMemoryTraceExporter) TraceExporter

func (e *InMemoryTraceExporter) TraceExporter() *metry.TraceExporter

TraceExporter returns a metry.TraceExporter that sends spans to this in-memory store. Use it in metry.Options when calling metry.Init.

Jump to

Keyboard shortcuts

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