Simplify back-channel between spring-boot starter and spring library modules#18291
Conversation
47eb959 to
c1030eb
Compare
Each *BuilderUtil now exposes applyCommonConfig(builder, openTelemetry)
instead of getBuilderExtractor(). Receiving a *TelemetryBuilder instance
proves its <clinit> ran and registered the extractor, which lets callers
pass through CommonConfig without a public API change. Drop the now-unused
InstrumentationConfigUtil.configure{Server,Client}Builder helpers and
inline DbConfig.isQuerySanitizationEnabled at the four remaining call sites.
| return builder; | ||
| } | ||
|
|
||
| @Initializer |
There was a problem hiding this comment.
The idea is that since static initialization of SpringWebTelemetryBuilder calls setBuilderExtractor it is impossible to create and instance of SpringWebTelemetryBuilder so that the builderExtractor would be null.
There was a problem hiding this comment.
added comments
the reason I prefer this compared to using @Initializer is that there's no enforcement of @Initializer, so it's basically just a suppression mechanism
There was a problem hiding this comment.
I added requireNonNull() to make it clearer
# Conflicts: # instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/WebTelemetryUtil.java # instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java
There was a problem hiding this comment.
Pull request overview
This PR refactors how Spring Boot autoconfigure modules “reach into” Spring library builders to apply shared OpenTelemetry configuration, aiming to make initialization ordering more deterministic and align with patterns used by existing Experimental back-channels.
Changes:
- Replace “extractor getter + shared
InstrumentationConfigUtil” with library-ownedapply*CommonConfig(...)back-channel helpers for Spring WebMVC/WebFlux/Spring Web builders. - Remove
InstrumentationConfigUtiland update Spring Boot autoconfiguration to use the new helpers andDbConfigdirectly for query sanitization settings. - Update build wiring/comments to reflect the removal of shared starter-side config utilities.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/internal/SpringMvcBuilderUtil.java | Introduces builder back-channel helper to apply CommonConfig to the internal server builder. |
| instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/internal/SpringMvcBuilderUtil.java | Same as above for Spring WebMVC 5.3. |
| instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/internal/SpringWebfluxBuilderUtil.java | Adds client/server common-config application helpers and removes extractor getters. |
| instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/internal/WebTelemetryUtil.java | Adds common-config application helper for Spring Web client builder and removes extractor getter. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/javaSpring4/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/web/RestClientBeanPostProcessorSpring4.java | Switches to library-side common-config helper when building the interceptor. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/javaSpring4/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/mongo/MongoClientInstrumentationSpringBoot4AutoConfiguration.java | Uses DbConfig directly for Mongo query sanitization configuration. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/javaSpring3/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webmvc/SpringWebMvc6InstrumentationAutoConfiguration.java | Switches to library-side common-config helper when building the servlet filter. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/javaSpring3/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/web/RestClientBeanPostProcessor.java | Switches to library-side common-config helper when building the interceptor. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/properties/InstrumentationConfigUtil.java | Deleted (previously provided generic builder config + DbConfig delegation). |
| instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webmvc/SpringWebMvc5InstrumentationAutoConfiguration.java | Switches to library-side common-config helper when building the servlet filter. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/webflux/WebClientBeanPostProcessor.java | Switches to library-side common-config helpers when building WebFlux client/server telemetry. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/web/RestTemplateInstrumentation.java | Switches to library-side common-config helper when building the interceptor. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/r2dbc/R2dbcInstrumentingPostProcessor.java | Uses DbConfig directly for R2DBC query sanitization configuration. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/mongo/MongoClientInstrumentationAutoConfiguration.java | Uses DbConfig directly for Mongo query sanitization configuration. |
| instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/jdbc/DataSourcePostProcessor.java | Uses DbConfig directly for JDBC query sanitization configuration. |
| instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts | Updates comment after removing the shared config utility. |
Mark the field @nullable and use requireNonNull at the call site, matching the pattern used in open-telemetry#18291. Add a comment noting that the factory is registered in GrpcTelemetry's static initializer before any GrpcTelemetry instance can be passed here.
Main motivation was to make the initialization order easier to reason about and more guaranteed. Also, this follow the pattern used in
Experimentalclasses.