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

trace

package
v1.19.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exporter

type Exporter struct {
	Buffer *string
	// contains filtered or unexported fields
}

Exporter is an OpenTelemetry string exporter.

func NewStringExporter

func NewStringExporter(buffer *string, logger logger.Logger) *Exporter

NewStringExporter returns a new string exporter instance.

It is very useful in testing scenario where we want to validate trace propagation.

func (*Exporter) ExportSpans added in v1.9.0

func (se *Exporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error

ExportSpan exports span content to the buffer.

func (*Exporter) Register

func (se *Exporter) Register(daprID string)

Register creates a new string exporter endpoint and reporter.

func (*Exporter) Shutdown added in v1.9.0

func (se *Exporter) Shutdown(ctx context.Context) error

ExportSpan exports span content to the buffer.

type SpanRecorder

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

SpanRecorder records every span that is started, whether or not that span is ever ended. A span that is started and never ended never reaches an exporter, so OnStart is the only place a leaked span can be observed.

func NewSpanRecorder

func NewSpanRecorder() *SpanRecorder

NewSpanRecorder installs a recorder as the global tracer provider's span processor and returns it.

The global provider accepts a delegate only once per process, so a test binary gets one recorder: call this from a single parent test or TestMain and share it, rather than once per test. Because the recorder is process-wide, tests that run in parallel with span-producing tests should select the spans they care about by span ID rather than assert on the full set.

func (*SpanRecorder) BySpanID

func (s *SpanRecorder) BySpanID(id trace.SpanID) (StartedSpan, bool)

BySpanID returns the recorded span with the given span ID. Tests running alongside other span-producing tests use it to pick out their own span.

func (*SpanRecorder) Ended

func (s *SpanRecorder) Ended(id trace.SpanID) bool

Ended reports whether the span with the given span ID has been ended. A started span that is never ended never reaches an exporter, so this is how a test catches a delivery path that leaks one.

func (*SpanRecorder) EndedStatus

func (s *SpanRecorder) EndedStatus(id trace.SpanID) (otelcodes.Code, bool)

EndedStatus returns the status the span with the given span ID carried when it ended, and whether it ended at all. A delivery that failed before reaching the app should not end its span Unset, which reads as success.

func (*SpanRecorder) ForceFlush

func (s *SpanRecorder) ForceFlush(context.Context) error

func (*SpanRecorder) Names

func (s *SpanRecorder) Names() []string

Names returns the name of every span started since the last Reset.

func (*SpanRecorder) OnEnd

func (s *SpanRecorder) OnEnd(span sdktrace.ReadOnlySpan)

OnEnd implements sdktrace.SpanProcessor, recording the span as ended along with the status it carried at the time.

func (*SpanRecorder) OnStart

func (s *SpanRecorder) OnStart(_ context.Context, span sdktrace.ReadWriteSpan)

OnStart implements sdktrace.SpanProcessor, recording the span as it starts.

func (*SpanRecorder) Reset

func (s *SpanRecorder) Reset()

Reset drops everything recorded so far.

func (*SpanRecorder) Shutdown

func (s *SpanRecorder) Shutdown(context.Context) error

Shutdown and ForceFlush complete sdktrace.SpanProcessor. The recorder keeps everything it sees in memory and has nothing to flush.

func (*SpanRecorder) Started

func (s *SpanRecorder) Started() []StartedSpan

Started returns every span started since the last Reset.

type StartedSpan

type StartedSpan struct {
	Name string
	// SpanContext is the started span's own context.
	SpanContext trace.SpanContext
	// Parent is the span context the span was started from. An invalid Parent
	// means the span is a new root.
	Parent trace.SpanContext
}

StartedSpan is a snapshot, taken when a span is started, of the properties a test needs in order to tell a new root span from a continued trace.

Jump to

Keyboard shortcuts

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