4.x Allow users to direct Helidon to use an existing global OpenTelemetry
instance rather than create its own
#9205
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 #9204
This PR adds the ability of Helidon MP users to indicate that some code other than Helidon will create the global OpenTelemetry instance and Helidon MP should simply use that instance rather than trying to create it.
This PR affects the public API of Helidon in these ways:
io.helidon.telemetry.otel.use-existing-instance
indicating whether Helidon MP should use the global instance of OTel which some other code has already created. Defaults tofalse
so Helidon MP creates the global OTel instance itself.HelidonOpenTelemetry.AgentDetector
has a new public methoduseExistingGlobalOpenTelemetry
. This method combines the results of the existingisAgentPresent
method with a check of the new config setting. IfisAgentPresent
returnstrue
then this new method returns true regardless of the config setting. Otherwise the method essentially returns the config setting (which, as mentioned above, defaults tofalse
).OpenTelemetryProducer
now invokes the newAgentDetector#useExistingGlobalOpenTelemetry
method (instead ofisAgentPresent
as it used to) to decide whether to create a new global OTel instance or use whatever existing one is present.If
otel.agent.present
istrue
andio.helidon.telemetry.otel.use-existing-instance
isfalse
the agent setting takes precedence and Helidon uses the global OTel instance which the agent provided.The PR also includes some new tests.
Documentation
There is no doc impact currently but, at some point, we need to add documentation for the OpenTelemetry tracing provider and this enhancement would be discussed there.