@@ -144,6 +144,7 @@ public final <RequestT, ResponseT, ErrorT> ResponseT performRequest(
144144 @ Nullable TransportOptions options
145145 ) throws IOException {
146146 try (Instrumentation .Context ctx = instrumentation .newContext (request , endpoint )) {
147+ // HTTP client span is parented to the logical Elasticsearch request span
147148 try (Instrumentation .ThreadScope ts = ctx .makeCurrent ()) {
148149
149150 TransportOptions opts = options == null ? transportOptions : options ;
@@ -173,10 +174,18 @@ public final <RequestT, ResponseT, ErrorT> CompletableFuture<ResponseT> performR
173174 Instrumentation .Context ctx = instrumentation .newContext (request , endpoint );
174175
175176 TransportOptions opts = options == null ? transportOptions : options ;
176- TransportHttpClient .Request clientReq ;
177- try (Instrumentation .ThreadScope ss = ctx .makeCurrent ()) {
178- clientReq = prepareTransportRequest (request , endpoint );
177+ // Propagate required property checks to the thread that will decode the response
178+ boolean disableRequiredChecks = ApiTypeHelper .requiredPropertiesCheckDisabled ();
179+
180+ CompletableFuture <TransportHttpClient .Response > clientFuture ;
181+ // HTTP client span is parented to the logical Elasticsearch request span
182+ try (Instrumentation .ThreadScope ts = ctx .makeCurrent ()) {
183+ TransportHttpClient .Request clientReq = prepareTransportRequest (request , endpoint );
179184 ctx .beforeSendingHttpRequest (clientReq , options );
185+
186+ clientFuture = httpClient .performRequestAsync (
187+ endpoint .id (), null , clientReq , opts
188+ );
180189 } catch (Exception e ) {
181190 // Terminate early
182191 ctx .recordException (e );
@@ -186,13 +195,6 @@ public final <RequestT, ResponseT, ErrorT> CompletableFuture<ResponseT> performR
186195 return future ;
187196 }
188197
189- // Propagate required property checks to the thread that will decode the response
190- boolean disableRequiredChecks = ApiTypeHelper .requiredPropertiesCheckDisabled ();
191-
192- CompletableFuture <TransportHttpClient .Response > clientFuture = httpClient .performRequestAsync (
193- endpoint .id (), null , clientReq , opts
194- );
195-
196198 // Cancelling the result will cancel the upstream future created by the http client, allowing to
197199 // stop in-flight requests
198200 CompletableFuture <ResponseT > future = new CompletableFuture <ResponseT >() {
0 commit comments