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

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 (347) hide show
  1. package/README.md +69 -4
  2. package/dist/commonjs/a365/configuration/A365Configuration.d.ts +42 -0
  3. package/dist/commonjs/a365/configuration/A365Configuration.d.ts.map +1 -0
  4. package/dist/commonjs/a365/configuration/A365Configuration.js +162 -0
  5. package/dist/commonjs/a365/configuration/A365Configuration.js.map +1 -0
  6. package/dist/commonjs/a365/configuration/A365ConfigurationOptions.d.ts +53 -0
  7. package/dist/commonjs/a365/configuration/A365ConfigurationOptions.d.ts.map +1 -0
  8. package/dist/commonjs/a365/configuration/A365ConfigurationOptions.js +5 -0
  9. package/dist/commonjs/a365/configuration/A365ConfigurationOptions.js.map +1 -0
  10. package/dist/commonjs/a365/configuration/index.d.ts +3 -0
  11. package/dist/commonjs/a365/configuration/index.d.ts.map +1 -0
  12. package/dist/commonjs/a365/configuration/index.js +9 -0
  13. package/dist/commonjs/a365/configuration/index.js.map +1 -0
  14. package/dist/commonjs/a365/constants.d.ts +93 -0
  15. package/dist/commonjs/a365/constants.d.ts.map +1 -0
  16. package/dist/commonjs/a365/constants.js +120 -0
  17. package/dist/commonjs/a365/constants.js.map +1 -0
  18. package/dist/commonjs/a365/context/tokenContext.d.ts +25 -0
  19. package/dist/commonjs/a365/context/tokenContext.d.ts.map +1 -0
  20. package/dist/commonjs/a365/context/tokenContext.js +67 -0
  21. package/dist/commonjs/a365/context/tokenContext.js.map +1 -0
  22. package/dist/commonjs/a365/context.d.ts +31 -0
  23. package/dist/commonjs/a365/context.d.ts.map +1 -0
  24. package/dist/commonjs/a365/context.js +109 -0
  25. package/dist/commonjs/a365/context.js.map +1 -0
  26. package/dist/commonjs/a365/contracts.d.ts +250 -0
  27. package/dist/commonjs/a365/contracts.d.ts.map +1 -0
  28. package/dist/commonjs/a365/contracts.js +52 -0
  29. package/dist/commonjs/a365/contracts.js.map +1 -0
  30. package/dist/commonjs/a365/exporter/Agent365Exporter.d.ts +25 -0
  31. package/dist/commonjs/a365/exporter/Agent365Exporter.d.ts.map +1 -0
  32. package/dist/commonjs/a365/exporter/Agent365Exporter.js +219 -0
  33. package/dist/commonjs/a365/exporter/Agent365Exporter.js.map +1 -0
  34. package/dist/commonjs/a365/exporter/Agent365ExporterOptions.d.ts +43 -0
  35. package/dist/commonjs/a365/exporter/Agent365ExporterOptions.d.ts.map +1 -0
  36. package/dist/commonjs/a365/exporter/Agent365ExporterOptions.js +30 -0
  37. package/dist/commonjs/a365/exporter/Agent365ExporterOptions.js.map +1 -0
  38. package/dist/commonjs/a365/exporter/ExporterEventNames.d.ts +9 -0
  39. package/dist/commonjs/a365/exporter/ExporterEventNames.d.ts.map +1 -0
  40. package/dist/commonjs/a365/exporter/ExporterEventNames.js +15 -0
  41. package/dist/commonjs/a365/exporter/ExporterEventNames.js.map +1 -0
  42. package/dist/commonjs/a365/exporter/index.d.ts +6 -0
  43. package/dist/commonjs/a365/exporter/index.d.ts.map +1 -0
  44. package/dist/commonjs/a365/exporter/index.js +15 -0
  45. package/dist/commonjs/a365/exporter/index.js.map +1 -0
  46. package/dist/commonjs/a365/exporter/utils.d.ts +41 -0
  47. package/dist/commonjs/a365/exporter/utils.d.ts.map +1 -0
  48. package/dist/commonjs/a365/exporter/utils.js +410 -0
  49. package/dist/commonjs/a365/exporter/utils.js.map +1 -0
  50. package/dist/commonjs/a365/hosting/baggageBuilderUtils.d.ts +22 -0
  51. package/dist/commonjs/a365/hosting/baggageBuilderUtils.d.ts.map +1 -0
  52. package/dist/commonjs/a365/hosting/baggageBuilderUtils.js +47 -0
  53. package/dist/commonjs/a365/hosting/baggageBuilderUtils.js.map +1 -0
  54. package/dist/commonjs/a365/hosting/baggageMiddleware.d.ts +9 -0
  55. package/dist/commonjs/a365/hosting/baggageMiddleware.d.ts.map +1 -0
  56. package/dist/commonjs/a365/hosting/baggageMiddleware.js +38 -0
  57. package/dist/commonjs/a365/hosting/baggageMiddleware.js.map +1 -0
  58. package/dist/commonjs/a365/hosting/index.d.ts +9 -0
  59. package/dist/commonjs/a365/hosting/index.d.ts.map +1 -0
  60. package/dist/commonjs/a365/hosting/index.js +25 -0
  61. package/dist/commonjs/a365/hosting/index.js.map +1 -0
  62. package/dist/commonjs/a365/hosting/observabilityHostingManager.d.ts +30 -0
  63. package/dist/commonjs/a365/hosting/observabilityHostingManager.d.ts.map +1 -0
  64. package/dist/commonjs/a365/hosting/observabilityHostingManager.js +49 -0
  65. package/dist/commonjs/a365/hosting/observabilityHostingManager.js.map +1 -0
  66. package/dist/commonjs/a365/hosting/outputLoggingMiddleware.d.ts +24 -0
  67. package/dist/commonjs/a365/hosting/outputLoggingMiddleware.d.ts.map +1 -0
  68. package/dist/commonjs/a365/hosting/outputLoggingMiddleware.js +82 -0
  69. package/dist/commonjs/a365/hosting/outputLoggingMiddleware.js.map +1 -0
  70. package/dist/commonjs/a365/hosting/scopeUtils.d.ts +56 -0
  71. package/dist/commonjs/a365/hosting/scopeUtils.d.ts.map +1 -0
  72. package/dist/commonjs/a365/hosting/scopeUtils.js +161 -0
  73. package/dist/commonjs/a365/hosting/scopeUtils.js.map +1 -0
  74. package/dist/commonjs/a365/hosting/turnContextUtils.d.ts +32 -0
  75. package/dist/commonjs/a365/hosting/turnContextUtils.d.ts.map +1 -0
  76. package/dist/commonjs/a365/hosting/turnContextUtils.js +141 -0
  77. package/dist/commonjs/a365/hosting/turnContextUtils.js.map +1 -0
  78. package/dist/commonjs/a365/hosting/types.d.ts +52 -0
  79. package/dist/commonjs/a365/hosting/types.d.ts.map +1 -0
  80. package/dist/commonjs/a365/hosting/types.js +5 -0
  81. package/dist/commonjs/a365/hosting/types.js.map +1 -0
  82. package/dist/commonjs/a365/index.d.ts +18 -0
  83. package/dist/commonjs/a365/index.d.ts.map +1 -0
  84. package/dist/commonjs/a365/index.js +69 -0
  85. package/dist/commonjs/a365/index.js.map +1 -0
  86. package/dist/commonjs/a365/message-utils.d.ts +42 -0
  87. package/dist/commonjs/a365/message-utils.d.ts.map +1 -0
  88. package/dist/commonjs/a365/message-utils.js +116 -0
  89. package/dist/commonjs/a365/message-utils.js.map +1 -0
  90. package/dist/commonjs/a365/middleware/BaggageBuilder.d.ts +112 -0
  91. package/dist/commonjs/a365/middleware/BaggageBuilder.d.ts.map +1 -0
  92. package/dist/commonjs/a365/middleware/BaggageBuilder.js +248 -0
  93. package/dist/commonjs/a365/middleware/BaggageBuilder.js.map +1 -0
  94. package/dist/commonjs/a365/middleware/index.d.ts +2 -0
  95. package/dist/commonjs/a365/middleware/index.d.ts.map +1 -0
  96. package/dist/commonjs/a365/middleware/index.js +9 -0
  97. package/dist/commonjs/a365/middleware/index.js.map +1 -0
  98. package/dist/commonjs/a365/processors/A365SpanProcessor.d.ts +32 -0
  99. package/dist/commonjs/a365/processors/A365SpanProcessor.d.ts.map +1 -0
  100. package/dist/commonjs/a365/processors/A365SpanProcessor.js +104 -0
  101. package/dist/commonjs/a365/processors/A365SpanProcessor.js.map +1 -0
  102. package/dist/commonjs/a365/processors/PerRequestSpanProcessor.d.ts +44 -0
  103. package/dist/commonjs/a365/processors/PerRequestSpanProcessor.d.ts.map +1 -0
  104. package/dist/commonjs/a365/processors/PerRequestSpanProcessor.js +260 -0
  105. package/dist/commonjs/a365/processors/PerRequestSpanProcessor.js.map +1 -0
  106. package/dist/commonjs/a365/processors/index.d.ts +5 -0
  107. package/dist/commonjs/a365/processors/index.d.ts.map +1 -0
  108. package/dist/commonjs/a365/processors/index.js +13 -0
  109. package/dist/commonjs/a365/processors/index.js.map +1 -0
  110. package/dist/commonjs/a365/processors/util.d.ts +10 -0
  111. package/dist/commonjs/a365/processors/util.d.ts.map +1 -0
  112. package/dist/commonjs/a365/processors/util.js +56 -0
  113. package/dist/commonjs/a365/processors/util.js.map +1 -0
  114. package/dist/commonjs/a365/scopes/ExecuteToolScope.d.ts +24 -0
  115. package/dist/commonjs/a365/scopes/ExecuteToolScope.d.ts.map +1 -0
  116. package/dist/commonjs/a365/scopes/ExecuteToolScope.js +60 -0
  117. package/dist/commonjs/a365/scopes/ExecuteToolScope.js.map +1 -0
  118. package/dist/commonjs/a365/scopes/InferenceScope.d.ts +29 -0
  119. package/dist/commonjs/a365/scopes/InferenceScope.d.ts.map +1 -0
  120. package/dist/commonjs/a365/scopes/InferenceScope.js +75 -0
  121. package/dist/commonjs/a365/scopes/InferenceScope.js.map +1 -0
  122. package/dist/commonjs/a365/scopes/InvokeAgentScope.d.ts +25 -0
  123. package/dist/commonjs/a365/scopes/InvokeAgentScope.d.ts.map +1 -0
  124. package/dist/commonjs/a365/scopes/InvokeAgentScope.js +84 -0
  125. package/dist/commonjs/a365/scopes/InvokeAgentScope.js.map +1 -0
  126. package/dist/commonjs/a365/scopes/OpenTelemetryScope.d.ts +69 -0
  127. package/dist/commonjs/a365/scopes/OpenTelemetryScope.d.ts.map +1 -0
  128. package/dist/commonjs/a365/scopes/OpenTelemetryScope.js +211 -0
  129. package/dist/commonjs/a365/scopes/OpenTelemetryScope.js.map +1 -0
  130. package/dist/commonjs/a365/scopes/OutputScope.d.ts +26 -0
  131. package/dist/commonjs/a365/scopes/OutputScope.d.ts.map +1 -0
  132. package/dist/commonjs/a365/scopes/OutputScope.js +73 -0
  133. package/dist/commonjs/a365/scopes/OutputScope.js.map +1 -0
  134. package/dist/commonjs/a365/scopes/index.d.ts +6 -0
  135. package/dist/commonjs/a365/scopes/index.d.ts.map +1 -0
  136. package/dist/commonjs/a365/scopes/index.js +16 -0
  137. package/dist/commonjs/a365/scopes/index.js.map +1 -0
  138. package/dist/commonjs/a365/utils/utils.d.ts +6 -0
  139. package/dist/commonjs/a365/utils/utils.d.ts.map +1 -0
  140. package/dist/commonjs/a365/utils/utils.js +14 -0
  141. package/dist/commonjs/a365/utils/utils.js.map +1 -0
  142. package/dist/commonjs/azureMonitor/index.d.ts +14 -0
  143. package/dist/commonjs/azureMonitor/index.d.ts.map +1 -1
  144. package/dist/commonjs/azureMonitor/index.js +29 -0
  145. package/dist/commonjs/azureMonitor/index.js.map +1 -1
  146. package/dist/commonjs/azureMonitor/metrics/handler.js +2 -2
  147. package/dist/commonjs/azureMonitor/metrics/handler.js.map +1 -1
  148. package/dist/commonjs/azureMonitor/metrics/quickpulse/types.d.ts +1 -1
  149. package/dist/commonjs/azureMonitor/traces/handler.d.ts +0 -3
  150. package/dist/commonjs/azureMonitor/traces/handler.d.ts.map +1 -1
  151. package/dist/commonjs/azureMonitor/traces/handler.js +8 -19
  152. package/dist/commonjs/azureMonitor/traces/handler.js.map +1 -1
  153. package/dist/commonjs/distro/distro.d.ts +3 -1
  154. package/dist/commonjs/distro/distro.d.ts.map +1 -1
  155. package/dist/commonjs/distro/distro.js +88 -92
  156. package/dist/commonjs/distro/distro.js.map +1 -1
  157. package/dist/commonjs/distro/instrumentations.d.ts +31 -0
  158. package/dist/commonjs/distro/instrumentations.d.ts.map +1 -0
  159. package/dist/commonjs/distro/instrumentations.js +131 -0
  160. package/dist/commonjs/distro/instrumentations.js.map +1 -0
  161. package/dist/commonjs/distro/types.d.ts +2 -1
  162. package/dist/commonjs/distro/types.d.ts.map +1 -1
  163. package/dist/commonjs/index.d.ts +8 -12
  164. package/dist/commonjs/index.d.ts.map +1 -1
  165. package/dist/commonjs/index.js +48 -20
  166. package/dist/commonjs/index.js.map +1 -1
  167. package/dist/commonjs/package.json +1 -0
  168. package/dist/commonjs/shared/jsonConfig.d.ts +2 -1
  169. package/dist/commonjs/shared/jsonConfig.d.ts.map +1 -1
  170. package/dist/commonjs/shared/module.js +15 -11
  171. package/dist/commonjs/shared/module.js.map +1 -1
  172. package/dist/commonjs/types.d.ts +8 -32
  173. package/dist/commonjs/types.d.ts.map +1 -1
  174. package/dist/commonjs/types.js +1 -1
  175. package/dist/commonjs/types.js.map +1 -1
  176. package/dist/esm/a365/configuration/A365Configuration.d.ts +42 -0
  177. package/dist/esm/a365/configuration/A365Configuration.d.ts.map +1 -0
  178. package/dist/esm/a365/configuration/A365Configuration.js +158 -0
  179. package/dist/esm/a365/configuration/A365Configuration.js.map +1 -0
  180. package/dist/esm/a365/configuration/A365ConfigurationOptions.d.ts +53 -0
  181. package/dist/esm/a365/configuration/A365ConfigurationOptions.d.ts.map +1 -0
  182. package/dist/esm/a365/configuration/A365ConfigurationOptions.js +4 -0
  183. package/dist/esm/a365/configuration/A365ConfigurationOptions.js.map +1 -0
  184. package/dist/esm/a365/configuration/index.d.ts +3 -0
  185. package/dist/esm/a365/configuration/index.d.ts.map +1 -0
  186. package/dist/esm/a365/configuration/index.js +4 -0
  187. package/dist/esm/a365/configuration/index.js.map +1 -0
  188. package/dist/esm/a365/constants.d.ts +93 -0
  189. package/dist/esm/a365/constants.d.ts.map +1 -0
  190. package/dist/esm/a365/constants.js +116 -0
  191. package/dist/esm/a365/constants.js.map +1 -0
  192. package/dist/esm/a365/context/tokenContext.d.ts +25 -0
  193. package/dist/esm/a365/context/tokenContext.d.ts.map +1 -0
  194. package/dist/esm/a365/context/tokenContext.js +62 -0
  195. package/dist/esm/a365/context/tokenContext.js.map +1 -0
  196. package/dist/esm/a365/context.d.ts +31 -0
  197. package/dist/esm/a365/context.d.ts.map +1 -0
  198. package/dist/esm/a365/context.js +101 -0
  199. package/dist/esm/a365/context.js.map +1 -0
  200. package/dist/esm/a365/contracts.d.ts +250 -0
  201. package/dist/esm/a365/contracts.d.ts.map +1 -0
  202. package/dist/esm/a365/contracts.js +49 -0
  203. package/dist/esm/a365/contracts.js.map +1 -0
  204. package/dist/esm/a365/exporter/Agent365Exporter.d.ts +25 -0
  205. package/dist/esm/a365/exporter/Agent365Exporter.d.ts.map +1 -0
  206. package/dist/esm/a365/exporter/Agent365Exporter.js +215 -0
  207. package/dist/esm/a365/exporter/Agent365Exporter.js.map +1 -0
  208. package/dist/esm/a365/exporter/Agent365ExporterOptions.d.ts +43 -0
  209. package/dist/esm/a365/exporter/Agent365ExporterOptions.d.ts.map +1 -0
  210. package/dist/esm/a365/exporter/Agent365ExporterOptions.js +26 -0
  211. package/dist/esm/a365/exporter/Agent365ExporterOptions.js.map +1 -0
  212. package/dist/esm/a365/exporter/ExporterEventNames.d.ts +9 -0
  213. package/dist/esm/a365/exporter/ExporterEventNames.d.ts.map +1 -0
  214. package/dist/esm/a365/exporter/ExporterEventNames.js +12 -0
  215. package/dist/esm/a365/exporter/ExporterEventNames.js.map +1 -0
  216. package/dist/esm/a365/exporter/index.d.ts +6 -0
  217. package/dist/esm/a365/exporter/index.d.ts.map +1 -0
  218. package/dist/esm/a365/exporter/index.js +7 -0
  219. package/dist/esm/a365/exporter/index.js.map +1 -0
  220. package/dist/esm/a365/exporter/utils.d.ts +41 -0
  221. package/dist/esm/a365/exporter/utils.d.ts.map +1 -0
  222. package/dist/esm/a365/exporter/utils.js +398 -0
  223. package/dist/esm/a365/exporter/utils.js.map +1 -0
  224. package/dist/esm/a365/hosting/baggageBuilderUtils.d.ts +22 -0
  225. package/dist/esm/a365/hosting/baggageBuilderUtils.d.ts.map +1 -0
  226. package/dist/esm/a365/hosting/baggageBuilderUtils.js +43 -0
  227. package/dist/esm/a365/hosting/baggageBuilderUtils.js.map +1 -0
  228. package/dist/esm/a365/hosting/baggageMiddleware.d.ts +9 -0
  229. package/dist/esm/a365/hosting/baggageMiddleware.d.ts.map +1 -0
  230. package/dist/esm/a365/hosting/baggageMiddleware.js +34 -0
  231. package/dist/esm/a365/hosting/baggageMiddleware.js.map +1 -0
  232. package/dist/esm/a365/hosting/index.d.ts +9 -0
  233. package/dist/esm/a365/hosting/index.d.ts.map +1 -0
  234. package/dist/esm/a365/hosting/index.js +9 -0
  235. package/dist/esm/a365/hosting/index.js.map +1 -0
  236. package/dist/esm/a365/hosting/observabilityHostingManager.d.ts +30 -0
  237. package/dist/esm/a365/hosting/observabilityHostingManager.d.ts.map +1 -0
  238. package/dist/esm/a365/hosting/observabilityHostingManager.js +45 -0
  239. package/dist/esm/a365/hosting/observabilityHostingManager.js.map +1 -0
  240. package/dist/esm/a365/hosting/outputLoggingMiddleware.d.ts +24 -0
  241. package/dist/esm/a365/hosting/outputLoggingMiddleware.d.ts.map +1 -0
  242. package/dist/esm/a365/hosting/outputLoggingMiddleware.js +78 -0
  243. package/dist/esm/a365/hosting/outputLoggingMiddleware.js.map +1 -0
  244. package/dist/esm/a365/hosting/scopeUtils.d.ts +56 -0
  245. package/dist/esm/a365/hosting/scopeUtils.d.ts.map +1 -0
  246. package/dist/esm/a365/hosting/scopeUtils.js +157 -0
  247. package/dist/esm/a365/hosting/scopeUtils.js.map +1 -0
  248. package/dist/esm/a365/hosting/turnContextUtils.d.ts +32 -0
  249. package/dist/esm/a365/hosting/turnContextUtils.d.ts.map +1 -0
  250. package/dist/esm/a365/hosting/turnContextUtils.js +133 -0
  251. package/dist/esm/a365/hosting/turnContextUtils.js.map +1 -0
  252. package/dist/esm/a365/hosting/types.d.ts +52 -0
  253. package/dist/esm/a365/hosting/types.d.ts.map +1 -0
  254. package/dist/esm/a365/hosting/types.js +4 -0
  255. package/dist/esm/a365/hosting/types.js.map +1 -0
  256. package/dist/esm/a365/index.d.ts +18 -0
  257. package/dist/esm/a365/index.d.ts.map +1 -0
  258. package/dist/esm/a365/index.js +22 -0
  259. package/dist/esm/a365/index.js.map +1 -0
  260. package/dist/esm/a365/message-utils.d.ts +42 -0
  261. package/dist/esm/a365/message-utils.d.ts.map +1 -0
  262. package/dist/esm/a365/message-utils.js +107 -0
  263. package/dist/esm/a365/message-utils.js.map +1 -0
  264. package/dist/esm/a365/middleware/BaggageBuilder.d.ts +112 -0
  265. package/dist/esm/a365/middleware/BaggageBuilder.d.ts.map +1 -0
  266. package/dist/esm/a365/middleware/BaggageBuilder.js +243 -0
  267. package/dist/esm/a365/middleware/BaggageBuilder.js.map +1 -0
  268. package/dist/esm/a365/middleware/index.d.ts +2 -0
  269. package/dist/esm/a365/middleware/index.d.ts.map +1 -0
  270. package/dist/esm/a365/middleware/index.js +4 -0
  271. package/dist/esm/a365/middleware/index.js.map +1 -0
  272. package/dist/esm/a365/processors/A365SpanProcessor.d.ts +32 -0
  273. package/dist/esm/a365/processors/A365SpanProcessor.d.ts.map +1 -0
  274. package/dist/esm/a365/processors/A365SpanProcessor.js +100 -0
  275. package/dist/esm/a365/processors/A365SpanProcessor.js.map +1 -0
  276. package/dist/esm/a365/processors/PerRequestSpanProcessor.d.ts +44 -0
  277. package/dist/esm/a365/processors/PerRequestSpanProcessor.d.ts.map +1 -0
  278. package/dist/esm/a365/processors/PerRequestSpanProcessor.js +256 -0
  279. package/dist/esm/a365/processors/PerRequestSpanProcessor.js.map +1 -0
  280. package/dist/esm/a365/processors/index.d.ts +5 -0
  281. package/dist/esm/a365/processors/index.d.ts.map +1 -0
  282. package/dist/esm/a365/processors/index.js +6 -0
  283. package/dist/esm/a365/processors/index.js.map +1 -0
  284. package/dist/esm/a365/processors/util.d.ts +10 -0
  285. package/dist/esm/a365/processors/util.d.ts.map +1 -0
  286. package/dist/esm/a365/processors/util.js +53 -0
  287. package/dist/esm/a365/processors/util.js.map +1 -0
  288. package/dist/esm/a365/scopes/ExecuteToolScope.d.ts +24 -0
  289. package/dist/esm/a365/scopes/ExecuteToolScope.d.ts.map +1 -0
  290. package/dist/esm/a365/scopes/ExecuteToolScope.js +56 -0
  291. package/dist/esm/a365/scopes/ExecuteToolScope.js.map +1 -0
  292. package/dist/esm/a365/scopes/InferenceScope.d.ts +29 -0
  293. package/dist/esm/a365/scopes/InferenceScope.d.ts.map +1 -0
  294. package/dist/esm/a365/scopes/InferenceScope.js +71 -0
  295. package/dist/esm/a365/scopes/InferenceScope.js.map +1 -0
  296. package/dist/esm/a365/scopes/InvokeAgentScope.d.ts +25 -0
  297. package/dist/esm/a365/scopes/InvokeAgentScope.d.ts.map +1 -0
  298. package/dist/esm/a365/scopes/InvokeAgentScope.js +80 -0
  299. package/dist/esm/a365/scopes/InvokeAgentScope.js.map +1 -0
  300. package/dist/esm/a365/scopes/OpenTelemetryScope.d.ts +69 -0
  301. package/dist/esm/a365/scopes/OpenTelemetryScope.d.ts.map +1 -0
  302. package/dist/esm/a365/scopes/OpenTelemetryScope.js +207 -0
  303. package/dist/esm/a365/scopes/OpenTelemetryScope.js.map +1 -0
  304. package/dist/esm/a365/scopes/OutputScope.d.ts +26 -0
  305. package/dist/esm/a365/scopes/OutputScope.d.ts.map +1 -0
  306. package/dist/esm/a365/scopes/OutputScope.js +69 -0
  307. package/dist/esm/a365/scopes/OutputScope.js.map +1 -0
  308. package/dist/esm/a365/scopes/index.d.ts +6 -0
  309. package/dist/esm/a365/scopes/index.d.ts.map +1 -0
  310. package/dist/esm/a365/scopes/index.js +8 -0
  311. package/dist/esm/a365/scopes/index.js.map +1 -0
  312. package/dist/esm/a365/utils/utils.d.ts +6 -0
  313. package/dist/esm/a365/utils/utils.d.ts.map +1 -0
  314. package/dist/esm/a365/utils/utils.js +11 -0
  315. package/dist/esm/a365/utils/utils.js.map +1 -0
  316. package/dist/esm/azureMonitor/index.d.ts +14 -0
  317. package/dist/esm/azureMonitor/index.d.ts.map +1 -1
  318. package/dist/esm/azureMonitor/index.js +27 -0
  319. package/dist/esm/azureMonitor/index.js.map +1 -1
  320. package/dist/esm/azureMonitor/metrics/handler.js +2 -2
  321. package/dist/esm/azureMonitor/metrics/handler.js.map +1 -1
  322. package/dist/esm/azureMonitor/metrics/quickpulse/types.d.ts +1 -1
  323. package/dist/esm/azureMonitor/traces/handler.d.ts +0 -3
  324. package/dist/esm/azureMonitor/traces/handler.d.ts.map +1 -1
  325. package/dist/esm/azureMonitor/traces/handler.js +6 -19
  326. package/dist/esm/azureMonitor/traces/handler.js.map +1 -1
  327. package/dist/esm/distro/distro.d.ts +3 -1
  328. package/dist/esm/distro/distro.d.ts.map +1 -1
  329. package/dist/esm/distro/distro.js +89 -93
  330. package/dist/esm/distro/distro.js.map +1 -1
  331. package/dist/esm/distro/instrumentations.d.ts +31 -0
  332. package/dist/esm/distro/instrumentations.d.ts.map +1 -0
  333. package/dist/esm/distro/instrumentations.js +126 -0
  334. package/dist/esm/distro/instrumentations.js.map +1 -0
  335. package/dist/esm/distro/types.d.ts +2 -1
  336. package/dist/esm/distro/types.d.ts.map +1 -1
  337. package/dist/esm/index.d.ts +8 -12
  338. package/dist/esm/index.d.ts.map +1 -1
  339. package/dist/esm/index.js +6 -17
  340. package/dist/esm/index.js.map +1 -1
  341. package/dist/esm/shared/jsonConfig.d.ts +2 -1
  342. package/dist/esm/shared/jsonConfig.d.ts.map +1 -1
  343. package/dist/esm/types.d.ts +8 -32
  344. package/dist/esm/types.d.ts.map +1 -1
  345. package/dist/esm/types.js +1 -1
  346. package/dist/esm/types.js.map +1 -1
  347. package/package.json +7 -8
@@ -0,0 +1,100 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { propagation } from "@opentelemetry/api";
4
+ import { OpenTelemetryConstants } from "../constants.js";
5
+ import { GENERIC_ATTRIBUTES, INVOKE_AGENT_ATTRIBUTES } from "./util.js";
6
+ /**
7
+ * Copies relevant baggage entries to span attributes on span start.
8
+ *
9
+ * This is the "automatic" counterpart to the manual scope API — it ensures
10
+ * every span in the pipeline gets agent identity attributes from baggage
11
+ * without explicitly creating scopes.
12
+ */
13
+ export class A365SpanProcessor {
14
+ /**
15
+ * Called when a span is started.
16
+ * Copies relevant baggage entries to span attributes.
17
+ */
18
+ onStart(span, parentContext) {
19
+ const ctx = parentContext;
20
+ if (!ctx) {
21
+ return;
22
+ }
23
+ // Get existing span attributes
24
+ const existingAttrs = new Set();
25
+ try {
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ const spanRecord = span;
28
+ if (spanRecord.attributes) {
29
+ Object.keys(spanRecord.attributes).forEach((key) => existingAttrs.add(key));
30
+ }
31
+ }
32
+ catch {
33
+ // Ignore errors accessing span attributes
34
+ }
35
+ // Get all baggage entries
36
+ const baggage = propagation.getBaggage(ctx);
37
+ if (!baggage) {
38
+ return;
39
+ }
40
+ const baggageMap = new Map();
41
+ baggage.getAllEntries().forEach(([key, entry]) => {
42
+ if (entry.value) {
43
+ baggageMap.set(key, entry.value);
44
+ }
45
+ });
46
+ // Determine if this is an invoke_agent operation
47
+ const operationName = baggageMap.get(OpenTelemetryConstants.GEN_AI_OPERATION_NAME_KEY) ||
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
+ span.attributes?.[OpenTelemetryConstants.GEN_AI_OPERATION_NAME_KEY];
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ const spanName = span.name || "";
52
+ const isInvokeAgent = operationName === OpenTelemetryConstants.INVOKE_AGENT_OPERATION_NAME ||
53
+ spanName.startsWith(OpenTelemetryConstants.INVOKE_AGENT_OPERATION_NAME);
54
+ // Build target key set
55
+ const targetKeys = new Set(GENERIC_ATTRIBUTES);
56
+ if (isInvokeAgent) {
57
+ INVOKE_AGENT_ATTRIBUTES.forEach((key) => targetKeys.add(key));
58
+ }
59
+ // Set telemetry SDK attributes
60
+ if (!existingAttrs.has(OpenTelemetryConstants.TELEMETRY_SDK_NAME_KEY)) {
61
+ span.setAttribute(OpenTelemetryConstants.TELEMETRY_SDK_NAME_KEY, OpenTelemetryConstants.TELEMETRY_SDK_NAME_VALUE);
62
+ }
63
+ if (!existingAttrs.has(OpenTelemetryConstants.TELEMETRY_SDK_LANGUAGE_KEY)) {
64
+ span.setAttribute(OpenTelemetryConstants.TELEMETRY_SDK_LANGUAGE_KEY, OpenTelemetryConstants.TELEMETRY_SDK_LANGUAGE_VALUE);
65
+ }
66
+ if (!existingAttrs.has(OpenTelemetryConstants.TELEMETRY_SDK_VERSION_KEY)) {
67
+ span.setAttribute(OpenTelemetryConstants.TELEMETRY_SDK_VERSION_KEY, OpenTelemetryConstants.TELEMETRY_SDK_VERSION_VALUE);
68
+ }
69
+ // Copy baggage to span attributes
70
+ for (const key of targetKeys) {
71
+ // Skip if attribute already exists
72
+ if (existingAttrs.has(key)) {
73
+ continue;
74
+ }
75
+ const value = baggageMap.get(key);
76
+ if (!value) {
77
+ continue;
78
+ }
79
+ try {
80
+ span.setAttribute(key, value);
81
+ }
82
+ catch {
83
+ // Ignore errors setting attributes
84
+ }
85
+ }
86
+ }
87
+ /** Called when a span is ended. */
88
+ onEnd(_span) {
89
+ // No-op for this processor
90
+ }
91
+ /** Shutdown the processor. */
92
+ async shutdown() {
93
+ // No-op for this processor
94
+ }
95
+ /** Force flush the processor. */
96
+ async forceFlush() {
97
+ // No-op for this processor
98
+ }
99
+ }
100
+ //# sourceMappingURL=A365SpanProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"A365SpanProcessor.js","sourceRoot":"","sources":["../../../../src/a365/processors/A365SpanProcessor.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAalC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAKjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAExE;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IAC5B;;;OAGG;IACH,OAAO,CAAC,IAAU,EAAE,aAAuB;QACzC,MAAM,GAAG,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO;QACT,CAAC;QAED,+BAA+B;QAC/B,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;QACxC,IAAI,CAAC;YACH,8DAA8D;YAC9D,MAAM,UAAU,GAAG,IAAW,CAAC;YAC/B,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;gBAC1B,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YAC9E,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,0CAA0C;QAC5C,CAAC;QAED,0BAA0B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J,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,sBAAsB,CAAC,0BAA0B,CAAC,EAAE,CAAC;YAC1E,IAAI,CAAC,YAAY,CACf,sBAAsB,CAAC,0BAA0B,EACjD,sBAAsB,CAAC,4BAA4B,CACpD,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,sBAAsB,CAAC,yBAAyB,CAAC,EAAE,CAAC;YACzE,IAAI,CAAC,YAAY,CACf,sBAAsB,CAAC,yBAAyB,EAChD,sBAAsB,CAAC,2BAA2B,CACnD,CAAC;QACJ,CAAC;QAED,kCAAkC;QAClC,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;YAC7B,mCAAmC;YACnC,IAAI,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC3B,SAAS;YACX,CAAC;YAED,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAClC,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,SAAS;YACX,CAAC;YAED,IAAI,CAAC;gBACH,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAChC,CAAC;YAAC,MAAM,CAAC;gBACP,mCAAmC;YACrC,CAAC;QACH,CAAC;IACH,CAAC;IAED,mCAAmC;IACnC,KAAK,CAAC,KAAmB;QACvB,2BAA2B;IAC7B,CAAC;IAED,8BAA8B;IAC9B,KAAK,CAAC,QAAQ;QACZ,2BAA2B;IAC7B,CAAC;IAED,iCAAiC;IACjC,KAAK,CAAC,UAAU;QACd,2BAA2B;IAC7B,CAAC;CACF"}
@@ -0,0 +1,44 @@
1
+ import type { Context, Span } from "@opentelemetry/api";
2
+ import type { ReadableSpan, SpanProcessor, SpanExporter } from "@opentelemetry/sdk-trace-base";
3
+ /**
4
+ * Configuration options for the PerRequestSpanProcessor.
5
+ */
6
+ export interface PerRequestSpanProcessorOptions {
7
+ maxBufferedTraces?: number;
8
+ maxSpansPerTrace?: number;
9
+ maxConcurrentExports?: number;
10
+ flushGraceMs?: number;
11
+ maxTraceAgeMs?: number;
12
+ }
13
+ /**
14
+ * Buffers spans per trace and exports them together once the trace completes.
15
+ *
16
+ * This processor supports per-request token resolution by exporting under
17
+ * the original request Context so that getExportToken() can read the token
18
+ * from the active OpenTelemetry Context at export time.
19
+ */
20
+ export declare class PerRequestSpanProcessor implements SpanProcessor {
21
+ private readonly exporter;
22
+ private traces;
23
+ private sweepTimer?;
24
+ private isSweeping;
25
+ private readonly maxBufferedTraces;
26
+ private readonly maxSpansPerTrace;
27
+ private readonly maxConcurrentExports;
28
+ private readonly flushGraceMs;
29
+ private readonly maxTraceAgeMs;
30
+ private inFlightExports;
31
+ private exportWaiters;
32
+ constructor(exporter: SpanExporter, options?: PerRequestSpanProcessorOptions);
33
+ onStart(span: Span, ctx: Context): void;
34
+ onEnd(span: ReadableSpan): void;
35
+ forceFlush(): Promise<void>;
36
+ shutdown(): Promise<void>;
37
+ private ensureSweepTimer;
38
+ private stopSweepTimerIfIdle;
39
+ private sweep;
40
+ private flushTrace;
41
+ private acquireExportSlot;
42
+ private releaseExportSlot;
43
+ }
44
+ //# sourceMappingURL=PerRequestSpanProcessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PerRequestSpanProcessor.d.ts","sourceRoot":"","sources":["../../../../src/a365/processors/PerRequestSpanProcessor.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AA+B/F;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAeD;;;;;;GAMG;AACH,qBAAa,uBAAwB,YAAW,aAAa;IAezD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAd3B,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,UAAU,CAAC,CAAiC;IACpD,OAAO,CAAC,UAAU,CAAS;IAE3B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IAEvC,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,aAAa,CAAyB;gBAG3B,QAAQ,EAAE,YAAY,EACvC,OAAO,CAAC,EAAE,8BAA8B;IAwB1C,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI;IA0CvC,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAwCzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAM/B,OAAO,CAAC,gBAAgB;IAaxB,OAAO,CAAC,oBAAoB;YAOd,KAAK;YAkCL,UAAU;YA8DV,iBAAiB;IAe/B,OAAO,CAAC,iBAAiB;CAM1B"}
@@ -0,0 +1,256 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ /**
4
+ * Buffers spans per trace and exports once the request completes.
5
+ * Token is not stored; we export under the saved request Context so that
6
+ * getExportToken() can read the token from the active OpenTelemetry Context at export time.
7
+ *
8
+ * Adapted from microsoft/Agent365-nodejs agents-a365-observability/src/tracing/PerRequestSpanProcessor.ts
9
+ */
10
+ import { context, trace } from "@opentelemetry/api";
11
+ import { Logger } from "../../shared/logging/index.js";
12
+ const logger = Logger.getInstance();
13
+ function isRootSpan(span) {
14
+ return !span.parentSpanContext;
15
+ }
16
+ /**
17
+ * Check whether this span is a root span by examining the parent context.
18
+ * In onStart, the SDK passes a live Span (not ReadableSpan), so we check
19
+ * whether the parent context already contains a span.
20
+ */
21
+ function isRootSpanFromContext(ctx) {
22
+ const parentSpan = trace.getSpan(ctx);
23
+ return !parentSpan;
24
+ }
25
+ // Default values
26
+ const DEFAULT_MAX_BUFFERED_TRACES = 1000;
27
+ const DEFAULT_MAX_SPANS_PER_TRACE = 5000;
28
+ const DEFAULT_MAX_CONCURRENT_EXPORTS = 20;
29
+ const DEFAULT_FLUSH_GRACE_MS = 250;
30
+ const DEFAULT_MAX_TRACE_AGE_MS = 1800000; // 30 minutes
31
+ function parseEnvInt(envVar, defaultValue) {
32
+ if (envVar === undefined || envVar === "")
33
+ return defaultValue;
34
+ const parsed = parseInt(envVar, 10);
35
+ return Number.isNaN(parsed) ? defaultValue : parsed;
36
+ }
37
+ /**
38
+ * Buffers spans per trace and exports them together once the trace completes.
39
+ *
40
+ * This processor supports per-request token resolution by exporting under
41
+ * the original request Context so that getExportToken() can read the token
42
+ * from the active OpenTelemetry Context at export time.
43
+ */
44
+ export class PerRequestSpanProcessor {
45
+ exporter;
46
+ traces = new Map();
47
+ sweepTimer;
48
+ isSweeping = false;
49
+ maxBufferedTraces;
50
+ maxSpansPerTrace;
51
+ maxConcurrentExports;
52
+ flushGraceMs;
53
+ maxTraceAgeMs;
54
+ inFlightExports = 0;
55
+ exportWaiters = [];
56
+ constructor(exporter, options) {
57
+ this.exporter = exporter;
58
+ this.maxBufferedTraces = parseEnvInt(process.env.A365_PER_REQUEST_MAX_TRACES, options?.maxBufferedTraces ?? DEFAULT_MAX_BUFFERED_TRACES);
59
+ this.maxSpansPerTrace = parseEnvInt(process.env.A365_PER_REQUEST_MAX_SPANS_PER_TRACE, options?.maxSpansPerTrace ?? DEFAULT_MAX_SPANS_PER_TRACE);
60
+ this.maxConcurrentExports = parseEnvInt(process.env.A365_PER_REQUEST_MAX_CONCURRENT_EXPORTS, options?.maxConcurrentExports ?? DEFAULT_MAX_CONCURRENT_EXPORTS);
61
+ this.flushGraceMs = parseEnvInt(process.env.A365_PER_REQUEST_FLUSH_GRACE_MS, options?.flushGraceMs ?? DEFAULT_FLUSH_GRACE_MS);
62
+ this.maxTraceAgeMs = parseEnvInt(process.env.A365_PER_REQUEST_MAX_TRACE_AGE_MS, options?.maxTraceAgeMs ?? DEFAULT_MAX_TRACE_AGE_MS);
63
+ }
64
+ onStart(span, ctx) {
65
+ const traceId = span.spanContext().traceId;
66
+ let buf = this.traces.get(traceId);
67
+ if (!buf) {
68
+ if (this.traces.size >= this.maxBufferedTraces) {
69
+ logger.warn(`[PerRequestSpanProcessor] Dropping new trace due to maxBufferedTraces=${this.maxBufferedTraces} traceId=${traceId}`);
70
+ return;
71
+ }
72
+ buf = {
73
+ spans: [],
74
+ openCount: 0,
75
+ rootEnded: false,
76
+ rootCtx: undefined,
77
+ startedAtMs: Date.now(),
78
+ droppedSpans: 0,
79
+ };
80
+ this.traces.set(traceId, buf);
81
+ this.ensureSweepTimer();
82
+ logger.debug(`[PerRequestSpanProcessor] Trace started traceId=${traceId} maxTraceAgeMs=${this.maxTraceAgeMs}`);
83
+ }
84
+ buf.openCount += 1;
85
+ const root = isRootSpanFromContext(ctx);
86
+ logger.debug(`[PerRequestSpanProcessor] Span start traceId=${traceId} spanId=${span.spanContext().spanId}` +
87
+ ` root=${root} openCount=${buf.openCount}`);
88
+ // Capture a context to export under.
89
+ if (root) {
90
+ buf.rootCtx = ctx;
91
+ }
92
+ else {
93
+ buf.rootCtx ??= ctx;
94
+ }
95
+ }
96
+ onEnd(span) {
97
+ const traceId = span.spanContext().traceId;
98
+ const buf = this.traces.get(traceId);
99
+ if (!buf)
100
+ return;
101
+ if (buf.spans.length >= this.maxSpansPerTrace) {
102
+ buf.droppedSpans += 1;
103
+ if (buf.droppedSpans === 1 || buf.droppedSpans % 100 === 0) {
104
+ logger.warn(`[PerRequestSpanProcessor] Dropping ended span due to maxSpansPerTrace=${this.maxSpansPerTrace} ` +
105
+ `traceId=${traceId} droppedSpans=${buf.droppedSpans}`);
106
+ }
107
+ }
108
+ else {
109
+ buf.spans.push(span);
110
+ }
111
+ buf.openCount -= 1;
112
+ if (buf.openCount < 0) {
113
+ logger.warn(`[PerRequestSpanProcessor] openCount underflow traceId=${traceId} spanId=${span.spanContext().spanId} resettingToZero`);
114
+ buf.openCount = 0;
115
+ }
116
+ logger.debug(`[PerRequestSpanProcessor] Span end name=${span.name} traceId=${traceId} spanId=${span.spanContext().spanId}` +
117
+ ` root=${isRootSpan(span)} openCount=${buf.openCount} rootEnded=${buf.rootEnded}`);
118
+ if (isRootSpan(span)) {
119
+ buf.rootEnded = true;
120
+ buf.rootEndedAtMs = Date.now();
121
+ if (buf.openCount === 0) {
122
+ this.flushTrace(traceId, "trace_completed");
123
+ }
124
+ }
125
+ else if (buf.rootEnded && buf.openCount === 0) {
126
+ this.flushTrace(traceId, "trace_completed");
127
+ }
128
+ }
129
+ async forceFlush() {
130
+ await Promise.all([...this.traces.keys()].map((id) => this.flushTrace(id, "force_flush")));
131
+ }
132
+ async shutdown() {
133
+ await this.forceFlush();
134
+ this.stopSweepTimerIfIdle();
135
+ await this.exporter.shutdown?.();
136
+ }
137
+ ensureSweepTimer() {
138
+ if (this.sweepTimer)
139
+ return;
140
+ const intervalMs = Math.max(10, Math.min(this.flushGraceMs, 250));
141
+ this.sweepTimer = setInterval(() => {
142
+ void this.sweep();
143
+ }, intervalMs);
144
+ if (typeof this.sweepTimer === "object" && "unref" in this.sweepTimer) {
145
+ this.sweepTimer.unref();
146
+ }
147
+ }
148
+ stopSweepTimerIfIdle() {
149
+ if (this.traces.size !== 0)
150
+ return;
151
+ if (!this.sweepTimer)
152
+ return;
153
+ clearInterval(this.sweepTimer);
154
+ this.sweepTimer = undefined;
155
+ }
156
+ async sweep() {
157
+ if (this.isSweeping)
158
+ return;
159
+ this.isSweeping = true;
160
+ try {
161
+ if (this.traces.size === 0) {
162
+ this.stopSweepTimerIfIdle();
163
+ return;
164
+ }
165
+ const now = Date.now();
166
+ const toFlush = [];
167
+ for (const [traceId, trace] of this.traces.entries()) {
168
+ // 1) Max age safety flush
169
+ if (now - trace.startedAtMs >= this.maxTraceAgeMs) {
170
+ toFlush.push({ traceId, reason: "max_trace_age" });
171
+ continue;
172
+ }
173
+ // 2) Root ended grace window flush
174
+ if (trace.rootEnded && trace.openCount > 0 && trace.rootEndedAtMs) {
175
+ if (now - trace.rootEndedAtMs >= this.flushGraceMs) {
176
+ toFlush.push({ traceId, reason: "root_ended_grace" });
177
+ }
178
+ }
179
+ }
180
+ await Promise.all(toFlush.map((x) => this.flushTrace(x.traceId, x.reason)));
181
+ this.stopSweepTimerIfIdle();
182
+ }
183
+ finally {
184
+ this.isSweeping = false;
185
+ }
186
+ }
187
+ async flushTrace(traceId, reason) {
188
+ const trace = this.traces.get(traceId);
189
+ if (!trace)
190
+ return;
191
+ this.traces.delete(traceId);
192
+ this.stopSweepTimerIfIdle();
193
+ const spans = trace.spans;
194
+ if (spans.length === 0)
195
+ return;
196
+ logger.debug(`[PerRequestSpanProcessor] Flushing trace traceId=${traceId} reason=${reason} spans=${spans.length} rootEnded=${trace.rootEnded}`);
197
+ if (!trace.rootCtx) {
198
+ logger.error(`[PerRequestSpanProcessor] Missing rootCtx for trace ${traceId}, cannot export spans`);
199
+ return;
200
+ }
201
+ await this.acquireExportSlot();
202
+ try {
203
+ await new Promise((resolve) => {
204
+ try {
205
+ context.with(trace.rootCtx, () => {
206
+ try {
207
+ this.exporter.export(spans, (result) => {
208
+ if (result.code !== 0) {
209
+ logger.error(`[PerRequestSpanProcessor] Export failed traceId=${traceId} reason=${reason} code=${result.code}`, result.error);
210
+ }
211
+ else {
212
+ logger.debug(`[PerRequestSpanProcessor] Export succeeded traceId=${traceId} reason=${reason} spans=${spans.length}`);
213
+ }
214
+ resolve();
215
+ });
216
+ }
217
+ catch (err) {
218
+ logger.error(`[PerRequestSpanProcessor] Export threw traceId=${traceId} reason=${reason} spans=${spans.length}`, err);
219
+ resolve();
220
+ }
221
+ });
222
+ }
223
+ catch (err) {
224
+ logger.error(`[PerRequestSpanProcessor] context.with threw traceId=${traceId} reason=${reason}`, err);
225
+ resolve();
226
+ }
227
+ });
228
+ }
229
+ finally {
230
+ this.releaseExportSlot();
231
+ }
232
+ }
233
+ async acquireExportSlot() {
234
+ if (this.maxConcurrentExports <= 0)
235
+ return;
236
+ if (this.inFlightExports < this.maxConcurrentExports) {
237
+ this.inFlightExports += 1;
238
+ return;
239
+ }
240
+ await new Promise((resolve) => {
241
+ this.exportWaiters.push(() => {
242
+ this.inFlightExports += 1;
243
+ resolve();
244
+ });
245
+ });
246
+ }
247
+ releaseExportSlot() {
248
+ if (this.maxConcurrentExports <= 0)
249
+ return;
250
+ this.inFlightExports = Math.max(0, this.inFlightExports - 1);
251
+ const next = this.exportWaiters.shift();
252
+ if (next)
253
+ next();
254
+ }
255
+ }
256
+ //# sourceMappingURL=PerRequestSpanProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PerRequestSpanProcessor.js","sourceRoot":"","sources":["../../../../src/a365/processors/PerRequestSpanProcessor.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAEvD,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;AAEpC,SAAS,UAAU,CAAC,IAAkB;IACpC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,SAAS,qBAAqB,CAAC,GAAY;IACzC,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,C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B,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,iBAAiB;QAC7B,IAAI,IAAI,CAAC,oBAAoB,IAAI,CAAC;YAAE,OAAO;QAC3C,IAAI,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;YACrD,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC;YAC1B,OAAO;QACT,CAAC;QAED,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YAClC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE;gBAC3B,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC;gBAC1B,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,iBAAiB;QACvB,IAAI,IAAI,CAAC,oBAAoB,IAAI,CAAC;YAAE,OAAO;QAC3C,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC;QAC7D,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QACxC,IAAI,IAAI;YAAE,IAAI,EAAE,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export { A365SpanProcessor } from "./A365SpanProcessor.js";
2
+ export { GENERIC_ATTRIBUTES, INVOKE_AGENT_ATTRIBUTES } from "./util.js";
3
+ export { PerRequestSpanProcessor } from "./PerRequestSpanProcessor.js";
4
+ export type { PerRequestSpanProcessorOptions } from "./PerRequestSpanProcessor.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/a365/processors/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,YAAY,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,6 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ export { A365SpanProcessor } from "./A365SpanProcessor.js";
4
+ export { GENERIC_ATTRIBUTES, INVOKE_AGENT_ATTRIBUTES } from "./util.js";
5
+ export { PerRequestSpanProcessor } from "./PerRequestSpanProcessor.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/a365/processors/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Generic / common tracing attributes applied to all spans.
3
+ */
4
+ export declare const GENERIC_ATTRIBUTES: readonly string[];
5
+ /**
6
+ * Invoke Agent-specific attributes.
7
+ * These are only applied to spans whose operation is `invoke_agent`.
8
+ */
9
+ export declare const INVOKE_AGENT_ATTRIBUTES: readonly string[];
10
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/a365/processors/util.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EA0B/C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,SAAS,MAAM,EASpD,CAAC"}
@@ -0,0 +1,53 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ /**
4
+ * Attribute key sets used by the SpanProcessor to copy baggage entries to span attributes.
5
+ *
6
+ * Adapted from microsoft/Agent365-nodejs agents-a365-observability/src/tracing/processors/util.ts
7
+ */
8
+ import { OpenTelemetryConstants as consts } from "../constants.js";
9
+ /**
10
+ * Generic / common tracing attributes applied to all spans.
11
+ */
12
+ export const GENERIC_ATTRIBUTES = [
13
+ consts.TENANT_ID_KEY,
14
+ consts.CUSTOM_PARENT_SPAN_ID_KEY,
15
+ consts.CUSTOM_SPAN_NAME_KEY,
16
+ consts.SESSION_ID_KEY,
17
+ consts.GEN_AI_CONVERSATION_ID_KEY,
18
+ consts.GEN_AI_CONVERSATION_ITEM_LINK_KEY,
19
+ consts.GEN_AI_OPERATION_NAME_KEY,
20
+ consts.GEN_AI_AGENT_ID_KEY,
21
+ consts.GEN_AI_AGENT_NAME_KEY,
22
+ consts.GEN_AI_AGENT_DESCRIPTION_KEY,
23
+ consts.SESSION_DESCRIPTION_KEY,
24
+ consts.GEN_AI_AGENT_EMAIL_KEY,
25
+ consts.GEN_AI_AGENT_AUID_KEY,
26
+ consts.GEN_AI_AGENT_PLATFORM_ID_KEY,
27
+ consts.GEN_AI_AGENT_BLUEPRINT_ID_KEY,
28
+ consts.GEN_AI_AGENT_VERSION_KEY,
29
+ consts.SERVICE_NAME_KEY,
30
+ // Caller / Invoker attributes
31
+ consts.USER_ID_KEY,
32
+ consts.USER_NAME_KEY,
33
+ consts.USER_EMAIL_KEY,
34
+ consts.GEN_AI_CALLER_CLIENT_IP_KEY,
35
+ // Channel attributes
36
+ consts.CHANNEL_NAME_KEY,
37
+ consts.CHANNEL_LINK_KEY,
38
+ ];
39
+ /**
40
+ * Invoke Agent-specific attributes.
41
+ * These are only applied to spans whose operation is `invoke_agent`.
42
+ */
43
+ export const INVOKE_AGENT_ATTRIBUTES = [
44
+ // Caller Agent (A2A) attributes
45
+ consts.GEN_AI_CALLER_AGENT_ID_KEY,
46
+ consts.GEN_AI_CALLER_AGENT_NAME_KEY,
47
+ consts.GEN_AI_CALLER_AGENT_USER_ID_KEY,
48
+ consts.GEN_AI_CALLER_AGENT_EMAIL_KEY,
49
+ consts.GEN_AI_CALLER_AGENT_APPLICATION_ID_KEY,
50
+ consts.GEN_AI_CALLER_AGENT_PLATFORM_ID_KEY,
51
+ consts.GEN_AI_CALLER_AGENT_VERSION_KEY,
52
+ ];
53
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/a365/processors/util.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;GAIG;AAEH,OAAO,EAAE,sBAAsB,IAAI,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEnE;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAsB;IACnD,MAAM,CAAC,aAAa;IACpB,MAAM,CAAC,yBAAyB;IAChC,MAAM,CAAC,oBAAoB;IAC3B,MAAM,CAAC,cAAc;IACrB,MAAM,CAAC,0BAA0B;IACjC,MAAM,CAAC,iCAAiC;IACxC,MAAM,CAAC,yBAAyB;IAChC,MAAM,CAAC,mBAAmB;IAC1B,MAAM,CAAC,qBAAqB;IAC5B,MAAM,CAAC,4BAA4B;IACnC,MAAM,CAAC,uBAAuB;IAC9B,MAAM,CAAC,sBAAsB;IAC7B,MAAM,CAAC,qBAAqB;IAC5B,MAAM,CAAC,4BAA4B;IACnC,MAAM,CAAC,6BAA6B;IACpC,MAAM,CAAC,wBAAwB;IAC/B,MAAM,CAAC,gBAAgB;IACvB,8BAA8B;IAC9B,MAAM,CAAC,WAAW;IAClB,MAAM,CAAC,aAAa;IACpB,MAAM,CAAC,cAAc;IACrB,MAAM,CAAC,2BAA2B;IAClC,qBAAqB;IACrB,MAAM,CAAC,gBAAgB;IACvB,MAAM,CAAC,gBAAgB;CACxB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAsB;IACxD,gCAAgC;IAChC,MAAM,CAAC,0BAA0B;IACjC,MAAM,CAAC,4BAA4B;IACnC,MAAM,CAAC,+BAA+B;IACtC,MAAM,CAAC,6BAA6B;IACpC,MAAM,CAAC,sCAAsC;IAC7C,MAAM,CAAC,mCAAmC;IAC1C,MAAM,CAAC,+BAA+B;CACvC,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { OpenTelemetryScope } from "./OpenTelemetryScope.js";
2
+ import type { ToolCallDetails, AgentDetails, UserDetails, Request, SpanDetails } from "../contracts.js";
3
+ /**
4
+ * Provides OpenTelemetry tracing scope for AI tool execution operations.
5
+ */
6
+ export declare class ExecuteToolScope extends OpenTelemetryScope {
7
+ /**
8
+ * Creates and starts a new scope for tool execution tracing.
9
+ *
10
+ * @param request Request payload (channel, conversationId, content, sessionId).
11
+ * @param details The tool call details (name, type, args, call id, etc.).
12
+ * @param agentDetails The agent executing the tool. `tenantId` is required.
13
+ * @param userDetails Optional human caller identity.
14
+ * @param spanDetails Optional span configuration. Defaults to SpanKind.INTERNAL.
15
+ */
16
+ static start(request: Request, details: ToolCallDetails, agentDetails: AgentDetails, userDetails?: UserDetails, spanDetails?: SpanDetails): ExecuteToolScope;
17
+ private constructor();
18
+ /**
19
+ * Records response information for telemetry tracking.
20
+ * Objects are serialized to JSON automatically.
21
+ */
22
+ recordResponse(response: Record<string, unknown> | string): void;
23
+ }
24
+ //# sourceMappingURL=ExecuteToolScope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExecuteToolScope.d.ts","sourceRoot":"","sources":["../../../../src/a365/scopes/ExecuteToolScope.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,WAAW,EACX,OAAO,EACP,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,kBAAkB;IACtD;;;;;;;;OAQG;WACW,KAAK,CACjB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,eAAe,EACxB,YAAY,EAAE,YAAY,EAC1B,WAAW,CAAC,EAAE,WAAW,EACzB,WAAW,CAAC,EAAE,WAAW,GACxB,gBAAgB;IAInB,OAAO;IA+CP;;;OAGG;IACI,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI;CAMxE"}
@@ -0,0 +1,56 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { SpanKind } from "@opentelemetry/api";
4
+ import { OpenTelemetryScope } from "./OpenTelemetryScope.js";
5
+ import { OpenTelemetryConstants } from "../constants.js";
6
+ import { safeSerializeToJson } from "../message-utils.js";
7
+ /**
8
+ * Provides OpenTelemetry tracing scope for AI tool execution operations.
9
+ */
10
+ export class ExecuteToolScope extends OpenTelemetryScope {
11
+ /**
12
+ * Creates and starts a new scope for tool execution tracing.
13
+ *
14
+ * @param request Request payload (channel, conversationId, content, sessionId).
15
+ * @param details The tool call details (name, type, args, call id, etc.).
16
+ * @param agentDetails The agent executing the tool. `tenantId` is required.
17
+ * @param userDetails Optional human caller identity.
18
+ * @param spanDetails Optional span configuration. Defaults to SpanKind.INTERNAL.
19
+ */
20
+ static start(request, details, agentDetails, userDetails, spanDetails) {
21
+ return new ExecuteToolScope(request, details, agentDetails, userDetails, spanDetails);
22
+ }
23
+ constructor(request, details, agentDetails, userDetails, spanDetails) {
24
+ if (!agentDetails.tenantId) {
25
+ throw new Error("ExecuteToolScope: tenantId is required on agentDetails");
26
+ }
27
+ const resolvedSpanDetails = {
28
+ spanKind: SpanKind.INTERNAL,
29
+ ...spanDetails,
30
+ };
31
+ super(OpenTelemetryConstants.EXECUTE_TOOL_OPERATION_NAME, `${OpenTelemetryConstants.EXECUTE_TOOL_OPERATION_NAME} ${details.toolName}`, agentDetails, resolvedSpanDetails, userDetails);
32
+ const { toolName, arguments: args, toolCallId, description, toolType, endpoint } = details;
33
+ this.setTagMaybe(OpenTelemetryConstants.GEN_AI_TOOL_NAME_KEY, toolName);
34
+ this.setTagMaybe(OpenTelemetryConstants.GEN_AI_TOOL_ARGS_KEY, args != null ? safeSerializeToJson(args, "arguments") : undefined);
35
+ this.setTagMaybe(OpenTelemetryConstants.GEN_AI_TOOL_TYPE_KEY, toolType);
36
+ this.setTagMaybe(OpenTelemetryConstants.GEN_AI_TOOL_CALL_ID_KEY, toolCallId);
37
+ this.setTagMaybe(OpenTelemetryConstants.GEN_AI_TOOL_DESCRIPTION_KEY, description);
38
+ this.setTagMaybe(OpenTelemetryConstants.GEN_AI_CONVERSATION_ID_KEY, request.conversationId);
39
+ this.setTagMaybe(OpenTelemetryConstants.CHANNEL_NAME_KEY, request.channel?.name);
40
+ this.setTagMaybe(OpenTelemetryConstants.CHANNEL_LINK_KEY, request.channel?.description);
41
+ if (endpoint) {
42
+ this.setTagMaybe(OpenTelemetryConstants.SERVER_ADDRESS_KEY, endpoint.host);
43
+ if (endpoint.port && endpoint.port !== 443) {
44
+ this.setTagMaybe(OpenTelemetryConstants.SERVER_PORT_KEY, endpoint.port);
45
+ }
46
+ }
47
+ }
48
+ /**
49
+ * Records response information for telemetry tracking.
50
+ * Objects are serialized to JSON automatically.
51
+ */
52
+ recordResponse(response) {
53
+ this.setTagMaybe(OpenTelemetryConstants.GEN_AI_TOOL_CALL_RESULT_KEY, safeSerializeToJson(response, "result"));
54
+ }
55
+ }
56
+ //# sourceMappingURL=ExecuteToolScope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExecuteToolScope.js","sourceRoot":"","sources":["../../../../src/a365/scopes/ExecuteToolScope.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OA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AAW,CAAC,sBAAsB,CAAC,uBAAuB,EAAE,UAAU,CAAC,CAAC;QAC7E,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC,2BAA2B,EAAE,WAAW,CAAC,CAAC;QAElF,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC,0BAA0B,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;QAC5F,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC,gBAAgB,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACjF,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC,gBAAgB,EAAE,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAExF,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC,kBAAkB,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC3E,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,KAAK,GAAG,EAAE,CAAC;gBAC3C,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC,eAAe,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC1E,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,cAAc,CAAC,QAA0C;QAC9D,IAAI,CAAC,WAAW,CACd,sBAAsB,CAAC,2BAA2B,EAClD,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CACxC,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,29 @@
1
+ import { OpenTelemetryScope } from "./OpenTelemetryScope.js";
2
+ import type { InferenceDetails, AgentDetails, UserDetails, Request, SpanDetails, InputMessagesParam, OutputMessagesParam } from "../contracts.js";
3
+ /**
4
+ * Provides OpenTelemetry tracing scope for generative AI inference operations.
5
+ */
6
+ export declare class InferenceScope extends OpenTelemetryScope {
7
+ /**
8
+ * Creates and starts a new scope for inference tracing.
9
+ *
10
+ * @param request Request payload (channel, conversationId, content, sessionId).
11
+ * @param details The inference call details (model, provider, tokens, etc.).
12
+ * @param agentDetails The agent performing the inference. `tenantId` is required.
13
+ * @param userDetails Optional human caller identity.
14
+ * @param spanDetails Optional span configuration. `spanKind` is always CLIENT.
15
+ */
16
+ static start(request: Request, details: InferenceDetails, agentDetails: AgentDetails, userDetails?: UserDetails, spanDetails?: SpanDetails): InferenceScope;
17
+ private constructor();
18
+ /** Records the number of input tokens. */
19
+ recordInputTokens(inputTokens: number): void;
20
+ /** Records the number of output tokens. */
21
+ recordOutputTokens(outputTokens: number): void;
22
+ /** Records the finish reasons. */
23
+ recordFinishReasons(finishReasons: string[]): void;
24
+ /** Records the input messages for telemetry tracking. */
25
+ recordInputMessages(messages: InputMessagesParam): void;
26
+ /** Records the output messages for telemetry tracking. */
27
+ recordOutputMessages(messages: OutputMessagesParam): void;
28
+ }
29
+ //# sourceMappingURL=InferenceScope.d.ts.map