package tracetest
import "go.opentelemetry.io/otel/sdk/trace/tracetest"
Package tracetest is a testing helper package for the SDK. User can configure no-op or in-memory exporters to verify different SDK behaviors or custom instrumentation.
Index ¶
- type InMemoryExporter
- func NewInMemoryExporter() *InMemoryExporter
- func (imsb *InMemoryExporter) ExportSpans(_ context.Context, spans []trace.ReadOnlySpan) error
- func (imsb *InMemoryExporter) GetSpans() SpanStubs
- func (imsb *InMemoryExporter) Reset()
- func (imsb *InMemoryExporter) Shutdown(context.Context) error
- type NoopExporter
- func NewNoopExporter() *NoopExporter
- func (nsb *NoopExporter) ExportSpans(context.Context, []trace.ReadOnlySpan) error
- func (nsb *NoopExporter) Shutdown(context.Context) error
- type SpanRecorder
- func NewSpanRecorder() *SpanRecorder
- func (sr *SpanRecorder) Ended() []sdktrace.ReadOnlySpan
- func (sr *SpanRecorder) ForceFlush(context.Context) error
- func (sr *SpanRecorder) OnEnd(s sdktrace.ReadOnlySpan)
- func (sr *SpanRecorder) OnStart(_ context.Context, s sdktrace.ReadWriteSpan)
- func (sr *SpanRecorder) Reset()
- func (sr *SpanRecorder) Shutdown(context.Context) error
- func (sr *SpanRecorder) Started() []sdktrace.ReadWriteSpan
- type SpanStub
- func SpanStubFromReadOnlySpan(ro tracesdk.ReadOnlySpan) SpanStub
- func (s SpanStub) Snapshot() tracesdk.ReadOnlySpan
- type SpanStubs
Types ¶
type InMemoryExporter ¶
type InMemoryExporter struct {
// contains filtered or unexported fields
}
InMemoryExporter is an exporter that stores all received spans in-memory.
func NewInMemoryExporter ¶
func NewInMemoryExporter() *InMemoryExporter
NewInMemoryExporter returns a new InMemoryExporter.
func (*InMemoryExporter) ExportSpans ¶
func (imsb *InMemoryExporter) ExportSpans(_ context.Context, spans []trace.ReadOnlySpan) error
ExportSpans handles export of spans by storing them in memory.
func (*InMemoryExporter) GetSpans ¶
func (imsb *InMemoryExporter) GetSpans() SpanStubs
GetSpans returns the current in-memory stored spans.
func (*InMemoryExporter) Reset ¶
func (imsb *InMemoryExporter) Reset()
Reset the current in-memory storage.
func (*InMemoryExporter) Shutdown ¶
func (imsb *InMemoryExporter) Shutdown(context.Context) error
Shutdown stops the exporter by clearing spans held in memory.
type NoopExporter ¶
type NoopExporter struct{}
NoopExporter is an exporter that drops all received spans and performs no action.
func NewNoopExporter ¶
func NewNoopExporter() *NoopExporter
NewNoopExporter returns a new no-op exporter.
func (*NoopExporter) ExportSpans ¶
func (nsb *NoopExporter) ExportSpans(context.Context, []trace.ReadOnlySpan) error
ExportSpans handles export of spans by dropping them.
func (*NoopExporter) Shutdown ¶
func (nsb *NoopExporter) Shutdown(context.Context) error
Shutdown stops the exporter by doing nothing.
type SpanRecorder ¶
type SpanRecorder struct {
// contains filtered or unexported fields
}
SpanRecorder records started and ended spans.
func NewSpanRecorder ¶
func NewSpanRecorder() *SpanRecorder
NewSpanRecorder returns a new initialized SpanRecorder.
func (*SpanRecorder) Ended ¶
func (sr *SpanRecorder) Ended() []sdktrace.ReadOnlySpan
Ended returns a copy of all ended spans that have been recorded.
This method is safe to be called concurrently.
func (*SpanRecorder) ForceFlush ¶
func (sr *SpanRecorder) ForceFlush(context.Context) error
ForceFlush does nothing.
This method is safe to be called concurrently.
func (*SpanRecorder) OnEnd ¶
func (sr *SpanRecorder) OnEnd(s sdktrace.ReadOnlySpan)
OnEnd records completed spans.
This method is safe to be called concurrently.
func (*SpanRecorder) OnStart ¶
func (sr *SpanRecorder) OnStart(_ context.Context, s sdktrace.ReadWriteSpan)
OnStart records started spans.
This method is safe to be called concurrently.
func (*SpanRecorder) Reset ¶
func (sr *SpanRecorder) Reset()
Reset clears the recorded spans.
This method is safe to be called concurrently.
func (*SpanRecorder) Shutdown ¶
func (sr *SpanRecorder) Shutdown(context.Context) error
Shutdown does nothing.
This method is safe to be called concurrently.
func (*SpanRecorder) Started ¶
func (sr *SpanRecorder) Started() []sdktrace.ReadWriteSpan
Started returns a copy of all started spans that have been recorded.
This method is safe to be called concurrently.
type SpanStub ¶
type SpanStub struct { Name string SpanContext trace.SpanContext Parent trace.SpanContext SpanKind trace.SpanKind StartTime time.Time EndTime time.Time Attributes []attribute.KeyValue Events []tracesdk.Event Links []tracesdk.Link Status tracesdk.Status DroppedAttributes int DroppedEvents int DroppedLinks int ChildSpanCount int Resource *resource.Resource InstrumentationScope instrumentation.Scope // Deprecated: use InstrumentationScope instead. InstrumentationLibrary instrumentation.Library //nolint:staticcheck // This method needs to be define for backwards compatibility }
SpanStub is a stand-in for a Span.
func SpanStubFromReadOnlySpan ¶
func SpanStubFromReadOnlySpan(ro tracesdk.ReadOnlySpan) SpanStub
SpanStubFromReadOnlySpan returns a SpanStub populated from ro.
func (SpanStub) Snapshot ¶
func (s SpanStub) Snapshot() tracesdk.ReadOnlySpan
Snapshot returns a read-only copy of the SpanStub.
type SpanStubs ¶
type SpanStubs []SpanStub
SpanStubs is a slice of SpanStub use for testing an SDK.
func SpanStubsFromReadOnlySpans ¶
func SpanStubsFromReadOnlySpans(ro []tracesdk.ReadOnlySpan) SpanStubs
SpanStubsFromReadOnlySpans returns SpanStubs populated from ro.
func (SpanStubs) Snapshots ¶
func (s SpanStubs) Snapshots() []tracesdk.ReadOnlySpan
Snapshots returns s as a slice of ReadOnlySpans.
Source Files ¶
exporter.go recorder.go span.go
- Version
- v1.34.0 (latest)
- Published
- Jan 17, 2025
- Platform
- linux/amd64
- Imports
- 8 packages
- Last checked
- 1 day ago –
Tools for package owners.