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
|
@@ -26,6 +26,14 @@ const { DIAGNOSTIC_KEYS } = require('./waf/diagnostics')
|
|
|
26
26
|
const REQUEST_HEADER_TAG_PREFIX = 'http.request.headers.'
|
|
27
27
|
const RESPONSE_HEADER_TAG_PREFIX = 'http.response.headers.'
|
|
28
28
|
|
|
29
|
+
// Preserve the first redirect target across independently evaluated outgoing requests.
|
|
30
|
+
const REDIRECT_TARGET_ATTRIBUTES = new Set([
|
|
31
|
+
'appsec.api.redirection.move_target',
|
|
32
|
+
'appsec.api.redirection.redirect_target',
|
|
33
|
+
'api.security.redirection.move_target',
|
|
34
|
+
'api.security.redirection.redirect_target',
|
|
35
|
+
])
|
|
36
|
+
|
|
29
37
|
const COLLECTED_REQUEST_BODY_MAX_STRING_LENGTH = 4096
|
|
30
38
|
const COLLECTED_REQUEST_BODY_MAX_DEPTH = 20
|
|
31
39
|
const COLLECTED_REQUEST_BODY_MAX_ELEMENTS_PER_NODE = 256
|
|
@@ -560,6 +568,7 @@ function reportAttributes (attributes, req, rootSpan) {
|
|
|
560
568
|
|
|
561
569
|
const tags = {}
|
|
562
570
|
for (let [tag, value] of Object.entries(attributes)) {
|
|
571
|
+
if (REDIRECT_TARGET_ATTRIBUTES.has(tag) && rootSpan.context().hasTag(tag)) continue
|
|
563
572
|
if (isSchemaAttribute(tag)) {
|
|
564
573
|
const gzippedValue = zlib.gzipSync(JSON.stringify(value))
|
|
565
574
|
value = gzippedValue.toString('base64')
|
|
@@ -27,15 +27,15 @@ function setUser (tracer, user) {
|
|
|
27
27
|
|
|
28
28
|
setUserTags(user, rootSpan)
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const requestData = {
|
|
31
31
|
[addresses.USER_ID]: String(user.id),
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
if (user.session_id && typeof user.session_id === 'string') {
|
|
35
|
-
|
|
35
|
+
requestData[addresses.USER_SESSION_ID] = user.session_id
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
waf.run(
|
|
38
|
+
waf.run(requestData)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
module.exports = {
|
|
@@ -211,19 +211,19 @@ function trackEvent (eventName, fields, sdkMethodName, rootSpan) {
|
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
function runWaf (eventName, user) {
|
|
214
|
-
const
|
|
214
|
+
const requestData = {
|
|
215
215
|
[`server.business_logic.${eventName}`]: null,
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
if (user?.id) {
|
|
219
|
-
|
|
219
|
+
requestData[addresses.USER_ID] = String(user.id)
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
if (user?.login) {
|
|
223
|
-
|
|
223
|
+
requestData[addresses.USER_LOGIN] = String(user.login)
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
waf.run(
|
|
226
|
+
waf.run(requestData)
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
module.exports = {
|
|
@@ -10,7 +10,7 @@ const { setUserTags } = require('./set_user')
|
|
|
10
10
|
const { getRootSpan } = require('./utils')
|
|
11
11
|
|
|
12
12
|
function isUserBlocked (user) {
|
|
13
|
-
const results = waf.run({
|
|
13
|
+
const results = waf.run({ [USER_ID]: user.id })
|
|
14
14
|
return !!getBlockingAction(results?.actions)
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -87,7 +87,7 @@ function trackLogin (framework, login, user, success, rootSpan) {
|
|
|
87
87
|
|
|
88
88
|
let newTags
|
|
89
89
|
|
|
90
|
-
const
|
|
90
|
+
const requestData = {
|
|
91
91
|
[addresses.USER_LOGIN]: login,
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -116,11 +116,11 @@ function trackLogin (framework, login, user, success, rootSpan) {
|
|
|
116
116
|
|
|
117
117
|
if (shouldSetTag('usr.id')) {
|
|
118
118
|
newTags['usr.id'] = userId
|
|
119
|
-
|
|
119
|
+
requestData[addresses.USER_ID] = userId
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
requestData[addresses.LOGIN_SUCCESS] = null
|
|
124
124
|
} else {
|
|
125
125
|
newTags = {
|
|
126
126
|
'appsec.events.users.login.failure.track': 'true',
|
|
@@ -146,14 +146,14 @@ function trackLogin (framework, login, user, success, rootSpan) {
|
|
|
146
146
|
}
|
|
147
147
|
*/
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
requestData[addresses.LOGIN_FAILURE] = null
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
keepTrace(rootSpan, ASM)
|
|
153
153
|
|
|
154
154
|
rootSpan.addTags(newTags)
|
|
155
155
|
|
|
156
|
-
return waf.run(
|
|
156
|
+
return waf.run(requestData)
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
function trackUser (user, rootSpan) {
|
|
@@ -177,9 +177,7 @@ function trackUser (user, rootSpan) {
|
|
|
177
177
|
})
|
|
178
178
|
|
|
179
179
|
return waf.run({
|
|
180
|
-
|
|
181
|
-
[addresses.USER_ID]: userId,
|
|
182
|
-
},
|
|
180
|
+
[addresses.USER_ID]: userId,
|
|
183
181
|
})
|
|
184
182
|
}
|
|
185
183
|
}
|
|
@@ -37,6 +37,9 @@ const waf = {
|
|
|
37
37
|
removeConfig,
|
|
38
38
|
checkAsmDdFallback,
|
|
39
39
|
run: noop,
|
|
40
|
+
runSubContext: noop,
|
|
41
|
+
disposeSubContext,
|
|
42
|
+
getRequest,
|
|
40
43
|
disposeContext: noop,
|
|
41
44
|
WafUpdateError,
|
|
42
45
|
}
|
|
@@ -55,6 +58,7 @@ function init (rules, config) {
|
|
|
55
58
|
|
|
56
59
|
waf.wafManager = new WAFManager(rules, config)
|
|
57
60
|
|
|
61
|
+
waf.runSubContext = runSubContext
|
|
58
62
|
waf.run = run
|
|
59
63
|
waf.disposeContext = disposeContext
|
|
60
64
|
}
|
|
@@ -65,6 +69,7 @@ function destroy () {
|
|
|
65
69
|
waf.wafManager = null
|
|
66
70
|
}
|
|
67
71
|
|
|
72
|
+
waf.runSubContext = noop
|
|
68
73
|
waf.run = noop
|
|
69
74
|
waf.disposeContext = noop
|
|
70
75
|
}
|
|
@@ -116,7 +121,7 @@ function removeConfig (configPath) {
|
|
|
116
121
|
// @see packages/dd-trace/test/appsec/lambda.spec.js
|
|
117
122
|
|
|
118
123
|
/**
|
|
119
|
-
* @param {object} data - WAF address
|
|
124
|
+
* @param {object} data - Flat WAF address map
|
|
120
125
|
* @param {object} req - Request key for WAF context lookup. May be an HTTP
|
|
121
126
|
* IncomingMessage or a plain object (Lambda invocation key).
|
|
122
127
|
* @param {string} [raspRule] - RASP rule identifier
|
|
@@ -132,7 +137,19 @@ function run (data, req, raspRule, rootSpan) {
|
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
const wafContext = waf.wafManager.getWAFContext(req)
|
|
135
|
-
|
|
140
|
+
if (!wafContext) return
|
|
141
|
+
return runContext(data, wafContext, raspRule, rootSpan)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @param {object} data - Flat WAF address map.
|
|
146
|
+
* @param {import('./waf_context_wrapper')} wafContext - Context selected for this evaluation.
|
|
147
|
+
* @param {object} [raspRule] - RASP rule metadata.
|
|
148
|
+
* @param {object} [rootSpan] - Explicit Lambda root span.
|
|
149
|
+
*/
|
|
150
|
+
function runContext (data, wafContext, raspRule, rootSpan) {
|
|
151
|
+
const req = wafContext.parent ? wafContext.parent.req : wafContext.req
|
|
152
|
+
const result = wafContext.run(data, raspRule, rootSpan)
|
|
136
153
|
|
|
137
154
|
if (result?.keep) {
|
|
138
155
|
if (limiter.isAllowed()) {
|
|
@@ -146,12 +163,54 @@ function run (data, req, raspRule, rootSpan) {
|
|
|
146
163
|
return result
|
|
147
164
|
}
|
|
148
165
|
|
|
149
|
-
|
|
150
|
-
|
|
166
|
+
/**
|
|
167
|
+
* @typedef {{ wafSubcontext?: import('./waf_context_wrapper') }} SubcontextState
|
|
168
|
+
*/
|
|
151
169
|
|
|
152
|
-
|
|
153
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Evaluate an isolated check, or reuse a subcontext across calls carrying the same state.
|
|
172
|
+
* @param {object} data - Flat WAF address map.
|
|
173
|
+
* @param {object} [raspRule] - RASP rule metadata.
|
|
174
|
+
* @param {SubcontextState} [state] - Instrumentation context, released by calling disposeSubContext.
|
|
175
|
+
* @param {object} [req] - Explicit request when the publisher provides it.
|
|
176
|
+
*/
|
|
177
|
+
function runSubContext (data, raspRule, state, req) {
|
|
178
|
+
let subcontext = state?.wafSubcontext
|
|
179
|
+
if (!subcontext) {
|
|
180
|
+
req ||= getActiveRequest()
|
|
181
|
+
if (!req) return
|
|
182
|
+
const context = waf.wafManager.getWAFContext(req)
|
|
183
|
+
if (!context) return
|
|
184
|
+
if (context.ddwafContext.disposed) return runContext(data, context, raspRule)
|
|
185
|
+
// Stateful checks can need response inputs even when no request inputs are known.
|
|
186
|
+
if (!state && (data === null || typeof data !== 'object' ||
|
|
187
|
+
!Object.keys(data).some(key => context.knownAddresses.has(key)))) return
|
|
188
|
+
subcontext = context.createSubcontext()
|
|
189
|
+
if (!subcontext) return
|
|
190
|
+
if (state) state.wafSubcontext = subcontext
|
|
154
191
|
}
|
|
192
|
+
try {
|
|
193
|
+
return runContext(data, subcontext, raspRule)
|
|
194
|
+
} finally {
|
|
195
|
+
if (!state) subcontext.dispose()
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** @param {SubcontextState} state - Instrumentation context bound by runSubContext. */
|
|
200
|
+
function getRequest (state) {
|
|
201
|
+
return state.wafSubcontext?.parent.req
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** @param {SubcontextState} state - Instrumentation context whose evaluation is complete. */
|
|
205
|
+
function disposeSubContext (state) {
|
|
206
|
+
const subcontext = state.wafSubcontext
|
|
207
|
+
if (!subcontext) return
|
|
208
|
+
state.wafSubcontext = undefined
|
|
209
|
+
subcontext.dispose()
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function disposeContext (req) {
|
|
213
|
+
waf.wafManager.disposeContext(req)
|
|
155
214
|
}
|
|
156
215
|
|
|
157
216
|
function noop () {}
|
|
@@ -6,14 +6,16 @@ const addresses = require('../addresses')
|
|
|
6
6
|
const { getBlockingAction } = require('../blocking')
|
|
7
7
|
const { wafRunFinished } = require('../channels')
|
|
8
8
|
|
|
9
|
-
//
|
|
9
|
+
// Some HTTP hooks can supply the same query more than once.
|
|
10
10
|
const preventDuplicateAddresses = new Set([
|
|
11
11
|
addresses.HTTP_INCOMING_QUERY,
|
|
12
12
|
])
|
|
13
13
|
|
|
14
14
|
class WAFContextWrapper {
|
|
15
|
-
constructor (ddwafContext, wafTimeout, wafVersion, rulesVersion, knownAddresses) {
|
|
15
|
+
constructor (ddwafContext, wafTimeout, wafVersion, rulesVersion, knownAddresses, req, parent) {
|
|
16
16
|
this.ddwafContext = ddwafContext
|
|
17
|
+
this.parent = parent
|
|
18
|
+
this.req = req
|
|
17
19
|
this.wafTimeout = wafTimeout
|
|
18
20
|
this.wafVersion = wafVersion
|
|
19
21
|
this.rulesVersion = rulesVersion
|
|
@@ -36,7 +38,7 @@ class WAFContextWrapper {
|
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
run (
|
|
41
|
+
run (data, raspRule, rootSpan) {
|
|
40
42
|
if (this.ddwafContext.disposed) {
|
|
41
43
|
log.warn('[ASM] Calling run on a disposed context')
|
|
42
44
|
if (raspRule) {
|
|
@@ -46,9 +48,8 @@ class WAFContextWrapper {
|
|
|
46
48
|
return
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const userId = persistent?.[addresses.USER_ID] || ephemeral?.[addresses.USER_ID]
|
|
51
|
+
const req = this.req
|
|
52
|
+
const userId = data?.[addresses.USER_ID]
|
|
52
53
|
if (userId) {
|
|
53
54
|
const cachedResults = this.cachedUserIdResults.get(userId)
|
|
54
55
|
if (cachedResults) {
|
|
@@ -61,42 +62,17 @@ class WAFContextWrapper {
|
|
|
61
62
|
// Cloned lazily; only the preventDuplicateAddresses branch below adds to it.
|
|
62
63
|
let newAddressesToSkip
|
|
63
64
|
|
|
64
|
-
if (
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
let hasPersistentInputs = false
|
|
68
|
-
for (const key of Object.keys(persistent)) {
|
|
65
|
+
if (data !== null && typeof data === 'object') {
|
|
66
|
+
for (const key of Object.keys(data)) {
|
|
69
67
|
if (!this.addressesToSkip.has(key) && this.knownAddresses.has(key)) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (preventDuplicateAddresses.has(key)) {
|
|
68
|
+
payloadHasData = true
|
|
69
|
+
payload[key] = data[key]
|
|
70
|
+
if (!this.parent && preventDuplicateAddresses.has(key)) {
|
|
73
71
|
newAddressesToSkip ??= new Set(this.addressesToSkip)
|
|
74
72
|
newAddressesToSkip.add(key)
|
|
75
73
|
}
|
|
76
74
|
}
|
|
77
75
|
}
|
|
78
|
-
|
|
79
|
-
if (hasPersistentInputs) {
|
|
80
|
-
payload.persistent = persistentInputs
|
|
81
|
-
payloadHasData = true
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (ephemeral !== null && typeof ephemeral === 'object') {
|
|
86
|
-
const ephemeralInputs = {}
|
|
87
|
-
|
|
88
|
-
let hasEphemeral = false
|
|
89
|
-
for (const key of Object.keys(ephemeral)) {
|
|
90
|
-
if (this.knownAddresses.has(key)) {
|
|
91
|
-
hasEphemeral = true
|
|
92
|
-
ephemeralInputs[key] = ephemeral[key]
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (hasEphemeral) {
|
|
97
|
-
payload.ephemeral = ephemeralInputs
|
|
98
|
-
payloadHasData = true
|
|
99
|
-
}
|
|
100
76
|
}
|
|
101
77
|
|
|
102
78
|
if (!payloadHasData) return
|
|
@@ -168,7 +144,7 @@ class WAFContextWrapper {
|
|
|
168
144
|
metrics.errorCode = err.errorCode ?? -127
|
|
169
145
|
} finally {
|
|
170
146
|
if (wafRunFinished.hasSubscribers) {
|
|
171
|
-
wafRunFinished.publish({ payload })
|
|
147
|
+
wafRunFinished.publish({ payload, req, isSubcontext: !!this.parent })
|
|
172
148
|
}
|
|
173
149
|
|
|
174
150
|
Reporter.reportMetrics(metrics, raspRule, req, rootSpan)
|
|
@@ -195,8 +171,27 @@ class WAFContextWrapper {
|
|
|
195
171
|
}
|
|
196
172
|
}
|
|
197
173
|
|
|
174
|
+
createSubcontext () {
|
|
175
|
+
if (this.parent || this.ddwafContext.disposed) return
|
|
176
|
+
try {
|
|
177
|
+
const subcontext = new WAFContextWrapper(
|
|
178
|
+
this.ddwafContext.createSubcontext(), this.wafTimeout, this.wafVersion,
|
|
179
|
+
this.rulesVersion, this.knownAddresses, this.req, this
|
|
180
|
+
)
|
|
181
|
+
this.subcontexts ??= new Set()
|
|
182
|
+
this.subcontexts.add(subcontext)
|
|
183
|
+
return subcontext
|
|
184
|
+
} catch (error) {
|
|
185
|
+
log.error('[ASM] Error creating an AppSec WAF subcontext', error)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
198
189
|
dispose () {
|
|
199
|
-
this.
|
|
190
|
+
this.parent?.subcontexts.delete(this)
|
|
191
|
+
if (this.subcontexts) {
|
|
192
|
+
for (const subcontext of this.subcontexts) subcontext.dispose()
|
|
193
|
+
}
|
|
194
|
+
if (!this.ddwafContext.disposed) this.ddwafContext.dispose()
|
|
200
195
|
}
|
|
201
196
|
}
|
|
202
197
|
|
|
@@ -53,14 +53,19 @@ class WAFManager {
|
|
|
53
53
|
|
|
54
54
|
getWAFContext (req) {
|
|
55
55
|
let wafContext = contexts.get(req)
|
|
56
|
+
if (wafContext === null) return
|
|
56
57
|
|
|
57
58
|
if (!wafContext) {
|
|
59
|
+
const context = this.ddwaf.createContext()
|
|
60
|
+
if (context === null) return
|
|
61
|
+
|
|
58
62
|
wafContext = new WAFContextWrapper(
|
|
59
|
-
|
|
63
|
+
context,
|
|
60
64
|
this.wafTimeout,
|
|
61
65
|
this.ddwafVersion,
|
|
62
66
|
this.rulesVersion,
|
|
63
|
-
this.ddwaf.knownAddresses
|
|
67
|
+
this.ddwaf.knownAddresses,
|
|
68
|
+
req
|
|
64
69
|
)
|
|
65
70
|
contexts.set(req, wafContext)
|
|
66
71
|
}
|
|
@@ -68,6 +73,17 @@ class WAFManager {
|
|
|
68
73
|
return wafContext
|
|
69
74
|
}
|
|
70
75
|
|
|
76
|
+
/** @param {object} req Request whose evaluations have finished. */
|
|
77
|
+
disposeContext (req) {
|
|
78
|
+
const context = contexts.get(req)
|
|
79
|
+
if (context) {
|
|
80
|
+
context.dispose()
|
|
81
|
+
} else {
|
|
82
|
+
// No native context exists when all rules were removed; late callbacks must still stay disabled.
|
|
83
|
+
contexts.set(req, null)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
71
87
|
setRulesVersion () {
|
|
72
88
|
if (this.ddwaf.diagnostics.ruleset_version) {
|
|
73
89
|
this.rulesVersion = this.ddwaf.diagnostics.ruleset_version
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/** @type {WeakSet<() => void>} */
|
|
4
|
+
const finalizers = new WeakSet()
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Registers synchronous span finalization before ordinary exit handlers flush and stop writers.
|
|
8
|
+
* Handlers remain in the existing set, so its normal registration/removal lifecycle is preserved.
|
|
9
|
+
* @param {() => void} handler
|
|
10
|
+
*/
|
|
11
|
+
function addBeforeExitFinalizer (handler) {
|
|
12
|
+
finalizers.add(handler)
|
|
13
|
+
globalThis[Symbol.for('dd-trace')]?.beforeExitHandlers?.add(handler)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** @param {Set<() => void>} handlers */
|
|
17
|
+
function runBeforeExitHandlers (handlers) {
|
|
18
|
+
for (const handler of handlers) {
|
|
19
|
+
if (!finalizers.has(handler)) continue
|
|
20
|
+
try {
|
|
21
|
+
handler()
|
|
22
|
+
} catch (error) {
|
|
23
|
+
// Lazy to avoid loading the logger while bootstrap creates the lifecycle registry.
|
|
24
|
+
require('./log').error('Error finalizing spans before process exit: %s', error?.message || error)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const handler of handlers) {
|
|
28
|
+
if (!finalizers.has(handler)) handler()
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = { addBeforeExitFinalizer, runBeforeExitHandlers }
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { runBeforeExitHandlers } = require('./before-exit')
|
|
4
|
+
|
|
3
5
|
if (!global._ddtrace) {
|
|
4
6
|
const ddTraceSymbol = Symbol.for('dd-trace')
|
|
5
7
|
|
|
@@ -8,6 +10,8 @@ if (!global._ddtrace) {
|
|
|
8
10
|
Object.defineProperty(globalThis, ddTraceSymbol, {
|
|
9
11
|
value: {
|
|
10
12
|
beforeExitHandlers: new Set(),
|
|
13
|
+
// Handler hooks may have populated Lambda caches before the tracer was initialized.
|
|
14
|
+
lambda: globalThis[ddTraceSymbol]?.lambda,
|
|
11
15
|
},
|
|
12
16
|
enumerable: false,
|
|
13
17
|
configurable: true,
|
|
@@ -16,9 +20,7 @@ if (!global._ddtrace) {
|
|
|
16
20
|
|
|
17
21
|
process.once('beforeExit', function mainBeforeExit () {
|
|
18
22
|
if (globalThis[ddTraceSymbol]?.beforeExitHandlers) {
|
|
19
|
-
|
|
20
|
-
handler()
|
|
21
|
-
}
|
|
23
|
+
runBeforeExitHandlers(globalThis[ddTraceSymbol].beforeExitHandlers)
|
|
22
24
|
}
|
|
23
25
|
})
|
|
24
26
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { performance } = require('node:perf_hooks')
|
|
4
|
+
|
|
3
5
|
const getConfig = require('../../config')
|
|
4
6
|
const id = require('../../id')
|
|
5
7
|
const log = require('../../log')
|
|
@@ -11,6 +13,9 @@ const {
|
|
|
11
13
|
TELEMETRY_KNOWN_TESTS_ERRORS,
|
|
12
14
|
TELEMETRY_KNOWN_TESTS_RESPONSE_TESTS,
|
|
13
15
|
TELEMETRY_KNOWN_TESTS_RESPONSE_BYTES,
|
|
16
|
+
TELEMETRY_KNOWN_TESTS_PAGES_FETCHED,
|
|
17
|
+
TELEMETRY_KNOWN_TESTS_TOTAL_FETCH_MS,
|
|
18
|
+
TELEMETRY_KNOWN_TESTS_TOTAL_REQUEST_MS,
|
|
14
19
|
} = require('../../ci-visibility/telemetry')
|
|
15
20
|
const { getNumFromKnownTests } = require('../../plugins/util/test')
|
|
16
21
|
const request = require('../requests/request')
|
|
@@ -59,7 +64,7 @@ function parseJsonResponse (rawJson) {
|
|
|
59
64
|
function parseKnownTestsResponse (rawJson, options = {}) {
|
|
60
65
|
const parsedResponse = parseJsonResponse(rawJson)
|
|
61
66
|
if (options.validateRequiredFields) {
|
|
62
|
-
validateKnownTestsResponse(parsedResponse
|
|
67
|
+
validateKnownTestsResponse(parsedResponse)
|
|
63
68
|
}
|
|
64
69
|
const { data: { attributes: { tests } } } = parsedResponse
|
|
65
70
|
return tests
|
|
@@ -178,9 +183,11 @@ function fetchFromApi ({
|
|
|
178
183
|
incrementCountMetric(TELEMETRY_KNOWN_TESTS)
|
|
179
184
|
|
|
180
185
|
const startTime = Date.now()
|
|
186
|
+
const totalFetchStartTime = performance.now()
|
|
181
187
|
let aggregateTests = null
|
|
182
188
|
let totalResponseBytes = 0
|
|
183
189
|
let pageNumber = 0
|
|
190
|
+
let totalRequestMs = 0
|
|
184
191
|
|
|
185
192
|
function fetchPage (pageState) {
|
|
186
193
|
pageNumber++
|
|
@@ -208,7 +215,9 @@ function fetchFromApi ({
|
|
|
208
215
|
},
|
|
209
216
|
})
|
|
210
217
|
|
|
218
|
+
const pageStartTime = performance.now()
|
|
211
219
|
request(data, options, (err, res, statusCode) => {
|
|
220
|
+
totalRequestMs += performance.now() - pageStartTime
|
|
212
221
|
if (err) {
|
|
213
222
|
distributionMetric(TELEMETRY_KNOWN_TESTS_MS, {}, Date.now() - startTime)
|
|
214
223
|
incrementCountMetric(TELEMETRY_KNOWN_TESTS_ERRORS, { statusCode })
|
|
@@ -238,9 +247,13 @@ function fetchFromApi ({
|
|
|
238
247
|
|
|
239
248
|
// Done — no more pages
|
|
240
249
|
distributionMetric(TELEMETRY_KNOWN_TESTS_MS, {}, Date.now() - startTime)
|
|
241
|
-
|
|
242
250
|
const numTests = getNumFromKnownTests(aggregateTests)
|
|
243
251
|
|
|
252
|
+
// Request time includes transport retries and backoff, but excludes parsing and merging pages.
|
|
253
|
+
distributionMetric(TELEMETRY_KNOWN_TESTS_PAGES_FETCHED, {}, pageNumber)
|
|
254
|
+
distributionMetric(TELEMETRY_KNOWN_TESTS_TOTAL_FETCH_MS, {}, performance.now() - totalFetchStartTime)
|
|
255
|
+
distributionMetric(TELEMETRY_KNOWN_TESTS_TOTAL_REQUEST_MS, {}, totalRequestMs)
|
|
256
|
+
|
|
244
257
|
distributionMetric(TELEMETRY_KNOWN_TESTS_RESPONSE_TESTS, {}, numTests)
|
|
245
258
|
distributionMetric(TELEMETRY_KNOWN_TESTS_RESPONSE_BYTES, {}, totalResponseBytes)
|
|
246
259
|
|
|
@@ -62,7 +62,7 @@ const SETTINGS_BOOLEAN_FIELDS = Object.freeze([
|
|
|
62
62
|
* the git repository or the runtime may not expose them.
|
|
63
63
|
*
|
|
64
64
|
* @typedef {{
|
|
65
|
-
* repositoryUrl?: string, sha?: string, branch?: string, tag?: string, testLevel?: string,
|
|
65
|
+
* repositoryUrl?: string, sha?: string, gitRoot?: string, branch?: string, tag?: string, testLevel?: string,
|
|
66
66
|
* osVersion?: string, osPlatform?: string, osArchitecture?: string,
|
|
67
67
|
* runtimeName?: string, runtimeVersion?: string, commitMessage?: string,
|
|
68
68
|
* pullRequestBaseSha?: string, commitHeadSha?: string, commitHeadMessage?: string,
|
|
@@ -212,7 +212,7 @@ class CiVisibilityExporter extends BufferingExporter {
|
|
|
212
212
|
#deferredTestSuiteSpans = new Map()
|
|
213
213
|
#gitUploadTimeoutId
|
|
214
214
|
|
|
215
|
-
constructor (config
|
|
215
|
+
constructor (config) {
|
|
216
216
|
super(config)
|
|
217
217
|
this._timer = undefined
|
|
218
218
|
this._coverageTimer = undefined
|
|
@@ -223,8 +223,7 @@ class CiVisibilityExporter extends BufferingExporter {
|
|
|
223
223
|
this._dynamicAtrEnabled = isDynamicAtrEnabled(dynamicAtrEnabled)
|
|
224
224
|
this._dynamicAtrBuckets = this._dynamicAtrEnabled ? getDynamicAtrBuckets(dynamicAtrBuckets) ?? undefined : undefined
|
|
225
225
|
this._hasRecordedDynamicAtrTelemetry = false
|
|
226
|
-
this._testOptimizationHttpCache =
|
|
227
|
-
this._isTestOptimizationCacheOnly = options.cacheOnly === true
|
|
226
|
+
this._testOptimizationHttpCache = new TestOptimizationHttpCache()
|
|
228
227
|
const coverageReportFlags = parsers.ARRAY(config?.testOptimization?.DD_CODE_COVERAGE_FLAGS)
|
|
229
228
|
if (coverageReportFlags?.length > MAX_COVERAGE_REPORT_FLAGS) {
|
|
230
229
|
log.warn(
|
|
@@ -327,12 +326,10 @@ class CiVisibilityExporter extends BufferingExporter {
|
|
|
327
326
|
const { skippableSuites, correlationId, coverage } = cachedSkippableSuites
|
|
328
327
|
return callback(null, skippableSuites, correlationId, coverage)
|
|
329
328
|
}
|
|
330
|
-
if (this._isTestOptimizationCacheOnly) {
|
|
331
|
-
return callback(this._getCacheOnlyError('skippable tests'), [])
|
|
332
|
-
}
|
|
333
|
-
|
|
334
329
|
this._gitUploadPromise.then(gitUploadError => {
|
|
335
|
-
|
|
330
|
+
const isKnownCommitUnavailable = gitUploadError?.code === 'ERR_GIT_COMMIT_UNAVAILABLE' &&
|
|
331
|
+
this._libraryConfig?.requireGit === false
|
|
332
|
+
if (gitUploadError && !isKnownCommitUnavailable) {
|
|
336
333
|
return callback(gitUploadError, [])
|
|
337
334
|
}
|
|
338
335
|
getSkippableSuitesRequest(requestConfiguration, callback)
|
|
@@ -347,9 +344,6 @@ class CiVisibilityExporter extends BufferingExporter {
|
|
|
347
344
|
if (cachedKnownTests !== CACHE_MISS) {
|
|
348
345
|
return callback(null, cachedKnownTests)
|
|
349
346
|
}
|
|
350
|
-
if (this._isTestOptimizationCacheOnly) {
|
|
351
|
-
return callback(this._getCacheOnlyError('known tests'))
|
|
352
|
-
}
|
|
353
347
|
getKnownTestsRequest(this.getRequestConfiguration(testConfiguration), callback)
|
|
354
348
|
}
|
|
355
349
|
|
|
@@ -361,9 +355,6 @@ class CiVisibilityExporter extends BufferingExporter {
|
|
|
361
355
|
if (cachedTestManagementTests !== CACHE_MISS) {
|
|
362
356
|
return callback(null, cachedTestManagementTests)
|
|
363
357
|
}
|
|
364
|
-
if (this._isTestOptimizationCacheOnly) {
|
|
365
|
-
return callback(this._getCacheOnlyError('test management tests'))
|
|
366
|
-
}
|
|
367
358
|
getTestManagementTestsRequest(this.getRequestConfiguration(testConfiguration), callback)
|
|
368
359
|
}
|
|
369
360
|
|
|
@@ -387,10 +378,6 @@ class CiVisibilityExporter extends BufferingExporter {
|
|
|
387
378
|
return this._applyCachedSettings(cachedLibraryConfig, configuration, repositoryUrl, false, callback)
|
|
388
379
|
}
|
|
389
380
|
|
|
390
|
-
if (this._isTestOptimizationCacheOnly) {
|
|
391
|
-
return callback(this._getCacheOnlyError('settings'), {})
|
|
392
|
-
}
|
|
393
|
-
|
|
394
381
|
// The settings request has a two-phase shape: when the backend returns
|
|
395
382
|
// `require_git`, we upload git metadata and re-request settings. Only the
|
|
396
383
|
// final (post-git-upload) configuration is cached, so the cross-process
|
|
@@ -471,7 +458,7 @@ class CiVisibilityExporter extends BufferingExporter {
|
|
|
471
458
|
isCoverageReportUploadEnabled: configuration.isCoverageReportUploadEnabled,
|
|
472
459
|
})
|
|
473
460
|
if (!canUseCachedSkippableSuites && (this._libraryConfig.requireGit || isFilesystemCache)) {
|
|
474
|
-
this.sendGitMetadata(repositoryUrl)
|
|
461
|
+
this.sendGitMetadata(repositoryUrl, configuration.sha, configuration.gitRoot)
|
|
475
462
|
} else {
|
|
476
463
|
this._resolveGit()
|
|
477
464
|
}
|
|
@@ -489,7 +476,7 @@ class CiVisibilityExporter extends BufferingExporter {
|
|
|
489
476
|
* @param {Function} done - Completion callback.
|
|
490
477
|
*/
|
|
491
478
|
_fetchLibraryConfigurationFromBackend (configuration, repositoryUrl, cacheKey, done) {
|
|
492
|
-
this.sendGitMetadata(repositoryUrl)
|
|
479
|
+
this.sendGitMetadata(repositoryUrl, configuration.sha, configuration.gitRoot)
|
|
493
480
|
getLibraryConfigurationRequest(configuration, (err, libraryConfig) => {
|
|
494
481
|
// Mirror the original live path: keep the phase-1 config on `_libraryConfig` even
|
|
495
482
|
// before the git upload resolves, so `shouldRequestSkippableSuites()` and the
|
|
@@ -523,17 +510,6 @@ class CiVisibilityExporter extends BufferingExporter {
|
|
|
523
510
|
})
|
|
524
511
|
}
|
|
525
512
|
|
|
526
|
-
/**
|
|
527
|
-
* Returns the deterministic cache error for offline exporters.
|
|
528
|
-
*
|
|
529
|
-
* @param {string} input required cache input
|
|
530
|
-
* @returns {Error} cache error
|
|
531
|
-
*/
|
|
532
|
-
_getCacheOnlyError (input) {
|
|
533
|
-
return this._testOptimizationHttpCache.getLastError?.() ||
|
|
534
|
-
new Error(`Offline Test Optimization validation requires a valid ${input} cache fixture.`)
|
|
535
|
-
}
|
|
536
|
-
|
|
537
513
|
// Takes into account potential kill switches
|
|
538
514
|
filterConfiguration (remoteConfiguration = EMPTY_SETTINGS) {
|
|
539
515
|
const { testOptimization } = this._config
|
|
@@ -604,7 +580,7 @@ class CiVisibilityExporter extends BufferingExporter {
|
|
|
604
580
|
}
|
|
605
581
|
}
|
|
606
582
|
|
|
607
|
-
sendGitMetadata (repositoryUrl) {
|
|
583
|
+
sendGitMetadata (repositoryUrl, sha, gitRoot = process.cwd()) {
|
|
608
584
|
if (!this._config.testOptimization.DD_CIVISIBILITY_GIT_UPLOAD_ENABLED) {
|
|
609
585
|
this._resolveGit()
|
|
610
586
|
return
|
|
@@ -631,7 +607,9 @@ class CiVisibilityExporter extends BufferingExporter {
|
|
|
631
607
|
log.debug('Successfully uploaded git metadata')
|
|
632
608
|
}
|
|
633
609
|
this._resolveGit(err)
|
|
634
|
-
}
|
|
610
|
+
},
|
|
611
|
+
sha,
|
|
612
|
+
gitRoot
|
|
635
613
|
)
|
|
636
614
|
})
|
|
637
615
|
}
|