Skip to content

Commit 0cf81db

Browse files
committed
Fix WebFluxObservationPropagationTests for HTTP
The `WebTestClient` was previously binding directly to the web layer (no HTTP layer involved). Because the new instrumentation is done at the HTTP level (it's required to fully capture error handling and more), the test client must bind at the HTTP level with a `Connector`.
1 parent e9f7780 commit 0cf81db

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

spring-integration-webflux/src/test/java/org/springframework/integration/webflux/observation/WebFluxObservationPropagationTests.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.springframework.messaging.support.ChannelInterceptor;
5858
import org.springframework.test.annotation.DirtiesContext;
5959
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
60+
import org.springframework.test.web.reactive.server.HttpHandlerConnector;
6061
import org.springframework.test.web.reactive.server.WebTestClient;
6162
import org.springframework.web.reactive.config.EnableWebFlux;
6263
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
@@ -107,8 +108,7 @@ void observationIsPropagatedFromWebFluxToServiceActivator() {
107108

108109
this.observationRegistry.getCurrentObservation().stop();
109110

110-
// assertThat(SPANS.spans()).hasSize(6);
111-
assertThat(SPANS.spans()).hasSize(5);
111+
assertThat(SPANS.spans()).hasSize(6);
112112
SpansAssert.assertThat(SPANS.spans().stream().map(BraveFinishedSpan::fromBrave).collect(Collectors.toList()))
113113
.haveSameTraceId();
114114
}
@@ -123,9 +123,7 @@ void observationIsPropagatedWebFluxRequestReply() {
123123
.expectBody(String.class)
124124
.isEqualTo(testData.toLowerCase());
125125

126-
// assertThat(SPANS.spans()).hasSize(3);
127-
assertThat(SPANS.spans()).hasSize(2);
128-
// System. out .println(SPANS.spans().stream().map(Objects::toString).collect(Collectors.joining("\n")));
126+
assertThat(SPANS.spans()).hasSize(3);
129127
SpansAssert.assertThat(SPANS.spans().stream().map(BraveFinishedSpan::fromBrave).collect(Collectors.toList()))
130128
.haveSameTraceId();
131129
}
@@ -171,16 +169,12 @@ ObservationRegistry observationRegistry(Tracer tracer, Propagator propagator) {
171169
}
172170

173171
@Bean
174-
WebTestClient webTestClient(ApplicationContext applicationContext) {
175-
return WebTestClient.bindToApplicationContext(applicationContext).build();
176-
}
177-
178-
// TODO This config does not add a SERVER span into a trace
179-
@Bean
180-
public HttpHandler httpHandler(ObservationRegistry registry, ApplicationContext applicationContext) {
181-
return WebHttpHandlerBuilder.applicationContext(applicationContext)
182-
.observationRegistry(registry)
183-
.build();
172+
WebTestClient webTestClient(ObservationRegistry registry, ApplicationContext applicationContext) {
173+
HttpHandler httpHandler =
174+
WebHttpHandlerBuilder.applicationContext(applicationContext)
175+
.observationRegistry(registry)
176+
.build();
177+
return WebTestClient.bindToServer(new HttpHandlerConnector(httpHandler)).build();
184178
}
185179

186180
@Bean

0 commit comments

Comments
 (0)