Assuming 500 status code when an exception was thrown in the controller; fixes gh-1880
This commit is contained in:
@@ -38,6 +38,7 @@ import reactor.util.context.Context;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
@@ -422,9 +423,11 @@ public final class TraceWebFilter implements WebFilter, Ordered {
|
||||
|
||||
@Override
|
||||
public int statusCode() {
|
||||
if (this.throwable != null
|
||||
&& this.throwable instanceof ResponseStatusException) {
|
||||
return ((ResponseStatusException) this.throwable).getStatus().value();
|
||||
if (!this.delegate.isCommitted() && this.throwable != null) {
|
||||
if (this.throwable instanceof ResponseStatusException) {
|
||||
return ((ResponseStatusException) this.throwable).getStatus().value();
|
||||
}
|
||||
return HttpStatus.INTERNAL_SERVER_ERROR.value();
|
||||
}
|
||||
return delegate.getStatusCode() != null ? delegate.getStatusCode().value()
|
||||
: 0;
|
||||
|
||||
@@ -88,6 +88,12 @@ public class TraceWebFluxTests {
|
||||
thenSpanWith404StatusCodeWasReported(spans, response);
|
||||
spans.clear();
|
||||
|
||||
// when
|
||||
response = whenRequestIsSent(port, "/exception");
|
||||
// then
|
||||
thenSpanWithExceptionWasReported(spans, response);
|
||||
spans.clear();
|
||||
|
||||
// when
|
||||
ClientResponse nonSampledResponse = whenNonSampledRequestIsSent(port);
|
||||
// then
|
||||
@@ -151,6 +157,15 @@ public class TraceWebFluxTests {
|
||||
value -> then(value).isEqualTo("404"));
|
||||
}
|
||||
|
||||
private void thenSpanWithExceptionWasReported(TestSpanHandler spans,
|
||||
ClientResponse response) {
|
||||
Awaitility.await()
|
||||
.untilAsserted(() -> then(response.statusCode().value()).isEqualTo(500));
|
||||
then(spans).hasSize(1);
|
||||
then(spans.get(0).tags()).hasEntrySatisfying("http.status_code",
|
||||
value -> then(value).isEqualTo("500"));
|
||||
}
|
||||
|
||||
private void thenNoSpanWasReported(TestSpanHandler spans, ClientResponse response,
|
||||
Controller2 controller2) {
|
||||
Awaitility.await().untilAsserted(() -> {
|
||||
@@ -252,6 +267,11 @@ public class TraceWebFluxTests {
|
||||
return Flux.just(sampled.toString());
|
||||
}
|
||||
|
||||
@GetMapping("/exception")
|
||||
public Flux<Void> exception() {
|
||||
throw new RuntimeException("Exception");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user