propagation

package
v1.0.0-RC1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: Apache-2.0 Imports: 7 Imported by: 4,205

Documentation

Overview

Package propagation contains OpenTelemetry context propagators.

This package is currently in a Release Candidate phase. Backwards incompatible changes may be introduced prior to v1.0.0, but we believe the current API is ready to stabilize.

OpenTelemetry propagators are used to extract and inject context data from and into messages exchanged by applications. The propagator supported by this package is the W3C Trace Context encoding (https://www.w3.org/TR/trace-context/), and W3C Baggage (https://w3c.github.io/baggage/).

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Baggage added in v0.14.0

type Baggage struct{}

Baggage is a propagator that supports the W3C Baggage format.

This propagates user-defined baggage associated with a trace. The complete specification is defined at https://w3c.github.io/baggage/.

func (Baggage) Extract added in v0.14.0

func (b Baggage) Extract(parent context.Context, carrier TextMapCarrier) context.Context

Extract returns a copy of parent with the baggage from the carrier added.

func (Baggage) Fields added in v0.14.0

func (b Baggage) Fields() []string

Fields returns the keys who's values are set with Inject.

func (Baggage) Inject added in v0.14.0

func (b Baggage) Inject(ctx context.Context, carrier TextMapCarrier)

Inject sets baggage key-values from ctx into the carrier.

type HeaderCarrier added in v0.18.0

type HeaderCarrier http.Header

HeaderCarrier adapts http.Header to satisfy the TextMapCarrier interface.

func (HeaderCarrier) Get added in v0.18.0

func (hc HeaderCarrier) Get(key string) string

Get returns the value associated with the passed key.

func (HeaderCarrier) Keys added in v0.18.0

func (hc HeaderCarrier) Keys() []string

Keys lists the keys stored in this carrier.

func (HeaderCarrier) Set added in v0.18.0

func (hc HeaderCarrier) Set(key string, value string)

Set stores the key-value pair.

type TextMapCarrier added in v0.14.0

type TextMapCarrier interface {

	// Get returns the value associated with the passed key.
	Get(key string) string

	// Set stores the key-value pair.
	Set(key string, value string)

	// Keys lists the keys stored in this carrier.
	Keys() []string
}

TextMapCarrier is the storage medium used by a TextMapPropagator.

type TextMapPropagator added in v0.14.0

type TextMapPropagator interface {

	// Inject set cross-cutting concerns from the Context into the carrier.
	Inject(ctx context.Context, carrier TextMapCarrier)

	// Extract reads cross-cutting concerns from the carrier into a Context.
	Extract(ctx context.Context, carrier TextMapCarrier) context.Context

	// Fields returns the keys who's values are set with Inject.
	Fields() []string
}

TextMapPropagator propagates cross-cutting concerns as key-value text pairs within a carrier that travels in-band across process boundaries.

func NewCompositeTextMapPropagator added in v0.14.0

func NewCompositeTextMapPropagator(p ...TextMapPropagator) TextMapPropagator

NewCompositeTextMapPropagator returns a unified TextMapPropagator from the group of passed TextMapPropagator. This allows different cross-cutting concerns to be propagates in a unified manner.

The returned TextMapPropagator will inject and extract cross-cutting concerns in the order the TextMapPropagators were provided. Additionally, the Fields method will return a de-duplicated slice of the keys that are set with the Inject method.

type TraceContext added in v0.14.0

type TraceContext struct{}

TraceContext is a propagator that supports the W3C Trace Context format (https://www.w3.org/TR/trace-context/)

This propagator will propagate the traceparent and tracestate headers to guarantee traces are not broken. It is up to the users of this propagator to choose if they want to participate in a trace by modifying the traceparent header and relevant parts of the tracestate header containing their proprietary information.

Example
package main

import (
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/propagation"
)

func main() {
	tc := propagation.TraceContext{}
	// Register the TraceContext propagator globally.
	otel.SetTextMapPropagator(tc)
}
Output:

func (TraceContext) Extract added in v0.14.0

func (tc TraceContext) Extract(ctx context.Context, carrier TextMapCarrier) context.Context

Extract reads tracecontext from the carrier into a returned Context.

The returned Context will be a copy of ctx and contain the extracted tracecontext as the remote SpanContext. If the extracted tracecontext is invalid, the passed ctx will be returned directly instead.

func (TraceContext) Fields added in v0.14.0

func (tc TraceContext) Fields() []string

Fields returns the keys who's values are set with Inject.

func (TraceContext) Inject added in v0.14.0

func (tc TraceContext) Inject(ctx context.Context, carrier TextMapCarrier)

Inject set tracecontext from the Context into the carrier.

Jump to

Keyboard shortcuts

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