@microsoft/opentelemetry 0.1.0-alpha.2 → 0.1.0-alpha.3

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 (260) hide show
  1. package/dist/commonjs/a365/configuration/A365Configuration.d.ts +42 -0
  2. package/dist/commonjs/a365/configuration/A365Configuration.d.ts.map +1 -0
  3. package/dist/commonjs/a365/configuration/A365Configuration.js +162 -0
  4. package/dist/commonjs/a365/configuration/A365Configuration.js.map +1 -0
  5. package/dist/commonjs/a365/configuration/A365ConfigurationOptions.d.ts +53 -0
  6. package/dist/commonjs/a365/configuration/A365ConfigurationOptions.d.ts.map +1 -0
  7. package/dist/commonjs/a365/configuration/A365ConfigurationOptions.js +5 -0
  8. package/dist/commonjs/a365/configuration/A365ConfigurationOptions.js.map +1 -0
  9. package/dist/commonjs/a365/configuration/index.d.ts +3 -0
  10. package/dist/commonjs/a365/configuration/index.d.ts.map +1 -0
  11. package/dist/commonjs/a365/configuration/index.js +9 -0
  12. package/dist/commonjs/a365/configuration/index.js.map +1 -0
  13. package/dist/commonjs/a365/constants.d.ts +76 -0
  14. package/dist/commonjs/a365/constants.d.ts.map +1 -0
  15. package/dist/commonjs/a365/constants.js +99 -0
  16. package/dist/commonjs/a365/constants.js.map +1 -0
  17. package/dist/commonjs/a365/context/tokenContext.d.ts +25 -0
  18. package/dist/commonjs/a365/context/tokenContext.d.ts.map +1 -0
  19. package/dist/commonjs/a365/context/tokenContext.js +67 -0
  20. package/dist/commonjs/a365/context/tokenContext.js.map +1 -0
  21. package/dist/commonjs/a365/context.d.ts +31 -0
  22. package/dist/commonjs/a365/context.d.ts.map +1 -0
  23. package/dist/commonjs/a365/context.js +109 -0
  24. package/dist/commonjs/a365/context.js.map +1 -0
  25. package/dist/commonjs/a365/contracts.d.ts +250 -0
  26. package/dist/commonjs/a365/contracts.d.ts.map +1 -0
  27. package/dist/commonjs/a365/contracts.js +52 -0
  28. package/dist/commonjs/a365/contracts.js.map +1 -0
  29. package/dist/commonjs/a365/exporter/Agent365Exporter.d.ts +25 -0
  30. package/dist/commonjs/a365/exporter/Agent365Exporter.d.ts.map +1 -0
  31. package/dist/commonjs/a365/exporter/Agent365Exporter.js +220 -0
  32. package/dist/commonjs/a365/exporter/Agent365Exporter.js.map +1 -0
  33. package/dist/commonjs/a365/exporter/Agent365ExporterOptions.d.ts +43 -0
  34. package/dist/commonjs/a365/exporter/Agent365ExporterOptions.d.ts.map +1 -0
  35. package/dist/commonjs/a365/exporter/Agent365ExporterOptions.js +30 -0
  36. package/dist/commonjs/a365/exporter/Agent365ExporterOptions.js.map +1 -0
  37. package/dist/commonjs/a365/exporter/ExporterEventNames.d.ts +9 -0
  38. package/dist/commonjs/a365/exporter/ExporterEventNames.d.ts.map +1 -0
  39. package/dist/commonjs/a365/exporter/ExporterEventNames.js +15 -0
  40. package/dist/commonjs/a365/exporter/ExporterEventNames.js.map +1 -0
  41. package/dist/commonjs/a365/exporter/index.d.ts +6 -0
  42. package/dist/commonjs/a365/exporter/index.d.ts.map +1 -0
  43. package/dist/commonjs/a365/exporter/index.js +15 -0
  44. package/dist/commonjs/a365/exporter/index.js.map +1 -0
  45. package/dist/commonjs/a365/exporter/utils.d.ts +41 -0
  46. package/dist/commonjs/a365/exporter/utils.d.ts.map +1 -0
  47. package/dist/commonjs/a365/exporter/utils.js +410 -0
  48. package/dist/commonjs/a365/exporter/utils.js.map +1 -0
  49. package/dist/commonjs/a365/index.d.ts +16 -0
  50. package/dist/commonjs/a365/index.d.ts.map +1 -0
  51. package/dist/commonjs/a365/index.js +54 -0
  52. package/dist/commonjs/a365/index.js.map +1 -0
  53. package/dist/commonjs/a365/message-utils.d.ts +42 -0
  54. package/dist/commonjs/a365/message-utils.d.ts.map +1 -0
  55. package/dist/commonjs/a365/message-utils.js +116 -0
  56. package/dist/commonjs/a365/message-utils.js.map +1 -0
  57. package/dist/commonjs/a365/middleware/BaggageBuilder.d.ts +112 -0
  58. package/dist/commonjs/a365/middleware/BaggageBuilder.d.ts.map +1 -0
  59. package/dist/commonjs/a365/middleware/BaggageBuilder.js +249 -0
  60. package/dist/commonjs/a365/middleware/BaggageBuilder.js.map +1 -0
  61. package/dist/commonjs/a365/middleware/index.d.ts +2 -0
  62. package/dist/commonjs/a365/middleware/index.d.ts.map +1 -0
  63. package/dist/commonjs/a365/middleware/index.js +9 -0
  64. package/dist/commonjs/a365/middleware/index.js.map +1 -0
  65. package/dist/commonjs/a365/processors/A365SpanProcessor.d.ts +32 -0
  66. package/dist/commonjs/a365/processors/A365SpanProcessor.d.ts.map +1 -0
  67. package/dist/commonjs/a365/processors/A365SpanProcessor.js +104 -0
  68. package/dist/commonjs/a365/processors/A365SpanProcessor.js.map +1 -0
  69. package/dist/commonjs/a365/processors/PerRequestSpanProcessor.d.ts +44 -0
  70. package/dist/commonjs/a365/processors/PerRequestSpanProcessor.d.ts.map +1 -0
  71. package/dist/commonjs/a365/processors/PerRequestSpanProcessor.js +260 -0
  72. package/dist/commonjs/a365/processors/PerRequestSpanProcessor.js.map +1 -0
  73. package/dist/commonjs/a365/processors/index.d.ts +5 -0
  74. package/dist/commonjs/a365/processors/index.d.ts.map +1 -0
  75. package/dist/commonjs/a365/processors/index.js +13 -0
  76. package/dist/commonjs/a365/processors/index.js.map +1 -0
  77. package/dist/commonjs/a365/processors/util.d.ts +10 -0
  78. package/dist/commonjs/a365/processors/util.d.ts.map +1 -0
  79. package/dist/commonjs/a365/processors/util.js +56 -0
  80. package/dist/commonjs/a365/processors/util.js.map +1 -0
  81. package/dist/commonjs/a365/scopes/ExecuteToolScope.d.ts +24 -0
  82. package/dist/commonjs/a365/scopes/ExecuteToolScope.d.ts.map +1 -0
  83. package/dist/commonjs/a365/scopes/ExecuteToolScope.js +60 -0
  84. package/dist/commonjs/a365/scopes/ExecuteToolScope.js.map +1 -0
  85. package/dist/commonjs/a365/scopes/InferenceScope.d.ts +29 -0
  86. package/dist/commonjs/a365/scopes/InferenceScope.d.ts.map +1 -0
  87. package/dist/commonjs/a365/scopes/InferenceScope.js +75 -0
  88. package/dist/commonjs/a365/scopes/InferenceScope.js.map +1 -0
  89. package/dist/commonjs/a365/scopes/InvokeAgentScope.d.ts +25 -0
  90. package/dist/commonjs/a365/scopes/InvokeAgentScope.d.ts.map +1 -0
  91. package/dist/commonjs/a365/scopes/InvokeAgentScope.js +84 -0
  92. package/dist/commonjs/a365/scopes/InvokeAgentScope.js.map +1 -0
  93. package/dist/commonjs/a365/scopes/OpenTelemetryScope.d.ts +59 -0
  94. package/dist/commonjs/a365/scopes/OpenTelemetryScope.d.ts.map +1 -0
  95. package/dist/commonjs/a365/scopes/OpenTelemetryScope.js +199 -0
  96. package/dist/commonjs/a365/scopes/OpenTelemetryScope.js.map +1 -0
  97. package/dist/commonjs/a365/scopes/OutputScope.d.ts +26 -0
  98. package/dist/commonjs/a365/scopes/OutputScope.d.ts.map +1 -0
  99. package/dist/commonjs/a365/scopes/OutputScope.js +73 -0
  100. package/dist/commonjs/a365/scopes/OutputScope.js.map +1 -0
  101. package/dist/commonjs/a365/scopes/index.d.ts +6 -0
  102. package/dist/commonjs/a365/scopes/index.d.ts.map +1 -0
  103. package/dist/commonjs/a365/scopes/index.js +16 -0
  104. package/dist/commonjs/a365/scopes/index.js.map +1 -0
  105. package/dist/commonjs/a365/utils/utils.d.ts +6 -0
  106. package/dist/commonjs/a365/utils/utils.d.ts.map +1 -0
  107. package/dist/commonjs/a365/utils/utils.js +14 -0
  108. package/dist/commonjs/a365/utils/utils.js.map +1 -0
  109. package/dist/commonjs/azureMonitor/metrics/quickpulse/types.d.ts +1 -1
  110. package/dist/commonjs/azureMonitor/traces/handler.d.ts.map +1 -1
  111. package/dist/commonjs/azureMonitor/traces/handler.js +8 -2
  112. package/dist/commonjs/azureMonitor/traces/handler.js.map +1 -1
  113. package/dist/commonjs/distro/distro.d.ts +1 -1
  114. package/dist/commonjs/distro/distro.d.ts.map +1 -1
  115. package/dist/commonjs/distro/distro.js +44 -92
  116. package/dist/commonjs/distro/distro.js.map +1 -1
  117. package/dist/commonjs/distro/types.d.ts +2 -1
  118. package/dist/commonjs/distro/types.d.ts.map +1 -1
  119. package/dist/commonjs/index.d.ts +5 -0
  120. package/dist/commonjs/index.d.ts.map +1 -1
  121. package/dist/commonjs/index.js +33 -1
  122. package/dist/commonjs/index.js.map +1 -1
  123. package/dist/commonjs/package.json +1 -0
  124. package/dist/commonjs/shared/jsonConfig.d.ts +2 -1
  125. package/dist/commonjs/shared/jsonConfig.d.ts.map +1 -1
  126. package/dist/commonjs/shared/module.js +15 -11
  127. package/dist/commonjs/shared/module.js.map +1 -1
  128. package/dist/commonjs/types.d.ts +4 -30
  129. package/dist/commonjs/types.d.ts.map +1 -1
  130. package/dist/commonjs/types.js +1 -1
  131. package/dist/commonjs/types.js.map +1 -1
  132. package/dist/esm/a365/configuration/A365Configuration.d.ts +42 -0
  133. package/dist/esm/a365/configuration/A365Configuration.d.ts.map +1 -0
  134. package/dist/esm/a365/configuration/A365Configuration.js +158 -0
  135. package/dist/esm/a365/configuration/A365Configuration.js.map +1 -0
  136. package/dist/esm/a365/configuration/A365ConfigurationOptions.d.ts +53 -0
  137. package/dist/esm/a365/configuration/A365ConfigurationOptions.d.ts.map +1 -0
  138. package/dist/esm/a365/configuration/A365ConfigurationOptions.js +4 -0
  139. package/dist/esm/a365/configuration/A365ConfigurationOptions.js.map +1 -0
  140. package/dist/esm/a365/configuration/index.d.ts +3 -0
  141. package/dist/esm/a365/configuration/index.d.ts.map +1 -0
  142. package/dist/esm/a365/configuration/index.js +4 -0
  143. package/dist/esm/a365/configuration/index.js.map +1 -0
  144. package/dist/esm/a365/constants.d.ts +76 -0
  145. package/dist/esm/a365/constants.d.ts.map +1 -0
  146. package/dist/esm/a365/constants.js +95 -0
  147. package/dist/esm/a365/constants.js.map +1 -0
  148. package/dist/esm/a365/context/tokenContext.d.ts +25 -0
  149. package/dist/esm/a365/context/tokenContext.d.ts.map +1 -0
  150. package/dist/esm/a365/context/tokenContext.js +62 -0
  151. package/dist/esm/a365/context/tokenContext.js.map +1 -0
  152. package/dist/esm/a365/context.d.ts +31 -0
  153. package/dist/esm/a365/context.d.ts.map +1 -0
  154. package/dist/esm/a365/context.js +101 -0
  155. package/dist/esm/a365/context.js.map +1 -0
  156. package/dist/esm/a365/contracts.d.ts +250 -0
  157. package/dist/esm/a365/contracts.d.ts.map +1 -0
  158. package/dist/esm/a365/contracts.js +49 -0
  159. package/dist/esm/a365/contracts.js.map +1 -0
  160. package/dist/esm/a365/exporter/Agent365Exporter.d.ts +25 -0
  161. package/dist/esm/a365/exporter/Agent365Exporter.d.ts.map +1 -0
  162. package/dist/esm/a365/exporter/Agent365Exporter.js +216 -0
  163. package/dist/esm/a365/exporter/Agent365Exporter.js.map +1 -0
  164. package/dist/esm/a365/exporter/Agent365ExporterOptions.d.ts +43 -0
  165. package/dist/esm/a365/exporter/Agent365ExporterOptions.d.ts.map +1 -0
  166. package/dist/esm/a365/exporter/Agent365ExporterOptions.js +26 -0
  167. package/dist/esm/a365/exporter/Agent365ExporterOptions.js.map +1 -0
  168. package/dist/esm/a365/exporter/ExporterEventNames.d.ts +9 -0
  169. package/dist/esm/a365/exporter/ExporterEventNames.d.ts.map +1 -0
  170. package/dist/esm/a365/exporter/ExporterEventNames.js +12 -0
  171. package/dist/esm/a365/exporter/ExporterEventNames.js.map +1 -0
  172. package/dist/esm/a365/exporter/index.d.ts +6 -0
  173. package/dist/esm/a365/exporter/index.d.ts.map +1 -0
  174. package/dist/esm/a365/exporter/index.js +7 -0
  175. package/dist/esm/a365/exporter/index.js.map +1 -0
  176. package/dist/esm/a365/exporter/utils.d.ts +41 -0
  177. package/dist/esm/a365/exporter/utils.d.ts.map +1 -0
  178. package/dist/esm/a365/exporter/utils.js +398 -0
  179. package/dist/esm/a365/exporter/utils.js.map +1 -0
  180. package/dist/esm/a365/index.d.ts +16 -0
  181. package/dist/esm/a365/index.d.ts.map +1 -0
  182. package/dist/esm/a365/index.js +20 -0
  183. package/dist/esm/a365/index.js.map +1 -0
  184. package/dist/esm/a365/message-utils.d.ts +42 -0
  185. package/dist/esm/a365/message-utils.d.ts.map +1 -0
  186. package/dist/esm/a365/message-utils.js +107 -0
  187. package/dist/esm/a365/message-utils.js.map +1 -0
  188. package/dist/esm/a365/middleware/BaggageBuilder.d.ts +112 -0
  189. package/dist/esm/a365/middleware/BaggageBuilder.d.ts.map +1 -0
  190. package/dist/esm/a365/middleware/BaggageBuilder.js +244 -0
  191. package/dist/esm/a365/middleware/BaggageBuilder.js.map +1 -0
  192. package/dist/esm/a365/middleware/index.d.ts +2 -0
  193. package/dist/esm/a365/middleware/index.d.ts.map +1 -0
  194. package/dist/esm/a365/middleware/index.js +4 -0
  195. package/dist/esm/a365/middleware/index.js.map +1 -0
  196. package/dist/esm/a365/processors/A365SpanProcessor.d.ts +32 -0
  197. package/dist/esm/a365/processors/A365SpanProcessor.d.ts.map +1 -0
  198. package/dist/esm/a365/processors/A365SpanProcessor.js +100 -0
  199. package/dist/esm/a365/processors/A365SpanProcessor.js.map +1 -0
  200. package/dist/esm/a365/processors/PerRequestSpanProcessor.d.ts +44 -0
  201. package/dist/esm/a365/processors/PerRequestSpanProcessor.d.ts.map +1 -0
  202. package/dist/esm/a365/processors/PerRequestSpanProcessor.js +256 -0
  203. package/dist/esm/a365/processors/PerRequestSpanProcessor.js.map +1 -0
  204. package/dist/esm/a365/processors/index.d.ts +5 -0
  205. package/dist/esm/a365/processors/index.d.ts.map +1 -0
  206. package/dist/esm/a365/processors/index.js +6 -0
  207. package/dist/esm/a365/processors/index.js.map +1 -0
  208. package/dist/esm/a365/processors/util.d.ts +10 -0
  209. package/dist/esm/a365/processors/util.d.ts.map +1 -0
  210. package/dist/esm/a365/processors/util.js +53 -0
  211. package/dist/esm/a365/processors/util.js.map +1 -0
  212. package/dist/esm/a365/scopes/ExecuteToolScope.d.ts +24 -0
  213. package/dist/esm/a365/scopes/ExecuteToolScope.d.ts.map +1 -0
  214. package/dist/esm/a365/scopes/ExecuteToolScope.js +56 -0
  215. package/dist/esm/a365/scopes/ExecuteToolScope.js.map +1 -0
  216. package/dist/esm/a365/scopes/InferenceScope.d.ts +29 -0
  217. package/dist/esm/a365/scopes/InferenceScope.d.ts.map +1 -0
  218. package/dist/esm/a365/scopes/InferenceScope.js +71 -0
  219. package/dist/esm/a365/scopes/InferenceScope.js.map +1 -0
  220. package/dist/esm/a365/scopes/InvokeAgentScope.d.ts +25 -0
  221. package/dist/esm/a365/scopes/InvokeAgentScope.d.ts.map +1 -0
  222. package/dist/esm/a365/scopes/InvokeAgentScope.js +80 -0
  223. package/dist/esm/a365/scopes/InvokeAgentScope.js.map +1 -0
  224. package/dist/esm/a365/scopes/OpenTelemetryScope.d.ts +59 -0
  225. package/dist/esm/a365/scopes/OpenTelemetryScope.d.ts.map +1 -0
  226. package/dist/esm/a365/scopes/OpenTelemetryScope.js +195 -0
  227. package/dist/esm/a365/scopes/OpenTelemetryScope.js.map +1 -0
  228. package/dist/esm/a365/scopes/OutputScope.d.ts +26 -0
  229. package/dist/esm/a365/scopes/OutputScope.d.ts.map +1 -0
  230. package/dist/esm/a365/scopes/OutputScope.js +69 -0
  231. package/dist/esm/a365/scopes/OutputScope.js.map +1 -0
  232. package/dist/esm/a365/scopes/index.d.ts +6 -0
  233. package/dist/esm/a365/scopes/index.d.ts.map +1 -0
  234. package/dist/esm/a365/scopes/index.js +8 -0
  235. package/dist/esm/a365/scopes/index.js.map +1 -0
  236. package/dist/esm/a365/utils/utils.d.ts +6 -0
  237. package/dist/esm/a365/utils/utils.d.ts.map +1 -0
  238. package/dist/esm/a365/utils/utils.js +11 -0
  239. package/dist/esm/a365/utils/utils.js.map +1 -0
  240. package/dist/esm/azureMonitor/metrics/quickpulse/types.d.ts +1 -1
  241. package/dist/esm/azureMonitor/traces/handler.d.ts.map +1 -1
  242. package/dist/esm/azureMonitor/traces/handler.js +5 -1
  243. package/dist/esm/azureMonitor/traces/handler.js.map +1 -1
  244. package/dist/esm/distro/distro.d.ts +1 -1
  245. package/dist/esm/distro/distro.d.ts.map +1 -1
  246. package/dist/esm/distro/distro.js +44 -92
  247. package/dist/esm/distro/distro.js.map +1 -1
  248. package/dist/esm/distro/types.d.ts +2 -1
  249. package/dist/esm/distro/types.d.ts.map +1 -1
  250. package/dist/esm/index.d.ts +5 -0
  251. package/dist/esm/index.d.ts.map +1 -1
  252. package/dist/esm/index.js +4 -0
  253. package/dist/esm/index.js.map +1 -1
  254. package/dist/esm/shared/jsonConfig.d.ts +2 -1
  255. package/dist/esm/shared/jsonConfig.d.ts.map +1 -1
  256. package/dist/esm/types.d.ts +4 -30
  257. package/dist/esm/types.d.ts.map +1 -1
  258. package/dist/esm/types.js +1 -1
  259. package/dist/esm/types.js.map +1 -1
  260. package/package.json +3 -4
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.InferenceScope = void 0;
6
+ const api_1 = require("@opentelemetry/api");
7
+ const OpenTelemetryScope_js_1 = require("./OpenTelemetryScope.js");
8
+ const constants_js_1 = require("../constants.js");
9
+ /**
10
+ * Provides OpenTelemetry tracing scope for generative AI inference operations.
11
+ */
12
+ class InferenceScope extends OpenTelemetryScope_js_1.OpenTelemetryScope {
13
+ /**
14
+ * Creates and starts a new scope for inference tracing.
15
+ *
16
+ * @param request Request payload (channel, conversationId, content, sessionId).
17
+ * @param details The inference call details (model, provider, tokens, etc.).
18
+ * @param agentDetails The agent performing the inference. `tenantId` is required.
19
+ * @param userDetails Optional human caller identity.
20
+ * @param spanDetails Optional span configuration. `spanKind` is always CLIENT.
21
+ */
22
+ static start(request, details, agentDetails, userDetails, spanDetails) {
23
+ return new InferenceScope(request, details, agentDetails, userDetails, spanDetails);
24
+ }
25
+ constructor(request, details, agentDetails, userDetails, spanDetails) {
26
+ if (!agentDetails.tenantId) {
27
+ throw new Error("InferenceScope: tenantId is required on agentDetails");
28
+ }
29
+ // spanKind for InferenceScope is always CLIENT
30
+ const resolvedSpanDetails = { ...spanDetails, spanKind: api_1.SpanKind.CLIENT };
31
+ super(details.operationName.toString(), `${details.operationName} ${details.model}`, agentDetails, resolvedSpanDetails, userDetails);
32
+ // Core inference information
33
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_REQUEST_MODEL_KEY, details.model);
34
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_PROVIDER_NAME_KEY, details.providerName);
35
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_USAGE_INPUT_TOKENS_KEY, details.inputTokens);
36
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_USAGE_OUTPUT_TOKENS_KEY, details.outputTokens);
37
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_RESPONSE_FINISH_REASONS_KEY, details.finishReasons);
38
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_THOUGHT_PROCESS_KEY, details.thoughtProcess);
39
+ // Conversation and channel
40
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_CONVERSATION_ID_KEY, request.conversationId);
41
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.CHANNEL_NAME_KEY, request.channel?.name);
42
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.CHANNEL_LINK_KEY, request.channel?.description);
43
+ // Endpoint
44
+ if (details.endpoint) {
45
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.SERVER_ADDRESS_KEY, details.endpoint.host);
46
+ if (details.endpoint.port && details.endpoint.port !== 443) {
47
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.SERVER_PORT_KEY, details.endpoint.port);
48
+ }
49
+ }
50
+ }
51
+ /** Records the number of input tokens. */
52
+ recordInputTokens(inputTokens) {
53
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_USAGE_INPUT_TOKENS_KEY, inputTokens);
54
+ }
55
+ /** Records the number of output tokens. */
56
+ recordOutputTokens(outputTokens) {
57
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_USAGE_OUTPUT_TOKENS_KEY, outputTokens);
58
+ }
59
+ /** Records the finish reasons. */
60
+ recordFinishReasons(finishReasons) {
61
+ if (finishReasons && finishReasons.length > 0) {
62
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_RESPONSE_FINISH_REASONS_KEY, finishReasons);
63
+ }
64
+ }
65
+ /** Records the input messages for telemetry tracking. */
66
+ recordInputMessages(messages) {
67
+ super.recordInputMessages(messages);
68
+ }
69
+ /** Records the output messages for telemetry tracking. */
70
+ recordOutputMessages(messages) {
71
+ super.recordOutputMessages(messages);
72
+ }
73
+ }
74
+ exports.InferenceScope = InferenceScope;
75
+ //# sourceMappingURL=InferenceScope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InferenceScope.js","sourceRoot":"","sources":["../../../../src/a365/scopes/InferenceScope.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,4CAA8C;AAC9C,mEAA6D;AAC7D,kDAAyD;AAWzD;;GAEG;AACH,MAAa,cAAe,SAAQ,0CAAkB;IACpD;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAK,CACjB,OAAgB,EAChB,OAAyB,EACzB,YAA0B,EAC1B,WAAyB,EACzB,WAAyB;QAEzB,OAAO,IAAI,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;IACtF,CAAC;IAED,YACE,OAAgB,EAChB,OAAyB,EACzB,YAA0B,EAC1B,WAAyB,EACzB,WAAyB;QAEzB,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;QAED,+CAA+C;QAC/C,MAAM,mBAAmB,GAAgB,EAAE,GAAG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CAAC;YACnF,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,GAAG,EAAE,CAAC;gBAC3D,IAAI,CAAC,WAAW,CAAC,qCAAsB,CAAC,eAAe,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAClF,CAAC;QACH,CAAC;IACH,CAAC;IAED,0CAA0C;IACnC,iBAAiB,CAAC,WAAmB;QAC1C,IAAI,CAAC,WAAW,CAAC,qCAAsB,CAAC,6BAA6B,EAAE,WAAW,CAAC,CAAC;IACtF,CAAC;IAED,2CAA2C;IACpC,kBAAkB,CAAC,YAAoB;QAC5C,IAAI,CAAC,WAAW,CAAC,qCAAsB,CAAC,8BAA8B,EAAE,YAAY,CAAC,CAAC;IACxF,CAAC;IAED,kCAAkC;IAC3B,mBAAmB,CAAC,aAAuB;QAChD,IAAI,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,WAAW,CAAC,qCAAsB,CAAC,kCAAkC,EAAE,aAAa,CAAC,CAAC;QAC7F,CAAC;IACH,CAAC;IAED,yDAAyD;IACzC,mBAAmB,CAAC,QAA4B;QAC9D,KAAK,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;IAED,0DAA0D;IAC1C,oBAAoB,CAAC,QAA6B;QAChE,KAAK,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;CACF;AAhGD,wCAgGC"}
@@ -0,0 +1,25 @@
1
+ import { OpenTelemetryScope } from "./OpenTelemetryScope.js";
2
+ import type { InvokeAgentScopeDetails, CallerDetails, Request, SpanDetails, AgentDetails, InputMessagesParam, OutputMessagesParam } from "../contracts.js";
3
+ /**
4
+ * Provides OpenTelemetry tracing scope for AI agent invocation operations.
5
+ */
6
+ export declare class InvokeAgentScope extends OpenTelemetryScope {
7
+ /**
8
+ * Creates and starts a new scope for agent invocation tracing.
9
+ *
10
+ * @param request Request payload (channel, conversationId, content, sessionId).
11
+ * @param invokeScopeDetails Scope-level details (endpoint).
12
+ * @param agentDetails The agent identity. `tenantId` is required.
13
+ * @param callerDetails Optional caller information (human, agent, or both for A2A).
14
+ * @param spanDetails Optional span configuration.
15
+ */
16
+ static start(request: Request, invokeScopeDetails: InvokeAgentScopeDetails, agentDetails: AgentDetails, callerDetails?: CallerDetails, spanDetails?: SpanDetails): InvokeAgentScope;
17
+ private constructor();
18
+ /** Records response information for telemetry tracking. */
19
+ recordResponse(response: string): void;
20
+ /** Records the input messages for telemetry tracking. */
21
+ recordInputMessages(messages: InputMessagesParam): void;
22
+ /** Records the output messages for telemetry tracking. */
23
+ recordOutputMessages(messages: OutputMessagesParam): void;
24
+ }
25
+ //# sourceMappingURL=InvokeAgentScope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InvokeAgentScope.d.ts","sourceRoot":"","sources":["../../../../src/a365/scopes/InvokeAgentScope.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,KAAK,EACV,uBAAuB,EACvB,aAAa,EACb,OAAO,EACP,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,kBAAkB;IACtD;;;;;;;;OAQG;WACW,KAAK,CACjB,OAAO,EAAE,OAAO,EAChB,kBAAkB,EAAE,uBAAuB,EAC3C,YAAY,EAAE,YAAY,EAC1B,aAAa,CAAC,EAAE,aAAa,EAC7B,WAAW,CAAC,EAAE,WAAW,GACxB,gBAAgB;IAUnB,OAAO;IAkFP,2DAA2D;IACpD,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAI7C,yDAAyD;IACzC,mBAAmB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAIvE,0DAA0D;IAC1C,oBAAoB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,IAAI;CAG1E"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.InvokeAgentScope = void 0;
6
+ const api_1 = require("@opentelemetry/api");
7
+ const OpenTelemetryScope_js_1 = require("./OpenTelemetryScope.js");
8
+ const constants_js_1 = require("../constants.js");
9
+ /**
10
+ * Provides OpenTelemetry tracing scope for AI agent invocation operations.
11
+ */
12
+ class InvokeAgentScope extends OpenTelemetryScope_js_1.OpenTelemetryScope {
13
+ /**
14
+ * Creates and starts a new scope for agent invocation tracing.
15
+ *
16
+ * @param request Request payload (channel, conversationId, content, sessionId).
17
+ * @param invokeScopeDetails Scope-level details (endpoint).
18
+ * @param agentDetails The agent identity. `tenantId` is required.
19
+ * @param callerDetails Optional caller information (human, agent, or both for A2A).
20
+ * @param spanDetails Optional span configuration.
21
+ */
22
+ static start(request, invokeScopeDetails, agentDetails, callerDetails, spanDetails) {
23
+ return new InvokeAgentScope(request, invokeScopeDetails, agentDetails, callerDetails, spanDetails);
24
+ }
25
+ constructor(request, invokeScopeDetails, agentDetails, callerDetails, spanDetails) {
26
+ if (!agentDetails.tenantId) {
27
+ throw new Error("InvokeAgentScope: tenantId is required on agentDetails");
28
+ }
29
+ const resolvedSpanDetails = {
30
+ ...spanDetails,
31
+ spanKind: spanDetails?.spanKind ?? api_1.SpanKind.CLIENT,
32
+ };
33
+ super(constants_js_1.OpenTelemetryConstants.INVOKE_AGENT_OPERATION_NAME, agentDetails.agentName
34
+ ? `${constants_js_1.OpenTelemetryConstants.INVOKE_AGENT_OPERATION_NAME} ${agentDetails.agentName}`
35
+ : constants_js_1.OpenTelemetryConstants.INVOKE_AGENT_OPERATION_NAME, agentDetails, resolvedSpanDetails, callerDetails?.userDetails);
36
+ // Provider name
37
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_PROVIDER_NAME_KEY, agentDetails.providerName);
38
+ // Session ID
39
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.SESSION_ID_KEY, request.sessionId);
40
+ // Endpoint
41
+ if (invokeScopeDetails.endpoint) {
42
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.SERVER_ADDRESS_KEY, invokeScopeDetails.endpoint.host);
43
+ if (invokeScopeDetails.endpoint.port && invokeScopeDetails.endpoint.port !== 443) {
44
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.SERVER_PORT_KEY, invokeScopeDetails.endpoint.port);
45
+ }
46
+ }
47
+ // Channel
48
+ if (request.channel) {
49
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.CHANNEL_NAME_KEY, request.channel.name);
50
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.CHANNEL_LINK_KEY, request.channel.description);
51
+ }
52
+ // Conversation ID
53
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_CONVERSATION_ID_KEY, request.conversationId);
54
+ // Request content as input messages
55
+ if (request.content != null) {
56
+ this.recordInputMessages(request.content);
57
+ }
58
+ // Caller agent details for A2A scenarios
59
+ const callerAgent = callerDetails?.callerAgentDetails;
60
+ if (callerAgent) {
61
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_CALLER_AGENT_NAME_KEY, callerAgent.agentName);
62
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_CALLER_AGENT_ID_KEY, callerAgent.agentId);
63
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_CALLER_AGENT_APPLICATION_ID_KEY, callerAgent.agentBlueprintId);
64
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_CALLER_AGENT_USER_ID_KEY, callerAgent.agentAUID);
65
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_CALLER_AGENT_EMAIL_KEY, callerAgent.agentEmail);
66
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_CALLER_AGENT_PLATFORM_ID_KEY, callerAgent.platformId);
67
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_CALLER_AGENT_VERSION_KEY, callerAgent.agentVersion);
68
+ }
69
+ }
70
+ /** Records response information for telemetry tracking. */
71
+ recordResponse(response) {
72
+ this.recordOutputMessages(response);
73
+ }
74
+ /** Records the input messages for telemetry tracking. */
75
+ recordInputMessages(messages) {
76
+ super.recordInputMessages(messages);
77
+ }
78
+ /** Records the output messages for telemetry tracking. */
79
+ recordOutputMessages(messages) {
80
+ super.recordOutputMessages(messages);
81
+ }
82
+ }
83
+ exports.InvokeAgentScope = InvokeAgentScope;
84
+ //# sourceMappingURL=InvokeAgentScope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InvokeAgentScope.js","sourceRoot":"","sources":["../../../../src/a365/scopes/InvokeAgentScope.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,4CAA8C;AAC9C,mEAA6D;AAC7D,kDAAyD;AAWzD;;GAEG;AACH,MAAa,gBAAiB,SAAQ,0CAAkB;IACtD;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAK,CACjB,OAAgB,EAChB,kBAA2C,EAC3C,YAA0B,EAC1B,aAA6B,EAC7B,WAAyB;QAEzB,OAAO,IAAI,gBAAgB,CACzB,OAAO,EACP,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,WAAW,CACZ,CAAC;IACJ,CAAC;IAED,YACE,OAAgB,EAChB,kBAA2C,EAC3C,YAA0B,EAC1B,aAA6B,EAC7B,WAAyB;QAEzB,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC5E,CAAC;QAED,MAAM,mBAAmB,GAAgB;YACvC,GAAG,WAAW;YACd,QAAQ,EAAE,WAAW,EAAE,QAAQ,IAAI,cAAQ,CAAC,MAAM;S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@
1
+ /**
2
+ * Base class for OpenTelemetry tracing scopes.
3
+ *
4
+ * Adapted from microsoft/Agent365-nodejs agents-a365-observability/src/tracing/scopes/OpenTelemetryScope.ts
5
+ */
6
+ import type { Span, SpanContext, AttributeValue, TimeInput } from "@opentelemetry/api";
7
+ import type { AgentDetails, UserDetails, SpanDetails, InputMessagesParam, OutputMessagesParam } from "../contracts.js";
8
+ /**
9
+ * Base class for OpenTelemetry tracing scopes.
10
+ *
11
+ * Subclasses: `InvokeAgentScope`, `ExecuteToolScope`, `InferenceScope`, `OutputScope`.
12
+ */
13
+ export declare abstract class OpenTelemetryScope {
14
+ private static readonly tracer;
15
+ protected readonly span: Span;
16
+ private readonly wallClockStartMs;
17
+ private customStartTime?;
18
+ private customEndTime?;
19
+ private errorType?;
20
+ private hasEnded;
21
+ private readonly logger;
22
+ /**
23
+ * @param operationName The name of the operation being traced.
24
+ * @param spanName The display name of the span.
25
+ * @param agentDetails Optional agent details. Tenant ID is read from `agentDetails.tenantId`.
26
+ * @param spanDetails Optional span configuration including parent context, start/end times, span kind, and span links.
27
+ * @param userDetails Optional human caller identity details.
28
+ */
29
+ protected constructor(operationName: string, spanName: string, agentDetails?: AgentDetails, spanDetails?: SpanDetails, userDetails?: UserDetails);
30
+ /** Makes this span active for the duration of the async callback execution. */
31
+ withActiveSpanAsync<T>(callback: () => Promise<T>): Promise<T>;
32
+ /** Gets the span context for this scope. */
33
+ getSpanContext(): SpanContext;
34
+ /** Records an error that occurred during the operation. */
35
+ recordError(error: Error): void;
36
+ /** Records multiple attribute key/value pairs. */
37
+ recordAttributes(attributes: Iterable<[string, AttributeValue]> | Record<string, AttributeValue> | null | undefined): void;
38
+ /** Records the input messages for telemetry tracking. */
39
+ protected recordInputMessages(messages: InputMessagesParam): void;
40
+ /** Records the output messages for telemetry tracking. */
41
+ protected recordOutputMessages(messages: OutputMessagesParam): void;
42
+ /** Sets a tag on the span if the value is not null or undefined. */
43
+ protected setTagMaybe<T extends string | number | boolean | string[] | number[]>(name: string, value: T | null | undefined): void;
44
+ /**
45
+ * Sets a custom end time for the scope.
46
+ * When set, `dispose()` will pass this value to `span.end()` instead of using wall-clock time.
47
+ */
48
+ setEndTime(endTime: TimeInput): void;
49
+ /** Records a cancellation event on the span. */
50
+ recordCancellation(reason?: string): void;
51
+ /** Converts a TimeInput value to milliseconds since epoch. */
52
+ private static timeInputToMs;
53
+ private end;
54
+ /** Disposes the scope and finalizes telemetry data collection. */
55
+ [Symbol.dispose](): void;
56
+ /** Legacy dispose method for compatibility. */
57
+ dispose(): void;
58
+ }
59
+ //# sourceMappingURL=OpenTelemetryScope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenTelemetryScope.d.ts","sourceRoot":"","sources":["../../../../src/a365/scopes/OpenTelemetryScope.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGvF,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AASzB;;;;GAIG;AACH,8BAAsB,kBAAkB;IACtC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAuD;IAErF,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,eAAe,CAAC,CAAY;IACpC,OAAO,CAAC,aAAa,CAAC,CAAY;IAClC,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwB;IAE/C;;;;;;OAMG;IACH,SAAS,aACP,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,YAAY,CAAC,EAAE,YAAY,EAC3B,WAAW,CAA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object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.OpenTelemetryScope = void 0;
6
+ const api_1 = require("@opentelemetry/api");
7
+ const constants_js_1 = require("../constants.js");
8
+ const context_js_1 = require("../context.js");
9
+ const message_utils_js_1 = require("../message-utils.js");
10
+ const index_js_1 = require("../../shared/logging/index.js");
11
+ /**
12
+ * Base class for OpenTelemetry tracing scopes.
13
+ *
14
+ * Subclasses: `InvokeAgentScope`, `ExecuteToolScope`, `InferenceScope`, `OutputScope`.
15
+ */
16
+ class OpenTelemetryScope {
17
+ static tracer = api_1.trace.getTracer(constants_js_1.OpenTelemetryConstants.SOURCE_NAME);
18
+ span;
19
+ wallClockStartMs;
20
+ customStartTime;
21
+ customEndTime;
22
+ errorType;
23
+ hasEnded = false;
24
+ logger = index_js_1.Logger.getInstance();
25
+ /**
26
+ * @param operationName The name of the operation being traced.
27
+ * @param spanName The display name of the span.
28
+ * @param agentDetails Optional agent details. Tenant ID is read from `agentDetails.tenantId`.
29
+ * @param spanDetails Optional span configuration including parent context, start/end times, span kind, and span links.
30
+ * @param userDetails Optional human caller identity details.
31
+ */
32
+ constructor(operationName, spanName, agentDetails, spanDetails, userDetails) {
33
+ const parentContext = spanDetails?.parentContext;
34
+ const startTime = spanDetails?.startTime;
35
+ const endTime = spanDetails?.endTime;
36
+ const spanLinks = spanDetails?.spanLinks;
37
+ const kind = spanDetails?.spanKind ?? api_1.SpanKind.CLIENT;
38
+ let currentContext = api_1.context.active();
39
+ if (parentContext) {
40
+ if ((0, context_js_1.isParentSpanRef)(parentContext)) {
41
+ currentContext = (0, context_js_1.createContextWithParentSpanRef)(currentContext, parentContext);
42
+ }
43
+ else {
44
+ currentContext = parentContext;
45
+ }
46
+ }
47
+ this.span = OpenTelemetryScope.tracer.startSpan(spanName, {
48
+ kind,
49
+ startTime,
50
+ links: spanLinks,
51
+ attributes: {
52
+ [constants_js_1.OpenTelemetryConstants.GEN_AI_OPERATION_NAME_KEY]: operationName,
53
+ },
54
+ }, currentContext);
55
+ this.wallClockStartMs = Date.now();
56
+ if (startTime !== undefined) {
57
+ this.customStartTime = startTime;
58
+ }
59
+ this.customEndTime = endTime;
60
+ // Set agent details
61
+ if (agentDetails) {
62
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_ID_KEY, agentDetails.agentId);
63
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_NAME_KEY, agentDetails.agentName);
64
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_DESCRIPTION_KEY, agentDetails.agentDescription);
65
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_PLATFORM_ID_KEY, agentDetails.platformId);
66
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_ICON_URI_KEY, agentDetails.iconUri);
67
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_AUID_KEY, agentDetails.agentAUID);
68
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_EMAIL_KEY, agentDetails.agentEmail);
69
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_BLUEPRINT_ID_KEY, agentDetails.agentBlueprintId);
70
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_AGENT_VERSION_KEY, agentDetails.agentVersion);
71
+ }
72
+ // Set tenant ID
73
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.TENANT_ID_KEY, agentDetails?.tenantId);
74
+ // Set caller details
75
+ if (userDetails) {
76
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.USER_ID_KEY, userDetails.userId);
77
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.USER_EMAIL_KEY, userDetails.userEmail);
78
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.USER_NAME_KEY, userDetails.userName);
79
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_CALLER_CLIENT_IP_KEY, userDetails.callerClientIp);
80
+ }
81
+ }
82
+ /** Makes this span active for the duration of the async callback execution. */
83
+ withActiveSpanAsync(callback) {
84
+ const newContext = api_1.trace.setSpan(api_1.context.active(), this.span);
85
+ return api_1.context.with(newContext, callback);
86
+ }
87
+ /** Gets the span context for this scope. */
88
+ getSpanContext() {
89
+ return this.span.spanContext();
90
+ }
91
+ /** Records an error that occurred during the operation. */
92
+ recordError(error) {
93
+ if ("status" in error && typeof error.status === "number") {
94
+ this.errorType = String(error.status);
95
+ }
96
+ else {
97
+ this.errorType = error.constructor.name;
98
+ }
99
+ this.span.setStatus({
100
+ code: api_1.SpanStatusCode.ERROR,
101
+ message: error.message,
102
+ });
103
+ this.span.recordException(error);
104
+ }
105
+ /** Records multiple attribute key/value pairs. */
106
+ recordAttributes(attributes) {
107
+ if (!attributes)
108
+ return;
109
+ if (Symbol.iterator in Object(attributes) && typeof attributes !== "string") {
110
+ for (const [key, value] of attributes) {
111
+ if (key && typeof key === "string" && key.trim()) {
112
+ this.span.setAttribute(key, value);
113
+ }
114
+ }
115
+ }
116
+ else if (typeof attributes === "object") {
117
+ for (const key of Object.keys(attributes)) {
118
+ if (key && key.trim()) {
119
+ this.span.setAttribute(key, attributes[key]);
120
+ }
121
+ }
122
+ }
123
+ }
124
+ /** Records the input messages for telemetry tracking. */
125
+ recordInputMessages(messages) {
126
+ const wrapper = (0, message_utils_js_1.normalizeInputMessages)(messages);
127
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_INPUT_MESSAGES_KEY, (0, message_utils_js_1.serializeMessages)(wrapper));
128
+ }
129
+ /** Records the output messages for telemetry tracking. */
130
+ recordOutputMessages(messages) {
131
+ const wrapper = (0, message_utils_js_1.normalizeOutputMessages)(messages);
132
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_OUTPUT_MESSAGES_KEY, (0, message_utils_js_1.serializeMessages)(wrapper));
133
+ }
134
+ /** Sets a tag on the span if the value is not null or undefined. */
135
+ setTagMaybe(name, value) {
136
+ if (value != null) {
137
+ this.span.setAttributes({
138
+ [name]: value,
139
+ });
140
+ }
141
+ }
142
+ /**
143
+ * Sets a custom end time for the scope.
144
+ * When set, `dispose()` will pass this value to `span.end()` instead of using wall-clock time.
145
+ */
146
+ setEndTime(endTime) {
147
+ this.customEndTime = endTime;
148
+ }
149
+ /** Records a cancellation event on the span. */
150
+ recordCancellation(reason) {
151
+ const message = reason ?? "Task was cancelled";
152
+ this.span.setStatus({ code: api_1.SpanStatusCode.ERROR, message });
153
+ this.errorType = constants_js_1.OpenTelemetryConstants.ERROR_TYPE_CANCELLED;
154
+ }
155
+ /** Converts a TimeInput value to milliseconds since epoch. */
156
+ static timeInputToMs(t) {
157
+ if (typeof t === "number")
158
+ return t;
159
+ if (t instanceof Date)
160
+ return t.getTime();
161
+ if (Array.isArray(t) && t.length === 2)
162
+ return t[0] * 1000 + t[1] / 1_000_000;
163
+ return Date.now();
164
+ }
165
+ end() {
166
+ if (this.hasEnded)
167
+ return;
168
+ const startMs = this.customStartTime !== undefined
169
+ ? OpenTelemetryScope.timeInputToMs(this.customStartTime)
170
+ : this.wallClockStartMs;
171
+ const endMs = this.customEndTime !== undefined
172
+ ? OpenTelemetryScope.timeInputToMs(this.customEndTime)
173
+ : Date.now();
174
+ const durationMs = Math.max(0, endMs - startMs);
175
+ if (this.errorType) {
176
+ this.span.setAttributes({ [constants_js_1.OpenTelemetryConstants.ERROR_TYPE_KEY]: this.errorType });
177
+ }
178
+ this.hasEnded = true;
179
+ this.logger.info(`[A365] Ending span[${this.span.spanContext().spanId}], duration: ${(durationMs / 1000).toFixed(3)}s`);
180
+ }
181
+ /** Disposes the scope and finalizes telemetry data collection. */
182
+ [Symbol.dispose]() {
183
+ if (!this.hasEnded) {
184
+ this.end();
185
+ if (this.customEndTime !== undefined) {
186
+ this.span.end(this.customEndTime);
187
+ }
188
+ else {
189
+ this.span.end();
190
+ }
191
+ }
192
+ }
193
+ /** Legacy dispose method for compatibility. */
194
+ dispose() {
195
+ this[Symbol.dispose]();
196
+ }
197
+ }
198
+ exports.OpenTelemetryScope = OpenTelemetryScope;
199
+ //# sourceMappingURL=OpenTelemetryScope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenTelemetryScope.js","sourceRoot":"","sources":["../../../../src/a365/scopes/OpenTelemetryScope.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AASlC,4CAA8E;AAC9E,kDAAyD;AAQzD,8CAAgF;AAChF,0DAI6B;AAC7B,4DAAuD;AAEvD;;;;GAIG;AACH,MAAsB,kBAAkB;IAC9B,MAAM,CAAU,MAAM,GAAG,WAAK,CAAC,SAAS,CAAC,qCAAsB,CAAC,WAAW,CAAC,CAAC;IAElE,IAAI,CAAO;IACb,gBAAgB,CAAS;IAClC,eAAe,CAAa;IAC5B,aAAa,CAAa;IAC1B,SAAS,CAAU;IACnB,QAAQ,GAAG,KAAK,CAAC;IACR,MAAM,GAAG,iBAAM,CAAC,WAAW,EAAE,CAAC;IAE/C;;;;;;OAMG;IACH,YACE,aAAqB,EACrB,QAAgB,EAChB,YAA2B,EAC3B,WAAyB,EACzB,WAAyB;QAEzB,MAAM,aAAa,GAAG,WAAW,EAAE,aAAa,CAAC;QACjD,MAAM,SAAS,GAAG,WAAW,EAAE,SAAS,CAAC;QACzC,MAAM,OAAO,GAAG,WAAW,EAAE,OAAO,CAAC;QACrC,MAAM,SAAS,GAAG,WAAW,EAAE,SAAS,CAAC;QACzC,MAAM,IAAI,GAAG,WAAW,EAAE,QAAQ,IAAI,cAAQ,CAAC,MAAM,CAAC;QAEtD,IAAI,cAAc,GAAG,aAAO,CAAC,MAAM,EAAE,CAAC;QACtC,IAAI,aAAa,EAAE,CAAC;YAClB,IAAI,IAAA,4BAAe,EAAC,aAAa,CAAC,EAAE,CAAC;gBACnC,cAAc,GAAG,IAAA,2CAA8B,EAAC,cAAc,EAAE,aAAa,CAAC,CAAC;YACjF,CAAC;iBA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AG,EAAE,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC;IAED,+CAA+C;IACxC,OAAO;QACZ,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IACzB,CAAC;;AAxOH,gDAyOC"}
@@ -0,0 +1,26 @@
1
+ import { OpenTelemetryScope } from "./OpenTelemetryScope.js";
2
+ import type { AgentDetails, UserDetails, OutputResponse, Request, SpanDetails, ResponseMessagesParam } from "../contracts.js";
3
+ /**
4
+ * Provides OpenTelemetry tracing scope for output message tracing.
5
+ */
6
+ export declare class OutputScope extends OpenTelemetryScope {
7
+ /**
8
+ * Creates and starts a new scope for output message tracing.
9
+ *
10
+ * @param request Request payload (channel, conversationId, content, sessionId).
11
+ * @param response The response containing initial output messages.
12
+ * @param agentDetails The agent producing the output. `tenantId` is required.
13
+ * @param userDetails Optional human caller identity details.
14
+ * @param spanDetails Optional span configuration.
15
+ */
16
+ static start(request: Request, response: OutputResponse, agentDetails: AgentDetails, userDetails?: UserDetails, spanDetails?: SpanDetails): OutputScope;
17
+ private constructor();
18
+ /**
19
+ * Records the output messages for telemetry tracking.
20
+ * Overwrites any previously recorded output messages.
21
+ */
22
+ recordOutputMessages(messages: ResponseMessagesParam): void;
23
+ private _setOutput;
24
+ private _isRawDict;
25
+ }
26
+ //# sourceMappingURL=OutputScope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OutputScope.d.ts","sourceRoot":"","sources":["../../../../src/a365/scopes/OutputScope.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,cAAc,EACd,OAAO,EACP,WAAW,EACX,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAGzB;;GAEG;AACH,qBAAa,WAAY,SAAQ,kBAAkB;IACjD;;;;;;;;OAQG;WACW,KAAK,CACjB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,cAAc,EACxB,YAAY,EAAE,YAAY,EAC1B,WAAW,CAAC,EAAE,WAAW,EACzB,WAAW,CAAC,EAAE,WAAW,GACxB,WAAW;IAId,OAAO;IAiCP;;;OAGG;IACI,oBAAoB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI;IAIlE,OAAO,CAAC,UAAU;IAqBlB,OAAO,CAAC,UAAU;CAQnB"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.OutputScope = void 0;
6
+ const api_1 = require("@opentelemetry/api");
7
+ const OpenTelemetryScope_js_1 = require("./OpenTelemetryScope.js");
8
+ const constants_js_1 = require("../constants.js");
9
+ const message_utils_js_1 = require("../message-utils.js");
10
+ const contracts_js_1 = require("../contracts.js");
11
+ /**
12
+ * Provides OpenTelemetry tracing scope for output message tracing.
13
+ */
14
+ class OutputScope extends OpenTelemetryScope_js_1.OpenTelemetryScope {
15
+ /**
16
+ * Creates and starts a new scope for output message tracing.
17
+ *
18
+ * @param request Request payload (channel, conversationId, content, sessionId).
19
+ * @param response The response containing initial output messages.
20
+ * @param agentDetails The agent producing the output. `tenantId` is required.
21
+ * @param userDetails Optional human caller identity details.
22
+ * @param spanDetails Optional span configuration.
23
+ */
24
+ static start(request, response, agentDetails, userDetails, spanDetails) {
25
+ return new OutputScope(request, response, agentDetails, userDetails, spanDetails);
26
+ }
27
+ constructor(request, response, agentDetails, userDetails, spanDetails) {
28
+ if (!agentDetails.tenantId) {
29
+ throw new Error("OutputScope: tenantId is required on agentDetails");
30
+ }
31
+ // spanKind for OutputScope is always CLIENT
32
+ const resolvedSpanDetails = { ...spanDetails, spanKind: api_1.SpanKind.CLIENT };
33
+ super(constants_js_1.OpenTelemetryConstants.OUTPUT_MESSAGES_OPERATION_NAME, agentDetails.agentName
34
+ ? `${constants_js_1.OpenTelemetryConstants.OUTPUT_MESSAGES_OPERATION_NAME} ${agentDetails.agentName}`
35
+ : `${constants_js_1.OpenTelemetryConstants.OUTPUT_MESSAGES_OPERATION_NAME} ${agentDetails.agentId}`, agentDetails, resolvedSpanDetails, userDetails);
36
+ // Set initial output messages
37
+ this._setOutput(response.messages);
38
+ // Conversation and channel
39
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_CONVERSATION_ID_KEY, request.conversationId);
40
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.CHANNEL_NAME_KEY, request.channel?.name);
41
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.CHANNEL_LINK_KEY, request.channel?.description);
42
+ }
43
+ /**
44
+ * Records the output messages for telemetry tracking.
45
+ * Overwrites any previously recorded output messages.
46
+ */
47
+ recordOutputMessages(messages) {
48
+ this._setOutput(messages);
49
+ }
50
+ _setOutput(messages) {
51
+ // Dict (Record<string, unknown>) — treat as tool call result, serialize directly
52
+ if (this._isRawDict(messages)) {
53
+ try {
54
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_OUTPUT_MESSAGES_KEY, JSON.stringify(messages));
55
+ }
56
+ catch {
57
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_OUTPUT_MESSAGES_KEY, JSON.stringify({ error: "serialization failed" }));
58
+ }
59
+ return;
60
+ }
61
+ const normalized = (0, message_utils_js_1.normalizeOutputMessages)(messages);
62
+ const wrapper = { version: contracts_js_1.A365_MESSAGE_SCHEMA_VERSION, messages: normalized.messages };
63
+ this.setTagMaybe(constants_js_1.OpenTelemetryConstants.GEN_AI_OUTPUT_MESSAGES_KEY, (0, message_utils_js_1.serializeMessages)(wrapper));
64
+ }
65
+ _isRawDict(messages) {
66
+ return (typeof messages === "object" &&
67
+ messages !== null &&
68
+ !Array.isArray(messages) &&
69
+ !("version" in messages && "messages" in messages));
70
+ }
71
+ }
72
+ exports.OutputScope = OutputScope;
73
+ //# sourceMappingURL=OutputScope.js.map
@@ -0,0 +1 @@
1
+ {"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A1FD,kCA0FC"}
@@ -0,0 +1,6 @@
1
+ export { OpenTelemetryScope } from "./OpenTelemetryScope.js";
2
+ export { InvokeAgentScope } from "./InvokeAgentScope.js";
3
+ export { ExecuteToolScope } from "./ExecuteToolScope.js";
4
+ export { InferenceScope } from "./InferenceScope.js";
5
+ export { OutputScope } from "./OutputScope.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/a365/scopes/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.OutputScope = exports.InferenceScope = exports.ExecuteToolScope = exports.InvokeAgentScope = exports.OpenTelemetryScope = void 0;
6
+ var OpenTelemetryScope_js_1 = require("./OpenTelemetryScope.js");
7
+ Object.defineProperty(exports, "OpenTelemetryScope", { enumerable: true, get: function () { return OpenTelemetryScope_js_1.OpenTelemetryScope; } });
8
+ var InvokeAgentScope_js_1 = require("./InvokeAgentScope.js");
9
+ Object.defineProperty(exports, "InvokeAgentScope", { enumerable: true, get: function () { return InvokeAgentScope_js_1.InvokeAgentScope; } });
10
+ var ExecuteToolScope_js_1 = require("./ExecuteToolScope.js");
11
+ Object.defineProperty(exports, "ExecuteToolScope", { enumerable: true, get: function () { return ExecuteToolScope_js_1.ExecuteToolScope; } });
12
+ var InferenceScope_js_1 = require("./InferenceScope.js");
13
+ Object.defineProperty(exports, "InferenceScope", { enumerable: true, get: function () { return InferenceScope_js_1.InferenceScope; } });
14
+ var OutputScope_js_1 = require("./OutputScope.js");
15
+ Object.defineProperty(exports, "OutputScope", { enumerable: true, get: function () { return OutputScope_js_1.OutputScope; } });
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/a365/scopes/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,iEAA6D;AAApD,2HAAA,kBAAkB,OAAA;AAC3B,6DAAyD;AAAhD,uHAAA,gBAAgB,OAAA;AACzB,6DAAyD;AAAhD,uHAAA,gBAAgB,OAAA;AACzB,yDAAqD;AAA5C,mHAAA,cAAc,OAAA;AACvB,mDAA+C;AAAtC,6GAAA,WAAW,OAAA"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Read an environment variable, trimmed and lowercased.
3
+ * Returns undefined if not set or empty.
4
+ */
5
+ export declare function getEnv(name: string): string | undefined;
6
+ //# sourceMappingURL=utils.d.ts.map