mocktracer - ActiveState ActiveGo 1.8
...

Package mocktracer

import "github.com/opentracing/opentracing-go/mocktracer"
Overview
Index

Overview ▾

Index ▾

type Extractor
type Injector
type MockKeyValue
    func (m *MockKeyValue) EmitBool(key string, value bool)
    func (m *MockKeyValue) EmitFloat32(key string, value float32)
    func (m *MockKeyValue) EmitFloat64(key string, value float64)
    func (m *MockKeyValue) EmitInt(key string, value int)
    func (m *MockKeyValue) EmitInt32(key string, value int32)
    func (m *MockKeyValue) EmitInt64(key string, value int64)
    func (m *MockKeyValue) EmitLazyLogger(value log.LazyLogger)
    func (m *MockKeyValue) EmitObject(key string, value interface{})
    func (m *MockKeyValue) EmitString(key, value string)
    func (m *MockKeyValue) EmitUint32(key string, value uint32)
    func (m *MockKeyValue) EmitUint64(key string, value uint64)
type MockLogRecord
type MockSpan
    func (s *MockSpan) BaggageItem(key string) string
    func (s *MockSpan) Context() opentracing.SpanContext
    func (s *MockSpan) Finish()
    func (s *MockSpan) FinishWithOptions(opts opentracing.FinishOptions)
    func (s *MockSpan) Log(data opentracing.LogData)
    func (s *MockSpan) LogEvent(event string)
    func (s *MockSpan) LogEventWithPayload(event string, payload interface{})
    func (s *MockSpan) LogFields(fields ...log.Field)
    func (s *MockSpan) LogKV(keyValues ...interface{})
    func (s *MockSpan) Logs() []MockLogRecord
    func (s *MockSpan) SetBaggageItem(key, val string) opentracing.Span
    func (s *MockSpan) SetOperationName(operationName string) opentracing.Span
    func (s *MockSpan) SetTag(key string, value interface{}) opentracing.Span
    func (s *MockSpan) String() string
    func (s *MockSpan) Tag(k string) interface{}
    func (s *MockSpan) Tags() map[string]interface{}
    func (s *MockSpan) Tracer() opentracing.Tracer
type MockSpanContext
    func (c MockSpanContext) ForeachBaggageItem(handler func(k, v string) bool)
    func (c MockSpanContext) WithBaggageItem(key, value string) MockSpanContext
type MockTracer
    func New() *MockTracer
    func (t *MockTracer) Extract(format interface{}, carrier interface{}) (opentracing.SpanContext, error)
    func (t *MockTracer) FinishedSpans() []*MockSpan
    func (t *MockTracer) Inject(sm opentracing.SpanContext, format interface{}, carrier interface{}) error
    func (t *MockTracer) RegisterExtractor(format interface{}, extractor Extractor)
    func (t *MockTracer) RegisterInjector(format interface{}, injector Injector)
    func (t *MockTracer) Reset()
    func (t *MockTracer) StartSpan(operationName string, opts ...opentracing.StartSpanOption) opentracing.Span
type TextMapPropagator
    func (t *TextMapPropagator) Extract(carrier interface{}) (MockSpanContext, error)
    func (t *TextMapPropagator) Inject(spanContext MockSpanContext, carrier interface{}) error

Package files

mocklogrecord.go mockspan.go mocktracer.go propagation.go

type Extractor

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 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)
}

type Injector

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 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
}

type MockKeyValue

MockKeyValue represents a single key:value pair.

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
}

func (*MockKeyValue) EmitBool

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

EmitBool belongs to the log.Encoder interface

func (*MockKeyValue) EmitFloat32

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

EmitFloat32 belongs to the log.Encoder interface

func (*MockKeyValue) EmitFloat64

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

EmitFloat64 belongs to the log.Encoder interface

func (*MockKeyValue) EmitInt

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

EmitInt belongs to the log.Encoder interface

func (*MockKeyValue) EmitInt32

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

EmitInt32 belongs to the log.Encoder interface

func (*MockKeyValue) EmitInt64

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

EmitInt64 belongs to the log.Encoder interface

func (*MockKeyValue) EmitLazyLogger

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

EmitLazyLogger belongs to the log.Encoder interface

func (*MockKeyValue) EmitObject

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

EmitObject belongs to the log.Encoder interface

func (*MockKeyValue) EmitString

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

EmitString belongs to the log.Encoder interface

func (*MockKeyValue) EmitUint32

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

EmitUint32 belongs to the log.Encoder interface

func (*MockKeyValue) EmitUint64

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

EmitUint64 belongs to the log.Encoder interface

type MockLogRecord

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

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

type MockSpan

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

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
}

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

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

LogFields belongs to the Span interface

func (*MockSpan) LogKV

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

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.

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

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

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.

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

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

TextMapPropagator implements Injector/Extractor for TextMap and HTTPHeaders formats.

type TextMapPropagator struct {
    HTTPHeaders bool
}

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