Skip to content

fix(webflux): register reactor hook in createWebFilter and add filter.#18844

Open
amit306 wants to merge 1 commit into
open-telemetry:mainfrom
amit306:fix/webflux-always-register-reactor-hook
Open

fix(webflux): register reactor hook in createWebFilter and add filter.#18844
amit306 wants to merge 1 commit into
open-telemetry:mainfrom
amit306:fix/webflux-always-register-reactor-hook

Conversation

@amit306
Copy link
Copy Markdown

@amit306 amit306 commented May 25, 2026

Fixes #17858

createWebFilter() and addFilter() now always register the Reactor
context propagation hook. The AndRegisterReactorHook variants are
deprecated and delegate to these methods.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 25, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: amit306 / name: amit306 (2f62a78)

@amit306 amit306 marked this pull request as ready for review May 25, 2026 13:54
@amit306 amit306 requested a review from a team as a code owner May 25, 2026 13:54
Copilot AI review requested due to automatic review settings May 25, 2026 13:54
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

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 ContextPropagationOperator inside SpringWebfluxClientTelemetry.addFilter() and SpringWebfluxServerTelemetry.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 invoke addFilter() 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();
@amit306 amit306 force-pushed the fix/webflux-always-register-reactor-hook branch from 2f62a78 to 4c57afb Compare May 25, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should webflux telemetry classes always register reactor hook

2 participants