diff --git a/instrumentation/spring/spring-boot-autoconfigure-3/README.md b/instrumentation/spring/spring-boot-autoconfigure-3/README.md new file mode 100644 index 000000000000..50b65c80adf9 --- /dev/null +++ b/instrumentation/spring/spring-boot-autoconfigure-3/README.md @@ -0,0 +1,7 @@ +# Why do we need a separate module for Spring Boot 3 auto-configuration? + +`RestClientInstrumentationAutoConfiguration` imports `RestClientCustomizer`, +which is part of Spring Boot 3 (rather than Spring framework). + +If we were to include this in the `spring-boot-autoconfigure` module, we would have to +bump the Spring Boot version to 3, which would break compatibility with Spring Boot 2. diff --git a/instrumentation/spring/spring-boot-autoconfigure-3/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestClientBeanPostProcessor.java b/instrumentation/spring/spring-boot-autoconfigure-3/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestClientBeanPostProcessor.java index 0f6159593663..dc7de4b22189 100644 --- a/instrumentation/spring/spring-boot-autoconfigure-3/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestClientBeanPostProcessor.java +++ b/instrumentation/spring/spring-boot-autoconfigure-3/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestClientBeanPostProcessor.java @@ -22,11 +22,10 @@ public RestClientBeanPostProcessor(ObjectProvider openTelemetryPr @Override public Object postProcessAfterInitialization(Object bean, String beanName) { - if (!(bean instanceof RestClient)) { - return bean; + if (bean instanceof RestClient restClient) { + return addRestClientInterceptorIfNotPresent(restClient, openTelemetryProvider.getObject()); } - return addRestClientInterceptorIfNotPresent( - ((RestClient) bean), openTelemetryProvider.getObject()); + return bean; } private static RestClient addRestClientInterceptorIfNotPresent( diff --git a/instrumentation/spring/spring-boot-autoconfigure-3/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestClientInstrumentationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure-3/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestClientInstrumentationAutoConfiguration.java index 4011b6ddc75e..a1032a4e5d1b 100644 --- a/instrumentation/spring/spring-boot-autoconfigure-3/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestClientInstrumentationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure-3/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/RestClientInstrumentationAutoConfiguration.java @@ -8,7 +8,6 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.SdkEnabled; import io.opentelemetry.instrumentation.spring.web.v3_1.SpringWebTelemetry; -import io.opentelemetry.testing.internal.armeria.client.RestClient; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -19,6 +18,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestClient; /** * Configures {@link RestClient} for tracing. @@ -33,8 +33,6 @@ @Configuration public class RestClientInstrumentationAutoConfiguration { - public RestClientInstrumentationAutoConfiguration() {} - @Bean static RestClientBeanPostProcessor otelRestClientBeanPostProcessor( ObjectProvider openTelemetryProvider) {