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