autotel 3.6.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (617) hide show
  1. package/dist/attribute-redacting-processor-DtTS9xxh.d.cts +175 -0
  2. package/dist/attribute-redacting-processor-DtTS9xxh.d.cts.map +1 -0
  3. package/dist/attribute-redacting-processor-DtTS9xxh.d.ts +175 -0
  4. package/dist/attribute-redacting-processor-DtTS9xxh.d.ts.map +1 -0
  5. package/dist/attribute-redacting-processor.cjs +374 -33
  6. package/dist/attribute-redacting-processor.cjs.map +1 -1
  7. package/dist/attribute-redacting-processor.d.cts +2 -207
  8. package/dist/attribute-redacting-processor.d.ts +2 -207
  9. package/dist/attribute-redacting-processor.js +368 -2
  10. package/dist/attribute-redacting-processor.js.map +1 -1
  11. package/dist/attributes-CmYpdqCN.js +591 -0
  12. package/dist/attributes-CmYpdqCN.js.map +1 -0
  13. package/dist/attributes-PZ5doLgw.cjs +704 -0
  14. package/dist/attributes-PZ5doLgw.cjs.map +1 -0
  15. package/dist/attributes.cjs +21 -85
  16. package/dist/attributes.d.cts +2 -20
  17. package/dist/attributes.d.ts +2 -20
  18. package/dist/attributes.js +3 -5
  19. package/dist/auto.cjs +50 -28
  20. package/dist/auto.cjs.map +1 -1
  21. package/dist/auto.d.cts +1 -2
  22. package/dist/auto.d.ts +1 -2
  23. package/dist/auto.js +49 -23
  24. package/dist/auto.js.map +1 -1
  25. package/dist/business-baggage.cjs +357 -13
  26. package/dist/business-baggage.cjs.map +1 -1
  27. package/dist/business-baggage.d.cts +106 -139
  28. package/dist/business-baggage.d.cts.map +1 -0
  29. package/dist/business-baggage.d.ts +106 -139
  30. package/dist/business-baggage.d.ts.map +1 -0
  31. package/dist/business-baggage.js +357 -2
  32. package/dist/business-baggage.js.map +1 -1
  33. package/dist/canonical-log-line-processor--RlFDHhm.cjs +377 -0
  34. package/dist/canonical-log-line-processor--RlFDHhm.cjs.map +1 -0
  35. package/dist/canonical-log-line-processor-BcRuAdRk.d.ts +147 -0
  36. package/dist/canonical-log-line-processor-BcRuAdRk.d.ts.map +1 -0
  37. package/dist/canonical-log-line-processor-DbBQT5vY.js +366 -0
  38. package/dist/canonical-log-line-processor-DbBQT5vY.js.map +1 -0
  39. package/dist/canonical-log-line-processor-xvjMgtpF.d.cts +147 -0
  40. package/dist/canonical-log-line-processor-xvjMgtpF.d.cts.map +1 -0
  41. package/dist/config.cjs +118 -22
  42. package/dist/config.cjs.map +1 -1
  43. package/dist/config.d.cts +33 -45
  44. package/dist/config.d.cts.map +1 -0
  45. package/dist/config.d.ts +33 -45
  46. package/dist/config.d.ts.map +1 -0
  47. package/dist/config.js +116 -3
  48. package/dist/config.js.map +1 -1
  49. package/dist/correlated-events-Bzh5y-UB.js +28 -0
  50. package/dist/correlated-events-Bzh5y-UB.js.map +1 -0
  51. package/dist/correlated-events-kSwLo3mi.cjs +34 -0
  52. package/dist/correlated-events-kSwLo3mi.cjs.map +1 -0
  53. package/dist/correlation-id.cjs +11 -54
  54. package/dist/correlation-id.d.cts +6 -5
  55. package/dist/correlation-id.d.cts.map +1 -0
  56. package/dist/correlation-id.d.ts +6 -5
  57. package/dist/correlation-id.d.ts.map +1 -0
  58. package/dist/correlation-id.js +3 -17
  59. package/dist/db.cjs +244 -209
  60. package/dist/db.cjs.map +1 -1
  61. package/dist/db.d.cts +28 -26
  62. package/dist/db.d.cts.map +1 -0
  63. package/dist/db.d.ts +28 -26
  64. package/dist/db.d.ts.map +1 -0
  65. package/dist/db.js +243 -207
  66. package/dist/db.js.map +1 -1
  67. package/dist/decorators.cjs +39 -66
  68. package/dist/decorators.cjs.map +1 -1
  69. package/dist/decorators.d.cts +10 -37
  70. package/dist/decorators.d.cts.map +1 -0
  71. package/dist/decorators.d.ts +10 -37
  72. package/dist/decorators.d.ts.map +1 -0
  73. package/dist/decorators.js +38 -64
  74. package/dist/decorators.js.map +1 -1
  75. package/dist/define-event-CreknLm3.d.ts +25 -0
  76. package/dist/define-event-CreknLm3.d.ts.map +1 -0
  77. package/dist/define-event-HZRizPwz.d.cts +25 -0
  78. package/dist/define-event-HZRizPwz.d.cts.map +1 -0
  79. package/dist/drain-pipeline.cjs +111 -9
  80. package/dist/drain-pipeline.cjs.map +1 -1
  81. package/dist/drain-pipeline.d.cts +27 -32
  82. package/dist/drain-pipeline.d.cts.map +1 -0
  83. package/dist/drain-pipeline.d.ts +27 -32
  84. package/dist/drain-pipeline.d.ts.map +1 -0
  85. package/dist/drain-pipeline.js +111 -2
  86. package/dist/drain-pipeline.js.map +1 -1
  87. package/dist/enrichers.cjs +59 -66
  88. package/dist/enrichers.cjs.map +1 -1
  89. package/dist/enrichers.d.cts +15 -13
  90. package/dist/enrichers.d.cts.map +1 -0
  91. package/dist/enrichers.d.ts +15 -13
  92. package/dist/enrichers.d.ts.map +1 -0
  93. package/dist/enrichers.js +58 -65
  94. package/dist/enrichers.js.map +1 -1
  95. package/dist/event-Dlqr4ZNL.cjs +778 -0
  96. package/dist/event-Dlqr4ZNL.cjs.map +1 -0
  97. package/dist/event-_58ryBjh.js +761 -0
  98. package/dist/event-_58ryBjh.js.map +1 -0
  99. package/dist/event-subscriber-D1XLkPzi.d.cts +223 -0
  100. package/dist/event-subscriber-D1XLkPzi.d.cts.map +1 -0
  101. package/dist/event-subscriber-D1XLkPzi.d.ts +223 -0
  102. package/dist/event-subscriber-D1XLkPzi.d.ts.map +1 -0
  103. package/dist/event-subscriber.cjs +0 -6
  104. package/dist/event-subscriber.d.cts +2 -221
  105. package/dist/event-subscriber.d.ts +2 -221
  106. package/dist/event-subscriber.js +1 -3
  107. package/dist/event-testing-BqRnI0z4.d.cts +106 -0
  108. package/dist/event-testing-BqRnI0z4.d.cts.map +1 -0
  109. package/dist/event-testing-CfFs3to2.d.ts +106 -0
  110. package/dist/event-testing-CfFs3to2.d.ts.map +1 -0
  111. package/dist/event-testing.cjs +93 -17
  112. package/dist/event-testing.cjs.map +1 -1
  113. package/dist/event-testing.d.cts +2 -110
  114. package/dist/event-testing.d.ts +2 -110
  115. package/dist/event-testing.js +91 -2
  116. package/dist/event-testing.js.map +1 -1
  117. package/dist/event.cjs +5 -37
  118. package/dist/event.d.cts +295 -340
  119. package/dist/event.d.cts.map +1 -0
  120. package/dist/event.d.ts +295 -340
  121. package/dist/event.d.ts.map +1 -0
  122. package/dist/event.js +3 -21
  123. package/dist/exporters.cjs +12 -16
  124. package/dist/exporters.d.cts +86 -111
  125. package/dist/exporters.d.cts.map +1 -0
  126. package/dist/exporters.d.ts +86 -111
  127. package/dist/exporters.d.ts.map +1 -0
  128. package/dist/exporters.js +4 -4
  129. package/dist/filtering-span-processor-B8R8B7Uk.d.cts +59 -0
  130. package/dist/filtering-span-processor-B8R8B7Uk.d.cts.map +1 -0
  131. package/dist/filtering-span-processor-B8R8B7Uk.d.ts +59 -0
  132. package/dist/filtering-span-processor-B8R8B7Uk.d.ts.map +1 -0
  133. package/dist/filtering-span-processor.cjs +49 -9
  134. package/dist/filtering-span-processor.cjs.map +1 -1
  135. package/dist/filtering-span-processor.d.cts +2 -80
  136. package/dist/filtering-span-processor.d.ts +2 -80
  137. package/dist/filtering-span-processor.js +49 -2
  138. package/dist/filtering-span-processor.js.map +1 -1
  139. package/dist/functional-BGkT8J-h.js +1265 -0
  140. package/dist/functional-BGkT8J-h.js.map +1 -0
  141. package/dist/functional-C4CzoVrX.cjs +1312 -0
  142. package/dist/functional-C4CzoVrX.cjs.map +1 -0
  143. package/dist/functional.cjs +11 -57
  144. package/dist/functional.d.cts +96 -97
  145. package/dist/functional.d.cts.map +1 -0
  146. package/dist/functional.d.ts +96 -97
  147. package/dist/functional.d.ts.map +1 -0
  148. package/dist/functional.js +3 -20
  149. package/dist/http.cjs +276 -176
  150. package/dist/http.cjs.map +1 -1
  151. package/dist/http.d.cts +17 -37
  152. package/dist/http.d.cts.map +1 -0
  153. package/dist/http.d.ts +17 -37
  154. package/dist/http.d.ts.map +1 -0
  155. package/dist/http.js +275 -174
  156. package/dist/http.js.map +1 -1
  157. package/dist/index-Ck06vlW2.d.ts +678 -0
  158. package/dist/index-Ck06vlW2.d.ts.map +1 -0
  159. package/dist/index-eKuioqT1.d.cts +678 -0
  160. package/dist/index-eKuioqT1.d.cts.map +1 -0
  161. package/dist/index.cjs +751 -1218
  162. package/dist/index.cjs.map +1 -1
  163. package/dist/index.d.cts +341 -659
  164. package/dist/index.d.cts.map +1 -0
  165. package/dist/index.d.ts +341 -659
  166. package/dist/index.d.ts.map +1 -0
  167. package/dist/index.js +606 -737
  168. package/dist/index.js.map +1 -1
  169. package/dist/init-CNp-ee80.d.cts +1157 -0
  170. package/dist/init-CNp-ee80.d.cts.map +1 -0
  171. package/dist/init-Ch6t7MNI.js +1015 -0
  172. package/dist/init-Ch6t7MNI.js.map +1 -0
  173. package/dist/init-DJQOdVlN.d.ts +1157 -0
  174. package/dist/init-DJQOdVlN.d.ts.map +1 -0
  175. package/dist/init-DvapOXCc.cjs +1092 -0
  176. package/dist/init-DvapOXCc.cjs.map +1 -0
  177. package/dist/instrumentation.cjs +159 -185
  178. package/dist/instrumentation.cjs.map +1 -1
  179. package/dist/instrumentation.d.cts +42 -40
  180. package/dist/instrumentation.d.cts.map +1 -0
  181. package/dist/instrumentation.d.ts +42 -40
  182. package/dist/instrumentation.d.ts.map +1 -0
  183. package/dist/instrumentation.js +158 -183
  184. package/dist/instrumentation.js.map +1 -1
  185. package/dist/logger-BauSUhUv.d.cts +313 -0
  186. package/dist/logger-BauSUhUv.d.cts.map +1 -0
  187. package/dist/logger-BauSUhUv.d.ts +313 -0
  188. package/dist/logger-BauSUhUv.d.ts.map +1 -0
  189. package/dist/logger.cjs +225 -25
  190. package/dist/logger.cjs.map +1 -1
  191. package/dist/logger.d.cts +2 -348
  192. package/dist/logger.d.ts +2 -348
  193. package/dist/logger.js +204 -4
  194. package/dist/logger.js.map +1 -1
  195. package/dist/messaging-adapters.cjs +292 -187
  196. package/dist/messaging-adapters.cjs.map +1 -1
  197. package/dist/messaging-adapters.d.cts +28 -66
  198. package/dist/messaging-adapters.d.cts.map +1 -0
  199. package/dist/messaging-adapters.d.ts +28 -66
  200. package/dist/messaging-adapters.d.ts.map +1 -0
  201. package/dist/messaging-adapters.js +291 -185
  202. package/dist/messaging-adapters.js.map +1 -1
  203. package/dist/messaging-testing.cjs +306 -372
  204. package/dist/messaging-testing.cjs.map +1 -1
  205. package/dist/messaging-testing.d.cts +194 -223
  206. package/dist/messaging-testing.d.cts.map +1 -0
  207. package/dist/messaging-testing.d.ts +194 -223
  208. package/dist/messaging-testing.d.ts.map +1 -0
  209. package/dist/messaging-testing.js +305 -371
  210. package/dist/messaging-testing.js.map +1 -1
  211. package/dist/messaging.cjs +757 -36
  212. package/dist/messaging.cjs.map +1 -1
  213. package/dist/messaging.d.cts +603 -644
  214. package/dist/messaging.d.cts.map +1 -0
  215. package/dist/messaging.d.ts +603 -644
  216. package/dist/messaging.d.ts.map +1 -0
  217. package/dist/messaging.js +756 -21
  218. package/dist/messaging.js.map +1 -1
  219. package/dist/metric-helpers.cjs +27 -27
  220. package/dist/metric-helpers.cjs.map +1 -1
  221. package/dist/metric-helpers.d.cts +4 -2
  222. package/dist/metric-helpers.d.cts.map +1 -0
  223. package/dist/metric-helpers.d.ts +4 -2
  224. package/dist/metric-helpers.d.ts.map +1 -0
  225. package/dist/metric-helpers.js +24 -4
  226. package/dist/metric-helpers.js.map +1 -1
  227. package/dist/metric-testing-DXdK3-Q3.d.ts +106 -0
  228. package/dist/metric-testing-DXdK3-Q3.d.ts.map +1 -0
  229. package/dist/metric-testing-MxvzChDp.d.cts +106 -0
  230. package/dist/metric-testing-MxvzChDp.d.cts.map +1 -0
  231. package/dist/metric-testing.cjs +93 -17
  232. package/dist/metric-testing.cjs.map +1 -1
  233. package/dist/metric-testing.d.cts +2 -110
  234. package/dist/metric-testing.d.ts +2 -110
  235. package/dist/metric-testing.js +91 -2
  236. package/dist/metric-testing.js.map +1 -1
  237. package/dist/metric.cjs +306 -22
  238. package/dist/metric.cjs.map +1 -1
  239. package/dist/metric.d.cts +170 -198
  240. package/dist/metric.d.cts.map +1 -0
  241. package/dist/metric.d.ts +170 -198
  242. package/dist/metric.d.ts.map +1 -0
  243. package/dist/metric.js +277 -7
  244. package/dist/metric.js.map +1 -1
  245. package/dist/node-require-DF5QBX6z.cjs +99 -0
  246. package/dist/node-require-DF5QBX6z.cjs.map +1 -0
  247. package/dist/node-require-Db1oDpLj.js +88 -0
  248. package/dist/node-require-Db1oDpLj.js.map +1 -0
  249. package/dist/operation-context-C-2hmmtP.js +59 -0
  250. package/dist/operation-context-C-2hmmtP.js.map +1 -0
  251. package/dist/operation-context-n4_obUwq.cjs +70 -0
  252. package/dist/operation-context-n4_obUwq.cjs.map +1 -0
  253. package/dist/parse-error.cjs +55 -9
  254. package/dist/parse-error.cjs.map +1 -1
  255. package/dist/parse-error.d.cts +12 -10
  256. package/dist/parse-error.d.cts.map +1 -0
  257. package/dist/parse-error.d.ts +12 -10
  258. package/dist/parse-error.d.ts.map +1 -0
  259. package/dist/parse-error.js +55 -2
  260. package/dist/parse-error.js.map +1 -1
  261. package/dist/pretty-console-exporter-CMzlrRNg.cjs +232 -0
  262. package/dist/pretty-console-exporter-CMzlrRNg.cjs.map +1 -0
  263. package/dist/pretty-console-exporter-DqKl_q9z.js +227 -0
  264. package/dist/pretty-console-exporter-DqKl_q9z.js.map +1 -0
  265. package/dist/processors.cjs +13 -17
  266. package/dist/processors.d.cts +3 -171
  267. package/dist/processors.d.ts +3 -171
  268. package/dist/processors.js +4 -4
  269. package/dist/register.cjs +35 -6
  270. package/dist/register.cjs.map +1 -1
  271. package/dist/register.d.cts +1 -2
  272. package/dist/register.d.ts +1 -2
  273. package/dist/register.js +36 -3
  274. package/dist/register.js.map +1 -1
  275. package/dist/registry-DVSmWg6Y.js +175 -0
  276. package/dist/registry-DVSmWg6Y.js.map +1 -0
  277. package/dist/registry-DYgvb62e.cjs +319 -0
  278. package/dist/registry-DYgvb62e.cjs.map +1 -0
  279. package/dist/sampling-CR0Va1VB.d.ts +351 -0
  280. package/dist/sampling-CR0Va1VB.d.ts.map +1 -0
  281. package/dist/sampling-DfYhDJij.d.cts +351 -0
  282. package/dist/sampling-DfYhDJij.d.cts.map +1 -0
  283. package/dist/sampling.cjs +452 -60
  284. package/dist/sampling.cjs.map +1 -1
  285. package/dist/sampling.d.cts +2 -379
  286. package/dist/sampling.d.ts +2 -379
  287. package/dist/sampling.js +441 -5
  288. package/dist/sampling.js.map +1 -1
  289. package/dist/security-schema.cjs +65 -46
  290. package/dist/security-schema.cjs.map +1 -1
  291. package/dist/security-schema.d.cts +23 -26
  292. package/dist/security-schema.d.cts.map +1 -0
  293. package/dist/security-schema.d.ts +23 -26
  294. package/dist/security-schema.d.ts.map +1 -0
  295. package/dist/security-schema.js +64 -45
  296. package/dist/security-schema.js.map +1 -1
  297. package/dist/semantic-conventions-FhSxv-bK.d.cts +32 -0
  298. package/dist/semantic-conventions-FhSxv-bK.d.cts.map +1 -0
  299. package/dist/semantic-conventions-FhSxv-bK.d.ts +32 -0
  300. package/dist/semantic-conventions-FhSxv-bK.d.ts.map +1 -0
  301. package/dist/semantic-conventions.cjs +15 -26
  302. package/dist/semantic-conventions.cjs.map +1 -1
  303. package/dist/semantic-conventions.d.cts +2 -29
  304. package/dist/semantic-conventions.d.ts +2 -29
  305. package/dist/semantic-conventions.js +12 -3
  306. package/dist/semantic-conventions.js.map +1 -1
  307. package/dist/semantic-helpers.cjs +327 -39
  308. package/dist/semantic-helpers.cjs.map +1 -1
  309. package/dist/semantic-helpers.d.cts +30 -150
  310. package/dist/semantic-helpers.d.cts.map +1 -0
  311. package/dist/semantic-helpers.d.ts +30 -150
  312. package/dist/semantic-helpers.d.ts.map +1 -0
  313. package/dist/semantic-helpers.js +326 -20
  314. package/dist/semantic-helpers.js.map +1 -1
  315. package/dist/span-name-normalizer-8ZOGJuwv.d.cts +70 -0
  316. package/dist/span-name-normalizer-8ZOGJuwv.d.cts.map +1 -0
  317. package/dist/span-name-normalizer-8ZOGJuwv.d.ts +70 -0
  318. package/dist/span-name-normalizer-8ZOGJuwv.d.ts.map +1 -0
  319. package/dist/span-name-normalizer.cjs +95 -17
  320. package/dist/span-name-normalizer.cjs.map +1 -1
  321. package/dist/span-name-normalizer.d.cts +2 -94
  322. package/dist/span-name-normalizer.d.ts +2 -94
  323. package/dist/span-name-normalizer.js +93 -2
  324. package/dist/span-name-normalizer.js.map +1 -1
  325. package/dist/stable-hash-BNTMrmdB.cjs +28 -0
  326. package/dist/stable-hash-BNTMrmdB.cjs.map +1 -0
  327. package/dist/stable-hash-Cg5cT34Q.js +23 -0
  328. package/dist/stable-hash-Cg5cT34Q.js.map +1 -0
  329. package/dist/structured-error-9--cxBay.js +143 -0
  330. package/dist/structured-error-9--cxBay.js.map +1 -0
  331. package/dist/structured-error-CHg7DoIQ.cjs +178 -0
  332. package/dist/structured-error-CHg7DoIQ.cjs.map +1 -0
  333. package/dist/tail-sampling-processor.cjs +26 -13
  334. package/dist/tail-sampling-processor.cjs.map +1 -1
  335. package/dist/tail-sampling-processor.d.cts +11 -23
  336. package/dist/tail-sampling-processor.d.cts.map +1 -0
  337. package/dist/tail-sampling-processor.d.ts +11 -23
  338. package/dist/tail-sampling-processor.d.ts.map +1 -0
  339. package/dist/tail-sampling-processor.js +27 -6
  340. package/dist/tail-sampling-processor.js.map +1 -1
  341. package/dist/test-span-collector.cjs +70 -72
  342. package/dist/test-span-collector.cjs.map +1 -1
  343. package/dist/test-span-collector.d.cts +25 -43
  344. package/dist/test-span-collector.d.cts.map +1 -0
  345. package/dist/test-span-collector.d.ts +25 -43
  346. package/dist/test-span-collector.d.ts.map +1 -0
  347. package/dist/test-span-collector.js +69 -70
  348. package/dist/test-span-collector.js.map +1 -1
  349. package/dist/testing.cjs +389 -278
  350. package/dist/testing.cjs.map +1 -1
  351. package/dist/testing.d.cts +39 -62
  352. package/dist/testing.d.cts.map +1 -0
  353. package/dist/testing.d.ts +39 -62
  354. package/dist/testing.d.ts.map +1 -0
  355. package/dist/testing.js +386 -265
  356. package/dist/testing.js.map +1 -1
  357. package/dist/trace-context-Cijqoi6e.d.cts +212 -0
  358. package/dist/trace-context-Cijqoi6e.d.cts.map +1 -0
  359. package/dist/trace-context-Cijqoi6e.d.ts +212 -0
  360. package/dist/trace-context-Cijqoi6e.d.ts.map +1 -0
  361. package/dist/trace-helpers.cjs +634 -54
  362. package/dist/trace-helpers.cjs.map +1 -1
  363. package/dist/trace-helpers.d.cts +17 -49
  364. package/dist/trace-helpers.d.cts.map +1 -0
  365. package/dist/trace-helpers.d.ts +17 -49
  366. package/dist/trace-helpers.d.ts.map +1 -0
  367. package/dist/trace-helpers.js +624 -3
  368. package/dist/trace-helpers.js.map +1 -1
  369. package/dist/tracer-provider.cjs +227 -16
  370. package/dist/tracer-provider.cjs.map +1 -1
  371. package/dist/tracer-provider.d.cts +5 -4
  372. package/dist/tracer-provider.d.cts.map +1 -0
  373. package/dist/tracer-provider.d.ts +5 -4
  374. package/dist/tracer-provider.d.ts.map +1 -0
  375. package/dist/tracer-provider.js +227 -2
  376. package/dist/tracer-provider.js.map +1 -1
  377. package/dist/track-3HY4NGV-.cjs +1212 -0
  378. package/dist/track-3HY4NGV-.cjs.map +1 -0
  379. package/dist/track-nsKVy-pj.js +1111 -0
  380. package/dist/track-nsKVy-pj.js.map +1 -0
  381. package/dist/validate.cjs +178 -115
  382. package/dist/validate.cjs.map +1 -1
  383. package/dist/validate.d.cts +40 -64
  384. package/dist/validate.d.cts.map +1 -0
  385. package/dist/validate.d.ts +40 -64
  386. package/dist/validate.d.ts.map +1 -0
  387. package/dist/validate.js +177 -113
  388. package/dist/validate.js.map +1 -1
  389. package/dist/validation-attributes.cjs +42 -17
  390. package/dist/validation-attributes.cjs.map +1 -1
  391. package/dist/validation-attributes.d.cts +13 -20
  392. package/dist/validation-attributes.d.cts.map +1 -0
  393. package/dist/validation-attributes.d.ts +13 -20
  394. package/dist/validation-attributes.d.ts.map +1 -0
  395. package/dist/validation-attributes.js +40 -2
  396. package/dist/validation-attributes.js.map +1 -1
  397. package/dist/webhook.cjs +286 -256
  398. package/dist/webhook.cjs.map +1 -1
  399. package/dist/webhook.d.cts +157 -192
  400. package/dist/webhook.d.cts.map +1 -0
  401. package/dist/webhook.d.ts +157 -192
  402. package/dist/webhook.d.ts.map +1 -0
  403. package/dist/webhook.js +285 -254
  404. package/dist/webhook.js.map +1 -1
  405. package/dist/workflow-distributed.cjs +498 -412
  406. package/dist/workflow-distributed.cjs.map +1 -1
  407. package/dist/workflow-distributed.d.cts +163 -173
  408. package/dist/workflow-distributed.d.cts.map +1 -0
  409. package/dist/workflow-distributed.d.ts +163 -173
  410. package/dist/workflow-distributed.d.ts.map +1 -0
  411. package/dist/workflow-distributed.js +497 -410
  412. package/dist/workflow-distributed.js.map +1 -1
  413. package/dist/workflow.cjs +405 -40
  414. package/dist/workflow.cjs.map +1 -1
  415. package/dist/workflow.d.cts +78 -131
  416. package/dist/workflow.d.cts.map +1 -0
  417. package/dist/workflow.d.ts +78 -131
  418. package/dist/workflow.d.ts.map +1 -0
  419. package/dist/workflow.js +403 -21
  420. package/dist/workflow.js.map +1 -1
  421. package/dist/yaml-config-B3dQ82GR.cjs +272 -0
  422. package/dist/yaml-config-B3dQ82GR.cjs.map +1 -0
  423. package/dist/yaml-config.cjs +5 -24
  424. package/dist/yaml-config.d.cts +30 -64
  425. package/dist/yaml-config.d.cts.map +1 -0
  426. package/dist/yaml-config.d.ts +30 -64
  427. package/dist/yaml-config.d.ts.map +1 -0
  428. package/dist/yaml-config.js +226 -7
  429. package/dist/yaml-config.js.map +1 -1
  430. package/package.json +4 -4
  431. package/skills/analyze-traces/SKILL.md +14 -12
  432. package/skills/review-otel-patterns/SKILL.md +4 -2
  433. package/skills/tune-sampling/SKILL.md +8 -3
  434. package/src/attributes/builders.ts +2 -20
  435. package/src/attributes/index.ts +0 -1
  436. package/src/attributes/registry.ts +2 -9
  437. package/src/attributes/types.ts +0 -8
  438. package/src/index.ts +7 -41
  439. package/src/request-logger.test.ts +53 -1
  440. package/src/request-logger.ts +58 -0
  441. package/src/semantic-helpers.test.ts +2 -87
  442. package/src/semantic-helpers.ts +0 -146
  443. package/src/validate.test.ts +3 -1
  444. package/src/validate.ts +9 -3
  445. package/dist/attributes.cjs.map +0 -1
  446. package/dist/attributes.js.map +0 -1
  447. package/dist/chunk-2ZKEORFN.cjs +0 -14
  448. package/dist/chunk-2ZKEORFN.cjs.map +0 -1
  449. package/dist/chunk-3QXBFGKP.js +0 -344
  450. package/dist/chunk-3QXBFGKP.js.map +0 -1
  451. package/dist/chunk-454CH4OV.js +0 -744
  452. package/dist/chunk-454CH4OV.js.map +0 -1
  453. package/dist/chunk-4A53YIAX.js +0 -180
  454. package/dist/chunk-4A53YIAX.js.map +0 -1
  455. package/dist/chunk-4IFSYQVX.js +0 -337
  456. package/dist/chunk-4IFSYQVX.js.map +0 -1
  457. package/dist/chunk-4P6ZOARG.cjs +0 -33
  458. package/dist/chunk-4P6ZOARG.cjs.map +0 -1
  459. package/dist/chunk-55ER2KD5.js +0 -228
  460. package/dist/chunk-55ER2KD5.js.map +0 -1
  461. package/dist/chunk-5ZN622AO.js +0 -73
  462. package/dist/chunk-5ZN622AO.js.map +0 -1
  463. package/dist/chunk-66YJ66GG.js +0 -1021
  464. package/dist/chunk-66YJ66GG.js.map +0 -1
  465. package/dist/chunk-6S5RUKU3.cjs +0 -347
  466. package/dist/chunk-6S5RUKU3.cjs.map +0 -1
  467. package/dist/chunk-6UQRVUN3.js +0 -222
  468. package/dist/chunk-6UQRVUN3.js.map +0 -1
  469. package/dist/chunk-7552UTQW.js +0 -11
  470. package/dist/chunk-7552UTQW.js.map +0 -1
  471. package/dist/chunk-7EQ4G4SI.cjs +0 -146
  472. package/dist/chunk-7EQ4G4SI.cjs.map +0 -1
  473. package/dist/chunk-7SAWIN74.js +0 -285
  474. package/dist/chunk-7SAWIN74.js.map +0 -1
  475. package/dist/chunk-A4E5AQFK.js +0 -30
  476. package/dist/chunk-A4E5AQFK.js.map +0 -1
  477. package/dist/chunk-ALPYR2GC.js +0 -1061
  478. package/dist/chunk-ALPYR2GC.js.map +0 -1
  479. package/dist/chunk-B7SWBE4P.cjs +0 -799
  480. package/dist/chunk-B7SWBE4P.cjs.map +0 -1
  481. package/dist/chunk-BZHG5IZ4.js +0 -73
  482. package/dist/chunk-BZHG5IZ4.js.map +0 -1
  483. package/dist/chunk-CEAQK2QY.cjs +0 -32
  484. package/dist/chunk-CEAQK2QY.cjs.map +0 -1
  485. package/dist/chunk-CMHVQR6P.js +0 -170
  486. package/dist/chunk-CMHVQR6P.js.map +0 -1
  487. package/dist/chunk-CU6IDACR.cjs +0 -224
  488. package/dist/chunk-CU6IDACR.cjs.map +0 -1
  489. package/dist/chunk-D4TM63S3.js +0 -795
  490. package/dist/chunk-D4TM63S3.js.map +0 -1
  491. package/dist/chunk-DCEDJQGG.js +0 -28
  492. package/dist/chunk-DCEDJQGG.js.map +0 -1
  493. package/dist/chunk-DPSA4QLA.js +0 -344
  494. package/dist/chunk-DPSA4QLA.js.map +0 -1
  495. package/dist/chunk-E6TERL5O.cjs +0 -23
  496. package/dist/chunk-E6TERL5O.cjs.map +0 -1
  497. package/dist/chunk-EE6CPXKH.cjs +0 -164
  498. package/dist/chunk-EE6CPXKH.cjs.map +0 -1
  499. package/dist/chunk-EOFB7XCL.cjs +0 -837
  500. package/dist/chunk-EOFB7XCL.cjs.map +0 -1
  501. package/dist/chunk-ESLWRGAG.cjs +0 -92
  502. package/dist/chunk-ESLWRGAG.cjs.map +0 -1
  503. package/dist/chunk-ESMHTKLJ.cjs +0 -206
  504. package/dist/chunk-ESMHTKLJ.cjs.map +0 -1
  505. package/dist/chunk-FMTHVSYY.cjs +0 -1039
  506. package/dist/chunk-FMTHVSYY.cjs.map +0 -1
  507. package/dist/chunk-FU6R566Y.cjs +0 -236
  508. package/dist/chunk-FU6R566Y.cjs.map +0 -1
  509. package/dist/chunk-GYR5K654.js +0 -91
  510. package/dist/chunk-GYR5K654.js.map +0 -1
  511. package/dist/chunk-HA2WBOGQ.js +0 -57
  512. package/dist/chunk-HA2WBOGQ.js.map +0 -1
  513. package/dist/chunk-HT5JQKN2.js +0 -118
  514. package/dist/chunk-HT5JQKN2.js.map +0 -1
  515. package/dist/chunk-INJD3G4K.cjs +0 -340
  516. package/dist/chunk-INJD3G4K.cjs.map +0 -1
  517. package/dist/chunk-IOYFAFHJ.cjs +0 -95
  518. package/dist/chunk-IOYFAFHJ.cjs.map +0 -1
  519. package/dist/chunk-J5QENANM.js +0 -87
  520. package/dist/chunk-J5QENANM.js.map +0 -1
  521. package/dist/chunk-J7VGRIAJ.js +0 -64
  522. package/dist/chunk-J7VGRIAJ.js.map +0 -1
  523. package/dist/chunk-KFOHQK7X.js +0 -144
  524. package/dist/chunk-KFOHQK7X.js.map +0 -1
  525. package/dist/chunk-KIL5CUN6.js +0 -31
  526. package/dist/chunk-KIL5CUN6.js.map +0 -1
  527. package/dist/chunk-KYXZS3EA.cjs +0 -100
  528. package/dist/chunk-KYXZS3EA.cjs.map +0 -1
  529. package/dist/chunk-LITNXTTT.js +0 -3
  530. package/dist/chunk-LITNXTTT.js.map +0 -1
  531. package/dist/chunk-LVIPBYFE.js +0 -157
  532. package/dist/chunk-LVIPBYFE.js.map +0 -1
  533. package/dist/chunk-M3LFHHTN.cjs +0 -764
  534. package/dist/chunk-M3LFHHTN.cjs.map +0 -1
  535. package/dist/chunk-N25JDZSC.js +0 -95
  536. package/dist/chunk-N25JDZSC.js.map +0 -1
  537. package/dist/chunk-NEIB3TLD.cjs +0 -360
  538. package/dist/chunk-NEIB3TLD.cjs.map +0 -1
  539. package/dist/chunk-NENU7E6V.cjs +0 -344
  540. package/dist/chunk-NENU7E6V.cjs.map +0 -1
  541. package/dist/chunk-NVAI5CCN.cjs +0 -39
  542. package/dist/chunk-NVAI5CCN.cjs.map +0 -1
  543. package/dist/chunk-NZ72VDNY.cjs +0 -4
  544. package/dist/chunk-NZ72VDNY.cjs.map +0 -1
  545. package/dist/chunk-OPPXYVEZ.cjs +0 -131
  546. package/dist/chunk-OPPXYVEZ.cjs.map +0 -1
  547. package/dist/chunk-Q4EULJQY.js +0 -35
  548. package/dist/chunk-Q4EULJQY.js.map +0 -1
  549. package/dist/chunk-QF7ARNUM.js +0 -339
  550. package/dist/chunk-QF7ARNUM.js.map +0 -1
  551. package/dist/chunk-QWW3E3JM.cjs +0 -178
  552. package/dist/chunk-QWW3E3JM.cjs.map +0 -1
  553. package/dist/chunk-R7QYGZUP.cjs +0 -1075
  554. package/dist/chunk-R7QYGZUP.cjs.map +0 -1
  555. package/dist/chunk-RUPKBKUF.js +0 -352
  556. package/dist/chunk-RUPKBKUF.js.map +0 -1
  557. package/dist/chunk-SEO6NAQT.js +0 -14
  558. package/dist/chunk-SEO6NAQT.js.map +0 -1
  559. package/dist/chunk-T4B5LB6E.cjs +0 -66
  560. package/dist/chunk-T4B5LB6E.cjs.map +0 -1
  561. package/dist/chunk-T5WRA76K.cjs +0 -32
  562. package/dist/chunk-T5WRA76K.cjs.map +0 -1
  563. package/dist/chunk-T7JO2TCP.js +0 -1233
  564. package/dist/chunk-T7JO2TCP.js.map +0 -1
  565. package/dist/chunk-TC5ZPWM4.cjs +0 -289
  566. package/dist/chunk-TC5ZPWM4.cjs.map +0 -1
  567. package/dist/chunk-TQ5UWA7S.js +0 -26
  568. package/dist/chunk-TQ5UWA7S.js.map +0 -1
  569. package/dist/chunk-UIKYE2QZ.js +0 -833
  570. package/dist/chunk-UIKYE2QZ.js.map +0 -1
  571. package/dist/chunk-UNPLAVE7.js +0 -21
  572. package/dist/chunk-UNPLAVE7.js.map +0 -1
  573. package/dist/chunk-UY3UYPBZ.cjs +0 -77
  574. package/dist/chunk-UY3UYPBZ.cjs.map +0 -1
  575. package/dist/chunk-V7UBMJAB.cjs +0 -1242
  576. package/dist/chunk-V7UBMJAB.cjs.map +0 -1
  577. package/dist/chunk-VH77IPJN.cjs +0 -358
  578. package/dist/chunk-VH77IPJN.cjs.map +0 -1
  579. package/dist/chunk-VQTCQKHQ.cjs +0 -17
  580. package/dist/chunk-VQTCQKHQ.cjs.map +0 -1
  581. package/dist/chunk-WGWSHJ2N.js +0 -38
  582. package/dist/chunk-WGWSHJ2N.js.map +0 -1
  583. package/dist/chunk-WJH6IYU2.cjs +0 -32
  584. package/dist/chunk-WJH6IYU2.cjs.map +0 -1
  585. package/dist/chunk-YREV3LGG.cjs +0 -61
  586. package/dist/chunk-YREV3LGG.cjs.map +0 -1
  587. package/dist/chunk-YTXEZ4SD.cjs +0 -77
  588. package/dist/chunk-YTXEZ4SD.cjs.map +0 -1
  589. package/dist/chunk-ZNMBW67B.cjs +0 -40
  590. package/dist/chunk-ZNMBW67B.cjs.map +0 -1
  591. package/dist/correlation-id.cjs.map +0 -1
  592. package/dist/correlation-id.js.map +0 -1
  593. package/dist/define-event-BL6Li7CM.d.ts +0 -23
  594. package/dist/define-event-ClP3T1Jx.d.cts +0 -23
  595. package/dist/event-subscriber.cjs.map +0 -1
  596. package/dist/event-subscriber.js.map +0 -1
  597. package/dist/event.cjs.map +0 -1
  598. package/dist/event.js.map +0 -1
  599. package/dist/exporters.cjs.map +0 -1
  600. package/dist/exporters.js.map +0 -1
  601. package/dist/functional.cjs.map +0 -1
  602. package/dist/functional.js.map +0 -1
  603. package/dist/init-DIowiiCh.d.ts +0 -1167
  604. package/dist/init-j-A1zI16.d.cts +0 -1167
  605. package/dist/processors.cjs.map +0 -1
  606. package/dist/processors.js.map +0 -1
  607. package/dist/trace-context-DbGKd1Rn.d.cts +0 -213
  608. package/dist/trace-context-DbGKd1Rn.d.ts +0 -213
  609. package/dist/utils-BahBCFtJ.d.cts +0 -712
  610. package/dist/utils-CLKwaUlG.d.ts +0 -712
  611. package/dist/yaml-config.cjs.map +0 -1
  612. package/src/gen-ai-cost.test.ts +0 -81
  613. package/src/gen-ai-cost.ts +0 -145
  614. package/src/gen-ai-events.test.ts +0 -135
  615. package/src/gen-ai-events.ts +0 -208
  616. package/src/gen-ai-metrics.test.ts +0 -96
  617. package/src/gen-ai-metrics.ts +0 -128
@@ -1,81 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import {
3
- estimateLLMCost,
4
- recordLLMCost,
5
- GEN_AI_COST_ATTRIBUTE,
6
- } from './gen-ai-cost';
7
-
8
- describe('estimateLLMCost', () => {
9
- it('estimates cost from input and output tokens', () => {
10
- // claude-sonnet-4: $3 / 1M in, $15 / 1M out
11
- const cost = estimateLLMCost('claude-sonnet-4', {
12
- inputTokens: 1_000_000,
13
- outputTokens: 1_000_000,
14
- });
15
- expect(cost).toBe(18);
16
- });
17
-
18
- it('matches versioned model ids by longest prefix', () => {
19
- const cost = estimateLLMCost('claude-sonnet-4-6-20251101', {
20
- inputTokens: 1_000_000,
21
- outputTokens: 0,
22
- });
23
- expect(cost).toBe(3);
24
- });
25
-
26
- it('returns undefined for an unknown model', () => {
27
- expect(
28
- estimateLLMCost('totally-made-up', { inputTokens: 1000 }),
29
- ).toBeUndefined();
30
- });
31
-
32
- it('bills cached input tokens at the cached rate', () => {
33
- const pricing = {
34
- custom: { inputPer1M: 10, outputPer1M: 30, cachedInputPer1M: 1 },
35
- };
36
- // 1M input, of which 800k cached: 200k @ $10/M + 800k @ $1/M = 2 + 0.8
37
- const cost = estimateLLMCost(
38
- 'custom',
39
- { inputTokens: 1_000_000, cachedInputTokens: 800_000 },
40
- { pricing },
41
- );
42
- expect(cost).toBeCloseTo(2.8, 6);
43
- });
44
-
45
- it('accepts a pricing override and extends the table', () => {
46
- const cost = estimateLLMCost(
47
- 'my-model',
48
- { inputTokens: 500_000, outputTokens: 500_000 },
49
- { pricing: { 'my-model': { inputPer1M: 4, outputPer1M: 8 } } },
50
- );
51
- expect(cost).toBe(6);
52
- });
53
-
54
- it('handles partial usage without throwing', () => {
55
- expect(estimateLLMCost('gpt-4o-mini', {})).toBe(0);
56
- expect(estimateLLMCost('gpt-4o-mini', { outputTokens: 1_000_000 })).toBe(
57
- 0.6,
58
- );
59
- });
60
- });
61
-
62
- describe('recordLLMCost', () => {
63
- it('sets the cost attribute on the context for a known model', () => {
64
- const setAttribute = vi.fn();
65
- const cost = recordLLMCost({ setAttribute }, 'gpt-4o', {
66
- inputTokens: 1_000_000,
67
- outputTokens: 0,
68
- });
69
- expect(cost).toBe(2.5);
70
- expect(setAttribute).toHaveBeenCalledWith(GEN_AI_COST_ATTRIBUTE, 2.5);
71
- });
72
-
73
- it('sets no attribute for an unknown model', () => {
74
- const setAttribute = vi.fn();
75
- const cost = recordLLMCost({ setAttribute }, 'unknown-model', {
76
- inputTokens: 100,
77
- });
78
- expect(cost).toBeUndefined();
79
- expect(setAttribute).not.toHaveBeenCalled();
80
- });
81
- });
@@ -1,145 +0,0 @@
1
- /**
2
- * Per-model LLM cost estimation.
3
- *
4
- * Estimate the USD cost of an LLM call from its token usage and record it as a
5
- * span attribute (`gen_ai.usage.cost.usd`). Pair with the
6
- * `gen_ai.client.cost.usd` metric bucket advice in `gen-ai-metrics`.
7
- *
8
- * @example
9
- * ```typescript
10
- * import { trace, recordLLMCost } from 'autotel';
11
- *
12
- * export const chat = trace((ctx) => async (prompt: string) => {
13
- * const res = await client.messages.create({ model, ... });
14
- * recordLLMCost(ctx, model, {
15
- * inputTokens: res.usage.input_tokens,
16
- * outputTokens: res.usage.output_tokens,
17
- * });
18
- * return res;
19
- * });
20
- * ```
21
- */
22
-
23
- import type { TraceContext } from './trace-context';
24
-
25
- /** Span attribute key autotel sets for an estimated call cost. */
26
- export const GEN_AI_COST_ATTRIBUTE = 'gen_ai.usage.cost.usd';
27
-
28
- /** Pricing for a single model, in USD per 1,000,000 tokens. */
29
- export interface ModelPricing {
30
- /** USD per 1M input (prompt) tokens. */
31
- inputPer1M: number;
32
- /** USD per 1M output (completion) tokens. */
33
- outputPer1M: number;
34
- /** USD per 1M cached input tokens. Defaults to {@link ModelPricing.inputPer1M}. */
35
- cachedInputPer1M?: number;
36
- }
37
-
38
- /** Token counts for a single LLM call. */
39
- export interface TokenUsage {
40
- inputTokens?: number;
41
- outputTokens?: number;
42
- /** Cached input tokens, billed at {@link ModelPricing.cachedInputPer1M}. */
43
- cachedInputTokens?: number;
44
- }
45
-
46
- export interface EstimateCostOptions {
47
- /** Override or extend {@link MODEL_PRICING}. Keys are matched first. */
48
- pricing?: Record<string, ModelPricing>;
49
- }
50
-
51
- /**
52
- * Approximate public list prices (USD per 1M tokens) at the time of writing.
53
- * Prices change; treat these as convenience defaults, not a billing source of
54
- * truth. Override per call via `options.pricing` or mutate this table at init.
55
- * Matching is exact first, then by longest key prefix, so versioned model ids
56
- * (`claude-sonnet-4-6-20251101`) resolve to a base entry (`claude-sonnet-4-6`).
57
- */
58
- export const MODEL_PRICING: Record<string, ModelPricing> = {
59
- // OpenAI
60
- 'gpt-4o': { inputPer1M: 2.5, outputPer1M: 10 },
61
- 'gpt-4o-mini': { inputPer1M: 0.15, outputPer1M: 0.6 },
62
- 'gpt-4.1': { inputPer1M: 2, outputPer1M: 8 },
63
- 'gpt-4.1-mini': { inputPer1M: 0.4, outputPer1M: 1.6 },
64
- 'gpt-4.1-nano': { inputPer1M: 0.1, outputPer1M: 0.4 },
65
- 'o3-mini': { inputPer1M: 1.1, outputPer1M: 4.4 },
66
- // Anthropic Claude
67
- 'claude-opus-4': { inputPer1M: 15, outputPer1M: 75 },
68
- 'claude-sonnet-4': { inputPer1M: 3, outputPer1M: 15 },
69
- 'claude-3-5-sonnet': { inputPer1M: 3, outputPer1M: 15 },
70
- 'claude-3-5-haiku': { inputPer1M: 0.8, outputPer1M: 4 },
71
- 'claude-3-opus': { inputPer1M: 15, outputPer1M: 75 },
72
- 'claude-3-haiku': { inputPer1M: 0.25, outputPer1M: 1.25 },
73
- // Google Gemini
74
- 'gemini-1.5-pro': { inputPer1M: 1.25, outputPer1M: 5 },
75
- 'gemini-1.5-flash': { inputPer1M: 0.075, outputPer1M: 0.3 },
76
- 'gemini-2.0-flash': { inputPer1M: 0.1, outputPer1M: 0.4 },
77
- };
78
-
79
- function resolvePricing(
80
- table: Record<string, ModelPricing>,
81
- model: string,
82
- ): ModelPricing | undefined {
83
- const exact = table[model];
84
- if (exact) return exact;
85
-
86
- let best: ModelPricing | undefined;
87
- let bestLength = 0;
88
- for (const key of Object.keys(table)) {
89
- if (model.startsWith(key) && key.length > bestLength) {
90
- best = table[key];
91
- bestLength = key.length;
92
- }
93
- }
94
- return best;
95
- }
96
-
97
- function round(value: number): number {
98
- return Math.round(value * 1e6) / 1e6;
99
- }
100
-
101
- /**
102
- * Estimate the USD cost of an LLM call. Returns `undefined` when the model has
103
- * no known pricing (supply one via `options.pricing`).
104
- */
105
- export function estimateLLMCost(
106
- model: string,
107
- usage: TokenUsage,
108
- options?: EstimateCostOptions,
109
- ): number | undefined {
110
- const table = options?.pricing
111
- ? { ...MODEL_PRICING, ...options.pricing }
112
- : MODEL_PRICING;
113
- const price = resolvePricing(table, model);
114
- if (!price) return undefined;
115
-
116
- const cachedInput = usage.cachedInputTokens ?? 0;
117
- const billedInput = Math.max(0, (usage.inputTokens ?? 0) - cachedInput);
118
- const output = usage.outputTokens ?? 0;
119
- const cachedRate = price.cachedInputPer1M ?? price.inputPer1M;
120
-
121
- const cost =
122
- (billedInput / 1_000_000) * price.inputPer1M +
123
- (cachedInput / 1_000_000) * cachedRate +
124
- (output / 1_000_000) * price.outputPer1M;
125
-
126
- return round(cost);
127
- }
128
-
129
- /**
130
- * Estimate cost and record it on `ctx` as the `gen_ai.usage.cost.usd` span
131
- * attribute. Returns the estimated cost, or `undefined` when the model is
132
- * unknown (in which case no attribute is set).
133
- */
134
- export function recordLLMCost(
135
- ctx: Pick<TraceContext, 'setAttribute'>,
136
- model: string,
137
- usage: TokenUsage,
138
- options?: EstimateCostOptions,
139
- ): number | undefined {
140
- const cost = estimateLLMCost(model, usage, options);
141
- if (cost !== undefined) {
142
- ctx.setAttribute(GEN_AI_COST_ATTRIBUTE, cost);
143
- }
144
- return cost;
145
- }
@@ -1,135 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { TraceContext } from './trace-context';
3
- import {
4
- recordPromptSent,
5
- recordResponseReceived,
6
- recordRetry,
7
- recordStreamFirstToken,
8
- recordToolCall,
9
- } from './gen-ai-events';
10
-
11
- type CapturedEvent = { name: string; attrs?: Record<string, unknown> };
12
-
13
- function captureCtx(): {
14
- ctx: TraceContext;
15
- events: CapturedEvent[];
16
- } {
17
- const events: CapturedEvent[] = [];
18
- const ctx = {
19
- addEvent: (name: string, attrs?: Record<string, unknown>) => {
20
- events.push({ name, attrs });
21
- },
22
- setAttribute: () => {},
23
- setAttributes: () => {},
24
- setStatus: () => {},
25
- recordException: () => {},
26
- addLink: () => {},
27
- addLinks: () => {},
28
- updateName: () => {},
29
- isRecording: () => true,
30
- end: () => {},
31
- } as unknown as TraceContext;
32
- return { ctx, events };
33
- }
34
-
35
- describe('GenAI span event helpers', () => {
36
- it('recordPromptSent emits gen_ai.prompt.sent with canonical attrs', () => {
37
- const { ctx, events } = captureCtx();
38
- recordPromptSent(ctx, {
39
- model: 'gpt-4o',
40
- promptTokens: 1200,
41
- messageCount: 3,
42
- operation: 'chat',
43
- });
44
- expect(events).toHaveLength(1);
45
- expect(events[0]).toEqual({
46
- name: 'gen_ai.prompt.sent',
47
- attrs: {
48
- 'gen_ai.request.model': 'gpt-4o',
49
- 'gen_ai.usage.input_tokens': 1200,
50
- 'gen_ai.request.message_count': 3,
51
- 'gen_ai.operation.name': 'chat',
52
- },
53
- });
54
- });
55
-
56
- it('recordPromptSent omits unset fields rather than writing undefined', () => {
57
- const { ctx, events } = captureCtx();
58
- recordPromptSent(ctx);
59
- expect(events[0]?.attrs).toEqual({});
60
- });
61
-
62
- it('recordResponseReceived joins finish reasons into a CSV for attribute compat', () => {
63
- const { ctx, events } = captureCtx();
64
- recordResponseReceived(ctx, {
65
- model: 'gpt-4o-2024-11-20',
66
- promptTokens: 1200,
67
- completionTokens: 400,
68
- totalTokens: 1600,
69
- finishReasons: ['stop', 'tool_calls'],
70
- });
71
- expect(events[0]).toEqual({
72
- name: 'gen_ai.response.received',
73
- attrs: {
74
- 'gen_ai.response.model': 'gpt-4o-2024-11-20',
75
- 'gen_ai.usage.input_tokens': 1200,
76
- 'gen_ai.usage.output_tokens': 400,
77
- 'gen_ai.usage.total_tokens': 1600,
78
- 'gen_ai.response.finish_reasons': 'stop,tool_calls',
79
- },
80
- });
81
- });
82
-
83
- it('recordResponseReceived omits finish_reasons when empty', () => {
84
- const { ctx, events } = captureCtx();
85
- recordResponseReceived(ctx, { model: 'claude-sonnet-4-6' });
86
- expect(events[0]?.attrs).not.toHaveProperty(
87
- 'gen_ai.response.finish_reasons',
88
- );
89
- });
90
-
91
- it('recordRetry captures attempt, reason, delay, and status code', () => {
92
- const { ctx, events } = captureCtx();
93
- recordRetry(ctx, {
94
- attempt: 2,
95
- reason: 'rate_limit',
96
- delayMs: 1000,
97
- statusCode: 429,
98
- });
99
- expect(events[0]).toEqual({
100
- name: 'gen_ai.retry',
101
- attrs: {
102
- 'retry.attempt': 2,
103
- 'retry.reason': 'rate_limit',
104
- 'retry.delay_ms': 1000,
105
- 'http.response.status_code': 429,
106
- },
107
- });
108
- });
109
-
110
- it('recordToolCall writes canonical gen_ai.tool.* keys', () => {
111
- const { ctx, events } = captureCtx();
112
- recordToolCall(ctx, {
113
- toolName: 'search_traces',
114
- toolCallId: 'call-123',
115
- arguments: '{"serviceName":"api"}',
116
- });
117
- expect(events[0]).toEqual({
118
- name: 'gen_ai.tool.call',
119
- attrs: {
120
- 'gen_ai.tool.name': 'search_traces',
121
- 'gen_ai.tool.call.id': 'call-123',
122
- 'gen_ai.tool.arguments': '{"serviceName":"api"}',
123
- },
124
- });
125
- });
126
-
127
- it('recordStreamFirstToken is the bare marker for TTFT', () => {
128
- const { ctx, events } = captureCtx();
129
- recordStreamFirstToken(ctx, { tokensSoFar: 1 });
130
- expect(events[0]).toEqual({
131
- name: 'gen_ai.stream.first_token',
132
- attrs: { 'gen_ai.stream.tokens_so_far': 1 },
133
- });
134
- });
135
- });
@@ -1,208 +0,0 @@
1
- /**
2
- * Span event helpers for LLM lifecycle, aligned with the OpenTelemetry
3
- * GenAI semantic conventions.
4
- *
5
- * Span events are timestamped points within a span — they render as dots
6
- * on the trace timeline in Jaeger / Tempo / Langfuse / Arize. Use them
7
- * to mark lifecycle moments the span attributes alone can't express:
8
- *
9
- * - When the prompt was sent (vs. when the first token arrived)
10
- * - When each retry attempt started, and why
11
- * - When a streaming response produced its first token (TTFT)
12
- * - When a tool was invoked
13
- *
14
- * Every helper pins the event name + attribute keys to the published
15
- * spec so downstream tooling (autotel-mcp, Langfuse, vendor UIs) can
16
- * render them consistently.
17
- *
18
- * @example
19
- * ```typescript
20
- * import { trace, recordPromptSent, recordResponseReceived, recordRetry } from 'autotel';
21
- *
22
- * export const chat = trace('chat', ctx => async (prompt: string) => {
23
- * recordPromptSent(ctx, { model: 'gpt-4o', messageCount: 1 });
24
- *
25
- * for (let attempt = 1; attempt <= 3; attempt++) {
26
- * try {
27
- * const res = await openai.chat.completions.create({...});
28
- * recordResponseReceived(ctx, {
29
- * model: res.model,
30
- * promptTokens: res.usage?.prompt_tokens,
31
- * completionTokens: res.usage?.completion_tokens,
32
- * finishReasons: res.choices.map(c => c.finish_reason),
33
- * });
34
- * return res;
35
- * } catch (err) {
36
- * recordRetry(ctx, { attempt, reason: 'rate_limit', delayMs: 500 });
37
- * await sleep(500 * attempt);
38
- * }
39
- * }
40
- * });
41
- * ```
42
- */
43
-
44
- import type { TraceContext } from './trace-context';
45
- import { emitCorrelatedEvent } from './correlated-events';
46
-
47
- type EventAttrs = Record<string, string | number | boolean>;
48
-
49
- /** Attributes expected on a `gen_ai.prompt.sent` event. */
50
- export interface PromptSentEvent {
51
- /** Model the caller intends to invoke (may differ from response model). */
52
- model?: string;
53
- /** Estimated input token count, when known before the call. */
54
- promptTokens?: number;
55
- /** Number of messages in a chat request (system + user + assistant). */
56
- messageCount?: number;
57
- /** Free-form operation kind — `chat` / `completion` / `embedding`. */
58
- operation?: string;
59
- }
60
-
61
- /** Attributes expected on a `gen_ai.response.received` event. */
62
- export interface ResponseReceivedEvent {
63
- /** Model the provider actually served (may be more specific than requested). */
64
- model?: string;
65
- promptTokens?: number;
66
- completionTokens?: number;
67
- totalTokens?: number;
68
- /** `stop`, `length`, `content_filter`, `tool_calls`, etc. */
69
- finishReasons?: string[];
70
- }
71
-
72
- /** Attributes expected on a `gen_ai.retry` event. */
73
- export interface RetryEvent {
74
- attempt: number;
75
- /** `rate_limit` | `timeout` | `provider_error` | custom label. */
76
- reason?: string;
77
- /** How long we'll wait before the next attempt. */
78
- delayMs?: number;
79
- /** HTTP status that triggered the retry, when applicable. */
80
- statusCode?: number;
81
- }
82
-
83
- /** Attributes expected on a `gen_ai.tool.call` event. */
84
- export interface ToolCallEvent {
85
- toolName: string;
86
- /** Call identifier so responses can be correlated back to calls. */
87
- toolCallId?: string;
88
- /** Pre-serialised tool arguments; omit if sensitive. */
89
- arguments?: string;
90
- }
91
-
92
- /** Attributes expected on a `gen_ai.stream.first_token` event. */
93
- export interface StreamFirstTokenEvent {
94
- /** Tokens streamed so far, if the caller tracks that. */
95
- tokensSoFar?: number;
96
- }
97
-
98
- /**
99
- * Record that a prompt was dispatched to the provider. Typically called
100
- * before `await provider.chat.completions.create(...)`.
101
- */
102
- export function recordPromptSent(
103
- ctx: TraceContext,
104
- event: PromptSentEvent = {},
105
- ): void {
106
- emitCorrelatedEvent(ctx, 'gen_ai.prompt.sent', buildPromptSentAttrs(event));
107
- }
108
-
109
- /**
110
- * Record a successful provider response. Call after the response arrives
111
- * (for non-streaming) or after the stream completes.
112
- */
113
- export function recordResponseReceived(
114
- ctx: TraceContext,
115
- event: ResponseReceivedEvent = {},
116
- ): void {
117
- emitCorrelatedEvent(
118
- ctx,
119
- 'gen_ai.response.received',
120
- buildResponseAttrs(event),
121
- );
122
- }
123
-
124
- /**
125
- * Record a retry attempt on an LLM call. Call *before* sleeping for
126
- * `delayMs` so the event timestamp accurately marks when the retry
127
- * decision was made.
128
- */
129
- export function recordRetry(ctx: TraceContext, event: RetryEvent): void {
130
- emitCorrelatedEvent(ctx, 'gen_ai.retry', buildRetryAttrs(event));
131
- }
132
-
133
- /**
134
- * Record a tool / function call made in the course of an agent step.
135
- * Emits an event rather than a child span because many frameworks fire
136
- * several tool calls within a single provider response.
137
- */
138
- export function recordToolCall(ctx: TraceContext, event: ToolCallEvent): void {
139
- emitCorrelatedEvent(ctx, 'gen_ai.tool.call', buildToolCallAttrs(event));
140
- }
141
-
142
- /**
143
- * Record the time-to-first-token for a streaming response. Pair with
144
- * `recordResponseReceived` at the end so the span carries both the TTFT
145
- * marker and the final usage numbers.
146
- */
147
- export function recordStreamFirstToken(
148
- ctx: TraceContext,
149
- event: StreamFirstTokenEvent = {},
150
- ): void {
151
- emitCorrelatedEvent(
152
- ctx,
153
- 'gen_ai.stream.first_token',
154
- buildStreamFirstTokenAttrs(event),
155
- );
156
- }
157
-
158
- // ---- Attribute builders -------------------------------------------------
159
-
160
- function buildPromptSentAttrs(event: PromptSentEvent): EventAttrs {
161
- const attrs: EventAttrs = {};
162
- if (event.model) attrs['gen_ai.request.model'] = event.model;
163
- if (event.promptTokens !== undefined)
164
- attrs['gen_ai.usage.input_tokens'] = event.promptTokens;
165
- if (event.messageCount !== undefined)
166
- attrs['gen_ai.request.message_count'] = event.messageCount;
167
- if (event.operation) attrs['gen_ai.operation.name'] = event.operation;
168
- return attrs;
169
- }
170
-
171
- function buildResponseAttrs(event: ResponseReceivedEvent): EventAttrs {
172
- const attrs: EventAttrs = {};
173
- if (event.model) attrs['gen_ai.response.model'] = event.model;
174
- if (event.promptTokens !== undefined)
175
- attrs['gen_ai.usage.input_tokens'] = event.promptTokens;
176
- if (event.completionTokens !== undefined)
177
- attrs['gen_ai.usage.output_tokens'] = event.completionTokens;
178
- if (event.totalTokens !== undefined)
179
- attrs['gen_ai.usage.total_tokens'] = event.totalTokens;
180
- if (event.finishReasons && event.finishReasons.length > 0) {
181
- // Arrays aren't primitive AttributeValues on this context, so join.
182
- attrs['gen_ai.response.finish_reasons'] = event.finishReasons.join(',');
183
- }
184
- return attrs;
185
- }
186
-
187
- function buildRetryAttrs(event: RetryEvent): EventAttrs {
188
- const attrs: EventAttrs = { 'retry.attempt': event.attempt };
189
- if (event.reason) attrs['retry.reason'] = event.reason;
190
- if (event.delayMs !== undefined) attrs['retry.delay_ms'] = event.delayMs;
191
- if (event.statusCode !== undefined)
192
- attrs['http.response.status_code'] = event.statusCode;
193
- return attrs;
194
- }
195
-
196
- function buildToolCallAttrs(event: ToolCallEvent): EventAttrs {
197
- const attrs: EventAttrs = { 'gen_ai.tool.name': event.toolName };
198
- if (event.toolCallId) attrs['gen_ai.tool.call.id'] = event.toolCallId;
199
- if (event.arguments) attrs['gen_ai.tool.arguments'] = event.arguments;
200
- return attrs;
201
- }
202
-
203
- function buildStreamFirstTokenAttrs(event: StreamFirstTokenEvent): EventAttrs {
204
- const attrs: EventAttrs = {};
205
- if (event.tokensSoFar !== undefined)
206
- attrs['gen_ai.stream.tokens_so_far'] = event.tokensSoFar;
207
- return attrs;
208
- }
@@ -1,96 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { AggregationType } from '@opentelemetry/sdk-metrics';
3
- import {
4
- GEN_AI_COST_USD_BUCKETS,
5
- GEN_AI_DURATION_BUCKETS_SECONDS,
6
- GEN_AI_TOKEN_USAGE_BUCKETS,
7
- genAiMetricViews,
8
- llmHistogramAdvice,
9
- } from './gen-ai-metrics';
10
-
11
- describe('gen-ai-metrics', () => {
12
- it('bucket arrays are strictly ascending (required by Prometheus + OTel)', () => {
13
- for (const buckets of [
14
- GEN_AI_DURATION_BUCKETS_SECONDS,
15
- GEN_AI_TOKEN_USAGE_BUCKETS,
16
- GEN_AI_COST_USD_BUCKETS,
17
- ]) {
18
- for (let i = 1; i < buckets.length; i++) {
19
- expect(
20
- buckets[i]! > buckets[i - 1]!,
21
- `index ${i} not ascending: ${buckets[i - 1]} → ${buckets[i]}`,
22
- ).toBe(true);
23
- }
24
- }
25
- });
26
-
27
- it('duration buckets cover tail through 5 minutes for reasoning models', () => {
28
- expect(GEN_AI_DURATION_BUCKETS_SECONDS[0]).toBeLessThanOrEqual(0.05);
29
- expect(
30
- GEN_AI_DURATION_BUCKETS_SECONDS[
31
- GEN_AI_DURATION_BUCKETS_SECONDS.length - 1
32
- ],
33
- ).toBeGreaterThanOrEqual(300);
34
- });
35
-
36
- it('token buckets cover up to a million-token context window', () => {
37
- expect(
38
- GEN_AI_TOKEN_USAGE_BUCKETS[GEN_AI_TOKEN_USAGE_BUCKETS.length - 1],
39
- ).toBeGreaterThanOrEqual(1_000_000);
40
- });
41
-
42
- it('cost buckets resolve sub-cent spend', () => {
43
- expect(GEN_AI_COST_USD_BUCKETS[0]).toBeLessThan(0.001);
44
- });
45
-
46
- it('bucket arrays are frozen — consumers cannot mutate shared state', () => {
47
- expect(() => {
48
- (GEN_AI_DURATION_BUCKETS_SECONDS as number[]).push(999);
49
- }).toThrow();
50
- });
51
-
52
- it('llmHistogramAdvice returns explicitBucketBoundaries advice shape', () => {
53
- const advice = llmHistogramAdvice('duration');
54
- expect(advice.advice.explicitBucketBoundaries).toEqual([
55
- ...GEN_AI_DURATION_BUCKETS_SECONDS,
56
- ]);
57
- // The returned array is a fresh copy so callers can mutate without
58
- // affecting the shared constant.
59
- advice.advice.explicitBucketBoundaries.push(0);
60
- expect([...GEN_AI_DURATION_BUCKETS_SECONDS]).not.toContain(0);
61
- });
62
-
63
- it('genAiMetricViews targets the OTel GenAI instrument names with the right buckets', () => {
64
- const views = genAiMetricViews();
65
- expect(views).toHaveLength(3);
66
-
67
- const byInstrument = Object.fromEntries(
68
- views.map((v) => [v.instrumentName, v]),
69
- );
70
- expect(
71
- byInstrument['gen_ai.client.operation.duration']?.aggregation,
72
- ).toEqual({
73
- type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
74
- options: { boundaries: [...GEN_AI_DURATION_BUCKETS_SECONDS] },
75
- });
76
- expect(byInstrument['gen_ai.client.token.usage']?.aggregation).toEqual({
77
- type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
78
- options: { boundaries: [...GEN_AI_TOKEN_USAGE_BUCKETS] },
79
- });
80
- expect(byInstrument['gen_ai.client.cost.usd']?.aggregation).toEqual({
81
- type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
82
- options: { boundaries: [...GEN_AI_COST_USD_BUCKETS] },
83
- });
84
- });
85
-
86
- it('genAiMetricViews accepts extra instruments', () => {
87
- const views = genAiMetricViews([
88
- { instrumentName: 'custom.llm.prompt_tokens', kind: 'tokens' },
89
- ]);
90
- expect(views).toHaveLength(4);
91
- const custom = views.find(
92
- (v) => v.instrumentName === 'custom.llm.prompt_tokens',
93
- );
94
- expect(custom).toBeDefined();
95
- });
96
- });