Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebClient instrumentation fails with IllegalArgumentException when adapting to WebClientExchangeTagsProvider #33483

Closed
bdeneuter opened this issue Dec 7, 2022 · 2 comments
Assignees
Labels
theme: observability Issues related to observability type: bug A general bug
Milestone

Comments

@bdeneuter
Copy link

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:

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.<init>(DefaultClientRequestBuilder.java:72)
		at app//org.springframework.web.reactive.function.client.ClientRequest.from(ClientRequest.java:134)
		at app//org.springframework.boot.actuate.autoconfigure.observation.web.client.ClientObservationConventionAdapter.mutateClientRequest(ClientObservationConventionAdapter.java:66)
		at app//org.springframework.boot.actuate.autoconfigure.observation.web.client.ClientObservationConventionAdapter.getLowCardinalityKeyValues(ClientObservationConventionAdapter.java:58)
		at app//org.springframework.boot.actuate.autoconfigure.observation.web.client.ClientObservationConventionAdapter.getLowCardinalityKeyValues(ClientObservationConventionAdapter.java:36)
		at app//io.micrometer.observation.SimpleObservation.start(SimpleObservation.java:134)
		at app//org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.lambda$exchange$9(DefaultWebClient.java:465)
		at app//reactor.core.publisher.MonoDeferContextual.subscribe(MonoDeferContextual.java:47)
		at app//reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
		at app//reactor.core.publisher.FluxRetryWhen.subscribe(FluxRetryWhen.java:77)
		at app//reactor.core.publisher.MonoRetryWhen.subscribeOrReturn(MonoRetryWhen.java:46)
		at app//reactor.core.publisher.Mono.subscribe(Mono.java:4429)
		at app//reactor.core.publisher.Mono.block(Mono.java:1709)

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:

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 7, 2022
@bdeneuter
Copy link
Author

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

@bclozel bclozel self-assigned this Dec 7, 2022
@bclozel bclozel transferred this issue from spring-projects/spring-framework Dec 7, 2022
@bclozel bclozel added type: bug A general bug theme: observability Issues related to observability and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 7, 2022
@bclozel bclozel added this to the 3.0.1 milestone Dec 7, 2022
@bclozel bclozel changed the title WebClient call fails with java.lang.IllegalArgumentException: ClientRequest must not be null WebClient instrumentation fails with IllegalArgumentException when adapting to WebClientExchangeTagsProvider Dec 7, 2022
@bclozel
Copy link
Member

bclozel commented Dec 7, 2022

Thanks @bdeneuter for your report, this fix will be released in the next maintenance version.

@bclozel bclozel closed this as completed in 50be8cb Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: observability Issues related to observability type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants