package oteltest
import "gocloud.dev/internal/testing/oteltest"
Package oteltest supports testing of OpenTelemetry integrations.
Index ¶
- func Diff(spans []sdktrace.ReadOnlySpan, pkg, provider string, want []Call) string
- func DiffSpanAttr(span sdktrace.ReadOnlySpan, key attribute.Key, wantValue string) string
- func FormatSpans(spans []sdktrace.ReadOnlySpan) string
- type Call
- type MetricExporter
- func NewMetricExporter() *MetricExporter
- func (e *MetricExporter) Aggregation(kind sdkmetric.InstrumentKind) sdkmetric.Aggregation
- func (e *MetricExporter) Export(ctx context.Context, data *metricdata.ResourceMetrics) error
- func (e *MetricExporter) ForceFlush(ctx context.Context) error
- func (e *MetricExporter) GetMetrics() []metricdata.ScopeMetrics
- func (e *MetricExporter) Shutdown(ctx context.Context) error
- func (e *MetricExporter) Temporality(kind sdkmetric.InstrumentKind) metricdata.Temporality
- func (e *MetricExporter) WaitForMetrics(timeout time.Duration) (metricdata.ScopeMetrics, bool)
- type TestExporter
- func NewTestExporter() *TestExporter
- func (te *TestExporter) ForceFlush(ctx context.Context) error
- func (te *TestExporter) Metrics() []metricdata.ScopeMetrics
- func (te *TestExporter) Shutdown(ctx context.Context) error
- func (te *TestExporter) SpanStubs() tracetest.SpanStubs
- func (te *TestExporter) Spans() []sdktrace.ReadOnlySpan
- func (te *TestExporter) WaitForMetrics(timeout time.Duration) (metricdata.ScopeMetrics, bool)
Functions ¶
func Diff ¶
func Diff(spans []sdktrace.ReadOnlySpan, pkg, provider string, want []Call) string
Diff compares OpenTelemetry trace spans and metrics to expected values. It returns a non-empty string if there are any discrepancies.
func DiffSpanAttr ¶
DiffSpanAttr verifies that a span has an attribute with the expected value. It's useful for more detailed assertions on span attributes.
func FormatSpans ¶
func FormatSpans(spans []sdktrace.ReadOnlySpan) string
FormatSpans returns a formatted string of span data for debugging.
Types ¶
type Call ¶
Call represents a method call/span with its result code
func SpanToCall ¶
func SpanToCall(span sdktrace.ReadOnlySpan) Call
SpanToCall converts a span to a Call
type MetricExporter ¶
type MetricExporter struct {
// contains filtered or unexported fields
}
MetricExporter is a simple metrics exporter for testing.
func NewMetricExporter ¶
func NewMetricExporter() *MetricExporter
NewMetricExporter creates a new metric exporter for testing
func (*MetricExporter) Aggregation ¶
func (e *MetricExporter) Aggregation(kind sdkmetric.InstrumentKind) sdkmetric.Aggregation
Aggregation returns the aggregation for the given instrument kind.
func (*MetricExporter) Export ¶
func (e *MetricExporter) Export(ctx context.Context, data *metricdata.ResourceMetrics) error
Export exports metric data.
func (*MetricExporter) ForceFlush ¶
func (e *MetricExporter) ForceFlush(ctx context.Context) error
ForceFlush forces a flush of metrics
func (*MetricExporter) GetMetrics ¶
func (e *MetricExporter) GetMetrics() []metricdata.ScopeMetrics
GetMetrics returns all collected metrics
func (*MetricExporter) Shutdown ¶
func (e *MetricExporter) Shutdown(ctx context.Context) error
Shutdown shuts down the exporter
func (*MetricExporter) Temporality ¶
func (e *MetricExporter) Temporality(kind sdkmetric.InstrumentKind) metricdata.Temporality
Temporality returns the aggregation temporality for the given instrument kind.
func (*MetricExporter) WaitForMetrics ¶
func (e *MetricExporter) WaitForMetrics(timeout time.Duration) (metricdata.ScopeMetrics, bool)
WaitForMetrics waits for metrics to be collected
type TestExporter ¶
type TestExporter struct {
// contains filtered or unexported fields
}
TestExporter is an exporter of OpenTelemetry traces and metrics, for testing. It should be created with NewTestExporter.
func NewTestExporter ¶
func NewTestExporter() *TestExporter
NewTestExporter creates a TestExporter and registers it with OpenTelemetry.
func (*TestExporter) ForceFlush ¶
func (te *TestExporter) ForceFlush(ctx context.Context) error
ForceFlush forces the export of all metrics.
func (*TestExporter) Metrics ¶
func (te *TestExporter) Metrics() []metricdata.ScopeMetrics
Metrics returns the collected metrics.
func (*TestExporter) Shutdown ¶
func (te *TestExporter) Shutdown(ctx context.Context) error
Shutdown unregisters and shuts down the exporter.
func (*TestExporter) SpanStubs ¶
func (te *TestExporter) SpanStubs() tracetest.SpanStubs
SpanStubs returns the collected span stubs.
func (*TestExporter) Spans ¶
func (te *TestExporter) Spans() []sdktrace.ReadOnlySpan
Spans returns the collected spans.
func (*TestExporter) WaitForMetrics ¶
func (te *TestExporter) WaitForMetrics(timeout time.Duration) (metricdata.ScopeMetrics, bool)
WaitForMetrics waits for metrics to be collected and returns the first scope
Source Files ¶
diff.go exporter.go
- Version
- v0.42.0
- Published
- Jun 28, 2025
- Platform
- js/wasm
- Imports
- 16 packages
- Last checked
- 1 day ago –
Tools for package owners.