dd-trace 5.135.0 → 5.137.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
|
@@ -5,7 +5,13 @@ const { isNativeError } = require('node:util').types
|
|
|
5
5
|
const shimmer = require('../../datadog-shimmer')
|
|
6
6
|
const nomenclature = require('../../dd-trace/src/service-naming')
|
|
7
7
|
const spanEndingHook = require('../../dd-trace/src/opentelemetry/span-ending-hook')
|
|
8
|
+
const {
|
|
9
|
+
HTTP_STATUS_ERROR,
|
|
10
|
+
otelHttpResourceName,
|
|
11
|
+
setInstrumentationHttpResource,
|
|
12
|
+
} = require('../../dd-trace/src/plugins/util/http-otel-semantics')
|
|
8
13
|
const { RESOURCE_NAME } = require('../../../ext/tags')
|
|
14
|
+
const satisfies = require('../../../vendor/dist/semifies')
|
|
9
15
|
const { channel, addHook } = require('./helpers/instrument')
|
|
10
16
|
|
|
11
17
|
const startChannel = channel('apm:next:request:start')
|
|
@@ -13,6 +19,7 @@ const finishChannel = channel('apm:next:request:finish')
|
|
|
13
19
|
const errorChannel = channel('apm:next:request:error')
|
|
14
20
|
const pageLoadChannel = channel('apm:next:page:load')
|
|
15
21
|
const bodyParsedChannel = channel('apm:next:body-parsed')
|
|
22
|
+
const responseJsonChannel = channel('apm:next:response:json')
|
|
16
23
|
const queryParsedChannel = channel('apm:next:query-parsed')
|
|
17
24
|
const backgroundRevalidationChannel = channel('apm:next:request:background-revalidation')
|
|
18
25
|
|
|
@@ -37,6 +44,7 @@ const backgroundRevalidationChannel = channel('apm:next:request:background-reval
|
|
|
37
44
|
* @property {boolean} [responseFinished]
|
|
38
45
|
* @property {unknown} [error]
|
|
39
46
|
* @property {NextRequest} [nextRequest]
|
|
47
|
+
* @property {(error: object) => void} ignoreError
|
|
40
48
|
*
|
|
41
49
|
* @typedef {object} ResponseGeneratorContext
|
|
42
50
|
* @property {boolean} [hasResolved]
|
|
@@ -50,6 +58,7 @@ const backgroundRevalidationChannel = channel('apm:next:request:background-reval
|
|
|
50
58
|
*/
|
|
51
59
|
|
|
52
60
|
const requests = new WeakSet()
|
|
61
|
+
const responseConstructors = new WeakSet()
|
|
53
62
|
const nodeNextRequestsToNextRequests = new WeakMap()
|
|
54
63
|
const noFallbackErrorPrototypes = new WeakSet()
|
|
55
64
|
// Next.js <= 14.2.6
|
|
@@ -60,6 +69,19 @@ const NEXT_REQUEST_META = Symbol.for('NextInternalRequestMeta')
|
|
|
60
69
|
const META_IS_MIDDLEWARE = 'middlewareInvoke'
|
|
61
70
|
const encounteredMiddleware = new WeakSet()
|
|
62
71
|
|
|
72
|
+
const abortReasons = new WeakSet()
|
|
73
|
+
const incomingRequests = new WeakSet()
|
|
74
|
+
const blockableApiModules = new WeakMap()
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Keeps an error a subscriber raised to stop the request, such as a blocked request, out of the request errors.
|
|
78
|
+
*
|
|
79
|
+
* @param {object} error
|
|
80
|
+
*/
|
|
81
|
+
function ignoreError (error) {
|
|
82
|
+
abortReasons.add(error)
|
|
83
|
+
}
|
|
84
|
+
|
|
63
85
|
// `next.span_type` value Next.js sets on its own OTel root request span; the whole detection surface.
|
|
64
86
|
const NEXT_BASE_SERVER_HANDLE_REQUEST = 'BaseServer.handleRequest'
|
|
65
87
|
|
|
@@ -67,18 +89,26 @@ const NEXT_BASE_SERVER_HANDLE_REQUEST = 'BaseServer.handleRequest'
|
|
|
67
89
|
// own OTel spans and renames the root request span to `${method} ${route}` at finish, which the
|
|
68
90
|
// bridge routes into the DD operation name and leaves the resource as the bare method — the reverse
|
|
69
91
|
// of Datadog's contract. Correct it via the bridge's pre-finish hook. See span-ending-hook.js.
|
|
70
|
-
spanEndingHook.hook = (ddSpan) => {
|
|
92
|
+
spanEndingHook.hook = (ddSpan, otelSemanticsEnabled) => {
|
|
71
93
|
const tags = ddSpan.context().getTags()
|
|
72
94
|
if (tags['next.span_type'] !== NEXT_BASE_SERVER_HANDLE_REQUEST) return
|
|
73
95
|
|
|
74
96
|
const method = tags['http.method']
|
|
75
97
|
const route = tags['next.route'] ?? tags['http.route']
|
|
76
|
-
// Next already wrote the RSC-aware `${method} ${route}` into `next.span_name`; prefer it so we
|
|
77
|
-
// mirror Next's own naming, and only construct the resource when it is absent.
|
|
78
|
-
const resource = tags['next.span_name'] ?? (route ? `${method} ${route}` : method)
|
|
79
|
-
|
|
80
98
|
ddSpan.setOperationName(nomenclature.opName('web', 'server', 'next'))
|
|
81
|
-
|
|
99
|
+
if (otelSemanticsEnabled) {
|
|
100
|
+
setInstrumentationHttpResource(ddSpan, otelHttpResourceName(method, route))
|
|
101
|
+
const status = tags['http.status_code']
|
|
102
|
+
if (status >= 500) {
|
|
103
|
+
ddSpan.setTag(HTTP_STATUS_ERROR, String(status))
|
|
104
|
+
return true
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
// Next already wrote the RSC-aware `${method} ${route}` into `next.span_name`; prefer it so we
|
|
108
|
+
// mirror Next's own naming, and only construct the resource when it is absent.
|
|
109
|
+
const resource = tags['next.span_name'] ?? (route ? `${method} ${route}` : method)
|
|
110
|
+
ddSpan.setTag(RESOURCE_NAME, resource)
|
|
111
|
+
}
|
|
82
112
|
}
|
|
83
113
|
|
|
84
114
|
function wrapHandleRequest (handleRequest) {
|
|
@@ -191,7 +221,7 @@ function getRequestMeta (req, key) {
|
|
|
191
221
|
* @param {(ctx: NextRequestContext) => Promise<T>} handler
|
|
192
222
|
* @param {unknown} [error]
|
|
193
223
|
* @param {boolean} [finishOnResponse]
|
|
194
|
-
* @returns {Promise<T>}
|
|
224
|
+
* @returns {Promise<T | undefined>}
|
|
195
225
|
*/
|
|
196
226
|
function instrument (req, res, handler, error, finishOnResponse = false) {
|
|
197
227
|
req = req.originalRequest || req
|
|
@@ -201,7 +231,7 @@ function instrument (req, res, handler, error, finishOnResponse = false) {
|
|
|
201
231
|
const isMiddleware = req.headers[MIDDLEWARE_HEADER] || getRequestMeta(req, META_IS_MIDDLEWARE)
|
|
202
232
|
if ((isMiddleware && !encounteredMiddleware.has(req)) || requests.has(req)) {
|
|
203
233
|
encounteredMiddleware.add(req)
|
|
204
|
-
if (error) {
|
|
234
|
+
if (error && !isIgnoredError(error)) {
|
|
205
235
|
errorChannel.publish({ error })
|
|
206
236
|
}
|
|
207
237
|
return handler()
|
|
@@ -209,7 +239,7 @@ function instrument (req, res, handler, error, finishOnResponse = false) {
|
|
|
209
239
|
|
|
210
240
|
requests.add(req)
|
|
211
241
|
|
|
212
|
-
const ctx = finishOnResponse ? { req, res, finishOnResponse } : { req, res }
|
|
242
|
+
const ctx = finishOnResponse ? { req, res, finishOnResponse, ignoreError } : { req, res, ignoreError }
|
|
213
243
|
if (finishOnResponse) {
|
|
214
244
|
const onResponseFinish = () => {
|
|
215
245
|
res.removeListener('finish', onResponseFinish)
|
|
@@ -224,14 +254,20 @@ function instrument (req, res, handler, error, finishOnResponse = false) {
|
|
|
224
254
|
const queryIndex = req.url.indexOf('?')
|
|
225
255
|
if (queryIndex !== -1) {
|
|
226
256
|
const searchParams = new URLSearchParams(req.url.slice(queryIndex + 1))
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
257
|
+
/** @type {Record<string, string[]>} */
|
|
258
|
+
const query = Object.create(null)
|
|
259
|
+
for (const [key, value] of searchParams) {
|
|
260
|
+
const values = query[key]
|
|
261
|
+
if (values === undefined) {
|
|
262
|
+
query[key] = [value]
|
|
263
|
+
} else {
|
|
264
|
+
values.push(value)
|
|
231
265
|
}
|
|
232
266
|
}
|
|
233
267
|
|
|
234
|
-
|
|
268
|
+
const abortController = new AbortController()
|
|
269
|
+
queryParsedChannel.publish({ req, res, query, abortController })
|
|
270
|
+
if (abortController.signal.aborted) return /** @type {Promise<undefined>} */ (Promise.resolve())
|
|
235
271
|
}
|
|
236
272
|
}
|
|
237
273
|
|
|
@@ -281,7 +317,7 @@ function publishFinish (ctx, error) {
|
|
|
281
317
|
function finish (ctx, result, error) {
|
|
282
318
|
if (ctx.finishOnResponse) {
|
|
283
319
|
ctx.handlerFinished = true
|
|
284
|
-
if (error && !
|
|
320
|
+
if (error && !isIgnoredError(error)) ctx.error = error
|
|
285
321
|
if (!ctx.responseFinished) return
|
|
286
322
|
}
|
|
287
323
|
|
|
@@ -293,13 +329,27 @@ function isNoFallbackError (error) {
|
|
|
293
329
|
return isNativeError(error) && noFallbackErrorPrototypes.has(Object.getPrototypeOf(error))
|
|
294
330
|
}
|
|
295
331
|
|
|
332
|
+
/**
|
|
333
|
+
* An error that keeps an abort reason as its own `cause`, whether it is a native error or not, comes from the same
|
|
334
|
+
* stop. Reading the own data property runs no getter of the application.
|
|
335
|
+
*
|
|
336
|
+
* @param {unknown} error
|
|
337
|
+
*/
|
|
338
|
+
function isIgnoredError (error) {
|
|
339
|
+
if (typeof error !== 'object' || error === null) return false
|
|
340
|
+
|
|
341
|
+
return abortReasons.has(error) ||
|
|
342
|
+
abortReasons.has(Object.getOwnPropertyDescriptor(error, 'cause')?.value) ||
|
|
343
|
+
isNoFallbackError(error)
|
|
344
|
+
}
|
|
345
|
+
|
|
296
346
|
/**
|
|
297
347
|
* @param {NextNodeRequest} req
|
|
298
348
|
* @param {NextRequestContext | undefined} ctx
|
|
299
349
|
* @param {unknown} error
|
|
300
350
|
*/
|
|
301
351
|
function publishError (req, ctx, error) {
|
|
302
|
-
if (!error ||
|
|
352
|
+
if (!error || isIgnoredError(error)) return
|
|
303
353
|
|
|
304
354
|
if (ctx) {
|
|
305
355
|
ctx.error = error
|
|
@@ -322,6 +372,7 @@ addHook({
|
|
|
322
372
|
return function (nodeNextRequest) {
|
|
323
373
|
const nextRequest = fromNodeNextRequest.apply(this, arguments)
|
|
324
374
|
nodeNextRequestsToNextRequests.set(nodeNextRequest.originalRequest, nextRequest)
|
|
375
|
+
if (bodyParsedChannel.hasSubscribers) incomingRequests.add(nextRequest)
|
|
325
376
|
return nextRequest
|
|
326
377
|
}
|
|
327
378
|
})
|
|
@@ -389,6 +440,7 @@ function wrapAppRouteHandle (handle) {
|
|
|
389
440
|
nodeNextRequestsToNextRequests.set(nodeRequest, req)
|
|
390
441
|
}
|
|
391
442
|
}
|
|
443
|
+
if (bodyParsedChannel.hasSubscribers) incomingRequests.add(req)
|
|
392
444
|
|
|
393
445
|
return handle.apply(this, arguments)
|
|
394
446
|
}
|
|
@@ -533,9 +585,13 @@ function wrapPagesApiRender (render) {
|
|
|
533
585
|
}
|
|
534
586
|
}
|
|
535
587
|
|
|
536
|
-
|
|
588
|
+
// Pages API routes run through the compiled runtime from Next.js 13.5, which inlines the body parser and apiResolver.
|
|
589
|
+
function instrumentPagesApiRuntime (runtime, version) {
|
|
537
590
|
const PagesAPIRouteModule = runtime.PagesAPIRouteModule || runtime.default
|
|
538
|
-
|
|
591
|
+
const wrappers = [['render', wrapPagesApiRenderBody]]
|
|
592
|
+
// Keep wrapPagesApiRender on its previous >=15.4.1 range; the hook is widened only for the body wrapper.
|
|
593
|
+
if (satisfies(version, '>=15.4.1')) wrappers.push(['render', wrapPagesApiRender])
|
|
594
|
+
instrumentRouteModule(PagesAPIRouteModule, wrappers, false)
|
|
539
595
|
return runtime
|
|
540
596
|
}
|
|
541
597
|
|
|
@@ -548,18 +604,96 @@ function instrumentAppPageRuntime (runtime) {
|
|
|
548
604
|
return runtime
|
|
549
605
|
}
|
|
550
606
|
|
|
551
|
-
for (const [runtime, instrumentRuntime] of [
|
|
552
|
-
['app-route', instrumentAppRouteRuntime],
|
|
553
|
-
['pages-api', instrumentPagesApiRuntime],
|
|
554
|
-
['app-page', instrumentAppPageRuntime],
|
|
555
|
-
]) {
|
|
607
|
+
for (const [runtime, instrumentRuntime, versions] of /** @type {const} */ ([
|
|
608
|
+
['app-route', instrumentAppRouteRuntime, '>=15.4.1'],
|
|
609
|
+
['pages-api', instrumentPagesApiRuntime, '>=13.5'],
|
|
610
|
+
['app-page', instrumentAppPageRuntime, '>=15.4.1'],
|
|
611
|
+
])) {
|
|
556
612
|
addHook({
|
|
557
613
|
name: 'next',
|
|
558
|
-
versions: [
|
|
614
|
+
versions: [versions],
|
|
559
615
|
filePattern: String.raw`${COMPILED_RUNTIME_PATH}${runtime}[\w-]*\.runtime\.(?:dev|prod)\.js$`,
|
|
560
616
|
}, instrumentRuntime)
|
|
561
617
|
}
|
|
562
618
|
|
|
619
|
+
/**
|
|
620
|
+
* @param {Function} handler
|
|
621
|
+
*/
|
|
622
|
+
function wrapApiHandler (handler) {
|
|
623
|
+
return function (req, res) {
|
|
624
|
+
const { body } = req
|
|
625
|
+
if (bodyParsedChannel.hasSubscribers && body !== undefined && body !== '') {
|
|
626
|
+
const abortController = new AbortController()
|
|
627
|
+
bodyParsedChannel.publish({ req, res, body, abortController })
|
|
628
|
+
if (abortController.signal.aborted) return
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
return handler.apply(this, arguments)
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Pages API modules expose the handler through a webpack export getter that can't be wrapped in place, so the
|
|
637
|
+
* module is replaced by one that inherits from it with a wrapped handler.
|
|
638
|
+
*
|
|
639
|
+
* @param {{ default?: unknown } | Function} apiModule
|
|
640
|
+
* @returns {{ default?: unknown } | Function}
|
|
641
|
+
*/
|
|
642
|
+
function getBlockableApiModule (apiModule) {
|
|
643
|
+
let blockableModule = blockableApiModules.get(apiModule)
|
|
644
|
+
if (blockableModule) return blockableModule
|
|
645
|
+
|
|
646
|
+
const handler = apiModule?.default || apiModule
|
|
647
|
+
if (typeof handler !== 'function') return apiModule
|
|
648
|
+
|
|
649
|
+
blockableModule = Object.create(apiModule, { default: { value: wrapApiHandler(handler) } })
|
|
650
|
+
blockableApiModules.set(apiModule, blockableModule)
|
|
651
|
+
// wrapPagesApiRenderBody stores the replacement as `userland`, so later renders pass it back here: resolve it to
|
|
652
|
+
// itself instead of nesting another handler wrapper.
|
|
653
|
+
blockableApiModules.set(blockableModule, blockableModule)
|
|
654
|
+
return blockableModule
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* @param {Function} render
|
|
659
|
+
*/
|
|
660
|
+
function wrapPagesApiRenderBody (render) {
|
|
661
|
+
/** @this {{ userland: { default?: unknown } }} */
|
|
662
|
+
return function () {
|
|
663
|
+
if (bodyParsedChannel.hasSubscribers) {
|
|
664
|
+
const blockableModule = getBlockableApiModule(this.userland)
|
|
665
|
+
if (blockableModule !== this.userland) {
|
|
666
|
+
// Next.js 16 exposes `userland` through a prototype getter, so shadow it instead of assigning it.
|
|
667
|
+
Object.defineProperty(this, 'userland', { value: blockableModule, configurable: true, writable: true })
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
return render.apply(this, arguments)
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* @param {Function} apiResolver
|
|
677
|
+
*/
|
|
678
|
+
function wrapApiResolver (apiResolver) {
|
|
679
|
+
return function (...args) {
|
|
680
|
+
if (bodyParsedChannel.hasSubscribers) {
|
|
681
|
+
args[3] = getBlockableApiModule(args[3])
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
return Reflect.apply(apiResolver, this, args)
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
for (const file of ['dist/server/api-utils.js', 'dist/server/api-utils/node.js']) {
|
|
689
|
+
addHook({ name: 'next', versions: ['>=11.1 <13.5'], file }, apiUtils => {
|
|
690
|
+
const apiUtilsExports = /** @type {{ apiResolver?: Function }} */ (apiUtils)
|
|
691
|
+
if (typeof apiUtilsExports.apiResolver !== 'function') return apiUtils
|
|
692
|
+
|
|
693
|
+
return shimmer.wrap(apiUtilsExports, 'apiResolver', wrapApiResolver, { replaceGetter: true })
|
|
694
|
+
})
|
|
695
|
+
}
|
|
696
|
+
|
|
563
697
|
addHook({
|
|
564
698
|
name: 'next',
|
|
565
699
|
versions: ['>=11.1'],
|
|
@@ -625,6 +759,23 @@ addHook({
|
|
|
625
759
|
return nextServer
|
|
626
760
|
})
|
|
627
761
|
|
|
762
|
+
/**
|
|
763
|
+
* @param {Request} request
|
|
764
|
+
* @param {unknown} body
|
|
765
|
+
*/
|
|
766
|
+
function publishBodyParsed (request, body) {
|
|
767
|
+
if (!bodyParsedChannel.hasSubscribers) return
|
|
768
|
+
|
|
769
|
+
const abortController = incomingRequests.has(request) ? new AbortController() : undefined
|
|
770
|
+
bodyParsedChannel.publish({ body, abortController })
|
|
771
|
+
|
|
772
|
+
if (abortController?.signal.aborted) {
|
|
773
|
+
const { reason } = abortController.signal
|
|
774
|
+
abortReasons.add(reason)
|
|
775
|
+
throw reason
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
628
779
|
addHook({
|
|
629
780
|
name: 'next',
|
|
630
781
|
versions: ['>=13'],
|
|
@@ -632,11 +783,25 @@ addHook({
|
|
|
632
783
|
}, request => {
|
|
633
784
|
const requestProto = Object.getPrototypeOf(request.NextRequest.prototype)
|
|
634
785
|
|
|
786
|
+
// Next bundles copies of NextResponse, but each delegates JSON serialization to the runtime's native/polyfill
|
|
787
|
+
// Response constructor. That constructor is selected at runtime and has no Next.js source function to rewrite.
|
|
788
|
+
const Response = globalThis.Response
|
|
789
|
+
if (typeof Response?.json === 'function' && !responseConstructors.has(Response)) {
|
|
790
|
+
responseConstructors.add(Response)
|
|
791
|
+
shimmer.wrap(Response, 'json', json => function (body) {
|
|
792
|
+
const response = json.apply(this, arguments)
|
|
793
|
+
if (responseJsonChannel.hasSubscribers) {
|
|
794
|
+
responseJsonChannel.publish({ body, stream: response.body })
|
|
795
|
+
}
|
|
796
|
+
return response
|
|
797
|
+
})
|
|
798
|
+
}
|
|
799
|
+
|
|
635
800
|
shimmer.massWrap(requestProto, ['text', 'json'], function (originalMethod) {
|
|
636
801
|
return async function wrappedJson () {
|
|
637
802
|
const body = await originalMethod.apply(this, arguments)
|
|
638
803
|
|
|
639
|
-
|
|
804
|
+
publishBodyParsed(this, body)
|
|
640
805
|
|
|
641
806
|
return body
|
|
642
807
|
}
|
|
@@ -650,11 +815,23 @@ addHook({
|
|
|
650
815
|
if (typeof body.entries === 'function') {
|
|
651
816
|
normalizedBody = Object.fromEntries(body.entries())
|
|
652
817
|
}
|
|
653
|
-
|
|
818
|
+
publishBodyParsed(this, normalizedBody)
|
|
654
819
|
|
|
655
820
|
return body
|
|
656
821
|
}
|
|
657
822
|
})
|
|
658
823
|
|
|
824
|
+
shimmer.wrap(requestProto, 'clone', function (originalClone) {
|
|
825
|
+
return function wrappedClone () {
|
|
826
|
+
const clone = originalClone.apply(this, arguments)
|
|
827
|
+
|
|
828
|
+
if (bodyParsedChannel.hasSubscribers && incomingRequests.has(this)) {
|
|
829
|
+
incomingRequests.add(clone)
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
return clone
|
|
833
|
+
}
|
|
834
|
+
})
|
|
835
|
+
|
|
659
836
|
return request
|
|
660
837
|
})
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const dc = require('dc-polyfill')
|
|
4
|
+
|
|
5
|
+
const { getValueFromEnvSources } = require('../../dd-trace/src/config/helper')
|
|
6
|
+
const log = require('../../dd-trace/src/log')
|
|
7
|
+
const shimmer = require('../../datadog-shimmer')
|
|
8
|
+
const { attachSocketClose, createSession, realtimeEnabled } = require('./openai-realtime')
|
|
9
|
+
|
|
10
|
+
const turnChannel = dc.tracingChannel('apm:openai:realtime:turn')
|
|
11
|
+
const records = new WeakMap()
|
|
12
|
+
const listening = new WeakSet()
|
|
13
|
+
const defaultUrls = new WeakMap()
|
|
14
|
+
|
|
15
|
+
/** @param {string | URL} value */
|
|
16
|
+
function connectionOptions (value) {
|
|
17
|
+
const url = new URL(value)
|
|
18
|
+
return {
|
|
19
|
+
basePath: url.origin + url.pathname,
|
|
20
|
+
callId: url.searchParams.get('call_id') || undefined,
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @param {object} ctx */
|
|
25
|
+
function listen (ctx) {
|
|
26
|
+
const transport = ctx.self
|
|
27
|
+
if (!transport || listening.has(transport)) return
|
|
28
|
+
try {
|
|
29
|
+
const url = ctx.arguments?.[0]?.url
|
|
30
|
+
if (url) defaultUrls.set(transport, connectionOptions(url))
|
|
31
|
+
// emit is inherited from agents-core's shared delegate. Orchestrion cannot skip
|
|
32
|
+
// its body, so wrap this instance to filter only tracer-owned request failures.
|
|
33
|
+
// Raw events still reach the session before any SDK/application listeners.
|
|
34
|
+
shimmer.wrap(transport, 'emit', emit => function (name, event) {
|
|
35
|
+
if (name === 'connection_change' && event === 'disconnected') {
|
|
36
|
+
// SDK listeners can reconnect before the old socket's close callback runs.
|
|
37
|
+
// Keep that callback's record alive so it still classifies the close code.
|
|
38
|
+
const record = records.get(this)
|
|
39
|
+
if (record) record.detached = true
|
|
40
|
+
}
|
|
41
|
+
if (name === '*' || name === 'error') {
|
|
42
|
+
const record = records.get(this)
|
|
43
|
+
if (record) {
|
|
44
|
+
const providerEvent = name === '*' ? event : event?.error
|
|
45
|
+
if (name === '*' && !record.closed) record.session.onServerEvent(event, Date.now())
|
|
46
|
+
if (record.session.isRetrievalError(providerEvent)) return false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return emit.apply(this, arguments)
|
|
50
|
+
})
|
|
51
|
+
listening.add(transport)
|
|
52
|
+
} catch (error) {
|
|
53
|
+
log.debug('Error observing Agents realtime events: %s', error?.message)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @param {object} ctx */
|
|
58
|
+
function connect (ctx) {
|
|
59
|
+
try {
|
|
60
|
+
const options = ctx.arguments?.[0] || {}
|
|
61
|
+
if (options.url) ctx.realtimeDefaultUrl = connectionOptions(options.url)
|
|
62
|
+
if (!turnChannel.start.hasSubscribers) return
|
|
63
|
+
listen(ctx)
|
|
64
|
+
const transport = ctx.self
|
|
65
|
+
const previous = records.get(transport)
|
|
66
|
+
if (previous && !previous.closed && !previous.detached) return
|
|
67
|
+
// Match the SDK's precedence. An explicit URL wins even when callId is also supplied.
|
|
68
|
+
const effective = ctx.realtimeDefaultUrl ?? (options.callId
|
|
69
|
+
? connectionOptions('wss://api.openai.com/v1/realtime?call_id=' + options.callId)
|
|
70
|
+
: defaultUrls.get(transport) || connectionOptions('wss://api.openai.com/v1/realtime'))
|
|
71
|
+
const retrieveAudio = getValueFromEnvSources('DD_OPENAI_REALTIME_SIDEBAND_AUDIO_RETRIEVAL_ENABLED') !== false
|
|
72
|
+
const connection = createSession({
|
|
73
|
+
model: options.model ?? transport.currentModel,
|
|
74
|
+
basePath: effective.basePath,
|
|
75
|
+
sessionId: effective.callId,
|
|
76
|
+
serverPlayback: effective.callId !== undefined,
|
|
77
|
+
requestItem: retrieveAudio
|
|
78
|
+
? (itemId, eventId) => {
|
|
79
|
+
if (transport.status === 'connected') {
|
|
80
|
+
transport.sendEvent({ type: 'conversation.item.retrieve', item_id: itemId, event_id: eventId })
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
: undefined,
|
|
84
|
+
})
|
|
85
|
+
const record = {
|
|
86
|
+
session: connection.session,
|
|
87
|
+
closed: false,
|
|
88
|
+
detached: false,
|
|
89
|
+
finalize: failed => {
|
|
90
|
+
if (record.closed) return
|
|
91
|
+
record.closed = true
|
|
92
|
+
connection.finalize(failed)
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
records.set(transport, record)
|
|
96
|
+
ctx.realtimeConnection = record
|
|
97
|
+
} catch (error) {
|
|
98
|
+
log.debug('Error starting Agents realtime instrumentation: %s', error?.message)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** @param {object} ctx */
|
|
103
|
+
function connected (ctx) {
|
|
104
|
+
try {
|
|
105
|
+
if (ctx.realtimeConnectFailed) return
|
|
106
|
+
// The SDK retains successful URL overrides even while tracing is disabled.
|
|
107
|
+
if (ctx.realtimeDefaultUrl) defaultUrls.set(ctx.self, ctx.realtimeDefaultUrl)
|
|
108
|
+
const record = ctx.realtimeConnection
|
|
109
|
+
if (record && !record.closed) {
|
|
110
|
+
attachSocketClose({ socket: ctx.self.connectionState?.websocket }, record.finalize)
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
log.debug('Error observing Agents realtime connection: %s', error?.message)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** @param {object} ctx */
|
|
118
|
+
function sent (ctx) {
|
|
119
|
+
const record = records.get(ctx.self)
|
|
120
|
+
if (record && !record.closed && !ctx.error) record.session.onClientEvent(ctx.arguments[0], Date.now())
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** @param {{ self: object, realtimeConnection?: { finalize: (failed?: boolean) => void } }} ctx */
|
|
124
|
+
function closing (ctx) {
|
|
125
|
+
ctx.realtimeConnection = records.get(ctx.self)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** @param {object} ctx */
|
|
129
|
+
function closed (ctx) {
|
|
130
|
+
ctx.realtimeConnection?.finalize(false)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** @param {object} ctx */
|
|
134
|
+
function failed (ctx) {
|
|
135
|
+
ctx.realtimeConnectFailed = true
|
|
136
|
+
ctx.realtimeConnection?.finalize(true)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (realtimeEnabled()) {
|
|
140
|
+
dc.tracingChannel('orchestrion:@openai/agents-realtime:constructor').end.subscribe(listen)
|
|
141
|
+
const connection = dc.tracingChannel('orchestrion:@openai/agents-realtime:connect')
|
|
142
|
+
connection.start.subscribe(connect)
|
|
143
|
+
connection.asyncEnd.subscribe(connected)
|
|
144
|
+
connection.error.subscribe(failed)
|
|
145
|
+
dc.tracingChannel('orchestrion:@openai/agents-realtime:send').end.subscribe(sent)
|
|
146
|
+
const close = dc.tracingChannel('orchestrion:@openai/agents-realtime:close')
|
|
147
|
+
close.start.subscribe(closing)
|
|
148
|
+
close.end.subscribe(closed)
|
|
149
|
+
}
|
|
@@ -226,6 +226,33 @@ class AudioAccumulator {
|
|
|
226
226
|
return this.chunks.length === 1 ? this.chunks[0] : Buffer.concat(this.chunks, this.#retainedBytes)
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Replace a retrieved clip with its latest bounded item buffers. The caller owns
|
|
231
|
+
* item ordering; shared Buffer references avoid copying the whole clip on every
|
|
232
|
+
* retrieval. An incomplete/oversize set carries a marker, never a partial clip.
|
|
233
|
+
*
|
|
234
|
+
* @param {Buffer[]} buffers
|
|
235
|
+
* @param {number} totalDecodedBytes
|
|
236
|
+
* @param {number} now
|
|
237
|
+
* @param {string} mimeType
|
|
238
|
+
* @param {number} sampleRate
|
|
239
|
+
*/
|
|
240
|
+
replaceBuffers (buffers, totalDecodedBytes, now, mimeType, sampleRate) {
|
|
241
|
+
this.clear()
|
|
242
|
+
this.present = totalDecodedBytes > 0
|
|
243
|
+
this.startTime = this.present ? now : undefined
|
|
244
|
+
this.totalDecodedBytes = totalDecodedBytes
|
|
245
|
+
this.mimeType = mimeType
|
|
246
|
+
this.sampleRate = sampleRate
|
|
247
|
+
this.#retain = this.#shouldRetain()
|
|
248
|
+
let retainedBytes = 0
|
|
249
|
+
for (const buffer of buffers) retainedBytes += buffer.length
|
|
250
|
+
this.oversize = totalDecodedBytes > LLMOBS_AUDIO_ACCUMULATE_MAX_BYTES || retainedBytes !== totalDecodedBytes
|
|
251
|
+
if (!this.#retain || this.oversize) return
|
|
252
|
+
this.chunks = buffers
|
|
253
|
+
this.#retainedBytes = retainedBytes
|
|
254
|
+
}
|
|
255
|
+
|
|
229
256
|
clear () {
|
|
230
257
|
this.chunks = []
|
|
231
258
|
this.present = false
|
|
@@ -4,6 +4,7 @@ const dc = require('dc-polyfill')
|
|
|
4
4
|
|
|
5
5
|
const { getValueFromEnvSources } = require('../../../dd-trace/src/config/helper')
|
|
6
6
|
const log = require('../../../dd-trace/src/log')
|
|
7
|
+
const { addBeforeExitFinalizer } = require('../../../dd-trace/src/before-exit')
|
|
7
8
|
const shimmer = require('../../../datadog-shimmer')
|
|
8
9
|
const RealtimeSession = require('./session')
|
|
9
10
|
|
|
@@ -117,14 +118,24 @@ function createConnection (emitter) {
|
|
|
117
118
|
// The URL shape is not guaranteed across SDK versions; the session works without it.
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
const connection = { ...createSession({ model, basePath }), socket: emitter.socket }
|
|
122
|
+
attachSocketClose(emitter, connection.finalize)
|
|
123
|
+
return connection
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Shared session lifecycle for SDK adapters. Only origin/path and non-secret
|
|
128
|
+
* protocol options cross this boundary.
|
|
129
|
+
* @param {object} [options]
|
|
130
|
+
*/
|
|
131
|
+
function createSession (options = {}) {
|
|
120
132
|
// Asked per segment rather than snapshotted here: a plugin can be reconfigured while a connection
|
|
121
133
|
// is open, and a session that outlived its consumer would otherwise keep buffering audio nothing
|
|
122
134
|
// reads.
|
|
123
135
|
const session = new RealtimeSession({
|
|
124
136
|
emitTurn,
|
|
125
137
|
captureContext,
|
|
126
|
-
|
|
127
|
-
basePath,
|
|
138
|
+
...options,
|
|
128
139
|
shouldRetainAudio: () => audioChannel.hasSubscribers,
|
|
129
140
|
})
|
|
130
141
|
|
|
@@ -140,9 +151,7 @@ function createConnection (emitter) {
|
|
|
140
151
|
session.finishSession(Date.now(), failed)
|
|
141
152
|
}
|
|
142
153
|
|
|
143
|
-
|
|
144
|
-
attachSocketClose(emitter, finalize)
|
|
145
|
-
return connection
|
|
154
|
+
return { session, finalize }
|
|
146
155
|
}
|
|
147
156
|
|
|
148
157
|
// Close codes that mean the conversation ended on purpose: a normal close, the peer going away, and
|
|
@@ -303,9 +312,11 @@ function flushLiveSessions () {
|
|
|
303
312
|
liveSessions.clear()
|
|
304
313
|
}
|
|
305
314
|
|
|
306
|
-
|
|
315
|
+
addBeforeExitFinalizer(flushLiveSessions)
|
|
307
316
|
|
|
308
317
|
module.exports = {
|
|
318
|
+
attachSocketClose,
|
|
319
|
+
createSession,
|
|
309
320
|
flushLiveSessions,
|
|
310
321
|
patchRealtimeEmitter,
|
|
311
322
|
patchRealtimeTransport,
|