-
Notifications
You must be signed in to change notification settings - Fork 783
Description
When using Spring Cloud Sleuth with a WebClient call, and the downstream service responds with a non-standard HTTP code (say 499), then WebClientTracerSubscriber.terminateSpan() throws an IllegalArgumentException because the status code cannot be mapped to one of the HttpStatus enum values.
The offending code is here:
void terminateSpan(@Nullable ClientResponse clientResponse,
@Nullable Throwable throwable) {
if (clientResponse == null || clientResponse.statusCode() == null) {
From the Javadoc, ClientResponse.statusCode() will never return null, but will instead throw an IllegalArgumentException. As suggested by spring-projects/spring-framework#21289 clientResponse.getRawStatusCode() should be used if there's a possibility of a non-standard response code. Our app will call something like:
webClient.get()
.uri(...)
.exchange()
.flatMap(response -> {
if (response.getRawStatusCode() == ...)
...
})
However, this response handler never gets control because of the exception thrown when terminateSpan()
calls clientResponse.statusCode()
. When we remove spring-cloud-sleuth, it works fine, but since we would like the OpenTracing support, we still want to use sleuth.