command module
Version: v1.11.1 Latest Latest

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

Go to latest
Published: Oct 19, 2022 License: Apache-2.0 Imports: 11 Imported by: 0


"Passthrough" setup for OpenTelemetry

Some Go programs may wish to propagate context without recording spans. To do this in OpenTelemetry, simply install TextMapPropagators, but do not install a TracerProvider using the SDK. This works because the default TracerProvider implementation returns a "Non-Recording" span that keeps the context of the caller but does not record spans.

For example, when you initialize your global settings, the following will propagate context without recording spans:

// Setup Propagators only
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))

But the following will propagate context and create new, potentially recorded spans:

// Setup SDK
exp, _ := stdout.New(stdout.WithPrettyPrint())
tp = sdktrace.NewTracerProvider(
// Setup Propagators
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))

The Demo

The demo has the following call structure:

Outer -> Passthrough -> Inner

If all components had both an SDK and propagators registered, we would expect the trace to look like:

 |-Passthrough recv-|
  |Passthrough send|

However, in this demo, only the outer and inner have TracerProvider backed by the SDK. All components have Propagators set. In this case, we expect to see:



The Go Gopher

There is no documentation for this package.

Source Files


Path Synopsis

Jump to

Keyboard shortcuts

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