When running the Spring Boot Application with the OpenTelemetry Java Agent as follows (see also)

java -javaagent:opentelemetry-agent.jar -jar spring-boot-app.jar

the Spring Boot Application must include the following configuration to enable support for Prometheus exemplars when the usual Actuator endpoint is used:

@Configuration
class PrometheusExemplarSamplerConfiguration {
    @Bean
    @ConditionalOnClass(name = "io.opentelemetry.javaagent.shaded.io.opentelemetry.api.trace.Span")
    OpenTelemetryAgentSpanContextSupplier openTelemetryAgentSpanContextSupplier() {
        return new OpenTelemetryAgentSpanContextSupplier();
    }
}

Support for Prometheus exemplars was added in #30472 and this PR essentially makes this above extra configuration unnecessary. Tests are missing (but will be added) once you agree that this is a meaningful addition to Spring Boot's auto-configuration. In particular, I'm not sure if you agree with the way how I detect the Java agent being present, that is by having a hard-coded condition on the (shaded) Opentelemetry API class of the agent.

I appreciate any feedback.

Comment From: neiser

@eddumelendez Thanks for your code improvements. I've squashed them into the existing commit and also removed public from the example above.

Comment From: neiser

Concerning a better detection of the OpenTelemetry agent being present, I only found https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/903 which is somewhat related I think. Let me know if I should ask there with another issue.

Comment From: jonatan-ivanov

Closing for now based on the discussion above: https://github.com/spring-projects/spring-boot/pull/35117#discussion_r1177176025