Skip to content
Merged
Show file tree
Hide file tree
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 @@ -58,11 +58,14 @@ public void transform(TypeTransformer transformer) {

public static class AdviceScope {
private final OpenSearchRequest otelRequest;
private final Context parentContext;
private final Context context;
private final Scope scope;

private AdviceScope(OpenSearchRequest otelRequest, Context context, Scope scope) {
private AdviceScope(
OpenSearchRequest otelRequest, Context parentContext, Context context, Scope scope) {
this.otelRequest = otelRequest;
this.parentContext = parentContext;
this.context = context;
this.scope = scope;
}
Expand All @@ -87,11 +90,29 @@ public static AdviceScope start(
return null;
}
Context context = instrumenter().start(parentContext, otelRequest);
return new AdviceScope(otelRequest, context, context.makeCurrent());
return new AdviceScope(otelRequest, parentContext, context, context.makeCurrent());
}

public CompletableFuture<Object> wrapFuture(CompletableFuture<Object> future) {
return future.whenComplete(new OpenSearchResponseHandler(context, otelRequest));
return wrapFuture(
future.whenComplete(new OpenSearchResponseHandler(context, otelRequest)), parentContext);
}

private static <T> CompletableFuture<T> wrapFuture(
CompletableFuture<T> future, Context context) {
CompletableFuture<T> result = new CompletableFuture<>();
future.whenComplete(
(T value, Throwable throwable) -> {
try (Scope ignored = context.makeCurrent()) {
if (throwable != null) {
result.completeExceptionally(throwable);
} else {
result.complete(value);
}
}
});

return result;
}

public void end(@Nullable Throwable throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void shouldGetStatusAsyncWithTraces() throws Exception {
span ->
span.hasName("callback")
.hasKind(SpanKind.INTERNAL)
.hasParent(trace.getSpan(1))));
.hasParent(trace.getSpan(0))));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,6 @@ void shouldGetStatusAsyncWithTraces() throws Exception {
span ->
span.hasName("callback")
.hasKind(SpanKind.INTERNAL)
.hasParent(trace.getSpan(1))));
.hasParent(trace.getSpan(0))));
}
}
Loading