From d84a46204337cfedb37498681010369e94a4fdf4 Mon Sep 17 00:00:00 2001 From: Laura Trotta Date: Thu, 9 Jul 2026 11:40:14 +0200 Subject: [PATCH 1/2] fix otel async path (#1269) --- .../transport/ElasticsearchTransportBase.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java b/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java index 913c10d479..4794922b64 100644 --- a/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java +++ b/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java @@ -129,6 +129,7 @@ public final ResponseT performRequest( @Nullable TransportOptions options ) throws IOException { try (Instrumentation.Context ctx = instrumentation.newContext(request, endpoint)) { + // HTTP client span is parented to the logical Elasticsearch request span try (Instrumentation.ThreadScope ts = ctx.makeCurrent()) { TransportOptions opts = options == null ? transportOptions : options; @@ -158,10 +159,18 @@ public final CompletableFuture performR Instrumentation.Context ctx = instrumentation.newContext(request, endpoint); TransportOptions opts = options == null ? transportOptions : options; - TransportHttpClient.Request clientReq; - try (Instrumentation.ThreadScope ss = ctx.makeCurrent()) { - clientReq = prepareTransportRequest(request, endpoint); + // Propagate required property checks to the thread that will decode the response + boolean disableRequiredChecks = ApiTypeHelper.requiredPropertiesCheckDisabled(); + + CompletableFuture clientFuture; + // HTTP client span is parented to the logical Elasticsearch request span + try (Instrumentation.ThreadScope ts = ctx.makeCurrent()) { + TransportHttpClient.Request clientReq = prepareTransportRequest(request, endpoint); ctx.beforeSendingHttpRequest(clientReq, options); + + clientFuture = httpClient.performRequestAsync( + endpoint.id(), null, clientReq, opts + ); } catch (Exception e) { // Terminate early ctx.recordException(e); @@ -178,7 +187,8 @@ public final CompletableFuture performR endpoint.id(), null, clientReq, opts ); - // Cancelling the result will cancel the upstream future created by the http client, allowing to stop in-flight requests + // Cancelling the result will cancel the upstream future created by the http client, allowing to + // stop in-flight requests CompletableFuture future = new CompletableFuture() { @Override public boolean cancel(boolean mayInterruptIfRunning) { From 6ce384195477e7cf521c7ce960daf21340624768 Mon Sep 17 00:00:00 2001 From: Laura Trotta Date: Thu, 9 Jul 2026 12:01:01 +0200 Subject: [PATCH 2/2] fix merge --- .../clients/transport/ElasticsearchTransportBase.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java b/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java index 4794922b64..f51b488f47 100644 --- a/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java +++ b/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java @@ -180,13 +180,6 @@ public final CompletableFuture performR return future; } - // Propagate required property checks to the thread that will decode the response - boolean disableRequiredChecks = ApiTypeHelper.requiredPropertiesCheckDisabled(); - - CompletableFuture clientFuture = httpClient.performRequestAsync( - endpoint.id(), null, clientReq, opts - ); - // Cancelling the result will cancel the upstream future created by the http client, allowing to // stop in-flight requests CompletableFuture future = new CompletableFuture() {