autotel 3.6.0 → 4.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/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-CmYpdqCN.js +591 -0
- package/dist/attributes-CmYpdqCN.js.map +1 -0
- package/dist/attributes-PZ5doLgw.cjs +704 -0
- package/dist/attributes-PZ5doLgw.cjs.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-Ck06vlW2.d.ts +678 -0
- package/dist/index-Ck06vlW2.d.ts.map +1 -0
- package/dist/index-eKuioqT1.d.cts +678 -0
- package/dist/index-eKuioqT1.d.cts.map +1 -0
- package/dist/index.cjs +751 -1218
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +341 -659
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +341 -659
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +606 -737
- 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-DVSmWg6Y.js +175 -0
- package/dist/registry-DVSmWg6Y.js.map +1 -0
- package/dist/registry-DYgvb62e.cjs +319 -0
- package/dist/registry-DYgvb62e.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 +327 -39
- package/dist/semantic-helpers.cjs.map +1 -1
- package/dist/semantic-helpers.d.cts +30 -150
- package/dist/semantic-helpers.d.cts.map +1 -0
- package/dist/semantic-helpers.d.ts +30 -150
- package/dist/semantic-helpers.d.ts.map +1 -0
- package/dist/semantic-helpers.js +326 -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/skills/analyze-traces/SKILL.md +14 -12
- package/skills/review-otel-patterns/SKILL.md +4 -2
- package/skills/tune-sampling/SKILL.md +8 -3
- package/src/attributes/builders.ts +2 -20
- package/src/attributes/index.ts +0 -1
- package/src/attributes/registry.ts +2 -9
- package/src/attributes/types.ts +0 -8
- package/src/index.ts +7 -41
- package/src/request-logger.test.ts +53 -1
- package/src/request-logger.ts +58 -0
- package/src/semantic-helpers.test.ts +2 -87
- package/src/semantic-helpers.ts +0 -146
- 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
- package/src/gen-ai-cost.test.ts +0 -81
- package/src/gen-ai-cost.ts +0 -145
- package/src/gen-ai-events.test.ts +0 -135
- package/src/gen-ai-events.ts +0 -208
- package/src/gen-ai-metrics.test.ts +0 -96
- package/src/gen-ai-metrics.ts +0 -128
package/dist/index.js
CHANGED
|
@@ -1,777 +1,646 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
import {
|
|
29
|
-
export { BaggageSpanProcessor, createStringRedactor, init, isInitialized, isLoggerLocked, lockLogger } from './chunk-ALPYR2GC.js';
|
|
30
|
-
import './chunk-CMHVQR6P.js';
|
|
31
|
-
import './chunk-A4E5AQFK.js';
|
|
32
|
-
export { FilteringSpanProcessor } from './chunk-WGWSHJ2N.js';
|
|
33
|
-
export { NORMALIZER_PATTERNS, NORMALIZER_PRESETS, SpanNameNormalizingProcessor } from './chunk-GYR5K654.js';
|
|
34
|
-
export { AttributeRedactingProcessor, REDACTOR_PATTERNS, REDACTOR_PRESETS, builtinPatterns, createAttributeRedactor, createRedactedSpan, normalizeAttributeRedactorConfig } from './chunk-RUPKBKUF.js';
|
|
35
|
-
import './chunk-6UQRVUN3.js';
|
|
36
|
-
export { formatDuration } from './chunk-3QXBFGKP.js';
|
|
37
|
-
import './chunk-Q4EULJQY.js';
|
|
38
|
-
export { AUTOTEL_SAMPLING_TAIL_EVALUATED, AUTOTEL_SAMPLING_TAIL_KEEP, AdaptiveSampler, AlwaysSampler, NeverSampler, RandomSampler, UserIdSampler, createLinkFromHeaders, extractLinksFromBatch, resolveSamplingPreset, samplingPresets } from './chunk-DPSA4QLA.js';
|
|
39
|
-
import './chunk-55ER2KD5.js';
|
|
40
|
-
import './chunk-J5QENANM.js';
|
|
41
|
-
export { getAutotelTracer, getAutotelTracerProvider, setAutotelTracerProvider } from './chunk-HA2WBOGQ.js';
|
|
42
|
-
import { trace } from '@opentelemetry/api';
|
|
43
|
-
export { ROOT_CONTEXT, SpanKind, SpanStatusCode, context, trace as otelTrace, propagation } from '@opentelemetry/api';
|
|
44
|
-
import { AsyncLocalStorage } from 'async_hooks';
|
|
45
|
-
import { AggregationType } from '@opentelemetry/sdk-metrics';
|
|
1
|
+
import { AUTOTEL_SAMPLING_TAIL_EVALUATED, AUTOTEL_SAMPLING_TAIL_KEEP, AdaptiveSampler, AlwaysSampler, NeverSampler, RandomSampler, UserIdSampler, createLinkFromHeaders, extractLinksFromBatch, resolveSamplingPreset, samplingPresets } from "./sampling.js";
|
|
2
|
+
import { a as getSdk, c as isInitialized, f as createStringRedactor, i as getLogger, l as isLoggerLocked, p as BaggageSpanProcessor, s as init, t as _closeEmbeddedDevtools, u as lockLogger } from "./init-Ch6t7MNI.js";
|
|
3
|
+
import { FilteringSpanProcessor } from "./filtering-span-processor.js";
|
|
4
|
+
import { NORMALIZER_PATTERNS, NORMALIZER_PRESETS, SpanNameNormalizingProcessor } from "./span-name-normalizer.js";
|
|
5
|
+
import { AttributeRedactingProcessor, REDACTOR_PATTERNS, REDACTOR_PRESETS, builtinPatterns, createAttributeRedactor, createRedactedSpan, normalizeAttributeRedactorConfig } from "./attribute-redacting-processor.js";
|
|
6
|
+
import { n as formatDuration } from "./canonical-log-line-processor-DbBQT5vY.js";
|
|
7
|
+
import { getAutotelTracer, getAutotelTracerProvider, setAutotelTracerProvider } from "./tracer-provider.js";
|
|
8
|
+
import { a as CORRELATION_ID_BAGGAGE_KEY, d as setCorrelationId, f as setCorrelationIdInBaggage, l as getOrCreateCorrelationId, m as defineBaggageSchema, n as resetEventQueue, o as generateCorrelationId, p as createTraceContext, r as track, s as getCorrelationId, t as getEventQueue, u as runWithCorrelationId } from "./track-nsKVy-pj.js";
|
|
9
|
+
import { a as flattenToAttributes, i as structuredErrorToJSON, n as getStructuredErrorAttributes, o as toAttributeValue, r as recordStructuredError, t as createStructuredError } from "./structured-error-9--cxBay.js";
|
|
10
|
+
import { createDeterministicTraceId, enrichWithTraceContext, finalizeSpan, flattenMetadata, getActiveContext, getActiveSpan, getTraceContext, getTracer, isTracing, resolveTraceUrl, runWithSpan } from "./trace-helpers.js";
|
|
11
|
+
import { n as runInOperationContext, t as getOperationContext } from "./operation-context-C-2hmmtP.js";
|
|
12
|
+
import { a as trace$2, c as withTracing, i as span, n as instrument, o as withBaggage, r as markAsImmediate, s as withNewContext, t as ctx } from "./functional-BGkT8J-h.js";
|
|
13
|
+
import { t as hashJson } from "./stable-hash-Cg5cT34Q.js";
|
|
14
|
+
import { n as getEvents, r as resetEvents, t as Event } from "./event-_58ryBjh.js";
|
|
15
|
+
import { Metric, getMetrics, resetMetrics } from "./metric.js";
|
|
16
|
+
import { t as emitCorrelatedEvent } from "./correlated-events-Bzh5y-UB.js";
|
|
17
|
+
import { parseError } from "./parse-error.js";
|
|
18
|
+
import { createDrainPipeline } from "./drain-pipeline.js";
|
|
19
|
+
import { createCounter, createHistogram, createObservableGauge, createUpDownCounter, getMeter } from "./metric-helpers.js";
|
|
20
|
+
import { traceDB, traceHTTP, traceMessaging } from "./semantic-helpers.js";
|
|
21
|
+
import { C as URLAttributes, d as HTTPAttributes, y as ServiceAttributes } from "./registry-DVSmWg6Y.js";
|
|
22
|
+
import { httpRequestHeaderAttribute, httpResponseHeaderAttribute } from "./semantic-conventions.js";
|
|
23
|
+
import { a as identify, c as setDevice, d as setSession, f as setUser, h as autoRedactPII, i as httpServer, l as setError, m as safeSetAttributes, n as dbClient, o as mergeServiceResource, p as mergeAttrs, r as httpClient, s as request, u as setException, v as validateAttribute, y as attrs } from "./attributes-CmYpdqCN.js";
|
|
24
|
+
import { traceConsumer, traceProducer } from "./messaging.js";
|
|
25
|
+
import { BusinessBaggage, createSafeBaggageSchema } from "./business-baggage.js";
|
|
26
|
+
import { getCurrentWorkflowContext, isInWorkflow, traceStep, traceWorkflow } from "./workflow.js";
|
|
27
|
+
import { ROOT_CONTEXT, SpanKind, SpanStatusCode, context, propagation, trace as otelTrace, trace as trace$1 } from "@opentelemetry/api";
|
|
28
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
46
29
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
30
|
+
//#region src/trace-hybrid.ts
|
|
31
|
+
/**
|
|
32
|
+
* Hybrid `trace` export: callable like autotel's `trace(fn)`, AND exposes the
|
|
33
|
+
* full `@opentelemetry/api` `TraceAPI` surface (`trace.getActiveSpan()`,
|
|
34
|
+
* `trace.getTracer()`, …) so existing OTel code "just works" when imported
|
|
35
|
+
* from `autotel`.
|
|
36
|
+
*
|
|
37
|
+
* Implementation: `Object.assign` mutates the autotel `trace` function to
|
|
38
|
+
* attach the OTel TraceAPI methods. Because every reference to `trace` across
|
|
39
|
+
* autotel resolves to the same function instance, this is a one-time, global
|
|
40
|
+
* augmentation.
|
|
41
|
+
*/
|
|
42
|
+
const otelMethods = {
|
|
43
|
+
setGlobalTracerProvider: trace$1.setGlobalTracerProvider.bind(trace$1),
|
|
44
|
+
getTracerProvider: trace$1.getTracerProvider.bind(trace$1),
|
|
45
|
+
getTracer: trace$1.getTracer.bind(trace$1),
|
|
46
|
+
disable: trace$1.disable.bind(trace$1),
|
|
47
|
+
wrapSpanContext: trace$1.wrapSpanContext,
|
|
48
|
+
isSpanContextValid: trace$1.isSpanContextValid,
|
|
49
|
+
deleteSpan: trace$1.deleteSpan,
|
|
50
|
+
getSpan: trace$1.getSpan,
|
|
51
|
+
getActiveSpan: trace$1.getActiveSpan,
|
|
52
|
+
getSpanContext: trace$1.getSpanContext,
|
|
53
|
+
setSpan: trace$1.setSpan,
|
|
54
|
+
setSpanContext: trace$1.setSpanContext
|
|
62
55
|
};
|
|
63
|
-
|
|
64
|
-
trace$1,
|
|
65
|
-
otelMethods
|
|
66
|
-
);
|
|
56
|
+
const trace = Object.assign(trace$2, otelMethods);
|
|
67
57
|
|
|
68
|
-
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/define-event.ts
|
|
69
60
|
function defineEvent(name, schema, options = {}) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
track(
|
|
87
|
-
name,
|
|
88
|
-
parsed.data,
|
|
89
|
-
schemaMetadata ? { schema: schemaMetadata } : void 0
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
61
|
+
const jsonSchema = options.toJsonSchema?.(schema);
|
|
62
|
+
const schemaMetadata = jsonSchema ? {
|
|
63
|
+
source: "zod",
|
|
64
|
+
jsonSchema,
|
|
65
|
+
hash: hashJson(jsonSchema)
|
|
66
|
+
} : void 0;
|
|
67
|
+
return {
|
|
68
|
+
name,
|
|
69
|
+
schemaMetadata,
|
|
70
|
+
track(payload) {
|
|
71
|
+
const parsed = schema.safeParse(payload);
|
|
72
|
+
if (!parsed.success) throw new Error(`Invalid payload for event "${name}". Schema validation failed.`);
|
|
73
|
+
track(name, parsed.data, schemaMetadata ? { schema: schemaMetadata } : void 0);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
93
76
|
}
|
|
94
77
|
|
|
95
|
-
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/shutdown.ts
|
|
80
|
+
/**
|
|
81
|
+
* Graceful shutdown with flush and cleanup
|
|
82
|
+
*/
|
|
83
|
+
/**
|
|
84
|
+
* Flush all pending telemetry
|
|
85
|
+
*
|
|
86
|
+
* Flushes both events events and OpenTelemetry spans to their destinations.
|
|
87
|
+
* Includes timeout protection to prevent hanging in serverless environments.
|
|
88
|
+
*
|
|
89
|
+
* Safe to call multiple times.
|
|
90
|
+
*
|
|
91
|
+
* @param options - Optional configuration
|
|
92
|
+
* @param options.timeout - Timeout in milliseconds (default: 2000ms)
|
|
93
|
+
* @param options.forShutdown - If true, permanently disables the events queue after flush (used internally by shutdown())
|
|
94
|
+
*
|
|
95
|
+
* @example Manual flush in serverless
|
|
96
|
+
* ```typescript
|
|
97
|
+
* import { flush } from 'autotel';
|
|
98
|
+
*
|
|
99
|
+
* export const handler = async (event) => {
|
|
100
|
+
* // ... process event
|
|
101
|
+
* await flush(); // Flush before function returns
|
|
102
|
+
* return result;
|
|
103
|
+
* };
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @example With custom timeout
|
|
107
|
+
* ```typescript
|
|
108
|
+
* await flush({ timeout: 5000 }); // 5 second timeout
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
96
111
|
async function flush(options) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
throw error;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
112
|
+
const timeout = options?.timeout ?? 2e3;
|
|
113
|
+
const forShutdown = options?.forShutdown ?? false;
|
|
114
|
+
const doFlush = async () => {
|
|
115
|
+
const eventsQueue = getEventQueue();
|
|
116
|
+
if (eventsQueue) if (forShutdown) await eventsQueue.shutdown();
|
|
117
|
+
else await eventsQueue.flush();
|
|
118
|
+
const sdk = getSdk();
|
|
119
|
+
if (sdk) try {
|
|
120
|
+
const sdkAny = sdk;
|
|
121
|
+
if (typeof sdkAny.getTracerProvider === "function") {
|
|
122
|
+
const tracerProvider = sdkAny.getTracerProvider();
|
|
123
|
+
if (tracerProvider && typeof tracerProvider.forceFlush === "function") await tracerProvider.forceFlush();
|
|
124
|
+
}
|
|
125
|
+
} catch {}
|
|
126
|
+
};
|
|
127
|
+
let timeoutHandle;
|
|
128
|
+
try {
|
|
129
|
+
await Promise.race([doFlush().finally(() => {
|
|
130
|
+
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
131
|
+
}), new Promise((_, reject) => {
|
|
132
|
+
timeoutHandle = setTimeout(() => reject(/* @__PURE__ */ new Error("Flush timeout")), timeout);
|
|
133
|
+
timeoutHandle.unref();
|
|
134
|
+
})]);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
137
|
+
getLogger().error({ err: error instanceof Error ? error : new Error(String(error)) }, "[autotel] Flush error");
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Shutdown telemetry and cleanup resources
|
|
143
|
+
*
|
|
144
|
+
* - Flushes all pending data
|
|
145
|
+
* - Shuts down OpenTelemetry SDK
|
|
146
|
+
* - Cleans up resources
|
|
147
|
+
*
|
|
148
|
+
* Call this before process exit.
|
|
149
|
+
*
|
|
150
|
+
* Always performs cleanup even if flush fails, preventing resource leaks
|
|
151
|
+
* in serverless handlers or tests.
|
|
152
|
+
*
|
|
153
|
+
* @example Express server
|
|
154
|
+
* ```typescript
|
|
155
|
+
* const server = app.listen(3000)
|
|
156
|
+
*
|
|
157
|
+
* process.on('SIGTERM', async () => {
|
|
158
|
+
* await server.close()
|
|
159
|
+
* await shutdown()
|
|
160
|
+
* process.exit(0)
|
|
161
|
+
* })
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
152
164
|
async function shutdown() {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
if (shutdownError) {
|
|
192
|
-
throw shutdownError;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
165
|
+
const logger = getLogger();
|
|
166
|
+
let shutdownError = null;
|
|
167
|
+
try {
|
|
168
|
+
await flush({ forShutdown: true });
|
|
169
|
+
} catch (error) {
|
|
170
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
171
|
+
shutdownError = err;
|
|
172
|
+
logger.error({ err }, "[autotel] Flush failed during shutdown, continuing cleanup");
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
const sdk = getSdk();
|
|
176
|
+
if (sdk) await sdk.shutdown();
|
|
177
|
+
} catch (error) {
|
|
178
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
179
|
+
if (!(typeof error === "object" && error !== null && "code" in error && error.code === "ECONNREFUSED")) {
|
|
180
|
+
if (!shutdownError) shutdownError = err;
|
|
181
|
+
logger.error({ err }, "[autotel] SDK shutdown failed");
|
|
182
|
+
}
|
|
183
|
+
} finally {
|
|
184
|
+
await _closeEmbeddedDevtools();
|
|
185
|
+
const eventsQueue = getEventQueue();
|
|
186
|
+
if (eventsQueue && typeof eventsQueue.cleanup === "function") eventsQueue.cleanup();
|
|
187
|
+
resetEvents();
|
|
188
|
+
resetMetrics();
|
|
189
|
+
resetEventQueue();
|
|
190
|
+
}
|
|
191
|
+
if (shutdownError) throw shutdownError;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Register automatic shutdown hooks for common signals
|
|
195
|
+
*
|
|
196
|
+
* Handles:
|
|
197
|
+
* - SIGTERM (Docker/K8s graceful shutdown)
|
|
198
|
+
* - SIGINT (Ctrl+C)
|
|
199
|
+
*
|
|
200
|
+
* @internal Called automatically on module load
|
|
201
|
+
*/
|
|
195
202
|
function registerShutdownHooks() {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
} catch (error) {
|
|
212
|
-
getLogger().error(
|
|
213
|
-
{
|
|
214
|
-
err: error instanceof Error ? error : void 0
|
|
215
|
-
},
|
|
216
|
-
"[autotel] Error during shutdown"
|
|
217
|
-
);
|
|
218
|
-
} finally {
|
|
219
|
-
process.exit(0);
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
}
|
|
203
|
+
if (typeof process === "undefined") return;
|
|
204
|
+
const signals = ["SIGTERM", "SIGINT"];
|
|
205
|
+
let shuttingDown = false;
|
|
206
|
+
for (const signal of signals) process.on(signal, async () => {
|
|
207
|
+
if (shuttingDown) return;
|
|
208
|
+
shuttingDown = true;
|
|
209
|
+
if (process.env.NODE_ENV !== "test") getLogger().info({}, `[autotel] Received ${signal}, flushing telemetry...`);
|
|
210
|
+
try {
|
|
211
|
+
await shutdown();
|
|
212
|
+
} catch (error) {
|
|
213
|
+
getLogger().error({ err: error instanceof Error ? error : void 0 }, "[autotel] Error during shutdown");
|
|
214
|
+
} finally {
|
|
215
|
+
process.exit(0);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
223
218
|
}
|
|
224
219
|
registerShutdownHooks();
|
|
225
|
-
|
|
220
|
+
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/request-logger.ts
|
|
223
|
+
const POST_EMIT_FORK_HINT = "For intentional background work tied to this request, use log.fork('label', fn) when available.";
|
|
226
224
|
function warnPostEmit(method, detail) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
225
|
+
console.warn(`[autotel] ${method} called after the wide event was emitted — ${detail} This data will not appear in observability. ${POST_EMIT_FORK_HINT}`);
|
|
226
|
+
}
|
|
227
|
+
function mergeInto$1(target, source) {
|
|
228
|
+
for (const key in source) {
|
|
229
|
+
const sourceVal = source[key];
|
|
230
|
+
if (sourceVal === void 0) continue;
|
|
231
|
+
const targetVal = target[key];
|
|
232
|
+
if (sourceVal !== null && typeof sourceVal === "object" && !Array.isArray(sourceVal) && targetVal !== null && typeof targetVal === "object" && !Array.isArray(targetVal)) mergeInto$1(targetVal, sourceVal);
|
|
233
|
+
else if (Array.isArray(targetVal) && Array.isArray(sourceVal)) target[key] = [...targetVal, ...sourceVal];
|
|
234
|
+
else target[key] = sourceVal;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const requestContextStore = new AsyncLocalStorage();
|
|
238
|
+
function runWithRequestContext(ctx, fn) {
|
|
239
|
+
return requestContextStore.run(ctx, fn);
|
|
240
|
+
}
|
|
241
|
+
function resolveContext(ctx) {
|
|
242
|
+
if (ctx) return ctx;
|
|
243
|
+
const stored = requestContextStore.getStore();
|
|
244
|
+
if (stored) return stored;
|
|
245
|
+
const span = trace$1.getActiveSpan();
|
|
246
|
+
if (!span) throw new Error("[autotel] getRequestLogger() requires an active span or runWithRequestContext(). Wrap your handler with trace() or use runWithRequestContext().");
|
|
247
|
+
return createTraceContext(span);
|
|
248
|
+
}
|
|
249
|
+
function getRequestLogger(ctx, options) {
|
|
250
|
+
const activeContext = resolveContext(ctx);
|
|
251
|
+
let contextState = {};
|
|
252
|
+
let emitted = false;
|
|
253
|
+
let lastSnapshot = null;
|
|
254
|
+
const addLogEvent = (level, message, fields) => {
|
|
255
|
+
const attrs = fields ? flattenToAttributes(fields) : void 0;
|
|
256
|
+
emitCorrelatedEvent(activeContext, `log.${level}`, {
|
|
257
|
+
message,
|
|
258
|
+
...attrs ?? {}
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
const sealCheck = (method, keys) => {
|
|
262
|
+
if (emitted) warnPostEmit(method, `Keys dropped: ${keys.length ? keys.join(", ") : "(empty)"}.`);
|
|
263
|
+
};
|
|
264
|
+
return {
|
|
265
|
+
set(fields) {
|
|
266
|
+
sealCheck("log.set()", Object.keys(fields));
|
|
267
|
+
if (emitted) return;
|
|
268
|
+
mergeInto$1(contextState, fields);
|
|
269
|
+
activeContext.setAttributes(flattenToAttributes(fields));
|
|
270
|
+
},
|
|
271
|
+
info(message, fields) {
|
|
272
|
+
sealCheck("log.info()", fields ? ["message", ...Object.keys(fields).filter((k) => k !== "requestLogs")] : ["message"]);
|
|
273
|
+
if (emitted) return;
|
|
274
|
+
addLogEvent("info", message, fields);
|
|
275
|
+
if (fields) {
|
|
276
|
+
mergeInto$1(contextState, fields);
|
|
277
|
+
activeContext.setAttributes(flattenToAttributes(fields));
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
warn(message, fields) {
|
|
281
|
+
sealCheck("log.warn()", fields ? ["message", ...Object.keys(fields).filter((k) => k !== "requestLogs")] : ["message"]);
|
|
282
|
+
if (emitted) return;
|
|
283
|
+
addLogEvent("warn", message, fields);
|
|
284
|
+
activeContext.setAttribute("autotel.log.level", "warn");
|
|
285
|
+
if (fields) {
|
|
286
|
+
mergeInto$1(contextState, fields);
|
|
287
|
+
activeContext.setAttributes(flattenToAttributes(fields));
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
error(error, fields) {
|
|
291
|
+
sealCheck("log.error()", fields ? [...Object.keys(fields), "error"] : ["error"]);
|
|
292
|
+
if (emitted) return;
|
|
293
|
+
const err = typeof error === "string" ? new Error(error) : error;
|
|
294
|
+
recordStructuredError(activeContext, err);
|
|
295
|
+
addLogEvent("error", err.message, fields);
|
|
296
|
+
if (fields) {
|
|
297
|
+
mergeInto$1(contextState, fields);
|
|
298
|
+
activeContext.setAttributes(flattenToAttributes(fields));
|
|
299
|
+
}
|
|
300
|
+
activeContext.setAttribute("autotel.log.level", "error");
|
|
301
|
+
},
|
|
302
|
+
getContext() {
|
|
303
|
+
return { ...contextState };
|
|
304
|
+
},
|
|
305
|
+
emitNow(overrides) {
|
|
306
|
+
if (emitted) {
|
|
307
|
+
warnPostEmit("log.emitNow()", "Ignoring duplicate emit.");
|
|
308
|
+
return lastSnapshot;
|
|
309
|
+
}
|
|
310
|
+
const mergedContext = {
|
|
311
|
+
...contextState,
|
|
312
|
+
...overrides ?? {}
|
|
313
|
+
};
|
|
314
|
+
const flattened = flattenToAttributes(mergedContext);
|
|
315
|
+
activeContext.setAttributes(flattened);
|
|
316
|
+
const snapshot = {
|
|
317
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
318
|
+
traceId: activeContext.traceId,
|
|
319
|
+
spanId: activeContext.spanId,
|
|
320
|
+
correlationId: activeContext.correlationId,
|
|
321
|
+
context: mergedContext
|
|
322
|
+
};
|
|
323
|
+
emitCorrelatedEvent(activeContext, "log.emit.manual", { ...flattened });
|
|
324
|
+
if (options?.onEmit) Promise.resolve(options.onEmit(snapshot)).catch((error) => {
|
|
325
|
+
console.warn("[autotel] request logger onEmit failed:", error);
|
|
326
|
+
});
|
|
327
|
+
emitted = true;
|
|
328
|
+
lastSnapshot = snapshot;
|
|
329
|
+
return snapshot;
|
|
330
|
+
},
|
|
331
|
+
fork(label, fn, forkOptions) {
|
|
332
|
+
const parentRequestId = activeContext.correlationId;
|
|
333
|
+
if (typeof parentRequestId !== "string" || parentRequestId.length === 0) throw new Error("[autotel] log.fork() requires the parent logger to have a correlationId. Ensure the request was created by autotel middleware.");
|
|
334
|
+
const tracer = trace$1.getTracer("autotel.request-logger");
|
|
335
|
+
const lifecycle = forkOptions?.lifecycle;
|
|
336
|
+
tracer.startActiveSpan(`request.fork:${label}`, (childSpan) => {
|
|
337
|
+
const childContext = {
|
|
338
|
+
...createTraceContext(childSpan),
|
|
339
|
+
correlationId: crypto.randomUUID()
|
|
340
|
+
};
|
|
341
|
+
requestContextStore.run(childContext, () => {
|
|
342
|
+
const childLog = getRequestLogger(childContext);
|
|
343
|
+
childLog.set({
|
|
344
|
+
operation: label,
|
|
345
|
+
_parentCorrelationId: parentRequestId
|
|
346
|
+
});
|
|
347
|
+
lifecycle?.onChildEnter?.(childLog);
|
|
348
|
+
Promise.resolve().then(() => fn()).then(() => {
|
|
349
|
+
childLog.emitNow();
|
|
350
|
+
}).catch((err) => {
|
|
351
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
352
|
+
childLog.error(error);
|
|
353
|
+
childLog.emitNow();
|
|
354
|
+
}).finally(() => {
|
|
355
|
+
try {
|
|
356
|
+
lifecycle?.onChildExit?.(childLog);
|
|
357
|
+
} catch (hookError) {
|
|
358
|
+
console.warn("[autotel] fork onChildExit hook threw:", hookError);
|
|
359
|
+
}
|
|
360
|
+
childSpan.end();
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Returns `true` when a request-logger context can be resolved without throwing —
|
|
369
|
+
* i.e. an explicit `ctx` was provided, a `runWithRequestContext()` scope is active,
|
|
370
|
+
* or there is an active OpenTelemetry span.
|
|
371
|
+
*
|
|
372
|
+
* Use this to branch on observability availability instead of wrapping
|
|
373
|
+
* {@link getRequestLogger} in try/catch.
|
|
374
|
+
*/
|
|
375
|
+
function hasRequestContext(ctx) {
|
|
376
|
+
if (ctx) return true;
|
|
377
|
+
if (requestContextStore.getStore()) return true;
|
|
378
|
+
return trace$1.getActiveSpan() != null;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Like {@link getRequestLogger}, but returns `null` instead of throwing when no
|
|
382
|
+
* request context is available. Intended for best-effort instrumentation where a
|
|
383
|
+
* missing telemetry context must never crash business logic.
|
|
384
|
+
*/
|
|
385
|
+
function getRequestLoggerSafe(ctx, options) {
|
|
386
|
+
if (!hasRequestContext(ctx)) return null;
|
|
387
|
+
return getRequestLogger(ctx, options);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* A no-op {@link RequestLogger} whose methods do nothing. Used as a fallback by
|
|
391
|
+
* best-effort instrumentation so wrapped handlers can run un-instrumented without
|
|
392
|
+
* branching on logger presence.
|
|
393
|
+
*/
|
|
394
|
+
function createNoopRequestLogger() {
|
|
395
|
+
const snapshot = () => ({
|
|
396
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
397
|
+
traceId: "",
|
|
398
|
+
spanId: "",
|
|
399
|
+
correlationId: "",
|
|
400
|
+
context: {}
|
|
401
|
+
});
|
|
402
|
+
return {
|
|
403
|
+
set() {},
|
|
404
|
+
info() {},
|
|
405
|
+
warn() {},
|
|
406
|
+
error() {},
|
|
407
|
+
getContext() {
|
|
408
|
+
return {};
|
|
409
|
+
},
|
|
410
|
+
emitNow() {
|
|
411
|
+
return snapshot();
|
|
412
|
+
},
|
|
413
|
+
fork(_label, fn) {
|
|
414
|
+
Promise.resolve().then(() => fn());
|
|
415
|
+
}
|
|
416
|
+
};
|
|
400
417
|
}
|
|
401
418
|
|
|
402
|
-
|
|
403
|
-
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region src/error-catalog.ts
|
|
421
|
+
/**
|
|
422
|
+
* Typed error and audit catalogs.
|
|
423
|
+
*
|
|
424
|
+
* Group related errors into one catalog and get a refactor-safe builder per
|
|
425
|
+
* code, with autocomplete at every call site and typed message parameters.
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* import { defineErrorCatalog } from 'autotel';
|
|
430
|
+
*
|
|
431
|
+
* export const billing = defineErrorCatalog('billing', {
|
|
432
|
+
* PAYMENT_DECLINED: {
|
|
433
|
+
* status: 402,
|
|
434
|
+
* message: 'Card declined',
|
|
435
|
+
* why: 'The issuer rejected the charge',
|
|
436
|
+
* fix: 'Try a different payment method',
|
|
437
|
+
* },
|
|
438
|
+
* INSUFFICIENT_FUNDS: {
|
|
439
|
+
* status: 402,
|
|
440
|
+
* message: ({ available, required }: { available: number; required: number }) =>
|
|
441
|
+
* `Insufficient funds: $${available} of $${required}`,
|
|
442
|
+
* },
|
|
443
|
+
* });
|
|
444
|
+
*
|
|
445
|
+
* throw billing.PAYMENT_DECLINED({ cause: stripeError });
|
|
446
|
+
* throw billing.INSUFFICIENT_FUNDS({ available: 5, required: 100 });
|
|
447
|
+
*
|
|
448
|
+
* // In a catch block — refactor-safe, no magic strings:
|
|
449
|
+
* if (billing.PAYMENT_DECLINED.match(err)) { ... }
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
const catalogCodeKey = Symbol.for("autotel.catalog.code");
|
|
404
453
|
function readCatalogCode(error) {
|
|
405
|
-
|
|
406
|
-
|
|
454
|
+
if (error === null || typeof error !== "object") return void 0;
|
|
455
|
+
return error[catalogCodeKey];
|
|
407
456
|
}
|
|
457
|
+
/** True when `error` was produced by any autotel error catalog. */
|
|
408
458
|
function isCatalogError(error) {
|
|
409
|
-
|
|
459
|
+
return readCatalogCode(error) !== void 0;
|
|
410
460
|
}
|
|
461
|
+
/** Returns the catalog code of `error`, or `undefined` if it has none. */
|
|
411
462
|
function getCatalogCode(error) {
|
|
412
|
-
|
|
463
|
+
return readCatalogCode(error);
|
|
413
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
* Define a typed error catalog. Returns an object whose keys are error
|
|
467
|
+
* builders. Each builder produces a {@link StructuredError} carrying the
|
|
468
|
+
* entry's message, status, code, why, fix, and link.
|
|
469
|
+
*/
|
|
414
470
|
function defineErrorCatalog(namespace, entries) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
471
|
+
const catalog = {};
|
|
472
|
+
for (const [key, entry] of Object.entries(entries)) {
|
|
473
|
+
const code = entry.code ?? `${namespace}.${key}`;
|
|
474
|
+
const usesParams = typeof entry.message === "function" || typeof entry.why === "function";
|
|
475
|
+
const builder = ((paramsOrOptions, maybeOptions) => {
|
|
476
|
+
const params = usesParams ? paramsOrOptions : void 0;
|
|
477
|
+
const options = usesParams ? maybeOptions : paramsOrOptions;
|
|
478
|
+
const message = typeof entry.message === "function" ? entry.message(params) : entry.message;
|
|
479
|
+
const why = typeof entry.why === "function" ? entry.why(params) : entry.why;
|
|
480
|
+
const error = createStructuredError({
|
|
481
|
+
message,
|
|
482
|
+
name: entry.name ?? key,
|
|
483
|
+
code,
|
|
484
|
+
...entry.status === void 0 ? {} : { status: entry.status },
|
|
485
|
+
...why === void 0 ? {} : { why },
|
|
486
|
+
...entry.fix === void 0 ? {} : { fix: entry.fix },
|
|
487
|
+
...entry.link === void 0 ? {} : { link: entry.link },
|
|
488
|
+
...options?.cause === void 0 ? {} : { cause: options.cause },
|
|
489
|
+
...options?.details === void 0 ? {} : { details: options.details },
|
|
490
|
+
...options?.internal === void 0 ? {} : { internal: options.internal }
|
|
491
|
+
});
|
|
492
|
+
Object.defineProperty(error, catalogCodeKey, {
|
|
493
|
+
value: code,
|
|
494
|
+
enumerable: false,
|
|
495
|
+
writable: false,
|
|
496
|
+
configurable: true
|
|
497
|
+
});
|
|
498
|
+
return error;
|
|
499
|
+
});
|
|
500
|
+
Object.defineProperty(builder, "code", {
|
|
501
|
+
value: code,
|
|
502
|
+
enumerable: true
|
|
503
|
+
});
|
|
504
|
+
Object.defineProperty(builder, "match", {
|
|
505
|
+
value: (error) => readCatalogCode(error) === code,
|
|
506
|
+
enumerable: false
|
|
507
|
+
});
|
|
508
|
+
catalog[key] = builder;
|
|
509
|
+
}
|
|
510
|
+
return Object.freeze(catalog);
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Define a typed audit catalog. Returns typed action descriptors you can pass
|
|
514
|
+
* to `track()` or audit helpers without scattering magic strings.
|
|
515
|
+
*/
|
|
456
516
|
function defineAuditCatalog(namespace, entries) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
517
|
+
const catalog = {};
|
|
518
|
+
for (const [key, entry] of Object.entries(entries)) {
|
|
519
|
+
const action = entry.action ?? `${namespace}.${key}`;
|
|
520
|
+
const severity = entry.severity ?? "info";
|
|
521
|
+
const descriptor = ((params) => {
|
|
522
|
+
const message = typeof entry.message === "function" ? entry.message(params) : entry.message;
|
|
523
|
+
return Object.freeze({
|
|
524
|
+
action,
|
|
525
|
+
severity,
|
|
526
|
+
...message === void 0 ? {} : { message }
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
Object.defineProperty(descriptor, "action", {
|
|
530
|
+
value: action,
|
|
531
|
+
enumerable: true
|
|
532
|
+
});
|
|
533
|
+
Object.defineProperty(descriptor, "severity", {
|
|
534
|
+
value: severity,
|
|
535
|
+
enumerable: true
|
|
536
|
+
});
|
|
537
|
+
catalog[key] = descriptor;
|
|
538
|
+
}
|
|
539
|
+
return Object.freeze(catalog);
|
|
480
540
|
}
|
|
481
541
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
542
|
+
//#endregion
|
|
543
|
+
//#region src/drain-toolkit.ts
|
|
544
|
+
const DEFAULT_TIMEOUT_MS = 5e3;
|
|
545
|
+
const DEFAULT_RETRIES = 2;
|
|
485
546
|
function delay(ms) {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
});
|
|
547
|
+
return new Promise((resolve) => {
|
|
548
|
+
setTimeout(resolve, ms).unref?.();
|
|
549
|
+
});
|
|
490
550
|
}
|
|
491
551
|
async function postWithRetry(options) {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
}
|
|
517
|
-
} finally {
|
|
518
|
-
clearTimeout(timeout);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
throw lastError;
|
|
552
|
+
const { name, request, timeoutMs, retries } = options;
|
|
553
|
+
const attempts = Math.max(1, retries);
|
|
554
|
+
let lastError;
|
|
555
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
556
|
+
const controller = new AbortController();
|
|
557
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
558
|
+
timeout.unref?.();
|
|
559
|
+
try {
|
|
560
|
+
const response = await fetch(request.url, {
|
|
561
|
+
method: "POST",
|
|
562
|
+
headers: request.headers,
|
|
563
|
+
body: request.body,
|
|
564
|
+
signal: controller.signal
|
|
565
|
+
});
|
|
566
|
+
if (!response.ok) throw new Error(`[autotel/${name}] HTTP ${response.status} draining ${request.url}`);
|
|
567
|
+
return;
|
|
568
|
+
} catch (error) {
|
|
569
|
+
lastError = error;
|
|
570
|
+
if (attempt < attempts) await delay(100 * attempt);
|
|
571
|
+
} finally {
|
|
572
|
+
clearTimeout(timeout);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
throw lastError;
|
|
522
576
|
}
|
|
523
577
|
function defineDrain(options) {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
578
|
+
return async (ctx) => {
|
|
579
|
+
const contexts = Array.isArray(ctx) ? ctx : [ctx];
|
|
580
|
+
if (contexts.length === 0) return;
|
|
581
|
+
const config = await options.resolve();
|
|
582
|
+
if (!config) return;
|
|
583
|
+
const payloads = options.transform ? options.transform(contexts) : contexts;
|
|
584
|
+
if (payloads.length === 0) return;
|
|
585
|
+
try {
|
|
586
|
+
await options.send(payloads, config);
|
|
587
|
+
} catch (error) {
|
|
588
|
+
console.error(`[autotel/${options.name}] drain failed:`, error);
|
|
589
|
+
}
|
|
590
|
+
};
|
|
537
591
|
}
|
|
538
592
|
function defineHttpDrain(options) {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
593
|
+
return defineDrain({
|
|
594
|
+
name: options.name,
|
|
595
|
+
resolve: options.resolve,
|
|
596
|
+
transform: options.transform,
|
|
597
|
+
send: async (payloads, config) => {
|
|
598
|
+
const request = options.encode(payloads, config);
|
|
599
|
+
if (!request) return;
|
|
600
|
+
const timeoutMs = options.resolveTimeoutMs?.(config) ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
601
|
+
const retries = options.resolveRetries?.(config) ?? options.retries ?? DEFAULT_RETRIES;
|
|
602
|
+
await postWithRetry({
|
|
603
|
+
name: options.name,
|
|
604
|
+
request,
|
|
605
|
+
timeoutMs,
|
|
606
|
+
retries
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
});
|
|
556
610
|
}
|
|
557
611
|
|
|
558
|
-
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region src/enricher-toolkit.ts
|
|
559
614
|
function isPlainObject(value) {
|
|
560
|
-
|
|
615
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
561
616
|
}
|
|
562
|
-
function
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
target[key] = sourceVal;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
617
|
+
function mergeInto(target, source) {
|
|
618
|
+
for (const key in source) {
|
|
619
|
+
const sourceVal = source[key];
|
|
620
|
+
if (sourceVal === void 0) continue;
|
|
621
|
+
const targetVal = target[key];
|
|
622
|
+
if (isPlainObject(sourceVal) && isPlainObject(targetVal)) mergeInto(targetVal, sourceVal);
|
|
623
|
+
else target[key] = sourceVal;
|
|
624
|
+
}
|
|
573
625
|
}
|
|
574
626
|
function defineEnricher(def, options = {}) {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
computed
|
|
591
|
-
);
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
var GEN_AI_DURATION_BUCKETS_SECONDS = Object.freeze(
|
|
595
|
-
[0.01, 0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 20, 30, 60, 120, 300]
|
|
596
|
-
);
|
|
597
|
-
var GEN_AI_TOKEN_USAGE_BUCKETS = Object.freeze([
|
|
598
|
-
1,
|
|
599
|
-
4,
|
|
600
|
-
16,
|
|
601
|
-
64,
|
|
602
|
-
256,
|
|
603
|
-
1024,
|
|
604
|
-
4096,
|
|
605
|
-
16384,
|
|
606
|
-
65536,
|
|
607
|
-
262144,
|
|
608
|
-
1048576,
|
|
609
|
-
4194304
|
|
610
|
-
]);
|
|
611
|
-
var GEN_AI_COST_USD_BUCKETS = Object.freeze([
|
|
612
|
-
1e-5,
|
|
613
|
-
1e-4,
|
|
614
|
-
1e-3,
|
|
615
|
-
5e-3,
|
|
616
|
-
0.01,
|
|
617
|
-
0.05,
|
|
618
|
-
0.1,
|
|
619
|
-
0.5,
|
|
620
|
-
1,
|
|
621
|
-
5,
|
|
622
|
-
10,
|
|
623
|
-
50
|
|
624
|
-
]);
|
|
625
|
-
function llmHistogramAdvice(kind) {
|
|
626
|
-
const boundaries = kind === "duration" ? GEN_AI_DURATION_BUCKETS_SECONDS : kind === "tokens" ? GEN_AI_TOKEN_USAGE_BUCKETS : GEN_AI_COST_USD_BUCKETS;
|
|
627
|
-
return { advice: { explicitBucketBoundaries: [...boundaries] } };
|
|
628
|
-
}
|
|
629
|
-
function genAiMetricViews(extra = []) {
|
|
630
|
-
const defaults = [
|
|
631
|
-
{ instrumentName: "gen_ai.client.operation.duration", kind: "duration" },
|
|
632
|
-
{ instrumentName: "gen_ai.client.token.usage", kind: "tokens" },
|
|
633
|
-
// Autotel-emitted cost metric. No-op if you don't emit it.
|
|
634
|
-
{ instrumentName: "gen_ai.client.cost.usd", kind: "cost" }
|
|
635
|
-
];
|
|
636
|
-
return [...defaults, ...extra].map(
|
|
637
|
-
({ instrumentName, kind }) => ({
|
|
638
|
-
instrumentName,
|
|
639
|
-
aggregation: {
|
|
640
|
-
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
|
|
641
|
-
options: {
|
|
642
|
-
boundaries: kind === "duration" ? [...GEN_AI_DURATION_BUCKETS_SECONDS] : kind === "tokens" ? [...GEN_AI_TOKEN_USAGE_BUCKETS] : [...GEN_AI_COST_USD_BUCKETS]
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
})
|
|
646
|
-
);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
// src/gen-ai-events.ts
|
|
650
|
-
function recordPromptSent(ctx2, event = {}) {
|
|
651
|
-
emitCorrelatedEvent(ctx2, "gen_ai.prompt.sent", buildPromptSentAttrs(event));
|
|
652
|
-
}
|
|
653
|
-
function recordResponseReceived(ctx2, event = {}) {
|
|
654
|
-
emitCorrelatedEvent(
|
|
655
|
-
ctx2,
|
|
656
|
-
"gen_ai.response.received",
|
|
657
|
-
buildResponseAttrs(event)
|
|
658
|
-
);
|
|
659
|
-
}
|
|
660
|
-
function recordRetry(ctx2, event) {
|
|
661
|
-
emitCorrelatedEvent(ctx2, "gen_ai.retry", buildRetryAttrs(event));
|
|
662
|
-
}
|
|
663
|
-
function recordToolCall(ctx2, event) {
|
|
664
|
-
emitCorrelatedEvent(ctx2, "gen_ai.tool.call", buildToolCallAttrs(event));
|
|
665
|
-
}
|
|
666
|
-
function recordStreamFirstToken(ctx2, event = {}) {
|
|
667
|
-
emitCorrelatedEvent(
|
|
668
|
-
ctx2,
|
|
669
|
-
"gen_ai.stream.first_token",
|
|
670
|
-
buildStreamFirstTokenAttrs(event)
|
|
671
|
-
);
|
|
672
|
-
}
|
|
673
|
-
function buildPromptSentAttrs(event) {
|
|
674
|
-
const attrs2 = {};
|
|
675
|
-
if (event.model) attrs2["gen_ai.request.model"] = event.model;
|
|
676
|
-
if (event.promptTokens !== void 0)
|
|
677
|
-
attrs2["gen_ai.usage.input_tokens"] = event.promptTokens;
|
|
678
|
-
if (event.messageCount !== void 0)
|
|
679
|
-
attrs2["gen_ai.request.message_count"] = event.messageCount;
|
|
680
|
-
if (event.operation) attrs2["gen_ai.operation.name"] = event.operation;
|
|
681
|
-
return attrs2;
|
|
682
|
-
}
|
|
683
|
-
function buildResponseAttrs(event) {
|
|
684
|
-
const attrs2 = {};
|
|
685
|
-
if (event.model) attrs2["gen_ai.response.model"] = event.model;
|
|
686
|
-
if (event.promptTokens !== void 0)
|
|
687
|
-
attrs2["gen_ai.usage.input_tokens"] = event.promptTokens;
|
|
688
|
-
if (event.completionTokens !== void 0)
|
|
689
|
-
attrs2["gen_ai.usage.output_tokens"] = event.completionTokens;
|
|
690
|
-
if (event.totalTokens !== void 0)
|
|
691
|
-
attrs2["gen_ai.usage.total_tokens"] = event.totalTokens;
|
|
692
|
-
if (event.finishReasons && event.finishReasons.length > 0) {
|
|
693
|
-
attrs2["gen_ai.response.finish_reasons"] = event.finishReasons.join(",");
|
|
694
|
-
}
|
|
695
|
-
return attrs2;
|
|
696
|
-
}
|
|
697
|
-
function buildRetryAttrs(event) {
|
|
698
|
-
const attrs2 = { "retry.attempt": event.attempt };
|
|
699
|
-
if (event.reason) attrs2["retry.reason"] = event.reason;
|
|
700
|
-
if (event.delayMs !== void 0) attrs2["retry.delay_ms"] = event.delayMs;
|
|
701
|
-
if (event.statusCode !== void 0)
|
|
702
|
-
attrs2["http.response.status_code"] = event.statusCode;
|
|
703
|
-
return attrs2;
|
|
704
|
-
}
|
|
705
|
-
function buildToolCallAttrs(event) {
|
|
706
|
-
const attrs2 = { "gen_ai.tool.name": event.toolName };
|
|
707
|
-
if (event.toolCallId) attrs2["gen_ai.tool.call.id"] = event.toolCallId;
|
|
708
|
-
if (event.arguments) attrs2["gen_ai.tool.arguments"] = event.arguments;
|
|
709
|
-
return attrs2;
|
|
710
|
-
}
|
|
711
|
-
function buildStreamFirstTokenAttrs(event) {
|
|
712
|
-
const attrs2 = {};
|
|
713
|
-
if (event.tokensSoFar !== void 0)
|
|
714
|
-
attrs2["gen_ai.stream.tokens_so_far"] = event.tokensSoFar;
|
|
715
|
-
return attrs2;
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
// src/gen-ai-cost.ts
|
|
719
|
-
var GEN_AI_COST_ATTRIBUTE = "gen_ai.usage.cost.usd";
|
|
720
|
-
var MODEL_PRICING = {
|
|
721
|
-
// OpenAI
|
|
722
|
-
"gpt-4o": { inputPer1M: 2.5, outputPer1M: 10 },
|
|
723
|
-
"gpt-4o-mini": { inputPer1M: 0.15, outputPer1M: 0.6 },
|
|
724
|
-
"gpt-4.1": { inputPer1M: 2, outputPer1M: 8 },
|
|
725
|
-
"gpt-4.1-mini": { inputPer1M: 0.4, outputPer1M: 1.6 },
|
|
726
|
-
"gpt-4.1-nano": { inputPer1M: 0.1, outputPer1M: 0.4 },
|
|
727
|
-
"o3-mini": { inputPer1M: 1.1, outputPer1M: 4.4 },
|
|
728
|
-
// Anthropic Claude
|
|
729
|
-
"claude-opus-4": { inputPer1M: 15, outputPer1M: 75 },
|
|
730
|
-
"claude-sonnet-4": { inputPer1M: 3, outputPer1M: 15 },
|
|
731
|
-
"claude-3-5-sonnet": { inputPer1M: 3, outputPer1M: 15 },
|
|
732
|
-
"claude-3-5-haiku": { inputPer1M: 0.8, outputPer1M: 4 },
|
|
733
|
-
"claude-3-opus": { inputPer1M: 15, outputPer1M: 75 },
|
|
734
|
-
"claude-3-haiku": { inputPer1M: 0.25, outputPer1M: 1.25 },
|
|
735
|
-
// Google Gemini
|
|
736
|
-
"gemini-1.5-pro": { inputPer1M: 1.25, outputPer1M: 5 },
|
|
737
|
-
"gemini-1.5-flash": { inputPer1M: 0.075, outputPer1M: 0.3 },
|
|
738
|
-
"gemini-2.0-flash": { inputPer1M: 0.1, outputPer1M: 0.4 }
|
|
739
|
-
};
|
|
740
|
-
function resolvePricing(table, model) {
|
|
741
|
-
const exact = table[model];
|
|
742
|
-
if (exact) return exact;
|
|
743
|
-
let best;
|
|
744
|
-
let bestLength = 0;
|
|
745
|
-
for (const key of Object.keys(table)) {
|
|
746
|
-
if (model.startsWith(key) && key.length > bestLength) {
|
|
747
|
-
best = table[key];
|
|
748
|
-
bestLength = key.length;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
return best;
|
|
752
|
-
}
|
|
753
|
-
function round(value) {
|
|
754
|
-
return Math.round(value * 1e6) / 1e6;
|
|
755
|
-
}
|
|
756
|
-
function estimateLLMCost(model, usage, options) {
|
|
757
|
-
const table = options?.pricing ? { ...MODEL_PRICING, ...options.pricing } : MODEL_PRICING;
|
|
758
|
-
const price = resolvePricing(table, model);
|
|
759
|
-
if (!price) return void 0;
|
|
760
|
-
const cachedInput = usage.cachedInputTokens ?? 0;
|
|
761
|
-
const billedInput = Math.max(0, (usage.inputTokens ?? 0) - cachedInput);
|
|
762
|
-
const output = usage.outputTokens ?? 0;
|
|
763
|
-
const cachedRate = price.cachedInputPer1M ?? price.inputPer1M;
|
|
764
|
-
const cost = billedInput / 1e6 * price.inputPer1M + cachedInput / 1e6 * cachedRate + output / 1e6 * price.outputPer1M;
|
|
765
|
-
return round(cost);
|
|
766
|
-
}
|
|
767
|
-
function recordLLMCost(ctx2, model, usage, options) {
|
|
768
|
-
const cost = estimateLLMCost(model, usage, options);
|
|
769
|
-
if (cost !== void 0) {
|
|
770
|
-
ctx2.setAttribute(GEN_AI_COST_ATTRIBUTE, cost);
|
|
771
|
-
}
|
|
772
|
-
return cost;
|
|
627
|
+
return (ctx) => {
|
|
628
|
+
let computed;
|
|
629
|
+
try {
|
|
630
|
+
computed = def.compute(ctx);
|
|
631
|
+
} catch (error) {
|
|
632
|
+
console.error(`[autotel/${def.name}] enrich failed:`, error);
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
if (!computed) return;
|
|
636
|
+
if (options.overwrite || !isPlainObject(ctx.event[def.field])) {
|
|
637
|
+
ctx.event[def.field] = computed;
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
mergeInto(ctx.event[def.field], computed);
|
|
641
|
+
};
|
|
773
642
|
}
|
|
774
643
|
|
|
775
|
-
|
|
776
|
-
|
|
644
|
+
//#endregion
|
|
645
|
+
export { AUTOTEL_SAMPLING_TAIL_EVALUATED, AUTOTEL_SAMPLING_TAIL_KEEP, AdaptiveSampler, AlwaysSampler, AttributeRedactingProcessor, BaggageSpanProcessor, BusinessBaggage, CORRELATION_ID_BAGGAGE_KEY, Event, FilteringSpanProcessor, HTTPAttributes, Metric, NORMALIZER_PATTERNS, NORMALIZER_PRESETS, NeverSampler, REDACTOR_PATTERNS, REDACTOR_PRESETS, ROOT_CONTEXT, RandomSampler, ServiceAttributes, SpanKind, SpanNameNormalizingProcessor, SpanStatusCode, URLAttributes, UserIdSampler, attrs, autoRedactPII, builtinPatterns, context, createAttributeRedactor, createCounter, createDeterministicTraceId, createDrainPipeline, createHistogram, createLinkFromHeaders, createNoopRequestLogger, createObservableGauge, createRedactedSpan, createSafeBaggageSchema, createStringRedactor, createStructuredError, createUpDownCounter, ctx, dbClient, defineAuditCatalog, defineBaggageSchema, defineDrain, defineEnricher, defineErrorCatalog, defineEvent, defineHttpDrain, enrichWithTraceContext, extractLinksFromBatch, finalizeSpan, flattenMetadata, flattenToAttributes, flush, formatDuration, generateCorrelationId, getActiveContext, getActiveSpan, getAutotelTracer, getAutotelTracerProvider, getCatalogCode, getCorrelationId, getCurrentWorkflowContext, getEventQueue, getEvents, getMeter, getMetrics, getOperationContext, getOrCreateCorrelationId, getRequestLogger, getRequestLoggerSafe, getStructuredErrorAttributes, getTraceContext, getTracer, hasRequestContext, httpClient, httpRequestHeaderAttribute, httpResponseHeaderAttribute, httpServer, identify, init, instrument, isCatalogError, isInWorkflow, isInitialized, isLoggerLocked, isTracing, lockLogger, markAsImmediate, mergeAttrs, mergeServiceResource, normalizeAttributeRedactorConfig, otelTrace, parseError, propagation, recordStructuredError, request, resetEvents, resetMetrics, resolveSamplingPreset, resolveTraceUrl, runInOperationContext, runWithCorrelationId, runWithRequestContext, runWithSpan, safeSetAttributes, samplingPresets, setAutotelTracerProvider, setCorrelationId, setCorrelationIdInBaggage, setDevice, setError, setException, setSession, setUser, shutdown, span, structuredErrorToJSON, toAttributeValue, trace, traceConsumer, traceDB, traceHTTP, traceMessaging, traceProducer, traceStep, traceWorkflow, track, validateAttribute, withBaggage, withNewContext, withTracing };
|
|
777
646
|
//# sourceMappingURL=index.js.map
|