Skip to content

Commit

Permalink
fix(js): set spans from instrumentation active span on context in Ope…
Browse files Browse the repository at this point in the history
…nAI instrumentor (#1121)
  • Loading branch information
Parker-Stafford authored Nov 14, 2024
1 parent 999ff42 commit 47cd6b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions js/.changeset/dirty-candles-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@arizeai/openinference-instrumentation-openai": patch
---

fix: propgate context to spans created as a result of work done within openai calls
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,12 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
},
},
);

const execContext = getExecContext(span);
const execPromise = safeExecuteInTheMiddle<
ReturnType<ChatCompletionCreateType>
>(
() => {
return context.with(execContext, () => {
return context.with(trace.setSpan(execContext, span), () => {
return original.apply(this, args);
});
},
Expand Down Expand Up @@ -263,7 +262,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
ReturnType<CompletionsCreateType>
>(
() => {
return context.with(execContext, () => {
return context.with(trace.setSpan(execContext, span), () => {
return original.apply(this, args);
});
},
Expand Down Expand Up @@ -335,7 +334,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
ReturnType<EmbeddingsCreateType>
>(
() => {
return context.with(execContext, () => {
return context.with(trace.setSpan(execContext, span), () => {
return original.apply(this, args);
});
},
Expand Down

0 comments on commit 47cd6b5

Please sign in to comment.