Skip to content
Open
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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
protected init(): InstrumentationModuleDefinition<typeof openai> {
const module = new InstrumentationNodeModuleDefinition<typeof openai>(
"openai",
["^5.0.0"],
["^6.0.0"],
this.patch.bind(this),
this.unpatch.bind(this),
);
Expand Down Expand Up @@ -753,6 +753,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 @@ -873,8 +876,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 @@ -883,6 +884,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,5 +1,5 @@
import { SemanticConventions } from "@arizeai/openinference-semantic-conventions";
import { Attributes } from "@opentelemetry/api";
import { Attributes, diag } from "@opentelemetry/api";
import {
ResponseCreateParamsBase,
ResponseInputItem,
Expand Down Expand Up @@ -42,8 +42,12 @@ 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 {
diag.warn("Failed to serialize non-string typed tool output");
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Tool Outputs Silently Dropped When Not Strings

Non-string tool outputs are being silently dropped with only a warning. If item.output can be an object or array, it should be JSON-stringified before being assigned to the attribute, not skipped. This could result in loss of tool output data when the output is not a string type.

Fix in Cursor Fix in Web

break;
}
case "reasoning": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,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 @@ -1073,6 +1073,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
89 changes: 36 additions & 53 deletions js/pnpm-lock.yaml

Large diffs are not rendered by default.

Loading