testotel

package
v0.3.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package testotel provides test utilities for OpenTelemetry tracing 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 RecordNewSpan

func RecordNewSpan(t *testing.T, 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.T, 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 data.

func (*OTLPCollector) Close

func (o *OTLPCollector) Close()

Close shuts down the collector and cleans up resources.

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) 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