autotel 4.3.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (384) hide show
  1. package/README.md +125 -103
  2. package/dist/analysis.cjs +87 -0
  3. package/dist/analysis.cjs.map +1 -0
  4. package/dist/analysis.d.cts +87 -0
  5. package/dist/analysis.d.cts.map +1 -0
  6. package/dist/analysis.d.ts +87 -0
  7. package/dist/analysis.d.ts.map +1 -0
  8. package/dist/analysis.js +85 -0
  9. package/dist/analysis.js.map +1 -0
  10. package/dist/{attribute-redacting-processor-DtTS9xxh.d.ts → attribute-redacting-processor-Pk7lAzWd.d.cts} +13 -8
  11. package/dist/attribute-redacting-processor-Pk7lAzWd.d.cts.map +1 -0
  12. package/dist/{attribute-redacting-processor-DtTS9xxh.d.cts → attribute-redacting-processor-Pk7lAzWd.d.ts} +13 -8
  13. package/dist/attribute-redacting-processor-Pk7lAzWd.d.ts.map +1 -0
  14. package/dist/attribute-redacting-processor.cjs +4 -4
  15. package/dist/attribute-redacting-processor.cjs.map +1 -1
  16. package/dist/attribute-redacting-processor.d.cts +1 -1
  17. package/dist/attribute-redacting-processor.d.ts +1 -1
  18. package/dist/attribute-redacting-processor.js +4 -4
  19. package/dist/attribute-redacting-processor.js.map +1 -1
  20. package/dist/attributes.d.cts +1 -1
  21. package/dist/attributes.d.ts +1 -1
  22. package/dist/auto.cjs +1 -1
  23. package/dist/auto.cjs.map +1 -1
  24. package/dist/auto.d.cts +1 -1
  25. package/dist/auto.d.ts +1 -1
  26. package/dist/auto.js +1 -1
  27. package/dist/auto.js.map +1 -1
  28. package/dist/business-baggage.d.cts +2 -3
  29. package/dist/business-baggage.d.cts.map +1 -1
  30. package/dist/business-baggage.d.ts +2 -3
  31. package/dist/business-baggage.d.ts.map +1 -1
  32. package/dist/{canonical-log-line-processor-xvjMgtpF.d.cts → canonical-log-line-processor-B4WgG-VS.d.cts} +2 -3
  33. package/dist/canonical-log-line-processor-B4WgG-VS.d.cts.map +1 -0
  34. package/dist/{canonical-log-line-processor-BcRuAdRk.d.ts → canonical-log-line-processor-CL_J7gb5.d.ts} +2 -3
  35. package/dist/canonical-log-line-processor-CL_J7gb5.d.ts.map +1 -0
  36. package/dist/{canonical-log-line-processor-CcrDi6TO.cjs → canonical-log-line-processor-DOjb6Kxy.cjs} +5 -5
  37. package/dist/canonical-log-line-processor-DOjb6Kxy.cjs.map +1 -0
  38. package/dist/{canonical-log-line-processor-FLezvFCB.js → canonical-log-line-processor-mKABvGP0.js} +5 -5
  39. package/dist/canonical-log-line-processor-mKABvGP0.js.map +1 -0
  40. package/dist/config.d.cts +12 -7
  41. package/dist/config.d.cts.map +1 -1
  42. package/dist/config.d.ts +12 -7
  43. package/dist/config.d.ts.map +1 -1
  44. package/dist/correlation-id.cjs +9 -9
  45. package/dist/correlation-id.d.cts +0 -1
  46. package/dist/correlation-id.d.cts.map +1 -1
  47. package/dist/correlation-id.d.ts +0 -1
  48. package/dist/correlation-id.d.ts.map +1 -1
  49. package/dist/correlation-id.js +1 -1
  50. package/dist/db.d.cts.map +1 -1
  51. package/dist/db.d.ts.map +1 -1
  52. package/dist/decorators.cjs +2 -2
  53. package/dist/decorators.cjs.map +1 -1
  54. package/dist/decorators.d.cts +1 -2
  55. package/dist/decorators.d.cts.map +1 -1
  56. package/dist/decorators.d.ts +1 -2
  57. package/dist/decorators.d.ts.map +1 -1
  58. package/dist/decorators.js +1 -1
  59. package/dist/decorators.js.map +1 -1
  60. package/dist/{define-event-CreknLm3.d.ts → define-event-B2z1SBe7.d.ts} +2 -3
  61. package/dist/define-event-B2z1SBe7.d.ts.map +1 -0
  62. package/dist/{define-event-HZRizPwz.d.cts → define-event-CGG048HE.d.cts} +2 -3
  63. package/dist/define-event-CGG048HE.d.cts.map +1 -0
  64. package/dist/diagnostics.cjs +10 -1
  65. package/dist/diagnostics.cjs.map +1 -1
  66. package/dist/diagnostics.d.cts +0 -1
  67. package/dist/diagnostics.d.cts.map +1 -1
  68. package/dist/diagnostics.d.ts +0 -1
  69. package/dist/diagnostics.d.ts.map +1 -1
  70. package/dist/diagnostics.js +10 -1
  71. package/dist/diagnostics.js.map +1 -1
  72. package/dist/drain-pipeline.d.cts +12 -5
  73. package/dist/drain-pipeline.d.cts.map +1 -1
  74. package/dist/drain-pipeline.d.ts +12 -5
  75. package/dist/drain-pipeline.d.ts.map +1 -1
  76. package/dist/enrichers.d.cts.map +1 -1
  77. package/dist/enrichers.d.ts.map +1 -1
  78. package/dist/{event-subscriber-D1XLkPzi.d.ts → event-subscriber-CWh8sTGh.d.cts} +2 -2
  79. package/dist/event-subscriber-CWh8sTGh.d.cts.map +1 -0
  80. package/dist/{event-subscriber-D1XLkPzi.d.cts → event-subscriber-CWh8sTGh.d.ts} +2 -2
  81. package/dist/event-subscriber-CWh8sTGh.d.ts.map +1 -0
  82. package/dist/event-subscriber.d.cts +1 -1
  83. package/dist/event-subscriber.d.ts +1 -1
  84. package/dist/{event-testing-CfFs3to2.d.ts → event-testing-CA2mIx1E.d.ts} +2 -3
  85. package/dist/event-testing-CA2mIx1E.d.ts.map +1 -0
  86. package/dist/{event-testing-BqRnI0z4.d.cts → event-testing-D0qWfqAy.d.cts} +2 -3
  87. package/dist/event-testing-D0qWfqAy.d.cts.map +1 -0
  88. package/dist/event-testing.d.cts +1 -1
  89. package/dist/event-testing.d.ts +1 -1
  90. package/dist/event.cjs +4 -4
  91. package/dist/event.d.cts +3 -4
  92. package/dist/event.d.cts.map +1 -1
  93. package/dist/event.d.ts +3 -4
  94. package/dist/event.d.ts.map +1 -1
  95. package/dist/event.js +1 -1
  96. package/dist/exporters.d.cts +0 -4
  97. package/dist/exporters.d.cts.map +1 -1
  98. package/dist/exporters.d.ts +0 -4
  99. package/dist/exporters.d.ts.map +1 -1
  100. package/dist/{filtering-span-processor-B8R8B7Uk.d.ts → filtering-span-processor-BpDagWNa.d.cts} +1 -2
  101. package/dist/filtering-span-processor-BpDagWNa.d.cts.map +1 -0
  102. package/dist/{filtering-span-processor-B8R8B7Uk.d.cts → filtering-span-processor-BpDagWNa.d.ts} +1 -2
  103. package/dist/filtering-span-processor-BpDagWNa.d.ts.map +1 -0
  104. package/dist/filtering-span-processor.d.cts +1 -1
  105. package/dist/filtering-span-processor.d.ts +1 -1
  106. package/dist/functional-BnDUxnSl.js +838 -0
  107. package/dist/functional-BnDUxnSl.js.map +1 -0
  108. package/dist/functional-DcLBuCPz.cjs +888 -0
  109. package/dist/functional-DcLBuCPz.cjs.map +1 -0
  110. package/dist/functional.cjs +2 -2
  111. package/dist/functional.d.cts +79 -130
  112. package/dist/functional.d.cts.map +1 -1
  113. package/dist/functional.d.ts +79 -130
  114. package/dist/functional.d.ts.map +1 -1
  115. package/dist/functional.js +2 -2
  116. package/dist/http.cjs +6 -6
  117. package/dist/http.cjs.map +1 -1
  118. package/dist/http.d.cts +4 -5
  119. package/dist/http.d.cts.map +1 -1
  120. package/dist/http.d.ts +4 -5
  121. package/dist/http.d.ts.map +1 -1
  122. package/dist/http.js +5 -5
  123. package/dist/http.js.map +1 -1
  124. package/dist/{index-eKuioqT1.d.cts → index-BPcxVucm.d.cts} +2 -3
  125. package/dist/index-BPcxVucm.d.cts.map +1 -0
  126. package/dist/{index-Ck06vlW2.d.ts → index-DolOVX6F.d.ts} +2 -3
  127. package/dist/index-DolOVX6F.d.ts.map +1 -0
  128. package/dist/index.cjs +25 -167
  129. package/dist/index.cjs.map +1 -1
  130. package/dist/index.d.cts +14 -14
  131. package/dist/index.d.cts.map +1 -1
  132. package/dist/index.d.ts +14 -14
  133. package/dist/index.d.ts.map +1 -1
  134. package/dist/index.js +6 -148
  135. package/dist/index.js.map +1 -1
  136. package/dist/init-C3RApHKJ.cjs +3371 -0
  137. package/dist/init-C3RApHKJ.cjs.map +1 -0
  138. package/dist/{init-DSrRmVnz.d.cts → init-D6n2diBy.d.ts} +46 -20
  139. package/dist/init-D6n2diBy.d.ts.map +1 -0
  140. package/dist/init-R-gSEXkJ.js +3190 -0
  141. package/dist/init-R-gSEXkJ.js.map +1 -0
  142. package/dist/{init-B7u-DjxM.d.ts → init-XzXzrarP.d.cts} +46 -20
  143. package/dist/init-XzXzrarP.d.cts.map +1 -0
  144. package/dist/instrumentation.cjs +7 -13
  145. package/dist/instrumentation.cjs.map +1 -1
  146. package/dist/instrumentation.d.cts +0 -1
  147. package/dist/instrumentation.d.cts.map +1 -1
  148. package/dist/instrumentation.d.ts +0 -1
  149. package/dist/instrumentation.d.ts.map +1 -1
  150. package/dist/instrumentation.js +8 -14
  151. package/dist/instrumentation.js.map +1 -1
  152. package/dist/{logger-BauSUhUv.d.ts → logger-CN4xpzMd.d.cts} +1 -2
  153. package/dist/logger-CN4xpzMd.d.cts.map +1 -0
  154. package/dist/{logger-BauSUhUv.d.cts → logger-CN4xpzMd.d.ts} +1 -2
  155. package/dist/logger-CN4xpzMd.d.ts.map +1 -0
  156. package/dist/logger-D3Ej3DII.js.map +1 -1
  157. package/dist/logger-thMPLpOG.cjs.map +1 -1
  158. package/dist/logger.d.cts +1 -1
  159. package/dist/logger.d.ts +1 -1
  160. package/dist/messaging-adapters.cjs.map +1 -1
  161. package/dist/messaging-adapters.d.cts +0 -1
  162. package/dist/messaging-adapters.d.cts.map +1 -1
  163. package/dist/messaging-adapters.d.ts +0 -1
  164. package/dist/messaging-adapters.d.ts.map +1 -1
  165. package/dist/messaging-adapters.js.map +1 -1
  166. package/dist/messaging-testing.d.cts +0 -1
  167. package/dist/messaging-testing.d.cts.map +1 -1
  168. package/dist/messaging-testing.d.ts +0 -1
  169. package/dist/messaging-testing.d.ts.map +1 -1
  170. package/dist/messaging.cjs +27 -10
  171. package/dist/messaging.cjs.map +1 -1
  172. package/dist/messaging.d.cts +6 -7
  173. package/dist/messaging.d.cts.map +1 -1
  174. package/dist/messaging.d.ts +6 -7
  175. package/dist/messaging.d.ts.map +1 -1
  176. package/dist/messaging.js +27 -10
  177. package/dist/messaging.js.map +1 -1
  178. package/dist/metric-helpers.d.cts +0 -1
  179. package/dist/metric-helpers.d.cts.map +1 -1
  180. package/dist/metric-helpers.d.ts +0 -1
  181. package/dist/metric-helpers.d.ts.map +1 -1
  182. package/dist/{metric-testing-DXdK3-Q3.d.ts → metric-testing-CWm6UhaR.d.ts} +2 -3
  183. package/dist/metric-testing-CWm6UhaR.d.ts.map +1 -0
  184. package/dist/{metric-testing-MxvzChDp.d.cts → metric-testing-CpvP3ZIa.d.cts} +2 -3
  185. package/dist/metric-testing-CpvP3ZIa.d.cts.map +1 -0
  186. package/dist/metric-testing.d.cts +1 -1
  187. package/dist/metric-testing.d.ts +1 -1
  188. package/dist/metric.d.cts +3 -4
  189. package/dist/metric.d.cts.map +1 -1
  190. package/dist/metric.d.ts +3 -4
  191. package/dist/metric.d.ts.map +1 -1
  192. package/dist/parse-error.d.cts.map +1 -1
  193. package/dist/parse-error.d.ts.map +1 -1
  194. package/dist/processors.cjs +1 -1
  195. package/dist/processors.d.cts +1 -1
  196. package/dist/processors.d.ts +1 -1
  197. package/dist/processors.js +1 -1
  198. package/dist/register.d.cts +1 -1
  199. package/dist/register.d.ts +1 -1
  200. package/dist/{sampling-DfYhDJij.d.cts → sampling-BR9fkSwx.d.cts} +127 -10
  201. package/dist/sampling-BR9fkSwx.d.cts.map +1 -0
  202. package/dist/{sampling-CR0Va1VB.d.ts → sampling-CP3e7-Yr.d.ts} +127 -10
  203. package/dist/sampling-CP3e7-Yr.d.ts.map +1 -0
  204. package/dist/sampling.cjs +160 -12
  205. package/dist/sampling.cjs.map +1 -1
  206. package/dist/sampling.d.cts +2 -2
  207. package/dist/sampling.d.ts +2 -2
  208. package/dist/sampling.js +157 -13
  209. package/dist/sampling.js.map +1 -1
  210. package/dist/security-schema.d.cts +9 -4
  211. package/dist/security-schema.d.cts.map +1 -1
  212. package/dist/security-schema.d.ts +9 -4
  213. package/dist/security-schema.d.ts.map +1 -1
  214. package/dist/semantic-conventions-FhSxv-bK.d.cts.map +1 -1
  215. package/dist/semantic-conventions-FhSxv-bK.d.ts.map +1 -1
  216. package/dist/semantic-conventions.cjs.map +1 -1
  217. package/dist/semantic-conventions.js.map +1 -1
  218. package/dist/semantic-helpers.cjs +85 -304
  219. package/dist/semantic-helpers.cjs.map +1 -1
  220. package/dist/semantic-helpers.d.cts +21 -12
  221. package/dist/semantic-helpers.d.cts.map +1 -1
  222. package/dist/semantic-helpers.d.ts +21 -12
  223. package/dist/semantic-helpers.d.ts.map +1 -1
  224. package/dist/semantic-helpers.js +85 -304
  225. package/dist/semantic-helpers.js.map +1 -1
  226. package/dist/slo.cjs +225 -0
  227. package/dist/slo.cjs.map +1 -0
  228. package/dist/slo.d.cts +97 -0
  229. package/dist/slo.d.cts.map +1 -0
  230. package/dist/slo.d.ts +97 -0
  231. package/dist/slo.d.ts.map +1 -0
  232. package/dist/slo.js +223 -0
  233. package/dist/slo.js.map +1 -0
  234. package/dist/{span-name-normalizer-8ZOGJuwv.d.ts → span-name-normalizer-CN1-8C76.d.cts} +1 -2
  235. package/dist/span-name-normalizer-CN1-8C76.d.cts.map +1 -0
  236. package/dist/{span-name-normalizer-8ZOGJuwv.d.cts → span-name-normalizer-CN1-8C76.d.ts} +1 -2
  237. package/dist/span-name-normalizer-CN1-8C76.d.ts.map +1 -0
  238. package/dist/span-name-normalizer.cjs.map +1 -1
  239. package/dist/span-name-normalizer.d.cts +1 -1
  240. package/dist/span-name-normalizer.d.ts +1 -1
  241. package/dist/span-name-normalizer.js.map +1 -1
  242. package/dist/tail-sampling-processor.d.cts +0 -1
  243. package/dist/tail-sampling-processor.d.cts.map +1 -1
  244. package/dist/tail-sampling-processor.d.ts +0 -1
  245. package/dist/tail-sampling-processor.d.ts.map +1 -1
  246. package/dist/test-span-collector.cjs.map +1 -1
  247. package/dist/test-span-collector.d.cts +0 -1
  248. package/dist/test-span-collector.d.cts.map +1 -1
  249. package/dist/test-span-collector.d.ts +0 -1
  250. package/dist/test-span-collector.d.ts.map +1 -1
  251. package/dist/test-span-collector.js.map +1 -1
  252. package/dist/testing.cjs +76 -11
  253. package/dist/testing.cjs.map +1 -1
  254. package/dist/testing.d.cts +30 -5
  255. package/dist/testing.d.cts.map +1 -1
  256. package/dist/testing.d.ts +30 -5
  257. package/dist/testing.d.ts.map +1 -1
  258. package/dist/testing.js +73 -12
  259. package/dist/testing.js.map +1 -1
  260. package/dist/{trace-context-Cijqoi6e.d.ts → trace-context-IuyoPyNq.d.cts} +9 -9
  261. package/dist/trace-context-IuyoPyNq.d.cts.map +1 -0
  262. package/dist/{trace-context-Cijqoi6e.d.cts → trace-context-IuyoPyNq.d.ts} +9 -9
  263. package/dist/trace-context-IuyoPyNq.d.ts.map +1 -0
  264. package/dist/trace-factory-validation-BjVAinz6.js +13 -0
  265. package/dist/trace-factory-validation-BjVAinz6.js.map +1 -0
  266. package/dist/trace-factory-validation-Dc8epn87.cjs +19 -0
  267. package/dist/trace-factory-validation-Dc8epn87.cjs.map +1 -0
  268. package/dist/trace-helpers.cjs +7 -7
  269. package/dist/trace-helpers.cjs.map +1 -1
  270. package/dist/trace-helpers.d.cts +6 -7
  271. package/dist/trace-helpers.d.cts.map +1 -1
  272. package/dist/trace-helpers.d.ts +6 -7
  273. package/dist/trace-helpers.d.ts.map +1 -1
  274. package/dist/trace-helpers.js +7 -7
  275. package/dist/trace-helpers.js.map +1 -1
  276. package/dist/tracer-provider.d.cts +0 -1
  277. package/dist/tracer-provider.d.cts.map +1 -1
  278. package/dist/tracer-provider.d.ts +0 -1
  279. package/dist/tracer-provider.d.ts.map +1 -1
  280. package/dist/validate.cjs.map +1 -1
  281. package/dist/validate.d.cts +1 -2
  282. package/dist/validate.d.cts.map +1 -1
  283. package/dist/validate.d.ts +1 -2
  284. package/dist/validate.d.ts.map +1 -1
  285. package/dist/validate.js.map +1 -1
  286. package/dist/validation-attributes.d.cts +17 -8
  287. package/dist/validation-attributes.d.cts.map +1 -1
  288. package/dist/validation-attributes.d.ts +17 -8
  289. package/dist/validation-attributes.d.ts.map +1 -1
  290. package/dist/webhook.cjs +5 -4
  291. package/dist/webhook.cjs.map +1 -1
  292. package/dist/webhook.d.cts +4 -4
  293. package/dist/webhook.d.cts.map +1 -1
  294. package/dist/webhook.d.ts +4 -4
  295. package/dist/webhook.d.ts.map +1 -1
  296. package/dist/webhook.js +5 -4
  297. package/dist/webhook.js.map +1 -1
  298. package/dist/workflow-distributed.cjs +5 -5
  299. package/dist/workflow-distributed.cjs.map +1 -1
  300. package/dist/workflow-distributed.d.cts +25 -15
  301. package/dist/workflow-distributed.d.cts.map +1 -1
  302. package/dist/workflow-distributed.d.ts +25 -15
  303. package/dist/workflow-distributed.d.ts.map +1 -1
  304. package/dist/workflow-distributed.js +5 -5
  305. package/dist/workflow-distributed.js.map +1 -1
  306. package/dist/workflow.cjs +24 -30
  307. package/dist/workflow.cjs.map +1 -1
  308. package/dist/workflow.d.cts +11 -6
  309. package/dist/workflow.d.cts.map +1 -1
  310. package/dist/workflow.d.ts +11 -6
  311. package/dist/workflow.d.ts.map +1 -1
  312. package/dist/workflow.js +24 -30
  313. package/dist/workflow.js.map +1 -1
  314. package/dist/yaml-config.d.cts +2 -3
  315. package/dist/yaml-config.d.cts.map +1 -1
  316. package/dist/yaml-config.d.ts +2 -3
  317. package/dist/yaml-config.d.ts.map +1 -1
  318. package/package.json +24 -16
  319. package/dist/attribute-redacting-processor-DtTS9xxh.d.cts.map +0 -1
  320. package/dist/attribute-redacting-processor-DtTS9xxh.d.ts.map +0 -1
  321. package/dist/canonical-log-line-processor-BcRuAdRk.d.ts.map +0 -1
  322. package/dist/canonical-log-line-processor-CcrDi6TO.cjs.map +0 -1
  323. package/dist/canonical-log-line-processor-FLezvFCB.js.map +0 -1
  324. package/dist/canonical-log-line-processor-xvjMgtpF.d.cts.map +0 -1
  325. package/dist/define-event-CreknLm3.d.ts.map +0 -1
  326. package/dist/define-event-HZRizPwz.d.cts.map +0 -1
  327. package/dist/event-BEm5IJ8U.js +0 -761
  328. package/dist/event-BEm5IJ8U.js.map +0 -1
  329. package/dist/event-rzA1X5h3.cjs +0 -778
  330. package/dist/event-rzA1X5h3.cjs.map +0 -1
  331. package/dist/event-subscriber-D1XLkPzi.d.cts.map +0 -1
  332. package/dist/event-subscriber-D1XLkPzi.d.ts.map +0 -1
  333. package/dist/event-testing-BqRnI0z4.d.cts.map +0 -1
  334. package/dist/event-testing-CfFs3to2.d.ts.map +0 -1
  335. package/dist/filtering-span-processor-B8R8B7Uk.d.cts.map +0 -1
  336. package/dist/filtering-span-processor-B8R8B7Uk.d.ts.map +0 -1
  337. package/dist/functional-CwsPyc4l.cjs +0 -1298
  338. package/dist/functional-CwsPyc4l.cjs.map +0 -1
  339. package/dist/functional-dAYhXQPA.js +0 -1248
  340. package/dist/functional-dAYhXQPA.js.map +0 -1
  341. package/dist/index-Ck06vlW2.d.ts.map +0 -1
  342. package/dist/index-eKuioqT1.d.cts.map +0 -1
  343. package/dist/init-B7u-DjxM.d.ts.map +0 -1
  344. package/dist/init-BvBB45-T.js +0 -1034
  345. package/dist/init-BvBB45-T.js.map +0 -1
  346. package/dist/init-BxJEJ9Tn.cjs +0 -1111
  347. package/dist/init-BxJEJ9Tn.cjs.map +0 -1
  348. package/dist/init-DSrRmVnz.d.cts.map +0 -1
  349. package/dist/logger-BauSUhUv.d.cts.map +0 -1
  350. package/dist/logger-BauSUhUv.d.ts.map +0 -1
  351. package/dist/metric-testing-DXdK3-Q3.d.ts.map +0 -1
  352. package/dist/metric-testing-MxvzChDp.d.cts.map +0 -1
  353. package/dist/operation-context-CKBoA4Qy.js +0 -59
  354. package/dist/operation-context-CKBoA4Qy.js.map +0 -1
  355. package/dist/operation-context-hzKbTKnt.cjs +0 -72
  356. package/dist/operation-context-hzKbTKnt.cjs.map +0 -1
  357. package/dist/sampling-CR0Va1VB.d.ts.map +0 -1
  358. package/dist/sampling-DfYhDJij.d.cts.map +0 -1
  359. package/dist/span-name-normalizer-8ZOGJuwv.d.cts.map +0 -1
  360. package/dist/span-name-normalizer-8ZOGJuwv.d.ts.map +0 -1
  361. package/dist/trace-context-Cijqoi6e.d.cts.map +0 -1
  362. package/dist/trace-context-Cijqoi6e.d.ts.map +0 -1
  363. package/dist/track-D7O7oIZa.js +0 -1115
  364. package/dist/track-D7O7oIZa.js.map +0 -1
  365. package/dist/track-eovhCJ-I.cjs +0 -1218
  366. package/dist/track-eovhCJ-I.cjs.map +0 -1
  367. package/skills/analyze-traces/SKILL.md +0 -180
  368. package/skills/autotel-core/SKILL.md +0 -159
  369. package/skills/autotel-events/SKILL.md +0 -84
  370. package/skills/autotel-frameworks/SKILL.md +0 -90
  371. package/skills/autotel-instrumentation/SKILL.md +0 -145
  372. package/skills/autotel-request-logging/SKILL.md +0 -94
  373. package/skills/autotel-structured-errors/SKILL.md +0 -125
  374. package/skills/build-audit-trails/SKILL.md +0 -460
  375. package/skills/build-audit-trails/references/audit-queries.md +0 -73
  376. package/skills/build-audit-trails/references/framework-wiring.md +0 -196
  377. package/skills/debug-missing-spans/SKILL.md +0 -250
  378. package/skills/migrate-to-autotel/SKILL.md +0 -269
  379. package/skills/review-otel-patterns/SKILL.md +0 -538
  380. package/skills/review-otel-patterns/references/code-review.md +0 -76
  381. package/skills/review-otel-patterns/references/processor-pipeline.md +0 -205
  382. package/skills/review-otel-patterns/references/structured-errors.md +0 -102
  383. package/skills/review-otel-patterns/references/wide-spans.md +0 -85
  384. package/skills/tune-sampling/SKILL.md +0 -215
@@ -1,1248 +0,0 @@
1
- import { getForceFlushableProvider } from "./tracer-provider.js";
2
- import { getConfig } from "./config.js";
3
- import { AUTOTEL_SAMPLING_TAIL_EVALUATED, AUTOTEL_SAMPLING_TAIL_KEEP, AlwaysSampler } from "./sampling.js";
4
- import { a as getSdk, n as getConfig$1 } from "./init-BvBB45-T.js";
5
- import { _ as getContextStorage, g as getActiveContextWithBaggage, h as enterOrRun, p as createTraceContext, t as getEventQueue } from "./track-D7O7oIZa.js";
6
- import { setSpanName } from "./trace-helpers.js";
7
- import { n as runInOperationContext } from "./operation-context-CKBoA4Qy.js";
8
- import { SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
9
- import * as nodeFs from "node:fs";
10
- import * as nodeUrl from "node:url";
11
-
12
- //#region src/variable-name-inference.ts
13
- /**
14
- * Variable Name Inference Utility
15
- *
16
- * Attempts to infer variable names from const/export const assignments
17
- * by analyzing the call stack and parsing source code.
18
- *
19
- * This is a best-effort approach with graceful degradation - if inference
20
- * fails for any reason, it returns undefined without breaking the application.
21
- */
22
- /**
23
- * LRU Cache for inferred variable names
24
- * Key: "file:line" (e.g., "/path/to/file.ts:42")
25
- * Value: inferred variable name or undefined
26
- */
27
- const inferenceCache = /* @__PURE__ */ new Map();
28
- const MAX_CACHE_SIZE = 50;
29
- /**
30
- * Captures the current call stack
31
- */
32
- function captureStackTrace() {
33
- const originalStackTraceLimit = Error.stackTraceLimit;
34
- Error.stackTraceLimit = 10;
35
- const stack = (/* @__PURE__ */ new Error("Stack trace capture")).stack || "";
36
- Error.stackTraceLimit = originalStackTraceLimit;
37
- return stack;
38
- }
39
- /**
40
- * Parses the stack trace to find where trace() was called
41
- *
42
- * Stack trace format (Node.js):
43
- * at functionName (file:line:column)
44
- * at file:line:column
45
- *
46
- * We skip frames until we find one that's NOT in functional.ts or this file.
47
- * We also need to skip one additional frame (the trace/span/instrument function itself)
48
- * to get to the actual user code.
49
- */
50
- function parseCallLocation(stack) {
51
- const lines = stack.split("\n");
52
- let skippedExternalFrame = false;
53
- for (const line of lines) {
54
- if (line.includes("variable-name-inference.ts") || line.includes("variable-name-inference.js") || line.includes("functional.ts") || line.includes("functional.js")) continue;
55
- const match = line.match(/at\s+(?:.*\s+)?\(?([^:]+):(\d+):(\d+)\)?/) || line.match(/^.*?([^:]+):(\d+):(\d+)/);
56
- if (match) {
57
- let filePath = match[1].trim();
58
- if (filePath.startsWith("file://")) try {
59
- filePath = nodeUrl.fileURLToPath(filePath);
60
- } catch {
61
- continue;
62
- }
63
- if (!skippedExternalFrame) {
64
- skippedExternalFrame = true;
65
- continue;
66
- }
67
- return {
68
- file: filePath,
69
- line: Number.parseInt(match[2], 10),
70
- column: Number.parseInt(match[3], 10)
71
- };
72
- }
73
- }
74
- }
75
- /**
76
- * Reads a specific line from a source file
77
- */
78
- function readSourceLine(filePath, lineNumber) {
79
- try {
80
- if (typeof nodeFs.readFileSync !== "function") return;
81
- return nodeFs.readFileSync(filePath, "utf8").split("\n")[lineNumber - 1];
82
- } catch {
83
- return;
84
- }
85
- }
86
- /**
87
- * Extracts variable name from source code line using regex patterns
88
- *
89
- * Supported patterns:
90
- * - const varName = anyFunction(
91
- * - export const varName = anyFunction(
92
- * - let varName = anyFunction(
93
- * - var varName = anyFunction(
94
- *
95
- * Note: This won't work with destructuring assignments or complex patterns
96
- */
97
- function extractVariableName(sourceLine) {
98
- const trimmed = sourceLine.trim();
99
- for (const pattern of [
100
- /export\s+const\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/,
101
- /const\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/,
102
- /export\s+let\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/,
103
- /let\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/,
104
- /export\s+var\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/,
105
- /var\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/
106
- ]) {
107
- const match = trimmed.match(pattern);
108
- if (match && match[1]) return match[1];
109
- }
110
- }
111
- /**
112
- * Adds an entry to the cache with LRU eviction
113
- */
114
- function cacheInference(key, value) {
115
- if (inferenceCache.size >= MAX_CACHE_SIZE) {
116
- const firstKey = inferenceCache.keys().next().value;
117
- if (firstKey) inferenceCache.delete(firstKey);
118
- }
119
- inferenceCache.set(key, value);
120
- }
121
- /**
122
- * Main entry point: Attempts to infer the variable name from the call stack
123
- *
124
- * This function:
125
- * 1. Captures the call stack
126
- * 2. Parses it to find where trace() was called (file + line)
127
- * 3. Reads that line from the source file
128
- * 4. Extracts the variable name using regex
129
- *
130
- * Returns undefined if inference fails at any step (graceful degradation).
131
- * Results are cached to avoid repeated file I/O.
132
- *
133
- * @returns The inferred variable name, or undefined if inference failed
134
- */
135
- function inferVariableNameFromCallStack() {
136
- try {
137
- const callLocation = parseCallLocation(captureStackTrace());
138
- if (!callLocation) return;
139
- const cacheKey = `${callLocation.file}:${callLocation.line}`;
140
- if (inferenceCache.has(cacheKey)) return inferenceCache.get(cacheKey);
141
- const sourceLine = readSourceLine(callLocation.file, callLocation.line);
142
- if (!sourceLine) return;
143
- const variableName = extractVariableName(sourceLine);
144
- cacheInference(cacheKey, variableName);
145
- return variableName;
146
- } catch {
147
- return;
148
- }
149
- }
150
-
151
- //#endregion
152
- //#region src/functional.ts
153
- /**
154
- * Functional API for non-class code
155
- *
156
- * Three approaches for different use cases:
157
- * 1. trace() - Zero-ceremony HOF for single functions
158
- * 2. withTracing() - Middleware-style composable wrapper
159
- * 3. instrument() - Batch auto-instrumentation for modules
160
- *
161
- * @example trace() - Single function
162
- * ```typescript
163
- * export const createUser = trace(ctx => async (data) => {
164
- * ctx.setAttribute('user.id', data.id)
165
- * return await db.users.create(data)
166
- * })
167
- * ```
168
- *
169
- * @example withTracing() - Composable middleware
170
- * ```typescript
171
- * export const createUser = withTracing({
172
- * name: 'user.create'
173
- * })(ctx => async (data) => {
174
- * ctx.setAttribute('user.id', data.id)
175
- * return await db.users.create(data)
176
- * })
177
- * ```
178
- *
179
- * @example instrument() - Batch instrumentation
180
- * ```typescript
181
- * export default instrument({
182
- * createUser: async (data) => { },
183
- * updateUser: async (id, data) => { }
184
- * }, { serviceName: 'user' })
185
- * ```
186
- */
187
- const FACTORY_NAME_HINTS = /* @__PURE__ */ new Set([
188
- "ctx",
189
- "_ctx",
190
- "context",
191
- "tracecontext",
192
- "tracectx"
193
- ]);
194
- const TRACE_FACTORY_SET = /* @__PURE__ */ new WeakSet();
195
- const SINGLE_LINE_COMMENT_REGEX = /\/\/.*$/gm;
196
- const MULTI_LINE_COMMENT_REGEX = /\/\*[\s\S]*?\*\//gm;
197
- const PARAM_TOKEN_SANITIZE_REGEX = new RegExp(String.raw`[{}\[\]\s]`, "g");
198
- function markAsTraceFactory(fn) {
199
- TRACE_FACTORY_SET.add(fn);
200
- }
201
- function hasFactoryMark(fn) {
202
- return TRACE_FACTORY_SET.has(fn);
203
- }
204
- function sanitizeParameterToken(token) {
205
- const [firstToken] = token.split("=");
206
- return (firstToken ?? "").replaceAll(PARAM_TOKEN_SANITIZE_REGEX, "").trim();
207
- }
208
- function getFirstParameterToken(fn) {
209
- let source = Function.prototype.toString.call(fn);
210
- source = source.replaceAll(MULTI_LINE_COMMENT_REGEX, "").replaceAll(SINGLE_LINE_COMMENT_REGEX, "").trim();
211
- const arrowMatch = source.match(/^(?:async\s*)?(?:\(([^)]*)\)|([^=()]+))\s*=>/);
212
- if (arrowMatch) {
213
- const first = (arrowMatch[1] ?? arrowMatch[2] ?? "").split(",")[0]?.trim();
214
- if (first) return sanitizeParameterToken(first);
215
- return null;
216
- }
217
- const functionMatch = source.match(/^[^(]*\(([^)]*)\)/);
218
- if (functionMatch) {
219
- const first = (functionMatch[1]?.split(","))?.[0]?.trim();
220
- if (first) return sanitizeParameterToken(first);
221
- }
222
- return null;
223
- }
224
- /**
225
- * Symbol that explicitly marks a function as immediate-execution-with-ctx
226
- * (`(ctx) => result`), bypassing parameter-name introspection. Library
227
- * authors who wrap user handlers — like `autotel-aws/lambda`'s `wrapHandler`
228
- * — should mark their inner trace function with this so dispatch survives
229
- * downstream bundlers that minify parameter names.
230
- */
231
- const IMMEDIATE_EXECUTION_SYMBOL = Symbol.for("autotel.immediate-execution");
232
- function hasImmediateExecutionMark(fn) {
233
- return typeof fn === "function" && fn[IMMEDIATE_EXECUTION_SYMBOL] === true;
234
- }
235
- /**
236
- * Mark a function as immediate-execution-with-ctx so `trace(name, fn)`
237
- * dispatch doesn't depend on the first parameter being named `ctx`.
238
- *
239
- * Necessary when the function will be bundled by a minifier (esbuild,
240
- * terser, etc.) that renames identifiers. The name-allowlist heuristic in
241
- * `looksLikeTraceFactory` cannot recover from that; the marker can.
242
- *
243
- * @example
244
- * ```ts
245
- * import { markAsImmediate, trace } from 'autotel';
246
- *
247
- * const inner = markAsImmediate(async (ctx) => {
248
- * ctx.setAttribute('user.id', '123');
249
- * return { ok: true };
250
- * });
251
- * const result = await trace('user.read', inner);
252
- * ```
253
- */
254
- function markAsImmediate(fn) {
255
- if (typeof fn === "function") fn[IMMEDIATE_EXECUTION_SYMBOL] = true;
256
- return fn;
257
- }
258
- function looksLikeTraceFactory(fn) {
259
- if (hasFactoryMark(fn)) return true;
260
- if (hasImmediateExecutionMark(fn)) return true;
261
- if (fn.length === 0) {
262
- if (!isAsyncFunction(fn)) try {
263
- return typeof fn() === "function";
264
- } catch {
265
- return false;
266
- }
267
- return false;
268
- }
269
- const firstParam = getFirstParameterToken(fn);
270
- if (!firstParam) return false;
271
- const normalized = firstParam.toLowerCase();
272
- if (FACTORY_NAME_HINTS.has(normalized) || normalized.startsWith("ctx") || normalized.startsWith("_ctx") || normalized.startsWith("trace") || normalized.endsWith("ctx") || normalized.includes("context")) return true;
273
- return false;
274
- }
275
- /**
276
- * Check if a function that takes ctx returns another function (factory pattern)
277
- * vs returning a value directly (immediate execution pattern)
278
- *
279
- * IMPORTANT: For async functions, we skip probing entirely and assume immediate execution.
280
- * This is because:
281
- * - Factory pattern: `(ctx) => async (...args) => result` - outer function is SYNC
282
- * - Immediate execution: `async (ctx) => result` - function itself is ASYNC
283
- *
284
- * Probing async functions by executing them causes side effects (like creating orphan spans)
285
- * because the async function starts executing synchronously until the first await.
286
- */
287
- function isFactoryReturningFunction(fnWithCtx) {
288
- if (isAsyncFunction(fnWithCtx)) return false;
289
- try {
290
- return typeof fnWithCtx(createDummyCtx()) === "function";
291
- } catch {
292
- return false;
293
- }
294
- }
295
- function isTraceFactoryFunction(fn) {
296
- if (typeof fn !== "function") return false;
297
- if (hasFactoryMark(fn)) return true;
298
- if (looksLikeTraceFactory(fn)) {
299
- markAsTraceFactory(fn);
300
- return true;
301
- }
302
- return false;
303
- }
304
- function ensureTraceFactory(fnOrFactory) {
305
- if (isTraceFactoryFunction(fnOrFactory)) return fnOrFactory;
306
- const plainFn = fnOrFactory;
307
- const factory = (ctx) => {
308
- return plainFn;
309
- };
310
- markAsTraceFactory(factory);
311
- return factory;
312
- }
313
- function wrapFactoryWithTracing(fnOrFactory, options, variableName) {
314
- const factory = ensureTraceFactory(fnOrFactory);
315
- const sampleFn = factory(createDummyCtx());
316
- const innerFunctionName = inferFunctionName(sampleFn);
317
- const callStackVariableName = innerFunctionName ? void 0 : inferVariableNameFromCallStack();
318
- const factoryName = inferFunctionName(factory);
319
- const effectiveVariableName = variableName || innerFunctionName || callStackVariableName || factoryName;
320
- if (isAsyncFunction(sampleFn)) return wrapWithTracing(factory, options, effectiveVariableName);
321
- return wrapWithTracingSync(factory, options, effectiveVariableName);
322
- }
323
- const MAX_ERROR_MESSAGE_LENGTH = 500;
324
- function createDummyCtx() {
325
- return {
326
- traceId: "",
327
- spanId: "",
328
- correlationId: "",
329
- setAttribute: () => {},
330
- setAttributes: () => {},
331
- setStatus: () => {},
332
- recordException: () => {},
333
- addEvent: () => {},
334
- addLink: () => {},
335
- addLinks: () => {},
336
- updateName: () => {},
337
- isRecording: () => false,
338
- getBaggage: () => {},
339
- setBaggage: () => "",
340
- deleteBaggage: () => {},
341
- getAllBaggage: () => /* @__PURE__ */ new Map()
342
- };
343
- }
344
- /** Attribute keys for opt-in function I/O capture (see TracingOptions). */
345
- const AUTOTEL_INPUT_ATTR = "autotel.input";
346
- const AUTOTEL_OUTPUT_ATTR = "autotel.output";
347
- const CAPTURE_MAX_CHARS = 4096;
348
- /** JSON-serialize a captured value, defensively (truncate, swallow cycles). */
349
- function serializeCapture(value) {
350
- if (value === void 0) return void 0;
351
- try {
352
- const json = typeof value === "string" ? value : JSON.stringify(value);
353
- if (json === void 0) return void 0;
354
- return json.length > CAPTURE_MAX_CHARS ? `${json.slice(0, CAPTURE_MAX_CHARS)}…[truncated]` : json;
355
- } catch {
356
- return;
357
- }
358
- }
359
- /** `autotel.input` from args (single arg captured directly, else the array). */
360
- function captureInputAttrs(args, enabled) {
361
- if (!enabled) return {};
362
- const s = serializeCapture(args.length === 1 ? args[0] : args);
363
- return s === void 0 ? {} : { [AUTOTEL_INPUT_ATTR]: s };
364
- }
365
- /** `autotel.output` from the return value. */
366
- function captureOutputAttrs(result, enabled) {
367
- if (!enabled) return {};
368
- const s = serializeCapture(result);
369
- return s === void 0 ? {} : { [AUTOTEL_OUTPUT_ATTR]: s };
370
- }
371
- function isAsyncFunction(fn) {
372
- return typeof fn === "function" && fn.constructor?.name === "AsyncFunction";
373
- }
374
- const INSTRUMENTED_SYMBOL = Symbol.for("autotel.functional.instrumented");
375
- function hasInstrumentationFlag(value) {
376
- return (typeof value === "function" || typeof value === "object") && value !== null && Boolean(value[INSTRUMENTED_SYMBOL]);
377
- }
378
- /**
379
- * Truncate error message to prevent span bloat
380
- */
381
- function truncateErrorMessage(message) {
382
- if (message.length <= MAX_ERROR_MESSAGE_LENGTH) return message;
383
- return `${message.slice(0, MAX_ERROR_MESSAGE_LENGTH)}... (truncated)`;
384
- }
385
- /**
386
- * Try to infer function name from function properties
387
- * Checks for displayName, name, or other metadata that might be set
388
- */
389
- function inferFunctionName(fn) {
390
- const displayName = fn.displayName;
391
- if (displayName) return displayName;
392
- if (fn.name && fn.name !== "anonymous" && fn.name !== "") return fn.name;
393
- const match = Function.prototype.toString.call(fn).match(/function\s+([^(\s]+)/);
394
- if (match && match[1] && match[1] !== "anonymous") return match[1];
395
- }
396
- /**
397
- * Determine span name using priority:
398
- * 1. Explicit name option
399
- * 2. serviceName + functionName
400
- * 3. Inferred from function/variable name (including stack trace fallback)
401
- * 4. Fallback to 'unknown'
402
- */
403
- function getSpanName(options, fn, variableName) {
404
- if (options.name) return options.name;
405
- let fnName = variableName || inferFunctionName(fn);
406
- fnName = fnName || "anonymous";
407
- if (options.serviceName) return `${options.serviceName}.${fnName}`;
408
- if (fnName && fnName !== "anonymous") return fnName;
409
- return "unknown";
410
- }
411
- /**
412
- * Check if function should be skipped
413
- */
414
- function shouldSkip(key, fn, skip) {
415
- if (key.startsWith("_")) return true;
416
- if (!skip || skip.length === 0) return false;
417
- for (const rule of skip) if (typeof rule === "string" && key === rule) return true;
418
- else if (rule instanceof RegExp && rule.test(key)) return true;
419
- else if (typeof rule === "function" && rule(key, fn)) return true;
420
- return false;
421
- }
422
- /**
423
- * Get current trace context value (internal helper)
424
- *
425
- * Returns base context (trace IDs) + span methods from the active span.
426
- */
427
- function getCtxValue() {
428
- const activeSpan = trace.getActiveSpan();
429
- if (!activeSpan) return null;
430
- return createTraceContext(activeSpan);
431
- }
432
- /**
433
- * Context object that lazily evaluates the active span on property access
434
- *
435
- * Access trace context directly without function call syntax.
436
- *
437
- * @example
438
- * ```typescript
439
- * import { trace, ctx } from 'autotel'
440
- *
441
- * export const createUser = trace(async (data) => {
442
- * // Direct property access - no function call!
443
- * if (ctx.traceId) {
444
- * ctx.setAttribute('user.id', data.id)
445
- * console.log('Trace:', ctx.traceId)
446
- * }
447
- * })
448
- * ```
449
- */
450
- const ctx = new Proxy({}, {
451
- get(_target, prop) {
452
- const ctxValue = getCtxValue();
453
- if (!ctxValue) return;
454
- return ctxValue[prop];
455
- },
456
- has(_target, prop) {
457
- const ctxValue = getCtxValue();
458
- if (!ctxValue) return false;
459
- return prop in ctxValue;
460
- },
461
- ownKeys() {
462
- const ctxValue = getCtxValue();
463
- if (!ctxValue) return [];
464
- return Object.keys(ctxValue);
465
- },
466
- getOwnPropertyDescriptor(_target, prop) {
467
- const ctxValue = getCtxValue();
468
- if (!ctxValue) return;
469
- return Object.getOwnPropertyDescriptor(ctxValue, prop);
470
- }
471
- });
472
- /**
473
- * Core tracing wrapper for async functions (internal implementation)
474
- */
475
- function wrapWithTracing(fnFactory, options, variableName) {
476
- if (hasInstrumentationFlag(fnFactory)) {}
477
- const config = getConfig();
478
- const tracer = config.tracer;
479
- const meter = config.meter;
480
- const sampler = options.sampler || new AlwaysSampler();
481
- const tempFn = fnFactory(createDummyCtx());
482
- const spanName = getSpanName(options, tempFn, variableName);
483
- const callCounter = options.withMetrics ? meter.createCounter(`${spanName}.calls`, {
484
- description: `Call count for ${spanName}`,
485
- unit: "1"
486
- }) : void 0;
487
- const durationHistogram = options.withMetrics ? meter.createHistogram(`${spanName}.duration`, {
488
- description: `Duration for ${spanName}`,
489
- unit: "ms"
490
- }) : void 0;
491
- const wrappedFunction = async function wrappedFunction(...args) {
492
- const samplingContext = {
493
- operationName: spanName,
494
- args,
495
- metadata: {}
496
- };
497
- const shouldSample = sampler.shouldSample(samplingContext);
498
- const needsTailSampling = "needsTailSampling" in sampler && typeof sampler.needsTailSampling === "function" ? sampler.needsTailSampling() : false;
499
- if (!shouldSample && !needsTailSampling) return await fnFactory(createDummyCtx()).call(this, ...args);
500
- const startTime = performance.now();
501
- const isRootSpan = options.startNewRoot || trace.getActiveSpan() === void 0;
502
- const shouldAutoFlush = options.flushOnRootSpanEnd ?? getConfig$1()?.flushOnRootSpanEnd ?? true;
503
- const shouldAutoFlushSpans = getConfig$1()?.forceFlushOnShutdown ?? false;
504
- const flushIfNeeded = async () => {
505
- if (!shouldAutoFlush || !isRootSpan) return;
506
- try {
507
- const queue = getEventQueue();
508
- if (queue && queue.size() > 0) await queue.flush();
509
- if (shouldAutoFlushSpans) try {
510
- const tracerProvider = getForceFlushableProvider(getSdk());
511
- if (tracerProvider) await tracerProvider.forceFlush();
512
- } catch {}
513
- } catch (error) {
514
- const logger = getConfig$1()?.logger;
515
- if (logger?.error) logger.error({ err: error instanceof Error ? error : void 0 }, `[autotel] Auto-flush failed${error instanceof Error ? "" : `: ${String(error)}`}`);
516
- }
517
- };
518
- const spanOptions = {};
519
- if (options.startNewRoot) spanOptions.root = true;
520
- if (options.spanKind !== void 0) spanOptions.kind = options.spanKind;
521
- const parentContext = getActiveContextWithBaggage();
522
- return tracer.startActiveSpan(spanName, spanOptions, parentContext, async (span) => {
523
- return runInOperationContext(spanName, async () => {
524
- let shouldKeepSpan = true;
525
- setSpanName(span, spanName);
526
- const initialContext = context.active();
527
- const contextStorage = getContextStorage();
528
- if (!contextStorage.getStore()) enterOrRun(contextStorage, initialContext);
529
- const fn = fnFactory(createTraceContext(span));
530
- const argsAttributes = {
531
- ...captureInputAttrs(args, options.captureInput),
532
- ...options.attributesFromArgs ? options.attributesFromArgs(args) : {}
533
- };
534
- const handleTailSampling = (success, duration, error) => {
535
- if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
536
- shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
537
- success,
538
- duration,
539
- error
540
- });
541
- span.setAttribute(AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
542
- span.setAttribute(AUTOTEL_SAMPLING_TAIL_EVALUATED, true);
543
- }
544
- };
545
- const onSuccess = async (result) => {
546
- const duration = performance.now() - startTime;
547
- callCounter?.add(1, {
548
- operation: spanName,
549
- status: "success"
550
- });
551
- durationHistogram?.record(duration, {
552
- operation: spanName,
553
- status: "success"
554
- });
555
- const resultAttributes = {
556
- ...captureOutputAttrs(result, options.captureOutput),
557
- ...options.attributesFromResult ? options.attributesFromResult(result) : {}
558
- };
559
- span.setStatus({ code: SpanStatusCode.OK });
560
- span.setAttributes({
561
- ...argsAttributes,
562
- ...resultAttributes,
563
- "operation.name": spanName,
564
- "code.function": spanName,
565
- "operation.duration": duration,
566
- "operation.success": true
567
- });
568
- handleTailSampling(true, duration);
569
- span.end();
570
- await flushIfNeeded();
571
- return result;
572
- };
573
- const onError = async (error) => {
574
- const duration = performance.now() - startTime;
575
- callCounter?.add(1, {
576
- operation: spanName,
577
- status: "error"
578
- });
579
- durationHistogram?.record(duration, {
580
- operation: spanName,
581
- status: "error"
582
- });
583
- const truncatedMessage = truncateErrorMessage(error instanceof Error ? error.message : "Unknown error");
584
- span.setStatus({
585
- code: SpanStatusCode.ERROR,
586
- message: truncatedMessage
587
- });
588
- span.setAttributes({
589
- ...argsAttributes,
590
- "operation.name": spanName,
591
- "code.function": spanName,
592
- "operation.duration": duration,
593
- "operation.success": false,
594
- error: true,
595
- "exception.type": error instanceof Error ? error.constructor.name : "Error",
596
- "exception.message": truncatedMessage
597
- });
598
- if (error instanceof Error && error.stack) span.setAttribute("exception.stack", error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH));
599
- span.recordException(error instanceof Error ? error : new Error(String(error)));
600
- handleTailSampling(false, duration, error);
601
- span.end();
602
- await flushIfNeeded();
603
- throw error;
604
- };
605
- try {
606
- callCounter?.add(1, {
607
- operation: spanName,
608
- status: "started"
609
- });
610
- const executeWithContext = async () => {
611
- const currentContext = getActiveContextWithBaggage();
612
- return context.with(currentContext, async () => {
613
- return fn.call(this, ...args);
614
- });
615
- };
616
- return await onSuccess(await executeWithContext());
617
- } catch (error) {
618
- await onError(error);
619
- throw error;
620
- }
621
- });
622
- });
623
- };
624
- wrappedFunction[INSTRUMENTED_SYMBOL] = true;
625
- Object.defineProperty(wrappedFunction, "name", {
626
- value: tempFn.name || "trace",
627
- configurable: true
628
- });
629
- return wrappedFunction;
630
- }
631
- /**
632
- * Core tracing wrapper for sync functions (internal implementation)
633
- */
634
- function wrapWithTracingSync(fnFactory, options, variableName) {
635
- if (hasInstrumentationFlag(fnFactory)) {}
636
- const config = getConfig();
637
- const tracer = config.tracer;
638
- const meter = config.meter;
639
- const sampler = options.sampler || new AlwaysSampler();
640
- const tempFn = fnFactory(createDummyCtx());
641
- const spanName = getSpanName(options, tempFn, variableName);
642
- const callCounter = options.withMetrics ? meter.createCounter(`${spanName}.calls`, {
643
- description: `Call count for ${spanName}`,
644
- unit: "1"
645
- }) : void 0;
646
- const durationHistogram = options.withMetrics ? meter.createHistogram(`${spanName}.duration`, {
647
- description: `Duration for ${spanName}`,
648
- unit: "ms"
649
- }) : void 0;
650
- function wrappedFunction(...args) {
651
- const samplingContext = {
652
- operationName: spanName,
653
- args,
654
- metadata: {}
655
- };
656
- const shouldSample = sampler.shouldSample(samplingContext);
657
- const needsTailSampling = "needsTailSampling" in sampler && typeof sampler.needsTailSampling === "function" ? sampler.needsTailSampling() : false;
658
- if (!shouldSample && !needsTailSampling) return fnFactory(createDummyCtx()).call(this, ...args);
659
- const startTime = performance.now();
660
- const isRootSpan = options.startNewRoot || trace.getActiveSpan() === void 0;
661
- const shouldAutoFlush = options.flushOnRootSpanEnd ?? getConfig$1()?.flushOnRootSpanEnd ?? true;
662
- const shouldAutoFlushSpans = getConfig$1()?.forceFlushOnShutdown ?? false;
663
- const flushIfNeeded = () => {
664
- if (!shouldAutoFlush || !isRootSpan) return;
665
- const queue = getEventQueue();
666
- if (queue && queue.size() > 0) queue.flush().catch((error) => {
667
- const logger = getConfig$1()?.logger;
668
- if (logger?.error) logger.error({ err: error instanceof Error ? error : void 0 }, `[autotel] Auto-flush failed${error instanceof Error ? "" : `: ${String(error)}`}`);
669
- });
670
- if (shouldAutoFlushSpans) try {
671
- const tracerProvider = getForceFlushableProvider(getSdk());
672
- if (tracerProvider) tracerProvider.forceFlush().catch((error) => {
673
- const logger = getConfig$1()?.logger;
674
- if (logger?.error) logger.error({ err: error instanceof Error ? error : void 0 }, `[autotel] Span flush failed${error instanceof Error ? "" : `: ${String(error)}`}`);
675
- });
676
- } catch {}
677
- };
678
- const spanOptions = {};
679
- if (options.startNewRoot) spanOptions.root = true;
680
- if (options.spanKind !== void 0) spanOptions.kind = options.spanKind;
681
- const parentContext = getActiveContextWithBaggage();
682
- return tracer.startActiveSpan(spanName, spanOptions, parentContext, (span) => {
683
- return runInOperationContext(spanName, () => {
684
- let shouldKeepSpan = true;
685
- setSpanName(span, spanName);
686
- const fn = fnFactory(createTraceContext(span));
687
- const argsAttributes = {
688
- ...captureInputAttrs(args, options.captureInput),
689
- ...options.attributesFromArgs ? options.attributesFromArgs(args) : {}
690
- };
691
- const handleTailSampling = (success, duration, error) => {
692
- if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
693
- shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
694
- success,
695
- duration,
696
- error
697
- });
698
- span.setAttribute(AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
699
- span.setAttribute(AUTOTEL_SAMPLING_TAIL_EVALUATED, true);
700
- }
701
- };
702
- const onSuccess = (result) => {
703
- const duration = performance.now() - startTime;
704
- callCounter?.add(1, {
705
- operation: spanName,
706
- status: "success"
707
- });
708
- durationHistogram?.record(duration, {
709
- operation: spanName,
710
- status: "success"
711
- });
712
- const resultAttributes = {
713
- ...captureOutputAttrs(result, options.captureOutput),
714
- ...options.attributesFromResult ? options.attributesFromResult(result) : {}
715
- };
716
- span.setStatus({ code: SpanStatusCode.OK });
717
- span.setAttributes({
718
- ...argsAttributes,
719
- ...resultAttributes,
720
- "operation.name": spanName,
721
- "code.function": spanName,
722
- "operation.duration": duration,
723
- "operation.success": true
724
- });
725
- handleTailSampling(true, duration);
726
- span.end();
727
- flushIfNeeded();
728
- return result;
729
- };
730
- const onError = (error) => {
731
- const duration = performance.now() - startTime;
732
- callCounter?.add(1, {
733
- operation: spanName,
734
- status: "error"
735
- });
736
- durationHistogram?.record(duration, {
737
- operation: spanName,
738
- status: "error"
739
- });
740
- const truncatedMessage = truncateErrorMessage(error instanceof Error ? error.message : "Unknown error");
741
- span.setStatus({
742
- code: SpanStatusCode.ERROR,
743
- message: truncatedMessage
744
- });
745
- span.setAttributes({
746
- ...argsAttributes,
747
- "operation.name": spanName,
748
- "code.function": spanName,
749
- "operation.duration": duration,
750
- "operation.success": false,
751
- error: true,
752
- "exception.type": error instanceof Error ? error.constructor.name : "Error",
753
- "exception.message": truncatedMessage
754
- });
755
- span.recordException(error instanceof Error ? error : new Error(String(error)));
756
- handleTailSampling(false, duration, error);
757
- span.end();
758
- flushIfNeeded();
759
- throw error;
760
- };
761
- try {
762
- callCounter?.add(1, {
763
- operation: spanName,
764
- status: "started"
765
- });
766
- const result = fn.call(this, ...args);
767
- if (result instanceof Promise) return result.then(onSuccess, onError);
768
- return onSuccess(result);
769
- } catch (error) {
770
- return onError(error);
771
- }
772
- });
773
- });
774
- }
775
- wrappedFunction[INSTRUMENTED_SYMBOL] = true;
776
- Object.defineProperty(wrappedFunction, "name", {
777
- value: tempFn.name || "trace",
778
- configurable: true
779
- });
780
- return wrappedFunction;
781
- }
782
- /**
783
- * Execute a function immediately within a trace span
784
- * Used for the immediate execution pattern: trace((ctx) => result)
785
- */
786
- function executeImmediately(fn, options) {
787
- const config = getConfig();
788
- const tracer = config.tracer;
789
- const meter = config.meter;
790
- const sampler = options.sampler || new AlwaysSampler();
791
- const spanName = options.name || "anonymous";
792
- const samplingContext = {
793
- operationName: spanName,
794
- args: [],
795
- metadata: {}
796
- };
797
- const shouldSample = sampler.shouldSample(samplingContext);
798
- const needsTailSampling = "needsTailSampling" in sampler && typeof sampler.needsTailSampling === "function" ? sampler.needsTailSampling() : false;
799
- if (!shouldSample && !needsTailSampling) return fn(createDummyCtx());
800
- const startTime = performance.now();
801
- const isRootSpan = options.startNewRoot || trace.getActiveSpan() === void 0;
802
- const shouldAutoFlush = options.flushOnRootSpanEnd ?? getConfig$1()?.flushOnRootSpanEnd ?? true;
803
- const shouldAutoFlushSpans = getConfig$1()?.forceFlushOnShutdown ?? false;
804
- const callCounter = options.withMetrics ? meter.createCounter(`${spanName}.calls`, {
805
- description: `Call count for ${spanName}`,
806
- unit: "1"
807
- }) : void 0;
808
- const durationHistogram = options.withMetrics ? meter.createHistogram(`${spanName}.duration`, {
809
- description: `Duration for ${spanName}`,
810
- unit: "ms"
811
- }) : void 0;
812
- const flushIfNeeded = async () => {
813
- if (!shouldAutoFlush || !isRootSpan) return;
814
- try {
815
- const queue = getEventQueue();
816
- if (queue && queue.size() > 0) await queue.flush();
817
- if (shouldAutoFlushSpans) try {
818
- const tracerProvider = getForceFlushableProvider(getSdk());
819
- if (tracerProvider) await tracerProvider.forceFlush();
820
- } catch {}
821
- } catch (error) {
822
- const logger = getConfig$1()?.logger;
823
- if (logger?.error) logger.error({ err: error instanceof Error ? error : void 0 }, `[autotel] Auto-flush failed${error instanceof Error ? "" : `: ${String(error)}`}`);
824
- }
825
- };
826
- const spanOptions = {};
827
- if (options.startNewRoot) spanOptions.root = true;
828
- if (options.spanKind !== void 0) spanOptions.kind = options.spanKind;
829
- const parentContext = getActiveContextWithBaggage();
830
- return tracer.startActiveSpan(spanName, spanOptions, parentContext, (span) => {
831
- return runInOperationContext(spanName, () => {
832
- let shouldKeepSpan = true;
833
- setSpanName(span, spanName);
834
- const ctxValue = createTraceContext(span);
835
- const handleTailSampling = (success, duration, error) => {
836
- if (needsTailSampling && "shouldKeepTrace" in sampler && typeof sampler.shouldKeepTrace === "function") {
837
- shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
838
- success,
839
- duration,
840
- error
841
- });
842
- span.setAttribute(AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
843
- span.setAttribute(AUTOTEL_SAMPLING_TAIL_EVALUATED, true);
844
- }
845
- };
846
- const onSuccessSync = (result) => {
847
- const duration = performance.now() - startTime;
848
- callCounter?.add(1, {
849
- operation: spanName,
850
- status: "success"
851
- });
852
- durationHistogram?.record(duration, {
853
- operation: spanName,
854
- status: "success"
855
- });
856
- span.setStatus({ code: SpanStatusCode.OK });
857
- span.setAttributes({
858
- "operation.name": spanName,
859
- "code.function": spanName,
860
- "operation.duration": duration,
861
- "operation.success": true
862
- });
863
- handleTailSampling(true, duration);
864
- span.end();
865
- flushIfNeeded();
866
- return result;
867
- };
868
- const onErrorSync = (error) => {
869
- const duration = performance.now() - startTime;
870
- callCounter?.add(1, {
871
- operation: spanName,
872
- status: "error"
873
- });
874
- durationHistogram?.record(duration, {
875
- operation: spanName,
876
- status: "error"
877
- });
878
- const truncatedMessage = truncateErrorMessage(error instanceof Error ? error.message : "Unknown error");
879
- span.setStatus({
880
- code: SpanStatusCode.ERROR,
881
- message: truncatedMessage
882
- });
883
- span.setAttributes({
884
- "operation.name": spanName,
885
- "code.function": spanName,
886
- "operation.duration": duration,
887
- "operation.success": false,
888
- error: true,
889
- "exception.type": error instanceof Error ? error.constructor.name : "Error",
890
- "exception.message": truncatedMessage
891
- });
892
- if (error instanceof Error && error.stack) span.setAttribute("exception.stack", error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH));
893
- span.recordException(error instanceof Error ? error : new Error(String(error)));
894
- handleTailSampling(false, duration, error);
895
- span.end();
896
- flushIfNeeded();
897
- throw error;
898
- };
899
- const onSuccessAsync = async (result) => {
900
- const duration = performance.now() - startTime;
901
- callCounter?.add(1, {
902
- operation: spanName,
903
- status: "success"
904
- });
905
- durationHistogram?.record(duration, {
906
- operation: spanName,
907
- status: "success"
908
- });
909
- span.setStatus({ code: SpanStatusCode.OK });
910
- span.setAttributes({
911
- "operation.name": spanName,
912
- "code.function": spanName,
913
- "operation.duration": duration,
914
- "operation.success": true
915
- });
916
- handleTailSampling(true, duration);
917
- span.end();
918
- await flushIfNeeded();
919
- return result;
920
- };
921
- const onErrorAsync = async (error) => {
922
- const duration = performance.now() - startTime;
923
- callCounter?.add(1, {
924
- operation: spanName,
925
- status: "error"
926
- });
927
- durationHistogram?.record(duration, {
928
- operation: spanName,
929
- status: "error"
930
- });
931
- const truncatedMessage = truncateErrorMessage(error instanceof Error ? error.message : "Unknown error");
932
- span.setStatus({
933
- code: SpanStatusCode.ERROR,
934
- message: truncatedMessage
935
- });
936
- span.setAttributes({
937
- "operation.name": spanName,
938
- "code.function": spanName,
939
- "operation.duration": duration,
940
- "operation.success": false,
941
- error: true,
942
- "exception.type": error instanceof Error ? error.constructor.name : "Error",
943
- "exception.message": truncatedMessage
944
- });
945
- if (error instanceof Error && error.stack) span.setAttribute("exception.stack", error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH));
946
- span.recordException(error instanceof Error ? error : new Error(String(error)));
947
- handleTailSampling(false, duration, error);
948
- span.end();
949
- await flushIfNeeded();
950
- throw error;
951
- };
952
- try {
953
- callCounter?.add(1, {
954
- operation: spanName,
955
- status: "started"
956
- });
957
- const result = fn(ctxValue);
958
- if (result instanceof Promise) return result.then(onSuccessAsync, onErrorAsync);
959
- return onSuccessSync(result);
960
- } catch (error) {
961
- return onErrorSync(error);
962
- }
963
- });
964
- });
965
- }
966
- function trace$1(fnOrNameOrOptions, maybeFn) {
967
- if (typeof fnOrNameOrOptions === "function") {
968
- if (looksLikeTraceFactory(fnOrNameOrOptions) && !isFactoryReturningFunction(fnOrNameOrOptions)) return executeImmediately(fnOrNameOrOptions, {});
969
- return wrapFactoryWithTracing(fnOrNameOrOptions, {});
970
- }
971
- if (typeof fnOrNameOrOptions === "string") {
972
- if (!maybeFn) throw new Error("trace(name, fn): fn is required");
973
- if (looksLikeTraceFactory(maybeFn) && !isFactoryReturningFunction(maybeFn)) return executeImmediately(maybeFn, { name: fnOrNameOrOptions });
974
- return wrapFactoryWithTracing(maybeFn, { name: fnOrNameOrOptions });
975
- }
976
- if (!maybeFn) throw new Error("trace(options, fn): fn is required");
977
- if (looksLikeTraceFactory(maybeFn) && !isFactoryReturningFunction(maybeFn)) return executeImmediately(maybeFn, fnOrNameOrOptions);
978
- return wrapFactoryWithTracing(maybeFn, fnOrNameOrOptions);
979
- }
980
- /**
981
- * Approach 2: withTracing() - Middleware-style composable wrapper
982
- *
983
- * Returns a HOF that wraps functions with tracing.
984
- * Perfect for composition and reusable configuration.
985
- *
986
- * @example Standard usage
987
- * ```typescript
988
- * export const createUser = withTracing({
989
- * name: 'user.create'
990
- * })(ctx => async (data) => {
991
- * ctx.setAttribute('user.id', data.id)
992
- * return await db.users.create(data)
993
- * })
994
- * ```
995
- *
996
- * @example Composable
997
- * ```typescript
998
- * const trace = withTracing({ serviceName: 'user' })
999
- *
1000
- * export const createUser = trace(ctx => async (data) => { })
1001
- * export const updateUser = trace(ctx => async (id, data) => { })
1002
- * ```
1003
- *
1004
- * @example With other middleware
1005
- * ```typescript
1006
- * export const createUser = compose(
1007
- * withAuth({ role: 'admin' }),
1008
- * withTracing({ name: 'user.create' }),
1009
- * withRateLimit({ max: 100 })
1010
- * )(ctx => async (data) => { })
1011
- * ```
1012
- */
1013
- function withTracing(options = {}) {
1014
- return (fnFactory) => wrapFactoryWithTracing(fnFactory, options);
1015
- }
1016
- /**
1017
- * Approach 3: instrument() - Batch auto-instrumentation
1018
- *
1019
- * Instrument an entire module/object at once.
1020
- * Closest to @Instrumented decorator pattern.
1021
- *
1022
- * @example Basic usage
1023
- * ```typescript
1024
- * export default instrument({
1025
- * functions: {
1026
- * createUser: async (data) => { },
1027
- * updateUser: async (id, data) => { },
1028
- * deleteUser: async (id) => { }
1029
- * },
1030
- * serviceName: 'user',
1031
- * sampler: new AdaptiveSampler()
1032
- * })
1033
- * // → Traced as "user.createUser", "user.updateUser", "user.deleteUser"
1034
- * ```
1035
- *
1036
- * @example Per-function overrides
1037
- * ```typescript
1038
- * export default instrument({
1039
- * functions: {
1040
- * createUser: async (data) => { },
1041
- * deleteUser: async (id) => { }
1042
- * },
1043
- * serviceName: 'user',
1044
- * overrides: {
1045
- * deleteUser: {
1046
- * sampler: new AlwaysSampler(),
1047
- * withMetrics: true
1048
- * }
1049
- * }
1050
- * })
1051
- * ```
1052
- *
1053
- * @example Skip functions
1054
- * ```typescript
1055
- * export default instrument({
1056
- * functions: {
1057
- * createUser: async (data) => { },
1058
- * _internal: async () => { }, // Auto-skipped (_-prefix)
1059
- * deleteUser: async (id) => { }
1060
- * },
1061
- * serviceName: 'user',
1062
- * skip: [/^test/, (key) => key.includes('debug')]
1063
- * })
1064
- * ```
1065
- */
1066
- function instrument(options) {
1067
- const { functions, ...tracingOptions } = options;
1068
- const instrumented = {};
1069
- for (const key of Object.keys(functions)) {
1070
- const typedKey = key;
1071
- const fn = functions[typedKey];
1072
- if (!fn || typeof fn !== "function") {
1073
- instrumented[typedKey] = fn;
1074
- continue;
1075
- }
1076
- if (shouldSkip(key, fn, tracingOptions.skip)) {
1077
- instrumented[typedKey] = fn;
1078
- continue;
1079
- }
1080
- const fnOptions = {
1081
- ...tracingOptions,
1082
- ...tracingOptions.overrides?.[key],
1083
- name: tracingOptions.overrides?.[key]?.name
1084
- };
1085
- const boundFn = fn.bind(functions);
1086
- const fnFactory = (ctx) => {
1087
- return boundFn;
1088
- };
1089
- instrumented[typedKey] = wrapFactoryWithTracing(fnFactory, fnOptions, key);
1090
- }
1091
- return instrumented;
1092
- }
1093
- function span(nameOrOptions, fn) {
1094
- const options = typeof nameOrOptions === "string" ? { name: nameOrOptions } : nameOrOptions;
1095
- const tracer = getConfig().tracer;
1096
- const { name, attributes } = options;
1097
- const executeSpan = (span) => {
1098
- return runInOperationContext(name, () => {
1099
- try {
1100
- if (attributes) for (const [key, value] of Object.entries(attributes)) span.setAttribute(key, value);
1101
- const result = fn(span);
1102
- if (result instanceof Promise) return result.then((resolved) => {
1103
- span.setStatus({ code: SpanStatusCode.OK });
1104
- span.end();
1105
- return resolved;
1106
- }).catch((error) => {
1107
- const errorMessage = error instanceof Error ? error.message.slice(0, MAX_ERROR_MESSAGE_LENGTH) : String(error).slice(0, MAX_ERROR_MESSAGE_LENGTH);
1108
- span.setAttribute("error.message", errorMessage);
1109
- span.setStatus({
1110
- code: SpanStatusCode.ERROR,
1111
- message: errorMessage
1112
- });
1113
- span.recordException(error instanceof Error ? error : new Error(String(error)));
1114
- span.end();
1115
- throw error;
1116
- });
1117
- else {
1118
- span.setStatus({ code: SpanStatusCode.OK });
1119
- span.end();
1120
- return result;
1121
- }
1122
- } catch (error) {
1123
- const errorMessage = error instanceof Error ? error.message.slice(0, MAX_ERROR_MESSAGE_LENGTH) : String(error).slice(0, MAX_ERROR_MESSAGE_LENGTH);
1124
- span.setAttribute("error.message", errorMessage);
1125
- span.setStatus({
1126
- code: SpanStatusCode.ERROR,
1127
- message: errorMessage
1128
- });
1129
- span.recordException(error instanceof Error ? error : new Error(String(error)));
1130
- span.end();
1131
- throw error;
1132
- }
1133
- });
1134
- };
1135
- const parentContext = getActiveContextWithBaggage();
1136
- const result = tracer.startActiveSpan(name, {}, parentContext, executeSpan);
1137
- if (result instanceof Promise) return result;
1138
- return result;
1139
- }
1140
- /**
1141
- * Execute a function in a new root context (prevents span propagation)
1142
- *
1143
- * Useful when you want to start a completely new trace without
1144
- * parent-child relationships.
1145
- *
1146
- * @example
1147
- * ```typescript
1148
- * async function handleWebhook(payload: WebhookPayload) {
1149
- * // This creates a new root trace, not connected to the HTTP request trace
1150
- * await withNewContext({
1151
- * fn: async () => {
1152
- * await trace(ctx => async () => {
1153
- * await processWebhookPayload(payload)
1154
- * })()
1155
- * }
1156
- * })
1157
- * }
1158
- * ```
1159
- */
1160
- async function withNewContext(options) {
1161
- const { fn } = options;
1162
- return getConfig().tracer.startActiveSpan("root", { root: true }, async (span) => {
1163
- try {
1164
- const result = await fn();
1165
- span.setStatus({ code: SpanStatusCode.OK });
1166
- return result;
1167
- } catch (error) {
1168
- span.recordException(error instanceof Error ? error : new Error(String(error)));
1169
- span.setStatus({ code: SpanStatusCode.ERROR });
1170
- throw error;
1171
- } finally {
1172
- span.end();
1173
- }
1174
- });
1175
- }
1176
- /**
1177
- * Execute a function with updated baggage entries
1178
- *
1179
- * Baggage is immutable in OpenTelemetry, so this helper creates a new context
1180
- * with the specified baggage entries and runs the function within that context.
1181
- * All child spans created within the function will inherit the baggage.
1182
- *
1183
- * @example Setting baggage for downstream services
1184
- * ```typescript
1185
- * import { trace, withBaggage } from 'autotel';
1186
- *
1187
- * export const createOrder = trace((ctx) => async (order: Order) => {
1188
- * // Set baggage that will be propagated to downstream HTTP calls
1189
- * return await withBaggage({
1190
- * baggage: {
1191
- * 'tenant.id': order.tenantId,
1192
- * 'user.id': order.userId,
1193
- * },
1194
- * fn: async () => {
1195
- * // This HTTP call will include the baggage in headers
1196
- * await fetch('/api/charge', {
1197
- * method: 'POST',
1198
- * body: JSON.stringify(order),
1199
- * });
1200
- * },
1201
- * });
1202
- * });
1203
- * ```
1204
- *
1205
- * @example Using with existing baggage
1206
- * ```typescript
1207
- * export const processOrder = trace((ctx) => async (order: Order) => {
1208
- * // Read existing baggage
1209
- * const tenantId = ctx.getBaggage('tenant.id');
1210
- *
1211
- * // Add additional baggage entries
1212
- * return await withBaggage({
1213
- * baggage: {
1214
- * 'order.id': order.id,
1215
- * 'order.amount': String(order.amount),
1216
- * },
1217
- * fn: async () => {
1218
- * await charge(order);
1219
- * },
1220
- * });
1221
- * });
1222
- * ```
1223
- */
1224
- function withBaggage(options) {
1225
- const { baggage: baggageEntries, fn } = options;
1226
- const currentContext = context.active();
1227
- let updatedBaggage = propagation.getBaggage(currentContext) ?? propagation.createBaggage();
1228
- for (const [key, value] of Object.entries(baggageEntries)) updatedBaggage = updatedBaggage.setEntry(key, { value });
1229
- const newContext = propagation.setBaggage(currentContext, updatedBaggage);
1230
- const ctxStorage = getContextStorage();
1231
- const previousStored = ctxStorage.getStore();
1232
- const baggageEnrichedStored = previousStored ? { value: propagation.setBaggage(previousStored.value, updatedBaggage) } : { value: newContext };
1233
- const result = previousStored ? ctxStorage.run(baggageEnrichedStored, () => context.with(newContext, fn)) : context.with(newContext, fn);
1234
- if (result instanceof Promise) return result.then((value) => {
1235
- if (previousStored) return ctxStorage.run(previousStored, () => value);
1236
- return value;
1237
- }, (error) => {
1238
- if (previousStored) return ctxStorage.run(previousStored, () => {
1239
- throw error;
1240
- });
1241
- throw error;
1242
- });
1243
- return result;
1244
- }
1245
-
1246
- //#endregion
1247
- export { trace$1 as a, withTracing as c, span as i, instrument as n, withBaggage as o, markAsImmediate as r, withNewContext as s, ctx as t };
1248
- //# sourceMappingURL=functional-dAYhXQPA.js.map