-
Notifications
You must be signed in to change notification settings - Fork 1k
[Spring Starter] Spring boot 4 support #15459
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
base: main
Are you sure you want to change the base?
[Spring Starter] Spring boot 4 support #15459
Conversation
0949e97 to
330cd89
Compare
|
Would that resolve the missing metrics going to mimir on spring boot 4 setup using the java agent @jaydeluca ? |
|
@George-C-Odes there is no ETA, im working on this as I can. |
|
my goal is to get this all completed before the next release 🤞. This is just the spring boot starter, there are still other javaagent instrumentations that need to be fixed too |
…entelemetry-java-instrumentation into spring-boot-4-autoconfigure
zeitlinger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great to see that the code size is getting smaller now 😄
| @ConditionalOnBean({DataSource.class}) | ||
| @ConditionalOnMissingClass( | ||
| "org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration") // Spring Boot 4+ | ||
| @ConditionalOnClass(DataSourceAutoConfiguration.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment back? e.g. "removed in Spring Boot 4"
...utoconfigure/internal/instrumentation/mongo/MongoClientInstrumentationAutoConfiguration.java
Outdated
Show resolved
Hide resolved
| @Configuration(proxyBeanMethods = false) | ||
| @ConditionalOnMissingClass( | ||
| "org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration") // Spring Boot 2 & 3 | ||
| @ConditionalOnClass(DataSourceAutoConfiguration.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
condition looks identical to boot 3
| DefaultKafkaProducerFactoryCustomizer.class | ||
| }) | ||
| @ConditionalOnMissingBean(name = "otelKafkaProducerFactoryCustomizer") | ||
| @ConditionalOnMissingClass( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not needed anymore?
...e/internal/instrumentation/mongo/MongoClientInstrumentationSpringBoot4AutoConfiguration.java
Outdated
Show resolved
Hide resolved
| @Autowired private RestTemplateBuilder restTemplateBuilder; | ||
| @Autowired private JdbcTemplate jdbcTemplate; | ||
|
|
||
| abstract void makeClientCall(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
| public JdbcInstrumentationSpringBoot4AutoConfiguration() {} | ||
|
|
||
| @Bean | ||
| // static to avoid "is not eligible for getting processed by all BeanPostProcessors" warning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really for this PR but I suspect that (proxyBeanMethods = false) has the same effect as making the method static. If I remember correctly the warning was triggered by proxying the configuration class methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right - that would be a nice follow-up PR
| @Bean | ||
| DefaultKafkaProducerFactoryCustomizer otelKafkaProducerFactoryCustomizer( | ||
| OpenTelemetry openTelemetry) { | ||
| KafkaTelemetry kafkaTelemetry = KafkaTelemetry.create(openTelemetry); | ||
| return producerFactory -> producerFactory.addPostProcessor(kafkaTelemetry::wrap); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually only this bean is different for spring boot 4. Wondering whether it would make sense to move this bean into separate (maybe nested?) configuration class so that the other beans wouldn't need to be copy-pasted. Or is that too much effort?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...ng/autoconfigure/internal/instrumentation/jdbc/JdbcInstrumentationAutoConfigurationTest.java
Outdated
Show resolved
Hide resolved
instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts
Outdated
Show resolved
Hide resolved
...ring-boot-4/src/test/java/io/opentelemetry/spring/smoketest/KafkaSpringStarterSmokeTest.java
Outdated
Show resolved
Hide resolved
...pring-boot-4/src/test/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java
Outdated
Show resolved
Hide resolved
| () -> getTelemetry(openTelemetryProvider, configProvider)); | ||
| } | ||
|
|
||
| @ConditionalOnClass(DefaultKafkaProducerFactoryCustomizer.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you also need to add @ConditionalOnEnabledInstrumentation(module = "kafka") here or is it somehow automatically inherited from the outer class?
Imo the way it is now pushing this into a nested configuration class doesn't make sense. If you'd remove DefaultKafkaProducerFactoryCustomizer condition from the outer class and only leave it on the inner class then the outer class could also be used for spring boot 4 and you'd only need to provide a spring boot 4 version of what the inner class does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it somehow automatically inherited from the outer class?
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo the way it is now pushing this into a nested configuration class doesn't make sense
agree - does it work if you inline the bean method?
| @@ -1,2 +1,2 @@ | |||
| Comparing source compatibility of opentelemetry-spring-boot-autoconfigure-2.23.0-SNAPSHOT.jar against opentelemetry-spring-boot-autoconfigure-2.22.0.jar | |||
| Comparing source compatibility of opentelemetry-spring-boot-autoconfigure-2.23.0-SNAPSHOT.jar against | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm still trying to figure this out. the build is failing for this
Run # need to "git add" in case any generated files did not already exist
Diff detected - did you run './gradlew jApiCmp'?
docs/apidiffs/current_vs_latest/opentelemetry-spring-boot-autoconfigure.txt
diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-spring-boot-autoconfigure.txt b/docs/apidiffs/current_vs_latest/opentelemetry-spring-boot-autoconfigure.txt
index 7e15cee7..9dfa3287 100644
--- a/docs/apidiffs/current_vs_latest/opentelemetry-spring-boot-autoconfigure.txt
+++ b/docs/apidiffs/current_vs_latest/opentelemetry-spring-boot-autoconfigure.txt
@@ -1,2 +1,2 @@
-Comparing source compatibility of opentelemetry-spring-boot-autoconfigure-2.23.0-SNAPSHOT.jar against opentelemetry-spring-boot-autoconfigure-2.22.0.jar
+Comparing source compatibility of opentelemetry-spring-boot-autoconfigure-2.23.0-SNAPSHOT.jar against
No changes.
\ No newline at end of file
and when i run ./gradlew :instrumentation:spring:spring-boot-autoconfigure:jApiCmp or ./gradlew jApiCmp I get the same result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you try deleting the file and rebasing against main?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix it for you
| // Spring Boot 2 & 3 | ||
| "org.springframework.boot.autoconfigure.kafka.DefaultKafkaProducerFactoryCustomizer") | ||
| @Configuration | ||
| public class KafkaInstrumentationSpringBoot4AutoConfiguration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this class still needed? Tests pass without it.
| exclude("ch.qos.logback", "logback-classic") | ||
| } | ||
| // testSpring2: configure Spring Boot 3.x dependencies for latest dep testing | ||
| if (name == "testSpring2Implementation") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this does not involve any latest dep checks this will bump the version to latest spring 3 even in regular tests?

Related to #14906
Notes:
I tried to avoid as much duplication as I could, If anyone has suggestions on areas to revisit, I can try again