@arizeai/openinference-instrumentation-beeai 1.1.0 → 1.1.2
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/dist/esm/helpers/getSerializedObjectSafe.d.ts.map +1 -1
- package/dist/esm/helpers/getSerializedObjectSafe.js +172 -165
- package/dist/esm/helpers/getSerializedObjectSafe.js.map +1 -1
- package/dist/esm/middleware.d.ts.map +1 -1
- package/dist/esm/middleware.js +89 -79
- package/dist/esm/middleware.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esnext/helpers/getSerializedObjectSafe.d.ts.map +1 -1
- package/dist/esnext/helpers/getSerializedObjectSafe.js +128 -121
- package/dist/esnext/helpers/getSerializedObjectSafe.js.map +1 -1
- package/dist/esnext/middleware.d.ts.map +1 -1
- package/dist/esnext/middleware.js +79 -69
- package/dist/esnext/middleware.js.map +1 -1
- package/dist/esnext/tsconfig.esnext.tsbuildinfo +1 -1
- package/dist/src/helpers/getSerializedObjectSafe.d.ts.map +1 -1
- package/dist/src/helpers/getSerializedObjectSafe.js +128 -121
- package/dist/src/helpers/getSerializedObjectSafe.js.map +1 -1
- package/dist/src/middleware.d.ts.map +1 -1
- package/dist/src/middleware.js +79 -69
- package/dist/src/middleware.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/helpers/getSerializedObjectSafe.ts +223 -214
- package/src/middleware.ts +103 -92
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arizeai/openinference-instrumentation-beeai",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "gallas.milan@gmail.com",
|
|
6
6
|
"description": "OpenInference Instrumentation for BeeAI framework",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"@arizeai/openinference-semantic-conventions": "1.0.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"beeai-framework": "^0.1.
|
|
39
|
+
"beeai-framework": "^0.1.9"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/jest": "^29.5.12",
|
|
43
43
|
"@types/node": "^20.14.11",
|
|
44
|
-
"beeai-framework": "^0.1.
|
|
44
|
+
"beeai-framework": "^0.1.9",
|
|
45
45
|
"import-in-the-middle": "^1.13.0",
|
|
46
46
|
"@opentelemetry/exporter-trace-otlp-proto": "^0.50.0",
|
|
47
47
|
"@opentelemetry/resources": "^1.30.1",
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { Serializable } from "beeai-framework/internals/serializable";
|
|
18
|
-
import { instrumentationLogger } from "beeai-framework/instrumentation/logger";
|
|
19
18
|
import { getProp } from "beeai-framework/internals/helpers/object";
|
|
20
19
|
import { EventMeta, InferCallbackValue } from "beeai-framework/emitter/types";
|
|
21
20
|
import type { ReActAgentCallbacks } from "beeai-framework/agents/react/types";
|
|
@@ -52,6 +51,7 @@ import {
|
|
|
52
51
|
SemanticConventions,
|
|
53
52
|
} from "@arizeai/openinference-semantic-conventions";
|
|
54
53
|
import { Tool, ToolEvents } from "beeai-framework/tools/base";
|
|
54
|
+
import { diag } from "@opentelemetry/api";
|
|
55
55
|
|
|
56
56
|
function parserLLMInputMessages(
|
|
57
57
|
messages: readonly Message<MessageContentPart, string>[],
|
|
@@ -93,233 +93,242 @@ export function getSerializedObjectSafe(
|
|
|
93
93
|
dataObject: unknown,
|
|
94
94
|
meta: EventMeta<unknown>,
|
|
95
95
|
) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
[SemanticConventions.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
96
|
+
try {
|
|
97
|
+
// agent events
|
|
98
|
+
if (
|
|
99
|
+
[
|
|
100
|
+
startEventName,
|
|
101
|
+
successEventName,
|
|
102
|
+
errorEventName,
|
|
103
|
+
retryEventName,
|
|
104
|
+
].includes(meta.name as keyof ReActAgentCallbacks) &&
|
|
105
|
+
meta.creator instanceof BaseAgent
|
|
106
|
+
) {
|
|
107
|
+
const { meta, tools, memory, error, data } =
|
|
108
|
+
dataObject as InferCallbackValue<
|
|
109
|
+
| ReActAgentCallbacks["start"]
|
|
110
|
+
| ReActAgentCallbacks["error"]
|
|
111
|
+
| ReActAgentCallbacks["success"]
|
|
112
|
+
| ReActAgentCallbacks["retry"]
|
|
113
|
+
>;
|
|
114
|
+
return {
|
|
115
|
+
[SemanticConventions.OPENINFERENCE_SPAN_KIND]:
|
|
116
|
+
OpenInferenceSpanKind.AGENT,
|
|
117
|
+
iteration: meta.iteration,
|
|
118
|
+
...(tools?.length > 0 && {
|
|
119
|
+
[SemanticConventions.LLM_TOOLS]: tools.map((tool) => ({
|
|
120
|
+
[SemanticConventions.TOOL_NAME]: tool.name,
|
|
121
|
+
[SemanticConventions.TOOL_DESCRIPTION]: tool.description,
|
|
122
|
+
"tool.options": tool.options,
|
|
123
|
+
})),
|
|
124
|
+
}),
|
|
125
|
+
...(memory?.messages.length > 0 && {
|
|
126
|
+
[SemanticConventions.INPUT_MIME_TYPE]: MimeType.JSON,
|
|
127
|
+
[SemanticConventions.INPUT_VALUE]: JSON.stringify(memory.messages),
|
|
128
|
+
}),
|
|
129
|
+
...(error && {
|
|
130
|
+
"exception.message": error.message,
|
|
131
|
+
"exception.stacktrace": error.stack,
|
|
132
|
+
"exception.type": error.name,
|
|
133
|
+
}),
|
|
134
|
+
...(data && {
|
|
135
|
+
[SemanticConventions.OUTPUT_MIME_TYPE]: MimeType.JSON,
|
|
136
|
+
[SemanticConventions.OUTPUT_VALUE]: JSON.stringify(data),
|
|
137
|
+
}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
136
140
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
// update events
|
|
142
|
+
if (
|
|
143
|
+
[updateEventName, partialUpdateEventName].includes(
|
|
144
|
+
meta.name as keyof ReActAgentCallbacks,
|
|
145
|
+
)
|
|
146
|
+
) {
|
|
147
|
+
const { data } = dataObject as InferCallbackValue<
|
|
148
|
+
ReActAgentCallbacks["partialUpdate"] | ReActAgentCallbacks["update"]
|
|
149
|
+
>;
|
|
146
150
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
151
|
+
const output = data?.final_answer || data?.tool_output;
|
|
152
|
+
return {
|
|
153
|
+
[SemanticConventions.OPENINFERENCE_SPAN_KIND]:
|
|
154
|
+
OpenInferenceSpanKind.AGENT,
|
|
155
|
+
thought: data.thought,
|
|
156
|
+
...(data?.tool_name && {
|
|
157
|
+
[SemanticConventions.TOOL_NAME]: data.tool_name,
|
|
158
|
+
}),
|
|
159
|
+
...(data?.tool_input && {
|
|
160
|
+
[SemanticConventions.TOOL_PARAMETERS]: JSON.stringify(
|
|
161
|
+
data.tool_input,
|
|
162
|
+
),
|
|
163
|
+
}),
|
|
164
|
+
...(output && {
|
|
165
|
+
[SemanticConventions.OUTPUT_MIME_TYPE]: MimeType.JSON,
|
|
166
|
+
[SemanticConventions.OUTPUT_VALUE]: output,
|
|
167
|
+
}),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
164
170
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
171
|
+
// tool events (from agent)
|
|
172
|
+
if (
|
|
173
|
+
[toolErrorEventName, toolStartEventName, toolSuccessEventName].includes(
|
|
174
|
+
meta.name as keyof ReActAgentCallbacks,
|
|
175
|
+
)
|
|
176
|
+
) {
|
|
177
|
+
const { data } = dataObject as InferCallbackValue<
|
|
178
|
+
| ReActAgentCallbacks["toolError"]
|
|
179
|
+
| ReActAgentCallbacks["toolStart"]
|
|
180
|
+
| ReActAgentCallbacks["toolSuccess"]
|
|
181
|
+
>;
|
|
182
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
183
|
+
const output: any = data?.result && data.result.createSnapshot();
|
|
178
184
|
|
|
179
|
-
return {
|
|
180
|
-
[SemanticConventions.OPENINFERENCE_SPAN_KIND]: OpenInferenceSpanKind.TOOL,
|
|
181
|
-
thought: data.iteration.thought,
|
|
182
|
-
...(data.input
|
|
183
|
-
? { [SemanticConventions.TOOL_PARAMETERS]: JSON.stringify(data.input) }
|
|
184
|
-
: {}),
|
|
185
|
-
...(data.tool.description && {
|
|
186
|
-
[SemanticConventions.TOOL_DESCRIPTION]: data.tool.description,
|
|
187
|
-
}),
|
|
188
|
-
...(data.tool.name && {
|
|
189
|
-
[SemanticConventions.TOOL_NAME]: data.tool.name,
|
|
190
|
-
}),
|
|
191
|
-
...(data.error && {
|
|
192
|
-
"exception.message": data.error.message,
|
|
193
|
-
"exception.stacktrace": data.error.stack,
|
|
194
|
-
"exception.type": data.error.name,
|
|
195
|
-
}),
|
|
196
|
-
...(output && {
|
|
197
|
-
[SemanticConventions.OUTPUT_VALUE]: JSON.stringify(output),
|
|
198
|
-
}),
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
// tool events native
|
|
202
|
-
if (
|
|
203
|
-
[
|
|
204
|
-
startToolEventName,
|
|
205
|
-
successToolEventName,
|
|
206
|
-
finishToolEventName,
|
|
207
|
-
errorToolEventName,
|
|
208
|
-
retryToolEventName,
|
|
209
|
-
].includes(meta.name as keyof ToolEvents) &&
|
|
210
|
-
meta.creator instanceof Tool
|
|
211
|
-
) {
|
|
212
|
-
if (!dataObject) {
|
|
213
185
|
return {
|
|
214
186
|
[SemanticConventions.OPENINFERENCE_SPAN_KIND]:
|
|
215
187
|
OpenInferenceSpanKind.TOOL,
|
|
188
|
+
thought: data.iteration.thought,
|
|
189
|
+
...(data?.input
|
|
190
|
+
? {
|
|
191
|
+
[SemanticConventions.TOOL_PARAMETERS]: JSON.stringify(data.input),
|
|
192
|
+
}
|
|
193
|
+
: {}),
|
|
194
|
+
...(data?.tool.description && {
|
|
195
|
+
[SemanticConventions.TOOL_DESCRIPTION]: data.tool.description,
|
|
196
|
+
}),
|
|
197
|
+
...(data?.tool.name && {
|
|
198
|
+
[SemanticConventions.TOOL_NAME]: data.tool.name,
|
|
199
|
+
}),
|
|
200
|
+
...(data?.error && {
|
|
201
|
+
"exception.message": data.error.message,
|
|
202
|
+
"exception.stacktrace": data.error.stack,
|
|
203
|
+
"exception.type": data.error.name,
|
|
204
|
+
}),
|
|
205
|
+
...(output && {
|
|
206
|
+
[SemanticConventions.OUTPUT_VALUE]: JSON.stringify(output),
|
|
207
|
+
}),
|
|
216
208
|
};
|
|
217
209
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
210
|
+
// tool events native
|
|
211
|
+
if (
|
|
212
|
+
[
|
|
213
|
+
startToolEventName,
|
|
214
|
+
successToolEventName,
|
|
215
|
+
finishToolEventName,
|
|
216
|
+
errorToolEventName,
|
|
217
|
+
retryToolEventName,
|
|
218
|
+
].includes(meta.name as keyof ToolEvents) &&
|
|
219
|
+
meta.creator instanceof Tool
|
|
220
|
+
) {
|
|
221
|
+
if (!dataObject) {
|
|
222
|
+
return {
|
|
223
|
+
[SemanticConventions.OPENINFERENCE_SPAN_KIND]:
|
|
224
|
+
OpenInferenceSpanKind.TOOL,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
const { input, output, error } = dataObject as InferCallbackValue<
|
|
228
|
+
| ToolEvents["start"]
|
|
229
|
+
| ToolEvents["success"]
|
|
230
|
+
| ToolEvents["retry"]
|
|
231
|
+
| ToolEvents["error"]
|
|
232
|
+
>;
|
|
224
233
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
234
|
+
return {
|
|
235
|
+
[SemanticConventions.OPENINFERENCE_SPAN_KIND]:
|
|
236
|
+
OpenInferenceSpanKind.TOOL,
|
|
237
|
+
...(input
|
|
238
|
+
? { [SemanticConventions.TOOL_PARAMETERS]: JSON.stringify(input) }
|
|
239
|
+
: {}),
|
|
240
|
+
...(output && {
|
|
241
|
+
[SemanticConventions.OUTPUT_VALUE]: JSON.stringify(output),
|
|
242
|
+
}),
|
|
243
|
+
...(error && {
|
|
244
|
+
"exception.message": error.message,
|
|
245
|
+
"exception.stacktrace": error.stack,
|
|
246
|
+
"exception.type": error.name,
|
|
247
|
+
}),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
240
250
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
251
|
+
// llm events
|
|
252
|
+
if (
|
|
253
|
+
[
|
|
254
|
+
successLLMEventName,
|
|
255
|
+
startLLMEventName,
|
|
256
|
+
errorLLMEventName,
|
|
257
|
+
newTokenLLMEventName,
|
|
258
|
+
].includes(meta.name as keyof ChatModelEvents) &&
|
|
259
|
+
meta.creator instanceof ChatModel
|
|
260
|
+
) {
|
|
261
|
+
const { value, input, error } = dataObject as InferCallbackValue<
|
|
262
|
+
| ChatModelEvents["success"]
|
|
263
|
+
| ChatModelEvents["start"]
|
|
264
|
+
| ChatModelEvents["error"]
|
|
265
|
+
| ChatModelEvents["newToken"]
|
|
266
|
+
>;
|
|
257
267
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
creator.providerId,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
creator.modelId,
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
268
|
+
const creator = meta.creator.createSnapshot();
|
|
269
|
+
return {
|
|
270
|
+
[SemanticConventions.OPENINFERENCE_SPAN_KIND]:
|
|
271
|
+
OpenInferenceSpanKind.LLM,
|
|
272
|
+
...(value?.usage?.completionTokens && {
|
|
273
|
+
[SemanticConventions.LLM_TOKEN_COUNT_COMPLETION]:
|
|
274
|
+
value?.usage?.completionTokens,
|
|
275
|
+
}),
|
|
276
|
+
...(value?.usage?.promptTokens && {
|
|
277
|
+
[SemanticConventions.LLM_TOKEN_COUNT_PROMPT]:
|
|
278
|
+
value?.usage?.promptTokens,
|
|
279
|
+
}),
|
|
280
|
+
...(value?.usage?.totalTokens && {
|
|
281
|
+
[SemanticConventions.LLM_TOKEN_COUNT_TOTAL]:
|
|
282
|
+
value?.usage?.totalTokens,
|
|
283
|
+
}),
|
|
284
|
+
...(input?.messages.length > 0 && {
|
|
285
|
+
[SemanticConventions.INPUT_MIME_TYPE]: MimeType.JSON,
|
|
286
|
+
[SemanticConventions.INPUT_VALUE]: JSON.stringify(input.messages),
|
|
287
|
+
...parserLLMInputMessages(input.messages),
|
|
288
|
+
}),
|
|
289
|
+
...(value?.messages.length > 0 && {
|
|
290
|
+
[SemanticConventions.OUTPUT_MIME_TYPE]: MimeType.JSON,
|
|
291
|
+
[SemanticConventions.OUTPUT_VALUE]: JSON.stringify(value.messages),
|
|
292
|
+
...parseLLMOutputMessages(value.messages),
|
|
293
|
+
}),
|
|
294
|
+
...(error && {
|
|
295
|
+
"exception.message": error.message,
|
|
296
|
+
"exception.stacktrace": error.stack,
|
|
297
|
+
"exception.type": error.name,
|
|
298
|
+
}),
|
|
299
|
+
...("providerId" in creator && {
|
|
300
|
+
[SemanticConventions.LLM_PROVIDER]: creator.providerId,
|
|
301
|
+
[`${SemanticAttributePrefixes.metadata}.${LLMAttributePostfixes.provider}`]:
|
|
302
|
+
creator.providerId,
|
|
303
|
+
}),
|
|
304
|
+
...("modelId" in creator && {
|
|
305
|
+
[SemanticConventions.LLM_MODEL_NAME]: creator.modelId,
|
|
306
|
+
[`${SemanticAttributePrefixes.metadata}.${LLMAttributePostfixes.model_name}`]:
|
|
307
|
+
creator.modelId,
|
|
308
|
+
}),
|
|
309
|
+
...(creator?.parameters && {
|
|
310
|
+
[SemanticConventions.LLM_INVOCATION_PARAMETERS]: JSON.stringify(
|
|
311
|
+
creator.parameters,
|
|
312
|
+
),
|
|
313
|
+
}),
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
if (meta.name === finishLLMEventName && meta.creator instanceof ChatModel) {
|
|
317
|
+
return {
|
|
318
|
+
[SemanticConventions.OPENINFERENCE_SPAN_KIND]:
|
|
319
|
+
OpenInferenceSpanKind.LLM,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
309
322
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
try {
|
|
323
|
+
// other events
|
|
324
|
+
const data = getProp(dataObject, ["data"], dataObject);
|
|
325
|
+
if (data instanceof Serializable) {
|
|
314
326
|
return { data: JSON.stringify(data.createSnapshot()), test: "hallo" };
|
|
315
|
-
} catch (e) {
|
|
316
|
-
instrumentationLogger.warn(
|
|
317
|
-
e,
|
|
318
|
-
"Invalid createSnapshot method in the Serializable class",
|
|
319
|
-
);
|
|
320
|
-
return null;
|
|
321
327
|
}
|
|
322
|
-
}
|
|
323
328
|
|
|
324
|
-
|
|
329
|
+
return { data: JSON.stringify(data) };
|
|
330
|
+
} catch (e) {
|
|
331
|
+
diag.warn("Failed to parse event data", e);
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
325
334
|
}
|