Help us shape the future of Go! Take the 2026 Go Developer Survey

oteltest

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package oteltest installs a span recorder for Dispatch's tests and checks what the recorded spans may and may not carry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertNoValue

func AssertNoValue(t *testing.T, spans []sdktrace.ReadOnlySpan, needle string)

AssertNoValue fails when any span quotes needle in its name, status, attributes or event attributes. Feed a personal value (an email address) through a payload or an error and check it never reaches a span.

func Attr

func Attr(s sdktrace.ReadOnlySpan, key string) (string, bool)

Attr returns the value of key on s as a string, and whether it is set.

func ChildOf

func ChildOf(child, parent sdktrace.ReadOnlySpan) bool

ChildOf reports whether child's parent is parent.

func IsRoot

func IsRoot(s sdktrace.ReadOnlySpan) bool

IsRoot reports whether s has no parent.

func LinksTo

LinksTo reports whether s links to sc.

func Named

func Named(spans []sdktrace.ReadOnlySpan, name string) []sdktrace.ReadOnlySpan

Named returns the ended spans called name.

func SpanContext

func SpanContext(t *testing.T) context.Context

SpanContext returns a context carrying a started span from a throwaway provider, standing in for the boot or request span a long-lived loop must not keep. End is called for you when the test ends.

Types

type Recorder

type Recorder struct {
	*tracetest.SpanRecorder
	// contains filtered or unexported fields
}

Recorder is a span recorder that also signals each span's end, so a test can wait for a span without sleeping.

func NewRecorder

func NewRecorder() *Recorder

NewRecorder returns a Recorder that is not installed anywhere. Register it with forge.RegisterSpanProcessor to record a Forge app's spans.

func Record

func Record(t *testing.T) *Recorder

Record installs a recording tracer provider as the global provider and restores the previous one when the test ends. Tests that call it must not run in parallel with other tests that read the global provider.

func (*Recorder) OnEnd

func (r *Recorder) OnEnd(s sdktrace.ReadOnlySpan)

OnEnd implements sdktrace.SpanProcessor.

func (*Recorder) WaitFor

func (r *Recorder) WaitFor(t *testing.T, name string, n int, timeout time.Duration) []sdktrace.ReadOnlySpan

WaitFor blocks until n spans called name have ended, or fails the test after timeout, and returns them.

Jump to

Keyboard shortcuts

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