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
5 changes: 5 additions & 0 deletions js/.changeset/clear-lemons-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@arizeai/openinference-instrumentation-openai": major
---

support for openai@6 with discriminated unions for tool types
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ openaiInstrumentation.setTracerProvider(customTracerProvider);

| OpenAI Version | OpenInference Instrumentation Version |
| -------------- | ------------------------------------- |
| ^6.0.0 | ^4.0.0 |
| ^5.0.0 | ^3.0.0 |
| ^4.0.0 | ^2.0.0 |
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"@opentelemetry/sdk-trace-base": "^1.25.1",
"@opentelemetry/sdk-trace-node": "^1.25.1",
"@opentelemetry/semantic-conventions": "^1.25.1",
"openai": "^6.7.0",
"vitest": "^2.1.8",
"openai": "^5.7.0",
"zod": "^3.24.3",
"typescript": "^5.5.4"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
protected init(): InstrumentationModuleDefinition<typeof openai> {
const module = new InstrumentationNodeModuleDefinition<typeof openai>(
"openai",
["^5.0.0"],
// 5.x is best effort
["^6.0.0", "^5.0.0"],
this.patch.bind(this),
this.unpatch.bind(this),
);
Expand Down Expand Up @@ -754,6 +755,9 @@ function getChatCompletionInputMessageAttributes(
attributes[
`${toolCallIndexPrefix}${SemanticConventions.TOOL_CALL_FUNCTION_ARGUMENTS_JSON}`
] = toolCall.function.arguments;
} else {
// TODO: add exhaustive checks
diag.warn(`Unsupported tool type: ${toolCall.type}`);
}
});
}
Expand Down Expand Up @@ -874,8 +878,6 @@ function getChatCompletionOutputMessageAttributes(
`${toolCallIndexPrefix}${SemanticConventions.TOOL_CALL_ID}`
] = toolCall.id;
}
// Double check that the tool call has a function
// NB: OpenAI only supports tool calls with functions right now but this may change
if (toolCall.type === "function") {
attributes[
toolCallIndexPrefix + SemanticConventions.TOOL_CALL_FUNCTION_NAME
Expand All @@ -884,6 +886,9 @@ function getChatCompletionOutputMessageAttributes(
toolCallIndexPrefix +
SemanticConventions.TOOL_CALL_FUNCTION_ARGUMENTS_JSON
] = toolCall.function.arguments;
} else {
// TODO: switch to exhaustive checks
diag.warn(`Unsupported tool type: ${toolCall.type}`);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { safelyJSONStringify } from "@arizeai/openinference-core";
import { SemanticConventions } from "@arizeai/openinference-semantic-conventions";

import { Attributes } from "@opentelemetry/api";
Expand Down Expand Up @@ -44,8 +45,15 @@ function getResponseItemAttributes(
attributes[`${prefix}${SemanticConventions.MESSAGE_ROLE}`] = "tool";
attributes[`${prefix}${SemanticConventions.MESSAGE_TOOL_CALL_ID}`] =
item.call_id;
attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] =
item.output;
if (typeof item.output === "string") {
attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] =
item.output;
} else {
// TODO(2410): figure out how to serialize the list of tools
attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] =
safelyJSONStringify(item.output) || undefined;
}

break;
}
case "reasoning": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,8 @@ describe("OpenAIInstrumentation - Responses", () => {
],
model: "gpt-4.1",
text: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Type instantiation is excessively deep with zod helper
format: zodTextFormat(CalendarEvent, "event"),
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,8 @@ describe("OpenAIInstrumentation", () => {
content: "Alice and Bob are going to a science fair on Friday.",
},
],
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Type instantiation is excessively deep with zod helper
response_format: zodResponseFormat(CalendarEvent, "event"),
});

Expand Down
95 changes: 39 additions & 56 deletions js/pnpm-lock.yaml

Large diffs are not rendered by default.

Loading