Documentation
¶
Overview ¶
Package telemetrytest provides recording OpenTelemetry providers, so a test can assert what an instrument emitted.
Why ¶
The property phase 9 has to keep is a negative one: that no device-supplied string ever reaches a metric attribute. Asserting a negative needs the attributes themselves, which the no-op providers discard and the SDK only exposes through a reader the library must not import. Recorder and SpanRecorder keep every measurement and span, and AttributeValues answers the cardinality question directly — a key whose values grow with the fleet shows up as a long list.
Every type here embeds the corresponding no-op. That 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, where implementing them directly would break the build on an upgrade.
References ¶
- Decision record 0040: docs/research/decisions/0040-opentelemetry-seam.md
- Plan of record: docs/research/implementation_plan.md (phase 9)
- OpenTelemetry: https://opentelemetry.io/docs/specs/otel/versioning-and-stability/
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.