@arizeai/openinference-instrumentation-beeai 1.0.0 → 1.1.0
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 +10 -10
- package/dist/esm/config.d.ts.map +1 -1
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/helpers/buildTraceTree.d.ts +3 -1
- package/dist/esm/helpers/buildTraceTree.d.ts.map +1 -1
- package/dist/esm/helpers/buildTraceTree.js +55 -7
- package/dist/esm/helpers/buildTraceTree.js.map +1 -1
- package/dist/esm/helpers/getSerializedObjectSafe.js.map +1 -1
- package/dist/esm/instrumentation.d.ts.map +1 -1
- package/dist/esm/instrumentation.js +24 -7
- package/dist/esm/instrumentation.js.map +1 -1
- package/dist/esm/middleware.d.ts +2 -1
- package/dist/esm/middleware.d.ts.map +1 -1
- package/dist/esm/middleware.js +3 -2
- package/dist/esm/middleware.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esnext/config.d.ts +10 -10
- package/dist/esnext/config.d.ts.map +1 -1
- package/dist/esnext/config.js.map +1 -1
- package/dist/esnext/helpers/buildTraceTree.d.ts +3 -1
- package/dist/esnext/helpers/buildTraceTree.d.ts.map +1 -1
- package/dist/esnext/helpers/buildTraceTree.js +44 -4
- package/dist/esnext/helpers/buildTraceTree.js.map +1 -1
- package/dist/esnext/helpers/getSerializedObjectSafe.js.map +1 -1
- package/dist/esnext/instrumentation.d.ts.map +1 -1
- package/dist/esnext/instrumentation.js +24 -7
- package/dist/esnext/instrumentation.js.map +1 -1
- package/dist/esnext/middleware.d.ts +2 -1
- package/dist/esnext/middleware.d.ts.map +1 -1
- package/dist/esnext/middleware.js +3 -2
- package/dist/esnext/middleware.js.map +1 -1
- package/dist/esnext/tsconfig.esnext.tsbuildinfo +1 -1
- package/dist/examples/run-agent.d.ts +2 -0
- package/dist/examples/run-agent.d.ts.map +1 -0
- package/dist/examples/{bee.js → run-agent.js} +3 -3
- package/dist/examples/run-agent.js.map +1 -0
- package/dist/examples/run-llm.d.ts +2 -0
- package/dist/examples/run-llm.d.ts.map +1 -0
- package/dist/examples/run-llm.js +30 -0
- package/dist/examples/run-llm.js.map +1 -0
- package/dist/examples/run-tool.d.ts +2 -0
- package/dist/examples/run-tool.d.ts.map +1 -0
- package/dist/examples/run-tool.js +28 -0
- package/dist/examples/run-tool.js.map +1 -0
- package/dist/src/config.d.ts +10 -10
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js.map +1 -1
- package/dist/src/helpers/buildTraceTree.d.ts +3 -1
- package/dist/src/helpers/buildTraceTree.d.ts.map +1 -1
- package/dist/src/helpers/buildTraceTree.js +44 -4
- package/dist/src/helpers/buildTraceTree.js.map +1 -1
- package/dist/src/helpers/getSerializedObjectSafe.js.map +1 -1
- package/dist/src/instrumentation.d.ts.map +1 -1
- package/dist/src/instrumentation.js +24 -7
- package/dist/src/instrumentation.js.map +1 -1
- package/dist/src/middleware.d.ts +2 -1
- package/dist/src/middleware.d.ts.map +1 -1
- package/dist/src/middleware.js +2 -1
- package/dist/src/middleware.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/config.ts +11 -10
- package/src/helpers/buildTraceTree.ts +88 -10
- package/src/helpers/getSerializedObjectSafe.ts +12 -12
- package/src/instrumentation.ts +60 -9
- package/src/middleware.ts +13 -6
- package/dist/examples/bee.d.ts +0 -2
- package/dist/examples/bee.d.ts.map +0 -1
- package/dist/examples/bee.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arizeai/openinference-instrumentation-beeai",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
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.8"
|
|
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.8",
|
|
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",
|
package/src/config.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import type { ReActAgentCallbacks } from "beeai-framework/agents/react/types";
|
|
18
18
|
import { ChatModelEvents } from "beeai-framework/backend/chat";
|
|
19
19
|
import { ToolEvents } from "beeai-framework/tools/base";
|
|
20
20
|
|
|
@@ -25,15 +25,16 @@ export const INSTRUMENTATION_IGNORED_KEYS = process.env
|
|
|
25
25
|
)
|
|
26
26
|
: [];
|
|
27
27
|
|
|
28
|
-
export const partialUpdateEventName: keyof
|
|
29
|
-
|
|
30
|
-
export const
|
|
31
|
-
export const
|
|
32
|
-
export const
|
|
33
|
-
export const
|
|
34
|
-
export const
|
|
35
|
-
export const
|
|
36
|
-
export const
|
|
28
|
+
export const partialUpdateEventName: keyof ReActAgentCallbacks =
|
|
29
|
+
"partialUpdate";
|
|
30
|
+
export const updateEventName: keyof ReActAgentCallbacks = "update";
|
|
31
|
+
export const toolErrorEventName: keyof ReActAgentCallbacks = "toolError";
|
|
32
|
+
export const toolStartEventName: keyof ReActAgentCallbacks = "toolStart";
|
|
33
|
+
export const toolSuccessEventName: keyof ReActAgentCallbacks = "toolSuccess";
|
|
34
|
+
export const startEventName: keyof ReActAgentCallbacks = "start";
|
|
35
|
+
export const successEventName: keyof ReActAgentCallbacks = "success";
|
|
36
|
+
export const errorEventName: keyof ReActAgentCallbacks = "error";
|
|
37
|
+
export const retryEventName: keyof ReActAgentCallbacks = "retry";
|
|
37
38
|
|
|
38
39
|
export const newTokenLLMEventName: keyof ChatModelEvents = `newToken`;
|
|
39
40
|
export const successLLMEventName: keyof ChatModelEvents = `success`;
|
|
@@ -5,9 +5,11 @@ import {
|
|
|
5
5
|
OpenInferenceSpanKind,
|
|
6
6
|
SemanticConventions,
|
|
7
7
|
} from "@arizeai/openinference-semantic-conventions";
|
|
8
|
+
import { startEventName, successEventName } from "../config";
|
|
8
9
|
|
|
9
10
|
interface BuiltTraceTreeProps {
|
|
10
11
|
tracer: OITracer;
|
|
12
|
+
mainSpanKind: OpenInferenceSpanKind;
|
|
11
13
|
data: {
|
|
12
14
|
prompt?: string | null;
|
|
13
15
|
history: GeneratedResponse[] | undefined;
|
|
@@ -72,7 +74,90 @@ function buildSpansForParent({ tracer, data }: BuildSpansForParentProps) {
|
|
|
72
74
|
});
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
function buildAgentMainSpanData(data: BuiltTraceTreeProps["data"]) {
|
|
78
|
+
return {
|
|
79
|
+
...(data.prompt && { [SemanticConventions.INPUT_VALUE]: data.prompt }),
|
|
80
|
+
...(data.generatedMessage !== undefined && {
|
|
81
|
+
[SemanticConventions.OUTPUT_VALUE]: JSON.stringify(data.generatedMessage),
|
|
82
|
+
}),
|
|
83
|
+
...(data.history && { history: JSON.stringify(data.history) }),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function buildToolMainSpanData(data: BuiltTraceTreeProps["data"]) {
|
|
88
|
+
const startBeeaiSpan = data.spans.find(
|
|
89
|
+
(span) => span.name === startEventName,
|
|
90
|
+
);
|
|
91
|
+
const successBeeeaiSpan = data.spans.find(
|
|
92
|
+
(span) => span.name === successEventName,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
...(startBeeaiSpan && {
|
|
97
|
+
[SemanticConventions.INPUT_VALUE]:
|
|
98
|
+
startBeeaiSpan.attributes.data?.[SemanticConventions.TOOL_PARAMETERS],
|
|
99
|
+
[SemanticConventions.TOOL_PARAMETERS]:
|
|
100
|
+
startBeeaiSpan.attributes.data?.[SemanticConventions.TOOL_PARAMETERS],
|
|
101
|
+
}),
|
|
102
|
+
...(successBeeeaiSpan && {
|
|
103
|
+
[SemanticConventions.OUTPUT_VALUE]:
|
|
104
|
+
successBeeeaiSpan.attributes.data?.[SemanticConventions.OUTPUT_VALUE],
|
|
105
|
+
}),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function buildLLMMainSpanData(data: BuiltTraceTreeProps["data"]) {
|
|
110
|
+
const startBeeaiSpan = data.spans.find(
|
|
111
|
+
(span) => span.name === startEventName,
|
|
112
|
+
);
|
|
113
|
+
const successBeeeaiSpan = data.spans.find(
|
|
114
|
+
(span) => span.name === successEventName,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
if (!startBeeaiSpan && !successBeeeaiSpan) return {};
|
|
118
|
+
|
|
119
|
+
const provider =
|
|
120
|
+
startBeeaiSpan?.attributes.data?.[SemanticConventions.LLM_PROVIDER] ||
|
|
121
|
+
successBeeeaiSpan?.attributes.data?.[SemanticConventions.LLM_PROVIDER];
|
|
122
|
+
|
|
123
|
+
const modelName =
|
|
124
|
+
startBeeaiSpan?.attributes.data?.[SemanticConventions.LLM_MODEL_NAME] ||
|
|
125
|
+
successBeeeaiSpan?.attributes.data?.[SemanticConventions.LLM_MODEL_NAME];
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
...(startBeeaiSpan && {
|
|
129
|
+
[SemanticConventions.INPUT_VALUE]:
|
|
130
|
+
startBeeaiSpan?.attributes.data?.[SemanticConventions.INPUT_VALUE],
|
|
131
|
+
[SemanticConventions.INPUT_MIME_TYPE]:
|
|
132
|
+
startBeeaiSpan?.attributes.data?.[SemanticConventions.INPUT_MIME_TYPE],
|
|
133
|
+
}),
|
|
134
|
+
...(successBeeeaiSpan && {
|
|
135
|
+
[SemanticConventions.OUTPUT_MIME_TYPE]:
|
|
136
|
+
successBeeeaiSpan.attributes.data?.[
|
|
137
|
+
SemanticConventions.OUTPUT_MIME_TYPE
|
|
138
|
+
],
|
|
139
|
+
[SemanticConventions.OUTPUT_VALUE]:
|
|
140
|
+
successBeeeaiSpan.attributes.data?.[SemanticConventions.OUTPUT_VALUE],
|
|
141
|
+
}),
|
|
142
|
+
...(provider && { [SemanticConventions.LLM_PROVIDER]: provider }),
|
|
143
|
+
...(modelName && { [SemanticConventions.LLM_MODEL_NAME]: modelName }),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function buildTraceTree({
|
|
148
|
+
tracer,
|
|
149
|
+
data,
|
|
150
|
+
mainSpanKind,
|
|
151
|
+
}: BuiltTraceTreeProps) {
|
|
152
|
+
const computedData =
|
|
153
|
+
mainSpanKind === OpenInferenceSpanKind.AGENT
|
|
154
|
+
? buildAgentMainSpanData(data)
|
|
155
|
+
: mainSpanKind === OpenInferenceSpanKind.TOOL
|
|
156
|
+
? buildToolMainSpanData(data)
|
|
157
|
+
: mainSpanKind === OpenInferenceSpanKind.LLM
|
|
158
|
+
? buildLLMMainSpanData(data)
|
|
159
|
+
: {};
|
|
160
|
+
|
|
76
161
|
tracer.startActiveSpan(
|
|
77
162
|
`beeai-framework-main`,
|
|
78
163
|
{
|
|
@@ -82,16 +167,9 @@ export function buildTraceTree({ tracer, data }: BuiltTraceTreeProps) {
|
|
|
82
167
|
attributes: {
|
|
83
168
|
source: data.source,
|
|
84
169
|
traceId: data.traceId,
|
|
85
|
-
[SemanticConventions.OPENINFERENCE_SPAN_KIND]:
|
|
86
|
-
OpenInferenceSpanKind.AGENT,
|
|
170
|
+
[SemanticConventions.OPENINFERENCE_SPAN_KIND]: mainSpanKind,
|
|
87
171
|
["beeai.version"]: data.version,
|
|
88
|
-
...
|
|
89
|
-
...(data.generatedMessage !== undefined && {
|
|
90
|
-
[SemanticConventions.OUTPUT_VALUE]: JSON.stringify(
|
|
91
|
-
data.generatedMessage,
|
|
92
|
-
),
|
|
93
|
-
}),
|
|
94
|
-
...(data.history && { history: JSON.stringify(data.history) }),
|
|
172
|
+
...computedData,
|
|
95
173
|
},
|
|
96
174
|
},
|
|
97
175
|
(activeSpan) => {
|
|
@@ -18,7 +18,7 @@ import { Serializable } from "beeai-framework/internals/serializable";
|
|
|
18
18
|
import { instrumentationLogger } from "beeai-framework/instrumentation/logger";
|
|
19
19
|
import { getProp } from "beeai-framework/internals/helpers/object";
|
|
20
20
|
import { EventMeta, InferCallbackValue } from "beeai-framework/emitter/types";
|
|
21
|
-
import {
|
|
21
|
+
import type { ReActAgentCallbacks } from "beeai-framework/agents/react/types";
|
|
22
22
|
import { ChatModel, ChatModelEvents } from "beeai-framework/backend/chat";
|
|
23
23
|
import { BaseAgent } from "beeai-framework/agents/base";
|
|
24
24
|
import { Message, MessageContentPart } from "beeai-framework/backend/message";
|
|
@@ -96,16 +96,16 @@ export function getSerializedObjectSafe(
|
|
|
96
96
|
// agent events
|
|
97
97
|
if (
|
|
98
98
|
[startEventName, successEventName, errorEventName, retryEventName].includes(
|
|
99
|
-
meta.name as keyof
|
|
99
|
+
meta.name as keyof ReActAgentCallbacks,
|
|
100
100
|
) &&
|
|
101
101
|
meta.creator instanceof BaseAgent
|
|
102
102
|
) {
|
|
103
103
|
const { meta, tools, memory, error, data } =
|
|
104
104
|
dataObject as InferCallbackValue<
|
|
105
|
-
|
|
|
106
|
-
|
|
|
107
|
-
|
|
|
108
|
-
|
|
|
105
|
+
| ReActAgentCallbacks["start"]
|
|
106
|
+
| ReActAgentCallbacks["error"]
|
|
107
|
+
| ReActAgentCallbacks["success"]
|
|
108
|
+
| ReActAgentCallbacks["retry"]
|
|
109
109
|
>;
|
|
110
110
|
return {
|
|
111
111
|
[SemanticConventions.OPENINFERENCE_SPAN_KIND]:
|
|
@@ -137,11 +137,11 @@ export function getSerializedObjectSafe(
|
|
|
137
137
|
// update events
|
|
138
138
|
if (
|
|
139
139
|
[updateEventName, partialUpdateEventName].includes(
|
|
140
|
-
meta.name as keyof
|
|
140
|
+
meta.name as keyof ReActAgentCallbacks,
|
|
141
141
|
)
|
|
142
142
|
) {
|
|
143
143
|
const { data } = dataObject as InferCallbackValue<
|
|
144
|
-
|
|
144
|
+
ReActAgentCallbacks["partialUpdate"] | ReActAgentCallbacks["update"]
|
|
145
145
|
>;
|
|
146
146
|
|
|
147
147
|
const output = data.final_answer || data.tool_output;
|
|
@@ -165,13 +165,13 @@ export function getSerializedObjectSafe(
|
|
|
165
165
|
// tool events (from agent)
|
|
166
166
|
if (
|
|
167
167
|
[toolErrorEventName, toolStartEventName, toolSuccessEventName].includes(
|
|
168
|
-
meta.name as keyof
|
|
168
|
+
meta.name as keyof ReActAgentCallbacks,
|
|
169
169
|
)
|
|
170
170
|
) {
|
|
171
171
|
const { data } = dataObject as InferCallbackValue<
|
|
172
|
-
|
|
|
173
|
-
|
|
|
174
|
-
|
|
|
172
|
+
| ReActAgentCallbacks["toolError"]
|
|
173
|
+
| ReActAgentCallbacks["toolStart"]
|
|
174
|
+
| ReActAgentCallbacks["toolSuccess"]
|
|
175
175
|
>;
|
|
176
176
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
177
177
|
const output: any = data.result && data.result.createSnapshot();
|
package/src/instrumentation.ts
CHANGED
|
@@ -9,6 +9,7 @@ import * as bee from "beeai-framework";
|
|
|
9
9
|
|
|
10
10
|
import { OITracer, TraceConfigOptions } from "@arizeai/openinference-core";
|
|
11
11
|
import { createTelemetryMiddleware } from "./middleware";
|
|
12
|
+
import { OpenInferenceSpanKind } from "@arizeai/openinference-semantic-conventions";
|
|
12
13
|
|
|
13
14
|
const MODULE_NAME = "beeai-framework";
|
|
14
15
|
|
|
@@ -83,21 +84,71 @@ export class BeeAIInstrumentation extends InstrumentationBase {
|
|
|
83
84
|
return module;
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
const createWrappedMethod = <T extends (...args: any[]) => any>(
|
|
89
|
+
instrumentation: BeeAIInstrumentation,
|
|
90
|
+
original: T,
|
|
91
|
+
mainSpanKind: OpenInferenceSpanKind,
|
|
92
|
+
) => {
|
|
93
|
+
return function wrappedMethod(this: unknown, ...args: unknown[]) {
|
|
94
|
+
const returned = original.apply(this, args);
|
|
95
|
+
if (returned?.middleware) {
|
|
96
|
+
returned.middleware(
|
|
97
|
+
createTelemetryMiddleware(instrumentation.oiTracer, mainSpanKind),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return returned;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
86
103
|
diag.info("[BeeaiInstrumentation] Patching BaseAgent.run");
|
|
87
104
|
|
|
88
105
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
89
106
|
const instrumentation: BeeAIInstrumentation = this;
|
|
90
107
|
|
|
91
|
-
this._wrap(module.BaseAgent.prototype, "run", (original) =>
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
this._wrap(module.BaseAgent.prototype, "run", (original) =>
|
|
109
|
+
createWrappedMethod(
|
|
110
|
+
instrumentation,
|
|
111
|
+
original,
|
|
112
|
+
OpenInferenceSpanKind.AGENT,
|
|
113
|
+
),
|
|
114
|
+
);
|
|
97
115
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
116
|
+
// tool instrumentation support
|
|
117
|
+
if (module.Tool) {
|
|
118
|
+
this._wrap(module.Tool.prototype, "run", (original) =>
|
|
119
|
+
createWrappedMethod(
|
|
120
|
+
instrumentation,
|
|
121
|
+
original,
|
|
122
|
+
OpenInferenceSpanKind.TOOL,
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
// model instrumentation support
|
|
127
|
+
if (module.ChatModel) {
|
|
128
|
+
this._wrap(module.ChatModel.prototype, "create", (original) =>
|
|
129
|
+
createWrappedMethod(
|
|
130
|
+
instrumentation,
|
|
131
|
+
original,
|
|
132
|
+
OpenInferenceSpanKind.LLM,
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
this._wrap(module.ChatModel.prototype, "createStructure", (original) =>
|
|
136
|
+
createWrappedMethod(
|
|
137
|
+
instrumentation,
|
|
138
|
+
original,
|
|
139
|
+
OpenInferenceSpanKind.LLM,
|
|
140
|
+
),
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
if (module.EmbeddingModel) {
|
|
144
|
+
this._wrap(module.EmbeddingModel.prototype, "create", (original) =>
|
|
145
|
+
createWrappedMethod(
|
|
146
|
+
instrumentation,
|
|
147
|
+
original,
|
|
148
|
+
OpenInferenceSpanKind.EMBEDDING,
|
|
149
|
+
),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
101
152
|
|
|
102
153
|
return module;
|
|
103
154
|
}
|
package/src/middleware.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { createSpan } from "./helpers/create-span";
|
|
|
20
20
|
import { IdNameManager } from "./helpers/idNameManager";
|
|
21
21
|
import { getErrorSafe } from "./helpers/getErrorSafe";
|
|
22
22
|
import { findLast, isEmpty } from "remeda";
|
|
23
|
-
import type {
|
|
23
|
+
import type { ReActAgentCallbacks } from "beeai-framework/agents/react/types";
|
|
24
24
|
import type { InferCallbackValue } from "beeai-framework/emitter/types";
|
|
25
25
|
import { FrameworkError } from "beeai-framework/errors";
|
|
26
26
|
import { Version } from "beeai-framework/version";
|
|
@@ -36,12 +36,15 @@ import {
|
|
|
36
36
|
successLLMEventName,
|
|
37
37
|
} from "./config";
|
|
38
38
|
import { createFullPath } from "beeai-framework/emitter/utils";
|
|
39
|
-
import type {
|
|
39
|
+
import type { ReActAgent } from "beeai-framework/agents/react/agent";
|
|
40
40
|
import { BaseAgent } from "beeai-framework/agents/base";
|
|
41
41
|
import { diag } from "@opentelemetry/api";
|
|
42
42
|
import { FrameworkSpan, GeneratedResponse } from "./types";
|
|
43
43
|
import { buildTraceTree } from "./helpers/buildTraceTree";
|
|
44
|
-
import {
|
|
44
|
+
import {
|
|
45
|
+
OpenInferenceSpanKind,
|
|
46
|
+
SemanticConventions,
|
|
47
|
+
} from "@arizeai/openinference-semantic-conventions";
|
|
45
48
|
|
|
46
49
|
export const activeTracesMap = new Map<string, string>();
|
|
47
50
|
|
|
@@ -52,7 +55,10 @@ export const activeTracesMap = new Map<string, string>();
|
|
|
52
55
|
* Then we create the open telemetry spans when all data are collected. We are retroactively deleting some unnecessary internal spans
|
|
53
56
|
* see "emitter.match((event) => event.path === `${basePath}.run.${finishEventName}`" section
|
|
54
57
|
*/
|
|
55
|
-
export function createTelemetryMiddleware(
|
|
58
|
+
export function createTelemetryMiddleware(
|
|
59
|
+
tracer: OITracer,
|
|
60
|
+
mainSpanKind: OpenInferenceSpanKind,
|
|
61
|
+
) {
|
|
56
62
|
return (context: GetRunContext<RunInstance, unknown>) => {
|
|
57
63
|
if (!context.emitter?.trace?.id) {
|
|
58
64
|
throw new FrameworkError(`Fatal error. Missing traceId`, [], { context });
|
|
@@ -73,7 +79,7 @@ export function createTelemetryMiddleware(tracer: OITracer) {
|
|
|
73
79
|
|
|
74
80
|
let prompt: string | undefined | null = null;
|
|
75
81
|
if (instance instanceof BaseAgent) {
|
|
76
|
-
prompt = (runParams as Parameters<
|
|
82
|
+
prompt = (runParams as Parameters<ReActAgent["run"]>)[0].prompt;
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
const spansMap = new Map<string, FrameworkSpan>();
|
|
@@ -151,6 +157,7 @@ export function createTelemetryMiddleware(tracer: OITracer) {
|
|
|
151
157
|
// create tracer spans from collected data
|
|
152
158
|
buildTraceTree({
|
|
153
159
|
tracer,
|
|
160
|
+
mainSpanKind,
|
|
154
161
|
data: {
|
|
155
162
|
prompt: prompt,
|
|
156
163
|
history,
|
|
@@ -301,7 +308,7 @@ export function createTelemetryMiddleware(tracer: OITracer) {
|
|
|
301
308
|
(event) =>
|
|
302
309
|
event.name === successLLMEventName &&
|
|
303
310
|
event.creator instanceof BaseAgent,
|
|
304
|
-
(data: InferCallbackValue<
|
|
311
|
+
(data: InferCallbackValue<ReActAgentCallbacks["success"]>) => {
|
|
305
312
|
const { data: dataObject, memory } = data;
|
|
306
313
|
|
|
307
314
|
generatedMessage = {
|
package/dist/examples/bee.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bee.d.ts","sourceRoot":"","sources":["../../examples/bee.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC"}
|
package/dist/examples/bee.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bee.js","sourceRoot":"","sources":["../../examples/bee.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA2B;AAC3B,4DAA4D;AAC5D,uEAA+E;AAC/E,oEAAiE;AACjE,oFAAqF;AACrF,uEAAwE;AAExE,MAAM,GAAG,GAAG,IAAI,sBAAe,CAAC,UAAU,CAAC,CAAC,CAAC,+DAA+D;AAC5G,MAAM,KAAK,GAAG,IAAI,gBAAQ,CAAC;IACzB,GAAG,EAAE,8CAA8C;IACnD,MAAM,EAAE,IAAI,yBAAW,EAAE,EAAE,4CAA4C;IACvE,KAAK,EAAE,CAAC,IAAI,uCAAoB,EAAE,EAAE,IAAI,yBAAa,EAAE,CAAC,EAAE,2CAA2C;CACtG,CAAC,CAAC;AAEH,SAAe,IAAI;;QACjB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC;YAC/B,MAAM,EAAE,0CAA0C;SACnD,CAAC,CAAC;QACH,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;CAAA;AAED,sCAAsC;AACtC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|