From 4c453878059230f2c6a17e72f557d14820e531eb Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Mon, 19 Sep 2022 10:05:42 +0200 Subject: [PATCH] Polish Observability instrumentation This commit removes the scoping of `RestTemplate` requests, since no user code is meant to run during HTTP client exchanges. This also polishes the reactive `WebFilter` to directly use the specific enum when creating the observation. --- .../java/org/springframework/web/client/RestTemplate.java | 4 +--- .../reactive/HttpRequestsObservationWebFilter.java | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java index 7c9190d98c..a5d4e93ac6 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java @@ -849,9 +849,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat if (requestCallback != null) { requestCallback.doWithRequest(request); } - try (Observation.Scope scope = observation.openScope()) { - response = request.execute(); - } + response = request.execute(); observationContext.setResponse(response); handleResponse(url, method, response); return (responseExtractor != null ? responseExtractor.extractData(response) : null); diff --git a/spring-web/src/main/java/org/springframework/web/observation/reactive/HttpRequestsObservationWebFilter.java b/spring-web/src/main/java/org/springframework/web/observation/reactive/HttpRequestsObservationWebFilter.java index 060550010b..d8182162d7 100644 --- a/spring-web/src/main/java/org/springframework/web/observation/reactive/HttpRequestsObservationWebFilter.java +++ b/spring-web/src/main/java/org/springframework/web/observation/reactive/HttpRequestsObservationWebFilter.java @@ -97,8 +97,8 @@ public class HttpRequestsObservationWebFilter implements WebFilter { } private Publisher filter(ServerWebExchange exchange, HttpRequestsObservationContext observationContext, Mono call) { - Observation observation = Observation.createNotStarted(this.observationConvention, DEFAULT_OBSERVATION_CONVENTION, - observationContext, this.observationRegistry); + Observation observation = HttpRequestsObservation.HTTP_REQUESTS.createNotStarted(this.observationConvention, + DEFAULT_OBSERVATION_CONVENTION, () -> observationContext, this.observationRegistry); observation.start(); return call.doOnEach(signal -> { Throwable throwable = signal.getThrowable();