@arizeai/openinference-instrumentation-beeai 1.5.10 → 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.
- package/dist/esm/config.d.ts +2 -2
- package/dist/esm/config.d.ts.map +1 -1
- package/dist/esm/config.js +1 -2
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/helpers/buildTraceTree.d.ts +4 -4
- package/dist/esm/helpers/buildTraceTree.d.ts.map +1 -1
- package/dist/esm/helpers/buildTraceTree.js +2 -2
- package/dist/esm/helpers/buildTraceTree.js.map +1 -1
- package/dist/esm/helpers/create-span.d.ts +2 -2
- package/dist/esm/helpers/create-span.d.ts.map +1 -1
- package/dist/esm/helpers/create-span.js.map +1 -1
- package/dist/esm/helpers/getSerializedObjectSafe.d.ts +1 -1
- package/dist/esm/helpers/getSerializedObjectSafe.d.ts.map +1 -1
- package/dist/esm/helpers/getSerializedObjectSafe.js +5 -17
- package/dist/esm/helpers/getSerializedObjectSafe.js.map +1 -1
- package/dist/esm/helpers/traceSerializer.d.ts +1 -1
- package/dist/esm/helpers/traceSerializer.d.ts.map +1 -1
- package/dist/esm/helpers/traceSerializer.js +2 -8
- package/dist/esm/helpers/traceSerializer.js.map +1 -1
- package/dist/esm/instrumentation.d.ts +5 -4
- package/dist/esm/instrumentation.d.ts.map +1 -1
- package/dist/esm/instrumentation.js +3 -3
- package/dist/esm/instrumentation.js.map +1 -1
- package/dist/esm/middleware.d.ts +2 -2
- package/dist/esm/middleware.d.ts.map +1 -1
- package/dist/esm/middleware.js +14 -23
- package/dist/esm/middleware.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types.d.ts +1 -1
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esnext/config.d.ts +2 -2
- package/dist/esnext/config.d.ts.map +1 -1
- package/dist/esnext/config.js +1 -2
- package/dist/esnext/config.js.map +1 -1
- package/dist/esnext/helpers/buildTraceTree.d.ts +4 -4
- package/dist/esnext/helpers/buildTraceTree.d.ts.map +1 -1
- package/dist/esnext/helpers/buildTraceTree.js +2 -2
- package/dist/esnext/helpers/buildTraceTree.js.map +1 -1
- package/dist/esnext/helpers/create-span.d.ts +2 -2
- package/dist/esnext/helpers/create-span.d.ts.map +1 -1
- package/dist/esnext/helpers/create-span.js.map +1 -1
- package/dist/esnext/helpers/getSerializedObjectSafe.d.ts +1 -1
- package/dist/esnext/helpers/getSerializedObjectSafe.d.ts.map +1 -1
- package/dist/esnext/helpers/getSerializedObjectSafe.js +5 -17
- package/dist/esnext/helpers/getSerializedObjectSafe.js.map +1 -1
- package/dist/esnext/helpers/traceSerializer.d.ts +1 -1
- package/dist/esnext/helpers/traceSerializer.d.ts.map +1 -1
- package/dist/esnext/helpers/traceSerializer.js +2 -8
- package/dist/esnext/helpers/traceSerializer.js.map +1 -1
- package/dist/esnext/instrumentation.d.ts +5 -4
- package/dist/esnext/instrumentation.d.ts.map +1 -1
- package/dist/esnext/instrumentation.js +3 -3
- package/dist/esnext/instrumentation.js.map +1 -1
- package/dist/esnext/middleware.d.ts +2 -2
- package/dist/esnext/middleware.d.ts.map +1 -1
- package/dist/esnext/middleware.js +14 -22
- package/dist/esnext/middleware.js.map +1 -1
- package/dist/esnext/tsconfig.esnext.tsbuildinfo +1 -1
- package/dist/esnext/types.d.ts +1 -1
- package/dist/esnext/types.d.ts.map +1 -1
- package/dist/src/config.d.ts +2 -2
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +1 -2
- package/dist/src/config.js.map +1 -1
- package/dist/src/helpers/buildTraceTree.d.ts +4 -4
- package/dist/src/helpers/buildTraceTree.d.ts.map +1 -1
- package/dist/src/helpers/buildTraceTree.js +2 -2
- package/dist/src/helpers/buildTraceTree.js.map +1 -1
- package/dist/src/helpers/create-span.d.ts +2 -2
- package/dist/src/helpers/create-span.d.ts.map +1 -1
- package/dist/src/helpers/create-span.js.map +1 -1
- package/dist/src/helpers/getSerializedObjectSafe.d.ts +1 -1
- package/dist/src/helpers/getSerializedObjectSafe.d.ts.map +1 -1
- package/dist/src/helpers/getSerializedObjectSafe.js +5 -17
- package/dist/src/helpers/getSerializedObjectSafe.js.map +1 -1
- package/dist/src/helpers/traceSerializer.d.ts +1 -1
- package/dist/src/helpers/traceSerializer.d.ts.map +1 -1
- package/dist/src/helpers/traceSerializer.js +2 -8
- package/dist/src/helpers/traceSerializer.js.map +1 -1
- package/dist/src/instrumentation.d.ts +5 -4
- package/dist/src/instrumentation.d.ts.map +1 -1
- package/dist/src/instrumentation.js +3 -3
- package/dist/src/instrumentation.js.map +1 -1
- package/dist/src/middleware.d.ts +2 -2
- package/dist/src/middleware.d.ts.map +1 -1
- package/dist/src/middleware.js +14 -22
- package/dist/src/middleware.js.map +1 -1
- package/dist/src/types.d.ts +1 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -28
- package/src/config.ts +5 -9
- package/src/helpers/buildTraceTree.ts +11 -24
- package/src/helpers/create-span.ts +4 -4
- package/src/helpers/getSerializedObjectSafe.ts +42 -76
- package/src/helpers/traceSerializer.ts +2 -12
- package/src/instrumentation.ts +20 -50
- package/src/middleware.ts +36 -74
- package/src/types.ts +1 -1
package/src/middleware.ts
CHANGED
|
@@ -14,30 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { OITracer } from "@arizeai/openinference-core";
|
|
18
|
-
import {
|
|
19
|
-
OpenInferenceSpanKind,
|
|
20
|
-
SemanticConventions,
|
|
21
|
-
} from "@arizeai/openinference-semantic-conventions";
|
|
22
|
-
|
|
23
17
|
import { diag } from "@opentelemetry/api";
|
|
24
|
-
|
|
25
|
-
import { buildTraceTree } from "./helpers/buildTraceTree";
|
|
26
|
-
import { createSpan } from "./helpers/create-span";
|
|
27
|
-
import { getErrorSafe } from "./helpers/getErrorSafe";
|
|
28
|
-
import { getSerializedObjectSafe } from "./helpers/getSerializedObjectSafe";
|
|
29
|
-
import { IdNameManager } from "./helpers/idNameManager";
|
|
30
|
-
import { traceSerializer } from "./helpers/traceSerializer";
|
|
31
|
-
import {
|
|
32
|
-
errorLLMEventName,
|
|
33
|
-
finishLLMEventName,
|
|
34
|
-
INSTRUMENTATION_IGNORED_KEYS,
|
|
35
|
-
newTokenLLMEventName,
|
|
36
|
-
partialUpdateEventName,
|
|
37
|
-
successLLMEventName,
|
|
38
|
-
} from "./config";
|
|
39
|
-
import { FrameworkSpan, GeneratedResponse } from "./types";
|
|
40
|
-
|
|
41
18
|
import { BaseAgent } from "beeai-framework/agents/base";
|
|
42
19
|
import { ReActAgent } from "beeai-framework/agents/react/agent";
|
|
43
20
|
import type { ReActAgentCallbacks } from "beeai-framework/agents/react/types";
|
|
@@ -51,6 +28,26 @@ import { FrameworkError } from "beeai-framework/errors";
|
|
|
51
28
|
import { Version } from "beeai-framework/version";
|
|
52
29
|
import { findLast, isEmpty } from "remeda";
|
|
53
30
|
|
|
31
|
+
import type { OITracer } from "@arizeai/openinference-core";
|
|
32
|
+
import type { OpenInferenceSpanKind } from "@arizeai/openinference-semantic-conventions";
|
|
33
|
+
import { SemanticConventions } from "@arizeai/openinference-semantic-conventions";
|
|
34
|
+
|
|
35
|
+
import {
|
|
36
|
+
errorLLMEventName,
|
|
37
|
+
finishLLMEventName,
|
|
38
|
+
INSTRUMENTATION_IGNORED_KEYS,
|
|
39
|
+
newTokenLLMEventName,
|
|
40
|
+
partialUpdateEventName,
|
|
41
|
+
successLLMEventName,
|
|
42
|
+
} from "./config";
|
|
43
|
+
import { buildTraceTree } from "./helpers/buildTraceTree";
|
|
44
|
+
import { createSpan } from "./helpers/create-span";
|
|
45
|
+
import { getErrorSafe } from "./helpers/getErrorSafe";
|
|
46
|
+
import { getSerializedObjectSafe } from "./helpers/getSerializedObjectSafe";
|
|
47
|
+
import { IdNameManager } from "./helpers/idNameManager";
|
|
48
|
+
import { traceSerializer } from "./helpers/traceSerializer";
|
|
49
|
+
import type { FrameworkSpan, GeneratedResponse } from "./types";
|
|
50
|
+
|
|
54
51
|
export const activeTracesMap = new Map<string, string>();
|
|
55
52
|
|
|
56
53
|
/**
|
|
@@ -60,10 +57,7 @@ export const activeTracesMap = new Map<string, string>();
|
|
|
60
57
|
* Then we create the open telemetry spans when all data are collected. We are retroactively deleting some unnecessary internal spans
|
|
61
58
|
* see "emitter.match((event) => event.path === `${basePath}.run.${finishEventName}`" section
|
|
62
59
|
*/
|
|
63
|
-
export function createTelemetryMiddleware(
|
|
64
|
-
tracer: OITracer,
|
|
65
|
-
mainSpanKind: OpenInferenceSpanKind,
|
|
66
|
-
) {
|
|
60
|
+
export function createTelemetryMiddleware(tracer: OITracer, mainSpanKind: OpenInferenceSpanKind) {
|
|
67
61
|
return (context: GetRunContext<RunInstance, unknown>) => {
|
|
68
62
|
if (!context.emitter?.trace?.id) {
|
|
69
63
|
throw new FrameworkError(`Fatal error. Missing traceId`, [], { context });
|
|
@@ -149,13 +143,9 @@ export function createTelemetryMiddleware(
|
|
|
149
143
|
)?.text;
|
|
150
144
|
|
|
151
145
|
if (!prompt) {
|
|
152
|
-
throw new FrameworkError(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
{
|
|
156
|
-
context,
|
|
157
|
-
},
|
|
158
|
-
);
|
|
146
|
+
throw new FrameworkError("The prompt must be defined for the Agent's run", [], {
|
|
147
|
+
context,
|
|
148
|
+
});
|
|
159
149
|
}
|
|
160
150
|
}
|
|
161
151
|
|
|
@@ -192,10 +182,7 @@ export function createTelemetryMiddleware(
|
|
|
192
182
|
*/
|
|
193
183
|
emitter.match("*.*", (data, meta) => {
|
|
194
184
|
// allow `run.error` event due to the runtime error information
|
|
195
|
-
if (
|
|
196
|
-
meta.path.includes(".run.") &&
|
|
197
|
-
meta.path !== `${basePath}.run.${errorLLMEventName}`
|
|
198
|
-
) {
|
|
185
|
+
if (meta.path.includes(".run.") && meta.path !== `${basePath}.run.${errorLLMEventName}`) {
|
|
199
186
|
return;
|
|
200
187
|
}
|
|
201
188
|
// skip all new token events
|
|
@@ -203,13 +190,9 @@ export function createTelemetryMiddleware(
|
|
|
203
190
|
return;
|
|
204
191
|
}
|
|
205
192
|
if (!meta.trace?.runId) {
|
|
206
|
-
throw new FrameworkError(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
{
|
|
210
|
-
context,
|
|
211
|
-
},
|
|
212
|
-
);
|
|
193
|
+
throw new FrameworkError(`Fatal error. Missing runId for event: ${meta.path}`, [], {
|
|
194
|
+
context,
|
|
195
|
+
});
|
|
213
196
|
}
|
|
214
197
|
|
|
215
198
|
try {
|
|
@@ -217,11 +200,7 @@ export function createTelemetryMiddleware(
|
|
|
217
200
|
* create groupId span level (id does not exist)
|
|
218
201
|
* I use only the top-level groups like iterations other nested groups like tokens would introduce unuseful complexity
|
|
219
202
|
*/
|
|
220
|
-
if (
|
|
221
|
-
meta.groupId &&
|
|
222
|
-
!meta.trace.parentRunId &&
|
|
223
|
-
!groupIterations.includes(meta.groupId)
|
|
224
|
-
) {
|
|
203
|
+
if (meta.groupId && !meta.trace.parentRunId && !groupIterations.includes(meta.groupId)) {
|
|
225
204
|
spansMap.set(
|
|
226
205
|
meta.groupId,
|
|
227
206
|
createSpan({
|
|
@@ -266,9 +245,7 @@ export function createTelemetryMiddleware(
|
|
|
266
245
|
const lastIteration = groupIterations[groupIterations.length - 1];
|
|
267
246
|
|
|
268
247
|
// delete the `partialUpdate` event if does not have nested spans
|
|
269
|
-
const lastIterationEventSpanId = eventsIterationsMap
|
|
270
|
-
.get(lastIteration)
|
|
271
|
-
?.get(meta.name);
|
|
248
|
+
const lastIterationEventSpanId = eventsIterationsMap.get(lastIteration)?.get(meta.name);
|
|
272
249
|
if (
|
|
273
250
|
lastIterationEventSpanId &&
|
|
274
251
|
partialUpdateEventName === meta.name &&
|
|
@@ -288,23 +265,15 @@ export function createTelemetryMiddleware(
|
|
|
288
265
|
spansMap.set(span.context.span_id, span);
|
|
289
266
|
// update number of nested spans for parent_id if exists
|
|
290
267
|
if (span.parent_id) {
|
|
291
|
-
parentIdsMap.set(
|
|
292
|
-
span.parent_id,
|
|
293
|
-
(parentIdsMap.get(span.parent_id) || 0) + 1,
|
|
294
|
-
);
|
|
268
|
+
parentIdsMap.set(span.parent_id, (parentIdsMap.get(span.parent_id) || 0) + 1);
|
|
295
269
|
}
|
|
296
270
|
|
|
297
271
|
// save the last event for each iteration
|
|
298
272
|
if (groupIterations.length > 0) {
|
|
299
273
|
if (eventsIterationsMap.has(lastIteration)) {
|
|
300
|
-
eventsIterationsMap
|
|
301
|
-
.get(lastIteration)!
|
|
302
|
-
.set(meta.name, span.context.span_id);
|
|
274
|
+
eventsIterationsMap.get(lastIteration)!.set(meta.name, span.context.span_id);
|
|
303
275
|
} else {
|
|
304
|
-
eventsIterationsMap.set(
|
|
305
|
-
lastIteration,
|
|
306
|
-
new Map().set(meta.name, span.context.span_id),
|
|
307
|
-
);
|
|
276
|
+
eventsIterationsMap.set(lastIteration, new Map().set(meta.name, span.context.span_id));
|
|
308
277
|
}
|
|
309
278
|
}
|
|
310
279
|
} catch (e) {
|
|
@@ -314,9 +283,7 @@ export function createTelemetryMiddleware(
|
|
|
314
283
|
|
|
315
284
|
// The generated response and message history are collected from the `success` event generated by ReActAgent
|
|
316
285
|
emitter.match(
|
|
317
|
-
(event) =>
|
|
318
|
-
event.name === successLLMEventName &&
|
|
319
|
-
event.creator instanceof ReActAgent,
|
|
286
|
+
(event) => event.name === successLLMEventName && event.creator instanceof ReActAgent,
|
|
320
287
|
(data: InferCallbackValue<ReActAgentCallbacks["success"]>) => {
|
|
321
288
|
try {
|
|
322
289
|
const { data: dataObject, memory } = data;
|
|
@@ -330,19 +297,14 @@ export function createTelemetryMiddleware(
|
|
|
330
297
|
role: msg.role,
|
|
331
298
|
}));
|
|
332
299
|
} catch (e) {
|
|
333
|
-
diag.warn(
|
|
334
|
-
"Instrumentation error. Unable to map messages to history for ReActAgent",
|
|
335
|
-
e,
|
|
336
|
-
);
|
|
300
|
+
diag.warn("Instrumentation error. Unable to map messages to history for ReActAgent", e);
|
|
337
301
|
}
|
|
338
302
|
},
|
|
339
303
|
);
|
|
340
304
|
|
|
341
305
|
// The generated response and message history are collected from the `success` event generated by ToolCallingAgentCallbacks
|
|
342
306
|
emitter.match(
|
|
343
|
-
(event) =>
|
|
344
|
-
event.name === successLLMEventName &&
|
|
345
|
-
event.creator instanceof ToolCallingAgent,
|
|
307
|
+
(event) => event.name === successLLMEventName && event.creator instanceof ToolCallingAgent,
|
|
346
308
|
(data: InferCallbackValue<ToolCallingAgentCallbacks["success"]>) => {
|
|
347
309
|
try {
|
|
348
310
|
const { state } = data;
|
package/src/types.ts
CHANGED