1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-04 09:43:23 +02:00
opentelemetry-go/example/passthrough
Tyler Yahn 8747a29580
Release v1.6.1 (#2746)
* Upgrade stable-v1 to v1.6.1

* Prepare stable-v1 for version v1.6.1

* Update changelog
2022-03-28 09:50:10 -07:00
..
handler chore: adds vanity import check. (#2255) 2021-09-27 22:37:26 -04:00
go.mod Release v1.6.1 (#2746) 2022-03-28 09:50:10 -07:00
go.sum Update versions of dependences (#2710) 2022-03-21 11:05:16 -04:00
main.go Split stdout exporter into stdouttrace and stdoutmetric (#2005) 2021-06-16 11:32:42 -04:00
README.md Refactor exporter creation functions (#1985) 2021-06-10 09:22:47 -07:00

"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(
    sdktrace.WithBatcher(exp),
)
otel.SetTracerProvider(tp)
// 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:

|-------outer---------|
 |-Passthrough recv-|
  |Passthrough send|
    |---inner---|

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:

|-------outer---------|
    |---inner---|