dd-trace 6.23.0 → 6.25.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/LICENSE-3rdparty.csv +0 -1
- package/ci/cypress/support.js +15 -1
- package/ci/init.js +2 -22
- package/ci/test-annotations.d.ts +5 -0
- package/ci/test-annotations.js +5 -0
- package/ci/vitest-no-worker-init-annotations.mjs +4 -0
- package/ci/vitest-no-worker-init-node-setup.mjs +22 -0
- package/ci/vitest-no-worker-init-runner-setup.mjs +7 -32
- package/ci/vitest-no-worker-init-setup.mjs +34 -12
- package/ci/vitest-no-worker-init-v5-setup.mjs +6 -0
- package/ext/exporters.js +1 -1
- package/index.d.ts +124 -5
- package/initialize.mjs +5 -2
- package/lambda.d.ts +39 -0
- package/lambda.js +3 -0
- package/loader-hook.mjs +53 -0
- package/openfeature/exposure-hook.d.ts +66 -0
- package/openfeature/exposure-hook.js +5 -0
- package/package.json +19 -15
- package/packages/datadog-core/src/storage.js +1 -1
- package/packages/datadog-esbuild/index.js +78 -62
- package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
- package/packages/datadog-instrumentations/src/cucumber.js +56 -19
- package/packages/datadog-instrumentations/src/cypress-config.js +163 -15
- package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
- package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
- package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
- package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
- package/packages/datadog-instrumentations/src/graphql.js +29 -20
- package/packages/datadog-instrumentations/src/grpc/server.js +23 -6
- package/packages/{datadog-esbuild/src/utils.js → datadog-instrumentations/src/helpers/bundler-esm-exports.js} +282 -40
- package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +573 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
- package/packages/datadog-instrumentations/src/helpers/fetch.js +5 -1
- package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +30 -8
- package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
- package/packages/datadog-instrumentations/src/helpers/hooks.js +4 -8
- package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +18 -6
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +26 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +3 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +40 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/react-router.js +49 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/typesafe.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +12 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +58 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +19 -2
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +25 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
- package/packages/datadog-instrumentations/src/ioredis.js +101 -3
- package/packages/datadog-instrumentations/src/jest.js +265 -82
- package/packages/datadog-instrumentations/src/mariadb-bundle.js +69 -11
- package/packages/datadog-instrumentations/src/mariadb.js +13 -6
- package/packages/datadog-instrumentations/src/mocha/common.js +89 -8
- package/packages/datadog-instrumentations/src/mocha/main.js +11 -2
- package/packages/datadog-instrumentations/src/mocha/utils.js +58 -12
- package/packages/datadog-instrumentations/src/mocha/worker.js +1 -1
- package/packages/datadog-instrumentations/src/next.js +19 -6
- package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
- package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
- package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
- package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
- package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
- package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
- package/packages/datadog-instrumentations/src/oracledb.js +33 -0
- package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
- package/packages/datadog-instrumentations/src/pg.js +2 -1
- package/packages/datadog-instrumentations/src/playwright.js +81 -28
- package/packages/datadog-instrumentations/src/react-router.js +106 -0
- package/packages/datadog-instrumentations/src/typesafe.js +89 -0
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +84 -48
- package/packages/datadog-instrumentations/src/vitest-main.js +26 -0
- package/packages/datadog-instrumentations/src/vitest-test-annotations.js +20 -0
- package/packages/datadog-instrumentations/src/vitest-worker.js +39 -17
- package/packages/datadog-instrumentations/src/vitest.js +10 -8
- package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
- package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
- package/packages/datadog-plugin-cucumber/src/index.js +5 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +296 -55
- package/packages/datadog-plugin-cypress/src/index.js +1 -1
- package/packages/datadog-plugin-cypress/src/lifecycle-owner.js +20 -0
- package/packages/datadog-plugin-cypress/src/plugin.js +10 -0
- package/packages/datadog-plugin-cypress/src/retry-config-observer.js +281 -0
- package/packages/datadog-plugin-cypress/src/setup-handoff.js +125 -0
- package/packages/datadog-plugin-cypress/src/support.js +1217 -439
- package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -7
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -52
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +4 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
- package/packages/datadog-plugin-graphql/src/execute.js +2 -2
- package/packages/datadog-plugin-graphql/src/utils.js +5 -5
- package/packages/datadog-plugin-http/src/client.js +32 -9
- package/packages/datadog-plugin-http2/src/client.js +38 -13
- package/packages/datadog-plugin-jest/src/index.js +25 -3
- package/packages/datadog-plugin-mocha/src/index.js +47 -6
- package/packages/datadog-plugin-next/src/index.js +112 -14
- package/packages/datadog-plugin-oracledb/src/connection-parser.js +21 -11
- package/packages/datadog-plugin-playwright/src/index.js +4 -0
- package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
- package/packages/datadog-plugin-react-router/src/index.js +118 -0
- package/packages/datadog-plugin-trpc/src/index.js +15 -0
- package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
- package/packages/datadog-plugin-trpc/src/request.js +81 -0
- package/packages/datadog-plugin-typesafe/src/index.js +17 -0
- package/packages/datadog-plugin-typesafe/src/tracing.js +31 -0
- package/packages/datadog-plugin-undici/src/index.js +22 -7
- package/packages/datadog-plugin-vitest/src/index.js +8 -0
- package/packages/datadog-turbopack/index.js +4 -28
- package/packages/datadog-turbopack/src/loader.js +14 -452
- package/packages/datadog-webpack/index.js +3 -55
- package/packages/dd-trace/src/agent/info.js +2 -1
- package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
- package/packages/dd-trace/src/aiguard/sdk.js +8 -13
- package/packages/dd-trace/src/aiguard/tags.js +2 -0
- package/packages/dd-trace/src/appsec/blocking/index.js +4 -0
- package/packages/dd-trace/src/appsec/graphql.js +91 -6
- package/packages/dd-trace/src/appsec/recommended.json +1287 -90
- package/packages/dd-trace/src/before-exit.js +32 -0
- package/packages/dd-trace/src/bootstrap.js +5 -3
- package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +24 -18
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +16 -36
- package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
- package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +10 -18
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +10 -15
- package/packages/dd-trace/src/ci-visibility/requests/route.js +44 -0
- package/packages/dd-trace/src/ci-visibility/telemetry-logs.js +5 -0
- package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
- package/packages/dd-trace/src/ci-visibility/test-annotations.js +72 -0
- package/packages/dd-trace/src/ci-visibility/test-declaration-annotations.js +170 -0
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +10 -17
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
- package/packages/dd-trace/src/config/config-types.d.ts +3 -0
- package/packages/dd-trace/src/config/defaults.js +9 -3
- package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -2
- package/packages/dd-trace/src/config/index.js +111 -43
- package/packages/dd-trace/src/config/parsers.js +18 -1
- package/packages/dd-trace/src/config/supported-configurations.json +174 -4
- package/packages/dd-trace/src/constants.js +1 -0
- package/packages/dd-trace/src/debugger/pause-duration-histogram.js +2 -1
- package/packages/dd-trace/src/debugger/probe_sampler.js +6 -6
- package/packages/dd-trace/src/encode/0.4.js +2 -2
- package/packages/dd-trace/src/esm-module-load.js +58 -0
- package/packages/dd-trace/src/exporter.js +23 -15
- package/packages/dd-trace/src/exporters/agent/index.js +3 -1
- package/packages/dd-trace/src/exporters/agentless/index.js +3 -1
- package/packages/dd-trace/src/exporters/common/request.js +83 -50
- package/packages/dd-trace/src/exporters/common/retry.js +12 -7
- package/packages/dd-trace/src/exporters/common/url.js +1 -1
- package/packages/dd-trace/src/exporters/llmobs/index.js +135 -0
- package/packages/dd-trace/src/exporters/log/index.js +4 -3
- package/packages/dd-trace/src/id.js +1 -1
- package/packages/dd-trace/src/lambda/facade.js +74 -0
- package/packages/dd-trace/src/lambda/handler.js +3 -41
- package/packages/dd-trace/src/lambda/index.js +38 -15
- package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
- package/packages/dd-trace/src/lambda/wrap.js +44 -0
- package/packages/dd-trace/src/llmobs/constants/tags.js +3 -0
- package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
- package/packages/dd-trace/src/llmobs/experiments/index.js +2 -3
- package/packages/dd-trace/src/llmobs/experiments/noop.js +5 -2
- package/packages/dd-trace/src/llmobs/index.js +13 -2
- package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +27 -10
- package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
- package/packages/dd-trace/src/llmobs/plugins/typesafe/index.js +102 -0
- package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
- package/packages/dd-trace/src/llmobs/prompts/cache.js +3 -1
- package/packages/dd-trace/src/llmobs/sdk.js +21 -1
- package/packages/dd-trace/src/llmobs/span_processor.js +219 -12
- package/packages/dd-trace/src/llmobs/tagger.js +25 -0
- package/packages/dd-trace/src/llmobs/writers/util.js +3 -3
- package/packages/dd-trace/src/log/channels.js +4 -0
- package/packages/dd-trace/src/log/writer.js +13 -2
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +68 -6
- package/packages/dd-trace/src/openfeature/configuration_source.js +41 -17
- package/packages/dd-trace/src/openfeature/debug-logging-hook.js +66 -3
- package/packages/dd-trace/src/openfeature/exposure-hook.js +185 -0
- package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +58 -14
- package/packages/dd-trace/src/openfeature/remote_config.js +16 -3
- package/packages/dd-trace/src/openfeature/writers/base.js +63 -30
- package/packages/dd-trace/src/openfeature/writers/exposures.js +161 -1
- package/packages/dd-trace/src/openfeature/writers/flag-eval-evp-hook.js +5 -0
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-aggregation.js +9 -4
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-payload.js +2 -0
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-pii.js +2 -0
- package/packages/dd-trace/src/openfeature/writers/split-features.js +25 -0
- package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
- package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
- package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -2
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
- package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
- package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
- package/packages/dd-trace/src/opentelemetry/span.js +2 -2
- package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
- package/packages/dd-trace/src/opentelemetry/tracer_provider.js +5 -1
- package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
- package/packages/dd-trace/src/opentracing/tracer.js +33 -13
- package/packages/dd-trace/src/otel-thread-ctx.js +72 -49
- package/packages/dd-trace/src/plugin_manager.js +34 -7
- package/packages/dd-trace/src/plugins/ci_plugin.js +45 -14
- package/packages/dd-trace/src/plugins/index.js +9 -0
- package/packages/dd-trace/src/plugins/plugin.js +4 -2
- package/packages/dd-trace/src/plugins/tracing.js +1 -1
- package/packages/dd-trace/src/plugins/util/ci.js +18 -1
- package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
- package/packages/dd-trace/src/plugins/util/git.js +273 -86
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +77 -50
- package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
- package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
- package/packages/dd-trace/src/plugins/util/tags.js +6 -0
- package/packages/dd-trace/src/plugins/util/test.js +90 -45
- package/packages/dd-trace/src/plugins/util/url.js +10 -2
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -2
- package/packages/dd-trace/src/plugins/util/web.js +81 -10
- package/packages/dd-trace/src/process-tags/index.js +1 -1
- package/packages/dd-trace/src/profiling/config.js +6 -3
- package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
- package/packages/dd-trace/src/proxy.js +48 -57
- package/packages/dd-trace/src/serverless.js +3 -2
- package/packages/dd-trace/src/span_processor.js +41 -9
- package/packages/dd-trace/src/span_stats.js +28 -2
- package/packages/dd-trace/src/startup-log.js +8 -5
- package/packages/dd-trace/src/tagger.js +7 -5
- package/packages/dd-trace/src/telemetry/dependencies.js +4 -0
- package/packages/dd-trace/src/telemetry/index.js +3 -0
- package/packages/dd-trace/src/telemetry/logs/index.js +21 -2
- package/packages/dd-trace/src/telemetry/logs/log-collector.js +1 -0
- package/packages/dd-trace/src/telemetry/metrics.js +2 -1
- package/packages/dd-trace/src/telemetry/telemetry.js +10 -3
- package/packages/dd-trace/src/tracer.js +0 -2
- package/packages/dd-trace/src/util.js +1 -1
- package/packages/dd-trace/src/web-tags-cache.js +8 -9
- package/register.js +4 -2
- package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
- package/vendor/dist/{@opentelemetry/resources → @datadog/flagging-core}/LICENSE +22 -2
- package/vendor/dist/@datadog/flagging-core/index.js +1 -0
- package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
- package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.d.ts +78 -0
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.js +1 -1
- package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
- package/vendor/dist/@datadog/source-map/LICENSE +1 -0
- package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
- package/vendor/dist/@opentelemetry/core/LICENSE +209 -1
- package/vendor/dist/@opentelemetry/core/index.js +1 -1
- package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
- package/vendor/dist/escape-string-regexp/LICENSE +13 -0
- package/vendor/dist/esquery/LICENSE +2 -0
- package/vendor/dist/https-proxy-agent/LICENSE +80 -1
- package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
- package/vendor/dist/jest-docblock/LICENSE +16 -0
- package/vendor/dist/jsonpath-plus/LICENSE +13 -0
- package/vendor/dist/limiter/LICENSE +2 -0
- package/vendor/dist/lodash.sortby/LICENSE +2 -0
- package/vendor/dist/lru-cache/LICENSE +13 -0
- package/vendor/dist/meriyah/LICENSE +13 -0
- package/vendor/dist/module-details-from-path/LICENSE +2 -0
- package/vendor/dist/mutexify/promise/LICENSE +28 -0
- package/vendor/dist/pprof-format/LICENSE +13 -0
- package/vendor/dist/pprof-format/index.js +1 -1
- package/vendor/dist/protobufjs/LICENSE +219 -0
- package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
- package/vendor/dist/proxy-from-env/LICENSE +13 -0
- package/vendor/dist/retry/LICENSE +2 -0
- package/vendor/dist/rfdc/LICENSE +2 -0
- package/vendor/dist/semifies/LICENSE +3 -1
- package/vendor/dist/shell-quote/LICENSE +3 -1
- package/vendor/dist/source-map/LICENSE +1 -0
- package/vendor/dist/source-map/lib/util/LICENSE +1 -0
- package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
- package/vendor/dist/ttl-set/LICENSE +28 -0
- package/ci/diagnose.js +0 -2215
- package/ci/runbook.md +0 -299
- package/ci/test-optimization-validation/approval-artifacts.js +0 -175
- package/ci/test-optimization-validation/approval.js +0 -386
- package/ci/test-optimization-validation/artifact-id.js +0 -19
- package/ci/test-optimization-validation/blocker-category.js +0 -24
- package/ci/test-optimization-validation/bounded-json.js +0 -120
- package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
- package/ci/test-optimization-validation/ci-discovery.js +0 -192
- package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
- package/ci/test-optimization-validation/ci-remediation.js +0 -283
- package/ci/test-optimization-validation/cli.js +0 -954
- package/ci/test-optimization-validation/command-blocker.js +0 -377
- package/ci/test-optimization-validation/command-output-policy.js +0 -188
- package/ci/test-optimization-validation/command-runner.js +0 -650
- package/ci/test-optimization-validation/environment.js +0 -88
- package/ci/test-optimization-validation/executable-approval.js +0 -47
- package/ci/test-optimization-validation/executable.js +0 -244
- package/ci/test-optimization-validation/execution-lock.js +0 -70
- package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
- package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
- package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
- package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
- package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
- package/ci/test-optimization-validation/generated-file-policy.js +0 -63
- package/ci/test-optimization-validation/generated-files.js +0 -425
- package/ci/test-optimization-validation/generated-test-contract.js +0 -284
- package/ci/test-optimization-validation/generated-verifier.js +0 -235
- package/ci/test-optimization-validation/literal-environment.js +0 -56
- package/ci/test-optimization-validation/literal-glob.js +0 -52
- package/ci/test-optimization-validation/manifest-loader.js +0 -116
- package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
- package/ci/test-optimization-validation/manifest-schema.js +0 -695
- package/ci/test-optimization-validation/offline-fixtures.js +0 -335
- package/ci/test-optimization-validation/offline-output.js +0 -406
- package/ci/test-optimization-validation/package-check.js +0 -97
- package/ci/test-optimization-validation/payload-normalizer.js +0 -72
- package/ci/test-optimization-validation/plan-writer.js +0 -541
- package/ci/test-optimization-validation/preflight-runner.js +0 -186
- package/ci/test-optimization-validation/project-build-artifact.js +0 -31
- package/ci/test-optimization-validation/redaction.js +0 -319
- package/ci/test-optimization-validation/report-writer.js +0 -666
- package/ci/test-optimization-validation/result-semantics.js +0 -103
- package/ci/test-optimization-validation/runner-command.js +0 -264
- package/ci/test-optimization-validation/runner-contract.js +0 -695
- package/ci/test-optimization-validation/safe-files.js +0 -202
- package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
- package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
- package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
- package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
- package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
- package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
- package/ci/test-optimization-validation/source-text.js +0 -84
- package/ci/test-optimization-validation/static-diagnosis.js +0 -166
- package/ci/test-optimization-validation/test-output.js +0 -120
- package/ci/test-optimization-validation/validation-blocker.js +0 -21
- package/ci/validate-test-optimization.js +0 -3
- package/packages/datadog-esbuild/src/resolver.js +0 -284
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
- package/vendor/dist/@opentelemetry/resources/index.js +0 -1
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { randomUUID } = require('node:crypto')
|
|
4
|
+
|
|
5
|
+
const { AudioBuffer, RAW_LIMIT } = require('./audio')
|
|
6
|
+
|
|
7
|
+
const AUDIO_PREFIX = '{"user_audio_chunk":"'
|
|
8
|
+
const MAX_TOOL_ID_CHARS = 1024
|
|
9
|
+
const MAX_TOOL_NAME_CHARS = 1024
|
|
10
|
+
|
|
11
|
+
const EVENT_FIELDS = {
|
|
12
|
+
user_transcript: 'user_transcription_event',
|
|
13
|
+
audio: 'audio_event',
|
|
14
|
+
agent_response: 'agent_response_event',
|
|
15
|
+
agent_response_correction: 'agent_response_correction_event',
|
|
16
|
+
agent_chat_response_part: 'text_response_part',
|
|
17
|
+
client_tool_call: 'client_tool_call',
|
|
18
|
+
context_usage: 'context_usage_event',
|
|
19
|
+
agent_tool_response_full_payload: 'agent_tool_response_full_payload',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @param {unknown} value */
|
|
23
|
+
function rateOf (value) {
|
|
24
|
+
if (typeof value !== 'string' || !/^pcm_\d+$/.test(value)) return 0
|
|
25
|
+
const rate = Number(value.slice(4))
|
|
26
|
+
return rate >= 8000 && rate <= 48_000 ? rate : 0
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @param {unknown} value */
|
|
30
|
+
function eventId (value) {
|
|
31
|
+
if (typeof value === 'string' && /^\d{1,100}$/.test(value)) return BigInt(value)
|
|
32
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? BigInt(value) : undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {unknown} value
|
|
37
|
+
* @param {number} [limit]
|
|
38
|
+
*/
|
|
39
|
+
function textOf (value, limit = 100_000) {
|
|
40
|
+
if (typeof value === 'string') return value.slice(0, limit)
|
|
41
|
+
return ''
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @param {unknown} value */
|
|
45
|
+
function toolIdOf (value) {
|
|
46
|
+
return typeof value === 'string' && value.length <= MAX_TOOL_ID_CHARS ? value : undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {{runInContext?: <T>(fn: () => T) => T}} Scope
|
|
51
|
+
* @typedef {{
|
|
52
|
+
* id: bigint, input: AudioBuffer, output: AudioBuffer, userText: string,
|
|
53
|
+
* responses: Map<string, string>, completed: Set<string>, calls: Map<string, object>,
|
|
54
|
+
* results: Map<string, object>, tools: Set<object>, model?: string, start: number,
|
|
55
|
+
* responseTime: number, toolEnd: number, retired: boolean, playbackEnd?: number, interrupted: boolean,
|
|
56
|
+
* failed: boolean, metadata: Record<string, unknown>, scope: Scope, root?: object, llm?: object,
|
|
57
|
+
* boundaryResponse?: boolean, closed?: boolean, text?: string, sessionId?: string,
|
|
58
|
+
* inputRate?: number, outputRate?: number, argumentsSize: number, argumentSizes: Map<string, number>,
|
|
59
|
+
* }} Turn
|
|
60
|
+
* @typedef {{
|
|
61
|
+
* begin: (turn: Turn) => void, finish: (turn: Turn) => void,
|
|
62
|
+
* retain: () => boolean, agentId: string,
|
|
63
|
+
* }} Options
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
class Session {
|
|
67
|
+
/** @type {{runInContext?: <T>(fn: () => T) => T}} */
|
|
68
|
+
scope = {}
|
|
69
|
+
/** @type {object | undefined} */
|
|
70
|
+
socket = undefined
|
|
71
|
+
/** @type {(failed: boolean) => void} */
|
|
72
|
+
finalize = () => {}
|
|
73
|
+
/** @type {Map<bigint, Turn>} */
|
|
74
|
+
turns = new Map()
|
|
75
|
+
pending = new AudioBuffer()
|
|
76
|
+
pendingText = ''
|
|
77
|
+
/** @type {number | undefined} */
|
|
78
|
+
#pendingTextStart = undefined
|
|
79
|
+
early = []
|
|
80
|
+
earlySize = 0
|
|
81
|
+
earlyOverflow = false
|
|
82
|
+
negotiated = false
|
|
83
|
+
inputRate = 0
|
|
84
|
+
outputRate = 0
|
|
85
|
+
/** @type {string} */
|
|
86
|
+
sessionId = randomUUID()
|
|
87
|
+
lastInterrupt = -1n
|
|
88
|
+
lastFinalized = -1n
|
|
89
|
+
/** @type {bigint | undefined} */
|
|
90
|
+
filteredAudioId = undefined
|
|
91
|
+
closed = false
|
|
92
|
+
#waiting = false
|
|
93
|
+
/** @type {Map<bigint, string>} */
|
|
94
|
+
#models = new Map()
|
|
95
|
+
|
|
96
|
+
/** @param {Options} options */
|
|
97
|
+
constructor (options) { this.options = options }
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @param {bigint} id
|
|
101
|
+
* @param {number} now
|
|
102
|
+
*/
|
|
103
|
+
turn (id, now) {
|
|
104
|
+
if (this.closed) return
|
|
105
|
+
const known = this.turns.get(id)
|
|
106
|
+
if (known) return known
|
|
107
|
+
// The server uses the interruption ID for the replacement response. Only lower
|
|
108
|
+
// unknown IDs are stale; treating the boundary as stale steals the next input.
|
|
109
|
+
if (id < this.lastInterrupt || id <= this.lastFinalized) return
|
|
110
|
+
while (this.turns.size >= 2) this.finish(/** @type {Turn} */ (this.turns.values().next().value))
|
|
111
|
+
for (const previous of this.turns.values()) previous.retired = true
|
|
112
|
+
const input = this.pending
|
|
113
|
+
this.pending = new AudioBuffer()
|
|
114
|
+
this.pending.activity = input.activity.continueAt(input.duration(this.inputRate))
|
|
115
|
+
/** @type {Turn} */
|
|
116
|
+
const turn = {
|
|
117
|
+
id,
|
|
118
|
+
input,
|
|
119
|
+
output: new AudioBuffer(),
|
|
120
|
+
userText: this.pendingText,
|
|
121
|
+
argumentsSize: 0,
|
|
122
|
+
argumentSizes: new Map(),
|
|
123
|
+
responses: new Map(),
|
|
124
|
+
completed: new Set(),
|
|
125
|
+
calls: new Map(),
|
|
126
|
+
results: new Map(),
|
|
127
|
+
tools: new Set(),
|
|
128
|
+
start: Math.min(input.start ?? now, this.#pendingTextStart ?? now),
|
|
129
|
+
responseTime: now,
|
|
130
|
+
toolEnd: now,
|
|
131
|
+
retired: false,
|
|
132
|
+
interrupted: false,
|
|
133
|
+
boundaryResponse: id === this.lastInterrupt,
|
|
134
|
+
model: this.#models.get(id),
|
|
135
|
+
failed: false,
|
|
136
|
+
scope: {},
|
|
137
|
+
metadata: {
|
|
138
|
+
agent_id: this.options.agentId,
|
|
139
|
+
ttfa_eligible: false,
|
|
140
|
+
audio_timing_source: 'sdk_transport',
|
|
141
|
+
audio_playback: 'estimated',
|
|
142
|
+
event_id: String(id),
|
|
143
|
+
},
|
|
144
|
+
}
|
|
145
|
+
if (id === this.filteredAudioId) {
|
|
146
|
+
turn.output.present = true
|
|
147
|
+
turn.output.omit()
|
|
148
|
+
turn.metadata.output_audio_omitted_reason = 'sdk_interruption_filter'
|
|
149
|
+
}
|
|
150
|
+
this.pendingText = ''
|
|
151
|
+
this.#pendingTextStart = undefined
|
|
152
|
+
this.#models.delete(id)
|
|
153
|
+
this.turns.set(id, turn)
|
|
154
|
+
this.options.begin(turn)
|
|
155
|
+
return turn
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @param {string} raw
|
|
160
|
+
* @param {number} now
|
|
161
|
+
*/
|
|
162
|
+
sendRaw (raw, now) {
|
|
163
|
+
// The SDK emits this single-field envelope for every microphone frame. Other JSON shapes,
|
|
164
|
+
// additional fields, and escaped values still use the normal parser.
|
|
165
|
+
if (raw.startsWith(AUDIO_PREFIX) && raw.endsWith('"}') &&
|
|
166
|
+
raw.indexOf('"', AUDIO_PREFIX.length) === raw.length - 2 &&
|
|
167
|
+
!raw.includes('\\', AUDIO_PREFIX.length)) {
|
|
168
|
+
this.send({ user_audio_chunk: raw.slice(AUDIO_PREFIX.length, -2) }, now)
|
|
169
|
+
} else {
|
|
170
|
+
this.send(JSON.parse(raw), now)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @param {object} event
|
|
176
|
+
* @param {number} now
|
|
177
|
+
*/
|
|
178
|
+
send (event, now) {
|
|
179
|
+
if (this.closed || !event || typeof event !== 'object') return
|
|
180
|
+
if (typeof event.user_audio_chunk === 'string') {
|
|
181
|
+
const encoded = event.user_audio_chunk
|
|
182
|
+
if (this.inputRate) this.pending.append(encoded, now, this.inputRate, true, this.options.retain())
|
|
183
|
+
else if (this.negotiated) {
|
|
184
|
+
this.pending.present = true
|
|
185
|
+
this.pending.omit()
|
|
186
|
+
} else if (!this.earlyOverflow) {
|
|
187
|
+
this.earlySize += encoded.length
|
|
188
|
+
if (this.early.length < 256 && this.earlySize <= RAW_LIMIT * 4 / 3 && this.options.retain()) {
|
|
189
|
+
this.early.push([encoded, now])
|
|
190
|
+
} else {
|
|
191
|
+
this.early = []
|
|
192
|
+
this.earlyOverflow = true
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
} else if (event.type === 'user_message') {
|
|
196
|
+
this.#pendingTextStart ??= now
|
|
197
|
+
this.pendingText = textOf(this.pendingText ? `${this.pendingText}\n${textOf(event.text)}` : textOf(event.text))
|
|
198
|
+
} else if (event.type === 'client_tool_result') {
|
|
199
|
+
const id = toolIdOf(event.tool_call_id)
|
|
200
|
+
if (id === undefined) return
|
|
201
|
+
for (const turn of this.turns.values()) {
|
|
202
|
+
if (turn.calls.has(id)) this.toolResult(turn, id, event.result)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @param {object} event
|
|
209
|
+
* @param {number} now
|
|
210
|
+
* @param {boolean} [audioAccepted] Whether the SDK delivered this audio to its output interface.
|
|
211
|
+
*/
|
|
212
|
+
receive (event, now, audioAccepted = true) {
|
|
213
|
+
if (this.closed || !event || typeof event !== 'object') return
|
|
214
|
+
const kind = event.type
|
|
215
|
+
if (kind === 'conversation_initiation_metadata') {
|
|
216
|
+
const data = event.conversation_initiation_metadata_event
|
|
217
|
+
if (!data || typeof data !== 'object') return
|
|
218
|
+
this.sessionId = textOf(data.conversation_id) || this.sessionId
|
|
219
|
+
this.negotiated = true
|
|
220
|
+
this.inputRate = rateOf(data.user_input_audio_format)
|
|
221
|
+
this.outputRate = rateOf(data.agent_output_audio_format)
|
|
222
|
+
if (this.earlyOverflow || (!this.inputRate && this.early.length)) {
|
|
223
|
+
this.pending.present = true
|
|
224
|
+
this.pending.omit()
|
|
225
|
+
}
|
|
226
|
+
for (const [encoded, sent] of this.early) {
|
|
227
|
+
this.pending.append(encoded, sent, this.inputRate, true, this.options.retain())
|
|
228
|
+
}
|
|
229
|
+
this.early = []
|
|
230
|
+
this.earlySize = 0
|
|
231
|
+
this.earlyOverflow = false
|
|
232
|
+
return
|
|
233
|
+
}
|
|
234
|
+
if (kind === 'queue_status') {
|
|
235
|
+
const status = event.queue_status_event?.status
|
|
236
|
+
if (status === 'admitted') this.#waiting = false
|
|
237
|
+
else if (status === 'waiting' || status === 'timed_out') this.#waiting = true
|
|
238
|
+
return
|
|
239
|
+
}
|
|
240
|
+
if (kind === 'audio' && this.#waiting) return
|
|
241
|
+
if (kind === 'interruption') {
|
|
242
|
+
const id = eventId(event.interruption_event?.event_id)
|
|
243
|
+
if (id === undefined) return
|
|
244
|
+
if (id > this.lastInterrupt) {
|
|
245
|
+
this.lastInterrupt = id
|
|
246
|
+
this.filteredAudioId = undefined
|
|
247
|
+
}
|
|
248
|
+
for (const turn of this.turns.values()) {
|
|
249
|
+
if (turn.id <= id && (!this.responseFinished(turn, now) || (turn.playbackEnd ?? 0) > now)) {
|
|
250
|
+
turn.interrupted = true
|
|
251
|
+
this.trimOutput(turn, now)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
if (kind === 'vad_score') {
|
|
257
|
+
if (this.inputRate && this.options.retain()) {
|
|
258
|
+
this.pending.activity.observe(event.vad_score_event?.vad_score, this.pending.duration(this.inputRate), now)
|
|
259
|
+
}
|
|
260
|
+
return
|
|
261
|
+
}
|
|
262
|
+
if (!Object.hasOwn(EVENT_FIELDS, kind)) return
|
|
263
|
+
const data = event[EVENT_FIELDS[kind]]
|
|
264
|
+
if (!data || typeof data !== 'object') return
|
|
265
|
+
const id = eventId(data.event_id)
|
|
266
|
+
if (id === undefined) return
|
|
267
|
+
if (kind === 'audio' && !audioAccepted) {
|
|
268
|
+
if (id === this.lastInterrupt) {
|
|
269
|
+
this.filteredAudioId = id
|
|
270
|
+
const rejected = this.turns.get(id)
|
|
271
|
+
if (rejected?.boundaryResponse) {
|
|
272
|
+
rejected.output.present = true
|
|
273
|
+
rejected.output.omit()
|
|
274
|
+
rejected.metadata.output_audio_omitted_reason = 'sdk_interruption_filter'
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return
|
|
278
|
+
}
|
|
279
|
+
if (kind === 'audio' && id < this.lastInterrupt) return
|
|
280
|
+
if (kind === 'context_usage') {
|
|
281
|
+
const model = textOf(data.model)
|
|
282
|
+
if (!model) return
|
|
283
|
+
const known = this.turns.get(id)
|
|
284
|
+
if (known) known.model = model
|
|
285
|
+
else if (id >= this.lastInterrupt && id > this.lastFinalized) {
|
|
286
|
+
this.#models.delete(id)
|
|
287
|
+
this.#models.set(id, model)
|
|
288
|
+
while (this.#models.size > 2) this.#models.delete(/** @type {bigint} */ (this.#models.keys().next().value))
|
|
289
|
+
}
|
|
290
|
+
return
|
|
291
|
+
}
|
|
292
|
+
const lookupOnly = kind === 'agent_tool_response_full_payload'
|
|
293
|
+
const turn = lookupOnly ? this.turns.get(id) : this.turn(id, now)
|
|
294
|
+
if (!turn) return
|
|
295
|
+
switch (kind) {
|
|
296
|
+
case 'user_transcript': turn.userText = textOf(data.user_transcript); break
|
|
297
|
+
case 'audio': {
|
|
298
|
+
const previousDuration = turn.output.duration(this.outputRate)
|
|
299
|
+
turn.output.append(data.audio_base_64, now, this.outputRate, false, this.options.retain())
|
|
300
|
+
const duration = turn.output.duration(this.outputRate) - previousDuration
|
|
301
|
+
if (duration > 0) turn.playbackEnd = Math.max(turn.playbackEnd ?? now, now) + duration
|
|
302
|
+
this.boundAudio(turn)
|
|
303
|
+
break
|
|
304
|
+
}
|
|
305
|
+
case 'client_tool_call': {
|
|
306
|
+
const id = toolIdOf(data.tool_call_id)
|
|
307
|
+
if (id === undefined || (!turn.calls.has(id) && turn.calls.size >= 64)) {
|
|
308
|
+
turn.metadata.tool_calls_omitted = true
|
|
309
|
+
break
|
|
310
|
+
}
|
|
311
|
+
const argumentsJson = JSON.stringify(data.parameters || {})
|
|
312
|
+
const used = turn.argumentsSize - (turn.argumentSizes.get(id) || 0)
|
|
313
|
+
const argumentsFit = argumentsJson.length + used <= 100_000
|
|
314
|
+
if (!argumentsFit) turn.metadata.tool_arguments_truncated = true
|
|
315
|
+
const size = argumentsFit ? argumentsJson.length : 2 // omitted arguments retain the empty object
|
|
316
|
+
turn.argumentSizes.set(id, size)
|
|
317
|
+
turn.argumentsSize = used + size
|
|
318
|
+
// The 64-call limit also bounds retained names to 65,536 characters per turn.
|
|
319
|
+
const name = textOf(data.tool_name, MAX_TOOL_NAME_CHARS)
|
|
320
|
+
if (typeof data.tool_name === 'string' && data.tool_name.length > MAX_TOOL_NAME_CHARS) {
|
|
321
|
+
turn.metadata.tool_names_truncated = true
|
|
322
|
+
}
|
|
323
|
+
turn.calls.set(id, {
|
|
324
|
+
name,
|
|
325
|
+
arguments: argumentsFit ? data.parameters || {} : {},
|
|
326
|
+
toolId: id,
|
|
327
|
+
type: 'tool',
|
|
328
|
+
})
|
|
329
|
+
break
|
|
330
|
+
}
|
|
331
|
+
case 'agent_tool_response_full_payload':
|
|
332
|
+
if (toolIdOf(data.tool_call_id) !== undefined && turn.calls.has(data.tool_call_id)) {
|
|
333
|
+
this.toolResult(turn, data.tool_call_id, data.full_tool_result)
|
|
334
|
+
}
|
|
335
|
+
break
|
|
336
|
+
default: this.response(turn, kind, data, now)
|
|
337
|
+
}
|
|
338
|
+
return turn
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* @param {Turn} turn
|
|
343
|
+
* @param {string} kind
|
|
344
|
+
* @param {object} data
|
|
345
|
+
* @param {number} now
|
|
346
|
+
*/
|
|
347
|
+
response (turn, kind, data, now) {
|
|
348
|
+
const key = textOf(data.response_id)
|
|
349
|
+
if (!turn.responses.has(key) && turn.responses.size >= 64) return
|
|
350
|
+
if (kind === 'agent_chat_response_part') {
|
|
351
|
+
if (turn.completed.has(key)) return
|
|
352
|
+
const prefix = data.type === 'start' ? '' : (turn.responses.get(key) || '')
|
|
353
|
+
turn.responses.set(key, textOf(prefix + textOf(data.text)))
|
|
354
|
+
if (data.type === 'stop') turn.completed.add(key)
|
|
355
|
+
} else {
|
|
356
|
+
const field = kind === 'agent_response_correction' ? 'corrected_agent_response' : 'agent_response'
|
|
357
|
+
turn.responses.set(key, textOf(data[field]))
|
|
358
|
+
turn.completed.add(key)
|
|
359
|
+
}
|
|
360
|
+
turn.responseTime = now
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* @param {Turn} turn
|
|
365
|
+
* @param {string} id
|
|
366
|
+
* @param {unknown} result
|
|
367
|
+
*/
|
|
368
|
+
toolResult (turn, id, result) {
|
|
369
|
+
if (turn.closed || toolIdOf(id) === undefined) return ''
|
|
370
|
+
let remaining = 100_000
|
|
371
|
+
for (const [key, item] of turn.results) if (key !== id) remaining -= item.result.length
|
|
372
|
+
let text = typeof result === 'string' ? result : JSON.stringify(result) ?? ''
|
|
373
|
+
if (text.length > remaining) {
|
|
374
|
+
text = text.slice(0, remaining)
|
|
375
|
+
turn.metadata.tool_results_truncated = true
|
|
376
|
+
}
|
|
377
|
+
turn.results.set(id, { toolId: id, result: text, type: 'tool_result' })
|
|
378
|
+
return text
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Completion remains estimated: final text plus the observed playback queue, or retirement by a
|
|
383
|
+
* newer response. A text event alone cannot prove that audio delivery has finished.
|
|
384
|
+
* @param {Turn} turn
|
|
385
|
+
* @param {number} now
|
|
386
|
+
*/
|
|
387
|
+
responseFinished (turn, now) {
|
|
388
|
+
return turn.retired || (turn.responses.size > 0 && turn.completed.size === turn.responses.size &&
|
|
389
|
+
turn.tools.size === 0 && turn.playbackEnd !== undefined && now >= turn.playbackEnd)
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* @param {Turn} turn
|
|
394
|
+
* @param {number} now
|
|
395
|
+
*/
|
|
396
|
+
trimOutput (turn, now) {
|
|
397
|
+
turn.output.trim(now, this.outputRate, turn.playbackEnd)
|
|
398
|
+
// Discarded queued samples must not be subtracted again by another interruption or close.
|
|
399
|
+
if (turn.playbackEnd !== undefined) turn.playbackEnd = Math.min(turn.playbackEnd, now)
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** @param {Turn} turn */
|
|
403
|
+
boundAudio (turn) { if (turn.input.size + turn.output.size > RAW_LIMIT) turn.output.omit() }
|
|
404
|
+
|
|
405
|
+
/** @param {Turn} turn */
|
|
406
|
+
finish (turn) {
|
|
407
|
+
if (turn.closed) return
|
|
408
|
+
this.turns.delete(turn.id)
|
|
409
|
+
turn.metadata.interrupted = turn.interrupted
|
|
410
|
+
if (turn.model) turn.metadata.configured_llm = turn.model
|
|
411
|
+
if (turn.input.overflow || turn.output.overflow) turn.metadata.audio_omitted = true
|
|
412
|
+
this.options.finish(turn)
|
|
413
|
+
turn.closed = true
|
|
414
|
+
turn.input.chunks = []
|
|
415
|
+
turn.output.chunks = []
|
|
416
|
+
if (turn.id > this.lastFinalized) this.lastFinalized = turn.id
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* @param {number} now
|
|
421
|
+
* @param {boolean} failed
|
|
422
|
+
*/
|
|
423
|
+
close (now, failed) {
|
|
424
|
+
if (this.closed) return
|
|
425
|
+
this.closed = true
|
|
426
|
+
const last = [...this.turns.values()].at(-1)
|
|
427
|
+
if (last) {
|
|
428
|
+
last.input.extend(this.pending, this.inputRate)
|
|
429
|
+
this.boundAudio(last)
|
|
430
|
+
}
|
|
431
|
+
this.pending = new AudioBuffer()
|
|
432
|
+
this.pendingText = ''
|
|
433
|
+
this.#pendingTextStart = undefined
|
|
434
|
+
this.early = []
|
|
435
|
+
this.#models.clear()
|
|
436
|
+
for (const turn of this.turns.values()) {
|
|
437
|
+
if (failed && !this.responseFinished(turn, now) && !turn.interrupted) turn.failed = true
|
|
438
|
+
this.trimOutput(turn, now)
|
|
439
|
+
this.finish(turn)
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
module.exports = Session
|
|
@@ -11,10 +11,16 @@ const { addHook, getHooks } = require('./helpers/instrument')
|
|
|
11
11
|
* @param {string} name
|
|
12
12
|
*/
|
|
13
13
|
function addRewriterHooks (name) {
|
|
14
|
-
const
|
|
14
|
+
const hooks = new Map()
|
|
15
15
|
for (const hook of getHooks(name).values()) {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const existing = hooks.get(hook.file)
|
|
17
|
+
if (existing) {
|
|
18
|
+
existing.versions.push(...hook.versions)
|
|
19
|
+
} else {
|
|
20
|
+
hooks.set(hook.file, hook)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
for (const hook of hooks.values()) {
|
|
18
24
|
addHook(hook, exports => exports)
|
|
19
25
|
}
|
|
20
26
|
}
|
|
@@ -27,20 +33,23 @@ addRewriterHooks('graphql-jit')
|
|
|
27
33
|
// (read lazily inside each callback so agent.load() between mocha suites can
|
|
28
34
|
// rebind globalThis[dd-trace] without us stashing a stale reference).
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
// Capture ESM namespace exports through module hooks: __module_export__ only matches CommonJS exports.
|
|
37
|
+
for (const extension of ['js', 'mjs']) {
|
|
38
|
+
addHook({ name: 'graphql', file: `language/printer.${extension}`, versions: ['>=0.10'] }, printer => {
|
|
39
|
+
const ddGlobal = globalThis[Symbol.for('dd-trace')]
|
|
40
|
+
if (ddGlobal) ddGlobal.graphql_printer = printer
|
|
41
|
+
return printer
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
addHook({ name: 'graphql', file: `language/visitor.${extension}`, versions: ['>=0.10'] }, visitor => {
|
|
45
|
+
const ddGlobal = globalThis[Symbol.for('dd-trace')]
|
|
46
|
+
if (ddGlobal) ddGlobal.graphql_visitor = visitor
|
|
47
|
+
return visitor
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
addHook({ name: 'graphql', file: `utilities/index.${extension}`, versions: ['>=0.10'] }, utilities => {
|
|
51
|
+
const ddGlobal = globalThis[Symbol.for('dd-trace')]
|
|
52
|
+
if (ddGlobal) ddGlobal.graphql_utilities = utilities
|
|
53
|
+
return utilities
|
|
54
|
+
})
|
|
55
|
+
}
|
|
@@ -23,6 +23,16 @@ const isValid = (server, args) => {
|
|
|
23
23
|
(server.type === 'unary' ? typeof args[1] === 'function' : isEmitter(args[0])))
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
// A call can end through several paths (cancellation, error, handler callback);
|
|
27
|
+
// only the first one may finish the span and set its status. Later terminal
|
|
28
|
+
// events must not publish errors or status updates either: the span can still
|
|
29
|
+
// be buffered by an unfinished child, so they would overwrite the final tags.
|
|
30
|
+
function finish (ctx) {
|
|
31
|
+
if (ctx.finished) return
|
|
32
|
+
ctx.finished = true
|
|
33
|
+
finishChannel.publish(ctx)
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
function wrapHandler (func, name) {
|
|
27
37
|
return function (call, callback) {
|
|
28
38
|
if (!isValid(this, arguments)) return func.apply(this, arguments)
|
|
@@ -37,7 +47,7 @@ function wrapHandler (func, name) {
|
|
|
37
47
|
try {
|
|
38
48
|
const onCancel = () => {
|
|
39
49
|
ctx.code = CANCELLED
|
|
40
|
-
|
|
50
|
+
finish(ctx)
|
|
41
51
|
}
|
|
42
52
|
|
|
43
53
|
// Finish the span if the call was cancelled.
|
|
@@ -96,12 +106,14 @@ function wrapSetupHandlers (setupHandlers) {
|
|
|
96
106
|
function createWrapEmit (call, ctx, onCancel) {
|
|
97
107
|
return function wrapEmit (emit) {
|
|
98
108
|
return function (event, arg1) {
|
|
109
|
+
if (ctx.finished) return emit.apply(this, arguments)
|
|
110
|
+
|
|
99
111
|
switch (event) {
|
|
100
112
|
case 'error':
|
|
101
113
|
ctx.error = arg1
|
|
102
114
|
errorChannel.publish(ctx)
|
|
103
115
|
ctx.code = arg1.code
|
|
104
|
-
|
|
116
|
+
finish(ctx)
|
|
105
117
|
call.removeListener('cancelled', onCancel)
|
|
106
118
|
break
|
|
107
119
|
// Streams are always cancelled before `finish` since 1.10.0 so we have
|
|
@@ -111,7 +123,7 @@ function createWrapEmit (call, ctx, onCancel) {
|
|
|
111
123
|
updateChannel.publish(call.status)
|
|
112
124
|
}
|
|
113
125
|
if (!call.status || call.status.code === 0) {
|
|
114
|
-
|
|
126
|
+
finish(ctx)
|
|
115
127
|
}
|
|
116
128
|
call.removeListener('cancelled', onCancel)
|
|
117
129
|
break
|
|
@@ -132,6 +144,9 @@ function wrapStream (call, ctx, onCancel) {
|
|
|
132
144
|
|
|
133
145
|
function wrapCallback (callback = () => {}, call, ctx, onCancel) {
|
|
134
146
|
return shimmer.wrapFunction(callback, callback => function (err, value, trailer, flags) {
|
|
147
|
+
if (ctx.finished) {
|
|
148
|
+
return asyncStartChannel.runStores(ctx, () => callback.apply(this, arguments))
|
|
149
|
+
}
|
|
135
150
|
if (err) {
|
|
136
151
|
ctx.error = err
|
|
137
152
|
errorChannel.publish(ctx)
|
|
@@ -140,7 +155,7 @@ function wrapCallback (callback = () => {}, call, ctx, onCancel) {
|
|
|
140
155
|
ctx.trailer = trailer
|
|
141
156
|
}
|
|
142
157
|
|
|
143
|
-
|
|
158
|
+
finish(ctx)
|
|
144
159
|
|
|
145
160
|
call.removeListener('cancelled', onCancel)
|
|
146
161
|
|
|
@@ -153,8 +168,10 @@ function wrapCallback (callback = () => {}, call, ctx, onCancel) {
|
|
|
153
168
|
|
|
154
169
|
function wrapSendStatus (sendStatus, ctx) {
|
|
155
170
|
return function (status) {
|
|
156
|
-
ctx.
|
|
157
|
-
|
|
171
|
+
if (!ctx.finished) {
|
|
172
|
+
ctx.status = status
|
|
173
|
+
updateChannel.publish(ctx)
|
|
174
|
+
}
|
|
158
175
|
|
|
159
176
|
return sendStatus.apply(this, arguments)
|
|
160
177
|
}
|