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.
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.