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, _ *metricdata.ResourceMetrics) error
- func (e *InMemoryMetricExporter) ForceFlush(context.Context) error
- func (e *InMemoryMetricExporter) GetMetrics() int
- func (e *InMemoryMetricExporter) Len() int
- func (e *InMemoryMetricExporter) MetricExporter() *metry.MetricExporter
- 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 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 ¶
func (e *InMemoryMetricExporter) Aggregation(k sdkmetric.InstrumentKind) sdkmetric.Aggregation
Aggregation implements sdkmetric.Exporter.
func (*InMemoryMetricExporter) Export ¶
func (e *InMemoryMetricExporter) Export(_ context.Context, _ *metricdata.ResourceMetrics) error
Export implements sdkmetric.Exporter and increments the export count.
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) 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 ¶
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) 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.