Skip to content

Commit 87820df

Browse files
committed
Fix context
1 parent df19b40 commit 87820df

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

instrumentation/openai/openai-java-1.1/library/src/main/java/io/opentelemetry/instrumentation/openai/v1_1/InstrumentedChatCompletionServiceAsync.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private CompletableFuture<ChatCompletion> create(
9292
future =
9393
future.whenComplete(
9494
(res, t) -> instrumenter.end(context, chatCompletionCreateParams, res, t));
95-
return CompletableFutureWrapper.wrap(future, context);
95+
return CompletableFutureWrapper.wrap(future, parentContext);
9696
}
9797

9898
private CompletableFuture<ChatCompletion> createWithLogs(

instrumentation/openai/openai-java-1.1/testing/src/main/java/io/opentelemetry/instrumentation/openai/v1_1/AbstractChatTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
import io.opentelemetry.api.common.AttributeKey;
6060
import io.opentelemetry.api.common.KeyValue;
6161
import io.opentelemetry.api.common.Value;
62+
import io.opentelemetry.api.trace.Span;
6263
import io.opentelemetry.api.trace.SpanContext;
64+
import io.opentelemetry.context.Context;
6365
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
6466
import io.opentelemetry.instrumentation.testing.recording.RecordingExtension;
6567
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
@@ -158,7 +160,15 @@ protected final ChatCompletion doCompletions(
158160
case ASYNC_FROM_SYNC:
159161
OpenAIClientAsync cl = testType == TestType.ASYNC ? clientAsync : client.async();
160162
try {
161-
return cl.chat().completions().create(params).join();
163+
return cl.chat()
164+
.completions()
165+
.create(params)
166+
.thenApply(
167+
res -> {
168+
assertThat(Span.fromContextOrNull(Context.current())).isNull();
169+
return res;
170+
})
171+
.join();
162172
} catch (CompletionException e) {
163173
if (e.getCause() instanceof OpenAIIoException) {
164174
throw ((OpenAIIoException) e.getCause());

0 commit comments

Comments
 (0)