4.1.5: Fully initialize OpenTelemetry items during start-up #9553
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.
Backport #9489 to Helidon 4.1.5
Description
Resolves #9488
The
helidon-microprofile-telemetry
component includes CDI producer methods for OpenTelemetry tracing types and the Helidon tracing counterparts backed by our OTel implementation.Helidon provides these producer methods on an app-scoped bean. This works fine in a pure CDI world; the first time CDI needs to produce a tracer (for example), it prepares the
OpenTelemetryProducer
app-scoped bean which contains the producer methods. Part of that bean's post-construct code assigns the newly-created OTel tracer as the Helidon global tracer and subsequent retrievals of the global tracer return the correct, fully-featured tracer.A problem can arise if user code accesses the global tracer before CDI has had to prepare the producer. In that case the code that accesses the global tracer triggers the creation of the default, no-op OTel tracer and assigns that to the global tracer.
This PR adds an observer method to the existing Helidon OTel telemetry CDI extension which forces CDI to create the producer bean during start-up. This ensures that the global tracer is set correctly before any user code gains control and potentially accesses the global tracer.
The PR also includes a test which reproduced the problem and ensures that the global tracer is set correctly as part of start-up, before user code gains control.
Documentation
No impact.