Allow developer to choose whether Helidon injects OTel types which notify span listeners #9610
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 #9079
Release Note
As part of Helidon's support for MP Telemetry developers have been able to inject the OpenTelemetry
Tracer
andSpan
types into their code. But these types do not support Helidon-specific span listeners (which are notified when spans start and end or scopes are activated and closed).This PR allows users to assign the config setting
telemetry.injection-type
tonative
orneutral
:native
- the default and the prior behavior - Helidon injects native OTelTracer
andSpan
objects - span listeners are not notified of state changes related to injected objectsneutral
- Helidon injects wrappers around the native OTel types which delegate to the underlying OTel object but also notify any registeredSpanListener
objects (which receive parameters that are the Helidon neutral types:Tracer
,Span.Builder
,Span
,Scope
).Developers need to opt into the new behavior because pre-existing applications might use
instanceof
or similar type-sensitive constructs on injected values referring to OTel implementation types. If Helidon were to change now to always inject wrapped objects in order to notify span listeners then those constructs would no longer work as before.Alternative not adopted: always inject the neutral wrapping objects
We could have just changed Helidon so it always inject the neutral wrapping objects, avoiding the addition of the config setting and the parallel producers.
Some people advocated for that, pointing out that developers should probably not be injecting objects (which could be proxies) and then query their types.
But we know that some existing user code checks OTel
Span
objects to see if they areReadableSpan
and then casts them to use theReadableSpan
API. AFAIK these use cases do not currently do so with injected spans but, if they do or if they tried to, such code would break if Helidon started injecting only the wrapping objects.That's why this PR added the config setting, maintains the current behavior by default, and gives the user control (and responsibility).
Highlights of the changes
The main point is offer a choice for whether Helidon should inject the native OTel
Span
andTracer
objects as before or to inject Helidon-written wrappers around those OTel types, wrappers which notify registered span listeners of state changes and also delegate to the native OTel objects.io.helidon.tracing.Wrapper
interface which declares theunwrap
method. Theneutral
injected objects implementWrapper
so developers, if needed, can cast injected objects toWrapper
and then unwrap them to get to the underlying OTel objects.injection-type
setting. We do not have pre-existing telemetry-based configuration that is Helidon-specific. (There areotel.*
settings which Helidon supports in compliance with the MP Telemetry spec but the new setting is Helidon-specific and not related to OTel so should not be under theotel
section.)Tracer
orSpan
etc. wrapper around the native OTel object. Most methods in the wrapper classes simply delegate to the native OTel object. The exception: any method that causes changes of state (which the span listeners observe)--such as starting or ending a span or activating or closing a scope--invoke the Helidon wrapper which does the notification and delegates to the OTel object.Documentation
PR includes doc updates.