fix(webflux): register reactor hook in createWebFilter and add filter.#18844
Open
amit306 wants to merge 1 commit into
Open
fix(webflux): register reactor hook in createWebFilter and add filter.#18844amit306 wants to merge 1 commit into
amit306 wants to merge 1 commit into
Conversation
|
|
Contributor
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;
}
Comment on lines
+31
to
+34
| @AfterEach | ||
| void tearDown() { | ||
| ContextPropagationOperator.builder().build().resetOnEachOperator(); | ||
| } |
Comment on lines
+36
to
+37
| @Test | ||
| void addFilterRegisterRectorHookSoContextPropogatesAcrossThreads() throws Exception { |
Comment on lines
+62
to
+63
| @Test | ||
| void createWebFilterRegisterRectorHookSoContextPropogatesAcrossThreads() throws Exception { |
Comment on lines
35
to
39
| /** Returns a {@link WebFilter} that instruments HTTP server requests. */ | ||
| public WebFilter createWebFilter() { | ||
| ContextPropagationOperator.builder().build().registerOnEachOperator(); | ||
| return new TelemetryProducingWebFilter(serverInstrumenter); | ||
| } |
Comment on lines
45
to
47
| 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #17858
createWebFilter()andaddFilter()now always register the Reactorcontext propagation hook. The
AndRegisterReactorHookvariants aredeprecated and delegate to these methods.