Skip to content

Simplify back-channel between spring-boot starter and spring library modules#18291

Merged
trask merged 6 commits into
open-telemetry:mainfrom
trask:initializer
May 11, 2026
Merged

Simplify back-channel between spring-boot starter and spring library modules#18291
trask merged 6 commits into
open-telemetry:mainfrom
trask:initializer

Conversation

@trask
Copy link
Copy Markdown
Member

@trask trask commented Apr 25, 2026

Main motivation was to make the initialization order easier to reason about and more guaranteed. Also, this follow the pattern used in Experimental classes.

@otelbot-java-instrumentation otelbot-java-instrumentation Bot added the test native This label can be applied to PRs to trigger them to run native tests label Apr 25, 2026
@trask trask force-pushed the initializer branch 2 times, most recently from 47eb959 to c1030eb Compare April 26, 2026 01:20
@trask trask marked this pull request as ready for review April 26, 2026 01:20
@trask trask requested a review from a team as a code owner April 26, 2026 01:20
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added requireNonNull() to make it clearer

trask added 2 commits April 29, 2026 10:09
# 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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-owned apply*CommonConfig(...) back-channel helpers for Spring WebMVC/WebFlux/Spring Web builders.
  • Remove InstrumentationConfigUtil and update Spring Boot autoconfiguration to use the new helpers and DbConfig directly 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.

@trask trask merged commit 78f146a into open-telemetry:main May 11, 2026
99 checks passed
@trask trask deleted the initializer branch May 11, 2026 14:52
trask added a commit to trask/opentelemetry-java-instrumentation that referenced this pull request May 12, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test native This label can be applied to PRs to trigger them to run native tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants