Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public final <RequestT, ResponseT, ErrorT> 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;
Expand Down Expand Up @@ -173,10 +174,18 @@ public final <RequestT, ResponseT, ErrorT> CompletableFuture<ResponseT> 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<TransportHttpClient.Response> 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);
Expand All @@ -186,13 +195,6 @@ public final <RequestT, ResponseT, ErrorT> CompletableFuture<ResponseT> performR
return future;
}

// Propagate required property checks to the thread that will decode the response
boolean disableRequiredChecks = ApiTypeHelper.requiredPropertiesCheckDisabled();

CompletableFuture<TransportHttpClient.Response> 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<ResponseT> future = new CompletableFuture<ResponseT>() {
Expand Down
Loading