autotel 3.5.0 → 3.7.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 (591) 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-D3etyRVc.cjs +713 -0
  12. package/dist/attributes-D3etyRVc.cjs.map +1 -0
  13. package/dist/attributes-ksn4HVbd.js +600 -0
  14. package/dist/attributes-ksn4HVbd.js.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 -53
  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 -16
  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 -65
  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 -63
  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 -36
  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 -20
  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 -56
  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 -19
  149. package/dist/http.cjs +276 -175
  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 -173
  156. package/dist/http.js.map +1 -1
  157. package/dist/index-CX0aG1Uh.d.ts +708 -0
  158. package/dist/index-CX0aG1Uh.d.ts.map +1 -0
  159. package/dist/index-DIWZFKUS.d.cts +708 -0
  160. package/dist/index-DIWZFKUS.d.cts.map +1 -0
  161. package/dist/index.cjs +1050 -1184
  162. package/dist/index.cjs.map +1 -1
  163. package/dist/index.d.cts +401 -570
  164. package/dist/index.d.cts.map +1 -0
  165. package/dist/index.d.ts +401 -570
  166. package/dist/index.d.ts.map +1 -0
  167. package/dist/index.js +913 -725
  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 -35
  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 -20
  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-DfXA3R1L.js +184 -0
  276. package/dist/registry-DfXA3R1L.js.map +1 -0
  277. package/dist/registry-JZg2J3RZ.cjs +334 -0
  278. package/dist/registry-JZg2J3RZ.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 +440 -38
  308. package/dist/semantic-helpers.cjs.map +1 -1
  309. package/dist/semantic-helpers.d.cts +38 -45
  310. package/dist/semantic-helpers.d.cts.map +1 -0
  311. package/dist/semantic-helpers.d.ts +38 -45
  312. package/dist/semantic-helpers.d.ts.map +1 -0
  313. package/dist/semantic-helpers.js +438 -19
  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 +201 -0
  382. package/dist/validate.cjs.map +1 -0
  383. package/dist/validate.d.cts +105 -0
  384. package/dist/validate.d.cts.map +1 -0
  385. package/dist/validate.d.ts +105 -0
  386. package/dist/validate.d.ts.map +1 -0
  387. package/dist/validate.js +197 -0
  388. package/dist/validate.js.map +1 -0
  389. package/dist/validation-attributes.cjs +45 -0
  390. package/dist/validation-attributes.cjs.map +1 -0
  391. package/dist/validation-attributes.d.cts +33 -0
  392. package/dist/validation-attributes.d.cts.map +1 -0
  393. package/dist/validation-attributes.d.ts +33 -0
  394. package/dist/validation-attributes.d.ts.map +1 -0
  395. package/dist/validation-attributes.js +41 -0
  396. package/dist/validation-attributes.js.map +1 -0
  397. package/dist/webhook.cjs +286 -255
  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 -253
  404. package/dist/webhook.js.map +1 -1
  405. package/dist/workflow-distributed.cjs +498 -411
  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 -409
  412. package/dist/workflow-distributed.js.map +1 -1
  413. package/dist/workflow.cjs +405 -39
  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 -20
  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 +14 -4
  431. package/src/define-event.ts +2 -21
  432. package/src/index.ts +3 -0
  433. package/src/request-logger.test.ts +53 -1
  434. package/src/request-logger.ts +58 -0
  435. package/src/stable-hash.ts +27 -0
  436. package/src/validate.test.ts +287 -0
  437. package/src/validate.ts +307 -0
  438. package/src/validation-attributes.ts +43 -0
  439. package/dist/attributes.cjs.map +0 -1
  440. package/dist/attributes.js.map +0 -1
  441. package/dist/chunk-2ZKEORFN.cjs +0 -14
  442. package/dist/chunk-2ZKEORFN.cjs.map +0 -1
  443. package/dist/chunk-3QXBFGKP.js +0 -344
  444. package/dist/chunk-3QXBFGKP.js.map +0 -1
  445. package/dist/chunk-454CH4OV.js +0 -744
  446. package/dist/chunk-454CH4OV.js.map +0 -1
  447. package/dist/chunk-4A53YIAX.js +0 -180
  448. package/dist/chunk-4A53YIAX.js.map +0 -1
  449. package/dist/chunk-4IFSYQVX.js +0 -337
  450. package/dist/chunk-4IFSYQVX.js.map +0 -1
  451. package/dist/chunk-4P6ZOARG.cjs +0 -33
  452. package/dist/chunk-4P6ZOARG.cjs.map +0 -1
  453. package/dist/chunk-55ER2KD5.js +0 -228
  454. package/dist/chunk-55ER2KD5.js.map +0 -1
  455. package/dist/chunk-5ZN622AO.js +0 -73
  456. package/dist/chunk-5ZN622AO.js.map +0 -1
  457. package/dist/chunk-6S5RUKU3.cjs +0 -347
  458. package/dist/chunk-6S5RUKU3.cjs.map +0 -1
  459. package/dist/chunk-6UQRVUN3.js +0 -222
  460. package/dist/chunk-6UQRVUN3.js.map +0 -1
  461. package/dist/chunk-7552UTQW.js +0 -11
  462. package/dist/chunk-7552UTQW.js.map +0 -1
  463. package/dist/chunk-7EQ4G4SI.cjs +0 -146
  464. package/dist/chunk-7EQ4G4SI.cjs.map +0 -1
  465. package/dist/chunk-7SAWIN74.js +0 -285
  466. package/dist/chunk-7SAWIN74.js.map +0 -1
  467. package/dist/chunk-A4E5AQFK.js +0 -30
  468. package/dist/chunk-A4E5AQFK.js.map +0 -1
  469. package/dist/chunk-AC5GNZKB.cjs +0 -344
  470. package/dist/chunk-AC5GNZKB.cjs.map +0 -1
  471. package/dist/chunk-ALPYR2GC.js +0 -1061
  472. package/dist/chunk-ALPYR2GC.js.map +0 -1
  473. package/dist/chunk-BZHG5IZ4.js +0 -73
  474. package/dist/chunk-BZHG5IZ4.js.map +0 -1
  475. package/dist/chunk-CEAQK2QY.cjs +0 -32
  476. package/dist/chunk-CEAQK2QY.cjs.map +0 -1
  477. package/dist/chunk-CMHVQR6P.js +0 -170
  478. package/dist/chunk-CMHVQR6P.js.map +0 -1
  479. package/dist/chunk-CU6IDACR.cjs +0 -224
  480. package/dist/chunk-CU6IDACR.cjs.map +0 -1
  481. package/dist/chunk-DPSA4QLA.js +0 -344
  482. package/dist/chunk-DPSA4QLA.js.map +0 -1
  483. package/dist/chunk-DQEHQNQE.js +0 -795
  484. package/dist/chunk-DQEHQNQE.js.map +0 -1
  485. package/dist/chunk-ESLWRGAG.cjs +0 -92
  486. package/dist/chunk-ESLWRGAG.cjs.map +0 -1
  487. package/dist/chunk-ESMHTKLJ.cjs +0 -206
  488. package/dist/chunk-ESMHTKLJ.cjs.map +0 -1
  489. package/dist/chunk-FGNDN2FD.cjs +0 -1242
  490. package/dist/chunk-FGNDN2FD.cjs.map +0 -1
  491. package/dist/chunk-FU6R566Y.cjs +0 -236
  492. package/dist/chunk-FU6R566Y.cjs.map +0 -1
  493. package/dist/chunk-GBFTC7Q7.cjs +0 -837
  494. package/dist/chunk-GBFTC7Q7.cjs.map +0 -1
  495. package/dist/chunk-GYR5K654.js +0 -91
  496. package/dist/chunk-GYR5K654.js.map +0 -1
  497. package/dist/chunk-HA2WBOGQ.js +0 -57
  498. package/dist/chunk-HA2WBOGQ.js.map +0 -1
  499. package/dist/chunk-HT5JQKN2.js +0 -118
  500. package/dist/chunk-HT5JQKN2.js.map +0 -1
  501. package/dist/chunk-INJD3G4K.cjs +0 -340
  502. package/dist/chunk-INJD3G4K.cjs.map +0 -1
  503. package/dist/chunk-IOYFAFHJ.cjs +0 -95
  504. package/dist/chunk-IOYFAFHJ.cjs.map +0 -1
  505. package/dist/chunk-J5QENANM.js +0 -87
  506. package/dist/chunk-J5QENANM.js.map +0 -1
  507. package/dist/chunk-J7VGRIAJ.js +0 -64
  508. package/dist/chunk-J7VGRIAJ.js.map +0 -1
  509. package/dist/chunk-KFOHQK7X.js +0 -144
  510. package/dist/chunk-KFOHQK7X.js.map +0 -1
  511. package/dist/chunk-KIL5CUN6.js +0 -31
  512. package/dist/chunk-KIL5CUN6.js.map +0 -1
  513. package/dist/chunk-LITNXTTT.js +0 -3
  514. package/dist/chunk-LITNXTTT.js.map +0 -1
  515. package/dist/chunk-M3LFHHTN.cjs +0 -764
  516. package/dist/chunk-M3LFHHTN.cjs.map +0 -1
  517. package/dist/chunk-NEIB3TLD.cjs +0 -360
  518. package/dist/chunk-NEIB3TLD.cjs.map +0 -1
  519. package/dist/chunk-NVAI5CCN.cjs +0 -39
  520. package/dist/chunk-NVAI5CCN.cjs.map +0 -1
  521. package/dist/chunk-NVGPMGI4.js +0 -95
  522. package/dist/chunk-NVGPMGI4.js.map +0 -1
  523. package/dist/chunk-NZ72VDNY.cjs +0 -4
  524. package/dist/chunk-NZ72VDNY.cjs.map +0 -1
  525. package/dist/chunk-O4JZUCUE.js +0 -1174
  526. package/dist/chunk-O4JZUCUE.js.map +0 -1
  527. package/dist/chunk-O7JOKRN2.js +0 -833
  528. package/dist/chunk-O7JOKRN2.js.map +0 -1
  529. package/dist/chunk-OPPXYVEZ.cjs +0 -131
  530. package/dist/chunk-OPPXYVEZ.cjs.map +0 -1
  531. package/dist/chunk-Q4EULJQY.js +0 -35
  532. package/dist/chunk-Q4EULJQY.js.map +0 -1
  533. package/dist/chunk-QWW3E3JM.cjs +0 -178
  534. package/dist/chunk-QWW3E3JM.cjs.map +0 -1
  535. package/dist/chunk-R7QYGZUP.cjs +0 -1075
  536. package/dist/chunk-R7QYGZUP.cjs.map +0 -1
  537. package/dist/chunk-RUPKBKUF.js +0 -352
  538. package/dist/chunk-RUPKBKUF.js.map +0 -1
  539. package/dist/chunk-SEO6NAQT.js +0 -14
  540. package/dist/chunk-SEO6NAQT.js.map +0 -1
  541. package/dist/chunk-T4B5LB6E.cjs +0 -66
  542. package/dist/chunk-T4B5LB6E.cjs.map +0 -1
  543. package/dist/chunk-TC5ZPWM4.cjs +0 -289
  544. package/dist/chunk-TC5ZPWM4.cjs.map +0 -1
  545. package/dist/chunk-TQ5UWA7S.js +0 -26
  546. package/dist/chunk-TQ5UWA7S.js.map +0 -1
  547. package/dist/chunk-URHPSJW2.js +0 -339
  548. package/dist/chunk-URHPSJW2.js.map +0 -1
  549. package/dist/chunk-UY3UYPBZ.cjs +0 -77
  550. package/dist/chunk-UY3UYPBZ.cjs.map +0 -1
  551. package/dist/chunk-VG2ABKJX.cjs +0 -100
  552. package/dist/chunk-VG2ABKJX.cjs.map +0 -1
  553. package/dist/chunk-VH77IPJN.cjs +0 -358
  554. package/dist/chunk-VH77IPJN.cjs.map +0 -1
  555. package/dist/chunk-VQTCQKHQ.cjs +0 -17
  556. package/dist/chunk-VQTCQKHQ.cjs.map +0 -1
  557. package/dist/chunk-WGWSHJ2N.js +0 -38
  558. package/dist/chunk-WGWSHJ2N.js.map +0 -1
  559. package/dist/chunk-WJH6IYU2.cjs +0 -32
  560. package/dist/chunk-WJH6IYU2.cjs.map +0 -1
  561. package/dist/chunk-YREV3LGG.cjs +0 -61
  562. package/dist/chunk-YREV3LGG.cjs.map +0 -1
  563. package/dist/chunk-YTXEZ4SD.cjs +0 -77
  564. package/dist/chunk-YTXEZ4SD.cjs.map +0 -1
  565. package/dist/chunk-YWCESU4Y.js +0 -1233
  566. package/dist/chunk-YWCESU4Y.js.map +0 -1
  567. package/dist/chunk-Z6HRSM2Y.cjs +0 -799
  568. package/dist/chunk-Z6HRSM2Y.cjs.map +0 -1
  569. package/dist/chunk-Z7PW3KHL.cjs +0 -1198
  570. package/dist/chunk-Z7PW3KHL.cjs.map +0 -1
  571. package/dist/chunk-ZNMBW67B.cjs +0 -40
  572. package/dist/chunk-ZNMBW67B.cjs.map +0 -1
  573. package/dist/correlation-id.cjs.map +0 -1
  574. package/dist/correlation-id.js.map +0 -1
  575. package/dist/event-subscriber.cjs.map +0 -1
  576. package/dist/event-subscriber.js.map +0 -1
  577. package/dist/event.cjs.map +0 -1
  578. package/dist/event.js.map +0 -1
  579. package/dist/exporters.cjs.map +0 -1
  580. package/dist/exporters.js.map +0 -1
  581. package/dist/functional.cjs.map +0 -1
  582. package/dist/functional.js.map +0 -1
  583. package/dist/init-DIowiiCh.d.ts +0 -1167
  584. package/dist/init-j-A1zI16.d.cts +0 -1167
  585. package/dist/processors.cjs.map +0 -1
  586. package/dist/processors.js.map +0 -1
  587. package/dist/trace-context-DbGKd1Rn.d.cts +0 -213
  588. package/dist/trace-context-DbGKd1Rn.d.ts +0 -213
  589. package/dist/utils-BahBCFtJ.d.cts +0 -712
  590. package/dist/utils-CLKwaUlG.d.ts +0 -712
  591. package/dist/yaml-config.cjs.map +0 -1
@@ -1,1174 +0,0 @@
1
- import { getValidationConfig, isInitialized, warnIfNotInitialized, getConfig, getEventsConfig, getLogger } from './chunk-ALPYR2GC.js';
2
- import { getConfig as getConfig$1 } from './chunk-J5QENANM.js';
3
- import { SpanStatusCode, trace, context, propagation } from '@opentelemetry/api';
4
- import { AsyncLocalStorage } from 'async_hooks';
5
-
6
- // src/flatten-attributes.ts
7
- function toAttributeValue(value) {
8
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
9
- return value;
10
- }
11
- if (Array.isArray(value)) {
12
- if (value.every((v) => typeof v === "string") || value.every((v) => typeof v === "number") || value.every((v) => typeof v === "boolean")) {
13
- return value;
14
- }
15
- try {
16
- return JSON.stringify(value);
17
- } catch {
18
- return "<serialization-failed>";
19
- }
20
- }
21
- if (value instanceof Date) {
22
- return value.toISOString();
23
- }
24
- if (value instanceof Error) {
25
- return value.message;
26
- }
27
- return void 0;
28
- }
29
- function flattenToAttributes(fields, prefix = "") {
30
- const out = {};
31
- const seen = /* @__PURE__ */ new WeakSet();
32
- function flatten(obj, currentPrefix) {
33
- for (const [key, value] of Object.entries(obj)) {
34
- if (value == null) continue;
35
- const nextKey = currentPrefix ? `${currentPrefix}.${key}` : key;
36
- const attr = toAttributeValue(value);
37
- if (attr !== void 0) {
38
- out[nextKey] = attr;
39
- continue;
40
- }
41
- if (typeof value === "object" && value.constructor === Object) {
42
- if (seen.has(value)) {
43
- out[nextKey] = "<circular-reference>";
44
- continue;
45
- }
46
- seen.add(value);
47
- flatten(value, nextKey);
48
- continue;
49
- }
50
- try {
51
- out[nextKey] = JSON.stringify(value);
52
- } catch {
53
- out[nextKey] = "<serialization-failed>";
54
- }
55
- }
56
- }
57
- flatten(fields, prefix);
58
- return out;
59
- }
60
-
61
- // src/structured-error.ts
62
- var internalKey = /* @__PURE__ */ Symbol.for("autotel.error.internal");
63
- function createStructuredError(input) {
64
- const error = new Error(input.message, {
65
- cause: input.cause
66
- });
67
- error.name = input.name ?? "StructuredError";
68
- if (input.why !== void 0) error.why = input.why;
69
- if (input.fix !== void 0) error.fix = input.fix;
70
- if (input.link !== void 0) error.link = input.link;
71
- if (input.code !== void 0) error.code = input.code;
72
- if (input.status !== void 0) error.status = input.status;
73
- if (input.details !== void 0) error.details = input.details;
74
- if (input.internal !== void 0) {
75
- Object.defineProperty(error, internalKey, {
76
- value: input.internal,
77
- enumerable: false,
78
- writable: false,
79
- configurable: true
80
- });
81
- }
82
- Object.defineProperty(error, "internal", {
83
- get() {
84
- return this[internalKey];
85
- },
86
- enumerable: false,
87
- configurable: true
88
- });
89
- error.toString = () => {
90
- const lines = [`${error.name}: ${error.message}`];
91
- if (error.why) lines.push(` Why: ${error.why}`);
92
- if (error.fix) lines.push(` Fix: ${error.fix}`);
93
- if (error.link) lines.push(` Link: ${error.link}`);
94
- if (error.code !== void 0) lines.push(` Code: ${error.code}`);
95
- if (error.status !== void 0) lines.push(` Status: ${error.status}`);
96
- if (error.cause) {
97
- const cause = error.cause;
98
- lines.push(` Caused by: ${cause.name}: ${cause.message}`);
99
- }
100
- return lines.join("\n");
101
- };
102
- return error;
103
- }
104
- function structuredErrorToJSON(error) {
105
- const result = {
106
- name: error.name,
107
- message: error.message
108
- };
109
- if (error.status !== void 0) result.status = error.status;
110
- if (error.why || error.fix || error.link) {
111
- result.data = {
112
- ...error.why && { why: error.why },
113
- ...error.fix && { fix: error.fix },
114
- ...error.link && { link: error.link }
115
- };
116
- }
117
- if (error.code !== void 0) result.code = error.code;
118
- if (error.details) result.details = error.details;
119
- if (error.cause instanceof Error) {
120
- result.cause = { name: error.cause.name, message: error.cause.message };
121
- }
122
- return result;
123
- }
124
- function getStructuredErrorAttributes(error) {
125
- const structured = error;
126
- const attributes = {
127
- "error.type": error.name || "Error",
128
- "error.message": error.message
129
- };
130
- if (error.stack) attributes["error.stack"] = error.stack;
131
- if (structured.why) attributes["error.why"] = structured.why;
132
- if (structured.fix) attributes["error.fix"] = structured.fix;
133
- if (structured.link) attributes["error.link"] = structured.link;
134
- if (structured.code !== void 0) {
135
- attributes["error.code"] = typeof structured.code === "string" ? structured.code : String(structured.code);
136
- }
137
- if (structured.status !== void 0) {
138
- attributes["error.status"] = structured.status;
139
- }
140
- if (structured.details) {
141
- Object.assign(
142
- attributes,
143
- flattenToAttributes(structured.details, "error.details")
144
- );
145
- }
146
- return attributes;
147
- }
148
- function recordStructuredError(ctx, error) {
149
- const maybeRecordException = ctx.recordException;
150
- if (typeof maybeRecordException === "function") {
151
- maybeRecordException(error);
152
- }
153
- ctx.setStatus({
154
- code: SpanStatusCode.ERROR,
155
- message: error.message
156
- });
157
- ctx.setAttributes(getStructuredErrorAttributes(error));
158
- }
159
-
160
- // src/rate-limiter.ts
161
- var TokenBucketRateLimiter = class {
162
- tokens;
163
- maxTokens;
164
- refillRate;
165
- // tokens per millisecond
166
- lastRefill;
167
- constructor(config) {
168
- this.maxTokens = config.burstCapacity || config.maxEventsPerSecond * 2;
169
- this.tokens = this.maxTokens;
170
- this.refillRate = config.maxEventsPerSecond / 1e3;
171
- this.lastRefill = Date.now();
172
- }
173
- /**
174
- * Try to consume a token (allow an event)
175
- * Returns true if allowed, false if rate limit exceeded
176
- */
177
- tryConsume(count = 1) {
178
- this.refill();
179
- if (this.tokens >= count) {
180
- this.tokens -= count;
181
- return true;
182
- }
183
- return false;
184
- }
185
- /**
186
- * Wait until a token is available (async rate limiting)
187
- * Returns a promise that resolves when the event can be processed
188
- */
189
- async waitForToken(count = 1) {
190
- this.refill();
191
- if (this.tokens >= count) {
192
- this.tokens -= count;
193
- return;
194
- }
195
- const tokensNeeded = count - this.tokens;
196
- const waitMs = Math.ceil(tokensNeeded / this.refillRate);
197
- await new Promise((resolve) => setTimeout(resolve, waitMs));
198
- return this.waitForToken(count);
199
- }
200
- /**
201
- * Refill tokens based on elapsed time
202
- */
203
- refill() {
204
- const now = Date.now();
205
- const elapsed = now - this.lastRefill;
206
- const tokensToAdd = elapsed * this.refillRate;
207
- this.tokens = Math.min(this.maxTokens, this.tokens + tokensToAdd);
208
- this.lastRefill = now;
209
- }
210
- /**
211
- * Get current available tokens (for testing/debugging)
212
- */
213
- getAvailableTokens() {
214
- this.refill();
215
- return Math.floor(this.tokens);
216
- }
217
- /**
218
- * Reset the rate limiter (for testing)
219
- */
220
- reset() {
221
- this.tokens = this.maxTokens;
222
- this.lastRefill = Date.now();
223
- }
224
- };
225
-
226
- // src/event-queue.ts
227
- var DEFAULT_CONFIG = {
228
- maxSize: 5e4,
229
- batchSize: 100,
230
- flushInterval: 1e4,
231
- maxRetries: 3,
232
- rateLimit: {
233
- maxEventsPerSecond: 100,
234
- burstCapacity: 200
235
- }
236
- };
237
- function getSubscriberName(subscriber) {
238
- if (subscriber.name) {
239
- return subscriber.name.toLowerCase();
240
- }
241
- const className = subscriber.constructor?.name || "unknown";
242
- return className.replace(/Subscriber$/i, "").toLowerCase();
243
- }
244
- var EventQueue = class {
245
- queue = [];
246
- flushTimer = null;
247
- config;
248
- subscribers;
249
- rateLimiter;
250
- flushPromise = null;
251
- isShuttingDown = false;
252
- // Metrics
253
- metrics = null;
254
- // Observable callback cleanup functions
255
- observableCleanups = [];
256
- // Subscriber health tracking (for observable gauges)
257
- subscriberHealthy = /* @__PURE__ */ new Map();
258
- constructor(subscribers, config) {
259
- this.subscribers = subscribers;
260
- this.config = { ...DEFAULT_CONFIG, ...config };
261
- this.rateLimiter = this.config.rateLimit ? new TokenBucketRateLimiter(this.config.rateLimit) : null;
262
- for (const subscriber of subscribers) {
263
- const name = getSubscriberName(subscriber);
264
- this.subscriberHealthy.set(name, true);
265
- }
266
- this.initMetrics();
267
- }
268
- /**
269
- * Initialize OTel metrics for queue observability
270
- */
271
- initMetrics() {
272
- const runtimeConfig = getConfig$1();
273
- const meter = runtimeConfig.meter;
274
- const queueSize = meter.createObservableGauge(
275
- "autotel.event_delivery.queue.size",
276
- {
277
- description: "Current number of events in the delivery queue",
278
- unit: "count"
279
- }
280
- );
281
- const queueSizeCallback = (observableResult) => {
282
- observableResult.observe(this.queue.length);
283
- };
284
- queueSize.addCallback(queueSizeCallback);
285
- this.observableCleanups.push(
286
- () => queueSize.removeCallback(queueSizeCallback)
287
- );
288
- const oldestAge = meter.createObservableGauge(
289
- "autotel.event_delivery.queue.oldest_age_ms",
290
- {
291
- description: "Age of the oldest event in the queue in milliseconds",
292
- unit: "ms"
293
- }
294
- );
295
- const oldestAgeCallback = (observableResult) => {
296
- if (this.queue.length > 0) {
297
- const oldest = this.queue[0];
298
- const ageMs = Date.now() - oldest.timestamp;
299
- observableResult.observe(ageMs);
300
- } else {
301
- observableResult.observe(0);
302
- }
303
- };
304
- oldestAge.addCallback(oldestAgeCallback);
305
- this.observableCleanups.push(
306
- () => oldestAge.removeCallback(oldestAgeCallback)
307
- );
308
- const delivered = meter.createCounter(
309
- "autotel.event_delivery.queue.delivered",
310
- {
311
- description: "Number of events successfully delivered to subscribers",
312
- unit: "count"
313
- }
314
- );
315
- const failed = meter.createCounter("autotel.event_delivery.queue.failed", {
316
- description: "Number of events that failed delivery after all retry attempts",
317
- unit: "count"
318
- });
319
- const dropped = meter.createCounter(
320
- "autotel.event_delivery.queue.dropped",
321
- {
322
- description: "Number of events dropped from the queue",
323
- unit: "count"
324
- }
325
- );
326
- const latency = meter.createHistogram(
327
- "autotel.event_delivery.queue.latency_ms",
328
- {
329
- description: "Event delivery latency from enqueue to successful send",
330
- unit: "ms"
331
- }
332
- );
333
- const subscriberHealth = meter.createObservableGauge(
334
- "autotel.event_delivery.subscriber.health",
335
- {
336
- description: "Subscriber health status (1=healthy, 0=unhealthy)",
337
- unit: "1"
338
- }
339
- );
340
- const subscriberHealthCallback = (observableResult) => {
341
- for (const [subscriberName, isHealthy] of this.subscriberHealthy) {
342
- observableResult.observe(isHealthy ? 1 : 0, {
343
- subscriber: subscriberName
344
- });
345
- }
346
- };
347
- subscriberHealth.addCallback(subscriberHealthCallback);
348
- this.observableCleanups.push(
349
- () => subscriberHealth.removeCallback(subscriberHealthCallback)
350
- );
351
- this.metrics = {
352
- queueSize,
353
- oldestAge,
354
- delivered,
355
- failed,
356
- dropped,
357
- latency,
358
- subscriberHealth
359
- };
360
- }
361
- /**
362
- * Record a dropped event with reason and emit debug breadcrumb
363
- */
364
- recordDropped(reason, event, subscriberName) {
365
- const attrs = { reason };
366
- if (subscriberName) {
367
- attrs.subscriber = subscriberName;
368
- }
369
- this.metrics?.dropped.add(1, attrs);
370
- const logLevel = reason === "payload_invalid" ? "error" : "warn";
371
- const logger = getLogger();
372
- if (logLevel === "error") {
373
- logger.error(
374
- {
375
- eventName: event?.name,
376
- subscriber: subscriberName,
377
- reason,
378
- correlationId: event?._correlationId,
379
- traceId: event?._traceId
380
- },
381
- `[autotel] Event dropped: ${reason}`
382
- );
383
- } else {
384
- logger.warn(
385
- {
386
- eventName: event?.name,
387
- subscriber: subscriberName,
388
- reason,
389
- correlationId: event?._correlationId,
390
- traceId: event?._traceId
391
- },
392
- `[autotel] Event dropped: ${reason}`
393
- );
394
- }
395
- }
396
- /**
397
- * Record permanent delivery failure (after all retries exhausted)
398
- * Increments failed counter and logs error
399
- */
400
- recordFailed(event, subscriberName, error) {
401
- this.metrics?.failed.add(1, { subscriber: subscriberName });
402
- this.subscriberHealthy.set(subscriberName, false);
403
- getLogger().error(
404
- {
405
- eventName: event.name,
406
- subscriber: subscriberName,
407
- correlationId: event._correlationId,
408
- traceId: event._traceId,
409
- err: error
410
- },
411
- `[autotel] Event delivery failed after all retries`
412
- );
413
- }
414
- /**
415
- * Mark subscriber as unhealthy on transient failure (without incrementing failed counter)
416
- * Used during retry attempts - only recordFailed should increment the counter
417
- */
418
- markSubscriberUnhealthy(subscriberName) {
419
- this.subscriberHealthy.set(subscriberName, false);
420
- }
421
- /**
422
- * Record successful delivery
423
- */
424
- recordDelivered(event, subscriberName, startTime) {
425
- const latencyMs = Date.now() - startTime;
426
- this.metrics?.delivered.add(1, { subscriber: subscriberName });
427
- this.metrics?.latency.record(latencyMs, { subscriber: subscriberName });
428
- this.subscriberHealthy.set(subscriberName, true);
429
- }
430
- /**
431
- * Enqueue an event for sending
432
- *
433
- * Backpressure policy:
434
- * - Drops oldest event and logs warning if queue is full (same behavior in all environments)
435
- */
436
- enqueue(event) {
437
- if (this.isShuttingDown) {
438
- this.recordDropped("shutdown", event);
439
- return;
440
- }
441
- if (this.queue.length >= this.config.maxSize) {
442
- const droppedEvent = this.queue.shift();
443
- this.recordDropped("rate_limit", droppedEvent);
444
- getLogger().warn(
445
- {
446
- droppedEvent: droppedEvent?.name
447
- },
448
- `[autotel] Events queue full (${this.config.maxSize} events). Dropping oldest event. Events are being produced faster than they can be sent. Check your subscribers or reduce tracking frequency.`
449
- );
450
- }
451
- const enrichedEvent = {
452
- ...event,
453
- _correlationId: event._correlationId || getOrCreateCorrelationId()
454
- };
455
- this.queue.push(enrichedEvent);
456
- this.scheduleBatchFlush();
457
- }
458
- /**
459
- * Schedule a batch flush if not already scheduled
460
- */
461
- scheduleBatchFlush() {
462
- if (this.flushTimer || this.flushPromise) return;
463
- this.flushTimer = setTimeout(() => {
464
- this.flushTimer = null;
465
- void this.flushBatch();
466
- }, this.config.flushInterval);
467
- }
468
- /**
469
- * Flush a batch of events
470
- * Uses promise-based concurrency control to prevent race conditions
471
- */
472
- async flushBatch() {
473
- if (this.queue.length === 0) return;
474
- if (this.flushPromise) {
475
- await this.flushPromise;
476
- return;
477
- }
478
- this.flushPromise = this.doFlushBatch();
479
- try {
480
- await this.flushPromise;
481
- } finally {
482
- this.flushPromise = null;
483
- if (this.queue.length > 0) {
484
- this.scheduleBatchFlush();
485
- }
486
- }
487
- }
488
- /**
489
- * Internal flush implementation
490
- */
491
- async doFlushBatch() {
492
- const batch = this.queue.splice(0, this.config.batchSize);
493
- await this.sendWithRetry(batch, this.config.maxRetries);
494
- }
495
- /**
496
- * Send events with exponential backoff retry
497
- * Tracks per-event, per-subscriber failures so failed counter reflects actual failed deliveries.
498
- * On retry, only failed (event, subscriber) pairs are re-sent to avoid double-counting delivered.
499
- */
500
- async sendWithRetry(events, retriesLeft, subscribersByEventIndex) {
501
- const failedDeliveries = await this.sendToSubscribers(
502
- events,
503
- subscribersByEventIndex
504
- );
505
- if (failedDeliveries.length > 0) {
506
- if (retriesLeft > 0) {
507
- const failedEventIndices = new Set(
508
- failedDeliveries.map((f) => f.eventIndex)
509
- );
510
- const failedEventIndicesOrdered = [...failedEventIndices].sort(
511
- (a, b) => a - b
512
- );
513
- const eventsToRetry = failedEventIndicesOrdered.map(
514
- (i) => events[i]
515
- );
516
- const failedSubscribersByRetryIndex = /* @__PURE__ */ new Map();
517
- for (let j = 0; j < failedEventIndicesOrdered.length; j++) {
518
- const origIndex = failedEventIndicesOrdered[j];
519
- const set = /* @__PURE__ */ new Set();
520
- for (const { eventIndex, subscriberName } of failedDeliveries) {
521
- if (eventIndex === origIndex) set.add(subscriberName);
522
- }
523
- failedSubscribersByRetryIndex.set(j, set);
524
- }
525
- const delay = Math.pow(2, this.config.maxRetries - retriesLeft) * 1e3;
526
- await new Promise((resolve) => setTimeout(resolve, delay));
527
- return this.sendWithRetry(
528
- eventsToRetry,
529
- retriesLeft - 1,
530
- failedSubscribersByRetryIndex
531
- );
532
- } else {
533
- for (const { eventIndex, subscriberName, error } of failedDeliveries) {
534
- const event = events[eventIndex];
535
- if (event) this.recordFailed(event, subscriberName, error);
536
- }
537
- const failedSubscriberNames = [
538
- ...new Set(failedDeliveries.map((f) => f.subscriberName))
539
- ];
540
- getLogger().error(
541
- {
542
- failedSubscribers: failedSubscriberNames,
543
- retriesAttempted: this.config.maxRetries
544
- },
545
- "[autotel] Failed to send events after retries"
546
- );
547
- }
548
- }
549
- }
550
- /**
551
- * Send events to configured subscribers with rate limiting and metrics.
552
- * When subscribersByEventIndex is provided (retry path), only those subscribers are tried per event.
553
- * Returns per-event, per-subscriber failures (empty if all succeeded).
554
- */
555
- async sendToSubscribers(events, subscribersByEventIndex) {
556
- const failedDeliveries = [];
557
- const sendOne = async (event, eventIndex) => {
558
- const subscriberNames = subscribersByEventIndex?.get(eventIndex);
559
- const failures = await this.sendEventToSubscribers(
560
- event,
561
- subscriberNames ?? void 0
562
- );
563
- for (const failure of failures) {
564
- failedDeliveries.push({
565
- eventIndex,
566
- subscriberName: failure.subscriberName,
567
- error: failure.error
568
- });
569
- }
570
- };
571
- if (!this.rateLimiter) {
572
- for (let i = 0; i < events.length; i++) {
573
- const event = events[i];
574
- if (event) await sendOne(event, i);
575
- }
576
- return failedDeliveries;
577
- }
578
- for (let i = 0; i < events.length; i++) {
579
- await this.rateLimiter.waitForToken();
580
- const event = events[i];
581
- if (event) await sendOne(event, i);
582
- }
583
- return failedDeliveries;
584
- }
585
- /**
586
- * Send a single event to subscribers.
587
- * - When subscriberNames is undefined (initial attempt): send to all subscribers.
588
- * - When subscriberNames is provided (retry): send only to those subscribers (never re-send to healthy ones).
589
- * Returns list of subscribers that failed (empty if all succeeded).
590
- */
591
- async sendEventToSubscribers(event, subscriberNames) {
592
- const startTime = event.timestamp;
593
- const failures = [];
594
- const subscribersToTry = subscriberNames === void 0 ? this.subscribers : this.subscribers.filter(
595
- (s) => subscriberNames.has(getSubscriberName(s))
596
- );
597
- const results = await Promise.allSettled(
598
- subscribersToTry.map(async (subscriber) => {
599
- const subscriberName = getSubscriberName(subscriber);
600
- try {
601
- await subscriber.trackEvent(event.name, event.attributes, {
602
- autotel: event.autotel,
603
- schema: event.schema
604
- });
605
- this.recordDelivered(event, subscriberName, startTime);
606
- return { subscriberName, success: true };
607
- } catch (error) {
608
- this.markSubscriberUnhealthy(subscriberName);
609
- return {
610
- subscriberName,
611
- success: false,
612
- error: error instanceof Error ? error : void 0
613
- };
614
- }
615
- })
616
- );
617
- for (const result of results) {
618
- if (result.status === "fulfilled" && !result.value.success) {
619
- failures.push({
620
- subscriberName: result.value.subscriberName,
621
- error: result.value.error
622
- });
623
- }
624
- }
625
- return failures;
626
- }
627
- /**
628
- * Flush all remaining events. Queue remains usable after flush (e.g. for
629
- * auto-flush at root span end). Use shutdown() when tearing down the queue.
630
- */
631
- async flush() {
632
- if (this.flushTimer) {
633
- clearTimeout(this.flushTimer);
634
- this.flushTimer = null;
635
- }
636
- if (this.flushPromise) {
637
- await this.flushPromise;
638
- }
639
- while (this.queue.length > 0) {
640
- await this.doFlushBatch();
641
- }
642
- }
643
- /**
644
- * Flush remaining events and permanently disable the queue (reject new events).
645
- * Use for process/SDK shutdown; use flush() for periodic or span-end drain.
646
- */
647
- async shutdown() {
648
- this.isShuttingDown = true;
649
- await this.flush();
650
- }
651
- /**
652
- * Cleanup observable metric callbacks to prevent memory leaks
653
- * Call this when destroying the EventQueue instance
654
- */
655
- cleanup() {
656
- for (const cleanupFn of this.observableCleanups) {
657
- try {
658
- cleanupFn();
659
- } catch {
660
- }
661
- }
662
- this.observableCleanups = [];
663
- }
664
- /**
665
- * Get queue size (for testing/debugging)
666
- */
667
- size() {
668
- return this.queue.length;
669
- }
670
- /**
671
- * Get subscriber health status (for testing/debugging)
672
- */
673
- getSubscriberHealth() {
674
- return new Map(this.subscriberHealthy);
675
- }
676
- /**
677
- * Check if a specific subscriber is healthy
678
- */
679
- isSubscriberHealthy(subscriberName) {
680
- return this.subscriberHealthy.get(subscriberName.toLowerCase()) ?? true;
681
- }
682
- /**
683
- * Manually mark a subscriber as healthy or unhealthy
684
- * (used for circuit breaker integration)
685
- */
686
- setSubscriberHealth(subscriberName, healthy) {
687
- this.subscriberHealthy.set(subscriberName.toLowerCase(), healthy);
688
- }
689
- };
690
-
691
- // src/validation.ts
692
- var DEFAULT_CONFIG2 = {
693
- maxEventNameLength: 100,
694
- maxAttributeKeyLength: 100,
695
- maxAttributeValueLength: 1e3,
696
- maxAttributeCount: 50,
697
- maxNestingDepth: 3,
698
- sensitivePatterns: [
699
- /password/i,
700
- /secret/i,
701
- /token/i,
702
- /api[_-]?key/i,
703
- /access[_-]?key/i,
704
- /private[_-]?key/i,
705
- /auth/i,
706
- /credential/i,
707
- /ssn/i,
708
- /credit[_-]?card/i
709
- ]
710
- };
711
- var ValidationError = class extends Error {
712
- constructor(message) {
713
- super(message);
714
- this.name = "ValidationError";
715
- }
716
- };
717
- function validateEventName(eventName, config = DEFAULT_CONFIG2) {
718
- if (typeof eventName !== "string") {
719
- throw new ValidationError(
720
- `Event name must be a string, got ${typeof eventName}`
721
- );
722
- }
723
- const trimmed = eventName.trim();
724
- if (trimmed.length === 0) {
725
- throw new ValidationError("Event name cannot be empty");
726
- }
727
- if (trimmed.length > config.maxEventNameLength) {
728
- throw new ValidationError(
729
- `Event name too long (${trimmed.length} chars). Max: ${config.maxEventNameLength}`
730
- );
731
- }
732
- if (!/^[a-zA-Z0-9._-]+$/.test(trimmed)) {
733
- throw new ValidationError(
734
- `Event name contains invalid characters: "${trimmed}". Use only letters, numbers, dots, underscores, and hyphens.`
735
- );
736
- }
737
- return trimmed;
738
- }
739
- function validateAttributes(attributes, config = DEFAULT_CONFIG2) {
740
- if (attributes === void 0 || attributes === null) {
741
- return void 0;
742
- }
743
- if (typeof attributes !== "object" || Array.isArray(attributes)) {
744
- throw new ValidationError("Attributes must be an object");
745
- }
746
- const keys = Object.keys(attributes);
747
- if (keys.length > config.maxAttributeCount) {
748
- throw new ValidationError(
749
- `Too many attributes (${keys.length}). Max: ${config.maxAttributeCount}`
750
- );
751
- }
752
- const sanitized = {};
753
- for (const key of keys) {
754
- if (key.length > config.maxAttributeKeyLength) {
755
- throw new ValidationError(
756
- `Attribute key too long: "${key.slice(0, 20)}..." (${key.length} chars). Max: ${config.maxAttributeKeyLength}`
757
- );
758
- }
759
- const value = attributes[key];
760
- const isSensitive = typeof value === "string" && config.sensitivePatterns.some((pattern) => pattern.test(key));
761
- if (isSensitive) {
762
- sanitized[key] = "[REDACTED]";
763
- continue;
764
- }
765
- sanitized[key] = sanitizeValue(value, config, 1);
766
- }
767
- return sanitized;
768
- }
769
- function sanitizeValue(value, config, depth) {
770
- if (depth > config.maxNestingDepth) {
771
- return "[MAX_DEPTH_EXCEEDED]";
772
- }
773
- if (value === null || value === void 0) {
774
- return value;
775
- }
776
- if (typeof value === "string") {
777
- if (value.length > config.maxAttributeValueLength) {
778
- return value.slice(0, config.maxAttributeValueLength) + "...";
779
- }
780
- return value;
781
- }
782
- if (typeof value === "number" || typeof value === "boolean") {
783
- return value;
784
- }
785
- if (Array.isArray(value)) {
786
- return value.map((item) => sanitizeValue(item, config, depth + 1));
787
- }
788
- if (typeof value === "object") {
789
- try {
790
- JSON.stringify(value);
791
- const sanitized = {};
792
- for (const key in value) {
793
- if (Object.prototype.hasOwnProperty.call(value, key)) {
794
- const nested = value[key];
795
- const isSensitive = typeof nested === "string" && config.sensitivePatterns.some((pattern) => pattern.test(key));
796
- sanitized[key] = isSensitive ? "[REDACTED]" : sanitizeValue(nested, config, depth + 1);
797
- }
798
- }
799
- return sanitized;
800
- } catch {
801
- return "[CIRCULAR]";
802
- }
803
- }
804
- return `[${typeof value}]`;
805
- }
806
- function validateEvent(eventName, attributes, config) {
807
- const fullConfig = { ...DEFAULT_CONFIG2, ...config };
808
- return {
809
- eventName: validateEventName(eventName, fullConfig),
810
- attributes: validateAttributes(attributes, fullConfig)
811
- };
812
- }
813
-
814
- // src/track.ts
815
- var eventsQueue = null;
816
- function buildAutotelContext(span) {
817
- const eventsConfig = getEventsConfig();
818
- const config = getConfig();
819
- const correlationId = getOrCreateCorrelationId();
820
- if (!eventsConfig?.includeTraceContext) {
821
- return {
822
- correlation_id: correlationId
823
- };
824
- }
825
- const autotelContext = {
826
- correlation_id: correlationId
827
- };
828
- const spanContext = span?.spanContext();
829
- if (spanContext) {
830
- autotelContext.trace_id = spanContext.traceId;
831
- autotelContext.span_id = spanContext.spanId;
832
- autotelContext.trace_flags = spanContext.traceFlags.toString(16).padStart(2, "0");
833
- const traceState = spanContext.traceState;
834
- if (traceState) {
835
- try {
836
- if (typeof traceState.serialize === "function") {
837
- const traceStateStr = traceState.serialize();
838
- if (traceStateStr) {
839
- autotelContext.trace_state = traceStateStr;
840
- }
841
- }
842
- } catch {
843
- }
844
- }
845
- if (eventsConfig.traceUrl && config) {
846
- const traceUrl = eventsConfig.traceUrl({
847
- traceId: spanContext.traceId,
848
- spanId: spanContext.spanId,
849
- correlationId,
850
- serviceName: config.service,
851
- environment: config.environment
852
- });
853
- if (traceUrl) {
854
- autotelContext.trace_url = traceUrl;
855
- }
856
- }
857
- } else {
858
- if (eventsConfig.traceUrl && config) {
859
- const traceUrl = eventsConfig.traceUrl({
860
- correlationId,
861
- serviceName: config.service,
862
- environment: config.environment
863
- });
864
- if (traceUrl) {
865
- autotelContext.trace_url = traceUrl;
866
- }
867
- }
868
- }
869
- return autotelContext;
870
- }
871
- function getOrCreateQueue() {
872
- if (!isInitialized()) {
873
- warnIfNotInitialized("track()");
874
- return null;
875
- }
876
- if (!eventsQueue) {
877
- const config = getConfig();
878
- if (!config?.subscribers || config.subscribers.length === 0) {
879
- return null;
880
- }
881
- eventsQueue = new EventQueue(config.subscribers);
882
- }
883
- return eventsQueue;
884
- }
885
- function track(event, data, options) {
886
- const queue = getOrCreateQueue();
887
- if (!queue) return;
888
- const validationConfig = getValidationConfig();
889
- const validated = validateEvent(event, data, validationConfig || void 0);
890
- const span = trace.getActiveSpan();
891
- const enrichedData = span ? {
892
- ...validated.attributes,
893
- traceId: span.spanContext().traceId,
894
- spanId: span.spanContext().spanId
895
- } : validated.attributes;
896
- const autotelContext = buildAutotelContext(span);
897
- queue.enqueue({
898
- name: validated.eventName,
899
- attributes: enrichedData,
900
- timestamp: Date.now(),
901
- autotel: autotelContext,
902
- schema: options?.schema
903
- });
904
- }
905
- function getEventQueue() {
906
- return eventsQueue;
907
- }
908
- function resetEventQueue() {
909
- eventsQueue = null;
910
- }
911
-
912
- // src/trace-context.ts
913
- var contextStorage = new AsyncLocalStorage();
914
- function getContextStorage() {
915
- return contextStorage;
916
- }
917
- function getActiveContextWithBaggage() {
918
- const stored = contextStorage.getStore()?.value;
919
- return stored ?? context.active();
920
- }
921
- function enterOrRun(storage, value) {
922
- const existingStore = storage.getStore();
923
- if (existingStore) {
924
- existingStore.value = value;
925
- return;
926
- }
927
- const boxedValue = { value };
928
- try {
929
- storage.enterWith(boxedValue);
930
- } catch {
931
- storage.run(boxedValue, () => {
932
- });
933
- }
934
- }
935
- function updateActiveContext(newContext) {
936
- enterOrRun(contextStorage, newContext);
937
- const contextWithManager = context;
938
- const manager = contextWithManager._getContextManager?.();
939
- if (!manager) return;
940
- const asyncLocal = manager._asyncLocalStorage ?? void 0;
941
- if (asyncLocal?.enterWith) {
942
- asyncLocal.enterWith(newContext);
943
- return;
944
- }
945
- if (typeof manager.with === "function") {
946
- manager.with(newContext, () => {
947
- });
948
- }
949
- }
950
- function createTraceContext(span) {
951
- const spanContext = span.spanContext();
952
- const existingStored = contextStorage.getStore()?.value;
953
- if (!existingStored) {
954
- const activeContext = context.active();
955
- enterOrRun(contextStorage, activeContext);
956
- }
957
- const baggageHelpers = {
958
- getBaggage(key) {
959
- const activeCtx = context.active();
960
- let baggage = propagation.getBaggage(activeCtx);
961
- if (!baggage) {
962
- const storedContext = contextStorage.getStore()?.value;
963
- if (storedContext) {
964
- baggage = propagation.getBaggage(storedContext);
965
- }
966
- }
967
- return baggage?.getEntry(key)?.value;
968
- },
969
- setBaggage(key, value) {
970
- const activeCtx = context.active();
971
- const storedContext = contextStorage.getStore()?.value;
972
- const currentContext = storedContext ?? activeCtx;
973
- const baggage = propagation.getBaggage(currentContext) ?? propagation.createBaggage();
974
- const updated = baggage.setEntry(key, { value });
975
- const newContext = propagation.setBaggage(currentContext, updated);
976
- updateActiveContext(newContext);
977
- return value;
978
- },
979
- deleteBaggage(key) {
980
- const activeCtx = context.active();
981
- const storedContext = contextStorage.getStore()?.value;
982
- const currentContext = storedContext ?? activeCtx;
983
- const baggage = propagation.getBaggage(currentContext);
984
- if (baggage) {
985
- const updated = baggage.removeEntry(key);
986
- const newContext = propagation.setBaggage(currentContext, updated);
987
- updateActiveContext(newContext);
988
- }
989
- },
990
- getAllBaggage() {
991
- const activeCtx = context.active();
992
- let baggage = propagation.getBaggage(activeCtx);
993
- if (!baggage) {
994
- const storedContext = contextStorage.getStore()?.value;
995
- if (storedContext) {
996
- baggage = propagation.getBaggage(storedContext);
997
- }
998
- }
999
- if (!baggage) {
1000
- return /* @__PURE__ */ new Map();
1001
- }
1002
- const entries = /* @__PURE__ */ new Map();
1003
- for (const [key, entry] of baggage.getAllEntries()) {
1004
- entries.set(key, entry);
1005
- }
1006
- return entries;
1007
- },
1008
- // Typed baggage helpers (used by defineBaggageSchema)
1009
- getTypedBaggage: ((namespace) => {
1010
- const activeCtx = context.active();
1011
- let baggage = propagation.getBaggage(activeCtx);
1012
- if (!baggage) {
1013
- const storedContext = contextStorage.getStore()?.value;
1014
- if (storedContext) {
1015
- baggage = propagation.getBaggage(storedContext);
1016
- }
1017
- }
1018
- if (!baggage) return;
1019
- const prefix = namespace ? `${namespace}.` : "";
1020
- const result = {};
1021
- for (const [key, entry] of baggage.getAllEntries()) {
1022
- if (namespace && key.startsWith(prefix)) {
1023
- const fieldName = key.slice(prefix.length);
1024
- result[fieldName] = entry.value;
1025
- } else if (!namespace) {
1026
- result[key] = entry.value;
1027
- }
1028
- }
1029
- return Object.keys(result).length > 0 ? result : void 0;
1030
- }),
1031
- setTypedBaggage: ((namespace, value) => {
1032
- const activeCtx = context.active();
1033
- const storedContext = contextStorage.getStore()?.value;
1034
- const currentContext = storedContext ?? activeCtx;
1035
- let baggage = propagation.getBaggage(currentContext) ?? propagation.createBaggage();
1036
- const prefix = namespace ? `${namespace}.` : "";
1037
- for (const [key, val] of Object.entries(value)) {
1038
- if (val !== void 0) {
1039
- const baggageKey = `${prefix}${key}`;
1040
- baggage = baggage.setEntry(baggageKey, { value: String(val) });
1041
- }
1042
- }
1043
- const newContext = propagation.setBaggage(currentContext, baggage);
1044
- updateActiveContext(newContext);
1045
- })
1046
- };
1047
- const traceCtx = {
1048
- traceId: spanContext.traceId,
1049
- spanId: spanContext.spanId,
1050
- correlationId: spanContext.traceId.slice(0, 16),
1051
- setAttribute: span.setAttribute.bind(span),
1052
- setAttributes: span.setAttributes.bind(span),
1053
- setStatus: span.setStatus.bind(span),
1054
- recordException: span.recordException.bind(span),
1055
- addEvent: span.addEvent.bind(span),
1056
- addLink: span.addLink.bind(span),
1057
- addLinks: span.addLinks.bind(span),
1058
- updateName: span.updateName.bind(span),
1059
- isRecording: span.isRecording.bind(span),
1060
- recordError: (error) => {
1061
- const err = error instanceof Error ? error : new Error(String(error));
1062
- recordStructuredError(traceCtx, err);
1063
- },
1064
- track: (event, data) => {
1065
- track(event, data);
1066
- },
1067
- ...baggageHelpers
1068
- };
1069
- return traceCtx;
1070
- }
1071
- function defineBaggageSchema(namespace) {
1072
- return {
1073
- /**
1074
- * Get typed baggage from context
1075
- * @param ctx - Trace context
1076
- * @returns Partial baggage object or undefined if no baggage is set
1077
- */
1078
- get: (ctx) => {
1079
- if (!ctx.getTypedBaggage) return void 0;
1080
- return ctx.getTypedBaggage(namespace);
1081
- },
1082
- /**
1083
- * Set typed baggage in context
1084
- *
1085
- * Note: For proper scoping across async boundaries, use the `with` method instead
1086
- *
1087
- * @param ctx - Trace context
1088
- * @param value - Partial baggage object to set
1089
- */
1090
- set: (ctx, value) => {
1091
- if (!ctx.setTypedBaggage) return;
1092
- ctx.setTypedBaggage(namespace, value);
1093
- },
1094
- /**
1095
- * Run a function with typed baggage properly scoped
1096
- *
1097
- * This is the recommended way to set baggage as it ensures proper
1098
- * scoping across async boundaries.
1099
- *
1100
- * @param ctx - Trace context (can be omitted, will use active context)
1101
- * @param value - Partial baggage object to set
1102
- * @param fn - Function to execute with the baggage
1103
- */
1104
- with: (ctxOrValue, valueOrFn, maybeFn) => {
1105
- const value = maybeFn ? valueOrFn : ctxOrValue;
1106
- const fn = maybeFn || valueOrFn;
1107
- const prefix = namespace ? `${namespace}.` : "";
1108
- const flatBaggage = {};
1109
- for (const [key, val] of Object.entries(value)) {
1110
- if (val !== void 0) {
1111
- flatBaggage[`${prefix}${key}`] = String(val);
1112
- }
1113
- }
1114
- const currentContext = context.active();
1115
- let baggage = propagation.getBaggage(currentContext) ?? propagation.createBaggage();
1116
- for (const [key, val] of Object.entries(flatBaggage)) {
1117
- baggage = baggage.setEntry(key, { value: val });
1118
- }
1119
- const newContext = propagation.setBaggage(currentContext, baggage);
1120
- return context.with(newContext, fn);
1121
- }
1122
- };
1123
- }
1124
-
1125
- // src/correlation-id.ts
1126
- var correlationStorage = new AsyncLocalStorage();
1127
- var CORRELATION_ID_BAGGAGE_KEY = "autotel.correlation_id";
1128
- function generateCorrelationId() {
1129
- const bytes = new Uint8Array(8);
1130
- crypto.getRandomValues(bytes);
1131
- return [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
1132
- }
1133
- function getCorrelationId() {
1134
- const storedId = correlationStorage.getStore()?.value;
1135
- if (storedId) {
1136
- return storedId;
1137
- }
1138
- const activeContext = context.active();
1139
- const baggage = propagation.getBaggage(activeContext);
1140
- const baggageEntry = baggage?.getEntry(CORRELATION_ID_BAGGAGE_KEY);
1141
- if (baggageEntry?.value) {
1142
- return baggageEntry.value;
1143
- }
1144
- const span = trace.getActiveSpan();
1145
- if (span) {
1146
- const spanContext = span.spanContext();
1147
- return spanContext.traceId.slice(0, 16);
1148
- }
1149
- return void 0;
1150
- }
1151
- function getOrCreateCorrelationId() {
1152
- return getCorrelationId() ?? generateCorrelationId();
1153
- }
1154
- function runWithCorrelationId(correlationId, fn) {
1155
- return correlationStorage.run({ value: correlationId }, fn);
1156
- }
1157
- function setCorrelationId(correlationId) {
1158
- enterOrRun(correlationStorage, correlationId);
1159
- }
1160
- function setCorrelationIdInBaggage(correlationId) {
1161
- const activeContext = context.active();
1162
- let baggage = propagation.getBaggage(activeContext) ?? propagation.createBaggage();
1163
- baggage = baggage.setEntry(CORRELATION_ID_BAGGAGE_KEY, {
1164
- value: correlationId
1165
- });
1166
- return propagation.setBaggage(activeContext, baggage);
1167
- }
1168
- function getCorrelationStorage() {
1169
- return correlationStorage;
1170
- }
1171
-
1172
- export { CORRELATION_ID_BAGGAGE_KEY, createStructuredError, createTraceContext, defineBaggageSchema, enterOrRun, flattenToAttributes, generateCorrelationId, getActiveContextWithBaggage, getContextStorage, getCorrelationId, getCorrelationStorage, getEventQueue, getOrCreateCorrelationId, getStructuredErrorAttributes, recordStructuredError, resetEventQueue, runWithCorrelationId, setCorrelationId, setCorrelationIdInBaggage, structuredErrorToJSON, toAttributeValue, track, validateEvent };
1173
- //# sourceMappingURL=chunk-O4JZUCUE.js.map
1174
- //# sourceMappingURL=chunk-O4JZUCUE.js.map