testotel

package
v0.4.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package testotel provides test utilities for OpenTelemetry tracing and metrics tests. This is not internal for use in cmd/extproc/mainlib/main_test.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCounterValue added in v0.4.0

func GetCounterValue(t testing.TB, reader metric.Reader, metric string, attrs attribute.Set) float64

func GetHistogramValues added in v0.4.0

func GetHistogramValues(t testing.TB, reader metric.Reader, metric string, attrs attribute.Set) (uint64, float64)

GetHistogramValues returns the count and sum of a histogram metric with the given attributes.

func RecordNewSpan

func RecordNewSpan(t testing.TB, spanName string, opts ...oteltrace.SpanStartOption) tracetest.SpanStub

RecordNewSpan starts a new span with the given name and options and immediately ends it. Then, it returns the recorded span.

func RecordWithSpan

func RecordWithSpan(t testing.TB, fn func(oteltrace.Span) bool) tracetest.SpanStub

RecordWithSpan executes the provided function with a span and returns the recorded span. The function should return true if it ended the span.

Types

type MockSpan

type MockSpan struct {
	Resp          *openai.ChatCompletionResponse
	RespChunks    []*openai.ChatCompletionResponseChunk
	ErrorStatus   int
	ErrBody       string
	EndSpanCalled bool
}

MockSpan is a mock implementation of api.ChatCompletionSpan for testing purposes.

func (*MockSpan) EndSpan

func (s *MockSpan) EndSpan()

EndSpan implements api.ChatCompletionSpan.

func (*MockSpan) EndSpanOnError

func (s *MockSpan) EndSpanOnError(statusCode int, body []byte)

EndSpanOnError implements api.ChatCompletionSpan.

func (*MockSpan) RecordResponse

func (s *MockSpan) RecordResponse(resp *openai.ChatCompletionResponse)

RecordResponse implements api.ChatCompletionSpan.

func (*MockSpan) RecordResponseChunk

func (s *MockSpan) RecordResponseChunk(resp *openai.ChatCompletionResponseChunk)

RecordResponseChunk implements api.ChatCompletionSpan.

type OTLPCollector

type OTLPCollector struct {
	// contains filtered or unexported fields
}

func StartOTLPCollector

func StartOTLPCollector() *OTLPCollector

StartOTLPCollector starts a test OTLP collector server that receives trace and metrics data.

func (*OTLPCollector) Close

func (o *OTLPCollector) Close()

Close shuts down the collector and cleans up resources.

func (*OTLPCollector) DrainMetrics added in v0.4.0

func (o *OTLPCollector) DrainMetrics() *metricsv1.ResourceMetrics

DrainMetrics returns metrics or nil if none were recorded.

func (*OTLPCollector) Env

func (o *OTLPCollector) Env() []string

Env returns the environment variables needed to configure the OTLP collector.

func (*OTLPCollector) SetEnv

func (o *OTLPCollector) SetEnv(setenv func(key string, value string))

SetEnv calls setenv for each environment variable in Env.

func (*OTLPCollector) TakeMetrics added in v0.4.0

func (o *OTLPCollector) TakeMetrics(expectedCount int) []*metricsv1.ResourceMetrics

TakeMetrics collects metrics until the expected count is reached or a timeout occurs.

func (*OTLPCollector) TakeSpan

func (o *OTLPCollector) TakeSpan() *tracev1.Span

TakeSpan returns a single span or nil if none were recorded.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL