fix(webflux): register reactor hook in createWebFilter and add filter.#18844
fix(webflux): register reactor hook in createWebFilter and add filter.#18844amit306 wants to merge 1 commit into
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR makes Spring WebFlux 5.3 client/server telemetry automatically register Reactor’s context-propagation hook and adds tests to verify OTel context survives a thread switch.
Changes:
- Register
ContextPropagationOperatorinsideSpringWebfluxClientTelemetry.addFilter()andSpringWebfluxServerTelemetry.createWebFilter(). - Make the explicit “...AndRegisterReactorHook” APIs delegate to the now-hook-registering methods.
- Add unit tests asserting span context propagation across
Schedulers.boundedElastic()thread switching.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/test/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/ReactorHookRegistrationTest.java | Adds tests validating context propagation after hook auto-registration. |
| instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetry.java | Auto-registers Reactor hook when creating the server WebFilter. |
| instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetry.java | Auto-registers Reactor hook when adding the client ExchangeFilterFunction. |
Comments suppressed due to low confidence (1)
instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetry.java:50
- This now registers a global Reactor hook even when
addFilter()returns early because the filter is already present. If the intent is to register the hook only when enabling instrumentation via this API, consider moving hook registration after the ‘already instrumented’ check, and/or guarding registration so it only happens once. This avoids repeated global work and reduces surprising side effects when callers invokeaddFilter()defensively.
public void addFilter(List<ExchangeFilterFunction> exchangeFilterFunctions) {
ContextPropagationOperator.builder().build().registerOnEachOperator();
for (ExchangeFilterFunction filterFunction : exchangeFilterFunctions) {
if (filterFunction instanceof WebClientTracingFilter) {
return;
}
| @AfterEach | ||
| void tearDown() { | ||
| ContextPropagationOperator.builder().build().resetOnEachOperator(); | ||
| } |
| @Test | ||
| void addFilterRegisterRectorHookSoContextPropogatesAcrossThreads() throws Exception { |
| @Test | ||
| void createWebFilterRegisterRectorHookSoContextPropogatesAcrossThreads() throws Exception { |
| /** Returns a {@link WebFilter} that instruments HTTP server requests. */ | ||
| public WebFilter createWebFilter() { | ||
| ContextPropagationOperator.builder().build().registerOnEachOperator(); | ||
| return new TelemetryProducingWebFilter(serverInstrumenter); | ||
| } |
| public WebFilter createWebFilterAndRegisterReactorHook() { | ||
| registerReactorHook(); | ||
| return this.createWebFilter(); | ||
| } |
|
|
||
| /** Returns a {@link WebFilter} that instruments HTTP server requests. */ | ||
| public WebFilter createWebFilter() { | ||
| ContextPropagationOperator.builder().build().registerOnEachOperator(); |
2f62a78 to
4c57afb
Compare
singhvibhanshu
left a comment
There was a problem hiding this comment.
LGTM, just a nit:
Suggested change: return webfluxServerTelemetry.createWebFilter();
4c57afb to
5d17641
Compare
@singhvibhanshu , Done, Thanks for catching this |
Fixes #17858
createWebFilter()andaddFilter()now always register the Reactorcontext propagation hook. The
AndRegisterReactorHookvariants aredeprecated and delegate to these methods.