package propagators
import "go.opentelemetry.io/otel/propagators"
Package propagators contains OpenTelemetry context propagators.
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/).
Index ¶
Examples ¶
Functions ¶
func DefaultHTTPPropagator ¶
func DefaultHTTPPropagator() propagation.HTTPPropagator
DefaultHTTPPropagator returns the default OpenTelemetry HTTP propagator, the W3C Trace Context propagator.
Types ¶
type TraceContext ¶
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.
Code:play
Example¶
package main
import (
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/propagators"
)
func main() {
tc := propagators.TraceContext{}
// Register the TraceContext propagator globally.
global.SetPropagators(propagation.New(
propagation.WithExtractors(tc),
propagation.WithInjectors(tc),
))
}
func (TraceContext) Extract ¶
func (tc TraceContext) Extract(ctx context.Context, supplier propagation.HTTPSupplier) context.Context
Extract extracts a context from the supplier if it contains W3C Trace Context headers.
func (TraceContext) GetAllKeys ¶
func (tc TraceContext) GetAllKeys() []string
GetAllKeys returns the HTTP header names this propagator will use when injecting.
func (TraceContext) Inject ¶
func (tc TraceContext) Inject(ctx context.Context, supplier propagation.HTTPSupplier)
Inject injects a context into the supplier as W3C Trace Context HTTP headers.
Source Files ¶
doc.go propagators.go trace_context.go
- Version
- v0.12.0
- Published
- Sep 24, 2020
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 1 hour ago –
Tools for package owners.