basictracer - ActiveState ActiveGo 1.8
...

Package basictracer

import "github.com/opentracing/basictracer-go"
Overview
Index
Subdirectories

Overview ▾

Variables

Delegator is the format to use for DelegatingCarrier.

var Delegator delegatorType

func New

func New(recorder SpanRecorder) opentracing.Tracer

New creates and returns a standard Tracer which defers completed Spans to `recorder`. Spans created by this Tracer support the ext.SamplingPriority tag: Setting ext.SamplingPriority causes the Span to be Sampled from that point on.

func NewWithOptions

func NewWithOptions(opts Options) opentracing.Tracer

NewWithOptions creates a customized Tracer.

type DelegatingCarrier

DelegatingCarrier is a flexible carrier interface which can be implemented by types which have a means of storing the trace metadata and already know how to serialize themselves (for example, protocol buffers).

type DelegatingCarrier interface {
    SetState(traceID, spanID uint64, sampled bool)
    State() (traceID, spanID uint64, sampled bool)
    SetBaggageItem(key, value string)
    GetBaggage(func(key, value string))
}

type EventBaggage

EventBaggage is received when SetBaggageItem is called.

type EventBaggage struct {
    Key, Value string
}

type EventCreate

EventCreate is emitted when a Span is created.

type EventCreate struct{ OperationName string }

type EventFinish

EventFinish is received when Finish is called.

type EventFinish RawSpan

type EventLog

EventLog is received when Log (or one of its derivatives) is called.

DEPRECATED

type EventLog opentracing.LogData

type EventLogFields

EventLogFields is received when LogFields or LogKV is called.

type EventLogFields opentracing.LogRecord

type EventTag

EventTag is received when SetTag is called.

type EventTag struct {
    Key   string
    Value interface{}
}

type InMemorySpanRecorder

InMemorySpanRecorder is a simple thread-safe implementation of SpanRecorder that stores all reported spans in memory, accessible via reporter.GetSpans(). It is primarily intended for testing purposes.

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

func NewInMemoryRecorder

func NewInMemoryRecorder() *InMemorySpanRecorder

NewInMemoryRecorder creates new InMemorySpanRecorder

func (*InMemorySpanRecorder) GetSampledSpans

func (r *InMemorySpanRecorder) GetSampledSpans() []RawSpan

GetSampledSpans returns a slice of spans accumulated so far which were sampled.

func (*InMemorySpanRecorder) GetSpans

func (r *InMemorySpanRecorder) GetSpans() []RawSpan

GetSpans returns a copy of the array of spans accumulated so far.

func (*InMemorySpanRecorder) RecordSpan

func (r *InMemorySpanRecorder) RecordSpan(span RawSpan)

RecordSpan implements the respective method of SpanRecorder.

func (*InMemorySpanRecorder) Reset

func (r *InMemorySpanRecorder) Reset()

Reset clears the internal array of spans.

type Options

Options allows creating a customized Tracer via NewWithOptions. The object must not be updated when there is an active tracer using it.

type Options struct {
    // ShouldSample is a function which is called when creating a new Span and
    // determines whether that Span is sampled. The randomized TraceID is supplied
    // to allow deterministic sampling decisions to be made across different nodes.
    // For example,
    //
    //   func(traceID uint64) { return traceID % 64 == 0 }
    //
    // samples every 64th trace on average.
    ShouldSample func(traceID uint64) bool
    // TrimUnsampledSpans turns potentially expensive operations on unsampled
    // Spans into no-ops. More precisely, tags and log events are silently
    // discarded. If NewSpanEventListener is set, the callbacks will still fire.
    TrimUnsampledSpans bool
    // Recorder receives Spans which have been finished.
    Recorder SpanRecorder
    // NewSpanEventListener can be used to enhance the tracer by effectively
    // attaching external code to trace events. See NetTraceIntegrator for a
    // practical example, and event.go for the list of possible events.
    NewSpanEventListener func() func(SpanEvent)
    // DropAllLogs turns log events on all Spans into no-ops.
    // If NewSpanEventListener is set, the callbacks will still fire.
    DropAllLogs bool
    // MaxLogsPerSpan limits the number of Logs in a span (if set to a nonzero
    // value). If a span has more logs than this value, logs are dropped as
    // necessary (and replaced with a log describing how many were dropped).
    //
    // About half of the MaxLogPerSpan logs kept are the oldest logs, and about
    // half are the newest logs.
    //
    // If NewSpanEventListener is set, the callbacks will still fire for all log
    // events. This value is ignored if DropAllLogs is true.
    MaxLogsPerSpan int
    // DebugAssertSingleGoroutine internally records the ID of the goroutine
    // creating each Span and verifies that no operation is carried out on
    // it on a different goroutine.
    // Provided strictly for development purposes.
    // Passing Spans between goroutine without proper synchronization often
    // results in use-after-Finish() errors. For a simple example, consider the
    // following pseudocode:
    //
    //  func (s *Server) Handle(req http.Request) error {
    //    sp := s.StartSpan("server")
    //    defer sp.Finish()
    //    wait := s.queueProcessing(opentracing.ContextWithSpan(context.Background(), sp), req)
    //    select {
    //    case resp := <-wait:
    //      return resp.Error
    //    case <-time.After(10*time.Second):
    //      sp.LogEvent("timed out waiting for processing")
    //      return ErrTimedOut
    //    }
    //  }
    //
    // This looks reasonable at first, but a request which spends more than ten
    // seconds in the queue is abandoned by the main goroutine and its trace
    // finished, leading to use-after-finish when the request is finally
    // processed. Note also that even joining on to a finished Span via
    // StartSpanWithOptions constitutes an illegal operation.
    //
    // Code bases which do not require (or decide they do not want) Spans to
    // be passed across goroutine boundaries can run with this flag enabled in
    // tests to increase their chances of spotting wrong-doers.
    DebugAssertSingleGoroutine bool
    // DebugAssertUseAfterFinish is provided strictly for development purposes.
    // When set, it attempts to exacerbate issues emanating from use of Spans
    // after calling Finish by running additional assertions.
    DebugAssertUseAfterFinish bool
    // EnableSpanPool enables the use of a pool, so that the tracer reuses spans
    // after Finish has been called on it. Adds a slight performance gain as it
    // reduces allocations. However, if you have any use-after-finish race
    // conditions the code may panic.
    EnableSpanPool bool
}

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns an Options object with a 1 in 64 sampling rate and all options disabled. A Recorder needs to be set manually before using the returned object with a Tracer.

type RawSpan

RawSpan encapsulates all state associated with a (finished) Span.

type RawSpan struct {
    // Those recording the RawSpan should also record the contents of its
    // SpanContext.
    Context SpanContext

    // The SpanID of this SpanContext's first intra-trace reference (i.e.,
    // "parent"), or 0 if there is no parent.
    ParentSpanID uint64

    // The name of the "operation" this span is an instance of. (Called a "span
    // name" in some implementations)
    Operation string

    // We store <start, duration> rather than <start, end> so that only
    // one of the timestamps has global clock uncertainty issues.
    Start    time.Time
    Duration time.Duration

    // Essentially an extension mechanism. Can be used for many purposes,
    // not to be enumerated here.
    Tags opentracing.Tags

    // The span's "microlog".
    Logs []opentracing.LogRecord
}

type Span

Span provides access to the essential details of the span, for use by basictracer consumers. These methods may only be called prior to (*opentracing.Span).Finish().

type Span interface {
    opentracing.Span

    // Operation names the work done by this span instance
    Operation() string

    // Start indicates when the span began
    Start() time.Time
}

type SpanContext

SpanContext holds the basic Span metadata.

type SpanContext struct {
    // A probabilistically unique identifier for a [multi-span] trace.
    TraceID uint64

    // A probabilistically unique identifier for a span.
    SpanID uint64

    // Whether the trace is sampled.
    Sampled bool

    // The span's associated baggage.
    Baggage map[string]string // initialized on first use
}

func (SpanContext) ForeachBaggageItem

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

ForeachBaggageItem belongs to the opentracing.SpanContext interface

func (SpanContext) WithBaggageItem

func (c SpanContext) WithBaggageItem(key, val string) SpanContext

WithBaggageItem returns an entirely new basictracer SpanContext with the given key:value baggage pair set.

type SpanEvent

A SpanEvent is emitted when a mutating command is called on a Span.

type SpanEvent interface{}

type SpanRecorder

A SpanRecorder handles all of the `RawSpan` data generated via an associated `Tracer` (see `NewStandardTracer`) instance. It also names the containing process and provides access to a straightforward tag map.

type SpanRecorder interface {
    // Implementations must determine whether and where to store `span`.
    RecordSpan(span RawSpan)
}

type Tracer

Tracer extends the opentracing.Tracer interface with methods to probe implementation state, for use by basictracer consumers.

type Tracer interface {
    opentracing.Tracer

    // Options gets the Options used in New() or NewWithOptions().
    Options() Options
}

Subdirectories

Name Synopsis
..
events
examples
dapperish
wire Package wire is a generated protocol buffer package.