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