Documentation
¶
Overview ¶
Package telemetrytest records OpenTelemetry measurements and spans for assertions.
Design ¶
Recorder and SpanRecorder expose what instruments emit so tests can verify values, cardinality and excluded sensitive attributes. Implementations embed no-op API types to accommodate additive interface methods. Recorder behavior is tested directly so a missing measurement cannot make a negative disclosure assertion pass without exercising instrumentation. No exporter or OpenTelemetry SDK is required.
References ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Measurement ¶
type Measurement struct {
// Scope is the instrumentation scope of the meter that produced it.
Scope string
// Instrument is the metric name.
Instrument string
// Value is the recorded number. Counters record their increment.
Value float64
// Attrs are the attributes as key=value strings, sorted, so a test can
// compare them without depending on argument order.
Attrs []string
}
Measurement is one recorded value with the attributes it carried.
type Recorder ¶
type Recorder struct {
embedded.MeterProvider
// contains filtered or unexported fields
}
Recorder is a metric.MeterProvider that keeps every measurement, for tests that need to assert what an instrument emitted — above all which attribute values reached it.
Every type here embeds the corresponding no-op, which is what the OpenTelemetry API's stability policy requires of an implementation outside the SDK: the interfaces may gain methods in a minor release, and an embedded no-op absorbs them. Implementing them directly would break the build on an upgrade.
It is safe for concurrent use.
func (*Recorder) AttributeValues ¶
AttributeValues returns every distinct value seen for one attribute key across every instrument, sorted. It is the cardinality question: a key whose values grow with the fleet shows up here as a long list.
func (*Recorder) Instrument ¶
func (r *Recorder) Instrument(name string) []Measurement
Instrument returns every measurement recorded for one instrument name.
func (*Recorder) Measurements ¶
func (r *Recorder) Measurements() []Measurement
Measurements returns everything recorded so far, in order.
type Span ¶
type Span struct {
// Scope is the instrumentation scope of the tracer that started it.
Scope string
// Name is the span name.
Name string
// Attrs are the attributes as sorted key=value strings.
Attrs []string
// Status and StatusMessage are what SetStatus recorded.
Status codes.Code
StatusMessage string
// Ended reports whether End was called.
Ended bool
}
Span is one recorded span.
type SpanRecorder ¶
type SpanRecorder struct {
embedded.TracerProvider
// contains filtered or unexported fields
}
SpanRecorder is a trace.TracerProvider that keeps every span. Like Recorder, every type embeds the corresponding no-op so the API may gain methods without breaking this package.
It is safe for concurrent use.
func NewSpanRecorder ¶
func NewSpanRecorder() *SpanRecorder
NewSpanRecorder returns an empty SpanRecorder.
func (*SpanRecorder) Named ¶
func (r *SpanRecorder) Named(name string) []*Span
Named returns every span with a given name.
func (*SpanRecorder) Spans ¶
func (r *SpanRecorder) Spans() []*Span
Spans returns every span started so far, in order.
func (*SpanRecorder) Tracer ¶
func (r *SpanRecorder) Tracer(scope string, opts ...trace.TracerOption) trace.Tracer
Tracer implements trace.TracerProvider.