diff --git a/js/.changeset/dirty-candles-brake.md b/js/.changeset/dirty-candles-brake.md new file mode 100644 index 000000000..31258521d --- /dev/null +++ b/js/.changeset/dirty-candles-brake.md @@ -0,0 +1,5 @@ +--- +"@arizeai/openinference-instrumentation-openai": patch +--- + +fix: propgate context to spans created as a result of work done within openai calls diff --git a/js/packages/openinference-instrumentation-openai/src/instrumentation.ts b/js/packages/openinference-instrumentation-openai/src/instrumentation.ts index 580b95f4b..233986aec 100644 --- a/js/packages/openinference-instrumentation-openai/src/instrumentation.ts +++ b/js/packages/openinference-instrumentation-openai/src/instrumentation.ts @@ -175,13 +175,12 @@ export class OpenAIInstrumentation extends InstrumentationBase { }, }, ); - const execContext = getExecContext(span); const execPromise = safeExecuteInTheMiddle< ReturnType >( () => { - return context.with(execContext, () => { + return context.with(trace.setSpan(execContext, span), () => { return original.apply(this, args); }); }, @@ -263,7 +262,7 @@ export class OpenAIInstrumentation extends InstrumentationBase { ReturnType >( () => { - return context.with(execContext, () => { + return context.with(trace.setSpan(execContext, span), () => { return original.apply(this, args); }); }, @@ -335,7 +334,7 @@ export class OpenAIInstrumentation extends InstrumentationBase { ReturnType >( () => { - return context.with(execContext, () => { + return context.with(trace.setSpan(execContext, span), () => { return original.apply(this, args); }); },