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