package oteltest
import "gocloud.dev/internal/testing/oteltest"
Package oteltest supports testing of OpenTelemetry integrations.
Index ¶
- func Diff(gotSpans []sdktrace.ReadOnlySpan, gotMetrics []metricdata.ScopeMetrics, namePrefix, provider string, want []Call) string
- func DiffMetrics(got []metricdata.ScopeMetrics, prefix, provider string, wantCalls []Call) string
- type Call
- type TestExporter
- func NewTestExporter(t *testing.T, views []sdkmetric.View) *TestExporter
- func (te *TestExporter) ForceFlush(ctx context.Context) error
- func (te *TestExporter) GetMetrics(ctx context.Context) []metricdata.ScopeMetrics
- func (te *TestExporter) GetSpans() tracetest.SpanStubs
- func (te *TestExporter) Shutdown(ctx context.Context) error
Functions ¶
func Diff ¶
func Diff(gotSpans []sdktrace.ReadOnlySpan, gotMetrics []metricdata.ScopeMetrics, namePrefix, provider string, want []Call) string
Diff compares the list of spans and metric data obtained from OpenTelemetry instrumentation (using a test exporter like `sdktrace/tracetest.NewExporter` and `sdkmetric/metrictest.NewExporter`) with an expected list of calls. The span/metric name and status code/status attribute are compared. Order matters for traces (though not for metrics).
gotSpans should be the result from a test trace exporter (e.g., exporter.GetSpans()). gotMetrics should be the result from a test metric exporter (e.g., exporter.GetMetrics()). namePrefix is the prefix prepended to method names in spans/metrics mostly its the package name. provider is the name of the provider used (e.g., "aws"). want is the list of expected calls.
func DiffMetrics ¶
func DiffMetrics(got []metricdata.ScopeMetrics, prefix, provider string, wantCalls []Call) string
Types ¶
type Call ¶
Call represents a method call/span with its result code.
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(t *testing.T, views []sdkmetric.View) *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) GetMetrics ¶
func (te *TestExporter) GetMetrics(ctx context.Context) []metricdata.ScopeMetrics
GetMetrics returns the collected metrics.
func (*TestExporter) GetSpans ¶
func (te *TestExporter) GetSpans() tracetest.SpanStubs
GetSpans returns the collected span stubs.
func (*TestExporter) Shutdown ¶
func (te *TestExporter) Shutdown(ctx context.Context) error
Shutdown unregisters and shuts down the exporter.
Source Files ¶
diff.go exporter.go init.go
- Version
- v0.43.0 (latest)
- Published
- Jul 19, 2025
- Platform
- linux/amd64
- Imports
- 19 packages
- Last checked
- 1 day ago –
Tools for package owners.