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 ¶
- func GetCounterValue(t testing.TB, reader metric.Reader, metric string, attrs attribute.Set) float64
- func GetHistogramValues(t testing.TB, reader metric.Reader, metric string, attrs attribute.Set) (uint64, float64)
- func RecordNewSpan(t testing.TB, spanName string, opts ...oteltrace.SpanStartOption) tracetest.SpanStub
- func RecordWithSpan(t testing.TB, fn func(oteltrace.Span) bool) tracetest.SpanStub
- type MockSpan
- type OTLPCollector
- func (o *OTLPCollector) Close()
- func (o *OTLPCollector) DrainMetrics() *metricsv1.ResourceMetrics
- func (o *OTLPCollector) Env() []string
- func (o *OTLPCollector) SetEnv(setenv func(key string, value string))
- func (o *OTLPCollector) TakeMetrics(expectedCount int) []*metricsv1.ResourceMetrics
- func (o *OTLPCollector) TakeSpan() *tracev1.Span
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCounterValue ¶ added in v0.4.0
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.
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) EndSpanOnError ¶
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.