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.
This commit is contained in:
Brian Clozel
2022-09-19 10:05:42 +02:00
parent d55bd6d28d
commit 4c45387805
2 changed files with 3 additions and 5 deletions

View File

@@ -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);

View File

@@ -97,8 +97,8 @@ public class HttpRequestsObservationWebFilter implements WebFilter {
}
private Publisher<Void> filter(ServerWebExchange exchange, HttpRequestsObservationContext observationContext, Mono<Void> 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();