oteltest

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(m *testing.M) int

Main is a helper function that initializes OTel and runs the tests before exiting. Use it in your TestMain function.

Main covers initializing the OTel trace and logger providers, pointing to standard OTEL_* env vars.

It also initializes a context that will be used to propagate trace context to subtests.

func WithLogging

func WithLogging[T testctx.Runner[T]](cfg ...LogConfig) testctx.Middleware[T]

WithLogging creates middleware that adds OpenTelemetry logging to each test/benchmark

func WithTracing

func WithTracing[T testctx.Runner[T]](cfg ...TraceConfig[T]) testctx.Middleware[T]

WithTracing creates middleware that adds OpenTelemetry tracing around each test/benchmark

Types

type LogConfig

type LogConfig struct {
	// LoggerProvider to use for logging. If nil, the global provider will be used.
	LoggerProvider *sdklog.LoggerProvider
	// Attributes to add to all test logs
	Attributes []log.KeyValue
}

LogConfig holds configuration for the OpenTelemetry logging middleware

type TraceConfig

type TraceConfig[T testctx.Runner[T]] struct {
	// TracerProvider to use for creating spans. If nil, the global provider will be used.
	TracerProvider trace.TracerProvider
	// Attributes to add to all test spans
	Attributes []attribute.KeyValue
	// StartOptions allows customizing the span start options for each test/benchmark
	StartOptions func(*testctx.W[T]) []trace.SpanStartOption
}

TraceConfig holds configuration for the OpenTelemetry tracing middleware

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳