Fix handling of baggage when retrieving current span #8567
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Resolves #8548
OpenTelemetry separates baggage from spans and stores them separately in the OTel context. In contrast, the Helidon tracing API treats baggage as a characteristic of a span.
Earlier PRs fixed a problem in which Helidon failed to store the baggage associated with a span correctly in the OTel context. This PR fixes a problem in reconstituting the correct current span from what is in the OTel context, making sure the new reconstituted span draws from both the OTel span in the context and the OTel baggage in the context.
The central fix is in
OpenTelemetryTracerProvider
and itscurrentSpan
method (which now delegates toactiveSpan
so the Jaeger code can also use it). TheSpan
constructed forcurrentSpan
/activeSpan
now holds a reference to the OTelBaggage
instance from the OtelContext
.Normally, that baggage will be our writeable baggage implementation of OTel's
Baggage
interface. That implementation allows the HelidonSpan
wrapper around the OTel span to permit updates to its baggage. By storing a reference to that baggage in the reconstituted span, changes to the baggage via the baggage methods on the reconstitutedSpan
will write through to the baggage that is stored in the context.But, it's possible that immutable Otel baggage might be in the OTel context when the current span is reconstructed. The Helidon
OpenTelemetrySpan
method for updating baggage therefore must now check to see if its baggage is writeable or not and act accordingly.The PR also contains new tests for OTel and Jaeger (which relies on the OTel implementation internally).
Documentation
Bug fix; no doc changes.