Documentation
¶
Overview ¶
Package tracingtest provides OpenTelemetry test helpers. Use ContextWithFakeSpan to inject a span into a context for unit tests, and NewRecorder to capture and assert on spans emitted by production code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithFakeSpan ¶
ContextWithFakeSpan returns a context carrying a fake OTel span with randomly-generated trace and span IDs. It returns the context plus the hex-encoded trace ID and span ID so callers can assert on them without hardcoding values.
Types ¶
type Recorder ¶
type Recorder struct {
*tracetest.SpanRecorder
// contains filtered or unexported fields
}
Recorder captures all spans emitted during a test. Install it with NewRecorder and call Cleanup when the test ends.
func NewRecorder ¶
func NewRecorder() *Recorder
NewRecorder installs an in-memory OTel provider that records all spans. The previous global provider is restored on Cleanup.
rec := tracingtest.NewRecorder() t.Cleanup(rec.Cleanup)
func (*Recorder) Cleanup ¶
func (r *Recorder) Cleanup()
Cleanup restores the global tracer provider to the value it had before NewRecorder was called.