autotel 4.2.5 → 5.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 (387) 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 +1 -1
  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 +1 -1
  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-rzA1X5h3.cjs → event-CwIpFdoY.cjs} +3 -3
  79. package/dist/event-CwIpFdoY.cjs.map +1 -0
  80. package/dist/{event-BEm5IJ8U.js → event-pLMF5b3d.js} +4 -4
  81. package/dist/event-pLMF5b3d.js.map +1 -0
  82. package/dist/{event-subscriber-D1XLkPzi.d.ts → event-subscriber-CWh8sTGh.d.cts} +2 -2
  83. package/dist/event-subscriber-CWh8sTGh.d.cts.map +1 -0
  84. package/dist/{event-subscriber-D1XLkPzi.d.cts → event-subscriber-CWh8sTGh.d.ts} +2 -2
  85. package/dist/event-subscriber-CWh8sTGh.d.ts.map +1 -0
  86. package/dist/event-subscriber.d.cts +1 -1
  87. package/dist/event-subscriber.d.ts +1 -1
  88. package/dist/{event-testing-CfFs3to2.d.ts → event-testing-CA2mIx1E.d.ts} +2 -3
  89. package/dist/event-testing-CA2mIx1E.d.ts.map +1 -0
  90. package/dist/{event-testing-BqRnI0z4.d.cts → event-testing-D0qWfqAy.d.cts} +2 -3
  91. package/dist/event-testing-D0qWfqAy.d.cts.map +1 -0
  92. package/dist/event-testing.d.cts +1 -1
  93. package/dist/event-testing.d.ts +1 -1
  94. package/dist/event.cjs +1 -1
  95. package/dist/event.d.cts +3 -4
  96. package/dist/event.d.cts.map +1 -1
  97. package/dist/event.d.ts +3 -4
  98. package/dist/event.d.ts.map +1 -1
  99. package/dist/event.js +1 -1
  100. package/dist/exporters.d.cts +0 -4
  101. package/dist/exporters.d.cts.map +1 -1
  102. package/dist/exporters.d.ts +0 -4
  103. package/dist/exporters.d.ts.map +1 -1
  104. package/dist/{filtering-span-processor-B8R8B7Uk.d.ts → filtering-span-processor-BpDagWNa.d.cts} +1 -2
  105. package/dist/filtering-span-processor-BpDagWNa.d.cts.map +1 -0
  106. package/dist/{filtering-span-processor-B8R8B7Uk.d.cts → filtering-span-processor-BpDagWNa.d.ts} +1 -2
  107. package/dist/filtering-span-processor-BpDagWNa.d.ts.map +1 -0
  108. package/dist/filtering-span-processor.d.cts +1 -1
  109. package/dist/filtering-span-processor.d.ts +1 -1
  110. package/dist/functional-Bit6noRu.js +840 -0
  111. package/dist/functional-Bit6noRu.js.map +1 -0
  112. package/dist/functional-Cj7PSItS.cjs +890 -0
  113. package/dist/functional-Cj7PSItS.cjs.map +1 -0
  114. package/dist/functional.cjs +2 -2
  115. package/dist/functional.d.cts +79 -130
  116. package/dist/functional.d.cts.map +1 -1
  117. package/dist/functional.d.ts +79 -130
  118. package/dist/functional.d.ts.map +1 -1
  119. package/dist/functional.js +2 -2
  120. package/dist/http.cjs +5 -5
  121. package/dist/http.cjs.map +1 -1
  122. package/dist/http.d.cts +4 -5
  123. package/dist/http.d.cts.map +1 -1
  124. package/dist/http.d.ts +4 -5
  125. package/dist/http.d.ts.map +1 -1
  126. package/dist/http.js +5 -5
  127. package/dist/http.js.map +1 -1
  128. package/dist/{index-eKuioqT1.d.cts → index-BPcxVucm.d.cts} +2 -3
  129. package/dist/index-BPcxVucm.d.cts.map +1 -0
  130. package/dist/{index-Ck06vlW2.d.ts → index-DolOVX6F.d.ts} +2 -3
  131. package/dist/index-DolOVX6F.d.ts.map +1 -0
  132. package/dist/index.cjs +10 -15
  133. package/dist/index.cjs.map +1 -1
  134. package/dist/index.d.cts +14 -14
  135. package/dist/index.d.cts.map +1 -1
  136. package/dist/index.d.ts +14 -14
  137. package/dist/index.d.ts.map +1 -1
  138. package/dist/index.js +11 -16
  139. package/dist/index.js.map +1 -1
  140. package/dist/{init-BxJEJ9Tn.cjs → init-B2uvZReD.cjs} +19 -10
  141. package/dist/init-B2uvZReD.cjs.map +1 -0
  142. package/dist/{init-B7u-DjxM.d.ts → init-CTyqG9qR.d.ts} +24 -17
  143. package/dist/init-CTyqG9qR.d.ts.map +1 -0
  144. package/dist/{init-BvBB45-T.js → init-CdEWjhvl.js} +20 -11
  145. package/dist/init-CdEWjhvl.js.map +1 -0
  146. package/dist/{init-DSrRmVnz.d.cts → init-a4yPDYqC.d.cts} +24 -17
  147. package/dist/init-a4yPDYqC.d.cts.map +1 -0
  148. package/dist/instrumentation.cjs +7 -13
  149. package/dist/instrumentation.cjs.map +1 -1
  150. package/dist/instrumentation.d.cts +0 -1
  151. package/dist/instrumentation.d.cts.map +1 -1
  152. package/dist/instrumentation.d.ts +0 -1
  153. package/dist/instrumentation.d.ts.map +1 -1
  154. package/dist/instrumentation.js +8 -14
  155. package/dist/instrumentation.js.map +1 -1
  156. package/dist/{logger-BauSUhUv.d.ts → logger-CN4xpzMd.d.cts} +1 -2
  157. package/dist/logger-CN4xpzMd.d.cts.map +1 -0
  158. package/dist/{logger-BauSUhUv.d.cts → logger-CN4xpzMd.d.ts} +1 -2
  159. package/dist/logger-CN4xpzMd.d.ts.map +1 -0
  160. package/dist/logger-D3Ej3DII.js.map +1 -1
  161. package/dist/logger-thMPLpOG.cjs.map +1 -1
  162. package/dist/logger.d.cts +1 -1
  163. package/dist/logger.d.ts +1 -1
  164. package/dist/messaging-adapters.cjs.map +1 -1
  165. package/dist/messaging-adapters.d.cts +0 -1
  166. package/dist/messaging-adapters.d.cts.map +1 -1
  167. package/dist/messaging-adapters.d.ts +0 -1
  168. package/dist/messaging-adapters.d.ts.map +1 -1
  169. package/dist/messaging-adapters.js.map +1 -1
  170. package/dist/messaging-testing.d.cts +0 -1
  171. package/dist/messaging-testing.d.cts.map +1 -1
  172. package/dist/messaging-testing.d.ts +0 -1
  173. package/dist/messaging-testing.d.ts.map +1 -1
  174. package/dist/messaging.cjs +27 -10
  175. package/dist/messaging.cjs.map +1 -1
  176. package/dist/messaging.d.cts +6 -7
  177. package/dist/messaging.d.cts.map +1 -1
  178. package/dist/messaging.d.ts +6 -7
  179. package/dist/messaging.d.ts.map +1 -1
  180. package/dist/messaging.js +27 -10
  181. package/dist/messaging.js.map +1 -1
  182. package/dist/metric-helpers.d.cts +0 -1
  183. package/dist/metric-helpers.d.cts.map +1 -1
  184. package/dist/metric-helpers.d.ts +0 -1
  185. package/dist/metric-helpers.d.ts.map +1 -1
  186. package/dist/{metric-testing-DXdK3-Q3.d.ts → metric-testing-CWm6UhaR.d.ts} +2 -3
  187. package/dist/metric-testing-CWm6UhaR.d.ts.map +1 -0
  188. package/dist/{metric-testing-MxvzChDp.d.cts → metric-testing-CpvP3ZIa.d.cts} +2 -3
  189. package/dist/metric-testing-CpvP3ZIa.d.cts.map +1 -0
  190. package/dist/metric-testing.d.cts +1 -1
  191. package/dist/metric-testing.d.ts +1 -1
  192. package/dist/metric.d.cts +3 -4
  193. package/dist/metric.d.cts.map +1 -1
  194. package/dist/metric.d.ts +3 -4
  195. package/dist/metric.d.ts.map +1 -1
  196. package/dist/parse-error.d.cts.map +1 -1
  197. package/dist/parse-error.d.ts.map +1 -1
  198. package/dist/processors.cjs +1 -1
  199. package/dist/processors.d.cts +1 -1
  200. package/dist/processors.d.ts +1 -1
  201. package/dist/processors.js +1 -1
  202. package/dist/register.d.cts +1 -1
  203. package/dist/register.d.ts +1 -1
  204. package/dist/{sampling-DfYhDJij.d.cts → sampling-BR9fkSwx.d.cts} +127 -10
  205. package/dist/sampling-BR9fkSwx.d.cts.map +1 -0
  206. package/dist/{sampling-CR0Va1VB.d.ts → sampling-CP3e7-Yr.d.ts} +127 -10
  207. package/dist/sampling-CP3e7-Yr.d.ts.map +1 -0
  208. package/dist/sampling.cjs +160 -12
  209. package/dist/sampling.cjs.map +1 -1
  210. package/dist/sampling.d.cts +2 -2
  211. package/dist/sampling.d.ts +2 -2
  212. package/dist/sampling.js +157 -13
  213. package/dist/sampling.js.map +1 -1
  214. package/dist/security-schema.d.cts +9 -4
  215. package/dist/security-schema.d.cts.map +1 -1
  216. package/dist/security-schema.d.ts +9 -4
  217. package/dist/security-schema.d.ts.map +1 -1
  218. package/dist/semantic-conventions-FhSxv-bK.d.cts.map +1 -1
  219. package/dist/semantic-conventions-FhSxv-bK.d.ts.map +1 -1
  220. package/dist/semantic-conventions.cjs.map +1 -1
  221. package/dist/semantic-conventions.js.map +1 -1
  222. package/dist/semantic-helpers.cjs +85 -304
  223. package/dist/semantic-helpers.cjs.map +1 -1
  224. package/dist/semantic-helpers.d.cts +21 -12
  225. package/dist/semantic-helpers.d.cts.map +1 -1
  226. package/dist/semantic-helpers.d.ts +21 -12
  227. package/dist/semantic-helpers.d.ts.map +1 -1
  228. package/dist/semantic-helpers.js +85 -304
  229. package/dist/semantic-helpers.js.map +1 -1
  230. package/dist/slo.cjs +225 -0
  231. package/dist/slo.cjs.map +1 -0
  232. package/dist/slo.d.cts +97 -0
  233. package/dist/slo.d.cts.map +1 -0
  234. package/dist/slo.d.ts +97 -0
  235. package/dist/slo.d.ts.map +1 -0
  236. package/dist/slo.js +223 -0
  237. package/dist/slo.js.map +1 -0
  238. package/dist/{span-name-normalizer-8ZOGJuwv.d.ts → span-name-normalizer-CN1-8C76.d.cts} +1 -2
  239. package/dist/span-name-normalizer-CN1-8C76.d.cts.map +1 -0
  240. package/dist/{span-name-normalizer-8ZOGJuwv.d.cts → span-name-normalizer-CN1-8C76.d.ts} +1 -2
  241. package/dist/span-name-normalizer-CN1-8C76.d.ts.map +1 -0
  242. package/dist/span-name-normalizer.cjs.map +1 -1
  243. package/dist/span-name-normalizer.d.cts +1 -1
  244. package/dist/span-name-normalizer.d.ts +1 -1
  245. package/dist/span-name-normalizer.js.map +1 -1
  246. package/dist/tail-sampling-processor.d.cts +0 -1
  247. package/dist/tail-sampling-processor.d.cts.map +1 -1
  248. package/dist/tail-sampling-processor.d.ts +0 -1
  249. package/dist/tail-sampling-processor.d.ts.map +1 -1
  250. package/dist/test-span-collector.cjs +13 -1
  251. package/dist/test-span-collector.cjs.map +1 -1
  252. package/dist/test-span-collector.d.cts +8 -1
  253. package/dist/test-span-collector.d.cts.map +1 -1
  254. package/dist/test-span-collector.d.ts +8 -1
  255. package/dist/test-span-collector.d.ts.map +1 -1
  256. package/dist/test-span-collector.js +13 -1
  257. package/dist/test-span-collector.js.map +1 -1
  258. package/dist/testing.cjs +76 -11
  259. package/dist/testing.cjs.map +1 -1
  260. package/dist/testing.d.cts +30 -5
  261. package/dist/testing.d.cts.map +1 -1
  262. package/dist/testing.d.ts +30 -5
  263. package/dist/testing.d.ts.map +1 -1
  264. package/dist/testing.js +73 -12
  265. package/dist/testing.js.map +1 -1
  266. package/dist/{trace-context-Cijqoi6e.d.ts → trace-context-IuyoPyNq.d.cts} +9 -9
  267. package/dist/trace-context-IuyoPyNq.d.cts.map +1 -0
  268. package/dist/{trace-context-Cijqoi6e.d.cts → trace-context-IuyoPyNq.d.ts} +9 -9
  269. package/dist/trace-context-IuyoPyNq.d.ts.map +1 -0
  270. package/dist/trace-factory-validation-BjVAinz6.js +13 -0
  271. package/dist/trace-factory-validation-BjVAinz6.js.map +1 -0
  272. package/dist/trace-factory-validation-Dc8epn87.cjs +19 -0
  273. package/dist/trace-factory-validation-Dc8epn87.cjs.map +1 -0
  274. package/dist/trace-helpers.cjs +7 -7
  275. package/dist/trace-helpers.cjs.map +1 -1
  276. package/dist/trace-helpers.d.cts +6 -7
  277. package/dist/trace-helpers.d.cts.map +1 -1
  278. package/dist/trace-helpers.d.ts +6 -7
  279. package/dist/trace-helpers.d.ts.map +1 -1
  280. package/dist/trace-helpers.js +7 -7
  281. package/dist/trace-helpers.js.map +1 -1
  282. package/dist/tracer-provider.cjs +27 -0
  283. package/dist/tracer-provider.cjs.map +1 -1
  284. package/dist/tracer-provider.d.cts +19 -2
  285. package/dist/tracer-provider.d.cts.map +1 -1
  286. package/dist/tracer-provider.d.ts +19 -2
  287. package/dist/tracer-provider.d.ts.map +1 -1
  288. package/dist/tracer-provider.js +27 -1
  289. package/dist/tracer-provider.js.map +1 -1
  290. package/dist/{track-D7O7oIZa.js → track-BBcxEJEC.js} +7 -12
  291. package/dist/track-BBcxEJEC.js.map +1 -0
  292. package/dist/{track-eovhCJ-I.cjs → track-BI6dmZ2X.cjs} +6 -17
  293. package/dist/track-BI6dmZ2X.cjs.map +1 -0
  294. package/dist/validate.cjs.map +1 -1
  295. package/dist/validate.d.cts +1 -2
  296. package/dist/validate.d.cts.map +1 -1
  297. package/dist/validate.d.ts +1 -2
  298. package/dist/validate.d.ts.map +1 -1
  299. package/dist/validate.js.map +1 -1
  300. package/dist/validation-attributes.d.cts +17 -8
  301. package/dist/validation-attributes.d.cts.map +1 -1
  302. package/dist/validation-attributes.d.ts +17 -8
  303. package/dist/validation-attributes.d.ts.map +1 -1
  304. package/dist/webhook.cjs +5 -4
  305. package/dist/webhook.cjs.map +1 -1
  306. package/dist/webhook.d.cts +4 -4
  307. package/dist/webhook.d.cts.map +1 -1
  308. package/dist/webhook.d.ts +4 -4
  309. package/dist/webhook.d.ts.map +1 -1
  310. package/dist/webhook.js +5 -4
  311. package/dist/webhook.js.map +1 -1
  312. package/dist/workflow-distributed.cjs +5 -5
  313. package/dist/workflow-distributed.cjs.map +1 -1
  314. package/dist/workflow-distributed.d.cts +25 -15
  315. package/dist/workflow-distributed.d.cts.map +1 -1
  316. package/dist/workflow-distributed.d.ts +25 -15
  317. package/dist/workflow-distributed.d.ts.map +1 -1
  318. package/dist/workflow-distributed.js +5 -5
  319. package/dist/workflow-distributed.js.map +1 -1
  320. package/dist/workflow.cjs +24 -30
  321. package/dist/workflow.cjs.map +1 -1
  322. package/dist/workflow.d.cts +11 -6
  323. package/dist/workflow.d.cts.map +1 -1
  324. package/dist/workflow.d.ts +11 -6
  325. package/dist/workflow.d.ts.map +1 -1
  326. package/dist/workflow.js +24 -30
  327. package/dist/workflow.js.map +1 -1
  328. package/dist/yaml-config.d.cts +2 -3
  329. package/dist/yaml-config.d.cts.map +1 -1
  330. package/dist/yaml-config.d.ts +2 -3
  331. package/dist/yaml-config.d.ts.map +1 -1
  332. package/package.json +23 -14
  333. package/skills/analyze-traces/SKILL.md +42 -13
  334. package/skills/autotel-core/SKILL.md +24 -17
  335. package/skills/autotel-events/SKILL.md +1 -1
  336. package/skills/autotel-frameworks/SKILL.md +41 -6
  337. package/skills/autotel-instrumentation/SKILL.md +14 -9
  338. package/skills/autotel-request-logging/SKILL.md +19 -14
  339. package/skills/autotel-structured-errors/SKILL.md +2 -2
  340. package/skills/build-audit-trails/SKILL.md +11 -11
  341. package/skills/build-audit-trails/references/audit-queries.md +3 -3
  342. package/skills/debug-missing-spans/SKILL.md +12 -12
  343. package/skills/migrate-to-autotel/SKILL.md +20 -20
  344. package/skills/review-otel-patterns/SKILL.md +44 -42
  345. package/skills/review-otel-patterns/references/code-review.md +4 -4
  346. package/skills/review-otel-patterns/references/processor-pipeline.md +3 -3
  347. package/skills/review-otel-patterns/references/structured-errors.md +1 -1
  348. package/skills/review-otel-patterns/references/wide-spans.md +2 -2
  349. package/skills/tune-sampling/SKILL.md +91 -16
  350. package/dist/attribute-redacting-processor-DtTS9xxh.d.cts.map +0 -1
  351. package/dist/attribute-redacting-processor-DtTS9xxh.d.ts.map +0 -1
  352. package/dist/canonical-log-line-processor-BcRuAdRk.d.ts.map +0 -1
  353. package/dist/canonical-log-line-processor-CcrDi6TO.cjs.map +0 -1
  354. package/dist/canonical-log-line-processor-FLezvFCB.js.map +0 -1
  355. package/dist/canonical-log-line-processor-xvjMgtpF.d.cts.map +0 -1
  356. package/dist/define-event-CreknLm3.d.ts.map +0 -1
  357. package/dist/define-event-HZRizPwz.d.cts.map +0 -1
  358. package/dist/event-BEm5IJ8U.js.map +0 -1
  359. package/dist/event-rzA1X5h3.cjs.map +0 -1
  360. package/dist/event-subscriber-D1XLkPzi.d.cts.map +0 -1
  361. package/dist/event-subscriber-D1XLkPzi.d.ts.map +0 -1
  362. package/dist/event-testing-BqRnI0z4.d.cts.map +0 -1
  363. package/dist/event-testing-CfFs3to2.d.ts.map +0 -1
  364. package/dist/filtering-span-processor-B8R8B7Uk.d.cts.map +0 -1
  365. package/dist/filtering-span-processor-B8R8B7Uk.d.ts.map +0 -1
  366. package/dist/functional-BCtxvYir.cjs +0 -1315
  367. package/dist/functional-BCtxvYir.cjs.map +0 -1
  368. package/dist/functional-CrAq8Az8.js +0 -1265
  369. package/dist/functional-CrAq8Az8.js.map +0 -1
  370. package/dist/index-Ck06vlW2.d.ts.map +0 -1
  371. package/dist/index-eKuioqT1.d.cts.map +0 -1
  372. package/dist/init-B7u-DjxM.d.ts.map +0 -1
  373. package/dist/init-BvBB45-T.js.map +0 -1
  374. package/dist/init-BxJEJ9Tn.cjs.map +0 -1
  375. package/dist/init-DSrRmVnz.d.cts.map +0 -1
  376. package/dist/logger-BauSUhUv.d.cts.map +0 -1
  377. package/dist/logger-BauSUhUv.d.ts.map +0 -1
  378. package/dist/metric-testing-DXdK3-Q3.d.ts.map +0 -1
  379. package/dist/metric-testing-MxvzChDp.d.cts.map +0 -1
  380. package/dist/sampling-CR0Va1VB.d.ts.map +0 -1
  381. package/dist/sampling-DfYhDJij.d.cts.map +0 -1
  382. package/dist/span-name-normalizer-8ZOGJuwv.d.cts.map +0 -1
  383. package/dist/span-name-normalizer-8ZOGJuwv.d.ts.map +0 -1
  384. package/dist/trace-context-Cijqoi6e.d.cts.map +0 -1
  385. package/dist/trace-context-Cijqoi6e.d.ts.map +0 -1
  386. package/dist/track-D7O7oIZa.js.map +0 -1
  387. package/dist/track-eovhCJ-I.cjs.map +0 -1
@@ -0,0 +1,890 @@
1
+ const require_rolldown_runtime = require('./rolldown-runtime-C_NdSu1c.cjs');
2
+ const require_tracer_provider = require('./tracer-provider.cjs');
3
+ const require_config = require('./config.cjs');
4
+ const require_sampling = require('./sampling.cjs');
5
+ const require_init = require('./init-B2uvZReD.cjs');
6
+ const require_track = require('./track-BI6dmZ2X.cjs');
7
+ const require_trace_helpers = require('./trace-helpers.cjs');
8
+ const require_operation_context = require('./operation-context-hzKbTKnt.cjs');
9
+ let _opentelemetry_api = require("@opentelemetry/api");
10
+ let node_fs = require("node:fs");
11
+ node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
12
+ let node_url = require("node:url");
13
+ node_url = require_rolldown_runtime.__toESM(node_url, 1);
14
+
15
+ //#region src/variable-name-inference.ts
16
+ /**
17
+ * Variable Name Inference Utility
18
+ *
19
+ * Attempts to infer variable names from const/export const assignments
20
+ * by analyzing the call stack and parsing source code.
21
+ *
22
+ * This is a best-effort approach with graceful degradation - if inference
23
+ * fails for any reason, it returns undefined without breaking the application.
24
+ */
25
+ /**
26
+ * LRU Cache for inferred variable names
27
+ * Key: "file:line" (e.g., "/path/to/file.ts:42")
28
+ * Value: inferred variable name or undefined
29
+ */
30
+ const inferenceCache = /* @__PURE__ */ new Map();
31
+ const MAX_CACHE_SIZE = 50;
32
+ /**
33
+ * Captures the current call stack
34
+ */
35
+ function captureStackTrace() {
36
+ const originalStackTraceLimit = Error.stackTraceLimit;
37
+ Error.stackTraceLimit = 10;
38
+ const stack = (/* @__PURE__ */ new Error("Stack trace capture")).stack || "";
39
+ Error.stackTraceLimit = originalStackTraceLimit;
40
+ return stack;
41
+ }
42
+ /**
43
+ * Parses the stack trace to find where trace() was called
44
+ *
45
+ * Stack trace format (Node.js):
46
+ * at functionName (file:line:column)
47
+ * at file:line:column
48
+ *
49
+ * We skip frames until we find one that's NOT in functional.ts or this file.
50
+ * We also need to skip one additional frame (the trace/span/instrument function itself)
51
+ * to get to the actual user code.
52
+ */
53
+ function parseCallLocation(stack) {
54
+ const lines = stack.split("\n");
55
+ let skippedExternalFrame = false;
56
+ for (const line of lines) {
57
+ if (line.includes("variable-name-inference.ts") || line.includes("variable-name-inference.js") || line.includes("functional.ts") || line.includes("functional.js")) continue;
58
+ const match = line.match(/at\s+(?:.*\s+)?\(?([^:]+):(\d+):(\d+)\)?/) || line.match(/^.*?([^:]+):(\d+):(\d+)/);
59
+ if (match) {
60
+ let filePath = match[1].trim();
61
+ if (filePath.startsWith("file://")) try {
62
+ filePath = node_url.fileURLToPath(filePath);
63
+ } catch {
64
+ continue;
65
+ }
66
+ if (!skippedExternalFrame) {
67
+ skippedExternalFrame = true;
68
+ continue;
69
+ }
70
+ return {
71
+ file: filePath,
72
+ line: Number.parseInt(match[2], 10),
73
+ column: Number.parseInt(match[3], 10)
74
+ };
75
+ }
76
+ }
77
+ }
78
+ /**
79
+ * Reads a specific line from a source file
80
+ */
81
+ function readSourceLine(filePath, lineNumber) {
82
+ try {
83
+ if (typeof node_fs.readFileSync !== "function") return;
84
+ return node_fs.readFileSync(filePath, "utf8").split("\n")[lineNumber - 1];
85
+ } catch {
86
+ return;
87
+ }
88
+ }
89
+ /**
90
+ * Extracts variable name from source code line using regex patterns
91
+ *
92
+ * Supported patterns:
93
+ * - const varName = anyFunction(
94
+ * - export const varName = anyFunction(
95
+ * - let varName = anyFunction(
96
+ * - var varName = anyFunction(
97
+ *
98
+ * Note: This won't work with destructuring assignments or complex patterns
99
+ */
100
+ function extractVariableName(sourceLine) {
101
+ const trimmed = sourceLine.trim();
102
+ for (const pattern of [
103
+ /export\s+const\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/,
104
+ /const\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/,
105
+ /export\s+let\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/,
106
+ /let\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/,
107
+ /export\s+var\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/,
108
+ /var\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=\s*[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/
109
+ ]) {
110
+ const match = trimmed.match(pattern);
111
+ if (match && match[1]) return match[1];
112
+ }
113
+ }
114
+ /**
115
+ * Adds an entry to the cache with LRU eviction
116
+ */
117
+ function cacheInference(key, value) {
118
+ if (inferenceCache.size >= MAX_CACHE_SIZE) {
119
+ const firstKey = inferenceCache.keys().next().value;
120
+ if (firstKey) inferenceCache.delete(firstKey);
121
+ }
122
+ inferenceCache.set(key, value);
123
+ }
124
+ /**
125
+ * Main entry point: Attempts to infer the variable name from the call stack
126
+ *
127
+ * This function:
128
+ * 1. Captures the call stack
129
+ * 2. Parses it to find where trace() was called (file + line)
130
+ * 3. Reads that line from the source file
131
+ * 4. Extracts the variable name using regex
132
+ *
133
+ * Returns undefined if inference fails at any step (graceful degradation).
134
+ * Results are cached to avoid repeated file I/O.
135
+ *
136
+ * @returns The inferred variable name, or undefined if inference failed
137
+ */
138
+ function inferVariableNameFromCallStack() {
139
+ try {
140
+ const callLocation = parseCallLocation(captureStackTrace());
141
+ if (!callLocation) return;
142
+ const cacheKey = `${callLocation.file}:${callLocation.line}`;
143
+ if (inferenceCache.has(cacheKey)) return inferenceCache.get(cacheKey);
144
+ const sourceLine = readSourceLine(callLocation.file, callLocation.line);
145
+ if (!sourceLine) return;
146
+ const variableName = extractVariableName(sourceLine);
147
+ cacheInference(cacheKey, variableName);
148
+ return variableName;
149
+ } catch {
150
+ return;
151
+ }
152
+ }
153
+
154
+ //#endregion
155
+ //#region src/functional.ts
156
+ /**
157
+ * Functional API for non-class code
158
+ *
159
+ * Three approaches for different use cases:
160
+ * 1. trace() - Zero-ceremony HOF for single functions
161
+ * 2. withTracing() - Middleware-style composable wrapper
162
+ * 3. instrument() - Batch auto-instrumentation for modules
163
+ *
164
+ * @example trace() - Single function
165
+ * ```typescript
166
+ * export const createUser = trace(async (data) => {
167
+ * getActiveTraceContext()?.setAttribute('user.id', data.id)
168
+ * return await db.users.create(data)
169
+ * })
170
+ * ```
171
+ *
172
+ * @example withTracing() - Composable middleware
173
+ * ```typescript
174
+ * export const createUser = withTracing({
175
+ * name: 'user.create'
176
+ * })(ctx => async (data) => {
177
+ * ctx.setAttribute('user.id', data.id)
178
+ * return await db.users.create(data)
179
+ * })
180
+ * ```
181
+ *
182
+ * @example instrument() - Batch instrumentation
183
+ * ```typescript
184
+ * export default instrument({
185
+ * createUser: async (data) => { },
186
+ * updateUser: async (id, data) => { }
187
+ * }, { serviceName: 'user' })
188
+ * ```
189
+ */
190
+ let unknownSpanNameWarningEmitted = false;
191
+ function resolveVariableName(named, variableName) {
192
+ const suppliedFunctionName = inferFunctionName(named);
193
+ const callStackVariableName = suppliedFunctionName ? void 0 : inferVariableNameFromCallStack();
194
+ return variableName || suppliedFunctionName || callStackVariableName;
195
+ }
196
+ /**
197
+ * Wrap an explicit context factory `(ctx) => (...args) => result`.
198
+ * Used by {@link withTracing}; the input is a factory by contract, so there is
199
+ * no plain-vs-factory detection. The factory is never invoked at construction
200
+ * time — only when the wrapper is called.
201
+ */
202
+ function wrapFactoryWithTracing(factory, options, variableName) {
203
+ return wrapWithTracingSync(factory, options, resolveVariableName(factory, variableName));
204
+ }
205
+ /**
206
+ * Wrap a plain function `(...args) => result`. Used by {@link trace} and
207
+ * {@link instrument}: the function receives its real arguments and no context
208
+ * is injected. Reach the active span via {@link getActiveTraceContext} inside
209
+ * the body (or any helper it calls).
210
+ */
211
+ function wrapPlainWithTracing(fn, options, variableName) {
212
+ const effectiveVariableName = resolveVariableName(fn, variableName);
213
+ const factory = (_ctx) => fn;
214
+ return wrapWithTracingSync(factory, options, effectiveVariableName);
215
+ }
216
+ const MAX_ERROR_MESSAGE_LENGTH = 500;
217
+ function createDummyCtx() {
218
+ return {
219
+ traceId: "",
220
+ spanId: "",
221
+ correlationId: "",
222
+ setAttribute: () => {},
223
+ setAttributes: () => {},
224
+ setStatus: () => {},
225
+ recordException: () => {},
226
+ addEvent: () => {},
227
+ addLink: () => {},
228
+ addLinks: () => {},
229
+ updateName: () => {},
230
+ isRecording: () => false,
231
+ getBaggage: () => {},
232
+ setBaggage: () => "",
233
+ deleteBaggage: () => {},
234
+ getAllBaggage: () => /* @__PURE__ */ new Map()
235
+ };
236
+ }
237
+ /** Attribute keys for opt-in function I/O capture (see TracingOptions). */
238
+ const AUTOTEL_INPUT_ATTR = "autotel.input";
239
+ const AUTOTEL_OUTPUT_ATTR = "autotel.output";
240
+ const CAPTURE_MAX_CHARS = 4096;
241
+ /** JSON-serialize a captured value, defensively (truncate, swallow cycles). */
242
+ function serializeCapture(value) {
243
+ if (value === void 0) return void 0;
244
+ try {
245
+ const json = typeof value === "string" ? value : JSON.stringify(value);
246
+ if (json === void 0) return void 0;
247
+ return json.length > CAPTURE_MAX_CHARS ? `${json.slice(0, CAPTURE_MAX_CHARS)}…[truncated]` : json;
248
+ } catch {
249
+ return;
250
+ }
251
+ }
252
+ /** `autotel.input` from args (single arg captured directly, else the array). */
253
+ function captureInputAttrs(args, enabled) {
254
+ if (!enabled) return {};
255
+ const s = serializeCapture(args.length === 1 ? args[0] : args);
256
+ return s === void 0 ? {} : { [AUTOTEL_INPUT_ATTR]: s };
257
+ }
258
+ /** `autotel.output` from the return value. */
259
+ function captureOutputAttrs(result, enabled) {
260
+ if (!enabled) return {};
261
+ const s = serializeCapture(result);
262
+ return s === void 0 ? {} : { [AUTOTEL_OUTPUT_ATTR]: s };
263
+ }
264
+ const INSTRUMENTED_SYMBOL = Symbol.for("autotel.functional.instrumented");
265
+ function hasInstrumentationFlag(value) {
266
+ return (typeof value === "function" || typeof value === "object") && value !== null && Boolean(value[INSTRUMENTED_SYMBOL]);
267
+ }
268
+ /**
269
+ * Truncate error message to prevent span bloat
270
+ */
271
+ function truncateErrorMessage(message) {
272
+ if (message.length <= MAX_ERROR_MESSAGE_LENGTH) return message;
273
+ return `${message.slice(0, MAX_ERROR_MESSAGE_LENGTH)}... (truncated)`;
274
+ }
275
+ /**
276
+ * Terminal handling for a value thrown by a traced function. Shared by all four
277
+ * `trace()` execution paths (immediate + wrapper, sync + async) so the outcome
278
+ * rules live in exactly one place. Ends the span; the caller flushes (await/void)
279
+ * and rethrows.
280
+ *
281
+ * If `isError` classifies the throw as expected control flow — e.g. a framework
282
+ * `redirect()` / `notFound()` signal — it is recorded as a success outcome with
283
+ * an OK status and no exception. Otherwise it is recorded as an error.
284
+ */
285
+ function finalizeThrownSpan(error, isError, ctx) {
286
+ const { span, spanName, duration, callCounter, durationHistogram, handleTailSampling, extraAttributes } = ctx;
287
+ const baseAttributes = {
288
+ ...extraAttributes,
289
+ "operation.name": spanName,
290
+ "code.function": spanName,
291
+ "operation.duration": duration
292
+ };
293
+ if (isError && !isError(error)) {
294
+ callCounter?.add(1, {
295
+ operation: spanName,
296
+ status: "success"
297
+ });
298
+ durationHistogram?.record(duration, {
299
+ operation: spanName,
300
+ status: "success"
301
+ });
302
+ span.setStatus({ code: _opentelemetry_api.SpanStatusCode.OK });
303
+ span.setAttributes({
304
+ ...baseAttributes,
305
+ "operation.success": true
306
+ });
307
+ handleTailSampling(true, duration);
308
+ span.end();
309
+ return;
310
+ }
311
+ callCounter?.add(1, {
312
+ operation: spanName,
313
+ status: "error"
314
+ });
315
+ durationHistogram?.record(duration, {
316
+ operation: spanName,
317
+ status: "error"
318
+ });
319
+ const truncatedMessage = truncateErrorMessage(error instanceof Error ? error.message : "Unknown error");
320
+ span.setStatus({
321
+ code: _opentelemetry_api.SpanStatusCode.ERROR,
322
+ message: truncatedMessage
323
+ });
324
+ span.setAttributes({
325
+ ...baseAttributes,
326
+ "operation.success": false,
327
+ error: true,
328
+ "exception.type": error instanceof Error ? error.constructor.name : "Error",
329
+ "exception.message": truncatedMessage
330
+ });
331
+ if (error instanceof Error && error.stack) span.setAttribute("exception.stack", error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH));
332
+ const thrown = error instanceof Error ? error : new Error(String(error));
333
+ span.recordException(thrown);
334
+ handleTailSampling(false, duration, thrown);
335
+ span.end();
336
+ }
337
+ /**
338
+ * Try to infer function name from function properties
339
+ * Checks for displayName, name, or other metadata that might be set
340
+ */
341
+ function inferFunctionName(fn) {
342
+ const displayName = fn.displayName;
343
+ if (displayName) return displayName;
344
+ if (fn.name && fn.name !== "anonymous" && fn.name !== "") return fn.name;
345
+ const match = Function.prototype.toString.call(fn).match(/function\s+([^(\s]+)/);
346
+ if (match && match[1] && match[1] !== "anonymous") return match[1];
347
+ }
348
+ /**
349
+ * Determine span name using priority:
350
+ * 1. Explicit name option
351
+ * 2. serviceName + functionName
352
+ * 3. Inferred from function/variable name (including stack trace fallback)
353
+ * 4. Fallback to 'unknown'
354
+ */
355
+ function getSpanName(options, fn, variableName) {
356
+ if (options.name) return options.name;
357
+ let fnName = variableName || inferFunctionName(fn);
358
+ fnName = fnName || "anonymous";
359
+ if (options.serviceName) return `${options.serviceName}.${fnName}`;
360
+ if (fnName && fnName !== "anonymous") return fnName;
361
+ const initConfig = require_init.getConfig();
362
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production" && !unknownSpanNameWarningEmitted && initConfig?.logger?.warn) {
363
+ unknownSpanNameWarningEmitted = true;
364
+ initConfig.logger.warn({}, "[autotel] Span name resolved to \"unknown\". Pass an explicit name, for example trace(\"operation.name\", fn).");
365
+ }
366
+ return "unknown";
367
+ }
368
+ /**
369
+ * Check if function should be skipped
370
+ */
371
+ function shouldSkip(key, fn, skip) {
372
+ if (key.startsWith("_")) return true;
373
+ if (!skip || skip.length === 0) return false;
374
+ for (const rule of skip) if (typeof rule === "string" && key === rule) return true;
375
+ else if (rule instanceof RegExp && rule.test(key)) return true;
376
+ else if (typeof rule === "function" && rule(key, fn)) return true;
377
+ return false;
378
+ }
379
+ /**
380
+ * Get current trace context value (internal helper)
381
+ *
382
+ * Returns base context (trace IDs) + span methods from the active span.
383
+ */
384
+ function getCtxValue() {
385
+ const activeSpan = _opentelemetry_api.trace.getActiveSpan();
386
+ if (!activeSpan) return null;
387
+ return require_track.createTraceContext(activeSpan);
388
+ }
389
+ /**
390
+ * Get the autotel {@link TraceContext} for the currently active span.
391
+ *
392
+ * This is the ambient accessor for the functional API: instead of threading a
393
+ * `ctx` parameter through a factory, call this inside any traced function (or a
394
+ * helper it calls) to reach `setAttribute`, `setUser`, `getBaggage`, and the
395
+ * rest of the context surface. Returns `undefined` when no span is active.
396
+ *
397
+ * @example
398
+ * ```typescript
399
+ * const getUser = trace('getUser', async (id: string) => {
400
+ * getActiveTraceContext()?.setAttribute('user.id', id);
401
+ * return db.users.find(id);
402
+ * });
403
+ * ```
404
+ *
405
+ * @see getActiveSpan for the raw OpenTelemetry span
406
+ * @see getRequestLogger which reads the active context when called with no args
407
+ */
408
+ function getActiveTraceContext() {
409
+ return getCtxValue() ?? void 0;
410
+ }
411
+ /**
412
+ * Context object that lazily evaluates the active span on property access
413
+ *
414
+ * Access trace context directly without function call syntax.
415
+ *
416
+ * @example
417
+ * ```typescript
418
+ * import { trace, ctx } from 'autotel'
419
+ *
420
+ * export const createUser = trace(async (data) => {
421
+ * // Direct property access - no function call!
422
+ * if (ctx.traceId) {
423
+ * ctx.setAttribute('user.id', data.id)
424
+ * console.log('Trace:', ctx.traceId)
425
+ * }
426
+ * })
427
+ * ```
428
+ */
429
+ const ctx = new Proxy({}, {
430
+ get(_target, prop) {
431
+ const ctxValue = getCtxValue();
432
+ if (!ctxValue) return;
433
+ return ctxValue[prop];
434
+ },
435
+ has(_target, prop) {
436
+ const ctxValue = getCtxValue();
437
+ if (!ctxValue) return false;
438
+ return prop in ctxValue;
439
+ },
440
+ ownKeys() {
441
+ const ctxValue = getCtxValue();
442
+ if (!ctxValue) return [];
443
+ return Object.keys(ctxValue);
444
+ },
445
+ getOwnPropertyDescriptor(_target, prop) {
446
+ const ctxValue = getCtxValue();
447
+ if (!ctxValue) return;
448
+ return Object.getOwnPropertyDescriptor(ctxValue, prop);
449
+ }
450
+ });
451
+ /**
452
+ * Build the root-operation flush policy once and reuse it for wrapped and
453
+ * immediate execution. Async operations await this function; sync operations
454
+ * trigger it without blocking.
455
+ */
456
+ function createRootTelemetryFlusher(options, isRootSpan) {
457
+ const initConfig = require_init.getConfig();
458
+ const shouldFlush = options.flushOnRootSpanEnd ?? initConfig?.flushOnRootSpanEnd ?? true;
459
+ const shouldFlushSpans = initConfig?.forceFlushOnShutdown ?? false;
460
+ return async () => {
461
+ if (!shouldFlush || !isRootSpan) return;
462
+ try {
463
+ const queue = require_track.getEventQueue();
464
+ if (queue && queue.size() > 0) await queue.flush();
465
+ if (shouldFlushSpans) await require_tracer_provider.getForceFlushableProvider(require_init.getSdk())?.forceFlush();
466
+ } catch (error) {
467
+ (require_init.getConfig()?.logger)?.error?.({ err: error instanceof Error ? error : void 0 }, `[autotel] Auto-flush failed${error instanceof Error ? "" : `: ${String(error)}`}`);
468
+ }
469
+ };
470
+ }
471
+ /**
472
+ * Give every root operation its own baggage context without replacing a
473
+ * caller's existing scope. AsyncLocalStorage keeps the scope alive until an
474
+ * async result settles and restores the previous store afterwards.
475
+ */
476
+ function runWithTraceContextStorage(fn) {
477
+ const storage = require_track.getContextStorage();
478
+ if (storage.getStore()) return fn();
479
+ return storage.run({ value: _opentelemetry_api.context.active() }, fn);
480
+ }
481
+ /**
482
+ * Core tracing wrapper for sync functions (internal implementation)
483
+ */
484
+ function wrapWithTracingSync(fnFactory, options, variableName) {
485
+ if (hasInstrumentationFlag(fnFactory)) {}
486
+ const config = require_config.getConfig();
487
+ const tracer = config.tracer;
488
+ const meter = config.meter;
489
+ const sampler = options.sampler || new require_sampling.AlwaysSampler();
490
+ const spanName = getSpanName(options, fnFactory, variableName);
491
+ const callCounter = options.withMetrics ? meter.createCounter(`${spanName}.calls`, {
492
+ description: `Call count for ${spanName}`,
493
+ unit: "1"
494
+ }) : void 0;
495
+ const durationHistogram = options.withMetrics ? meter.createHistogram(`${spanName}.duration`, {
496
+ description: `Duration for ${spanName}`,
497
+ unit: "ms"
498
+ }) : void 0;
499
+ function wrappedFunction(...args) {
500
+ const samplingContext = {
501
+ operationName: spanName,
502
+ args,
503
+ metadata: {}
504
+ };
505
+ const shouldSample = sampler.shouldSample(samplingContext);
506
+ const sampleRate = sampler.sampleRate?.(samplingContext);
507
+ const needsTailSampling = sampler.needsTailSampling?.() ?? false;
508
+ if (!shouldSample && !needsTailSampling) return fnFactory(createDummyCtx()).call(this, ...args);
509
+ const startTime = performance.now();
510
+ const flushRootTelemetry = createRootTelemetryFlusher(options, options.startNewRoot || _opentelemetry_api.trace.getActiveSpan() === void 0);
511
+ const spanOptions = {};
512
+ if (options.startNewRoot) spanOptions.root = true;
513
+ if (options.spanKind !== void 0) spanOptions.kind = options.spanKind;
514
+ const parentContext = require_track.getActiveContextWithBaggage();
515
+ return tracer.startActiveSpan(spanName, spanOptions, parentContext, (span) => {
516
+ return require_operation_context.runInOperationContext(spanName, () => runWithTraceContextStorage(() => {
517
+ let shouldKeepSpan = true;
518
+ require_trace_helpers.setSpanName(span, spanName);
519
+ if (sampleRate !== void 0 && sampleRate > 1) span.setAttribute(require_sampling.AUTOTEL_SAMPLING_RATE, sampleRate);
520
+ const fn = fnFactory(require_track.createTraceContext(span));
521
+ const argsAttributes = {
522
+ ...captureInputAttrs(args, options.captureInput),
523
+ ...options.attributesFromArgs ? options.attributesFromArgs(args) : {}
524
+ };
525
+ const handleTailSampling = (success, duration, error) => {
526
+ if (needsTailSampling && sampler.shouldKeepTrace) {
527
+ shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
528
+ success,
529
+ duration,
530
+ error
531
+ });
532
+ span.setAttribute(require_sampling.AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
533
+ span.setAttribute(require_sampling.AUTOTEL_SAMPLING_TAIL_EVALUATED, true);
534
+ }
535
+ };
536
+ const onSuccess = (result) => {
537
+ const duration = performance.now() - startTime;
538
+ callCounter?.add(1, {
539
+ operation: spanName,
540
+ status: "success"
541
+ });
542
+ durationHistogram?.record(duration, {
543
+ operation: spanName,
544
+ status: "success"
545
+ });
546
+ const resultAttributes = {
547
+ ...captureOutputAttrs(result, options.captureOutput),
548
+ ...options.attributesFromResult ? options.attributesFromResult(result) : {}
549
+ };
550
+ span.setStatus({ code: _opentelemetry_api.SpanStatusCode.OK });
551
+ span.setAttributes({
552
+ ...argsAttributes,
553
+ ...resultAttributes,
554
+ "operation.name": spanName,
555
+ "code.function": spanName,
556
+ "operation.duration": duration,
557
+ "operation.success": true
558
+ });
559
+ handleTailSampling(true, duration);
560
+ span.end();
561
+ return result;
562
+ };
563
+ const onError = (error) => {
564
+ finalizeThrownSpan(error, options.isError, {
565
+ span,
566
+ spanName,
567
+ duration: performance.now() - startTime,
568
+ callCounter,
569
+ durationHistogram,
570
+ handleTailSampling,
571
+ extraAttributes: argsAttributes
572
+ });
573
+ throw error;
574
+ };
575
+ try {
576
+ callCounter?.add(1, {
577
+ operation: spanName,
578
+ status: "started"
579
+ });
580
+ const result = _opentelemetry_api.context.with(require_track.getActiveContextWithBaggage(), () => fn.call(this, ...args));
581
+ if (result instanceof Promise) return result.then(async (value) => {
582
+ const completed = onSuccess(value);
583
+ await flushRootTelemetry();
584
+ return completed;
585
+ }, async (error) => {
586
+ try {
587
+ return onError(error);
588
+ } finally {
589
+ await flushRootTelemetry();
590
+ }
591
+ });
592
+ const completed = onSuccess(result);
593
+ flushRootTelemetry();
594
+ return completed;
595
+ } catch (error) {
596
+ try {
597
+ return onError(error);
598
+ } finally {
599
+ flushRootTelemetry();
600
+ }
601
+ }
602
+ }));
603
+ });
604
+ }
605
+ wrappedFunction[INSTRUMENTED_SYMBOL] = true;
606
+ Object.defineProperty(wrappedFunction, "name", {
607
+ value: variableName || "trace",
608
+ configurable: true
609
+ });
610
+ return wrappedFunction;
611
+ }
612
+ function trace(fnOrNameOrOptions, maybeFn) {
613
+ if (typeof fnOrNameOrOptions === "function") return wrapPlainWithTracing(fnOrNameOrOptions, {});
614
+ if (!maybeFn) throw new Error("trace(name|options, fn): fn is required");
615
+ return wrapPlainWithTracing(maybeFn, typeof fnOrNameOrOptions === "string" ? { name: fnOrNameOrOptions } : fnOrNameOrOptions);
616
+ }
617
+ /**
618
+ * Approach 2: withTracing() - Middleware-style composable wrapper
619
+ *
620
+ * Returns a HOF that wraps functions with tracing.
621
+ * Perfect for composition and reusable configuration.
622
+ *
623
+ * @example Standard usage
624
+ * ```typescript
625
+ * export const createUser = withTracing({
626
+ * name: 'user.create'
627
+ * })(ctx => async (data) => {
628
+ * ctx.setAttribute('user.id', data.id)
629
+ * return await db.users.create(data)
630
+ * })
631
+ * ```
632
+ *
633
+ * @example Composable
634
+ * ```typescript
635
+ * const tracer = withTracing({ serviceName: 'user' })
636
+ *
637
+ * export const createUser = tracer(ctx => async (data) => { })
638
+ * export const updateUser = tracer(ctx => async (id, data) => { })
639
+ * ```
640
+ *
641
+ * @example With other middleware
642
+ * ```typescript
643
+ * export const createUser = compose(
644
+ * withAuth({ role: 'admin' }),
645
+ * withTracing({ name: 'user.create' }),
646
+ * withRateLimit({ max: 100 })
647
+ * )(ctx => async (data) => { })
648
+ * ```
649
+ */
650
+ function withTracing(options = {}) {
651
+ return (fnFactory) => wrapFactoryWithTracing(fnFactory, options);
652
+ }
653
+ function instrument(options) {
654
+ if (!options || typeof options !== "object") throw new TypeError("instrument: expected { key, fn } or { functions: { name: fn } }");
655
+ if ("key" in options || "fn" in options) {
656
+ const { key, fn, ...tracingOptions } = options;
657
+ if (typeof key !== "string" || key.trim() === "") throw new TypeError("instrument: \"key\" must be a non-empty string in the { key, fn } form");
658
+ if (typeof fn !== "function") throw new TypeError("instrument: \"fn\" must be a function in the { key, fn } form");
659
+ return wrapPlainWithTracing(fn, tracingOptions, key);
660
+ }
661
+ const { functions, ...tracingOptions } = options;
662
+ if (!functions || typeof functions !== "object") throw new TypeError("instrument: expected { key, fn } or { functions: { name: fn } }");
663
+ const instrumented = {};
664
+ for (const key of Object.keys(functions)) {
665
+ const typedKey = key;
666
+ const fn = functions[typedKey];
667
+ if (!fn || typeof fn !== "function") {
668
+ instrumented[typedKey] = fn;
669
+ continue;
670
+ }
671
+ if (shouldSkip(key, fn, tracingOptions.skip)) {
672
+ instrumented[typedKey] = fn;
673
+ continue;
674
+ }
675
+ const fnOptions = {
676
+ ...tracingOptions,
677
+ ...tracingOptions.overrides?.[key],
678
+ name: tracingOptions.overrides?.[key]?.name
679
+ };
680
+ const boundFn = fn.bind(functions);
681
+ const fnFactory = (ctx) => {
682
+ return boundFn;
683
+ };
684
+ instrumented[typedKey] = wrapFactoryWithTracing(fnFactory, fnOptions, key);
685
+ }
686
+ return instrumented;
687
+ }
688
+ function span(nameOrOptions, fn) {
689
+ const options = typeof nameOrOptions === "string" ? { name: nameOrOptions } : nameOrOptions;
690
+ const tracer = require_config.getConfig().tracer;
691
+ const { name, attributes, spanKind } = options;
692
+ const executeSpan = (span) => {
693
+ return require_operation_context.runInOperationContext(name, () => {
694
+ try {
695
+ if (attributes) for (const [key, value] of Object.entries(attributes)) span.setAttribute(key, value);
696
+ const result = fn(span);
697
+ if (result instanceof Promise) return result.then((resolved) => {
698
+ span.setStatus({ code: _opentelemetry_api.SpanStatusCode.OK });
699
+ span.end();
700
+ return resolved;
701
+ }).catch((error) => {
702
+ const errorMessage = error instanceof Error ? error.message.slice(0, MAX_ERROR_MESSAGE_LENGTH) : String(error).slice(0, MAX_ERROR_MESSAGE_LENGTH);
703
+ span.setAttribute("error.message", errorMessage);
704
+ span.setStatus({
705
+ code: _opentelemetry_api.SpanStatusCode.ERROR,
706
+ message: errorMessage
707
+ });
708
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
709
+ span.end();
710
+ throw error;
711
+ });
712
+ else {
713
+ span.setStatus({ code: _opentelemetry_api.SpanStatusCode.OK });
714
+ span.end();
715
+ return result;
716
+ }
717
+ } catch (error) {
718
+ const errorMessage = error instanceof Error ? error.message.slice(0, MAX_ERROR_MESSAGE_LENGTH) : String(error).slice(0, MAX_ERROR_MESSAGE_LENGTH);
719
+ span.setAttribute("error.message", errorMessage);
720
+ span.setStatus({
721
+ code: _opentelemetry_api.SpanStatusCode.ERROR,
722
+ message: errorMessage
723
+ });
724
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
725
+ span.end();
726
+ throw error;
727
+ }
728
+ });
729
+ };
730
+ const parentContext = require_track.getActiveContextWithBaggage();
731
+ const result = tracer.startActiveSpan(name, spanKind === void 0 ? {} : { kind: spanKind }, parentContext, executeSpan);
732
+ if (result instanceof Promise) return result;
733
+ return result;
734
+ }
735
+ /**
736
+ * Execute a function in a new root context (prevents span propagation)
737
+ *
738
+ * Useful when you want to start a completely new trace without
739
+ * parent-child relationships.
740
+ *
741
+ * @example
742
+ * ```typescript
743
+ * async function handleWebhook(payload: WebhookPayload) {
744
+ * // This creates a new root trace, not connected to the HTTP request trace
745
+ * await withNewContext({
746
+ * fn: async () => {
747
+ * await span('webhook.process', async () => {
748
+ * await processWebhookPayload(payload)
749
+ * })
750
+ * }
751
+ * })
752
+ * }
753
+ * ```
754
+ */
755
+ async function withNewContext(options) {
756
+ const { fn } = options;
757
+ return require_config.getConfig().tracer.startActiveSpan("root", { root: true }, async (span) => {
758
+ try {
759
+ const result = await fn();
760
+ span.setStatus({ code: _opentelemetry_api.SpanStatusCode.OK });
761
+ return result;
762
+ } catch (error) {
763
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
764
+ span.setStatus({ code: _opentelemetry_api.SpanStatusCode.ERROR });
765
+ throw error;
766
+ } finally {
767
+ span.end();
768
+ }
769
+ });
770
+ }
771
+ /**
772
+ * Execute a function with updated baggage entries
773
+ *
774
+ * Baggage is immutable in OpenTelemetry, so this helper creates a new context
775
+ * with the specified baggage entries and runs the function within that context.
776
+ * All child spans created within the function will inherit the baggage.
777
+ *
778
+ * @example Setting baggage for downstream services
779
+ * ```typescript
780
+ * import { withTracing, withBaggage } from 'autotel';
781
+ *
782
+ * export const createOrder = withTracing({ name: 'order.create' })((ctx) => async (order: Order) => {
783
+ * // Set baggage that will be propagated to downstream HTTP calls
784
+ * return await withBaggage({
785
+ * baggage: {
786
+ * 'tenant.id': order.tenantId,
787
+ * 'user.id': order.userId,
788
+ * },
789
+ * fn: async () => {
790
+ * // This HTTP call will include the baggage in headers
791
+ * await fetch('/api/charge', {
792
+ * method: 'POST',
793
+ * body: JSON.stringify(order),
794
+ * });
795
+ * },
796
+ * });
797
+ * });
798
+ * ```
799
+ *
800
+ * @example Using with existing baggage
801
+ * ```typescript
802
+ * export const processOrder = withTracing({ name: 'order.process' })((ctx) => async (order: Order) => {
803
+ * // Read existing baggage
804
+ * const tenantId = ctx.getBaggage('tenant.id');
805
+ *
806
+ * // Add additional baggage entries
807
+ * return await withBaggage({
808
+ * baggage: {
809
+ * 'order.id': order.id,
810
+ * 'order.amount': String(order.amount),
811
+ * },
812
+ * fn: async () => {
813
+ * await charge(order);
814
+ * },
815
+ * });
816
+ * });
817
+ * ```
818
+ */
819
+ function withBaggage(options) {
820
+ const { baggage: baggageEntries, fn } = options;
821
+ const currentContext = _opentelemetry_api.context.active();
822
+ let updatedBaggage = _opentelemetry_api.propagation.getBaggage(currentContext) ?? _opentelemetry_api.propagation.createBaggage();
823
+ for (const [key, value] of Object.entries(baggageEntries)) updatedBaggage = updatedBaggage.setEntry(key, { value });
824
+ const newContext = _opentelemetry_api.propagation.setBaggage(currentContext, updatedBaggage);
825
+ const ctxStorage = require_track.getContextStorage();
826
+ const previousStored = ctxStorage.getStore();
827
+ const baggageEnrichedStored = previousStored ? { value: _opentelemetry_api.propagation.setBaggage(previousStored.value, updatedBaggage) } : { value: newContext };
828
+ const result = previousStored ? ctxStorage.run(baggageEnrichedStored, () => _opentelemetry_api.context.with(newContext, fn)) : _opentelemetry_api.context.with(newContext, fn);
829
+ if (result instanceof Promise) return result.then((value) => {
830
+ if (previousStored) return ctxStorage.run(previousStored, () => value);
831
+ return value;
832
+ }, (error) => {
833
+ if (previousStored) return ctxStorage.run(previousStored, () => {
834
+ throw error;
835
+ });
836
+ throw error;
837
+ });
838
+ return result;
839
+ }
840
+
841
+ //#endregion
842
+ Object.defineProperty(exports, 'ctx', {
843
+ enumerable: true,
844
+ get: function () {
845
+ return ctx;
846
+ }
847
+ });
848
+ Object.defineProperty(exports, 'getActiveTraceContext', {
849
+ enumerable: true,
850
+ get: function () {
851
+ return getActiveTraceContext;
852
+ }
853
+ });
854
+ Object.defineProperty(exports, 'instrument', {
855
+ enumerable: true,
856
+ get: function () {
857
+ return instrument;
858
+ }
859
+ });
860
+ Object.defineProperty(exports, 'span', {
861
+ enumerable: true,
862
+ get: function () {
863
+ return span;
864
+ }
865
+ });
866
+ Object.defineProperty(exports, 'trace', {
867
+ enumerable: true,
868
+ get: function () {
869
+ return trace;
870
+ }
871
+ });
872
+ Object.defineProperty(exports, 'withBaggage', {
873
+ enumerable: true,
874
+ get: function () {
875
+ return withBaggage;
876
+ }
877
+ });
878
+ Object.defineProperty(exports, 'withNewContext', {
879
+ enumerable: true,
880
+ get: function () {
881
+ return withNewContext;
882
+ }
883
+ });
884
+ Object.defineProperty(exports, 'withTracing', {
885
+ enumerable: true,
886
+ get: function () {
887
+ return withTracing;
888
+ }
889
+ });
890
+ //# sourceMappingURL=functional-Cj7PSItS.cjs.map