From 7e0a039291e57e4e71daa74b7a39b731e3eb441b Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 20 Oct 2022 11:13:36 +0200 Subject: [PATCH] Add ServerWebExchange getter in WebFlux Observation context The observation context relies on request and response for propagation, but the exchange itself holds attributes and locale context so this is needed for keyvalues extraction in general. This commit adds a getter to expose the exchange from the context. --- .../reactive/ServerRequestObservationContext.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spring-web/src/main/java/org/springframework/http/observation/reactive/ServerRequestObservationContext.java b/spring-web/src/main/java/org/springframework/http/observation/reactive/ServerRequestObservationContext.java index 7e00e9a5aa..51b8dc7033 100644 --- a/spring-web/src/main/java/org/springframework/http/observation/reactive/ServerRequestObservationContext.java +++ b/spring-web/src/main/java/org/springframework/http/observation/reactive/ServerRequestObservationContext.java @@ -35,6 +35,8 @@ import org.springframework.web.util.pattern.PathPattern; */ public class ServerRequestObservationContext extends RequestReplyReceiverContext { + private final ServerWebExchange serverWebExchange; + @Nullable private PathPattern pathPattern; @@ -42,10 +44,18 @@ public class ServerRequestObservationContext extends RequestReplyReceiverContext public ServerRequestObservationContext(ServerWebExchange exchange) { super((request, key) -> request.getHeaders().getFirst(key)); + this.serverWebExchange = exchange; setCarrier(exchange.getRequest()); setResponse(exchange.getResponse()); } + /** + * Return the current {@link ServerWebExchange HTTP exchange}. + */ + public ServerWebExchange getServerWebExchange() { + return this.serverWebExchange; + } + /** * Return the path pattern for the handler that matches the current request. * For example, {@code "/projects/{name}"}.