4e94f405ab
As discussed in a previous SIG meeting, this PR adds support for setting a default value for [`service.instance.id`](https://github.com/open-telemetry/semantic-conventions/tree/main/docs/resource#service-experimental) according to semantic conventions: > Implementations, such as SDKs, are recommended to generate a random Version 1 or Version 4 [RFC 4122](https://www.ietf.org/rfc/rfc4122.txt) UUID, but are free to use an inherent unique ID as the source of this value if stability is desirable. In that case, the ID SHOULD be used as source of a UUID Version 5 and SHOULD use the following UUID as the namespace: `4d63009a-8d0f-11ee-aad7-4c796ed8e320`. This PR follows the recommendation and populates `service.instance.id` with a random Version 4 UUID. The functionality is guarded by the `OTEL_GO_X_RESOURCE` feature flag environment variable. There are plans to declare `service.instance.id` stable and also make it a required attribute (similar to `service.name`). Once this happens, the functionality can be made available regardless of whether `OTEL_GO_X_RESOURCE` is set. Closes https://github.com/open-telemetry/opentelemetry-go-contrib/issues/5423 --------- Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> Co-authored-by: Tyler Yahn <codingalias@gmail.com> |
||
---|---|---|
.. | ||
handler | ||
go.mod | ||
go.sum | ||
main.go | ||
README.md |
"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---|