Skip to content

Commit 57bbc09

Browse files
committed
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
1 parent f99c02f commit 57bbc09

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import jakarta.servlet.http.HttpServletRequest;
2828
import jakarta.servlet.http.HttpServletResponse;
2929

30-
import org.springframework.http.HttpStatus;
3130
import org.springframework.http.observation.DefaultServerRequestObservationConvention;
3231
import org.springframework.http.observation.ServerHttpObservationDocumentation;
3332
import org.springframework.http.observation.ServerRequestObservationContext;
@@ -117,7 +116,6 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
117116
if (!request.isAsyncStarted()) {
118117
Throwable error = fetchException(request);
119118
if (error != null) {
120-
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
121119
observation.error(error);
122120
}
123121
observation.stop();

spring-web/src/test/java/org/springframework/web/filter/ServerHttpObservationFilterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void filterShouldUseThrownException() throws Exception {
7070
ServerRequestObservationContext context = (ServerRequestObservationContext) this.request
7171
.getAttribute(ServerHttpObservationFilter.CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE);
7272
assertThat(context.getError()).isEqualTo(customError);
73-
assertThatHttpObservation().hasLowCardinalityKeyValue("outcome", "SERVER_ERROR");
73+
assertThatHttpObservation().hasLowCardinalityKeyValue("exception", "IllegalArgumentException");
7474
}
7575

7676
@Test

0 commit comments

Comments
 (0)