@@ -129,6 +129,7 @@ public final <RequestT, ResponseT, ErrorT> ResponseT performRequest(
129129 @ Nullable TransportOptions options
130130 ) throws IOException {
131131 try (Instrumentation .Context ctx = instrumentation .newContext (request , endpoint )) {
132+ // HTTP client span is parented to the logical Elasticsearch request span
132133 try (Instrumentation .ThreadScope ts = ctx .makeCurrent ()) {
133134
134135 TransportOptions opts = options == null ? transportOptions : options ;
@@ -158,10 +159,18 @@ public final <RequestT, ResponseT, ErrorT> CompletableFuture<ResponseT> performR
158159 Instrumentation .Context ctx = instrumentation .newContext (request , endpoint );
159160
160161 TransportOptions opts = options == null ? transportOptions : options ;
161- TransportHttpClient .Request clientReq ;
162- try (Instrumentation .ThreadScope ss = ctx .makeCurrent ()) {
163- clientReq = prepareTransportRequest (request , endpoint );
162+ // Propagate required property checks to the thread that will decode the response
163+ boolean disableRequiredChecks = ApiTypeHelper .requiredPropertiesCheckDisabled ();
164+
165+ CompletableFuture <TransportHttpClient .Response > clientFuture ;
166+ // HTTP client span is parented to the logical Elasticsearch request span
167+ try (Instrumentation .ThreadScope ts = ctx .makeCurrent ()) {
168+ TransportHttpClient .Request clientReq = prepareTransportRequest (request , endpoint );
164169 ctx .beforeSendingHttpRequest (clientReq , options );
170+
171+ clientFuture = httpClient .performRequestAsync (
172+ endpoint .id (), null , clientReq , opts
173+ );
165174 } catch (Exception e ) {
166175 // Terminate early
167176 ctx .recordException (e );
@@ -171,14 +180,8 @@ public final <RequestT, ResponseT, ErrorT> CompletableFuture<ResponseT> performR
171180 return future ;
172181 }
173182
174- // Propagate required property checks to the thread that will decode the response
175- boolean disableRequiredChecks = ApiTypeHelper .requiredPropertiesCheckDisabled ();
176-
177- CompletableFuture <TransportHttpClient .Response > clientFuture = httpClient .performRequestAsync (
178- endpoint .id (), null , clientReq , opts
179- );
180-
181- // Cancelling the result will cancel the upstream future created by the http client, allowing to stop in-flight requests
183+ // Cancelling the result will cancel the upstream future created by the http client, allowing to
184+ // stop in-flight requests
182185 CompletableFuture <ResponseT > future = new CompletableFuture <ResponseT >() {
183186 @ Override
184187 public boolean cancel (boolean mayInterruptIfRunning ) {
0 commit comments