dd-trace 6.24.0 → 6.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/ci/cypress/support.js +2 -1
- package/ci/init.js +2 -22
- package/ci/vitest-no-worker-init-node-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-runner-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-setup.mjs +729 -724
- package/ci/vitest-no-worker-init-v5-setup.mjs +2 -1
- package/ext/exporters.js +0 -1
- package/index.d.ts +105 -5
- package/initialize.mjs +5 -2
- package/package.json +41 -36
- package/packages/datadog-esbuild/index.js +16 -70
- package/packages/datadog-esbuild/src/log.js +2 -29
- package/packages/datadog-instrumentations/src/ai.js +6 -1
- package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
- package/packages/datadog-instrumentations/src/cucumber.js +5 -2
- package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
- 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 +20 -17
- package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +582 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +576 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
- package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
- package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
- package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
- package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +8 -0
- 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.js +0 -36
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-client.js +30 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-server.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +61 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +80 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +23 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
- 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/microgateway-core.js +1 -2
- package/packages/datadog-instrumentations/src/modelcontextprotocol-client.js +21 -0
- package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +7 -1
- package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +41 -0
- package/packages/datadog-instrumentations/src/next.js +203 -26
- 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/otel-sdk-trace.js +11 -9
- package/packages/datadog-instrumentations/src/router.js +35 -12
- package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
- 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/arn.js +41 -0
- package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
- package/packages/datadog-plugin-aws-lambda/src/trigger.js +339 -0
- package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +7 -0
- package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +32 -10
- package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +10 -1
- package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -0
- package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +3 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +50 -13
- package/packages/datadog-plugin-cypress/src/support.mjs +1353 -0
- package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
- package/packages/datadog-plugin-express/src/code_origin.js +2 -2
- package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +20 -7
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +21 -52
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +11 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
- package/packages/datadog-plugin-google-cloud-pubsub/src/resource-names.js +24 -0
- package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
- package/packages/datadog-plugin-http/src/client.js +34 -10
- package/packages/datadog-plugin-http2/src/client.js +40 -14
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +28 -2
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +1 -0
- package/packages/datadog-plugin-mongodb-core/src/query.js +17 -1
- package/packages/datadog-plugin-next/src/index.js +112 -14
- package/packages/datadog-plugin-postgres/src/index.js +118 -41
- package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
- package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +18 -8
- package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +49 -13
- package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +34 -9
- 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-undici/src/index.js +22 -7
- package/packages/datadog-plugin-vitest/src/index.js +3 -2
- package/packages/datadog-plugin-ws/src/close.js +3 -5
- package/packages/datadog-plugin-ws/src/producer.js +1 -4
- package/packages/datadog-plugin-ws/src/receiver.js +3 -5
- package/packages/datadog-plugin-ws/src/server.js +44 -13
- package/packages/datadog-turbopack/index.js +4 -28
- package/packages/datadog-turbopack/src/loader.js +14 -452
- package/packages/datadog-vite/index.js +537 -0
- package/packages/datadog-vite/src/log.js +5 -0
- package/packages/datadog-webpack/index.js +3 -55
- package/packages/datadog-webpack/src/log.js +2 -29
- package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
- package/packages/dd-trace/src/aiguard/index.js +1 -1
- package/packages/dd-trace/src/aiguard/integrations/index.js +6 -5
- package/packages/dd-trace/src/aiguard/sdk.js +8 -2
- package/packages/dd-trace/src/aiguard/tags.js +2 -0
- package/packages/dd-trace/src/appsec/blocking/index.js +21 -1
- package/packages/dd-trace/src/appsec/channels.js +7 -0
- package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
- package/packages/dd-trace/src/appsec/graphql.js +89 -7
- package/packages/dd-trace/src/appsec/handlers/auth.js +1 -3
- package/packages/dd-trace/src/appsec/handlers/http-request.js +60 -65
- package/packages/dd-trace/src/appsec/handlers/http-response.js +61 -7
- package/packages/dd-trace/src/appsec/handlers/payments.js +23 -27
- package/packages/dd-trace/src/appsec/index.js +6 -0
- package/packages/dd-trace/src/appsec/lambda.js +17 -17
- package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -4
- package/packages/dd-trace/src/appsec/rasp/index.js +8 -1
- package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -2
- package/packages/dd-trace/src/appsec/rasp/sql_injection.js +7 -17
- package/packages/dd-trace/src/appsec/rasp/ssrf.js +80 -16
- package/packages/dd-trace/src/appsec/rasp/utils.js +33 -3
- package/packages/dd-trace/src/appsec/recommended.json +1358 -94
- package/packages/dd-trace/src/appsec/reporter.js +9 -0
- package/packages/dd-trace/src/appsec/sdk/set_user.js +3 -3
- package/packages/dd-trace/src/appsec/sdk/track_event.js +4 -4
- package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
- package/packages/dd-trace/src/appsec/user_tracking.js +6 -8
- package/packages/dd-trace/src/appsec/waf/index.js +65 -6
- package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -38
- package/packages/dd-trace/src/appsec/waf/waf_manager.js +18 -2
- 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 +15 -2
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
- 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 +1 -2
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
- package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
- 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 +5 -0
- package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -4
- package/packages/dd-trace/src/config/index.js +63 -31
- package/packages/dd-trace/src/config/parsers.js +44 -0
- package/packages/dd-trace/src/config/remote-config-layers.js +38 -0
- package/packages/dd-trace/src/config/remote_config.js +2 -1
- package/packages/dd-trace/src/config/supported-configurations.json +172 -10
- package/packages/dd-trace/src/constants.js +1 -0
- package/packages/dd-trace/src/datastreams/fnv.js +27 -0
- package/packages/dd-trace/src/datastreams/pathway.js +113 -28
- package/packages/dd-trace/src/datastreams/processor.js +5 -4
- package/packages/dd-trace/src/debugger/config.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/request-options.js +7 -9
- package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
- package/packages/dd-trace/src/debugger/devtools_client/tags.js +1 -1
- package/packages/dd-trace/src/debugger/index.js +2 -2
- package/packages/dd-trace/src/debugger/inspect-segment.js +3 -2
- package/packages/dd-trace/src/debugger/pause-duration-histogram.js +6 -2
- package/packages/dd-trace/src/debugger/probe_sampler.js +39 -17
- package/packages/dd-trace/src/debugger/unsupported-runtime.js +2 -0
- package/packages/dd-trace/src/exporter.js +0 -11
- package/packages/dd-trace/src/exporters/common/request.js +81 -48
- 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/git_metadata.js +2 -1
- package/packages/dd-trace/src/id.js +1 -1
- package/packages/dd-trace/src/index.js +6 -3
- package/packages/dd-trace/src/lambda/facade.js +75 -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 +2 -0
- package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
- package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +54 -3
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +81 -1
- package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
- package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
- package/packages/dd-trace/src/llmobs/sdk.js +19 -0
- package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
- package/packages/dd-trace/src/llmobs/tagger.js +22 -0
- package/packages/dd-trace/src/log/channels.js +4 -0
- package/packages/dd-trace/src/log/writer.js +6 -1
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +7 -0
- package/packages/dd-trace/src/openfeature/configuration_source.js +55 -27
- package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
- package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
- 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/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/opentracing/propagation/tracestate.js +77 -23
- package/packages/dd-trace/src/opentracing/tracer.js +24 -0
- package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
- package/packages/dd-trace/src/plugin_manager.js +34 -7
- package/packages/dd-trace/src/plugins/ci_plugin.js +143 -17
- package/packages/dd-trace/src/plugins/index.js +8 -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 +52 -1
- package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
- package/packages/dd-trace/src/plugins/util/git.js +263 -82
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +80 -56
- 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 +92 -40
- package/packages/dd-trace/src/plugins/util/url.js +18 -7
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +6 -6
- package/packages/dd-trace/src/plugins/util/web.js +65 -10
- package/packages/dd-trace/src/process-tags/index.js +1 -1
- package/packages/dd-trace/src/profiler.js +74 -12
- package/packages/dd-trace/src/profiling/profiler.js +30 -2
- package/packages/dd-trace/src/profiling/profilers/space.js +3 -1
- package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
- package/packages/dd-trace/src/profiling/remote-config.js +354 -0
- package/packages/dd-trace/src/profiling/runtime-capabilities.js +11 -0
- package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
- package/packages/dd-trace/src/propagation-hash/index.js +7 -0
- package/packages/dd-trace/src/proxy.js +46 -54
- package/packages/dd-trace/src/span_processor.js +20 -0
- package/packages/dd-trace/src/startup-log.js +8 -6
- package/packages/dd-trace/src/telemetry/metrics.js +2 -1
- package/packages/dd-trace/src/tracer.js +0 -2
- package/packages/dd-trace/src/web-tags-cache.js +8 -9
- package/register.js +2 -1
- package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
- package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
- 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/rules-based/LICENSE +3 -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 +220 -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/vite.d.ts +7 -0
- package/vite.js +3 -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 -18
- 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 -649
- 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/datadog-esbuild/src/utils.js +0 -318
- package/packages/datadog-plugin-cypress/src/support.js +0 -1348
- 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
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const dc = require('dc-polyfill')
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
HANDLER_STREAMING,
|
|
7
|
+
STREAM_RESPONSE,
|
|
8
|
+
promisifiedHandler,
|
|
9
|
+
copyHandlerMetadata,
|
|
10
|
+
getDataProperty,
|
|
11
|
+
} = require('./helpers/lambda-handler')
|
|
12
|
+
|
|
13
|
+
// Read through the process-global registry so two dd-trace copies (layer + bundled) resolve the
|
|
14
|
+
// same marker. The value is the wrapper itself, so a second wrap of the same handler returns the
|
|
15
|
+
// instrumented function rather than the raw one.
|
|
16
|
+
const WRAPPED = Symbol.for('dd-trace.lambda.wrapped')
|
|
17
|
+
const invocationChannel = dc.tracingChannel('datadog:aws-lambda:invoke')
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Wraps one customer handler with the shared Lambda invocation channel.
|
|
21
|
+
*
|
|
22
|
+
* @param {Function} handler Customer Lambda handler.
|
|
23
|
+
* @param {Record<string, unknown>} [config] Per-handler configuration overrides.
|
|
24
|
+
* @param {Function} [monitor] Monitors the shim adapter for impending timeouts.
|
|
25
|
+
* @returns {Function} Wrapped handler, or the existing wrapper when already marked.
|
|
26
|
+
*/
|
|
27
|
+
function wrapHandler (handler, config, monitor) {
|
|
28
|
+
if (typeof handler !== 'function') {
|
|
29
|
+
throw new TypeError('AWS Lambda handler must be a function')
|
|
30
|
+
}
|
|
31
|
+
const existing = getWrappedHandler(handler)
|
|
32
|
+
if (existing !== undefined && config?.forceWrap !== true) return existing
|
|
33
|
+
|
|
34
|
+
const isResponseStream = getDataProperty(handler, HANDLER_STREAMING) === STREAM_RESPONSE
|
|
35
|
+
const completion = promisifiedHandler(handler)
|
|
36
|
+
const invoke = monitor ? monitor(completion, true) : completion
|
|
37
|
+
|
|
38
|
+
function wrappedHandler (...args) {
|
|
39
|
+
const invocationContext = {
|
|
40
|
+
config,
|
|
41
|
+
context: args[isResponseStream ? 2 : 1],
|
|
42
|
+
event: args[0],
|
|
43
|
+
isResponseStream,
|
|
44
|
+
responseStream: isResponseStream ? args[1] : undefined,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The shim awaits its startup listeners before calling the adapter. Preserve that boundary so
|
|
48
|
+
// legacy RIC captures native context completion methods before the adapter replaces them.
|
|
49
|
+
return invocationChannel.tracePromise(
|
|
50
|
+
() => Promise.resolve().then(() => Reflect.apply(invoke, this, args)),
|
|
51
|
+
invocationContext
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Frozen customer handlers cannot carry markers; share their identity through the tracer registry.
|
|
56
|
+
const ddGlobal = globalThis[Symbol.for('dd-trace')] ??= { beforeExitHandlers: new Set() }
|
|
57
|
+
const lambda = ddGlobal.lambda ??= {}
|
|
58
|
+
const wrappers = lambda.wrappers ??= new WeakMap()
|
|
59
|
+
wrappers.set(handler, wrappedHandler)
|
|
60
|
+
wrappers.set(wrappedHandler, wrappedHandler)
|
|
61
|
+
Object.defineProperty(wrappedHandler, WRAPPED, { value: wrappedHandler })
|
|
62
|
+
copyHandlerMetadata(handler, wrappedHandler)
|
|
63
|
+
|
|
64
|
+
return wrappedHandler
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Looks up the invocation wrapper, including markers from older tracer copies.
|
|
69
|
+
*
|
|
70
|
+
* Deliberately does not set datadog-lambda-js's `_ddWrapped` property: the released shim treats
|
|
71
|
+
* that property as "already fully instrumented" and returns early, which would suppress its
|
|
72
|
+
* extractors, inferred spans, enhanced metrics, log injection, and cold-start tracing. dd-trace
|
|
73
|
+
* may only claim that marker once it reproduces those behaviors (Phases 2-3).
|
|
74
|
+
*
|
|
75
|
+
* @param {Function} handler Handler whose invocation wrapper is needed.
|
|
76
|
+
* @returns {Function|undefined} Existing invocation wrapper.
|
|
77
|
+
*/
|
|
78
|
+
function getWrappedHandler (handler) {
|
|
79
|
+
const wrappers = globalThis[Symbol.for('dd-trace')]?.lambda?.wrappers
|
|
80
|
+
return wrappers?.get(handler) || getDataProperty(handler, WRAPPED)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = {
|
|
84
|
+
WRAPPED,
|
|
85
|
+
invocationChannel,
|
|
86
|
+
getWrappedHandler,
|
|
87
|
+
wrapHandler,
|
|
88
|
+
}
|
|
@@ -584,9 +584,12 @@ function isNewTest (testSuite, testName) {
|
|
|
584
584
|
/** @param {{ tags?: Array<{ name: string }> }} pickle */
|
|
585
585
|
function getScenarioAnnotations (pickle) {
|
|
586
586
|
const tags = pickle.tags || []
|
|
587
|
+
// Preserve the colon spellings accepted by earlier tracer releases.
|
|
587
588
|
return {
|
|
588
|
-
mustFail: tags.some(tag => tag.name === '@
|
|
589
|
-
|
|
589
|
+
mustFail: tags.some(tag => tag.name === '@datadog_prevent_failure_suppression' ||
|
|
590
|
+
tag.name === '@datadog:prevent_failure_suppression'),
|
|
591
|
+
noAutoRetry: tags.some(tag => tag.name === '@datadog_no_auto_retry' ||
|
|
592
|
+
tag.name === '@datadog:no_auto_retry'),
|
|
590
593
|
}
|
|
591
594
|
}
|
|
592
595
|
|
|
@@ -301,14 +301,19 @@ function getRelativeImportPath (fromDirectory, importedFile) {
|
|
|
301
301
|
* @param {string} browserHooksSource Datadog browser-side support hooks
|
|
302
302
|
* @param {boolean} deferLifecycle whether manual support owns lifecycle registration
|
|
303
303
|
* @param {string} lifecycleOwnerSource browser lifecycle ownership detection
|
|
304
|
+
* @param {string} [localBrowserHooks] browser hooks module inside the project
|
|
304
305
|
* @returns {string[]} generated files
|
|
305
306
|
*/
|
|
306
307
|
function createSupportWrapper (
|
|
307
|
-
directory, originalSupportFile, browserHooksSource, deferLifecycle, lifecycleOwnerSource
|
|
308
|
+
directory, originalSupportFile, browserHooksSource, deferLifecycle, lifecycleOwnerSource, localBrowserHooks
|
|
308
309
|
) {
|
|
309
310
|
const suffix = `${process.pid}-${randomUUID()}`
|
|
310
|
-
|
|
311
|
-
const
|
|
311
|
+
// Stay on the project's TypeScript preprocessor instead of loading Babel for an injected .mjs entry.
|
|
312
|
+
const extension = /\.tsx?$/.test(originalSupportFile) ? path.extname(originalSupportFile) : '.mjs'
|
|
313
|
+
// These generated entries contain JavaScript; leave type checking to the user's support file.
|
|
314
|
+
const typeCheckDirective = extension === '.mjs' ? '' : '// @ts-nocheck\n'
|
|
315
|
+
const browserHooksFile = path.join(directory, `dd-cypress-support-hooks-${suffix}${extension}`)
|
|
316
|
+
const wrapperFile = path.join(directory, `dd-cypress-support-${suffix}${extension}`)
|
|
312
317
|
const wrapperImports = [
|
|
313
318
|
`import ${JSON.stringify(getRelativeImportPath(directory, browserHooksFile))}`,
|
|
314
319
|
]
|
|
@@ -319,7 +324,10 @@ function createSupportWrapper (
|
|
|
319
324
|
|
|
320
325
|
const generatedFiles = []
|
|
321
326
|
try {
|
|
322
|
-
const
|
|
327
|
+
const initializer = localBrowserHooks
|
|
328
|
+
? `import initializeBrowserSupport from ${JSON.stringify(getRelativeImportPath(directory, localBrowserHooks))}\n`
|
|
329
|
+
: `${browserHooksSource}\n`
|
|
330
|
+
const guardedSource = `${initializer}const ddSupportRoot = Cypress.mocha.getRootSuite()
|
|
323
331
|
const ddSupportKey = Symbol.for('dd-trace.cypress.support-installed')
|
|
324
332
|
const ddHasLifecycle = (() => {
|
|
325
333
|
const module = { exports: {} }
|
|
@@ -334,11 +342,11 @@ for (const key of ['_beforeAll', '_beforeEach', '_afterAll', '_afterEach']) {
|
|
|
334
342
|
}
|
|
335
343
|
ddSupportRoot[Symbol.for('dd-trace.cypress.lifecycle-positions')] = positions
|
|
336
344
|
ddSupportRoot[Symbol.for('dd-trace.cypress.defer-lifecycle')] = ${deferLifecycle}
|
|
337
|
-
|
|
345
|
+
initializeBrowserSupport()
|
|
338
346
|
ddSupportRoot[ddSupportKey] = true
|
|
339
347
|
}
|
|
340
348
|
`
|
|
341
|
-
writeExclusiveFile(browserHooksFile, guardedSource)
|
|
349
|
+
writeExclusiveFile(browserHooksFile, `${typeCheckDirective}${guardedSource}`)
|
|
342
350
|
generatedFiles.push(browserHooksFile)
|
|
343
351
|
const finalize = `const root = Cypress.mocha.getRootSuite()
|
|
344
352
|
const install = root[Symbol.for('dd-trace.cypress.install-lifecycle')]
|
|
@@ -359,7 +367,7 @@ if (typeof install === 'function' && (!hasLifecycle || !hasLifecycle(root))) {
|
|
|
359
367
|
}
|
|
360
368
|
}
|
|
361
369
|
`
|
|
362
|
-
writeExclusiveFile(wrapperFile, `${wrapperImports.join('\n')}\n${finalize}`)
|
|
370
|
+
writeExclusiveFile(wrapperFile, `${typeCheckDirective}${wrapperImports.join('\n')}\n${finalize}`)
|
|
363
371
|
generatedFiles.push(wrapperFile)
|
|
364
372
|
} catch (error) {
|
|
365
373
|
for (const generatedFile of generatedFiles) removeGeneratedFile(generatedFile)
|
|
@@ -410,7 +418,7 @@ function injectSupportFile (config, manualLifecycle = false) {
|
|
|
410
418
|
let browserHooksPath
|
|
411
419
|
let lifecycleOwnerSource
|
|
412
420
|
try {
|
|
413
|
-
browserHooksPath = require.resolve('../../datadog-plugin-cypress/src/support')
|
|
421
|
+
browserHooksPath = require.resolve('../../datadog-plugin-cypress/src/support.mjs')
|
|
414
422
|
browserHooksSource = fs.readFileSync(browserHooksPath, 'utf8')
|
|
415
423
|
lifecycleOwnerSource = fs.readFileSync(require.resolve('../../datadog-plugin-cypress/src/lifecycle-owner'), 'utf8')
|
|
416
424
|
} catch (error) {
|
|
@@ -423,6 +431,9 @@ function injectSupportFile (config, manualLifecycle = false) {
|
|
|
423
431
|
}
|
|
424
432
|
|
|
425
433
|
const projectRoot = config.projectRoot
|
|
434
|
+
// Local imports share one bundled module with manual support. External action
|
|
435
|
+
// preloads still need a project-local copy for Vite's filesystem boundary.
|
|
436
|
+
const localBrowserHooks = projectRoot && isPathInside(projectRoot, browserHooksPath) ? browserHooksPath : undefined
|
|
426
437
|
const candidateDirectories = []
|
|
427
438
|
if (originalSupportFile) candidateDirectories.push(path.dirname(originalSupportFile))
|
|
428
439
|
if (projectRoot) candidateDirectories.push(projectRoot)
|
|
@@ -432,7 +443,7 @@ function injectSupportFile (config, manualLifecycle = false) {
|
|
|
432
443
|
if (projectRoot && !isPathInside(projectRoot, directory)) continue
|
|
433
444
|
try {
|
|
434
445
|
const generatedFiles = createSupportWrapper(
|
|
435
|
-
directory, originalSupportFile, browserHooksSource, !!deferLifecycle, lifecycleOwnerSource
|
|
446
|
+
directory, originalSupportFile, browserHooksSource, !!deferLifecycle, lifecycleOwnerSource, localBrowserHooks
|
|
436
447
|
)
|
|
437
448
|
config.supportFile = generatedFiles[1]
|
|
438
449
|
// Shared across SDK copies, but scoped to this exact generated support path.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// Silence is inferred only between recent provider observations. Unknown samples stay active.
|
|
4
|
+
class SpeechActivity {
|
|
5
|
+
#silence = []
|
|
6
|
+
/** @type {number | undefined} */
|
|
7
|
+
#lastOffset = undefined
|
|
8
|
+
/** @type {number | undefined} */
|
|
9
|
+
#lastReceived = undefined
|
|
10
|
+
#speaking = true
|
|
11
|
+
#overflow = false
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {number} start
|
|
15
|
+
* @param {number} end
|
|
16
|
+
*/
|
|
17
|
+
addSilence (start, end) {
|
|
18
|
+
start = Math.max(0, start)
|
|
19
|
+
if (end <= start || this.#overflow) return
|
|
20
|
+
const last = this.#silence.at(-1)
|
|
21
|
+
if (last && start <= last[1]) last[1] = Math.max(end, last[1])
|
|
22
|
+
else if (this.#silence.length < 128) this.#silence.push([start, end])
|
|
23
|
+
else {
|
|
24
|
+
this.#silence = []
|
|
25
|
+
this.#overflow = true
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {unknown} score
|
|
31
|
+
* @param {number} offset
|
|
32
|
+
* @param {number} now
|
|
33
|
+
*/
|
|
34
|
+
observe (score, offset, now) {
|
|
35
|
+
if (typeof score !== 'number' || !Number.isFinite(score) || score < 0 || score > 1) return
|
|
36
|
+
if (this.#lastOffset !== undefined && this.#lastReceived !== undefined) {
|
|
37
|
+
if (offset < this.#lastOffset || now < this.#lastReceived) return
|
|
38
|
+
if (!this.#speaking && now - this.#lastReceived <= 500) {
|
|
39
|
+
this.addSilence(this.#lastOffset, Math.min(offset, this.#lastOffset + 500))
|
|
40
|
+
}
|
|
41
|
+
if (offset - this.#lastOffset > 500 || now - this.#lastReceived > 500) this.#speaking = true
|
|
42
|
+
}
|
|
43
|
+
this.#lastOffset = offset
|
|
44
|
+
this.#lastReceived = now
|
|
45
|
+
if (score >= 0.5) this.#speaking = true
|
|
46
|
+
else if (score <= 0.35) this.#speaking = false
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @param {number} duration */
|
|
50
|
+
continueAt (duration) {
|
|
51
|
+
const next = new SpeechActivity()
|
|
52
|
+
if (this.#lastOffset !== undefined && this.#lastReceived !== undefined) {
|
|
53
|
+
next.#lastOffset = this.#lastOffset - duration
|
|
54
|
+
next.#lastReceived = this.#lastReceived
|
|
55
|
+
next.#speaking = this.#speaking
|
|
56
|
+
}
|
|
57
|
+
return next
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {number} duration
|
|
62
|
+
* @param {number | undefined} lastAudio
|
|
63
|
+
*/
|
|
64
|
+
extendSilence (duration, lastAudio) {
|
|
65
|
+
if (!this.#speaking && this.#lastOffset !== undefined && this.#lastReceived !== undefined &&
|
|
66
|
+
lastAudio !== undefined &&
|
|
67
|
+
lastAudio - this.#lastReceived <= 500) {
|
|
68
|
+
this.addSilence(this.#lastOffset, Math.min(duration, this.#lastOffset + 500))
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {SpeechActivity} other
|
|
74
|
+
* @param {number} duration
|
|
75
|
+
* @param {number | undefined} lastAudio
|
|
76
|
+
*/
|
|
77
|
+
extend (other, duration, lastAudio) {
|
|
78
|
+
this.extendSilence(duration, lastAudio)
|
|
79
|
+
for (const [start, end] of other.#silence) this.addSilence(start + duration, end + duration)
|
|
80
|
+
if (other.#lastOffset !== undefined) {
|
|
81
|
+
this.#lastOffset = other.#lastOffset + duration
|
|
82
|
+
this.#lastReceived = other.#lastReceived
|
|
83
|
+
this.#speaking = other.#speaking
|
|
84
|
+
}
|
|
85
|
+
this.#overflow ||= other.#overflow
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @param {number} duration
|
|
90
|
+
* @param {number | undefined} lastAudio
|
|
91
|
+
*/
|
|
92
|
+
metadata (duration, lastAudio) {
|
|
93
|
+
if (this.#lastOffset === undefined || this.#overflow || duration <= 0) return
|
|
94
|
+
this.extendSilence(duration, lastAudio)
|
|
95
|
+
const intervals = []
|
|
96
|
+
let cursor = 0
|
|
97
|
+
for (const [from, to] of this.#silence) {
|
|
98
|
+
const start = Math.min(duration, from)
|
|
99
|
+
if (start > cursor) intervals.push([Math.floor(cursor), Math.ceil(start)])
|
|
100
|
+
cursor = Math.max(cursor, Math.min(duration, to))
|
|
101
|
+
}
|
|
102
|
+
if (cursor < duration) intervals.push([Math.floor(cursor), Math.ceil(duration)])
|
|
103
|
+
const merged = []
|
|
104
|
+
for (const [start, end] of intervals) {
|
|
105
|
+
const last = merged.at(-1)
|
|
106
|
+
if (last && start <= last[1]) last[1] = Math.max(end, last[1])
|
|
107
|
+
else merged.push([start, end])
|
|
108
|
+
}
|
|
109
|
+
if (merged.length > 128) return
|
|
110
|
+
return { version: 1, source: 'elevenlabs_vad', timing: 'estimated', intervals_ms: merged }
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
module.exports = SpeechActivity
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { LLMOBS_AUDIO_ACCUMULATE_MAX_BYTES } = require('../../../dd-trace/src/llmobs/constants/audio')
|
|
4
|
+
const SpeechActivity = require('./activity')
|
|
5
|
+
|
|
6
|
+
// Leave space for both WAV headers before spending the shared encoded event budget.
|
|
7
|
+
const RAW_LIMIT = LLMOBS_AUDIO_ACCUMULATE_MAX_BYTES - 128
|
|
8
|
+
const BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/
|
|
9
|
+
|
|
10
|
+
class AudioBuffer {
|
|
11
|
+
chunks = []
|
|
12
|
+
size = 0
|
|
13
|
+
total = 0
|
|
14
|
+
/** @type {number | undefined} */
|
|
15
|
+
start = undefined
|
|
16
|
+
/** @type {number | undefined} */
|
|
17
|
+
lastAudio = undefined
|
|
18
|
+
overflow = false
|
|
19
|
+
present = false
|
|
20
|
+
activity = new SpeechActivity()
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {unknown} encoded
|
|
24
|
+
* @param {number} now
|
|
25
|
+
* @param {number} rate
|
|
26
|
+
* @param {boolean} input
|
|
27
|
+
* @param {boolean} retain
|
|
28
|
+
*/
|
|
29
|
+
append (encoded, now, rate, input, retain) {
|
|
30
|
+
this.present = true
|
|
31
|
+
if (!rate || typeof encoded !== 'string' || !encoded.length) return
|
|
32
|
+
// Bound before validating/decoding an attacker-controlled string.
|
|
33
|
+
if (encoded.length > Math.ceil(RAW_LIMIT / 3) * 4) {
|
|
34
|
+
this.omit()
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
if (!BASE64.test(encoded)) return
|
|
38
|
+
const size = encoded.length / 4 * 3 - (encoded.endsWith('==') ? 2 : encoded.endsWith('=') ? 1 : 0)
|
|
39
|
+
if (size % 2) return
|
|
40
|
+
this.start ??= input ? now - size / (2 * rate) * 1000 : now
|
|
41
|
+
this.total += size
|
|
42
|
+
this.lastAudio = now
|
|
43
|
+
if (!retain) {
|
|
44
|
+
this.omit()
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
if (this.overflow || this.size + size > RAW_LIMIT) this.omit()
|
|
48
|
+
else {
|
|
49
|
+
if (this.chunks.length >= 1024) this.chunks = [this.bytes()]
|
|
50
|
+
this.chunks.push(Buffer.from(encoded, 'base64'))
|
|
51
|
+
this.size += size
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
omit () {
|
|
56
|
+
this.chunks = []
|
|
57
|
+
this.size = 0
|
|
58
|
+
this.overflow = true
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @param {number} rate */
|
|
62
|
+
duration (rate) { return rate ? this.total / (2 * rate) * 1000 : 0 }
|
|
63
|
+
|
|
64
|
+
/** @param {number} rate */
|
|
65
|
+
end (rate) { return this.start === undefined ? undefined : this.start + this.duration(rate) }
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {number} now
|
|
69
|
+
* @param {number} rate
|
|
70
|
+
* @param {number} [playbackEnd] Estimated end of the queued PCM, including delivery gaps.
|
|
71
|
+
*/
|
|
72
|
+
trim (now, rate, playbackEnd) {
|
|
73
|
+
if (this.start === undefined || !rate) return
|
|
74
|
+
const end = playbackEnd ?? this.start + this.duration(rate)
|
|
75
|
+
const remaining = Math.max(0, end - now) * rate / 1000
|
|
76
|
+
const size = Math.max(0, Math.floor(this.total / 2 - remaining)) * 2
|
|
77
|
+
this.total = size
|
|
78
|
+
if (!this.overflow && this.size > size) {
|
|
79
|
+
this.chunks = [this.bytes().subarray(0, size)]
|
|
80
|
+
this.size = size
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @param {AudioBuffer} other
|
|
86
|
+
* @param {number} rate
|
|
87
|
+
*/
|
|
88
|
+
extend (other, rate) {
|
|
89
|
+
this.activity.extend(other.activity, this.duration(rate), this.lastAudio)
|
|
90
|
+
this.start ??= other.start
|
|
91
|
+
this.total += other.total
|
|
92
|
+
this.lastAudio = other.lastAudio ?? this.lastAudio
|
|
93
|
+
this.present ||= other.present
|
|
94
|
+
if (this.overflow || other.overflow || this.size + other.size > RAW_LIMIT) this.omit()
|
|
95
|
+
else {
|
|
96
|
+
this.chunks.push(...other.chunks)
|
|
97
|
+
this.size += other.size
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
bytes () { return Buffer.concat(this.chunks, this.size) }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = { AudioBuffer, RAW_LIMIT }
|