We are upgrading to Spring Boot 3.0 and Spring framework 6.0.2. We have observability activated in our services and are using DataDog and Prometheus. When using the WebClient, we receive the following Exception:
```ClientRequest must not be null
java.lang.IllegalArgumentException: ClientRequest must not be null
at org.springframework.util.Assert.notNull(Assert.java:204)
Suppressed: The stacktrace has been enhanced by Reactor, refer to additional information below:
Original Stack Trace:
at app//org.springframework.util.Assert.notNull(Assert.java:204)
at app//org.springframework.web.reactive.function.client.DefaultClientRequestBuilder.
It seems that WebClient starts an Observation:
https://github.com/spring-projects/spring-framework/blob/main/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java#L465
observation .parentObservation(contextView.getOrDefault(ObservationThreadLocalAccessor.KEY, null)) .start();
This observation uses the ClientRequest in:
https://github.com/spring-projects/spring-boot/blob/0acaa0e46050017e75056d51918d447271fc16c7/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/ClientObservationConventionAdapter.java#L66
ClientRequest clientRequest = ClientRequest.from(context.getRequest()) .attribute(URI_TEMPLATE_ATTRIBUTE, context.getUriTemplate()).build();
But it is set afterwards in:
https://github.com/spring-projects/spring-framework/blob/main/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java#L468
ClientRequest request = requestBuilder.build(); observationContext.setUriTemplate((String) request.attribute(URI_TEMPLATE_ATTRIBUTE).orElse(null)); observationContext.setRequest(request); ``` Causing this IllegalArgumentException.
Comment From: bdeneuter
It seems to be triggered by our custom tags that we set on the WebClient with our own Spring bean that extends from org.springframework.boot.actuate.metrics.web.servlet.DefaultWebMvcTagsProvider
Comment From: bclozel
Thanks @bdeneuter for your report, this fix will be released in the next maintenance version.