Skip to content

Commit 7e0a039

Browse files
committed
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.
1 parent 68246dc commit 7e0a039

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

spring-web/src/main/java/org/springframework/http/observation/reactive/ServerRequestObservationContext.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,27 @@
3535
*/
3636
public class ServerRequestObservationContext extends RequestReplyReceiverContext<ServerHttpRequest, ServerHttpResponse> {
3737

38+
private final ServerWebExchange serverWebExchange;
39+
3840
@Nullable
3941
private PathPattern pathPattern;
4042

4143
private boolean connectionAborted;
4244

4345
public ServerRequestObservationContext(ServerWebExchange exchange) {
4446
super((request, key) -> request.getHeaders().getFirst(key));
47+
this.serverWebExchange = exchange;
4548
setCarrier(exchange.getRequest());
4649
setResponse(exchange.getResponse());
4750
}
4851

52+
/**
53+
* Return the current {@link ServerWebExchange HTTP exchange}.
54+
*/
55+
public ServerWebExchange getServerWebExchange() {
56+
return this.serverWebExchange;
57+
}
58+
4959
/**
5060
* Return the path pattern for the handler that matches the current request.
5161
* For example, {@code "/projects/{name}"}.

0 commit comments

Comments
 (0)