Documentation ¶
Overview ¶
Package tracing provides wrappers around opentracing's golang library to make them easier to use in Istio.
Index ¶
- func CurrentSpan(ctx context.Context) ot.Span
- func IORecorder(w io.Writer) bt.SpanRecorder
- func LoggingRecorder() bt.SpanRecorder
- func NewContext(ctx context.Context, carrier *AttributeCarrier) context.Context
- func RootSpan(ctx context.Context) ot.Span
- type AttributeCarrier
- type Tracer
- func (t *Tracer) PropagateSpan(ctx context.Context, span ot.Span) (metadata.MD, context.Context)
- func (t *Tracer) StartRootSpan(ctx context.Context, operationName string, opts ...ot.StartSpanOption) (ot.Span, context.Context)
- func (t *Tracer) StartSpanFromContext(ctx context.Context, operationName string, opts ...ot.StartSpanOption) (ot.Span, context.Context)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CurrentSpan ¶
CurrentSpan extracts the current span from the context, or returns a no-op span if no span exists in the context. This avoids boilerplate nil checking when calling opentracing.SpanFromContext.
func IORecorder ¶
func IORecorder(w io.Writer) bt.SpanRecorder
IORecorder returns a SpanRecorder which writes its spans to the provided io.Writer.
func LoggingRecorder ¶
func LoggingRecorder() bt.SpanRecorder
LoggingRecorder returns a SpanRecorder which logs writes its spans to glog.
func NewContext ¶
func NewContext(ctx context.Context, carrier *AttributeCarrier) context.Context
NewContext annotates the provided context with the provided carrier and returns the updated context.
Types ¶
type AttributeCarrier ¶
type AttributeCarrier struct {
// contains filtered or unexported fields
}
AttributeCarrier implements opentracing's TextMapWriter and TextMapReader interfaces using Istio's attribute system.
func FromContext ¶
func FromContext(ctx context.Context) *AttributeCarrier
FromContext extracts the AttributeCarrier from the provided context, or returns nil if one is not found.
func NewCarrier ¶
func NewCarrier(bag *attribute.MutableBag) *AttributeCarrier
NewCarrier initializes a carrier that can be used to modify the attributes in the current request context.
func (*AttributeCarrier) ForeachKey ¶
func (c *AttributeCarrier) ForeachKey(handler func(key, val string) error) error
ForeachKey iterates over the keys that correspond to string attributes, filtering keys for the prefix used by the AttributeCarrier to denote opentracing attributes. The AttributeCarrier specific prefix is stripped from the key before its passed to handler.
func (*AttributeCarrier) Set ¶
func (c *AttributeCarrier) Set(key, val string)
Set adds (key, val) to the set of string attributes in the request scope. It prefixes the key with an istio-private string to avoid collisions with other attributes when arbitrary tracer implementations are used.
type Tracer ¶
Tracer wraps an opentracing.Tracer with a flag that's enabled when tracing is enabled. This flag is used to short-circuit methods that may be costly (intercepting client calls, propagating span metadata, etc). The tracer's methods will always return objects that are safe to work with, e.g. if tracing is disabled and StartRootSpan is called, a no-op span will be returned, not nil.
func DisabledTracer ¶
func DisabledTracer() Tracer
DisabledTracer disables tracing, letting methods in tracing.go short-circuit.
func (*Tracer) PropagateSpan ¶
PropagateSpan inserts metadata about the span into the context's metadata so that the span is propagated to the receiver. This should be used to prepare the context for outgoing calls.
func (*Tracer) StartRootSpan ¶
func (t *Tracer) StartRootSpan(ctx context.Context, operationName string, opts ...ot.StartSpanOption) (ot.Span, context.Context)
StartRootSpan creates a span that is the root of all Istio spans in the current request context. This span will be a child of any spans propagated to the server in the request's metadata. The returned span is retrievable from the context via tracing.RootSpan.
func (*Tracer) StartSpanFromContext ¶
func (t *Tracer) StartSpanFromContext(ctx context.Context, operationName string, opts ...ot.StartSpanOption) (ot.Span, context.Context)
StartSpanFromContext starts a new span and propagates it in ctx. If there exists a span in ctx it will be the parent of the returned span.
We provide this method, which should be used instead of opentracing.StartSpanFromContext because opentracing's version always uses the global tracer, while we use the opentracing.Tracer stored in t.