gocloud.devgocloud.dev/internal/testing/oteltest Index | Files

package oteltest

import "gocloud.dev/internal/testing/oteltest"

Package oteltest supports testing of OpenTelemetry integrations.

Index

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

func DiffSpanAttr(span sdktrace.ReadOnlySpan, key attribute.Key, wantValue string) string

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

type Call struct {
	Method string
	Status string
	Attrs  []attribute.KeyValue
}

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

Aggregation returns the aggregation for the given instrument kind.

func (*MetricExporter) Export

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

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.