@arizeai/openinference-instrumentation-openai 3.2.5 → 4.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arizeai/openinference-instrumentation-openai",
3
- "version": "3.2.5",
3
+ "version": "4.0.5",
4
4
  "description": "OpenInference instrumentation for OpenAI",
5
5
  "private": false,
6
6
  "main": "dist/src/index.js",
@@ -21,8 +21,8 @@
21
21
  "@opentelemetry/api": "^1.9.0",
22
22
  "@opentelemetry/core": "^1.25.1",
23
23
  "@opentelemetry/instrumentation": "^0.46.0",
24
- "@arizeai/openinference-core": "2.0.0",
25
- "@arizeai/openinference-semantic-conventions": "2.1.2"
24
+ "@arizeai/openinference-core": "2.0.5",
25
+ "@arizeai/openinference-semantic-conventions": "2.1.7"
26
26
  },
27
27
  "keywords": [],
28
28
  "files": [
@@ -37,8 +37,8 @@
37
37
  "@opentelemetry/sdk-trace-base": "^1.25.1",
38
38
  "@opentelemetry/sdk-trace-node": "^1.25.1",
39
39
  "@opentelemetry/semantic-conventions": "^1.25.1",
40
+ "openai": "^6.7.0",
40
41
  "vitest": "^2.1.8",
41
- "openai": "^5.7.0",
42
42
  "zod": "^3.24.3",
43
43
  "typescript": "^5.5.4"
44
44
  },
@@ -208,7 +208,8 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
208
208
  protected init(): InstrumentationModuleDefinition<typeof openai> {
209
209
  const module = new InstrumentationNodeModuleDefinition<typeof openai>(
210
210
  "openai",
211
- ["^5.0.0"],
211
+ // 5.x is best effort
212
+ ["^6.0.0", "^5.0.0"],
212
213
  this.patch.bind(this),
213
214
  this.unpatch.bind(this),
214
215
  );
@@ -754,6 +755,9 @@ function getChatCompletionInputMessageAttributes(
754
755
  attributes[
755
756
  `${toolCallIndexPrefix}${SemanticConventions.TOOL_CALL_FUNCTION_ARGUMENTS_JSON}`
756
757
  ] = toolCall.function.arguments;
758
+ } else {
759
+ // TODO: add exhaustive checks
760
+ diag.warn(`Unsupported tool type: ${toolCall.type}`);
757
761
  }
758
762
  });
759
763
  }
@@ -874,8 +878,6 @@ function getChatCompletionOutputMessageAttributes(
874
878
  `${toolCallIndexPrefix}${SemanticConventions.TOOL_CALL_ID}`
875
879
  ] = toolCall.id;
876
880
  }
877
- // Double check that the tool call has a function
878
- // NB: OpenAI only supports tool calls with functions right now but this may change
879
881
  if (toolCall.type === "function") {
880
882
  attributes[
881
883
  toolCallIndexPrefix + SemanticConventions.TOOL_CALL_FUNCTION_NAME
@@ -884,6 +886,9 @@ function getChatCompletionOutputMessageAttributes(
884
886
  toolCallIndexPrefix +
885
887
  SemanticConventions.TOOL_CALL_FUNCTION_ARGUMENTS_JSON
886
888
  ] = toolCall.function.arguments;
889
+ } else {
890
+ // TODO: switch to exhaustive checks
891
+ diag.warn(`Unsupported tool type: ${toolCall.type}`);
887
892
  }
888
893
  });
889
894
  }
@@ -1,3 +1,4 @@
1
+ import { safelyJSONStringify } from "@arizeai/openinference-core";
1
2
  import { SemanticConventions } from "@arizeai/openinference-semantic-conventions";
2
3
 
3
4
  import { Attributes } from "@opentelemetry/api";
@@ -44,8 +45,15 @@ function getResponseItemAttributes(
44
45
  attributes[`${prefix}${SemanticConventions.MESSAGE_ROLE}`] = "tool";
45
46
  attributes[`${prefix}${SemanticConventions.MESSAGE_TOOL_CALL_ID}`] =
46
47
  item.call_id;
47
- attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] =
48
- item.output;
48
+ if (typeof item.output === "string") {
49
+ attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] =
50
+ item.output;
51
+ } else {
52
+ // TODO(2410): figure out how to serialize the list of tools
53
+ attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] =
54
+ safelyJSONStringify(item.output) || undefined;
55
+ }
56
+
49
57
  break;
50
58
  }
51
59
  case "reasoning": {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // this is an auto-generated file. see js/scripts/version-update.js
2
- export const VERSION = "3.2.5";
2
+ export const VERSION = "4.0.5";