Skip to content

Commit

Permalink
Fix WebFluxObservationPropagationTests for HTTP
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
artembilan committed Jun 7, 2023
1 parent e9f7780 commit 0cf81db
Showing 1 changed file with 9 additions and 15 deletions.
Expand Up @@ -57,6 +57,7 @@
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;
Expand Down Expand Up @@ -107,8 +108,7 @@ void observationIsPropagatedFromWebFluxToServiceActivator() {

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();
}
Expand All @@ -123,9 +123,7 @@ void observationIsPropagatedWebFluxRequestReply() {
.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();
}
Expand Down Expand Up @@ -171,16 +169,12 @@ ObservationRegistry observationRegistry(Tracer tracer, Propagator propagator) {
}

@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
Expand Down

0 comments on commit 0cf81db

Please sign in to comment.