From 57bbc09fca892479eac67b1dfc3c9bc0fcd07952 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Wed, 19 Oct 2022 12:11:00 +0200 Subject: [PATCH] Do not set response status in ServerHttpObservationFilter Prior to this commit, the `ServerHttpObservationFilter` would set the response status (and possibly overwrite it) in case an exception is found as an attribute. While the exception itself should be used in the observation, the filter should have no side effect on the response. Fixes gh-29353 --- .../springframework/web/filter/ServerHttpObservationFilter.java | 2 -- .../web/filter/ServerHttpObservationFilterTests.java | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java index 58b99aa129..c6852aecd3 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java @@ -27,7 +27,6 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import org.springframework.http.HttpStatus; import org.springframework.http.observation.DefaultServerRequestObservationConvention; import org.springframework.http.observation.ServerHttpObservationDocumentation; import org.springframework.http.observation.ServerRequestObservationContext; @@ -117,7 +116,6 @@ public class ServerHttpObservationFilter extends OncePerRequestFilter { if (!request.isAsyncStarted()) { Throwable error = fetchException(request); if (error != null) { - response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); observation.error(error); } observation.stop(); diff --git a/spring-web/src/test/java/org/springframework/web/filter/ServerHttpObservationFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/ServerHttpObservationFilterTests.java index a574faeac4..649f1a07af 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/ServerHttpObservationFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/ServerHttpObservationFilterTests.java @@ -70,7 +70,7 @@ class ServerHttpObservationFilterTests { ServerRequestObservationContext context = (ServerRequestObservationContext) this.request .getAttribute(ServerHttpObservationFilter.CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE); assertThat(context.getError()).isEqualTo(customError); - assertThatHttpObservation().hasLowCardinalityKeyValue("outcome", "SERVER_ERROR"); + assertThatHttpObservation().hasLowCardinalityKeyValue("exception", "IllegalArgumentException"); } @Test