otlptest

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package otlptest runs an in-process OTLP collector (HTTP or gRPC) for tests that export through the daemon's real telemetry runtime: the providers telemetry.Init installs, the sanitizing exporters, and the OTLP exporters.

Index

Constants

View Source
const (
	TracesPath  = "/v1/traces"
	MetricsPath = "/v1/metrics"
)

Signal request paths of the OTLP/HTTP protocol; Payloads also files gRPC requests under them.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector struct {
	URL string
	// contains filtered or unexported fields
}

Collector is an OTLP collector that keeps every request body and span it receives and the latest export of each metric.

func NewCollector

func NewCollector(t testing.TB) *Collector

NewCollector starts a collector that stops at test cleanup.

func NewGRPCCollector

func NewGRPCCollector(t testing.TB) *Collector

NewGRPCCollector starts an OTLP/gRPC collector that stops at test cleanup. Payloads holds each request's raw message bytes as they arrived on the wire, before decoding.

func (*Collector) Export

func (c *Collector) Export(t testing.TB, sampleRatio float64, reg telemetry.Registries)

Export starts the daemon telemetry runtime against the collector with the global OTel providers, the way the daemon boots it, and restores disabled export at cleanup. It installs process globals: callers must not run in parallel.

func (*Collector) ExportWithMetrics

func (c *Collector) ExportWithMetrics(t testing.TB, sampleRatio float64, reg telemetry.Registries)

ExportWithMetrics is Export with metric export on; FlushMetrics collects on demand.

func (*Collector) Flush

func (c *Collector) Flush(t testing.TB) []Span

Flush exports every span ended so far through the installed provider and returns everything received.

func (*Collector) FlushMetrics

func (c *Collector) FlushMetrics(t testing.TB) map[string]Metric

FlushMetrics collects and exports every metric through the installed meter provider and returns everything received.

func (*Collector) Metrics

func (c *Collector) Metrics() map[string]Metric

Metrics returns the latest export of every metric received so far, by name.

func (*Collector) Payloads

func (c *Collector) Payloads(path string) [][]byte

Payloads returns the raw serialized export requests received so far for a signal path (TracesPath or MetricsPath): the HTTP request bodies, or the gRPC request message bytes.

func (*Collector) Spans

func (c *Collector) Spans() []Span

Spans returns every span received so far.

type Event

type Event struct {
	Name string
	Time time.Time
}

Event is one exported span event.

type Metric

type Metric struct {
	Name      string
	Unit      string
	Scope     string
	Type      MetricType
	Monotonic bool
	Points    []Point
}

Metric is one metric of the latest export that carried it; cumulative temporality makes it the running total.

type MetricType

type MetricType string

MetricType is the OTLP data type of an exported metric.

const (
	MetricSum       MetricType = "sum"
	MetricGauge     MetricType = "gauge"
	MetricHistogram MetricType = "histogram"
	MetricOther     MetricType = "other"
)

Exported metric data types.

type Point

type Point struct {
	Attributes map[string]any
	Value      float64
	Count      uint64
	Sum        float64
	Bounds     []float64
	Exemplars  int
}

Point is one exported series. Value is the sum or gauge value; histograms set Count and Sum, plus Bounds and Exemplars to check the exported shape.

type Span

type Span struct {
	Name         string
	Scope        string
	Kind         tracepb.Span_SpanKind
	TraceID      trace.TraceID
	SpanID       trace.SpanID
	ParentSpanID trace.SpanID
	Start        time.Time
	End          time.Time
	// Attributes holds string, int64, bool, and float64 values by key.
	Attributes    map[string]any
	Events        []Event
	Links         []trace.SpanContext
	StatusCode    tracepb.Status_StatusCode
	StatusMessage string
}

Span is one exported span as the collector decoded it.

func (Span) HasEvent

func (s Span) HasEvent(name string) bool

HasEvent reports whether the span carries an event named name.

Jump to

Keyboard shortcuts

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