Documentation
¶
Index ¶
- type Exporter
- type SpanRecorder
- func (s *SpanRecorder) BySpanID(id trace.SpanID) (StartedSpan, bool)
- func (s *SpanRecorder) Ended(id trace.SpanID) bool
- func (s *SpanRecorder) EndedStatus(id trace.SpanID) (otelcodes.Code, bool)
- func (s *SpanRecorder) ForceFlush(context.Context) error
- func (s *SpanRecorder) Names() []string
- func (s *SpanRecorder) OnEnd(span sdktrace.ReadOnlySpan)
- func (s *SpanRecorder) OnStart(_ context.Context, span sdktrace.ReadWriteSpan)
- func (s *SpanRecorder) Reset()
- func (s *SpanRecorder) Shutdown(context.Context) error
- func (s *SpanRecorder) Started() []StartedSpan
- type StartedSpan
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 ¶
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
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 ¶
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) 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.