@arizeai/openinference-instrumentation-beeai 1.0.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.
Files changed (158) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +80 -0
  3. package/dist/esm/config.d.ts +39 -0
  4. package/dist/esm/config.d.ts.map +1 -0
  5. package/dist/esm/config.js +39 -0
  6. package/dist/esm/config.js.map +1 -0
  7. package/dist/esm/helpers/buildTraceTree.d.ts +21 -0
  8. package/dist/esm/helpers/buildTraceTree.d.ts.map +1 -0
  9. package/dist/esm/helpers/buildTraceTree.js +71 -0
  10. package/dist/esm/helpers/buildTraceTree.js.map +1 -0
  11. package/dist/esm/helpers/create-span.d.ts +32 -0
  12. package/dist/esm/helpers/create-span.d.ts.map +1 -0
  13. package/dist/esm/helpers/create-span.js +42 -0
  14. package/dist/esm/helpers/create-span.js.map +1 -0
  15. package/dist/esm/helpers/getErrorSafe.d.ts +17 -0
  16. package/dist/esm/helpers/getErrorSafe.d.ts.map +1 -0
  17. package/dist/esm/helpers/getErrorSafe.js +24 -0
  18. package/dist/esm/helpers/getErrorSafe.js.map +1 -0
  19. package/dist/esm/helpers/getSerializedObjectSafe.d.ts +18 -0
  20. package/dist/esm/helpers/getSerializedObjectSafe.d.ts.map +1 -0
  21. package/dist/esm/helpers/getSerializedObjectSafe.js +217 -0
  22. package/dist/esm/helpers/getSerializedObjectSafe.js.map +1 -0
  23. package/dist/esm/helpers/idNameManager.d.ts +31 -0
  24. package/dist/esm/helpers/idNameManager.d.ts.map +1 -0
  25. package/dist/esm/helpers/idNameManager.js +50 -0
  26. package/dist/esm/helpers/idNameManager.js.map +1 -0
  27. package/dist/esm/helpers/traceSerializer.d.ts +19 -0
  28. package/dist/esm/helpers/traceSerializer.d.ts.map +1 -0
  29. package/dist/esm/helpers/traceSerializer.js +35 -0
  30. package/dist/esm/helpers/traceSerializer.js.map +1 -0
  31. package/dist/esm/index.d.ts +2 -0
  32. package/dist/esm/index.d.ts.map +1 -0
  33. package/dist/esm/index.js +2 -0
  34. package/dist/esm/index.js.map +1 -0
  35. package/dist/esm/instrumentation.d.ts +34 -0
  36. package/dist/esm/instrumentation.d.ts.map +1 -0
  37. package/dist/esm/instrumentation.js +71 -0
  38. package/dist/esm/instrumentation.js.map +1 -0
  39. package/dist/esm/middleware.d.ts +27 -0
  40. package/dist/esm/middleware.d.ts.map +1 -0
  41. package/dist/esm/middleware.js +247 -0
  42. package/dist/esm/middleware.js.map +1 -0
  43. package/dist/esm/package.json +1 -0
  44. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
  45. package/dist/esm/types.d.ts +36 -0
  46. package/dist/esm/types.d.ts.map +1 -0
  47. package/dist/esm/types.js +17 -0
  48. package/dist/esm/types.js.map +1 -0
  49. package/dist/esnext/config.d.ts +39 -0
  50. package/dist/esnext/config.d.ts.map +1 -0
  51. package/dist/esnext/config.js +39 -0
  52. package/dist/esnext/config.js.map +1 -0
  53. package/dist/esnext/helpers/buildTraceTree.d.ts +21 -0
  54. package/dist/esnext/helpers/buildTraceTree.d.ts.map +1 -0
  55. package/dist/esnext/helpers/buildTraceTree.js +57 -0
  56. package/dist/esnext/helpers/buildTraceTree.js.map +1 -0
  57. package/dist/esnext/helpers/create-span.d.ts +32 -0
  58. package/dist/esnext/helpers/create-span.d.ts.map +1 -0
  59. package/dist/esnext/helpers/create-span.js +37 -0
  60. package/dist/esnext/helpers/create-span.js.map +1 -0
  61. package/dist/esnext/helpers/getErrorSafe.d.ts +17 -0
  62. package/dist/esnext/helpers/getErrorSafe.d.ts.map +1 -0
  63. package/dist/esnext/helpers/getErrorSafe.js +24 -0
  64. package/dist/esnext/helpers/getErrorSafe.js.map +1 -0
  65. package/dist/esnext/helpers/getSerializedObjectSafe.d.ts +18 -0
  66. package/dist/esnext/helpers/getSerializedObjectSafe.d.ts.map +1 -0
  67. package/dist/esnext/helpers/getSerializedObjectSafe.js +165 -0
  68. package/dist/esnext/helpers/getSerializedObjectSafe.js.map +1 -0
  69. package/dist/esnext/helpers/idNameManager.d.ts +31 -0
  70. package/dist/esnext/helpers/idNameManager.d.ts.map +1 -0
  71. package/dist/esnext/helpers/idNameManager.js +50 -0
  72. package/dist/esnext/helpers/idNameManager.js.map +1 -0
  73. package/dist/esnext/helpers/traceSerializer.d.ts +19 -0
  74. package/dist/esnext/helpers/traceSerializer.d.ts.map +1 -0
  75. package/dist/esnext/helpers/traceSerializer.js +35 -0
  76. package/dist/esnext/helpers/traceSerializer.js.map +1 -0
  77. package/dist/esnext/index.d.ts +2 -0
  78. package/dist/esnext/index.d.ts.map +1 -0
  79. package/dist/esnext/index.js +2 -0
  80. package/dist/esnext/index.js.map +1 -0
  81. package/dist/esnext/instrumentation.d.ts +34 -0
  82. package/dist/esnext/instrumentation.d.ts.map +1 -0
  83. package/dist/esnext/instrumentation.js +71 -0
  84. package/dist/esnext/instrumentation.js.map +1 -0
  85. package/dist/esnext/middleware.d.ts +27 -0
  86. package/dist/esnext/middleware.d.ts.map +1 -0
  87. package/dist/esnext/middleware.js +241 -0
  88. package/dist/esnext/middleware.js.map +1 -0
  89. package/dist/esnext/tsconfig.esnext.tsbuildinfo +1 -0
  90. package/dist/esnext/types.d.ts +36 -0
  91. package/dist/esnext/types.d.ts.map +1 -0
  92. package/dist/esnext/types.js +17 -0
  93. package/dist/esnext/types.js.map +1 -0
  94. package/dist/examples/bee.d.ts +2 -0
  95. package/dist/examples/bee.d.ts.map +1 -0
  96. package/dist/examples/bee.js +35 -0
  97. package/dist/examples/bee.js.map +1 -0
  98. package/dist/examples/instrumentation.d.ts +2 -0
  99. package/dist/examples/instrumentation.d.ts.map +1 -0
  100. package/dist/examples/instrumentation.js +54 -0
  101. package/dist/examples/instrumentation.js.map +1 -0
  102. package/dist/src/config.d.ts +39 -0
  103. package/dist/src/config.d.ts.map +1 -0
  104. package/dist/src/config.js +42 -0
  105. package/dist/src/config.js.map +1 -0
  106. package/dist/src/helpers/buildTraceTree.d.ts +21 -0
  107. package/dist/src/helpers/buildTraceTree.d.ts.map +1 -0
  108. package/dist/src/helpers/buildTraceTree.js +60 -0
  109. package/dist/src/helpers/buildTraceTree.js.map +1 -0
  110. package/dist/src/helpers/create-span.d.ts +32 -0
  111. package/dist/src/helpers/create-span.d.ts.map +1 -0
  112. package/dist/src/helpers/create-span.js +40 -0
  113. package/dist/src/helpers/create-span.js.map +1 -0
  114. package/dist/src/helpers/getErrorSafe.d.ts +17 -0
  115. package/dist/src/helpers/getErrorSafe.d.ts.map +1 -0
  116. package/dist/src/helpers/getErrorSafe.js +27 -0
  117. package/dist/src/helpers/getErrorSafe.js.map +1 -0
  118. package/dist/src/helpers/getSerializedObjectSafe.d.ts +18 -0
  119. package/dist/src/helpers/getSerializedObjectSafe.d.ts.map +1 -0
  120. package/dist/src/helpers/getSerializedObjectSafe.js +168 -0
  121. package/dist/src/helpers/getSerializedObjectSafe.js.map +1 -0
  122. package/dist/src/helpers/idNameManager.d.ts +31 -0
  123. package/dist/src/helpers/idNameManager.d.ts.map +1 -0
  124. package/dist/src/helpers/idNameManager.js +54 -0
  125. package/dist/src/helpers/idNameManager.js.map +1 -0
  126. package/dist/src/helpers/traceSerializer.d.ts +19 -0
  127. package/dist/src/helpers/traceSerializer.d.ts.map +1 -0
  128. package/dist/src/helpers/traceSerializer.js +38 -0
  129. package/dist/src/helpers/traceSerializer.js.map +1 -0
  130. package/dist/src/index.d.ts +2 -0
  131. package/dist/src/index.d.ts.map +1 -0
  132. package/dist/src/index.js +18 -0
  133. package/dist/src/index.js.map +1 -0
  134. package/dist/src/instrumentation.d.ts +34 -0
  135. package/dist/src/instrumentation.d.ts.map +1 -0
  136. package/dist/src/instrumentation.js +76 -0
  137. package/dist/src/instrumentation.js.map +1 -0
  138. package/dist/src/middleware.d.ts +27 -0
  139. package/dist/src/middleware.d.ts.map +1 -0
  140. package/dist/src/middleware.js +254 -0
  141. package/dist/src/middleware.js.map +1 -0
  142. package/dist/src/types.d.ts +36 -0
  143. package/dist/src/types.d.ts.map +1 -0
  144. package/dist/src/types.js +18 -0
  145. package/dist/src/types.js.map +1 -0
  146. package/dist/tsconfig.tsbuildinfo +1 -0
  147. package/package.json +64 -0
  148. package/src/config.ts +48 -0
  149. package/src/helpers/buildTraceTree.ts +118 -0
  150. package/src/helpers/create-span.ts +66 -0
  151. package/src/helpers/getErrorSafe.ts +26 -0
  152. package/src/helpers/getSerializedObjectSafe.ts +325 -0
  153. package/src/helpers/idNameManager.ts +53 -0
  154. package/src/helpers/traceSerializer.ts +46 -0
  155. package/src/index.ts +1 -0
  156. package/src/instrumentation.ts +123 -0
  157. package/src/middleware.ts +318 -0
  158. package/src/types.ts +38 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./instrumentation";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { InstrumentationBase, InstrumentationNodeModuleDefinition, InstrumentationConfig } from "@opentelemetry/instrumentation";
2
+ import * as bee from "beeai-framework";
3
+ import { TraceConfigOptions } from "@arizeai/openinference-core";
4
+ /**
5
+ * function to check if instrumentation is enabled / disabled
6
+ */
7
+ export declare function isPatched(): boolean;
8
+ export declare class BeeAIInstrumentation extends InstrumentationBase {
9
+ private oiTracer;
10
+ constructor({ instrumentationConfig, traceConfig, }?: {
11
+ /**
12
+ * The config for the instrumentation
13
+ * @see {@link InstrumentationConfig}
14
+ */
15
+ instrumentationConfig?: InstrumentationConfig;
16
+ /**
17
+ * The OpenInference trace configuration. Can be used to mask or redact sensitive information on spans.
18
+ * @see {@link TraceConfigOptions}
19
+ */
20
+ traceConfig?: TraceConfigOptions;
21
+ });
22
+ protected init(): InstrumentationNodeModuleDefinition;
23
+ /**
24
+ * Manually instruments the BeeAI module. This is needed when the module is not loaded via require (commonjs)
25
+ * @param {openai} module
26
+ */
27
+ manuallyInstrument(module: typeof bee): void;
28
+ private patch;
29
+ /**
30
+ * Un-patches the OpenAI module's chat completions API
31
+ */
32
+ private unpatch;
33
+ }
34
+ //# sourceMappingURL=instrumentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mCAAmC,EACnC,qBAAqB,EACtB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAY,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAW3E;;GAEG;AACH,wBAAgB,SAAS,YAExB;AAED,qBAAa,oBAAqB,SAAQ,mBAAmB;IAC3D,OAAO,CAAC,QAAQ,CAAW;gBAEf,EACV,qBAAqB,EACrB,WAAW,GACZ,GAAE;QACD;;;WAGG;QACH,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;QAC9C;;;WAGG;QACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;KAC7B;IASN,SAAS,CAAC,IAAI;IAWd;;;OAGG;IACH,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG;IAKrC,OAAO,CAAC,KAAK;IA+Bb;;OAEG;IACH,OAAO,CAAC,OAAO;CAehB"}
@@ -0,0 +1,71 @@
1
+ import { InstrumentationBase, InstrumentationNodeModuleDefinition, } from "@opentelemetry/instrumentation";
2
+ import { diag } from "@opentelemetry/api";
3
+ import { Version } from "beeai-framework";
4
+ import { OITracer } from "@arizeai/openinference-core";
5
+ import { createTelemetryMiddleware } from "./middleware";
6
+ const MODULE_NAME = "beeai-framework";
7
+ /**
8
+ * Flag to check if the openai module has been patched
9
+ * Note: This is a fallback in case the module is made immutable (e.x. Deno, webpack, etc.)
10
+ */
11
+ let _isOpenInferencePatched = false;
12
+ /**
13
+ * function to check if instrumentation is enabled / disabled
14
+ */
15
+ export function isPatched() {
16
+ return _isOpenInferencePatched;
17
+ }
18
+ export class BeeAIInstrumentation extends InstrumentationBase {
19
+ constructor({ instrumentationConfig, traceConfig, } = {}) {
20
+ super("@arizeai/openinference-instrumentation-beeai", Version, Object.assign({}, instrumentationConfig));
21
+ this.oiTracer = new OITracer({ tracer: this.tracer, traceConfig });
22
+ }
23
+ init() {
24
+ const module = new InstrumentationNodeModuleDefinition(MODULE_NAME, ["0.*"], this.patch.bind(this), this.unpatch.bind(this));
25
+ return module;
26
+ }
27
+ /**
28
+ * Manually instruments the BeeAI module. This is needed when the module is not loaded via require (commonjs)
29
+ * @param {openai} module
30
+ */
31
+ manuallyInstrument(module) {
32
+ diag.debug(`[BeeaiInstrumentation] Manually instrumenting ${MODULE_NAME}`);
33
+ this.patch(module);
34
+ }
35
+ patch(module) {
36
+ if (!(module === null || module === void 0 ? void 0 : module.BaseAgent)) {
37
+ diag.warn("[BeeaiInstrumentation] BaseAgent not found, skipping instrumentation.");
38
+ return module;
39
+ }
40
+ if ((module === null || module === void 0 ? void 0 : module.openInferencePatched) || _isOpenInferencePatched) {
41
+ return module;
42
+ }
43
+ diag.info("[BeeaiInstrumentation] Patching BaseAgent.run");
44
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
45
+ const instrumentation = this;
46
+ this._wrap(module.BaseAgent.prototype, "run", (original) => {
47
+ return function wrappedRun(...args) {
48
+ const returned = original.apply(this, args);
49
+ returned.middleware(createTelemetryMiddleware(instrumentation.oiTracer));
50
+ return returned;
51
+ };
52
+ });
53
+ return module;
54
+ }
55
+ /**
56
+ * Un-patches the OpenAI module's chat completions API
57
+ */
58
+ unpatch(moduleExports, moduleVersion) {
59
+ diag.debug(`Removing patch for ${MODULE_NAME}@${moduleVersion}`);
60
+ this._unwrap(moduleExports.BaseAgent.prototype, "run");
61
+ _isOpenInferencePatched = false;
62
+ try {
63
+ // This can fail if the module is made immutable via the runtime or bundler
64
+ moduleExports.openInferencePatched = false;
65
+ }
66
+ catch (e) {
67
+ diag.warn(`Failed to unset ${MODULE_NAME} patched flag on the module`, e);
68
+ }
69
+ }
70
+ }
71
+ //# sourceMappingURL=instrumentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mCAAmC,GAEpC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG1C,OAAO,EAAE,QAAQ,EAAsB,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAEzD,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC;;;GAGG;AACH,IAAI,uBAAuB,GAAG,KAAK,CAAC;AAEpC;;GAEG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,uBAAuB,CAAC;AACjC,CAAC;AAED,MAAM,OAAO,oBAAqB,SAAQ,mBAAmB;IAG3D,YAAY,EACV,qBAAqB,EACrB,WAAW,MAYT,EAAE;QACJ,KAAK,CACH,8CAA8C,EAC9C,OAAO,EACP,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,qBAAqB,CAAC,CACzC,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;IACrE,CAAC;IAES,IAAI;QACZ,MAAM,MAAM,GAAG,IAAI,mCAAmC,CACpD,WAAW,EACX,CAAC,KAAK,CAAC,EACP,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EACrB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CACxB,CA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S,EAAE,KAAK,CAAC,CAAC;QAEvD,uBAAuB,GAAG,KAAK,CAAC;QAChC,IAAI,CAAC;YACH,2EAA2E;YAC3E,aAAa,CAAC,oBAAoB,GAAG,KAAK,CAAC;QAC7C,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,IAAI,CAAC,mBAAmB,WAAW,6BAA6B,EAAE,CAAC,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright 2025 IBM Corp.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { OITracer } from "@arizeai/openinference-core";
17
+ import type { GetRunContext, RunInstance } from "beeai-framework/context";
18
+ export declare const activeTracesMap: Map<string, string>;
19
+ /**
20
+ * First we collect, filter and transform events from the beeai emitter to our internal framework spans in the `emitter.match("*.*"` block
21
+ * Some special data are collected in other `emitter.match` blocks like (history, response, rawPromt)
22
+ *
23
+ * Then we create the open telemetry spans when all data are collected. We are retroactively deleting some unnecessary internal spans
24
+ * see "emitter.match((event) => event.path === `${basePath}.run.${finishEventName}`" section
25
+ */
26
+ export declare function createTelemetryMiddleware(tracer: OITracer): (context: GetRunContext<RunInstance, unknown>) => void;
27
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAWvD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAkB1E,eAAO,MAAM,eAAe,qBAA4B,CAAC;AAEzD;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,QAAQ,aACvC,aAAa,CAAC,WAAW,EAAE,OAAO,CAAC,UAsQrD"}
@@ -0,0 +1,241 @@
1
+ /**
2
+ * Copyright 2025 IBM Corp.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { getSerializedObjectSafe } from "./helpers/getSerializedObjectSafe";
17
+ import { createSpan } from "./helpers/create-span";
18
+ import { IdNameManager } from "./helpers/idNameManager";
19
+ import { getErrorSafe } from "./helpers/getErrorSafe";
20
+ import { findLast, isEmpty } from "remeda";
21
+ import { FrameworkError } from "beeai-framework/errors";
22
+ import { Version } from "beeai-framework/version";
23
+ import { Role } from "beeai-framework/backend/message";
24
+ import { traceSerializer } from "./helpers/traceSerializer";
25
+ import { errorLLMEventName, finishLLMEventName, INSTRUMENTATION_IGNORED_KEYS, newTokenLLMEventName, partialUpdateEventName, successLLMEventName, } from "./config";
26
+ import { createFullPath } from "beeai-framework/emitter/utils";
27
+ import { BaseAgent } from "beeai-framework/agents/base";
28
+ import { diag } from "@opentelemetry/api";
29
+ import { buildTraceTree } from "./helpers/buildTraceTree";
30
+ import { SemanticConventions } from "@arizeai/openinference-semantic-conventions";
31
+ export const activeTracesMap = new Map();
32
+ /**
33
+ * First we collect, filter and transform events from the beeai emitter to our internal framework spans in the `emitter.match("*.*"` block
34
+ * Some special data are collected in other `emitter.match` blocks like (history, response, rawPromt)
35
+ *
36
+ * Then we create the open telemetry spans when all data are collected. We are retroactively deleting some unnecessary internal spans
37
+ * see "emitter.match((event) => event.path === `${basePath}.run.${finishEventName}`" section
38
+ */
39
+ export function createTelemetryMiddleware(tracer) {
40
+ return (context) => {
41
+ var _a, _b, _c, _d;
42
+ if (!((_b = (_a = context.emitter) === null || _a === void 0 ? void 0 : _a.trace) === null || _b === void 0 ? void 0 : _b.id)) {
43
+ throw new FrameworkError(`Fatal error. Missing traceId`, [], { context });
44
+ }
45
+ const traceId = (_d = (_c = context.emitter) === null || _c === void 0 ? void 0 : _c.trace) === null || _d === void 0 ? void 0 : _d.id;
46
+ if (activeTracesMap.has(traceId)) {
47
+ return;
48
+ }
49
+ activeTracesMap.set(traceId, context.instance.constructor.name);
50
+ diag.debug("createTelemetryMiddleware", {
51
+ source: context.instance.constructor.name,
52
+ traceId: traceId,
53
+ });
54
+ const { emitter, runParams, instance } = context;
55
+ const basePath = createFullPath(emitter.namespace, "");
56
+ let prompt = null;
57
+ if (instance instanceof BaseAgent) {
58
+ prompt = runParams[0].prompt;
59
+ }
60
+ const spansMap = new Map();
61
+ const parentIdsMap = new Map();
62
+ const spansToDeleteMap = new Map();
63
+ let generatedMessage = undefined;
64
+ let history = undefined;
65
+ const groupIterations = [];
66
+ const idNameManager = new IdNameManager();
67
+ const eventsIterationsMap = new Map();
68
+ const startTimeDate = new Date().getTime();
69
+ const startTimePerf = performance.now();
70
+ function convertDateToPerformance(date) {
71
+ return date.getTime() - startTimeDate + startTimePerf;
72
+ }
73
+ const serializer = traceSerializer({
74
+ ignored_keys: INSTRUMENTATION_IGNORED_KEYS,
75
+ });
76
+ function cleanSpanSources({ spanId }) {
77
+ var _a;
78
+ const parentId = (_a = spansMap.get(spanId)) === null || _a === void 0 ? void 0 : _a.parent_id;
79
+ if (!parentId) {
80
+ return;
81
+ }
82
+ const spanCount = parentIdsMap.get(parentId);
83
+ if (!spanCount) {
84
+ return;
85
+ }
86
+ if (spanCount > 1) {
87
+ // increase the span count for the parentId
88
+ parentIdsMap.set(parentId, spanCount - 1);
89
+ }
90
+ else if (spanCount === 1) {
91
+ parentIdsMap.delete(parentId);
92
+ // check the `spansToDelete` if the span should be deleted when it has no children's
93
+ if (spansToDeleteMap.has(parentId)) {
94
+ spansMap.delete(parentId);
95
+ spansToDeleteMap.delete(parentId);
96
+ }
97
+ }
98
+ }
99
+ /**
100
+ * Create OpenTelemetry spans from collected data
101
+ */
102
+ emitter.match((event) => event.path === `${basePath}.run.${finishLLMEventName}`, async (_, meta) => {
103
+ var _a;
104
+ try {
105
+ diag.debug("run finish event", { path: meta.path, traceId: traceId });
106
+ if (!prompt && instance instanceof BaseAgent) {
107
+ prompt = (_a = findLast(instance.memory.messages, (message) => message.role === Role.USER)) === null || _a === void 0 ? void 0 : _a.text;
108
+ if (!prompt) {
109
+ throw new FrameworkError("The prompt must be defined for the Agent's run", [], {
110
+ context,
111
+ });
112
+ }
113
+ }
114
+ // create tracer spans from collected data
115
+ buildTraceTree({
116
+ tracer,
117
+ data: {
118
+ prompt: prompt,
119
+ history,
120
+ generatedMessage,
121
+ spans: JSON.parse(serializer(Array.from(spansMap.values()))),
122
+ traceId,
123
+ version: Version,
124
+ runErrorSpanKey: `${basePath}.run.${errorLLMEventName}`,
125
+ startTime: startTimePerf,
126
+ endTime: performance.now(),
127
+ source: activeTracesMap.get(traceId),
128
+ },
129
+ });
130
+ }
131
+ catch (e) {
132
+ diag.warn("Instrumentation error", e);
133
+ }
134
+ finally {
135
+ activeTracesMap.delete(traceId);
136
+ }
137
+ });
138
+ /**
139
+ * This block collects all "not run category" events with their data and prepares spans for the OpenTelemetry.
140
+ * The huge number of `newToken` events are skipped and only the last one for each parent event is saved because of `generated_token_count` information
141
+ * The framework event tree structure is different from the open-telemetry tree structure and must be transformed from groupId and parentGroupId pattern via idNameManager
142
+ * The artificial "iteration" main tree level is computed from the `meta.groupId`
143
+ */
144
+ emitter.match("*.*", (data, meta) => {
145
+ var _a, _b;
146
+ // allow `run.error` event due to the runtime error information
147
+ if (meta.path.includes(".run.") &&
148
+ meta.path !== `${basePath}.run.${errorLLMEventName}`) {
149
+ return;
150
+ }
151
+ // skip all new token events
152
+ if (meta.name === newTokenLLMEventName) {
153
+ return;
154
+ }
155
+ if (!((_a = meta.trace) === null || _a === void 0 ? void 0 : _a.runId)) {
156
+ throw new FrameworkError(`Fatal error. Missing runId for event: ${meta.path}`, [], {
157
+ context,
158
+ });
159
+ }
160
+ /**
161
+ * create groupId span level (id does not exist)
162
+ * I use only the top-level groups like iterations other nested groups like tokens would introduce unuseful complexity
163
+ */
164
+ if (meta.groupId &&
165
+ !meta.trace.parentRunId &&
166
+ !groupIterations.includes(meta.groupId)) {
167
+ spansMap.set(meta.groupId, createSpan({
168
+ id: meta.groupId,
169
+ name: meta.groupId,
170
+ target: "groupId",
171
+ data: {
172
+ [SemanticConventions.OPENINFERENCE_SPAN_KIND]: "Chain",
173
+ },
174
+ startedAt: convertDateToPerformance(meta.createdAt),
175
+ }));
176
+ groupIterations.push(meta.groupId);
177
+ }
178
+ const { spanId, parentSpanId } = idNameManager.getIds({
179
+ path: meta.path,
180
+ id: meta.id,
181
+ runId: meta.trace.runId,
182
+ parentRunId: meta.trace.parentRunId,
183
+ groupId: meta.groupId,
184
+ });
185
+ const serializedData = getSerializedObjectSafe(data, meta);
186
+ // skip partialUpdate events with no data
187
+ if (meta.name === partialUpdateEventName && isEmpty(serializedData)) {
188
+ return;
189
+ }
190
+ const span = createSpan(Object.assign(Object.assign({ id: spanId, name: meta.name, target: meta.path }, (parentSpanId && { parent: { id: parentSpanId } })), { ctx: meta.context, data: serializedData, error: getErrorSafe(data), startedAt: convertDateToPerformance(meta.createdAt) }));
191
+ const lastIteration = groupIterations[groupIterations.length - 1];
192
+ // delete the `partialUpdate` event if does not have nested spans
193
+ const lastIterationEventSpanId = (_b = eventsIterationsMap
194
+ .get(lastIteration)) === null || _b === void 0 ? void 0 : _b.get(meta.name);
195
+ if (lastIterationEventSpanId &&
196
+ partialUpdateEventName === meta.name &&
197
+ spansMap.has(lastIterationEventSpanId)) {
198
+ const { context } = spansMap.get(lastIterationEventSpanId);
199
+ if (parentIdsMap.has(context.span_id)) {
200
+ spansToDeleteMap.set(lastIterationEventSpanId, undefined);
201
+ }
202
+ else {
203
+ // delete span
204
+ cleanSpanSources({ spanId: lastIterationEventSpanId });
205
+ spansMap.delete(lastIterationEventSpanId);
206
+ }
207
+ }
208
+ // create new span
209
+ spansMap.set(span.context.span_id, span);
210
+ // update number of nested spans for parent_id if exists
211
+ if (span.parent_id) {
212
+ parentIdsMap.set(span.parent_id, (parentIdsMap.get(span.parent_id) || 0) + 1);
213
+ }
214
+ // save the last event for each iteration
215
+ if (groupIterations.length > 0) {
216
+ if (eventsIterationsMap.has(lastIteration)) {
217
+ eventsIterationsMap
218
+ .get(lastIteration)
219
+ .set(meta.name, span.context.span_id);
220
+ }
221
+ else {
222
+ eventsIterationsMap.set(lastIteration, new Map().set(meta.name, span.context.span_id));
223
+ }
224
+ }
225
+ });
226
+ // The generated response and message history are collected from the `success` agent's event
227
+ emitter.match((event) => event.name === successLLMEventName &&
228
+ event.creator instanceof BaseAgent, (data) => {
229
+ const { data: dataObject, memory } = data;
230
+ generatedMessage = {
231
+ role: dataObject.role,
232
+ text: dataObject.text,
233
+ };
234
+ history = memory.messages.map((msg) => ({
235
+ text: msg.text,
236
+ role: msg.role,
237
+ }));
238
+ });
239
+ };
240
+ }
241
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;A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