Skip to content

Commit 4c45387

Browse files
committed
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.
1 parent d55bd6d commit 4c45387

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

spring-web/src/main/java/org/springframework/web/client/RestTemplate.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,9 +849,7 @@ protected <T> T doExecute(URI url, @Nullable String uriTemplate, @Nullable HttpM
849849
if (requestCallback != null) {
850850
requestCallback.doWithRequest(request);
851851
}
852-
try (Observation.Scope scope = observation.openScope()) {
853-
response = request.execute();
854-
}
852+
response = request.execute();
855853
observationContext.setResponse(response);
856854
handleResponse(url, method, response);
857855
return (responseExtractor != null ? responseExtractor.extractData(response) : null);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
9797
}
9898

9999
private Publisher<Void> filter(ServerWebExchange exchange, HttpRequestsObservationContext observationContext, Mono<Void> call) {
100-
Observation observation = Observation.createNotStarted(this.observationConvention, DEFAULT_OBSERVATION_CONVENTION,
101-
observationContext, this.observationRegistry);
100+
Observation observation = HttpRequestsObservation.HTTP_REQUESTS.createNotStarted(this.observationConvention,
101+
DEFAULT_OBSERVATION_CONVENTION, () -> observationContext, this.observationRegistry);
102102
observation.start();
103103
return call.doOnEach(signal -> {
104104
Throwable throwable = signal.getThrowable();

0 commit comments

Comments
 (0)