mocktracer

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2020 License: Apache-2.0 Imports: 11 Imported by: 44

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Extractor

type Extractor interface {
	// Extract decodes a SpanContext instance from the given `carrier`,
	// or (nil, opentracing.ErrSpanContextNotFound) if no context could
	// be found in the `carrier`.
	Extract(carrier interface{}) (MockSpanContext, error)
}

Extractor is responsible for extracting SpanContext instances from a format-specific "carrier" object. Typically the extraction will take place on the server side of an RPC boundary, but message queues and other IPC mechanisms are also reasonable places to use an Extractor.

type Injector

type Injector interface {
	// Inject takes `SpanContext` and injects it into `carrier`. The actual type
	// of `carrier` depends on the `format` passed to `Tracer.Inject()`.
	//
	// Implementations may return opentracing.ErrInvalidCarrier or any other
	// implementation-specific error if injection fails.
	Inject(ctx MockSpanContext, carrier interface{}) error
}

Injector is responsible for injecting SpanContext instances in a manner suitable for propagation via a format-specific "carrier" object. Typically the injection will take place across an RPC boundary, but message queues and other IPC mechanisms are also reasonable places to use an Injector.

type MockKeyValue added in v1.0.0

type MockKeyValue struct {
	Key string

	// All MockLogRecord values are coerced to strings via fmt.Sprint(), though
	// we retain their type separately.
	ValueKind   reflect.Kind
	ValueString string
}

MockKeyValue represents a single key:value pair.

func (*MockKeyValue) EmitBool added in v1.0.0

func (m *MockKeyValue) EmitBool(key string, value bool)

EmitBool belongs to the log.Encoder interface

func (*MockKeyValue) EmitFloat32 added in v1.0.0

func (m *MockKeyValue) EmitFloat32(key string, value float32)

EmitFloat32 belongs to the log.Encoder interface

func (*MockKeyValue) EmitFloat64 added in v1.0.0

func (m *MockKeyValue) EmitFloat64(key string, value float64)

EmitFloat64 belongs to the log.Encoder interface

func (*MockKeyValue) EmitInt added in v1.0.0

func (m *MockKeyValue) EmitInt(key string, value int)

EmitInt belongs to the log.Encoder interface

func (*MockKeyValue) EmitInt32 added in v1.0.0

func (m *MockKeyValue) EmitInt32(key string, value int32)

EmitInt32 belongs to the log.Encoder interface

func (*MockKeyValue) EmitInt64 added in v1.0.0

func (m *MockKeyValue) EmitInt64(key string, value int64)

EmitInt64 belongs to the log.Encoder interface

func (*MockKeyValue) EmitLazyLogger added in v1.0.0

func (m *MockKeyValue) EmitLazyLogger(value log.LazyLogger)

EmitLazyLogger belongs to the log.Encoder interface

func (*MockKeyValue) EmitObject added in v1.0.0

func (m *MockKeyValue) EmitObject(key string, value interface{})

EmitObject belongs to the log.Encoder interface

func (*MockKeyValue) EmitString added in v1.0.0

func (m *MockKeyValue) EmitString(key, value string)

EmitString belongs to the log.Encoder interface

func (*MockKeyValue) EmitUint32 added in v1.0.0

func (m *MockKeyValue) EmitUint32(key string, value uint32)

EmitUint32 belongs to the log.Encoder interface

func (*MockKeyValue) EmitUint64 added in v1.0.0

func (m *MockKeyValue) EmitUint64(key string, value uint64)

EmitUint64 belongs to the log.Encoder interface

type MockLogRecord added in v1.0.0

type MockLogRecord struct {
	Timestamp time.Time
	Fields    []MockKeyValue
}

MockLogRecord represents data logged to a Span via Span.LogFields or Span.LogKV.

type MockSpan

type MockSpan struct {
	sync.RWMutex

	ParentID int

	OperationName string
	StartTime     time.Time
	FinishTime    time.Time

	// All of the below are protected by the embedded RWMutex.
	SpanContext MockSpanContext
	// contains filtered or unexported fields
}

MockSpan is an opentracing.Span implementation that exports its internal state for testing purposes.

func (*MockSpan) BaggageItem

func (s *MockSpan) BaggageItem(key string) string

BaggageItem belongs to the Span interface

func (*MockSpan) Context

func (s *MockSpan) Context() opentracing.SpanContext

Context belongs to the Span interface

func (*MockSpan) Finish

func (s *MockSpan) Finish()

Finish belongs to the Span interface

func (*MockSpan) FinishWithOptions

func (s *MockSpan) FinishWithOptions(opts opentracing.FinishOptions)

FinishWithOptions belongs to the Span interface

func (*MockSpan) Log

func (s *MockSpan) Log(data opentracing.LogData)

Log belongs to the Span interface

func (*MockSpan) LogEvent

func (s *MockSpan) LogEvent(event string)

LogEvent belongs to the Span interface

func (*MockSpan) LogEventWithPayload

func (s *MockSpan) LogEventWithPayload(event string, payload interface{})

LogEventWithPayload belongs to the Span interface

func (*MockSpan) LogFields added in v1.0.0

func (s *MockSpan) LogFields(fields ...log.Field)

LogFields belongs to the Span interface

func (*MockSpan) LogKV added in v1.0.0

func (s *MockSpan) LogKV(keyValues ...interface{})

LogKV belongs to the Span interface.

This implementations coerces all "values" to strings, though that is not something all implementations need to do. Indeed, a motivated person can and probably should have this do a typed switch on the values.

func (*MockSpan) Logs

func (s *MockSpan) Logs() []MockLogRecord

Logs returns a copy of logs accumulated in the span so far

func (*MockSpan) SetBaggageItem

func (s *MockSpan) SetBaggageItem(key, val string) opentracing.Span

SetBaggageItem belongs to the Span interface

func (*MockSpan) SetOperationName

func (s *MockSpan) SetOperationName(operationName string) opentracing.Span

SetOperationName belongs to the Span interface

func (*MockSpan) SetTag

func (s *MockSpan) SetTag(key string, value interface{}) opentracing.Span

SetTag belongs to the Span interface

func (*MockSpan) String

func (s *MockSpan) String() string

String allows printing span for debugging

func (*MockSpan) Tag

func (s *MockSpan) Tag(k string) interface{}

Tag returns a single tag

func (*MockSpan) Tags

func (s *MockSpan) Tags() map[string]interface{}

Tags returns a copy of tags accumulated by the span so far

func (*MockSpan) Tracer

func (s *MockSpan) Tracer() opentracing.Tracer

Tracer belongs to the Span interface

type MockSpanContext

type MockSpanContext struct {
	TraceID int
	SpanID  int
	Sampled bool
	Baggage map[string]string
}

MockSpanContext is an opentracing.SpanContext implementation.

It is entirely unsuitable for production use, but appropriate for tests that want to verify tracing behavior in other frameworks/applications.

By default all spans have Sampled=true flag, unless {"sampling.priority": 0} tag is set.

func (MockSpanContext) ForeachBaggageItem

func (c MockSpanContext) ForeachBaggageItem(handler func(k, v string) bool)

ForeachBaggageItem belongs to the SpanContext interface

func (MockSpanContext) WithBaggageItem

func (c MockSpanContext) WithBaggageItem(key, value string) MockSpanContext

WithBaggageItem creates a new context with an extra baggage item.

type MockTracer

type MockTracer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

MockTracer is only intended for testing OpenTracing instrumentation.

It is entirely unsuitable for production use, but appropriate for tests that want to verify tracing behavior in other frameworks/applications.

func New

func New() *MockTracer

New returns a MockTracer opentracing.Tracer implementation that's intended to facilitate tests of OpenTracing instrumentation.

func (*MockTracer) Extract

func (t *MockTracer) Extract(format interface{}, carrier interface{}) (opentracing.SpanContext, error)

Extract belongs to the Tracer interface.

func (*MockTracer) FinishedSpans

func (t *MockTracer) FinishedSpans() []*MockSpan

FinishedSpans returns all spans that have been Finish()'ed since the MockTracer was constructed or since the last call to its Reset() method.

func (*MockTracer) Inject

func (t *MockTracer) Inject(sm opentracing.SpanContext, format interface{}, carrier interface{}) error

Inject belongs to the Tracer interface.

func (*MockTracer) RegisterExtractor

func (t *MockTracer) RegisterExtractor(format interface{}, extractor Extractor)

RegisterExtractor registers extractor for given format

func (*MockTracer) RegisterInjector

func (t *MockTracer) RegisterInjector(format interface{}, injector Injector)

RegisterInjector registers injector for given format

func (*MockTracer) Reset

func (t *MockTracer) Reset()

Reset clears the internally accumulated finished spans. Note that any extant MockSpans will still append to finishedSpans when they Finish(), even after a call to Reset().

func (*MockTracer) StartSpan

func (t *MockTracer) StartSpan(operationName string, opts ...opentracing.StartSpanOption) opentracing.Span

StartSpan belongs to the Tracer interface.

type TextMapPropagator

type TextMapPropagator struct {
	HTTPHeaders bool
}

TextMapPropagator implements Injector/Extractor for TextMap and HTTPHeaders formats.

func (*TextMapPropagator) Extract

func (t *TextMapPropagator) Extract(carrier interface{}) (MockSpanContext, error)

Extract implements the Extractor interface

func (*TextMapPropagator) Inject

func (t *TextMapPropagator) Inject(spanContext MockSpanContext, carrier interface{}) error

Inject implements the Injector interface

Jump to

Keyboard shortcuts

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