@arizeai/openinference-instrumentation-beeai 1.5.5 → 1.5.11

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.
Files changed (99) hide show
  1. package/dist/esm/config.d.ts +2 -2
  2. package/dist/esm/config.d.ts.map +1 -1
  3. package/dist/esm/config.js +1 -2
  4. package/dist/esm/config.js.map +1 -1
  5. package/dist/esm/helpers/buildTraceTree.d.ts +4 -4
  6. package/dist/esm/helpers/buildTraceTree.d.ts.map +1 -1
  7. package/dist/esm/helpers/buildTraceTree.js +2 -2
  8. package/dist/esm/helpers/buildTraceTree.js.map +1 -1
  9. package/dist/esm/helpers/create-span.d.ts +2 -2
  10. package/dist/esm/helpers/create-span.d.ts.map +1 -1
  11. package/dist/esm/helpers/create-span.js.map +1 -1
  12. package/dist/esm/helpers/getSerializedObjectSafe.d.ts +1 -1
  13. package/dist/esm/helpers/getSerializedObjectSafe.d.ts.map +1 -1
  14. package/dist/esm/helpers/getSerializedObjectSafe.js +5 -17
  15. package/dist/esm/helpers/getSerializedObjectSafe.js.map +1 -1
  16. package/dist/esm/helpers/traceSerializer.d.ts +1 -1
  17. package/dist/esm/helpers/traceSerializer.d.ts.map +1 -1
  18. package/dist/esm/helpers/traceSerializer.js +2 -8
  19. package/dist/esm/helpers/traceSerializer.js.map +1 -1
  20. package/dist/esm/instrumentation.d.ts +5 -4
  21. package/dist/esm/instrumentation.d.ts.map +1 -1
  22. package/dist/esm/instrumentation.js +3 -3
  23. package/dist/esm/instrumentation.js.map +1 -1
  24. package/dist/esm/middleware.d.ts +2 -2
  25. package/dist/esm/middleware.d.ts.map +1 -1
  26. package/dist/esm/middleware.js +14 -23
  27. package/dist/esm/middleware.js.map +1 -1
  28. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  29. package/dist/esm/types.d.ts +1 -1
  30. package/dist/esm/types.d.ts.map +1 -1
  31. package/dist/esnext/config.d.ts +2 -2
  32. package/dist/esnext/config.d.ts.map +1 -1
  33. package/dist/esnext/config.js +1 -2
  34. package/dist/esnext/config.js.map +1 -1
  35. package/dist/esnext/helpers/buildTraceTree.d.ts +4 -4
  36. package/dist/esnext/helpers/buildTraceTree.d.ts.map +1 -1
  37. package/dist/esnext/helpers/buildTraceTree.js +2 -2
  38. package/dist/esnext/helpers/buildTraceTree.js.map +1 -1
  39. package/dist/esnext/helpers/create-span.d.ts +2 -2
  40. package/dist/esnext/helpers/create-span.d.ts.map +1 -1
  41. package/dist/esnext/helpers/create-span.js.map +1 -1
  42. package/dist/esnext/helpers/getSerializedObjectSafe.d.ts +1 -1
  43. package/dist/esnext/helpers/getSerializedObjectSafe.d.ts.map +1 -1
  44. package/dist/esnext/helpers/getSerializedObjectSafe.js +5 -17
  45. package/dist/esnext/helpers/getSerializedObjectSafe.js.map +1 -1
  46. package/dist/esnext/helpers/traceSerializer.d.ts +1 -1
  47. package/dist/esnext/helpers/traceSerializer.d.ts.map +1 -1
  48. package/dist/esnext/helpers/traceSerializer.js +2 -8
  49. package/dist/esnext/helpers/traceSerializer.js.map +1 -1
  50. package/dist/esnext/instrumentation.d.ts +5 -4
  51. package/dist/esnext/instrumentation.d.ts.map +1 -1
  52. package/dist/esnext/instrumentation.js +3 -3
  53. package/dist/esnext/instrumentation.js.map +1 -1
  54. package/dist/esnext/middleware.d.ts +2 -2
  55. package/dist/esnext/middleware.d.ts.map +1 -1
  56. package/dist/esnext/middleware.js +14 -22
  57. package/dist/esnext/middleware.js.map +1 -1
  58. package/dist/esnext/tsconfig.esnext.tsbuildinfo +1 -1
  59. package/dist/esnext/types.d.ts +1 -1
  60. package/dist/esnext/types.d.ts.map +1 -1
  61. package/dist/src/config.d.ts +2 -2
  62. package/dist/src/config.d.ts.map +1 -1
  63. package/dist/src/config.js +1 -2
  64. package/dist/src/config.js.map +1 -1
  65. package/dist/src/helpers/buildTraceTree.d.ts +4 -4
  66. package/dist/src/helpers/buildTraceTree.d.ts.map +1 -1
  67. package/dist/src/helpers/buildTraceTree.js +2 -2
  68. package/dist/src/helpers/buildTraceTree.js.map +1 -1
  69. package/dist/src/helpers/create-span.d.ts +2 -2
  70. package/dist/src/helpers/create-span.d.ts.map +1 -1
  71. package/dist/src/helpers/create-span.js.map +1 -1
  72. package/dist/src/helpers/getSerializedObjectSafe.d.ts +1 -1
  73. package/dist/src/helpers/getSerializedObjectSafe.d.ts.map +1 -1
  74. package/dist/src/helpers/getSerializedObjectSafe.js +5 -17
  75. package/dist/src/helpers/getSerializedObjectSafe.js.map +1 -1
  76. package/dist/src/helpers/traceSerializer.d.ts +1 -1
  77. package/dist/src/helpers/traceSerializer.d.ts.map +1 -1
  78. package/dist/src/helpers/traceSerializer.js +2 -8
  79. package/dist/src/helpers/traceSerializer.js.map +1 -1
  80. package/dist/src/instrumentation.d.ts +5 -4
  81. package/dist/src/instrumentation.d.ts.map +1 -1
  82. package/dist/src/instrumentation.js +3 -3
  83. package/dist/src/instrumentation.js.map +1 -1
  84. package/dist/src/middleware.d.ts +2 -2
  85. package/dist/src/middleware.d.ts.map +1 -1
  86. package/dist/src/middleware.js +14 -22
  87. package/dist/src/middleware.js.map +1 -1
  88. package/dist/src/types.d.ts +1 -1
  89. package/dist/src/types.d.ts.map +1 -1
  90. package/dist/tsconfig.tsbuildinfo +1 -1
  91. package/package.json +29 -28
  92. package/src/config.ts +5 -9
  93. package/src/helpers/buildTraceTree.ts +11 -24
  94. package/src/helpers/create-span.ts +4 -4
  95. package/src/helpers/getSerializedObjectSafe.ts +42 -76
  96. package/src/helpers/traceSerializer.ts +2 -12
  97. package/src/instrumentation.ts +20 -50
  98. package/src/middleware.ts +36 -74
  99. package/src/types.ts +1 -1
package/package.json CHANGED
@@ -1,56 +1,57 @@
1
1
  {
2
2
  "name": "@arizeai/openinference-instrumentation-beeai",
3
- "version": "1.5.5",
3
+ "version": "1.5.11",
4
+ "private": false,
5
+ "description": "OpenInference Instrumentation for BeeAI framework",
6
+ "keywords": [
7
+ "beeai",
8
+ "opentelemetry",
9
+ "tracing"
10
+ ],
4
11
  "license": "Apache-2.0",
5
12
  "author": "gallas.milan@gmail.com",
6
- "description": "OpenInference Instrumentation for BeeAI framework",
7
- "private": false,
8
- "main": "dist/src/index.js",
9
- "module": "dist/esm/index.js",
10
- "esnext": "dist/esnext/index.js",
11
- "types": "dist/src/index.d.ts",
12
13
  "repository": {
13
14
  "type": "git",
14
15
  "url": "https://github.com/Arize-ai/openinference.git"
15
16
  },
17
+ "files": [
18
+ "dist",
19
+ "src"
20
+ ],
21
+ "main": "dist/src/index.js",
22
+ "module": "dist/esm/index.js",
23
+ "types": "dist/src/index.d.ts",
24
+ "esnext": "dist/esnext/index.js",
16
25
  "exports": {
17
26
  ".": {
18
27
  "import": "./dist/esm/index.js",
19
28
  "require": "./dist/src/index.js"
20
29
  }
21
30
  },
22
- "files": [
23
- "dist",
24
- "src"
25
- ],
26
- "keywords": [
27
- "beeai",
28
- "opentelemetry",
29
- "tracing"
30
- ],
31
31
  "dependencies": {
32
32
  "@opentelemetry/api": "^1.9.0",
33
33
  "@opentelemetry/instrumentation": "^0.57.1",
34
34
  "remeda": "^2.20.2",
35
35
  "semver": "^7.7.0",
36
- "@arizeai/openinference-core": "2.0.0",
37
- "@arizeai/openinference-semantic-conventions": "2.1.2"
38
- },
39
- "peerDependencies": {
40
- "beeai-framework": "^0.1.13"
36
+ "@arizeai/openinference-core": "2.0.6",
37
+ "@arizeai/openinference-semantic-conventions": "2.2.0"
41
38
  },
42
39
  "devDependencies": {
43
- "@types/node": "^20.14.11",
44
- "@types/semver": "7.7.0",
45
- "beeai-framework": "^0.1.13",
46
- "import-in-the-middle": "^1.13.0",
47
40
  "@opentelemetry/exporter-trace-otlp-proto": "^0.50.0",
48
41
  "@opentelemetry/resources": "^1.30.1",
49
42
  "@opentelemetry/sdk-node": "^0.57.1",
50
43
  "@opentelemetry/sdk-trace-node": "^1.30.1",
51
44
  "@opentelemetry/semantic-conventions": "^1.28.0",
52
- "vitest": "^4.0.3",
53
- "ts-node": "^10.9.2"
45
+ "@types/node": "^20.14.11",
46
+ "@types/semver": "7.7.0",
47
+ "beeai-framework": "^0.1.13",
48
+ "import-in-the-middle": "^1.13.0",
49
+ "ts-node": "^10.9.2",
50
+ "typescript": "^5.8.3",
51
+ "vitest": "^4.0.3"
52
+ },
53
+ "peerDependencies": {
54
+ "beeai-framework": "^0.1.13"
54
55
  },
55
56
  "optionalDependencies": {
56
57
  "ollama": "^0.5.12"
@@ -60,6 +61,6 @@
60
61
  "build": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json && tsc-alias -p tsconfig.esm.json",
61
62
  "postbuild": "echo '{\"type\": \"module\"}' > ./dist/esm/package.json && rimraf dist/test",
62
63
  "type:check": "tsc --noEmit",
63
- "test": "vitest --typecheck"
64
+ "test": "vitest run --typecheck"
64
65
  }
65
66
  }
package/src/config.ts CHANGED
@@ -15,18 +15,14 @@
15
15
  */
16
16
 
17
17
  import type { ReActAgentCallbacks } from "beeai-framework/agents/react/types";
18
- import { ChatModelEvents } from "beeai-framework/backend/chat";
19
- import { ToolEvents } from "beeai-framework/tools/base";
18
+ import type { ChatModelEvents } from "beeai-framework/backend/chat";
19
+ import type { ToolEvents } from "beeai-framework/tools/base";
20
20
 
21
- export const INSTRUMENTATION_IGNORED_KEYS = process.env
22
- .BEE_FRAMEWORK_INSTRUMENTATION_IGNORED_KEYS
23
- ? process.env.BEE_FRAMEWORK_INSTRUMENTATION_IGNORED_KEYS.split(",").filter(
24
- Boolean,
25
- )
21
+ export const INSTRUMENTATION_IGNORED_KEYS = process.env.BEE_FRAMEWORK_INSTRUMENTATION_IGNORED_KEYS
22
+ ? process.env.BEE_FRAMEWORK_INSTRUMENTATION_IGNORED_KEYS.split(",").filter(Boolean)
26
23
  : [];
27
24
 
28
- export const partialUpdateEventName: keyof ReActAgentCallbacks =
29
- "partialUpdate";
25
+ export const partialUpdateEventName: keyof ReActAgentCallbacks = "partialUpdate";
30
26
  export const updateEventName: keyof ReActAgentCallbacks = "update";
31
27
  export const toolErrorEventName: keyof ReActAgentCallbacks = "toolError";
32
28
  export const toolStartEventName: keyof ReActAgentCallbacks = "toolStart";
@@ -1,13 +1,14 @@
1
- import { OITracer } from "@arizeai/openinference-core";
1
+ import type { TimeInput } from "@opentelemetry/api";
2
+ import { SpanStatusCode } from "@opentelemetry/api";
3
+
4
+ import type { OITracer } from "@arizeai/openinference-core";
2
5
  import {
3
6
  OpenInferenceSpanKind,
4
7
  SemanticConventions,
5
8
  } from "@arizeai/openinference-semantic-conventions";
6
9
 
7
- import { SpanStatusCode, TimeInput } from "@opentelemetry/api";
8
-
9
10
  import { startEventName, successEventName } from "../config";
10
- import { FrameworkSpan, GeneratedResponse } from "../types";
11
+ import type { FrameworkSpan, GeneratedResponse } from "../types";
11
12
 
12
13
  interface BuiltTraceTreeProps {
13
14
  tracer: OITracer;
@@ -87,12 +88,8 @@ function buildAgentMainSpanData(data: BuiltTraceTreeProps["data"]) {
87
88
  }
88
89
 
89
90
  function buildToolMainSpanData(data: BuiltTraceTreeProps["data"]) {
90
- const startBeeaiSpan = data.spans.find(
91
- (span) => span.name === startEventName,
92
- );
93
- const successBeeeaiSpan = data.spans.find(
94
- (span) => span.name === successEventName,
95
- );
91
+ const startBeeaiSpan = data.spans.find((span) => span.name === startEventName);
92
+ const successBeeeaiSpan = data.spans.find((span) => span.name === successEventName);
96
93
 
97
94
  return {
98
95
  ...(startBeeaiSpan && {
@@ -109,12 +106,8 @@ function buildToolMainSpanData(data: BuiltTraceTreeProps["data"]) {
109
106
  }
110
107
 
111
108
  function buildLLMMainSpanData(data: BuiltTraceTreeProps["data"]) {
112
- const startBeeaiSpan = data.spans.find(
113
- (span) => span.name === startEventName,
114
- );
115
- const successBeeeaiSpan = data.spans.find(
116
- (span) => span.name === successEventName,
117
- );
109
+ const startBeeaiSpan = data.spans.find((span) => span.name === startEventName);
110
+ const successBeeeaiSpan = data.spans.find((span) => span.name === successEventName);
118
111
 
119
112
  if (!startBeeaiSpan && !successBeeeaiSpan) return {};
120
113
 
@@ -135,9 +128,7 @@ function buildLLMMainSpanData(data: BuiltTraceTreeProps["data"]) {
135
128
  }),
136
129
  ...(successBeeeaiSpan && {
137
130
  [SemanticConventions.OUTPUT_MIME_TYPE]:
138
- successBeeeaiSpan.attributes.data?.[
139
- SemanticConventions.OUTPUT_MIME_TYPE
140
- ],
131
+ successBeeeaiSpan.attributes.data?.[SemanticConventions.OUTPUT_MIME_TYPE],
141
132
  [SemanticConventions.OUTPUT_VALUE]:
142
133
  successBeeeaiSpan.attributes.data?.[SemanticConventions.OUTPUT_VALUE],
143
134
  }),
@@ -146,11 +137,7 @@ function buildLLMMainSpanData(data: BuiltTraceTreeProps["data"]) {
146
137
  };
147
138
  }
148
139
 
149
- export function buildTraceTree({
150
- tracer,
151
- data,
152
- mainSpanKind,
153
- }: BuiltTraceTreeProps) {
140
+ export function buildTraceTree({ tracer, data, mainSpanKind }: BuiltTraceTreeProps) {
154
141
  const computedData =
155
142
  mainSpanKind === OpenInferenceSpanKind.AGENT
156
143
  ? buildAgentMainSpanData(data)
@@ -14,12 +14,12 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { SpanStatusCode, TimeInput } from "@opentelemetry/api";
18
-
19
- import { FrameworkSpan } from "../types";
20
-
17
+ import type { TimeInput } from "@opentelemetry/api";
18
+ import { SpanStatusCode } from "@opentelemetry/api";
21
19
  import { isEmpty } from "remeda";
22
20
 
21
+ import type { FrameworkSpan } from "../types";
22
+
23
23
  interface CreateSpanProps {
24
24
  id: string;
25
25
  name: string;
@@ -14,6 +14,18 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ import { diag } from "@opentelemetry/api";
18
+ import { BaseAgent } from "beeai-framework/agents/base";
19
+ import type { ReActAgentCallbacks } from "beeai-framework/agents/react/types";
20
+ import type { ChatModelEvents } from "beeai-framework/backend/chat";
21
+ import { ChatModel } from "beeai-framework/backend/chat";
22
+ import type { Message, MessageContentPart } from "beeai-framework/backend/message";
23
+ import type { EventMeta, InferCallbackValue } from "beeai-framework/emitter/types";
24
+ import { getProp } from "beeai-framework/internals/helpers/object";
25
+ import { Serializable } from "beeai-framework/internals/serializable";
26
+ import type { ToolEvents } from "beeai-framework/tools/base";
27
+ import { Tool } from "beeai-framework/tools/base";
28
+
17
29
  import {
18
30
  LLMAttributePostfixes,
19
31
  MessageAttributePostfixes,
@@ -23,8 +35,6 @@ import {
23
35
  SemanticConventions,
24
36
  } from "@arizeai/openinference-semantic-conventions";
25
37
 
26
- import { diag } from "@opentelemetry/api";
27
-
28
38
  import {
29
39
  errorEventName,
30
40
  errorLLMEventName,
@@ -47,18 +57,7 @@ import {
47
57
  updateEventName,
48
58
  } from "../config";
49
59
 
50
- import { BaseAgent } from "beeai-framework/agents/base";
51
- import type { ReActAgentCallbacks } from "beeai-framework/agents/react/types";
52
- import { ChatModel, ChatModelEvents } from "beeai-framework/backend/chat";
53
- import { Message, MessageContentPart } from "beeai-framework/backend/message";
54
- import { EventMeta, InferCallbackValue } from "beeai-framework/emitter/types";
55
- import { getProp } from "beeai-framework/internals/helpers/object";
56
- import { Serializable } from "beeai-framework/internals/serializable";
57
- import { Tool, ToolEvents } from "beeai-framework/tools/base";
58
-
59
- function parserLLMInputMessages(
60
- messages: readonly Message<MessageContentPart, string>[],
61
- ) {
60
+ function parserLLMInputMessages(messages: readonly Message<MessageContentPart, string>[]) {
62
61
  return messages.reduce(
63
62
  (acc, item, key) => ({
64
63
  ...acc,
@@ -74,9 +73,7 @@ function parserLLMInputMessages(
74
73
  );
75
74
  }
76
75
 
77
- function parseLLMOutputMessages(
78
- messages: readonly Message<MessageContentPart, string>[],
79
- ) {
76
+ function parseLLMOutputMessages(messages: readonly Message<MessageContentPart, string>[]) {
80
77
  return messages.reduce(
81
78
  (acc, item, key) => ({
82
79
  ...acc,
@@ -92,31 +89,23 @@ function parseLLMOutputMessages(
92
89
  );
93
90
  }
94
91
 
95
- export function getSerializedObjectSafe(
96
- dataObject: unknown,
97
- meta: EventMeta<unknown>,
98
- ) {
92
+ export function getSerializedObjectSafe(dataObject: unknown, meta: EventMeta<unknown>) {
99
93
  try {
100
94
  // agent events
101
95
  if (
102
- [
103
- startEventName,
104
- successEventName,
105
- errorEventName,
106
- retryEventName,
107
- ].includes(meta.name as keyof ReActAgentCallbacks) &&
96
+ [startEventName, successEventName, errorEventName, retryEventName].includes(
97
+ meta.name as keyof ReActAgentCallbacks,
98
+ ) &&
108
99
  meta.creator instanceof BaseAgent
109
100
  ) {
110
- const { meta, tools, memory, error, data } =
111
- dataObject as InferCallbackValue<
112
- | ReActAgentCallbacks["start"]
113
- | ReActAgentCallbacks["error"]
114
- | ReActAgentCallbacks["success"]
115
- | ReActAgentCallbacks["retry"]
116
- >;
101
+ const { meta, tools, memory, error, data } = dataObject as InferCallbackValue<
102
+ | ReActAgentCallbacks["start"]
103
+ | ReActAgentCallbacks["error"]
104
+ | ReActAgentCallbacks["success"]
105
+ | ReActAgentCallbacks["retry"]
106
+ >;
117
107
  return {
118
- [SemanticConventions.OPENINFERENCE_SPAN_KIND]:
119
- OpenInferenceSpanKind.AGENT,
108
+ [SemanticConventions.OPENINFERENCE_SPAN_KIND]: OpenInferenceSpanKind.AGENT,
120
109
  iteration: meta?.iteration,
121
110
  ...(tools?.length > 0 && {
122
111
  [SemanticConventions.LLM_TOOLS]: tools.map((tool) => ({
@@ -143,9 +132,7 @@ export function getSerializedObjectSafe(
143
132
 
144
133
  // update events
145
134
  if (
146
- [updateEventName, partialUpdateEventName].includes(
147
- meta.name as keyof ReActAgentCallbacks,
148
- )
135
+ [updateEventName, partialUpdateEventName].includes(meta.name as keyof ReActAgentCallbacks)
149
136
  ) {
150
137
  const { data } = dataObject as InferCallbackValue<
151
138
  ReActAgentCallbacks["partialUpdate"] | ReActAgentCallbacks["update"]
@@ -153,16 +140,13 @@ export function getSerializedObjectSafe(
153
140
 
154
141
  const output = data?.final_answer || data?.tool_output;
155
142
  return {
156
- [SemanticConventions.OPENINFERENCE_SPAN_KIND]:
157
- OpenInferenceSpanKind.AGENT,
143
+ [SemanticConventions.OPENINFERENCE_SPAN_KIND]: OpenInferenceSpanKind.AGENT,
158
144
  thought: data.thought,
159
145
  ...(data?.tool_name && {
160
146
  [SemanticConventions.TOOL_NAME]: data.tool_name,
161
147
  }),
162
148
  ...(data?.tool_input && {
163
- [SemanticConventions.TOOL_PARAMETERS]: JSON.stringify(
164
- data.tool_input,
165
- ),
149
+ [SemanticConventions.TOOL_PARAMETERS]: JSON.stringify(data.tool_input),
166
150
  }),
167
151
  ...(output && {
168
152
  [SemanticConventions.OUTPUT_MIME_TYPE]: MimeType.JSON,
@@ -186,8 +170,7 @@ export function getSerializedObjectSafe(
186
170
  const output: any = data?.result && data.result.createSnapshot();
187
171
 
188
172
  return {
189
- [SemanticConventions.OPENINFERENCE_SPAN_KIND]:
190
- OpenInferenceSpanKind.TOOL,
173
+ [SemanticConventions.OPENINFERENCE_SPAN_KIND]: OpenInferenceSpanKind.TOOL,
191
174
  thought: data?.iteration?.thought,
192
175
  ...(data?.input
193
176
  ? {
@@ -223,23 +206,16 @@ export function getSerializedObjectSafe(
223
206
  ) {
224
207
  if (!dataObject) {
225
208
  return {
226
- [SemanticConventions.OPENINFERENCE_SPAN_KIND]:
227
- OpenInferenceSpanKind.TOOL,
209
+ [SemanticConventions.OPENINFERENCE_SPAN_KIND]: OpenInferenceSpanKind.TOOL,
228
210
  };
229
211
  }
230
212
  const { input, output, error } = dataObject as InferCallbackValue<
231
- | ToolEvents["start"]
232
- | ToolEvents["success"]
233
- | ToolEvents["retry"]
234
- | ToolEvents["error"]
213
+ ToolEvents["start"] | ToolEvents["success"] | ToolEvents["retry"] | ToolEvents["error"]
235
214
  >;
236
215
 
237
216
  return {
238
- [SemanticConventions.OPENINFERENCE_SPAN_KIND]:
239
- OpenInferenceSpanKind.TOOL,
240
- ...(input
241
- ? { [SemanticConventions.TOOL_PARAMETERS]: JSON.stringify(input) }
242
- : {}),
217
+ [SemanticConventions.OPENINFERENCE_SPAN_KIND]: OpenInferenceSpanKind.TOOL,
218
+ ...(input ? { [SemanticConventions.TOOL_PARAMETERS]: JSON.stringify(input) } : {}),
243
219
  ...(output && {
244
220
  [SemanticConventions.OUTPUT_VALUE]: JSON.stringify(output),
245
221
  }),
@@ -253,12 +229,9 @@ export function getSerializedObjectSafe(
253
229
 
254
230
  // llm events
255
231
  if (
256
- [
257
- successLLMEventName,
258
- startLLMEventName,
259
- errorLLMEventName,
260
- newTokenLLMEventName,
261
- ].includes(meta.name as keyof ChatModelEvents) &&
232
+ [successLLMEventName, startLLMEventName, errorLLMEventName, newTokenLLMEventName].includes(
233
+ meta.name as keyof ChatModelEvents,
234
+ ) &&
262
235
  meta.creator instanceof ChatModel
263
236
  ) {
264
237
  const { value, input, error } = dataObject as InferCallbackValue<
@@ -270,19 +243,15 @@ export function getSerializedObjectSafe(
270
243
 
271
244
  const creator = meta.creator.createSnapshot();
272
245
  return {
273
- [SemanticConventions.OPENINFERENCE_SPAN_KIND]:
274
- OpenInferenceSpanKind.LLM,
246
+ [SemanticConventions.OPENINFERENCE_SPAN_KIND]: OpenInferenceSpanKind.LLM,
275
247
  ...(value?.usage?.completionTokens && {
276
- [SemanticConventions.LLM_TOKEN_COUNT_COMPLETION]:
277
- value?.usage?.completionTokens,
248
+ [SemanticConventions.LLM_TOKEN_COUNT_COMPLETION]: value?.usage?.completionTokens,
278
249
  }),
279
250
  ...(value?.usage?.promptTokens && {
280
- [SemanticConventions.LLM_TOKEN_COUNT_PROMPT]:
281
- value?.usage?.promptTokens,
251
+ [SemanticConventions.LLM_TOKEN_COUNT_PROMPT]: value?.usage?.promptTokens,
282
252
  }),
283
253
  ...(value?.usage?.totalTokens && {
284
- [SemanticConventions.LLM_TOKEN_COUNT_TOTAL]:
285
- value?.usage?.totalTokens,
254
+ [SemanticConventions.LLM_TOKEN_COUNT_TOTAL]: value?.usage?.totalTokens,
286
255
  }),
287
256
  ...(input?.messages.length > 0 && {
288
257
  [SemanticConventions.INPUT_MIME_TYPE]: MimeType.JSON,
@@ -310,16 +279,13 @@ export function getSerializedObjectSafe(
310
279
  creator.modelId,
311
280
  }),
312
281
  ...(creator?.parameters && {
313
- [SemanticConventions.LLM_INVOCATION_PARAMETERS]: JSON.stringify(
314
- creator.parameters,
315
- ),
282
+ [SemanticConventions.LLM_INVOCATION_PARAMETERS]: JSON.stringify(creator.parameters),
316
283
  }),
317
284
  };
318
285
  }
319
286
  if (meta.name === finishLLMEventName && meta.creator instanceof ChatModel) {
320
287
  return {
321
- [SemanticConventions.OPENINFERENCE_SPAN_KIND]:
322
- OpenInferenceSpanKind.LLM,
288
+ [SemanticConventions.OPENINFERENCE_SPAN_KIND]: OpenInferenceSpanKind.LLM,
323
289
  };
324
290
  }
325
291
 
@@ -14,19 +14,9 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- const DEFAULT_IGNORE_KEYS = [
18
- "emitter",
19
- "logger",
20
- "tokens",
21
- "createdBy",
22
- "client",
23
- ];
17
+ const DEFAULT_IGNORE_KEYS = ["emitter", "logger", "tokens", "createdBy", "client"];
24
18
 
25
- export function traceSerializer({
26
- ignored_keys = [],
27
- }: {
28
- ignored_keys?: string[];
29
- }) {
19
+ export function traceSerializer({ ignored_keys = [] }: { ignored_keys?: string[] }) {
30
20
  const mergedIgnoreKeys = new Set([...DEFAULT_IGNORE_KEYS, ...ignored_keys]);
31
21
 
32
22
  return (body: object) =>
@@ -1,19 +1,20 @@
1
- import { OITracer, TraceConfigOptions } from "@arizeai/openinference-core";
2
- import { OpenInferenceSpanKind } from "@arizeai/openinference-semantic-conventions";
3
-
4
- import { diag, Tracer, TracerProvider } from "@opentelemetry/api";
1
+ import type { Tracer, TracerProvider } from "@opentelemetry/api";
2
+ import { diag } from "@opentelemetry/api";
3
+ import type { InstrumentationConfig } from "@opentelemetry/instrumentation";
5
4
  import {
6
5
  InstrumentationBase,
7
- InstrumentationConfig,
8
6
  InstrumentationNodeModuleDefinition,
9
7
  } from "@opentelemetry/instrumentation";
10
-
11
- import { createTelemetryMiddleware } from "./middleware";
12
-
13
8
  import { Version } from "beeai-framework";
14
- import * as bee from "beeai-framework";
9
+ import type * as bee from "beeai-framework";
15
10
  import { satisfies } from "semver";
16
11
 
12
+ import type { TraceConfigOptions } from "@arizeai/openinference-core";
13
+ import { OITracer } from "@arizeai/openinference-core";
14
+ import { OpenInferenceSpanKind } from "@arizeai/openinference-semantic-conventions";
15
+
16
+ import { createTelemetryMiddleware } from "./middleware";
17
+
17
18
  const MODULE_NAME = "beeai-framework";
18
19
 
19
20
  const INSTRUMENTATION_NAME = "@arizeai/openinference-instrumentation-beeai";
@@ -61,16 +62,11 @@ export class BeeAIInstrumentation extends InstrumentationBase {
61
62
  */
62
63
  tracerProvider?: TracerProvider;
63
64
  } = {}) {
64
- super(
65
- INSTRUMENTATION_NAME,
66
- Version,
67
- Object.assign({}, instrumentationConfig),
68
- );
65
+ super(INSTRUMENTATION_NAME, Version, Object.assign({}, instrumentationConfig));
69
66
  this.tracerProvider = tracerProvider;
70
67
  this.traceConfig = traceConfig;
71
68
  this.oiTracer = new OITracer({
72
- tracer:
73
- this.tracerProvider?.getTracer(INSTRUMENTATION_NAME) ?? this.tracer,
69
+ tracer: this.tracerProvider?.getTracer(INSTRUMENTATION_NAME) ?? this.tracer,
74
70
  traceConfig,
75
71
  });
76
72
  }
@@ -91,9 +87,7 @@ export class BeeAIInstrumentation extends InstrumentationBase {
91
87
  * @param {openai} module
92
88
  */
93
89
  manuallyInstrument(module: typeof bee) {
94
- if (
95
- !INSTRUMENTS.some((instrument) => satisfies(module.Version, instrument))
96
- ) {
90
+ if (!INSTRUMENTS.some((instrument) => satisfies(module.Version, instrument))) {
97
91
  const supportedVersionsString = `beeai-framework ["${INSTRUMENTS.join(',"')}"]`;
98
92
  diag.warn(
99
93
  `DependencyConflict: requested: '${supportedVersionsString}' but found: 'beeai-framework "${module.Version}"'`,
@@ -123,9 +117,7 @@ export class BeeAIInstrumentation extends InstrumentationBase {
123
117
 
124
118
  private patch(module: typeof bee & { openInferencePatched?: boolean }) {
125
119
  if (!module?.BaseAgent) {
126
- diag.warn(
127
- "[BeeaiInstrumentation] BaseAgent not found, skipping instrumentation.",
128
- );
120
+ diag.warn("[BeeaiInstrumentation] BaseAgent not found, skipping instrumentation.");
129
121
  return module;
130
122
  }
131
123
 
@@ -142,9 +134,7 @@ export class BeeAIInstrumentation extends InstrumentationBase {
142
134
  return function wrappedMethod(this: unknown, ...args: unknown[]) {
143
135
  const returned = original.apply(this, args);
144
136
  if (returned?.middleware) {
145
- returned.middleware(
146
- createTelemetryMiddleware(instrumentation.oiTracer, mainSpanKind),
147
- );
137
+ returned.middleware(createTelemetryMiddleware(instrumentation.oiTracer, mainSpanKind));
148
138
  }
149
139
  return returned;
150
140
  };
@@ -155,47 +145,27 @@ export class BeeAIInstrumentation extends InstrumentationBase {
155
145
  const instrumentation: BeeAIInstrumentation = this;
156
146
 
157
147
  this._wrap(module.BaseAgent.prototype, "run", (original) =>
158
- createWrappedMethod(
159
- instrumentation,
160
- original,
161
- OpenInferenceSpanKind.AGENT,
162
- ),
148
+ createWrappedMethod(instrumentation, original, OpenInferenceSpanKind.AGENT),
163
149
  );
164
150
 
165
151
  // tool instrumentation support
166
152
  if (module.Tool) {
167
153
  this._wrap(module.Tool.prototype, "run", (original) =>
168
- createWrappedMethod(
169
- instrumentation,
170
- original,
171
- OpenInferenceSpanKind.TOOL,
172
- ),
154
+ createWrappedMethod(instrumentation, original, OpenInferenceSpanKind.TOOL),
173
155
  );
174
156
  }
175
157
  // model instrumentation support
176
158
  if (module.ChatModel) {
177
159
  this._wrap(module.ChatModel.prototype, "create", (original) =>
178
- createWrappedMethod(
179
- instrumentation,
180
- original,
181
- OpenInferenceSpanKind.LLM,
182
- ),
160
+ createWrappedMethod(instrumentation, original, OpenInferenceSpanKind.LLM),
183
161
  );
184
162
  this._wrap(module.ChatModel.prototype, "createStructure", (original) =>
185
- createWrappedMethod(
186
- instrumentation,
187
- original,
188
- OpenInferenceSpanKind.LLM,
189
- ),
163
+ createWrappedMethod(instrumentation, original, OpenInferenceSpanKind.LLM),
190
164
  );
191
165
  }
192
166
  if (module.EmbeddingModel) {
193
167
  this._wrap(module.EmbeddingModel.prototype, "create", (original) =>
194
- createWrappedMethod(
195
- instrumentation,
196
- original,
197
- OpenInferenceSpanKind.EMBEDDING,
198
- ),
168
+ createWrappedMethod(instrumentation, original, OpenInferenceSpanKind.EMBEDDING),
199
169
  );
200
170
  }
201
171