Guard against no-op observation
Update `ServerHttpObservationFilter` to check if the `Observation` is a no-op before adding the `ServerRequestObservationContext`. Prior to this commit, if the `Observation` is a no-op then the context type added with the `CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE` would not be a `ServerRequestObservationContext`. This would mean that `findObservationContext` would throw a `ClassCastException`. Fixes gh-29356
This commit is contained in:
@@ -130,7 +130,9 @@ public class ServerHttpObservationFilter extends OncePerRequestFilter {
|
||||
observation = ServerHttpObservationDocumentation.HTTP_REQUESTS.observation(this.observationConvention,
|
||||
DEFAULT_OBSERVATION_CONVENTION, () -> context, this.observationRegistry).start();
|
||||
request.setAttribute(CURRENT_OBSERVATION_ATTRIBUTE, observation);
|
||||
request.setAttribute(CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE, observation.getContext());
|
||||
if (!observation.isNoop()) {
|
||||
request.setAttribute(CURRENT_OBSERVATION_CONTEXT_ATTRIBUTE, observation.getContext());
|
||||
}
|
||||
}
|
||||
return observation;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user