Documentation
¶
Overview ¶
Package testutil provides in-memory exporters and helpers for testing code that uses metry.
Index ¶
- func SetupTestMetrics(t *testing.T) (*sdkmetric.ManualReader, metric.Meter)
- type InMemoryMetricExporter
- func (e *InMemoryMetricExporter) Aggregation(k sdkmetric.InstrumentKind) sdkmetric.Aggregation
- func (e *InMemoryMetricExporter) Export(_ context.Context, rm *metricdata.ResourceMetrics) error
- func (e *InMemoryMetricExporter) Exporter() sdkmetric.Exporter
- func (e *InMemoryMetricExporter) ForceFlush(context.Context) error
- func (e *InMemoryMetricExporter) GetMetrics() int
- func (e *InMemoryMetricExporter) LastResourceMetrics() *metricdata.ResourceMetrics
- func (e *InMemoryMetricExporter) Len() int
- func (e *InMemoryMetricExporter) Reset()
- func (e *InMemoryMetricExporter) Shutdown(context.Context) error
- func (e *InMemoryMetricExporter) Temporality(k sdkmetric.InstrumentKind) metricdata.Temporality
- type InMemoryTraceExporter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetupTestMetrics ¶
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 and the last ResourceMetrics for test assertions (e.g. lifecycle tests that need to assert on datapoints). Contract: unsupported aggregation types (e.g. Gauge) cause panic in Export (fail-fast by design).
func NewInMemoryMetricExporter ¶
func NewInMemoryMetricExporter() *InMemoryMetricExporter
NewInMemoryMetricExporter returns a new in-memory metric exporter.
func (*InMemoryMetricExporter) Aggregation ¶
func (e *InMemoryMetricExporter) Aggregation(k sdkmetric.InstrumentKind) sdkmetric.Aggregation
Aggregation implements sdkmetric.Exporter.
func (*InMemoryMetricExporter) Export ¶
func (e *InMemoryMetricExporter) Export(_ context.Context, rm *metricdata.ResourceMetrics) error
Export implements sdkmetric.Exporter; it increments the export count and stores a deep copy of the payload. A snapshot is required because the SDK may reuse the same *ResourceMetrics buffer across export cycles. Unsupported aggregation types (e.g. Gauge) cause panic before copy (fail-fast contract).
func (*InMemoryMetricExporter) Exporter ¶ added in v0.2.0
func (e *InMemoryMetricExporter) Exporter() sdkmetric.Exporter
Exporter returns the underlying sdkmetric.Exporter.
func (*InMemoryMetricExporter) ForceFlush ¶
func (e *InMemoryMetricExporter) ForceFlush(context.Context) error
ForceFlush implements sdkmetric.Exporter.
func (*InMemoryMetricExporter) GetMetrics ¶
func (e *InMemoryMetricExporter) GetMetrics() int
GetMetrics returns the number of Export calls received.
func (*InMemoryMetricExporter) LastResourceMetrics ¶ added in v0.1.2
func (e *InMemoryMetricExporter) LastResourceMetrics() *metricdata.ResourceMetrics
LastResourceMetrics returns a deep copy of the last ResourceMetrics passed to Export, or nil. Safe to call after shutdown; returned value is independent of SDK buffers.
func (*InMemoryMetricExporter) Len ¶
func (e *InMemoryMetricExporter) Len() int
Len returns the number of Export calls received.
func (*InMemoryMetricExporter) Reset ¶
func (e *InMemoryMetricExporter) Reset()
Reset clears the export count and the last snapshot so tests do not see stale data.
func (*InMemoryMetricExporter) Shutdown ¶
func (e *InMemoryMetricExporter) Shutdown(context.Context) error
Shutdown implements sdkmetric.Exporter.
func (*InMemoryMetricExporter) Temporality ¶
func (e *InMemoryMetricExporter) Temporality(k sdkmetric.InstrumentKind) metricdata.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 ¶
func (e *InMemoryTraceExporter) GetSpans() tracetest.SpanStubs
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) SpanExporter ¶ added in v0.2.0
func (e *InMemoryTraceExporter) SpanExporter() sdktrace.SpanExporter
SpanExporter returns the underlying sdktrace.SpanExporter.