-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fully initialize OpenTelemetry items during start-up #9489
Conversation
Signed-off-by: Tim Quinn <[email protected]>
@@ -62,4 +68,12 @@ void processAnnotations(@Observes @WithAnnotations(WithSpan.class) ProcessAnnota | |||
} | |||
} | |||
} | |||
|
|||
void finish(@Observes @Priority(Interceptor.Priority.LIBRARY_BEFORE) @Initialized(ApplicationScoped.class) Object startup, | |||
Tracer tracer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have to refresh my memory here but I'm not fully sure whether the mere appearance of a Tracer
client proxy here will cause its underlying target instance to be created. You may have to invoke a business method on it to force proxy "inflation". toString
shouldn't do the trick, but IIRC it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(The relevant section of the specification is probably the one on client proxy invocations, not business methods; sorry about that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting. TRACE-level logging is not turned on during the build (and therefore when the unit test runs) nor would it likely be at runtime, so even toString
is not likely to be invoked.
That said, during the build the new unit test failed before I added that observer method to the extension and passed afterwards.
To be safer I can revise the observer method to invoke enabled
--not inherited from Object
as the spec warns against--on the Tracer
object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right; for posterity, you can call toString
. It is both the only method that has defined semantics for client proxies and fulfills the proxy inflation conditions.
…to ensure the bean is fully created
* Fully initialize OpenTelemetry items during start-up * Invoke method on CDI proxy for tracer from extension observer method to ensure the bean is fully created --------- Signed-off-by: Tim Quinn <[email protected]>
* Fully initialize OpenTelemetry items during start-up * Invoke method on CDI proxy for tracer from extension observer method to ensure the bean is fully created --------- Signed-off-by: Tim Quinn <[email protected]> Co-authored-by: Tim Quinn <[email protected]>
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.