tracingtest

package
v4.76.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RecordedSpan

type RecordedSpan struct {
	Name       string
	SpanID     string
	Parent     *RecordedSpan
	StartTime  time.Time
	EndTime    time.Time
	Ended      bool
	Events     []string
	Attributes map[string]any
	Status     codes.Code
	StatusDesc string
}

RecordedSpan captures span information for testing.

func (*RecordedSpan) Duration

func (rs *RecordedSpan) Duration() time.Duration

Duration returns the duration of the span. If the span has not ended, it returns 0.

func (*RecordedSpan) GetAttribute

func (rs *RecordedSpan) GetAttribute(key string) any

GetAttribute returns the value of an attribute by key, or nil if not found.

func (*RecordedSpan) GetIntAttribute

func (rs *RecordedSpan) GetIntAttribute(key string) int

GetIntAttribute returns an int attribute value, or 0 if not found.

func (*RecordedSpan) GetStringAttribute

func (rs *RecordedSpan) GetStringAttribute(key string) string

GetStringAttribute returns a string attribute value, or empty string if not found.

func (*RecordedSpan) HasParent

func (rs *RecordedSpan) HasParent() bool

HasParent returns true if this span has a parent span.

func (*RecordedSpan) IsChildOf

func (rs *RecordedSpan) IsChildOf(parent *RecordedSpan) bool

IsChildOf returns true if this span is a direct child of the given parent span.

func (*RecordedSpan) IsRoot

func (rs *RecordedSpan) IsRoot() bool

IsRoot returns true if this span has no parent (is a root span).

type RecordingTracerProvider

type RecordingTracerProvider struct {
	trace.TracerProvider
	*SpanRecorder
}

RecordingTracerProvider is a TracerProvider that records all spans for testing.

func NewInMemoryRecordingTracerProvider

func NewInMemoryRecordingTracerProvider() *RecordingTracerProvider

NewInMemoryRecordingTracerProvider creates a new noop tracer provider for testing. All spans created by this provider will be recorded and can be accessed via the [Spans] method.

func (*RecordingTracerProvider) Tracer

func (p *RecordingTracerProvider) Tracer(name string, options ...trace.TracerOption) trace.Tracer

Tracer returns a tracer that records all spans.

type SpanRecorder

type SpanRecorder struct {
	// contains filtered or unexported fields
}

SpanRecorder records spans for testing purposes.

func NewSpanRecorder

func NewSpanRecorder() *SpanRecorder

NewSpanRecorder creates a new span recorder for testing.

func (*SpanRecorder) FindSpan

func (sr *SpanRecorder) FindSpan(name string) *RecordedSpan

FindSpan returns the first recorded span with the given name, or nil if not found.

func (*SpanRecorder) FindSpansByName

func (sr *SpanRecorder) FindSpansByName(name string) []*RecordedSpan

FindSpansByName returns all recorded spans with the given name.

func (*SpanRecorder) GetChildren

func (sr *SpanRecorder) GetChildren(parent *RecordedSpan) []*RecordedSpan

GetChildren returns all child spans of the given parent span.

func (*SpanRecorder) Reset

func (sr *SpanRecorder) Reset()

Reset clears all recorded spans.

func (*SpanRecorder) Spans

func (sr *SpanRecorder) Spans() []*RecordedSpan

Spans returns a copy of all recorded spans.

Jump to

Keyboard shortcuts

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