Skip to content

Allow reusing registered global OpenTelemetry #46230

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

Closed
wants to merge 1 commit into from

Conversation

quaff
Copy link
Contributor

@quaff quaff commented Jun 30, 2025

Spring Boot instrumentation will be included when applications are running with OpenTelemetry Java Agent.

* @since 3.2.0
*/
@AutoConfiguration
@ConditionalOnClass(OpenTelemetrySdk.class)
@EnableConfigurationProperties(OpenTelemetryProperties.class)
public class OpenTelemetryAutoConfiguration {

@Bean
@ConditionalOnMissingBean(OpenTelemetry.class)
@Conditional(OnRegisteredGlobalOpenTelemetryCondition.class)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure reuse it by default or a boolean configuration property should be introduced.

@bclozel
Copy link
Member

bclozel commented Jul 1, 2025

I don't think this is a sane goal. It is already complicated for Spring Boot users to figure out the available options.

We have tried to clarify things in #41227 (even if the reverse is not true) but if I understand correctly, this change will cause duplicate metrics and will disrupt OTel Java agent users.

@quaff
Copy link
Contributor Author

quaff commented Jul 2, 2025

this change will cause duplicate metrics and will disrupt OTel Java agent users.

I think it's necessary to introduce a flag to allow users reuse it.

EDIT: I've updated the PR to introduce configuration key management.opentelemetry.reuse-registered-global.

Spring Boot instrumentation will be included when applications are running with OpenTelemetry Java Agent.

Signed-off-by: Yanming Zhou <[email protected]>
@quaff quaff changed the title Reuse registered global OpenTelemetry Allow reusing registered global OpenTelemetry Jul 2, 2025
@wilkinsona
Copy link
Member

Adding a flag doesn't really address Brian's point. We don't want users to be able to opt into having duplicate metrics. I'm going to close this one as the downsides outweigh any potential benefit. If we've misunderstood the implications of the change then please let us know and we can take another look.

@wilkinsona wilkinsona closed this Jul 2, 2025
@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 2, 2025
@quaff
Copy link
Contributor Author

quaff commented Jul 2, 2025

Adding a flag doesn't really address Brian's point. We don't want users to be able to opt into having duplicate metrics. I'm going to close this one as the downsides outweigh any potential benefit. If we've misunderstood the implications of the change then please let us know and we can take another look.

FYI, I'm using OpenTelemetry Java Agent instrument traces only, and didn't configure management.otlp.tracing.endpoint to export spans at Spring Boot side, spans collected by Spring Boot will not be included without this change.
Of course we could reuse global OpenTelemetry in our own applications, but it's good if Spring Boot autoconfigure that, maybe I should add another condition to check OpenTelemetry Java Agent is not used for metrics (OTEL_METRICS_EXPORTER=none)?

@quaff
Copy link
Contributor Author

quaff commented Jul 2, 2025

Another option, we could reuse global registered OpenTelemetry only for Tracer if management.otlp.tracing.endpoint doesn't configured:

@Bean
@ConditionalOnMissingBean
Tracer otelTracer(OpenTelemetry openTelemetry) {
return openTelemetry.getTracer("org.springframework.boot", SpringBootVersion.getVersion());
}

to

	@Bean
	@ConditionalOnMissingBean
	Tracer otelTracer(OpenTelemetry openTelemetry, Optional<OtlpTracingConnectionDetails> otlpTracingConnectionDetails) {
		OpenTelemetry otel = openTelemetry;
		if (GlobalOpenTelemetry.get() != OpenTelemetry.noop() && otlpTracingConnectionDetails.isEmpty()) {
			otel = GlobalOpenTelemetry.get();
		}
		return otel.getTracer("org.springframework.boot", SpringBootVersion.getVersion());
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants