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`.
This commit is contained in:
@@ -57,6 +57,7 @@ import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
|
||||
import org.springframework.test.web.reactive.server.HttpHandlerConnector;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.web.reactive.config.EnableWebFlux;
|
||||
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
||||
@@ -107,8 +108,7 @@ public class WebFluxObservationPropagationTests {
|
||||
|
||||
this.observationRegistry.getCurrentObservation().stop();
|
||||
|
||||
// assertThat(SPANS.spans()).hasSize(6);
|
||||
assertThat(SPANS.spans()).hasSize(5);
|
||||
assertThat(SPANS.spans()).hasSize(6);
|
||||
SpansAssert.assertThat(SPANS.spans().stream().map(BraveFinishedSpan::fromBrave).collect(Collectors.toList()))
|
||||
.haveSameTraceId();
|
||||
}
|
||||
@@ -123,9 +123,7 @@ public class WebFluxObservationPropagationTests {
|
||||
.expectBody(String.class)
|
||||
.isEqualTo(testData.toLowerCase());
|
||||
|
||||
// assertThat(SPANS.spans()).hasSize(3);
|
||||
assertThat(SPANS.spans()).hasSize(2);
|
||||
// System. out .println(SPANS.spans().stream().map(Objects::toString).collect(Collectors.joining("\n")));
|
||||
assertThat(SPANS.spans()).hasSize(3);
|
||||
SpansAssert.assertThat(SPANS.spans().stream().map(BraveFinishedSpan::fromBrave).collect(Collectors.toList()))
|
||||
.haveSameTraceId();
|
||||
}
|
||||
@@ -171,16 +169,12 @@ public class WebFluxObservationPropagationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
WebTestClient webTestClient(ApplicationContext applicationContext) {
|
||||
return WebTestClient.bindToApplicationContext(applicationContext).build();
|
||||
}
|
||||
|
||||
// TODO This config does not add a SERVER span into a trace
|
||||
@Bean
|
||||
public HttpHandler httpHandler(ObservationRegistry registry, ApplicationContext applicationContext) {
|
||||
return WebHttpHandlerBuilder.applicationContext(applicationContext)
|
||||
.observationRegistry(registry)
|
||||
.build();
|
||||
WebTestClient webTestClient(ObservationRegistry registry, ApplicationContext applicationContext) {
|
||||
HttpHandler httpHandler =
|
||||
WebHttpHandlerBuilder.applicationContext(applicationContext)
|
||||
.observationRegistry(registry)
|
||||
.build();
|
||||
return WebTestClient.bindToServer(new HttpHandlerConnector(httpHandler)).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user