Propagate context in reactive HTTP server and client
Prior to this commit, the ServerHttpObservationFilter would not add the current observation as a key in the Reactor context, preventing from being used or propagated during the HTTP exchange handling. Also, the client instrumentation in `DefaultWebClient` would start the observation once the request is fully formed and immutable, preventing the context from being propagated through HTTP request headers. This commit fixes both uses cases now by: * adding the current observation as a key in the reactor context on the server side * using the `ClientRequest.Builder` as a Carrier on the client side Closes gh-29388
This commit is contained in:
committed by
Brian Clozel
parent
396336fdcc
commit
c03ccb2e6c
@@ -59,6 +59,11 @@ public class ServerHttpObservationFilter implements WebFilter {
|
||||
private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS = Set.of("AbortedException",
|
||||
"ClientAbortException", "EOFException", "EofException");
|
||||
|
||||
/**
|
||||
* Aligned with ObservationThreadLocalAccessor#KEY from micrometer-core.
|
||||
*/
|
||||
private static final String MICROMETER_OBSERVATION_KEY = "micrometer.observation";
|
||||
|
||||
private final ObservationRegistry observationRegistry;
|
||||
|
||||
private final ServerRequestObservationConvention observationConvention;
|
||||
@@ -117,7 +122,8 @@ public class ServerHttpObservationFilter implements WebFilter {
|
||||
.doOnCancel(() -> {
|
||||
observationContext.setConnectionAborted(true);
|
||||
observation.stop();
|
||||
});
|
||||
})
|
||||
.contextWrite(context -> context.put(MICROMETER_OBSERVATION_KEY, observation));
|
||||
}
|
||||
|
||||
private void onTerminalSignal(Observation observation, ServerWebExchange exchange) {
|
||||
|
||||
Reference in New Issue
Block a user