propagators

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package propagators contains interface definition for BinaryFormat and TextFormat propagators and implementation of propagators for different format and suppliers.

Index

Constants

View Source
const (
	B3SingleHeader       = "X-B3"
	B3DebugFlagHeader    = "X-B3-Flags"
	B3TraceIDHeader      = "X-B3-TraceId"
	B3SpanIDHeader       = "X-B3-SpanId"
	B3SampledHeader      = "X-B3-Sampled"
	B3ParentSpanIDHeader = "X-B3-ParentSpanId"
)
View Source
const (
	TraceparentHeader        = "Traceparent"
	CorrelationContextHeader = "Correlation-Context"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type B3

type B3 struct {
	SingleHeader bool
}

B3 propagator serializes core.SpanContext to/from B3 Headers. This propagator supports both version of B3 headers,

  1. Single Header : X-B3: {TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
  2. Multiple Headers: X-B3-TraceId: {TraceId} X-B3-ParentSpanId: {ParentSpanId} X-B3-SpanId: {SpanId} X-B3-Sampled: {SamplingState} X-B3-Flags: {DebugFlag}

If SingleHeader is set to true then X-B3 header is used to inject and extract. Otherwise, separate headers are used to inject and extract.

func (B3) Extract

func (b3 B3) Extract(ctx context.Context, supplier Supplier) (core.SpanContext, dctx.Map)

Extract retrieves B3 Headers from the supplier

func (B3) GetAllKeys

func (b3 B3) GetAllKeys() []string

func (B3) Inject

func (b3 B3) Inject(ctx context.Context, supplier Supplier)

type BinaryFormat

type BinaryFormat interface {
	// ToBytes serializes span context into a byte array and returns the array.
	ToBytes(sc core.SpanContext) []byte

	// FromBytes de-serializes byte array into span context and returns the span context.
	FromBytes([]byte) core.SpanContext
}

BinaryFormat is an interface that specifies methods to convert SpanContext to/from byte array.

func Binary

func Binary() BinaryFormat

Binary creates a new propagator. The propagator implements ToBytes and FromBytes method to transform SpanContext to/from byte array.

type NoopTextFormat

type NoopTextFormat struct{}

NoopTextFormat implements TextFormat that does nothing.

func (NoopTextFormat) Extract

func (np NoopTextFormat) Extract(ctx context.Context, supplier Supplier) (core.SpanContext, dctx.Map)

Extract does nothing and returns an empty SpanContext

func (NoopTextFormat) GetAllKeys

func (np NoopTextFormat) GetAllKeys() []string

GetAllKeys returns empty list of strings.

func (NoopTextFormat) Inject

func (np NoopTextFormat) Inject(ctx context.Context, supplier Supplier)

Inject does nothing.

type Supplier

type Supplier interface {
	Get(key string) string
	Set(key string, value string)
}

Supplier is an interface that specifies methods to retrieve and store value for a key to an associated carrier. Get method retrieves the value for a given key. Set method stores the value for a given key.

type TextFormat

type TextFormat interface {
	// Inject method retrieves current SpanContext from the ctx, encodes it into propagator
	// specific format and then injects the encoded SpanContext using supplier into a carrier
	// associated with the supplier. It also takes a correlationCtx whose values will be
	// injected into a carrier using the supplier.
	Inject(ctx context.Context, supplier Supplier)

	// Extract method retrieves encoded SpanContext using supplier from the associated carrier.
	// It decodes the SpanContext and returns it and a dctx of correlated context.
	// If no SpanContext was retrieved OR if the retrieved SpanContext is invalid then
	// an empty SpanContext is returned.
	Extract(ctx context.Context, supplier Supplier) (core.SpanContext, dctx.Map)

	// GetAllKeys returns all the keys that this propagator injects/extracts into/from a
	// carrier. The use cases for this are
	// * allow pre-allocation of fields, especially in systems like gRPC Metadata
	// * allow a single-pass over an iterator (ex OpenTracing has no getter in TextMap)
	GetAllKeys() []string
}

TextFormat is an interface that specifies methods to inject and extract SpanContext and distributed context into/from a carrier using Supplier interface. For example, HTTP Trace Context propagator would encode SpanContext into W3C Trace Context Header and set the header into HttpRequest.

type TraceContext

type TraceContext struct{}

TraceContext propagates SpanContext in W3C TraceContext format.

func (TraceContext) Extract

func (hp TraceContext) Extract(
	ctx context.Context, supplier Supplier,
) (core.SpanContext, dctx.Map)

func (TraceContext) GetAllKeys

func (hp TraceContext) GetAllKeys() []string

func (TraceContext) Inject

func (hp TraceContext) Inject(ctx context.Context, supplier Supplier)

Jump to

Keyboard shortcuts

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