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,840 @@
1
+ import { getForceFlushableProvider } from "./tracer-provider.js";
2
+ import { getConfig } from "./config.js";
3
+ import { AUTOTEL_SAMPLING_RATE, AUTOTEL_SAMPLING_TAIL_EVALUATED, AUTOTEL_SAMPLING_TAIL_KEEP, AlwaysSampler } from "./sampling.js";
4
+ import { a as getSdk, n as getConfig$1 } from "./init-CdEWjhvl.js";
5
+ import { g as getContextStorage, h as getActiveContextWithBaggage, p as createTraceContext, t as getEventQueue } from "./track-BBcxEJEC.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(async (data) => {
164
+ * getActiveTraceContext()?.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
+ let unknownSpanNameWarningEmitted = false;
188
+ function resolveVariableName(named, variableName) {
189
+ const suppliedFunctionName = inferFunctionName(named);
190
+ const callStackVariableName = suppliedFunctionName ? void 0 : inferVariableNameFromCallStack();
191
+ return variableName || suppliedFunctionName || callStackVariableName;
192
+ }
193
+ /**
194
+ * Wrap an explicit context factory `(ctx) => (...args) => result`.
195
+ * Used by {@link withTracing}; the input is a factory by contract, so there is
196
+ * no plain-vs-factory detection. The factory is never invoked at construction
197
+ * time — only when the wrapper is called.
198
+ */
199
+ function wrapFactoryWithTracing(factory, options, variableName) {
200
+ return wrapWithTracingSync(factory, options, resolveVariableName(factory, variableName));
201
+ }
202
+ /**
203
+ * Wrap a plain function `(...args) => result`. Used by {@link trace} and
204
+ * {@link instrument}: the function receives its real arguments and no context
205
+ * is injected. Reach the active span via {@link getActiveTraceContext} inside
206
+ * the body (or any helper it calls).
207
+ */
208
+ function wrapPlainWithTracing(fn, options, variableName) {
209
+ const effectiveVariableName = resolveVariableName(fn, variableName);
210
+ const factory = (_ctx) => fn;
211
+ return wrapWithTracingSync(factory, options, effectiveVariableName);
212
+ }
213
+ const MAX_ERROR_MESSAGE_LENGTH = 500;
214
+ function createDummyCtx() {
215
+ return {
216
+ traceId: "",
217
+ spanId: "",
218
+ correlationId: "",
219
+ setAttribute: () => {},
220
+ setAttributes: () => {},
221
+ setStatus: () => {},
222
+ recordException: () => {},
223
+ addEvent: () => {},
224
+ addLink: () => {},
225
+ addLinks: () => {},
226
+ updateName: () => {},
227
+ isRecording: () => false,
228
+ getBaggage: () => {},
229
+ setBaggage: () => "",
230
+ deleteBaggage: () => {},
231
+ getAllBaggage: () => /* @__PURE__ */ new Map()
232
+ };
233
+ }
234
+ /** Attribute keys for opt-in function I/O capture (see TracingOptions). */
235
+ const AUTOTEL_INPUT_ATTR = "autotel.input";
236
+ const AUTOTEL_OUTPUT_ATTR = "autotel.output";
237
+ const CAPTURE_MAX_CHARS = 4096;
238
+ /** JSON-serialize a captured value, defensively (truncate, swallow cycles). */
239
+ function serializeCapture(value) {
240
+ if (value === void 0) return void 0;
241
+ try {
242
+ const json = typeof value === "string" ? value : JSON.stringify(value);
243
+ if (json === void 0) return void 0;
244
+ return json.length > CAPTURE_MAX_CHARS ? `${json.slice(0, CAPTURE_MAX_CHARS)}…[truncated]` : json;
245
+ } catch {
246
+ return;
247
+ }
248
+ }
249
+ /** `autotel.input` from args (single arg captured directly, else the array). */
250
+ function captureInputAttrs(args, enabled) {
251
+ if (!enabled) return {};
252
+ const s = serializeCapture(args.length === 1 ? args[0] : args);
253
+ return s === void 0 ? {} : { [AUTOTEL_INPUT_ATTR]: s };
254
+ }
255
+ /** `autotel.output` from the return value. */
256
+ function captureOutputAttrs(result, enabled) {
257
+ if (!enabled) return {};
258
+ const s = serializeCapture(result);
259
+ return s === void 0 ? {} : { [AUTOTEL_OUTPUT_ATTR]: s };
260
+ }
261
+ const INSTRUMENTED_SYMBOL = Symbol.for("autotel.functional.instrumented");
262
+ function hasInstrumentationFlag(value) {
263
+ return (typeof value === "function" || typeof value === "object") && value !== null && Boolean(value[INSTRUMENTED_SYMBOL]);
264
+ }
265
+ /**
266
+ * Truncate error message to prevent span bloat
267
+ */
268
+ function truncateErrorMessage(message) {
269
+ if (message.length <= MAX_ERROR_MESSAGE_LENGTH) return message;
270
+ return `${message.slice(0, MAX_ERROR_MESSAGE_LENGTH)}... (truncated)`;
271
+ }
272
+ /**
273
+ * Terminal handling for a value thrown by a traced function. Shared by all four
274
+ * `trace()` execution paths (immediate + wrapper, sync + async) so the outcome
275
+ * rules live in exactly one place. Ends the span; the caller flushes (await/void)
276
+ * and rethrows.
277
+ *
278
+ * If `isError` classifies the throw as expected control flow — e.g. a framework
279
+ * `redirect()` / `notFound()` signal — it is recorded as a success outcome with
280
+ * an OK status and no exception. Otherwise it is recorded as an error.
281
+ */
282
+ function finalizeThrownSpan(error, isError, ctx) {
283
+ const { span, spanName, duration, callCounter, durationHistogram, handleTailSampling, extraAttributes } = ctx;
284
+ const baseAttributes = {
285
+ ...extraAttributes,
286
+ "operation.name": spanName,
287
+ "code.function": spanName,
288
+ "operation.duration": duration
289
+ };
290
+ if (isError && !isError(error)) {
291
+ callCounter?.add(1, {
292
+ operation: spanName,
293
+ status: "success"
294
+ });
295
+ durationHistogram?.record(duration, {
296
+ operation: spanName,
297
+ status: "success"
298
+ });
299
+ span.setStatus({ code: SpanStatusCode.OK });
300
+ span.setAttributes({
301
+ ...baseAttributes,
302
+ "operation.success": true
303
+ });
304
+ handleTailSampling(true, duration);
305
+ span.end();
306
+ return;
307
+ }
308
+ callCounter?.add(1, {
309
+ operation: spanName,
310
+ status: "error"
311
+ });
312
+ durationHistogram?.record(duration, {
313
+ operation: spanName,
314
+ status: "error"
315
+ });
316
+ const truncatedMessage = truncateErrorMessage(error instanceof Error ? error.message : "Unknown error");
317
+ span.setStatus({
318
+ code: SpanStatusCode.ERROR,
319
+ message: truncatedMessage
320
+ });
321
+ span.setAttributes({
322
+ ...baseAttributes,
323
+ "operation.success": false,
324
+ error: true,
325
+ "exception.type": error instanceof Error ? error.constructor.name : "Error",
326
+ "exception.message": truncatedMessage
327
+ });
328
+ if (error instanceof Error && error.stack) span.setAttribute("exception.stack", error.stack.slice(0, MAX_ERROR_MESSAGE_LENGTH));
329
+ const thrown = error instanceof Error ? error : new Error(String(error));
330
+ span.recordException(thrown);
331
+ handleTailSampling(false, duration, thrown);
332
+ span.end();
333
+ }
334
+ /**
335
+ * Try to infer function name from function properties
336
+ * Checks for displayName, name, or other metadata that might be set
337
+ */
338
+ function inferFunctionName(fn) {
339
+ const displayName = fn.displayName;
340
+ if (displayName) return displayName;
341
+ if (fn.name && fn.name !== "anonymous" && fn.name !== "") return fn.name;
342
+ const match = Function.prototype.toString.call(fn).match(/function\s+([^(\s]+)/);
343
+ if (match && match[1] && match[1] !== "anonymous") return match[1];
344
+ }
345
+ /**
346
+ * Determine span name using priority:
347
+ * 1. Explicit name option
348
+ * 2. serviceName + functionName
349
+ * 3. Inferred from function/variable name (including stack trace fallback)
350
+ * 4. Fallback to 'unknown'
351
+ */
352
+ function getSpanName(options, fn, variableName) {
353
+ if (options.name) return options.name;
354
+ let fnName = variableName || inferFunctionName(fn);
355
+ fnName = fnName || "anonymous";
356
+ if (options.serviceName) return `${options.serviceName}.${fnName}`;
357
+ if (fnName && fnName !== "anonymous") return fnName;
358
+ const initConfig = getConfig$1();
359
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production" && !unknownSpanNameWarningEmitted && initConfig?.logger?.warn) {
360
+ unknownSpanNameWarningEmitted = true;
361
+ initConfig.logger.warn({}, "[autotel] Span name resolved to \"unknown\". Pass an explicit name, for example trace(\"operation.name\", fn).");
362
+ }
363
+ return "unknown";
364
+ }
365
+ /**
366
+ * Check if function should be skipped
367
+ */
368
+ function shouldSkip(key, fn, skip) {
369
+ if (key.startsWith("_")) return true;
370
+ if (!skip || skip.length === 0) return false;
371
+ for (const rule of skip) if (typeof rule === "string" && key === rule) return true;
372
+ else if (rule instanceof RegExp && rule.test(key)) return true;
373
+ else if (typeof rule === "function" && rule(key, fn)) return true;
374
+ return false;
375
+ }
376
+ /**
377
+ * Get current trace context value (internal helper)
378
+ *
379
+ * Returns base context (trace IDs) + span methods from the active span.
380
+ */
381
+ function getCtxValue() {
382
+ const activeSpan = trace.getActiveSpan();
383
+ if (!activeSpan) return null;
384
+ return createTraceContext(activeSpan);
385
+ }
386
+ /**
387
+ * Get the autotel {@link TraceContext} for the currently active span.
388
+ *
389
+ * This is the ambient accessor for the functional API: instead of threading a
390
+ * `ctx` parameter through a factory, call this inside any traced function (or a
391
+ * helper it calls) to reach `setAttribute`, `setUser`, `getBaggage`, and the
392
+ * rest of the context surface. Returns `undefined` when no span is active.
393
+ *
394
+ * @example
395
+ * ```typescript
396
+ * const getUser = trace('getUser', async (id: string) => {
397
+ * getActiveTraceContext()?.setAttribute('user.id', id);
398
+ * return db.users.find(id);
399
+ * });
400
+ * ```
401
+ *
402
+ * @see getActiveSpan for the raw OpenTelemetry span
403
+ * @see getRequestLogger which reads the active context when called with no args
404
+ */
405
+ function getActiveTraceContext() {
406
+ return getCtxValue() ?? void 0;
407
+ }
408
+ /**
409
+ * Context object that lazily evaluates the active span on property access
410
+ *
411
+ * Access trace context directly without function call syntax.
412
+ *
413
+ * @example
414
+ * ```typescript
415
+ * import { trace, ctx } from 'autotel'
416
+ *
417
+ * export const createUser = trace(async (data) => {
418
+ * // Direct property access - no function call!
419
+ * if (ctx.traceId) {
420
+ * ctx.setAttribute('user.id', data.id)
421
+ * console.log('Trace:', ctx.traceId)
422
+ * }
423
+ * })
424
+ * ```
425
+ */
426
+ const ctx = new Proxy({}, {
427
+ get(_target, prop) {
428
+ const ctxValue = getCtxValue();
429
+ if (!ctxValue) return;
430
+ return ctxValue[prop];
431
+ },
432
+ has(_target, prop) {
433
+ const ctxValue = getCtxValue();
434
+ if (!ctxValue) return false;
435
+ return prop in ctxValue;
436
+ },
437
+ ownKeys() {
438
+ const ctxValue = getCtxValue();
439
+ if (!ctxValue) return [];
440
+ return Object.keys(ctxValue);
441
+ },
442
+ getOwnPropertyDescriptor(_target, prop) {
443
+ const ctxValue = getCtxValue();
444
+ if (!ctxValue) return;
445
+ return Object.getOwnPropertyDescriptor(ctxValue, prop);
446
+ }
447
+ });
448
+ /**
449
+ * Build the root-operation flush policy once and reuse it for wrapped and
450
+ * immediate execution. Async operations await this function; sync operations
451
+ * trigger it without blocking.
452
+ */
453
+ function createRootTelemetryFlusher(options, isRootSpan) {
454
+ const initConfig = getConfig$1();
455
+ const shouldFlush = options.flushOnRootSpanEnd ?? initConfig?.flushOnRootSpanEnd ?? true;
456
+ const shouldFlushSpans = initConfig?.forceFlushOnShutdown ?? false;
457
+ return async () => {
458
+ if (!shouldFlush || !isRootSpan) return;
459
+ try {
460
+ const queue = getEventQueue();
461
+ if (queue && queue.size() > 0) await queue.flush();
462
+ if (shouldFlushSpans) await getForceFlushableProvider(getSdk())?.forceFlush();
463
+ } catch (error) {
464
+ (getConfig$1()?.logger)?.error?.({ err: error instanceof Error ? error : void 0 }, `[autotel] Auto-flush failed${error instanceof Error ? "" : `: ${String(error)}`}`);
465
+ }
466
+ };
467
+ }
468
+ /**
469
+ * Give every root operation its own baggage context without replacing a
470
+ * caller's existing scope. AsyncLocalStorage keeps the scope alive until an
471
+ * async result settles and restores the previous store afterwards.
472
+ */
473
+ function runWithTraceContextStorage(fn) {
474
+ const storage = getContextStorage();
475
+ if (storage.getStore()) return fn();
476
+ return storage.run({ value: context.active() }, fn);
477
+ }
478
+ /**
479
+ * Core tracing wrapper for sync functions (internal implementation)
480
+ */
481
+ function wrapWithTracingSync(fnFactory, options, variableName) {
482
+ if (hasInstrumentationFlag(fnFactory)) {}
483
+ const config = getConfig();
484
+ const tracer = config.tracer;
485
+ const meter = config.meter;
486
+ const sampler = options.sampler || new AlwaysSampler();
487
+ const spanName = getSpanName(options, fnFactory, variableName);
488
+ const callCounter = options.withMetrics ? meter.createCounter(`${spanName}.calls`, {
489
+ description: `Call count for ${spanName}`,
490
+ unit: "1"
491
+ }) : void 0;
492
+ const durationHistogram = options.withMetrics ? meter.createHistogram(`${spanName}.duration`, {
493
+ description: `Duration for ${spanName}`,
494
+ unit: "ms"
495
+ }) : void 0;
496
+ function wrappedFunction(...args) {
497
+ const samplingContext = {
498
+ operationName: spanName,
499
+ args,
500
+ metadata: {}
501
+ };
502
+ const shouldSample = sampler.shouldSample(samplingContext);
503
+ const sampleRate = sampler.sampleRate?.(samplingContext);
504
+ const needsTailSampling = sampler.needsTailSampling?.() ?? false;
505
+ if (!shouldSample && !needsTailSampling) return fnFactory(createDummyCtx()).call(this, ...args);
506
+ const startTime = performance.now();
507
+ const flushRootTelemetry = createRootTelemetryFlusher(options, options.startNewRoot || trace.getActiveSpan() === void 0);
508
+ const spanOptions = {};
509
+ if (options.startNewRoot) spanOptions.root = true;
510
+ if (options.spanKind !== void 0) spanOptions.kind = options.spanKind;
511
+ const parentContext = getActiveContextWithBaggage();
512
+ return tracer.startActiveSpan(spanName, spanOptions, parentContext, (span) => {
513
+ return runInOperationContext(spanName, () => runWithTraceContextStorage(() => {
514
+ let shouldKeepSpan = true;
515
+ setSpanName(span, spanName);
516
+ if (sampleRate !== void 0 && sampleRate > 1) span.setAttribute(AUTOTEL_SAMPLING_RATE, sampleRate);
517
+ const fn = fnFactory(createTraceContext(span));
518
+ const argsAttributes = {
519
+ ...captureInputAttrs(args, options.captureInput),
520
+ ...options.attributesFromArgs ? options.attributesFromArgs(args) : {}
521
+ };
522
+ const handleTailSampling = (success, duration, error) => {
523
+ if (needsTailSampling && sampler.shouldKeepTrace) {
524
+ shouldKeepSpan = sampler.shouldKeepTrace(samplingContext, {
525
+ success,
526
+ duration,
527
+ error
528
+ });
529
+ span.setAttribute(AUTOTEL_SAMPLING_TAIL_KEEP, shouldKeepSpan);
530
+ span.setAttribute(AUTOTEL_SAMPLING_TAIL_EVALUATED, true);
531
+ }
532
+ };
533
+ const onSuccess = (result) => {
534
+ const duration = performance.now() - startTime;
535
+ callCounter?.add(1, {
536
+ operation: spanName,
537
+ status: "success"
538
+ });
539
+ durationHistogram?.record(duration, {
540
+ operation: spanName,
541
+ status: "success"
542
+ });
543
+ const resultAttributes = {
544
+ ...captureOutputAttrs(result, options.captureOutput),
545
+ ...options.attributesFromResult ? options.attributesFromResult(result) : {}
546
+ };
547
+ span.setStatus({ code: SpanStatusCode.OK });
548
+ span.setAttributes({
549
+ ...argsAttributes,
550
+ ...resultAttributes,
551
+ "operation.name": spanName,
552
+ "code.function": spanName,
553
+ "operation.duration": duration,
554
+ "operation.success": true
555
+ });
556
+ handleTailSampling(true, duration);
557
+ span.end();
558
+ return result;
559
+ };
560
+ const onError = (error) => {
561
+ finalizeThrownSpan(error, options.isError, {
562
+ span,
563
+ spanName,
564
+ duration: performance.now() - startTime,
565
+ callCounter,
566
+ durationHistogram,
567
+ handleTailSampling,
568
+ extraAttributes: argsAttributes
569
+ });
570
+ throw error;
571
+ };
572
+ try {
573
+ callCounter?.add(1, {
574
+ operation: spanName,
575
+ status: "started"
576
+ });
577
+ const result = context.with(getActiveContextWithBaggage(), () => fn.call(this, ...args));
578
+ if (result instanceof Promise) return result.then(async (value) => {
579
+ const completed = onSuccess(value);
580
+ await flushRootTelemetry();
581
+ return completed;
582
+ }, async (error) => {
583
+ try {
584
+ return onError(error);
585
+ } finally {
586
+ await flushRootTelemetry();
587
+ }
588
+ });
589
+ const completed = onSuccess(result);
590
+ flushRootTelemetry();
591
+ return completed;
592
+ } catch (error) {
593
+ try {
594
+ return onError(error);
595
+ } finally {
596
+ flushRootTelemetry();
597
+ }
598
+ }
599
+ }));
600
+ });
601
+ }
602
+ wrappedFunction[INSTRUMENTED_SYMBOL] = true;
603
+ Object.defineProperty(wrappedFunction, "name", {
604
+ value: variableName || "trace",
605
+ configurable: true
606
+ });
607
+ return wrappedFunction;
608
+ }
609
+ function trace$1(fnOrNameOrOptions, maybeFn) {
610
+ if (typeof fnOrNameOrOptions === "function") return wrapPlainWithTracing(fnOrNameOrOptions, {});
611
+ if (!maybeFn) throw new Error("trace(name|options, fn): fn is required");
612
+ return wrapPlainWithTracing(maybeFn, typeof fnOrNameOrOptions === "string" ? { name: fnOrNameOrOptions } : fnOrNameOrOptions);
613
+ }
614
+ /**
615
+ * Approach 2: withTracing() - Middleware-style composable wrapper
616
+ *
617
+ * Returns a HOF that wraps functions with tracing.
618
+ * Perfect for composition and reusable configuration.
619
+ *
620
+ * @example Standard usage
621
+ * ```typescript
622
+ * export const createUser = withTracing({
623
+ * name: 'user.create'
624
+ * })(ctx => async (data) => {
625
+ * ctx.setAttribute('user.id', data.id)
626
+ * return await db.users.create(data)
627
+ * })
628
+ * ```
629
+ *
630
+ * @example Composable
631
+ * ```typescript
632
+ * const tracer = withTracing({ serviceName: 'user' })
633
+ *
634
+ * export const createUser = tracer(ctx => async (data) => { })
635
+ * export const updateUser = tracer(ctx => async (id, data) => { })
636
+ * ```
637
+ *
638
+ * @example With other middleware
639
+ * ```typescript
640
+ * export const createUser = compose(
641
+ * withAuth({ role: 'admin' }),
642
+ * withTracing({ name: 'user.create' }),
643
+ * withRateLimit({ max: 100 })
644
+ * )(ctx => async (data) => { })
645
+ * ```
646
+ */
647
+ function withTracing(options = {}) {
648
+ return (fnFactory) => wrapFactoryWithTracing(fnFactory, options);
649
+ }
650
+ function instrument(options) {
651
+ if (!options || typeof options !== "object") throw new TypeError("instrument: expected { key, fn } or { functions: { name: fn } }");
652
+ if ("key" in options || "fn" in options) {
653
+ const { key, fn, ...tracingOptions } = options;
654
+ if (typeof key !== "string" || key.trim() === "") throw new TypeError("instrument: \"key\" must be a non-empty string in the { key, fn } form");
655
+ if (typeof fn !== "function") throw new TypeError("instrument: \"fn\" must be a function in the { key, fn } form");
656
+ return wrapPlainWithTracing(fn, tracingOptions, key);
657
+ }
658
+ const { functions, ...tracingOptions } = options;
659
+ if (!functions || typeof functions !== "object") throw new TypeError("instrument: expected { key, fn } or { functions: { name: fn } }");
660
+ const instrumented = {};
661
+ for (const key of Object.keys(functions)) {
662
+ const typedKey = key;
663
+ const fn = functions[typedKey];
664
+ if (!fn || typeof fn !== "function") {
665
+ instrumented[typedKey] = fn;
666
+ continue;
667
+ }
668
+ if (shouldSkip(key, fn, tracingOptions.skip)) {
669
+ instrumented[typedKey] = fn;
670
+ continue;
671
+ }
672
+ const fnOptions = {
673
+ ...tracingOptions,
674
+ ...tracingOptions.overrides?.[key],
675
+ name: tracingOptions.overrides?.[key]?.name
676
+ };
677
+ const boundFn = fn.bind(functions);
678
+ const fnFactory = (ctx) => {
679
+ return boundFn;
680
+ };
681
+ instrumented[typedKey] = wrapFactoryWithTracing(fnFactory, fnOptions, key);
682
+ }
683
+ return instrumented;
684
+ }
685
+ function span(nameOrOptions, fn) {
686
+ const options = typeof nameOrOptions === "string" ? { name: nameOrOptions } : nameOrOptions;
687
+ const tracer = getConfig().tracer;
688
+ const { name, attributes, spanKind } = options;
689
+ const executeSpan = (span) => {
690
+ return runInOperationContext(name, () => {
691
+ try {
692
+ if (attributes) for (const [key, value] of Object.entries(attributes)) span.setAttribute(key, value);
693
+ const result = fn(span);
694
+ if (result instanceof Promise) return result.then((resolved) => {
695
+ span.setStatus({ code: SpanStatusCode.OK });
696
+ span.end();
697
+ return resolved;
698
+ }).catch((error) => {
699
+ const errorMessage = error instanceof Error ? error.message.slice(0, MAX_ERROR_MESSAGE_LENGTH) : String(error).slice(0, MAX_ERROR_MESSAGE_LENGTH);
700
+ span.setAttribute("error.message", errorMessage);
701
+ span.setStatus({
702
+ code: SpanStatusCode.ERROR,
703
+ message: errorMessage
704
+ });
705
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
706
+ span.end();
707
+ throw error;
708
+ });
709
+ else {
710
+ span.setStatus({ code: SpanStatusCode.OK });
711
+ span.end();
712
+ return result;
713
+ }
714
+ } catch (error) {
715
+ const errorMessage = error instanceof Error ? error.message.slice(0, MAX_ERROR_MESSAGE_LENGTH) : String(error).slice(0, MAX_ERROR_MESSAGE_LENGTH);
716
+ span.setAttribute("error.message", errorMessage);
717
+ span.setStatus({
718
+ code: SpanStatusCode.ERROR,
719
+ message: errorMessage
720
+ });
721
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
722
+ span.end();
723
+ throw error;
724
+ }
725
+ });
726
+ };
727
+ const parentContext = getActiveContextWithBaggage();
728
+ const result = tracer.startActiveSpan(name, spanKind === void 0 ? {} : { kind: spanKind }, parentContext, executeSpan);
729
+ if (result instanceof Promise) return result;
730
+ return result;
731
+ }
732
+ /**
733
+ * Execute a function in a new root context (prevents span propagation)
734
+ *
735
+ * Useful when you want to start a completely new trace without
736
+ * parent-child relationships.
737
+ *
738
+ * @example
739
+ * ```typescript
740
+ * async function handleWebhook(payload: WebhookPayload) {
741
+ * // This creates a new root trace, not connected to the HTTP request trace
742
+ * await withNewContext({
743
+ * fn: async () => {
744
+ * await span('webhook.process', async () => {
745
+ * await processWebhookPayload(payload)
746
+ * })
747
+ * }
748
+ * })
749
+ * }
750
+ * ```
751
+ */
752
+ async function withNewContext(options) {
753
+ const { fn } = options;
754
+ return getConfig().tracer.startActiveSpan("root", { root: true }, async (span) => {
755
+ try {
756
+ const result = await fn();
757
+ span.setStatus({ code: SpanStatusCode.OK });
758
+ return result;
759
+ } catch (error) {
760
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
761
+ span.setStatus({ code: SpanStatusCode.ERROR });
762
+ throw error;
763
+ } finally {
764
+ span.end();
765
+ }
766
+ });
767
+ }
768
+ /**
769
+ * Execute a function with updated baggage entries
770
+ *
771
+ * Baggage is immutable in OpenTelemetry, so this helper creates a new context
772
+ * with the specified baggage entries and runs the function within that context.
773
+ * All child spans created within the function will inherit the baggage.
774
+ *
775
+ * @example Setting baggage for downstream services
776
+ * ```typescript
777
+ * import { withTracing, withBaggage } from 'autotel';
778
+ *
779
+ * export const createOrder = withTracing({ name: 'order.create' })((ctx) => async (order: Order) => {
780
+ * // Set baggage that will be propagated to downstream HTTP calls
781
+ * return await withBaggage({
782
+ * baggage: {
783
+ * 'tenant.id': order.tenantId,
784
+ * 'user.id': order.userId,
785
+ * },
786
+ * fn: async () => {
787
+ * // This HTTP call will include the baggage in headers
788
+ * await fetch('/api/charge', {
789
+ * method: 'POST',
790
+ * body: JSON.stringify(order),
791
+ * });
792
+ * },
793
+ * });
794
+ * });
795
+ * ```
796
+ *
797
+ * @example Using with existing baggage
798
+ * ```typescript
799
+ * export const processOrder = withTracing({ name: 'order.process' })((ctx) => async (order: Order) => {
800
+ * // Read existing baggage
801
+ * const tenantId = ctx.getBaggage('tenant.id');
802
+ *
803
+ * // Add additional baggage entries
804
+ * return await withBaggage({
805
+ * baggage: {
806
+ * 'order.id': order.id,
807
+ * 'order.amount': String(order.amount),
808
+ * },
809
+ * fn: async () => {
810
+ * await charge(order);
811
+ * },
812
+ * });
813
+ * });
814
+ * ```
815
+ */
816
+ function withBaggage(options) {
817
+ const { baggage: baggageEntries, fn } = options;
818
+ const currentContext = context.active();
819
+ let updatedBaggage = propagation.getBaggage(currentContext) ?? propagation.createBaggage();
820
+ for (const [key, value] of Object.entries(baggageEntries)) updatedBaggage = updatedBaggage.setEntry(key, { value });
821
+ const newContext = propagation.setBaggage(currentContext, updatedBaggage);
822
+ const ctxStorage = getContextStorage();
823
+ const previousStored = ctxStorage.getStore();
824
+ const baggageEnrichedStored = previousStored ? { value: propagation.setBaggage(previousStored.value, updatedBaggage) } : { value: newContext };
825
+ const result = previousStored ? ctxStorage.run(baggageEnrichedStored, () => context.with(newContext, fn)) : context.with(newContext, fn);
826
+ if (result instanceof Promise) return result.then((value) => {
827
+ if (previousStored) return ctxStorage.run(previousStored, () => value);
828
+ return value;
829
+ }, (error) => {
830
+ if (previousStored) return ctxStorage.run(previousStored, () => {
831
+ throw error;
832
+ });
833
+ throw error;
834
+ });
835
+ return result;
836
+ }
837
+
838
+ //#endregion
839
+ export { trace$1 as a, withTracing as c, span as i, getActiveTraceContext as n, withBaggage as o, instrument as r, withNewContext as s, ctx as t };
840
+ //# sourceMappingURL=functional-Bit6noRu.js.map