dd-trace 5.134.0 → 5.136.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-3rdparty.csv +0 -1
- package/ci/cypress/support.js +15 -1
- package/ci/init.js +2 -22
- package/ci/test-annotations.d.ts +5 -0
- package/ci/test-annotations.js +5 -0
- package/ci/vitest-no-worker-init-annotations.mjs +4 -0
- package/ci/vitest-no-worker-init-node-setup.mjs +22 -0
- package/ci/vitest-no-worker-init-runner-setup.mjs +7 -32
- package/ci/vitest-no-worker-init-setup.mjs +34 -12
- package/ci/vitest-no-worker-init-v5-setup.mjs +6 -0
- package/ext/exporters.js +1 -1
- package/index.d.ts +124 -5
- package/initialize.mjs +5 -2
- package/lambda.d.ts +39 -0
- package/lambda.js +3 -0
- package/loader-hook.mjs +53 -0
- package/openfeature/exposure-hook.d.ts +66 -0
- package/openfeature/exposure-hook.js +5 -0
- package/package.json +19 -15
- package/packages/datadog-core/src/storage.js +1 -1
- package/packages/datadog-esbuild/index.js +78 -62
- package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
- package/packages/datadog-instrumentations/src/cucumber.js +56 -19
- package/packages/datadog-instrumentations/src/cypress-config.js +163 -15
- package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
- package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
- package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
- package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
- package/packages/datadog-instrumentations/src/graphql.js +29 -20
- package/packages/datadog-instrumentations/src/grpc/server.js +23 -6
- package/packages/{datadog-esbuild/src/utils.js → datadog-instrumentations/src/helpers/bundler-esm-exports.js} +282 -40
- package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +573 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
- package/packages/datadog-instrumentations/src/helpers/fetch.js +5 -1
- package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +30 -8
- package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
- package/packages/datadog-instrumentations/src/helpers/hooks.js +4 -8
- package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +18 -6
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +26 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +3 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +40 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/react-router.js +49 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/typesafe.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +12 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +58 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +19 -2
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +25 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
- package/packages/datadog-instrumentations/src/ioredis.js +101 -3
- package/packages/datadog-instrumentations/src/jest.js +265 -82
- package/packages/datadog-instrumentations/src/mariadb-bundle.js +69 -11
- package/packages/datadog-instrumentations/src/mariadb.js +13 -6
- package/packages/datadog-instrumentations/src/mocha/common.js +89 -8
- package/packages/datadog-instrumentations/src/mocha/main.js +11 -2
- package/packages/datadog-instrumentations/src/mocha/utils.js +58 -12
- package/packages/datadog-instrumentations/src/mocha/worker.js +1 -1
- package/packages/datadog-instrumentations/src/next.js +19 -6
- package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
- package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
- package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
- package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
- package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
- package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
- package/packages/datadog-instrumentations/src/oracledb.js +33 -0
- package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
- package/packages/datadog-instrumentations/src/pg.js +2 -1
- package/packages/datadog-instrumentations/src/playwright.js +81 -28
- package/packages/datadog-instrumentations/src/react-router.js +106 -0
- package/packages/datadog-instrumentations/src/typesafe.js +89 -0
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +84 -48
- package/packages/datadog-instrumentations/src/vitest-main.js +26 -0
- package/packages/datadog-instrumentations/src/vitest-test-annotations.js +20 -0
- package/packages/datadog-instrumentations/src/vitest-worker.js +39 -17
- package/packages/datadog-instrumentations/src/vitest.js +10 -8
- package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
- package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
- package/packages/datadog-plugin-cucumber/src/index.js +5 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +296 -55
- package/packages/datadog-plugin-cypress/src/index.js +1 -1
- package/packages/datadog-plugin-cypress/src/lifecycle-owner.js +20 -0
- package/packages/datadog-plugin-cypress/src/plugin.js +10 -0
- package/packages/datadog-plugin-cypress/src/retry-config-observer.js +281 -0
- package/packages/datadog-plugin-cypress/src/setup-handoff.js +125 -0
- package/packages/datadog-plugin-cypress/src/support.js +1217 -439
- package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -7
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -52
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +4 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
- package/packages/datadog-plugin-graphql/src/execute.js +2 -2
- package/packages/datadog-plugin-graphql/src/utils.js +5 -5
- package/packages/datadog-plugin-http/src/client.js +32 -9
- package/packages/datadog-plugin-http2/src/client.js +38 -13
- package/packages/datadog-plugin-jest/src/index.js +25 -3
- package/packages/datadog-plugin-mocha/src/index.js +47 -6
- package/packages/datadog-plugin-next/src/index.js +112 -14
- package/packages/datadog-plugin-oracledb/src/connection-parser.js +21 -11
- package/packages/datadog-plugin-playwright/src/index.js +4 -0
- package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
- package/packages/datadog-plugin-react-router/src/index.js +118 -0
- package/packages/datadog-plugin-trpc/src/index.js +15 -0
- package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
- package/packages/datadog-plugin-trpc/src/request.js +81 -0
- package/packages/datadog-plugin-typesafe/src/index.js +17 -0
- package/packages/datadog-plugin-typesafe/src/tracing.js +31 -0
- package/packages/datadog-plugin-undici/src/index.js +22 -7
- package/packages/datadog-plugin-vitest/src/index.js +8 -0
- package/packages/datadog-turbopack/index.js +4 -28
- package/packages/datadog-turbopack/src/loader.js +14 -452
- package/packages/datadog-webpack/index.js +3 -55
- package/packages/dd-trace/src/agent/info.js +2 -1
- package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
- package/packages/dd-trace/src/aiguard/sdk.js +8 -13
- package/packages/dd-trace/src/aiguard/tags.js +2 -0
- package/packages/dd-trace/src/appsec/blocking/index.js +4 -0
- package/packages/dd-trace/src/appsec/graphql.js +91 -6
- package/packages/dd-trace/src/appsec/recommended.json +1287 -90
- package/packages/dd-trace/src/before-exit.js +32 -0
- package/packages/dd-trace/src/bootstrap.js +5 -3
- package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +24 -18
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +16 -36
- package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
- package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +10 -18
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +10 -15
- package/packages/dd-trace/src/ci-visibility/requests/route.js +44 -0
- package/packages/dd-trace/src/ci-visibility/telemetry-logs.js +5 -0
- package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
- package/packages/dd-trace/src/ci-visibility/test-annotations.js +72 -0
- package/packages/dd-trace/src/ci-visibility/test-declaration-annotations.js +170 -0
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +10 -17
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
- package/packages/dd-trace/src/config/config-types.d.ts +3 -0
- package/packages/dd-trace/src/config/defaults.js +9 -3
- package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -2
- package/packages/dd-trace/src/config/index.js +111 -43
- package/packages/dd-trace/src/config/parsers.js +18 -1
- package/packages/dd-trace/src/config/supported-configurations.json +174 -4
- package/packages/dd-trace/src/constants.js +1 -0
- package/packages/dd-trace/src/debugger/pause-duration-histogram.js +2 -1
- package/packages/dd-trace/src/debugger/probe_sampler.js +6 -6
- package/packages/dd-trace/src/encode/0.4.js +2 -2
- package/packages/dd-trace/src/esm-module-load.js +58 -0
- package/packages/dd-trace/src/exporter.js +23 -15
- package/packages/dd-trace/src/exporters/agent/index.js +3 -1
- package/packages/dd-trace/src/exporters/agentless/index.js +3 -1
- package/packages/dd-trace/src/exporters/common/request.js +83 -50
- package/packages/dd-trace/src/exporters/common/retry.js +12 -7
- package/packages/dd-trace/src/exporters/common/url.js +1 -1
- package/packages/dd-trace/src/exporters/llmobs/index.js +135 -0
- package/packages/dd-trace/src/exporters/log/index.js +4 -3
- package/packages/dd-trace/src/id.js +1 -1
- package/packages/dd-trace/src/lambda/facade.js +74 -0
- package/packages/dd-trace/src/lambda/handler.js +3 -41
- package/packages/dd-trace/src/lambda/index.js +38 -15
- package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
- package/packages/dd-trace/src/lambda/wrap.js +44 -0
- package/packages/dd-trace/src/llmobs/constants/tags.js +3 -0
- package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
- package/packages/dd-trace/src/llmobs/experiments/index.js +2 -3
- package/packages/dd-trace/src/llmobs/experiments/noop.js +5 -2
- package/packages/dd-trace/src/llmobs/index.js +13 -2
- package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +27 -10
- package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
- package/packages/dd-trace/src/llmobs/plugins/typesafe/index.js +102 -0
- package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
- package/packages/dd-trace/src/llmobs/prompts/cache.js +3 -1
- package/packages/dd-trace/src/llmobs/sdk.js +21 -1
- package/packages/dd-trace/src/llmobs/span_processor.js +219 -12
- package/packages/dd-trace/src/llmobs/tagger.js +25 -0
- package/packages/dd-trace/src/llmobs/writers/util.js +3 -3
- package/packages/dd-trace/src/log/channels.js +4 -0
- package/packages/dd-trace/src/log/writer.js +13 -2
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +68 -6
- package/packages/dd-trace/src/openfeature/configuration_source.js +41 -17
- package/packages/dd-trace/src/openfeature/debug-logging-hook.js +66 -3
- package/packages/dd-trace/src/openfeature/exposure-hook.js +185 -0
- package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +58 -14
- package/packages/dd-trace/src/openfeature/remote_config.js +16 -3
- package/packages/dd-trace/src/openfeature/writers/base.js +63 -30
- package/packages/dd-trace/src/openfeature/writers/exposures.js +161 -1
- package/packages/dd-trace/src/openfeature/writers/flag-eval-evp-hook.js +5 -0
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-aggregation.js +9 -4
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-payload.js +2 -0
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-pii.js +2 -0
- package/packages/dd-trace/src/openfeature/writers/split-features.js +25 -0
- package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
- package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
- package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -2
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
- package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
- package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
- package/packages/dd-trace/src/opentelemetry/span.js +2 -2
- package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
- package/packages/dd-trace/src/opentelemetry/tracer_provider.js +5 -1
- package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
- package/packages/dd-trace/src/opentracing/tracer.js +33 -13
- package/packages/dd-trace/src/otel-thread-ctx.js +72 -49
- package/packages/dd-trace/src/plugin_manager.js +34 -7
- package/packages/dd-trace/src/plugins/ci_plugin.js +45 -14
- package/packages/dd-trace/src/plugins/index.js +9 -0
- package/packages/dd-trace/src/plugins/plugin.js +4 -2
- package/packages/dd-trace/src/plugins/tracing.js +1 -1
- package/packages/dd-trace/src/plugins/util/ci.js +18 -1
- package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
- package/packages/dd-trace/src/plugins/util/git.js +273 -86
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +77 -50
- package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
- package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
- package/packages/dd-trace/src/plugins/util/tags.js +6 -0
- package/packages/dd-trace/src/plugins/util/test.js +90 -45
- package/packages/dd-trace/src/plugins/util/url.js +10 -2
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -2
- package/packages/dd-trace/src/plugins/util/web.js +81 -10
- package/packages/dd-trace/src/process-tags/index.js +1 -1
- package/packages/dd-trace/src/profiling/config.js +6 -3
- package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
- package/packages/dd-trace/src/proxy.js +48 -57
- package/packages/dd-trace/src/serverless.js +3 -2
- package/packages/dd-trace/src/span_processor.js +41 -9
- package/packages/dd-trace/src/span_stats.js +28 -2
- package/packages/dd-trace/src/startup-log.js +8 -5
- package/packages/dd-trace/src/tagger.js +7 -5
- package/packages/dd-trace/src/telemetry/dependencies.js +4 -0
- package/packages/dd-trace/src/telemetry/index.js +3 -0
- package/packages/dd-trace/src/telemetry/logs/index.js +21 -2
- package/packages/dd-trace/src/telemetry/logs/log-collector.js +1 -0
- package/packages/dd-trace/src/telemetry/metrics.js +2 -1
- package/packages/dd-trace/src/telemetry/telemetry.js +10 -3
- package/packages/dd-trace/src/tracer.js +0 -2
- package/packages/dd-trace/src/util.js +1 -1
- package/packages/dd-trace/src/web-tags-cache.js +8 -9
- package/register.js +4 -2
- package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
- package/vendor/dist/{@opentelemetry/resources → @datadog/flagging-core}/LICENSE +22 -2
- package/vendor/dist/@datadog/flagging-core/index.js +1 -0
- package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
- package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.d.ts +78 -0
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.js +1 -1
- package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
- package/vendor/dist/@datadog/source-map/LICENSE +1 -0
- package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
- package/vendor/dist/@opentelemetry/core/LICENSE +209 -1
- package/vendor/dist/@opentelemetry/core/index.js +1 -1
- package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
- package/vendor/dist/escape-string-regexp/LICENSE +13 -0
- package/vendor/dist/esquery/LICENSE +2 -0
- package/vendor/dist/https-proxy-agent/LICENSE +80 -1
- package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
- package/vendor/dist/jest-docblock/LICENSE +16 -0
- package/vendor/dist/jsonpath-plus/LICENSE +13 -0
- package/vendor/dist/limiter/LICENSE +2 -0
- package/vendor/dist/lodash.sortby/LICENSE +2 -0
- package/vendor/dist/lru-cache/LICENSE +13 -0
- package/vendor/dist/meriyah/LICENSE +13 -0
- package/vendor/dist/module-details-from-path/LICENSE +2 -0
- package/vendor/dist/mutexify/promise/LICENSE +28 -0
- package/vendor/dist/pprof-format/LICENSE +13 -0
- package/vendor/dist/pprof-format/index.js +1 -1
- package/vendor/dist/protobufjs/LICENSE +219 -0
- package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
- package/vendor/dist/proxy-from-env/LICENSE +13 -0
- package/vendor/dist/retry/LICENSE +2 -0
- package/vendor/dist/rfdc/LICENSE +2 -0
- package/vendor/dist/semifies/LICENSE +3 -1
- package/vendor/dist/shell-quote/LICENSE +3 -1
- package/vendor/dist/source-map/LICENSE +1 -0
- package/vendor/dist/source-map/lib/util/LICENSE +1 -0
- package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
- package/vendor/dist/ttl-set/LICENSE +28 -0
- package/ci/diagnose.js +0 -2215
- package/ci/runbook.md +0 -299
- package/ci/test-optimization-validation/approval-artifacts.js +0 -175
- package/ci/test-optimization-validation/approval.js +0 -386
- package/ci/test-optimization-validation/artifact-id.js +0 -19
- package/ci/test-optimization-validation/blocker-category.js +0 -24
- package/ci/test-optimization-validation/bounded-json.js +0 -120
- package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
- package/ci/test-optimization-validation/ci-discovery.js +0 -192
- package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
- package/ci/test-optimization-validation/ci-remediation.js +0 -283
- package/ci/test-optimization-validation/cli.js +0 -954
- package/ci/test-optimization-validation/command-blocker.js +0 -377
- package/ci/test-optimization-validation/command-output-policy.js +0 -188
- package/ci/test-optimization-validation/command-runner.js +0 -650
- package/ci/test-optimization-validation/environment.js +0 -88
- package/ci/test-optimization-validation/executable-approval.js +0 -47
- package/ci/test-optimization-validation/executable.js +0 -244
- package/ci/test-optimization-validation/execution-lock.js +0 -70
- package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
- package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
- package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
- package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
- package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
- package/ci/test-optimization-validation/generated-file-policy.js +0 -63
- package/ci/test-optimization-validation/generated-files.js +0 -425
- package/ci/test-optimization-validation/generated-test-contract.js +0 -284
- package/ci/test-optimization-validation/generated-verifier.js +0 -235
- package/ci/test-optimization-validation/literal-environment.js +0 -56
- package/ci/test-optimization-validation/literal-glob.js +0 -52
- package/ci/test-optimization-validation/manifest-loader.js +0 -116
- package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
- package/ci/test-optimization-validation/manifest-schema.js +0 -695
- package/ci/test-optimization-validation/offline-fixtures.js +0 -335
- package/ci/test-optimization-validation/offline-output.js +0 -406
- package/ci/test-optimization-validation/package-check.js +0 -97
- package/ci/test-optimization-validation/payload-normalizer.js +0 -72
- package/ci/test-optimization-validation/plan-writer.js +0 -541
- package/ci/test-optimization-validation/preflight-runner.js +0 -186
- package/ci/test-optimization-validation/project-build-artifact.js +0 -31
- package/ci/test-optimization-validation/redaction.js +0 -319
- package/ci/test-optimization-validation/report-writer.js +0 -666
- package/ci/test-optimization-validation/result-semantics.js +0 -103
- package/ci/test-optimization-validation/runner-command.js +0 -264
- package/ci/test-optimization-validation/runner-contract.js +0 -695
- package/ci/test-optimization-validation/safe-files.js +0 -202
- package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
- package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
- package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
- package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
- package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
- package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
- package/ci/test-optimization-validation/source-text.js +0 -84
- package/ci/test-optimization-validation/static-diagnosis.js +0 -166
- package/ci/test-optimization-validation/test-output.js +0 -120
- package/ci/test-optimization-validation/validation-blocker.js +0 -21
- package/ci/validate-test-optimization.js +0 -3
- package/packages/datadog-esbuild/src/resolver.js +0 -284
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
- package/vendor/dist/@opentelemetry/resources/index.js +0 -1
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const path = require('node:path')
|
|
4
|
-
|
|
5
|
-
const DEFAULT_CI_SEARCHES = [
|
|
6
|
-
'.github/workflows/*.yml',
|
|
7
|
-
'.github/workflows/*.yaml',
|
|
8
|
-
'.gitlab-ci.yml',
|
|
9
|
-
'.gitlab-ci.yaml',
|
|
10
|
-
'.circleci/config.yml',
|
|
11
|
-
'.circleci/config.yaml',
|
|
12
|
-
'.buildkite/pipeline.yml',
|
|
13
|
-
'.buildkite/pipeline.yaml',
|
|
14
|
-
'bitbucket-pipelines.yml',
|
|
15
|
-
'bitbucket-pipelines.yaml',
|
|
16
|
-
'azure-pipelines.yml',
|
|
17
|
-
'azure-pipelines.yaml',
|
|
18
|
-
'.azure-pipelines/*.yml',
|
|
19
|
-
'.azure-pipelines/*.yaml',
|
|
20
|
-
'Jenkinsfile',
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
function annotateCiDiscovery ({ manifest, diagnosis }) {
|
|
24
|
-
manifest.ciDiscovery = buildCiDiscovery({ manifest, diagnosis })
|
|
25
|
-
|
|
26
|
-
if (manifest.ciDiscovery.contradictions.length === 0) return
|
|
27
|
-
|
|
28
|
-
const warnings = Array.isArray(manifest.warnings) ? manifest.warnings : []
|
|
29
|
-
for (const contradiction of manifest.ciDiscovery.contradictions) {
|
|
30
|
-
const warning = `CI discovery contradiction: ${contradiction}`
|
|
31
|
-
if (!warnings.includes(warning)) warnings.push(warning)
|
|
32
|
-
}
|
|
33
|
-
manifest.warnings = warnings
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function buildCiDiscovery ({ manifest, diagnosis }) {
|
|
37
|
-
const declared = isObject(manifest.ciDiscovery) ? manifest.ciDiscovery : {}
|
|
38
|
-
const staticFound = getStaticWorkflowLocations(diagnosis)
|
|
39
|
-
const declaredFound = normalizeStringArray(declared.found)
|
|
40
|
-
const candidateFound = getManifestWorkflowLocations(manifest)
|
|
41
|
-
const manifestFound = uniqueStrings([...declaredFound, ...candidateFound])
|
|
42
|
-
const searched = normalizeStringArray(declared.searched)
|
|
43
|
-
let method = candidateFound.length > 0 ? 'framework-ci-command' : 'validator-static-diagnosis'
|
|
44
|
-
if (declaredFound.length > 0) method = 'manifest'
|
|
45
|
-
if (typeof declared.method === 'string' && declared.method) method = declared.method
|
|
46
|
-
const found = manifestFound.length > 0 ? manifestFound : staticFound
|
|
47
|
-
const contradictions = getCiDiscoveryContradictions({ manifest, declaredFound: manifestFound, staticFound })
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
searched: searched.length > 0 ? searched : DEFAULT_CI_SEARCHES,
|
|
51
|
-
found,
|
|
52
|
-
staticFound,
|
|
53
|
-
method,
|
|
54
|
-
warnings: normalizeStringArray(declared.warnings),
|
|
55
|
-
notes: normalizeStringArray(declared.notes),
|
|
56
|
-
contradictions,
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function getManifestWorkflowLocations (manifest) {
|
|
61
|
-
const root = manifest.repository?.root
|
|
62
|
-
const locations = []
|
|
63
|
-
if (manifest.frameworks) {
|
|
64
|
-
for (const framework of manifest.frameworks) {
|
|
65
|
-
const configFile = framework.ciWiring?.configFile
|
|
66
|
-
if (typeof configFile !== 'string') continue
|
|
67
|
-
if (!root || !path.isAbsolute(configFile)) {
|
|
68
|
-
locations.push(configFile)
|
|
69
|
-
continue
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const relative = path.relative(root, configFile)
|
|
73
|
-
const isRelativePath = relative && relative !== '..' && !relative.startsWith(`..${path.sep}`) &&
|
|
74
|
-
!path.isAbsolute(relative)
|
|
75
|
-
locations.push(isRelativePath
|
|
76
|
-
? relative.split(path.sep).join('/')
|
|
77
|
-
: configFile)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return uniqueStrings(locations)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function getFrameworkCiDiscoveryContradiction (framework, manifest) {
|
|
84
|
-
const ciDiscovery = manifest?.ciDiscovery
|
|
85
|
-
if (
|
|
86
|
-
!ciDiscovery ||
|
|
87
|
-
!Array.isArray(ciDiscovery.staticFound) ||
|
|
88
|
-
ciDiscovery.staticFound.length === 0 ||
|
|
89
|
-
!frameworkClaimsNoCi(framework)
|
|
90
|
-
) {
|
|
91
|
-
return null
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
reason: 'CI workflow files were found by validator static diagnosis, but this manifest entry says no CI ' +
|
|
96
|
-
'workflow was found. The manifest cannot support a "no CI workflow found" conclusion.',
|
|
97
|
-
recommendation: 'Inspect the discovered CI files with hidden-directory-aware discovery, then update ciWiring, ' +
|
|
98
|
-
'ciWiring configuration evidence, omittedTestCommands, notes, or unresolved blockers before validation.',
|
|
99
|
-
ciDiscovery,
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function manifestHasCiDiscoveryContradiction (manifest) {
|
|
104
|
-
return Array.isArray(manifest?.ciDiscovery?.contradictions) &&
|
|
105
|
-
manifest.ciDiscovery.contradictions.length > 0
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function getCiDiscoveryContradictions ({ manifest, declaredFound, staticFound }) {
|
|
109
|
-
if (staticFound.length === 0) return []
|
|
110
|
-
|
|
111
|
-
const contradictions = []
|
|
112
|
-
if (isObject(manifest.ciDiscovery) && declaredFound.length === 0) {
|
|
113
|
-
contradictions.push(
|
|
114
|
-
`manifest ciDiscovery.found is empty, but static diagnosis found ${formatList(staticFound)}`
|
|
115
|
-
)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (manifest.frameworks) {
|
|
119
|
-
for (const framework of manifest.frameworks) {
|
|
120
|
-
if (!frameworkClaimsNoCi(framework)) continue
|
|
121
|
-
contradictions.push(
|
|
122
|
-
`framework ${framework.id || '<unknown>'} records no CI workflow, but static diagnosis found ` +
|
|
123
|
-
formatList(staticFound)
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return contradictions
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function frameworkClaimsNoCi (framework) {
|
|
132
|
-
const ciWiring = framework?.ciWiring
|
|
133
|
-
if (!isObject(ciWiring)) return false
|
|
134
|
-
if (ciWiring.provider === 'none') return true
|
|
135
|
-
|
|
136
|
-
return textClaimsNoCi([
|
|
137
|
-
ciWiring.diagnosis,
|
|
138
|
-
...(Array.isArray(ciWiring.unresolved) ? ciWiring.unresolved : []),
|
|
139
|
-
...(Array.isArray(framework.notes) ? framework.notes : []),
|
|
140
|
-
])
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function textClaimsNoCi (values) {
|
|
144
|
-
return values.some(value => {
|
|
145
|
-
if (typeof value !== 'string') return false
|
|
146
|
-
return /no .*ci .*workflow/i.test(value) ||
|
|
147
|
-
/no .*ci .*configuration/i.test(value) ||
|
|
148
|
-
/no github actions.*gitlab.*circleci.*jenkins/i.test(value)
|
|
149
|
-
})
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function getStaticWorkflowLocations (diagnosis) {
|
|
153
|
-
const results = Array.isArray(diagnosis?.results) ? diagnosis.results : []
|
|
154
|
-
const locations = []
|
|
155
|
-
const seen = new Set()
|
|
156
|
-
|
|
157
|
-
for (const result of results) {
|
|
158
|
-
if (result.title !== 'CI workflow files found' || !Array.isArray(result.locations)) continue
|
|
159
|
-
for (const location of result.locations) {
|
|
160
|
-
if (typeof location !== 'string' || seen.has(location)) continue
|
|
161
|
-
seen.add(location)
|
|
162
|
-
locations.push(location)
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return locations
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function normalizeStringArray (value) {
|
|
170
|
-
if (!Array.isArray(value)) return []
|
|
171
|
-
return value.filter(item => typeof item === 'string')
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function uniqueStrings (values) {
|
|
175
|
-
return [...new Set(values.filter(value => typeof value === 'string' && value !== ''))]
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function formatList (values) {
|
|
179
|
-
return values.map(value => `"${value}"`).join(', ')
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function isObject (value) {
|
|
183
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
module.exports = {
|
|
187
|
-
annotateCiDiscovery,
|
|
188
|
-
buildCiDiscovery,
|
|
189
|
-
getFrameworkCiDiscoveryContradiction,
|
|
190
|
-
getStaticWorkflowLocations,
|
|
191
|
-
manifestHasCiDiscoveryContradiction,
|
|
192
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { parseLiteralEnvironmentPrefix } = require('./literal-environment')
|
|
4
|
-
|
|
5
|
-
const MAX_SCRIPT_EXPANSIONS = 16
|
|
6
|
-
const DYNAMIC_VALUE_PATTERN = /[$`\r\n]|%[^%\s]+%|![^!\s]+!/
|
|
7
|
-
const RESERVED_PACKAGE_MANAGER_COMMANDS = {
|
|
8
|
-
pnpm: new Set([
|
|
9
|
-
'add', 'audit', 'bin', 'c', 'config', 'create', 'deploy', 'dlx', 'env', 'exec', 'fetch', 'i', 'import', 'init',
|
|
10
|
-
'install', 'link', 'list', 'ln', 'ls', 'outdated', 'pack', 'patch', 'patch-commit', 'prune', 'publish', 'rebuild',
|
|
11
|
-
'remove', 'rm', 'root', 'self-update', 'server', 'setup', 'store', 'uninstall', 'unlink', 'up', 'update', 'view',
|
|
12
|
-
'why',
|
|
13
|
-
]),
|
|
14
|
-
yarn: new Set([
|
|
15
|
-
'add', 'audit', 'bin', 'cache', 'check', 'config', 'constraints', 'create', 'dedupe', 'dlx', 'exec', 'global',
|
|
16
|
-
'help', 'import', 'info', 'init', 'install', 'link', 'list', 'node', 'npm', 'outdated', 'owner', 'pack', 'patch',
|
|
17
|
-
'plugin', 'policies', 'publish', 'rebuild', 'remove', 'set', 'stage', 'tag', 'team', 'unlink', 'unplug', 'up',
|
|
18
|
-
'upgrade', 'version', 'versions', 'why', 'workspace', 'workspaces',
|
|
19
|
-
]),
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Expands bounded local package-script references without executing them.
|
|
24
|
-
*
|
|
25
|
-
* @param {string} command selected CI command
|
|
26
|
-
* @param {Record<string, string>} scripts package.json scripts
|
|
27
|
-
* @returns {{error?: string, lifecycleScripts: string[], terminals: object[]}} expansion
|
|
28
|
-
*/
|
|
29
|
-
function expandLocalPackageScripts (command, scripts) {
|
|
30
|
-
const state = { count: 0, lifecycleScripts: new Set() }
|
|
31
|
-
const result = expandCommand(command, scripts || {}, [], new Set(), state)
|
|
32
|
-
return {
|
|
33
|
-
...(result.error ? { error: result.error } : {}),
|
|
34
|
-
lifecycleScripts: [...state.lifecycleScripts],
|
|
35
|
-
terminals: result.terminals || [],
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function expandCommand (command, scripts, path, stack, state) {
|
|
40
|
-
if (++state.count > MAX_SCRIPT_EXPANSIONS) {
|
|
41
|
-
return { error: `local package-script expansion exceeded ${MAX_SCRIPT_EXPANSIONS} commands` }
|
|
42
|
-
}
|
|
43
|
-
const segments = splitLiteralAndChain(command)
|
|
44
|
-
if (!segments) return { error: 'the command contains unsupported dynamic shell syntax' }
|
|
45
|
-
|
|
46
|
-
const terminals = []
|
|
47
|
-
for (const segment of segments) {
|
|
48
|
-
if (hasStatefulShellSemantics(segment)) {
|
|
49
|
-
return { error: 'the command contains unsupported stateful shell semantics' }
|
|
50
|
-
}
|
|
51
|
-
const invocation = getPackageScriptInvocation(segment)
|
|
52
|
-
if (!invocation) {
|
|
53
|
-
terminals.push({ command: segment, path: [...path, segment] })
|
|
54
|
-
continue
|
|
55
|
-
}
|
|
56
|
-
if (typeof scripts[invocation.script] !== 'string') {
|
|
57
|
-
return { error: `local package script ${invocation.script} is unavailable` }
|
|
58
|
-
}
|
|
59
|
-
if (stack.has(invocation.script)) {
|
|
60
|
-
return { error: `local package-script cycle includes ${invocation.script}` }
|
|
61
|
-
}
|
|
62
|
-
const lifecycleNames = invocation.manager === 'npm' || invocation.manager === 'bun'
|
|
63
|
-
? [`pre${invocation.script}`, `post${invocation.script}`]
|
|
64
|
-
.filter(name => typeof scripts[name] === 'string')
|
|
65
|
-
: []
|
|
66
|
-
for (const lifecycle of lifecycleNames) state.lifecycleScripts.add(lifecycle)
|
|
67
|
-
|
|
68
|
-
for (const scriptName of [
|
|
69
|
-
...(lifecycleNames.includes(`pre${invocation.script}`) ? [`pre${invocation.script}`] : []),
|
|
70
|
-
invocation.script,
|
|
71
|
-
...(lifecycleNames.includes(`post${invocation.script}`) ? [`post${invocation.script}`] : []),
|
|
72
|
-
]) {
|
|
73
|
-
if (stack.has(scriptName)) return { error: `local package-script cycle includes ${scriptName}` }
|
|
74
|
-
const nextStack = new Set(stack)
|
|
75
|
-
nextStack.add(invocation.script)
|
|
76
|
-
nextStack.add(scriptName)
|
|
77
|
-
const scriptCommand = scriptName === invocation.script && invocation.arguments
|
|
78
|
-
? `${scripts[scriptName]} ${invocation.arguments}`
|
|
79
|
-
: scripts[scriptName]
|
|
80
|
-
const expanded = expandCommand(
|
|
81
|
-
scriptCommand,
|
|
82
|
-
scripts,
|
|
83
|
-
[...path, segment],
|
|
84
|
-
nextStack,
|
|
85
|
-
state
|
|
86
|
-
)
|
|
87
|
-
if (expanded.error) return expanded
|
|
88
|
-
terminals.push(...expanded.terminals)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return { terminals }
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Splits only literal `&&` chains and rejects other shell control flow or expansion.
|
|
96
|
-
*
|
|
97
|
-
* @param {string} command command text
|
|
98
|
-
* @returns {string[]|undefined} literal command segments
|
|
99
|
-
*/
|
|
100
|
-
function splitLiteralAndChain (command) {
|
|
101
|
-
const source = String(command || '').trim()
|
|
102
|
-
if (!source || DYNAMIC_VALUE_PATTERN.test(source)) return
|
|
103
|
-
const segments = []
|
|
104
|
-
let quote
|
|
105
|
-
let start = 0
|
|
106
|
-
|
|
107
|
-
for (let index = 0; index < source.length; index++) {
|
|
108
|
-
const character = source[index]
|
|
109
|
-
if (character === '\\') {
|
|
110
|
-
index++
|
|
111
|
-
continue
|
|
112
|
-
}
|
|
113
|
-
if (quote) {
|
|
114
|
-
if (character === quote) quote = undefined
|
|
115
|
-
continue
|
|
116
|
-
}
|
|
117
|
-
if (character === '"' || character === "'") {
|
|
118
|
-
quote = character
|
|
119
|
-
continue
|
|
120
|
-
}
|
|
121
|
-
if (character === '&' && source[index + 1] === '&') {
|
|
122
|
-
const segment = source.slice(start, index).trim()
|
|
123
|
-
if (!segment) return
|
|
124
|
-
segments.push(segment)
|
|
125
|
-
start = ++index + 1
|
|
126
|
-
continue
|
|
127
|
-
}
|
|
128
|
-
if (';&|()'.includes(character)) return
|
|
129
|
-
}
|
|
130
|
-
if (quote) return
|
|
131
|
-
const finalSegment = source.slice(start).trim()
|
|
132
|
-
if (!finalSegment) return
|
|
133
|
-
segments.push(finalSegment)
|
|
134
|
-
return segments
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function hasStatefulShellSemantics (command) {
|
|
138
|
-
const prefix = parseLiteralEnvironmentPrefix(command)
|
|
139
|
-
const executable = command.slice(prefix.length).trim()
|
|
140
|
-
return !executable ||
|
|
141
|
-
/^(?:cd|eval|exec|export|popd|pushd|set|source|unset)\b/.test(executable) ||
|
|
142
|
-
/^\.(?:\s|$)/.test(executable)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function getPackageScriptInvocation (command) {
|
|
146
|
-
const literalPrefix = parseLiteralEnvironmentPrefix(command)
|
|
147
|
-
const source = command.slice(literalPrefix.length).trim()
|
|
148
|
-
.replace(/^(?:c8|nyc)(?:\.cmd)?\s+/, '')
|
|
149
|
-
const match = /^(bun|npm(?:\.cmd)?|pnpm(?:\.cmd)?|yarn(?:pkg)?(?:\.cmd)?)\s+(?:(run|run-script)\s+)?([\w:-]+)(?:\s+(\S.*))?$/
|
|
150
|
-
.exec(source)
|
|
151
|
-
if (!match) return
|
|
152
|
-
|
|
153
|
-
const manager = match[1].replace(/\.cmd$/i, '').replace(/^yarnpkg$/, 'yarn')
|
|
154
|
-
if (manager === 'npm' && !match[2] && !['restart', 'start', 'stop', 'test'].includes(match[3])) return
|
|
155
|
-
if (manager === 'bun' && match[2] !== 'run') return
|
|
156
|
-
if (!match[2] && RESERVED_PACKAGE_MANAGER_COMMANDS[manager]?.has(match[3])) return
|
|
157
|
-
const args = match[4]?.trim()
|
|
158
|
-
const separatedArguments = args ? /^--(?:\s+(\S.*))?$/.exec(args) : undefined
|
|
159
|
-
if (['npm', 'pnpm'].includes(manager) && args && !separatedArguments) return
|
|
160
|
-
const scriptArguments = ['npm', 'pnpm'].includes(manager) ? separatedArguments?.[1]?.trim() : args
|
|
161
|
-
if (scriptArguments && !splitLiteralAndChain(scriptArguments)) return
|
|
162
|
-
return {
|
|
163
|
-
...(scriptArguments ? { arguments: scriptArguments } : {}),
|
|
164
|
-
manager,
|
|
165
|
-
script: match[3],
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
module.exports = { expandLocalPackageScripts }
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const path = require('node:path')
|
|
4
|
-
|
|
5
|
-
const { findEnvironmentEntry } = require('./environment')
|
|
6
|
-
const { splitNodeOptions } = require('./executable')
|
|
7
|
-
const { removeEmptyLiteralEnvironmentAssignments } = require('./literal-environment')
|
|
8
|
-
|
|
9
|
-
const GITHUB_API_KEY_REFERENCE = '$' + '{{ secrets.DD_API_KEY }}'
|
|
10
|
-
const AGENTLESS_ENV = {
|
|
11
|
-
DD_CIVISIBILITY_AGENTLESS_ENABLED: 'true',
|
|
12
|
-
DD_API_KEY: GITHUB_API_KEY_REFERENCE,
|
|
13
|
-
}
|
|
14
|
-
const OPTIONAL_VALUES = {
|
|
15
|
-
agent: [],
|
|
16
|
-
agentless: [
|
|
17
|
-
{
|
|
18
|
-
name: 'DD_SITE',
|
|
19
|
-
description: 'Set when the Datadog account does not use the default datadoghq.com site.',
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Builds a customer-facing CI configuration fix without including real credentials.
|
|
26
|
-
*
|
|
27
|
-
* @param {object} framework normalized framework manifest entry
|
|
28
|
-
* @returns {object} structured remediation
|
|
29
|
-
*/
|
|
30
|
-
function buildCiRemediation (framework) {
|
|
31
|
-
const ciWiring = framework.ciWiring || {}
|
|
32
|
-
const transport = getConfiguredTransport(framework)
|
|
33
|
-
const location = getCiLocation(ciWiring)
|
|
34
|
-
const nodeOptions = getNodeOptions(framework)
|
|
35
|
-
const recommendedValues = getRecommendedValues(framework)
|
|
36
|
-
const variants = getVariants(transport, ciWiring, recommendedValues, nodeOptions)
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
provider: ciWiring.provider || 'unknown',
|
|
40
|
-
configFile: ciWiring.configFile,
|
|
41
|
-
workflow: ciWiring.workflow,
|
|
42
|
-
job: ciWiring.job,
|
|
43
|
-
step: ciWiring.step,
|
|
44
|
-
location,
|
|
45
|
-
transport,
|
|
46
|
-
summary: getSummary({ location, transport, recommendedValues, nodeOptions }),
|
|
47
|
-
variants,
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function getConfiguredTransport (framework) {
|
|
52
|
-
const mode = framework.ciWiring?.transport?.mode
|
|
53
|
-
return ['agentless', 'agent', 'none'].includes(mode) ? mode : 'unknown'
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function getCiLocation (ciWiring) {
|
|
57
|
-
let location = ''
|
|
58
|
-
if (ciWiring.configFile) location += `configuration ${formatPath(ciWiring.configFile)}`
|
|
59
|
-
if (ciWiring.workflow) location += `${location ? ', ' : ''}workflow ${JSON.stringify(String(ciWiring.workflow))}`
|
|
60
|
-
if (ciWiring.job) location += `${location ? ', ' : ''}job ${JSON.stringify(String(ciWiring.job))}`
|
|
61
|
-
if (ciWiring.step) location += `${location ? ', ' : ''}step ${JSON.stringify(String(ciWiring.step))}`
|
|
62
|
-
return location || 'the selected CI test step'
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function formatPath (filename) {
|
|
66
|
-
const value = String(filename)
|
|
67
|
-
const cwd = process.cwd()
|
|
68
|
-
const relative = path.relative(cwd, value)
|
|
69
|
-
return JSON.stringify(relative && !relative.startsWith('..') && !path.isAbsolute(relative) ? relative : value)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function getSummary ({ location, transport, recommendedValues, nodeOptions }) {
|
|
73
|
-
const recommended = recommendedValues.map(({ name, value }) => `${name}=${value}`).join(' and ')
|
|
74
|
-
if (transport === 'agentless') {
|
|
75
|
-
return `In ${location}, set NODE_OPTIONS=${nodeOptions}, keep ` +
|
|
76
|
-
`DD_CIVISIBILITY_AGENTLESS_ENABLED=true, provide DD_API_KEY from the CI secret store, and set ${recommended}. ` +
|
|
77
|
-
getAgentAlternative()
|
|
78
|
-
}
|
|
79
|
-
if (transport === 'agent') {
|
|
80
|
-
return `In ${location}, set NODE_OPTIONS=${nodeOptions} and set ${recommended}. A Datadog Agent is ` +
|
|
81
|
-
'already configured; when it is reachable by the test process, do not pass DD_API_KEY or ' +
|
|
82
|
-
'DD_CIVISIBILITY_AGENTLESS_ENABLED.'
|
|
83
|
-
}
|
|
84
|
-
return `In ${location}, set NODE_OPTIONS=${nodeOptions}, ` +
|
|
85
|
-
`DD_CIVISIBILITY_AGENTLESS_ENABLED=true, provide DD_API_KEY from the CI secret store, and set ${recommended}. ` +
|
|
86
|
-
getAgentAlternative()
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function getAgentAlternative () {
|
|
90
|
-
return 'If a Datadog Agent is available and reachable by the test process, do not pass DD_API_KEY or ' +
|
|
91
|
-
'DD_CIVISIBILITY_AGENTLESS_ENABLED.'
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function getVariants (transport, ciWiring, recommendedValues, nodeOptions) {
|
|
95
|
-
if (transport === 'agent') return [getVariant('agent', ciWiring, recommendedValues, nodeOptions)]
|
|
96
|
-
return [getVariant('agentless', ciWiring, recommendedValues, nodeOptions)]
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function getVariant (transport, ciWiring, recommendedValues, nodeOptions) {
|
|
100
|
-
const transportEnv = transport === 'agentless' ? AGENTLESS_ENV : {}
|
|
101
|
-
const requiredEnv = { NODE_OPTIONS: nodeOptions, ...transportEnv }
|
|
102
|
-
const recommendedEnv = Object.fromEntries(recommendedValues.map(({ name, value }) => [name, value]))
|
|
103
|
-
return {
|
|
104
|
-
id: transport,
|
|
105
|
-
name: transport === 'agentless' ? 'Agentless reporting' : 'Datadog Agent available to the CI job',
|
|
106
|
-
prerequisite: transport === 'agentless'
|
|
107
|
-
? 'Store the Datadog API key in the CI provider secret store.'
|
|
108
|
-
: 'A Datadog Agent must be reachable from the CI test job.',
|
|
109
|
-
requiredValues: Object.entries(requiredEnv).map(([name, value]) => ({
|
|
110
|
-
name,
|
|
111
|
-
value,
|
|
112
|
-
source: name === 'DD_API_KEY' ? 'ci-secret-store' : 'literal',
|
|
113
|
-
})),
|
|
114
|
-
recommendedValues,
|
|
115
|
-
optionalValues: OPTIONAL_VALUES[transport],
|
|
116
|
-
snippet: formatSnippet({ ...requiredEnv, ...recommendedEnv }, ciWiring),
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function getNodeOptions (framework) {
|
|
121
|
-
const existing = getEffectiveNodeOptions(framework.ciWiring)
|
|
122
|
-
const options = existing ? [existing] : []
|
|
123
|
-
if (framework.framework === 'vitest' &&
|
|
124
|
-
!hasNodeModuleOption(existing, ['--import'], isDatadogRegisterSpecifier)) {
|
|
125
|
-
options.push('--import dd-trace/register.js')
|
|
126
|
-
}
|
|
127
|
-
if (!hasNodeModuleOption(existing, ['-r', '--require'], isDatadogCiInitSpecifier)) {
|
|
128
|
-
options.push('-r dd-trace/ci/init')
|
|
129
|
-
}
|
|
130
|
-
return options.join(' ')
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function getEffectiveNodeOptions (ciWiring = {}) {
|
|
134
|
-
const platform = getCiPlatform(ciWiring)
|
|
135
|
-
let value
|
|
136
|
-
for (const field of ['inheritedEnv', 'workflowEnv', 'jobEnv', 'stepEnv']) {
|
|
137
|
-
const entry = findEnvironmentEntry(ciWiring[field], 'NODE_OPTIONS', platform)
|
|
138
|
-
if (entry) value = entry[1]
|
|
139
|
-
}
|
|
140
|
-
if (typeof value !== 'string') return ''
|
|
141
|
-
const literal = value.trim()
|
|
142
|
-
return hasDynamicEnvironmentReference(literal) ? '' : literal
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function hasNodeModuleOption (value, optionNames, matchesSpecifier) {
|
|
146
|
-
if (!value) return false
|
|
147
|
-
let args
|
|
148
|
-
try {
|
|
149
|
-
args = splitNodeOptions(value)
|
|
150
|
-
} catch {
|
|
151
|
-
return false
|
|
152
|
-
}
|
|
153
|
-
for (let index = 0; index < args.length; index++) {
|
|
154
|
-
const argument = args[index]
|
|
155
|
-
let specifier
|
|
156
|
-
if (optionNames.includes(argument)) {
|
|
157
|
-
specifier = args[++index]
|
|
158
|
-
} else {
|
|
159
|
-
for (const optionName of optionNames) {
|
|
160
|
-
const prefix = `${optionName}=`
|
|
161
|
-
if (argument.startsWith(prefix)) specifier = argument.slice(prefix.length)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (matchesSpecifier(specifier)) return true
|
|
165
|
-
}
|
|
166
|
-
return false
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function isDatadogCiInitSpecifier (specifier) {
|
|
170
|
-
return isDatadogModuleSpecifier(specifier, 'ci/init')
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function isDatadogRegisterSpecifier (specifier) {
|
|
174
|
-
return isDatadogModuleSpecifier(specifier, 'register')
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function isDatadogModuleSpecifier (specifier, entrypoint) {
|
|
178
|
-
if (typeof specifier !== 'string') return false
|
|
179
|
-
const normalized = specifier.replaceAll('\\', '/')
|
|
180
|
-
return [`dd-trace/${entrypoint}`, `dd-trace/${entrypoint}.js`].some(candidate => {
|
|
181
|
-
return normalized === candidate || normalized.endsWith(`/${candidate}`)
|
|
182
|
-
})
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function hasDynamicEnvironmentReference (value) {
|
|
186
|
-
return /\$[A-Za-z_{]|\$\(|%[A-Za-z_][A-Za-z0-9_]*%/.test(value)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function getRecommendedValues (framework) {
|
|
190
|
-
const projectName = normalizeName(framework.project?.name || framework.id || 'test')
|
|
191
|
-
const context = [
|
|
192
|
-
framework.ciWiring?.step,
|
|
193
|
-
framework.ciWiring?.job,
|
|
194
|
-
framework.ciWiring?.command,
|
|
195
|
-
].filter(Boolean).join(' ')
|
|
196
|
-
const testKind = /\bunit\b/i.test(context)
|
|
197
|
-
? 'unit-tests'
|
|
198
|
-
: /\bintegration\b/i.test(context) ? 'integration-tests' : 'tests'
|
|
199
|
-
const frameworkName = normalizeName(framework.framework || 'test')
|
|
200
|
-
|
|
201
|
-
return [
|
|
202
|
-
{
|
|
203
|
-
name: 'DD_SERVICE',
|
|
204
|
-
value: `${projectName}-tests`,
|
|
205
|
-
description: 'Use a service name that identifies this project test suite.',
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
name: 'DD_TEST_SESSION_NAME',
|
|
209
|
-
value: `${frameworkName}-${testKind}`,
|
|
210
|
-
description: 'Use a session name that identifies this test runner and suite.',
|
|
211
|
-
},
|
|
212
|
-
]
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function normalizeName (value) {
|
|
216
|
-
return String(value)
|
|
217
|
-
.toLowerCase()
|
|
218
|
-
.replaceAll(/^@/g, '')
|
|
219
|
-
.replaceAll(/[^a-z0-9]+/g, '-')
|
|
220
|
-
.replaceAll(/^-|-$/g, '') || 'test'
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function formatSnippet (env, ciWiring) {
|
|
224
|
-
if (ciWiring.provider === 'github-actions') {
|
|
225
|
-
const testCommand = getTestCommand(ciWiring)
|
|
226
|
-
const lines = [
|
|
227
|
-
ciWiring.configFile ? `# ${formatPath(ciWiring.configFile)}` : '# GitHub Actions workflow',
|
|
228
|
-
ciWiring.job ? `# Job: ${ciWiring.job}` : '# Selected test job',
|
|
229
|
-
]
|
|
230
|
-
if (!testCommand) {
|
|
231
|
-
return [
|
|
232
|
-
...lines,
|
|
233
|
-
'env:',
|
|
234
|
-
...Object.entries(env).map(([name, value]) => ` ${name}: ${quoteYamlValue(value)}`),
|
|
235
|
-
].join('\n')
|
|
236
|
-
}
|
|
237
|
-
return [
|
|
238
|
-
...lines,
|
|
239
|
-
`- name: ${quoteYamlValue(ciWiring.step || 'Run tests with Datadog')}`,
|
|
240
|
-
' env:',
|
|
241
|
-
...Object.entries(env).map(([name, value]) => ` ${name}: ${quoteYamlValue(value)}`),
|
|
242
|
-
' run: |',
|
|
243
|
-
...testCommand.split(/\r?\n/).map(line => ` ${line}`),
|
|
244
|
-
].join('\n')
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return Object.entries(env).map(([name, value]) => {
|
|
248
|
-
const safeValue = name === 'DD_API_KEY' ? '<DD_API_KEY_FROM_CI_SECRET_STORE>' : value
|
|
249
|
-
return `${name}=${quoteShellValue(safeValue)}`
|
|
250
|
-
}).join('\n')
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function quoteShellValue (value) {
|
|
254
|
-
return JSON.stringify(String(value))
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function getTestCommand (ciWiring) {
|
|
258
|
-
if (typeof ciWiring.command === 'string' && ciWiring.command.trim()) {
|
|
259
|
-
return removeEmptyLiteralEnvironmentAssignments(
|
|
260
|
-
ciWiring.command,
|
|
261
|
-
'NODE_OPTIONS',
|
|
262
|
-
getCiPlatform(ciWiring)
|
|
263
|
-
)
|
|
264
|
-
}
|
|
265
|
-
return ciWiring.packageScriptExpansionChain?.[0] || ciWiring.runnerToolChain?.[0]
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function getCiPlatform (ciWiring) {
|
|
269
|
-
const shellName = path.basename(String(ciWiring.shell || '')).toLowerCase()
|
|
270
|
-
return ['cmd', 'cmd.exe', 'powershell', 'powershell.exe', 'pwsh', 'pwsh.exe'].includes(shellName)
|
|
271
|
-
? 'win32'
|
|
272
|
-
: process.platform
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function quoteYamlValue (value) {
|
|
276
|
-
if (String(value).startsWith('${{')) return value
|
|
277
|
-
return JSON.stringify(String(value))
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
module.exports = {
|
|
281
|
-
buildCiRemediation,
|
|
282
|
-
getConfiguredTransport,
|
|
283
|
-
}
|