package tracetest
import "go.opentelemetry.io/otel/api/trace/tracetest"
Package tracetest provides testing utilities for tracing.
Index ¶
- type Event
- type MockSpan
- func (ms *MockSpan) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue)
- func (ms *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue)
- func (ms *MockSpan) End(options ...apitrace.SpanOption)
- func (ms *MockSpan) IsRecording() bool
- func (ms *MockSpan) RecordError(ctx context.Context, err error, opts ...apitrace.ErrorOption)
- func (ms *MockSpan) SetAttributes(attributes ...label.KeyValue)
- func (ms *MockSpan) SetError(v bool)
- func (ms *MockSpan) SetName(name string)
- func (ms *MockSpan) SetStatus(status codes.Code, msg string)
- func (ms *MockSpan) SpanContext() apitrace.SpanContext
- func (ms *MockSpan) Tracer() apitrace.Tracer
- type MockTracer
- type Option
- func WithSpanContextFunc(f func(context.Context) trace.SpanContext) Option
- func WithSpanRecorder(sr SpanRecorder) Option
- type Span
- func (s *Span) AddEvent(ctx context.Context, name string, attrs ...label.KeyValue)
- func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue)
- func (s *Span) Attributes() map[label.Key]label.Value
- func (s *Span) End(opts ...trace.SpanOption)
- func (s *Span) EndTime() (time.Time, bool)
- func (s *Span) Ended() bool
- func (s *Span) Events() []Event
- func (s *Span) IsRecording() bool
- func (s *Span) Links() map[trace.SpanContext][]label.KeyValue
- func (s *Span) Name() string
- func (s *Span) ParentSpanID() trace.SpanID
- func (s *Span) RecordError(ctx context.Context, err error, opts ...trace.ErrorOption)
- func (s *Span) SetAttributes(attrs ...label.KeyValue)
- func (s *Span) SetName(name string)
- func (s *Span) SetStatus(code codes.Code, msg string)
- func (s *Span) SpanContext() trace.SpanContext
- func (s *Span) SpanKind() trace.SpanKind
- func (s *Span) StartTime() time.Time
- func (s *Span) StatusCode() codes.Code
- func (s *Span) StatusMessage() string
- func (s *Span) Tracer() trace.Tracer
- type SpanRecorder
- type StandardSpanRecorder
- func (ssr *StandardSpanRecorder) Completed() []*Span
- func (ssr *StandardSpanRecorder) OnEnd(span *Span)
- func (ssr *StandardSpanRecorder) OnStart(span *Span)
- func (ssr *StandardSpanRecorder) Started() []*Span
- type Tracer
- type TracerProvider
Types ¶
type Event ¶
Event encapsulates the properties of calls to AddEvent or AddEventWithTimestamp.
type MockSpan ¶
type MockSpan struct { StatusMsg string Name string Status codes.Code // contains filtered or unexported fields }
MockSpan is a mock span used in association with MockTracer for testing purpose only.
func (*MockSpan) AddEvent ¶
AddEvent does nothing.
func (*MockSpan) AddEventWithTimestamp ¶
func (ms *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue)
AddEvent does nothing.
func (*MockSpan) End ¶
func (ms *MockSpan) End(options ...apitrace.SpanOption)
End does nothing.
func (*MockSpan) IsRecording ¶
IsRecording always returns false for MockSpan.
func (*MockSpan) RecordError ¶
RecordError does nothing.
func (*MockSpan) SetAttributes ¶
SetAttributes does nothing.
func (*MockSpan) SetError ¶
SetError does nothing.
func (*MockSpan) SetName ¶
SetName sets the span name.
func (*MockSpan) SetStatus ¶
SetStatus does nothing.
func (*MockSpan) SpanContext ¶
func (ms *MockSpan) SpanContext() apitrace.SpanContext
SpanContext returns associated label.SpanContext. If the receiver is nil it returns an empty label.SpanContext
func (*MockSpan) Tracer ¶
Tracer returns MockTracer implementation of Tracer.
type MockTracer ¶
type MockTracer struct { // StartSpanID is used to initialize spanId. It is incremented by one // every time a new span is created. // // StartSpanID has to be aligned for 64-bit atomic operations. StartSpanID *uint64 // Sampled specifies if the new span should be sampled or not. Sampled bool // OnSpanStarted is called every time a new trace span is started OnSpanStarted func(span *MockSpan) }
MockTracer is a simple tracer used for testing purpose only. It only supports ChildOf option. SpanId is atomically increased every time a new span is created.
func (*MockTracer) Start ¶
func (mt *MockTracer) Start(ctx context.Context, name string, o ...apitrace.SpanOption) (context.Context, apitrace.Span)
Start starts a MockSpan. It creates a new Span based on Parent SpanContext option. TraceID is used from Parent Span Context and SpanID is assigned. If Parent SpanContext option is not specified then random TraceID is used. No other options are supported.
type Option ¶
type Option interface {
Apply(*config)
}
func WithSpanContextFunc ¶
func WithSpanContextFunc(f func(context.Context) trace.SpanContext) Option
func WithSpanRecorder ¶
func WithSpanRecorder(sr SpanRecorder) Option
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
func (*Span) AddEvent ¶
func (*Span) AddEventWithTimestamp ¶
func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...label.KeyValue)
func (*Span) Attributes ¶
Attributes returns the attributes set on the Span, either at or after creation time. If the same attribute key was set multiple times, the last call will be used. Attributes cannot be changed after End has been called on the Span.
func (*Span) End ¶
func (s *Span) End(opts ...trace.SpanOption)
func (*Span) EndTime ¶
EndTime returns the time at which the Span was ended if at has been ended, or false otherwise. If the span has been ended, the returned time will be the wall-clock time unless a specific end time was provided.
func (*Span) Ended ¶
Ended returns whether the Span has been ended, i.e., whether End has been called at least once on the Span.
func (*Span) Events ¶
Events returns the events set on the Span. Events cannot be changed after End has been called on the Span.
func (*Span) IsRecording ¶
func (*Span) Links ¶
func (s *Span) Links() map[trace.SpanContext][]label.KeyValue
Links returns the links set on the Span at creation time. If multiple links for the same SpanContext were set, the last link will be used.
func (*Span) Name ¶
Name returns the name most recently set on the Span, either at or after creation time. It cannot be change after End has been called on the Span.
func (*Span) ParentSpanID ¶
ParentSpanID returns the SpanID of the parent Span. If the Span is a root Span and therefore does not have a parent, the returned SpanID will be invalid (i.e., it will contain all zeroes).
func (*Span) RecordError ¶
func (*Span) SetAttributes ¶
func (*Span) SetName ¶
func (*Span) SetStatus ¶
func (*Span) SpanContext ¶
func (s *Span) SpanContext() trace.SpanContext
func (*Span) SpanKind ¶
SpanKind returns the span kind of this span.
func (*Span) StartTime ¶
StartTime returns the time at which the Span was started. This will be the wall-clock time unless a specific start time was provided.
func (*Span) StatusCode ¶
Status returns the status most recently set on the Span, or codes.OK if no status has been explicitly set. It cannot be changed after End has been called on the Span.
func (*Span) StatusMessage ¶
StatusMessage returns the status message most recently set on the Span or the empty string if no status mesaage was set.
func (*Span) Tracer ¶
type SpanRecorder ¶
type StandardSpanRecorder ¶
type StandardSpanRecorder struct {
// contains filtered or unexported fields
}
func (*StandardSpanRecorder) Completed ¶
func (ssr *StandardSpanRecorder) Completed() []*Span
func (*StandardSpanRecorder) OnEnd ¶
func (ssr *StandardSpanRecorder) OnEnd(span *Span)
func (*StandardSpanRecorder) OnStart ¶
func (ssr *StandardSpanRecorder) OnStart(span *Span)
func (*StandardSpanRecorder) Started ¶
func (ssr *StandardSpanRecorder) Started() []*Span
type Tracer ¶
type Tracer struct { // Name is the instrumentation name. Name string // Version is the instrumentation version. Version string // contains filtered or unexported fields }
Tracer is an OpenTelemetry Tracer implementation used for testing.
func (*Tracer) Start ¶
func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.SpanOption) (context.Context, trace.Span)
type TracerProvider ¶
type TracerProvider struct {
// contains filtered or unexported fields
}
func NewTracerProvider ¶
func NewTracerProvider(opts ...Option) *TracerProvider
func (*TracerProvider) Tracer ¶
func (p *TracerProvider) Tracer(instName string, opts ...trace.TracerOption) trace.Tracer
Source Files ¶
config.go doc.go event.go mock_span.go mock_tracer.go provider.go span.go tracer.go
- Version
- v0.13.0
- Published
- Oct 8, 2020
- Platform
- js/wasm
- Imports
- 12 packages
- Last checked
- 47 minutes ago –
Tools for package owners.