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
package/loader-hook.mjs
CHANGED
|
@@ -52,11 +52,51 @@ if (!isInitializeMainThread) {
|
|
|
52
52
|
|
|
53
53
|
const nodeModulesIncludeSource = `node_modules/(?:${moduleNameAlternation})/(?!node_modules).+`
|
|
54
54
|
|
|
55
|
+
const NODE_MODULES = '/node_modules/'
|
|
56
|
+
|
|
57
|
+
// Package roots already reported, so each package costs a single report however many of its files load.
|
|
58
|
+
const reportedPackageRoots = new Set()
|
|
59
|
+
/** @type {((url: string) => void) | undefined} */
|
|
60
|
+
let reportModuleLoad
|
|
61
|
+
|
|
55
62
|
function initialize (data = {}) {
|
|
63
|
+
const { moduleLoadPort } = data
|
|
64
|
+
if (moduleLoadPort) {
|
|
65
|
+
// A MessagePort, not a timer; optional chaining would break the Node.js 12 syntax this file supports.
|
|
66
|
+
// eslint-disable-next-line eslint-rules/eslint-timer-unref
|
|
67
|
+
moduleLoadPort.unref()
|
|
68
|
+
reportModuleLoad = (url) => moduleLoadPort.postMessage(url)
|
|
69
|
+
}
|
|
70
|
+
|
|
56
71
|
prepareImportInTheMiddleOptions(data)
|
|
57
72
|
return origInitialize(data)
|
|
58
73
|
}
|
|
59
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Reports the first loaded file of each `node_modules` package, so packages that
|
|
77
|
+
* import-in-the-middle leaves unwrapped reach `dd-trace:moduleLoadStart` too. Wrapped
|
|
78
|
+
* modules are also published through iitm's `addHook`; dependency telemetry deduplicates.
|
|
79
|
+
*
|
|
80
|
+
* @param {string} url Loaded module URL.
|
|
81
|
+
*/
|
|
82
|
+
function reportUnwrappedPackage (url) {
|
|
83
|
+
if (!reportModuleLoad || !url.startsWith('file:') || url.includes('iitm=true')) return
|
|
84
|
+
|
|
85
|
+
const nodeModulesIndex = url.lastIndexOf(NODE_MODULES)
|
|
86
|
+
if (nodeModulesIndex === -1) return
|
|
87
|
+
|
|
88
|
+
const nameStart = nodeModulesIndex + NODE_MODULES.length
|
|
89
|
+
let nameEnd = url.indexOf('/', nameStart)
|
|
90
|
+
if (url[nameStart] === '@' && nameEnd !== -1) nameEnd = url.indexOf('/', nameEnd + 1)
|
|
91
|
+
if (nameEnd === -1) return
|
|
92
|
+
|
|
93
|
+
const packageRoot = url.slice(0, nameEnd)
|
|
94
|
+
if (reportedPackageRoots.has(packageRoot)) return
|
|
95
|
+
|
|
96
|
+
reportedPackageRoots.add(packageRoot)
|
|
97
|
+
reportModuleLoad(url)
|
|
98
|
+
}
|
|
99
|
+
|
|
60
100
|
function prepareImportInTheMiddleOptions (data = {}) {
|
|
61
101
|
// A consumer-owned shouldInclude predicate takes over the wrapping decision, so
|
|
62
102
|
// iitm ignores the include/exclude arrays. Building the matcher here keeps the
|
|
@@ -116,10 +156,14 @@ function buildIncludeSource (securityControlsConfig) {
|
|
|
116
156
|
}
|
|
117
157
|
|
|
118
158
|
function load (url, context, nextLoad) {
|
|
159
|
+
reportUnwrappedPackage(url)
|
|
119
160
|
return rewriterLoader.load(url, context, (url, context) => origLoad(url, context, nextLoad))
|
|
120
161
|
}
|
|
121
162
|
|
|
122
163
|
function loadSync (url, context, nextLoad) {
|
|
164
|
+
// require() loads are already published by require-in-the-middle.
|
|
165
|
+
if (!hasRequireCondition(context)) reportUnwrappedPackage(url)
|
|
166
|
+
|
|
123
167
|
if (isCommonJSLoad(context)) {
|
|
124
168
|
return getSyncImportInTheMiddleHook().loadSync(url, context, nextLoad)
|
|
125
169
|
}
|
|
@@ -135,6 +179,13 @@ function isCommonJSLoad (context) {
|
|
|
135
179
|
// Sync hooks report CommonJS require() dependency loads with a `require`
|
|
136
180
|
// condition but no format. If a format is present, trust it instead: ESM
|
|
137
181
|
// loaded through require() reports `format: 'module'` and still needs rewrite.
|
|
182
|
+
return hasRequireCondition(context)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @param {import('node:module').LoadHookContext} context
|
|
187
|
+
*/
|
|
188
|
+
function hasRequireCondition (context) {
|
|
138
189
|
const conditions = context.conditions
|
|
139
190
|
if (!conditions) return false
|
|
140
191
|
|
|
@@ -184,6 +235,8 @@ function registerSyncLoaderHooks (data = {}) {
|
|
|
184
235
|
// synchronous and asynchronous loaders share the same option preparation so
|
|
185
236
|
// that `import http from 'node:http'` is wrapped on both paths.
|
|
186
237
|
syncHook.applyOptions(prepareImportInTheMiddleOptions(data))
|
|
238
|
+
// The synchronous hooks run on the application thread, so publish directly.
|
|
239
|
+
reportModuleLoad = require('./packages/dd-trace/src/esm-module-load.js').publishModuleLoad
|
|
187
240
|
Module.registerHooks({
|
|
188
241
|
resolve: syncHook.resolveSync,
|
|
189
242
|
load: loadSync,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export type ExposureFeatureValue = string | number | boolean;
|
|
2
|
+
|
|
3
|
+
export interface ExposureFlagMetadata {
|
|
4
|
+
[key: string]: string | number | boolean | undefined;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface ExposureEvaluationDetails {
|
|
8
|
+
flagKey: string;
|
|
9
|
+
value?: unknown;
|
|
10
|
+
variant?: string;
|
|
11
|
+
reason?: string;
|
|
12
|
+
errorCode?: string;
|
|
13
|
+
errorMessage?: string;
|
|
14
|
+
flagMetadata?: Readonly<ExposureFlagMetadata>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ExposureEvaluationContext {
|
|
18
|
+
targetingKey?: string;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A completed flag evaluation and its Datadog exposure decision.
|
|
24
|
+
*/
|
|
25
|
+
export interface ExposureEvaluation {
|
|
26
|
+
/** The flag key. */
|
|
27
|
+
readonly flagKey: string;
|
|
28
|
+
/** The flag key, variant, value, error and flag metadata of the evaluation. */
|
|
29
|
+
readonly details: ExposureEvaluationDetails;
|
|
30
|
+
/** The selected variant key, or undefined when the default value was returned. */
|
|
31
|
+
readonly variant: string | undefined;
|
|
32
|
+
/** The key of the selected allocation, or undefined when none was selected. */
|
|
33
|
+
readonly allocation: string | undefined;
|
|
34
|
+
/** The evaluation context, including the targeting key. */
|
|
35
|
+
readonly context: ExposureEvaluationContext | undefined;
|
|
36
|
+
/** The targeting key of the evaluation context, if readable. */
|
|
37
|
+
readonly targetingKey: string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* True when the evaluation succeeded and selected an allocation that logs exposures,
|
|
40
|
+
* whether or not this subject was already exposed.
|
|
41
|
+
*/
|
|
42
|
+
isExposure(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* True when this exposure repeats one already recorded for this subject: same
|
|
45
|
+
* allocation, variant and serial id.
|
|
46
|
+
*/
|
|
47
|
+
isCacheHit(): boolean;
|
|
48
|
+
/** True for a new or changed exposure: the decision the provider uses for Datadog. */
|
|
49
|
+
shouldSend(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The HOOK features of the selected split, such as `holdout.key`. Read-only.
|
|
52
|
+
*/
|
|
53
|
+
getFeatures(): Readonly<Record<string, ExposureFeatureValue>>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* An OpenFeature hook that hands each completed flag evaluation to a callback,
|
|
58
|
+
* with the Datadog exposure decision.
|
|
59
|
+
*
|
|
60
|
+
* Register it with `OpenFeature.addHooks(new ExposureHook(callback))` or on a client.
|
|
61
|
+
* The callback runs on the evaluation thread and must not do I/O. An exception from
|
|
62
|
+
* the callback does not affect the evaluation.
|
|
63
|
+
*/
|
|
64
|
+
export declare class ExposureHook {
|
|
65
|
+
constructor(callback: (evaluation: ExposureEvaluation) => void);
|
|
66
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dd-trace",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.136.0",
|
|
4
4
|
"description": "Datadog APM tracing client for JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"prepare": "node scripts/patch-istanbul-lib-coverage.js && node scripts/patch-v8-to-istanbul.js && cd vendor && npm ci --include=dev",
|
|
10
10
|
"prepack": "node scripts/release/swap-v5-types.js",
|
|
11
11
|
"bench": "node benchmark/index.js",
|
|
12
|
+
"bench:elevenlabs": "node benchmark/elevenlabs.js",
|
|
12
13
|
"bench:e2e:test-optimization": "node benchmark/e2e-test-optimization/benchmark-run.js",
|
|
13
14
|
"dependencies:dedupe": "yarn-deduplicate yarn.lock",
|
|
14
15
|
"generate:config:types": "node scripts/generate-config-types.js",
|
|
@@ -18,12 +19,11 @@
|
|
|
18
19
|
"generate:rewriter:targets": "node scripts/generate-rewriter-targets.js",
|
|
19
20
|
"verify:rewriter:targets": "node scripts/generate-rewriter-targets.js --check",
|
|
20
21
|
"generate:supported-integrations": "node scripts/generate-supported-integrations.js",
|
|
21
|
-
"verify:supported-integrations": "node scripts/generate-supported-integrations.js --check",
|
|
22
22
|
"type:check": "tsc --noEmit -p tsconfig.dev.json",
|
|
23
23
|
"type:doc:build": "cd docs && yarn && yarn build",
|
|
24
24
|
"type:doc:test": "cd docs && yarn && yarn test",
|
|
25
25
|
"lint": "bash ./scripts/lint.sh",
|
|
26
|
-
"lint:fix": "node scripts/check_licenses.js && node scripts/check-agents-md-size.js && node scripts/check-no-coverage-artifacts.js && node scripts/check-no-mcr-images.js && node scripts/check-docker-image-shas.js && eslint . --concurrency=auto --max-warnings 0 --fix",
|
|
26
|
+
"lint:fix": "node scripts/check_licenses.js && node scripts/check-agents-md-size.js && node scripts/check-no-coverage-artifacts.js && node scripts/check-no-mcr-images.js && node scripts/check-docker-image-shas.js && node scripts/check-workflow-inline-js.js && eslint . --concurrency=auto --max-warnings 0 --fix",
|
|
27
27
|
"verify:carrier-fields": "node scripts/verify-carrier-fields.mjs",
|
|
28
28
|
"lint:inspect": "npx @eslint/config-inspector@latest",
|
|
29
29
|
"lint:codeowners": "codeowners-audit",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"test:profiler:ci": "node scripts/c8-ci.js test:profiler",
|
|
77
77
|
"test:otel-thread-ctx": "mocha --timeout 60000 packages/dd-trace/test/otel-thread-ctx.spec.js",
|
|
78
78
|
"test:docker:otel-thread-ctx": "./scripts/docker/run-otel-thread-ctx-spec.sh",
|
|
79
|
-
"test:integration": "mocha --timeout 60000 \"integration-tests/*.spec.js\"",
|
|
80
|
-
"test:integration:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/*.spec.js\"",
|
|
79
|
+
"test:integration": "mocha --timeout 60000 \"integration-tests/*.spec.js\" \"integration-tests/helpers/*.spec.js\"",
|
|
80
|
+
"test:integration:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/*.spec.js\" \"integration-tests/helpers/*.spec.js\"",
|
|
81
81
|
"test:integration:aiguard": "mocha --timeout 60000 \"integration-tests/aiguard/*.spec.js\"",
|
|
82
82
|
"test:integration:aiguard:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/aiguard/*.spec.js\"",
|
|
83
83
|
"test:integration:appsec": "mocha --timeout 60000 \"integration-tests/appsec/*.spec.js\"",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"test:integration:playwright:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/playwright/${SPEC:-playwright-*}.spec.js\"",
|
|
107
107
|
"test:integration:selenium": "mocha --timeout 60000 \"integration-tests/selenium/*.spec.js\"",
|
|
108
108
|
"test:integration:selenium:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/selenium/*.spec.js\"",
|
|
109
|
-
"test:integration:test-optimization:helpers": "mocha \"integration-tests/cypress/*dependencies.spec.js\" \"integration-tests/jest/*dependencies.spec.js\" \"integration-tests/playwright/version*.spec.js\" \"integration-tests/mocha/version*.spec.js\"",
|
|
109
|
+
"test:integration:test-optimization:helpers": "mocha \"integration-tests/cypress/config-lifecycle*.spec.js\" \"integration-tests/cypress/checkout-context*.spec.js\" \"integration-tests/cypress/*dependencies.spec.js\" \"integration-tests/jest/*dependencies.spec.js\" \"integration-tests/playwright/version*.spec.js\" \"integration-tests/mocha/version*.spec.js\"",
|
|
110
110
|
"test:integration:webdriverio": "mocha --timeout 60000 \"integration-tests/webdriverio/${SPEC:-*}.spec.js\"",
|
|
111
111
|
"test:integration:webdriverio:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/webdriverio/${SPEC:-*}.spec.js\"",
|
|
112
112
|
"test:integration:vitest": "mocha --timeout 60000 \"integration-tests/vitest/${SPEC:-vitest*}.spec.js\"",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"test:integration:plugins:coverage": "yarn services && node ./integration-tests/coverage/run-suite.js \"packages/datadog-plugin-@(${PLUGINS})/test/integration-test/**/${SPEC:-*}*.spec.js\"",
|
|
120
120
|
"test:unit:plugins": "mocha \"packages/datadog-instrumentations/test/@(${PLUGINS}).spec.js\" \"packages/datadog-plugin-@(${PLUGINS})/test/**/*.spec.js\" --exclude \"packages/datadog-plugin-@(${PLUGINS})/test/integration-test/**/*.spec.js\"",
|
|
121
121
|
"test:release": "mocha \"scripts/release/**/*.spec.js\"",
|
|
122
|
-
"test:scripts": "mocha \"benchmark/e2e-test-optimization/*.spec.js\" \"benchmark/sirun/*.spec.js\" \"scripts/helpers/**/*.spec.js\" \"scripts/*.spec.mjs\"",
|
|
122
|
+
"test:scripts": "mocha \"benchmark/e2e-test-optimization/*.spec.js\" \"benchmark/sirun/*.spec.js\" \"scripts/helpers/**/*.spec.js\" \"scripts/test/**/*.spec.js\" \"scripts/*.spec.mjs\"",
|
|
123
123
|
"test:shimmer": "mocha \"packages/datadog-shimmer/test/**/*.spec.js\"",
|
|
124
124
|
"test:shimmer:ci": "node scripts/c8-ci.js test:shimmer",
|
|
125
125
|
"verify:workflow-job-names": "node scripts/verify-workflow-job-names.js",
|
|
@@ -168,10 +168,14 @@
|
|
|
168
168
|
"LICENSE.Apache",
|
|
169
169
|
"LICENSE.BSD3",
|
|
170
170
|
"loader-hook.mjs",
|
|
171
|
+
"lambda.d.ts",
|
|
172
|
+
"lambda.js",
|
|
171
173
|
"openfeature.d.ts",
|
|
172
174
|
"openfeature.js",
|
|
173
175
|
"openfeature/rules-based.js",
|
|
174
176
|
"openfeature/rules-based.d.ts",
|
|
177
|
+
"openfeature/exposure-hook.js",
|
|
178
|
+
"openfeature/exposure-hook.d.ts",
|
|
175
179
|
"packages/*/index.js",
|
|
176
180
|
"packages/*/index.electron.js",
|
|
177
181
|
"packages/*/lib/**/*",
|
|
@@ -196,27 +200,27 @@
|
|
|
196
200
|
"@datadog/native-appsec": "11.0.3",
|
|
197
201
|
"@datadog/native-iast-taint-tracking": "4.2.1",
|
|
198
202
|
"@datadog/native-metrics": "4.0.0",
|
|
199
|
-
"@datadog/pprof": "5.20.
|
|
203
|
+
"@datadog/pprof": "5.20.1",
|
|
200
204
|
"@datadog/wasm-js-rewriter": "5.0.4",
|
|
201
|
-
"@opentelemetry/api": ">=1.
|
|
205
|
+
"@opentelemetry/api": ">=1.4.1 <1.11.0",
|
|
202
206
|
"@opentelemetry/api-logs": "<1.0.0",
|
|
203
207
|
"oxc-parser": "^0.132.0"
|
|
204
208
|
},
|
|
205
209
|
"devDependencies": {
|
|
206
210
|
"@actions/core": "^3.0.1",
|
|
207
211
|
"@actions/github": "^9.1.1",
|
|
208
|
-
"@babel/helpers": "^8.0.
|
|
212
|
+
"@babel/helpers": "^8.0.10",
|
|
209
213
|
"@eslint/eslintrc": "^3.3.7",
|
|
210
214
|
"@eslint/js": "^10.0.1",
|
|
211
215
|
"@eslint/plugin-kit": "^0.7.3",
|
|
212
|
-
"@datadog/openfeature-node-server": "2.
|
|
216
|
+
"@datadog/openfeature-node-server": "2.7.0",
|
|
213
217
|
"@msgpack/msgpack": "^3.1.3",
|
|
214
218
|
"@openfeature/core": "^1.12.0",
|
|
215
219
|
"@openfeature/server-sdk": "~1.23.0",
|
|
216
220
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
217
221
|
"@types/mocha": "^10.0.10",
|
|
218
222
|
"@types/node": "^18.19.106",
|
|
219
|
-
"@types/sinon": "^22.0.
|
|
223
|
+
"@types/sinon": "^22.0.2",
|
|
220
224
|
"@vercel/nft": "^1.11.0",
|
|
221
225
|
"@yarnpkg/lockfile": "^1.1.0",
|
|
222
226
|
"benchmark": "^2.1.4",
|
|
@@ -231,9 +235,9 @@
|
|
|
231
235
|
"eslint-plugin-mocha": "^12.0.2",
|
|
232
236
|
"eslint-plugin-n": "^18.5.0",
|
|
233
237
|
"eslint-plugin-promise": "^7.3.0",
|
|
234
|
-
"eslint-plugin-regexp": "^3.3.
|
|
238
|
+
"eslint-plugin-regexp": "^3.3.2",
|
|
235
239
|
"eslint-plugin-sonarjs": "^4.2.2",
|
|
236
|
-
"eslint-plugin-unicorn": "^
|
|
240
|
+
"eslint-plugin-unicorn": "^79.0.0",
|
|
237
241
|
"express": "^5.3.0",
|
|
238
242
|
"glob": "^10.4.5",
|
|
239
243
|
"globals": "^17.13.0",
|
|
@@ -244,7 +248,7 @@
|
|
|
244
248
|
"istanbul-reports": "^3.0.2",
|
|
245
249
|
"jsonc-parser": "^3.3.1",
|
|
246
250
|
"jszip": "^3.10.2",
|
|
247
|
-
"minimatch": "^
|
|
251
|
+
"minimatch": "^11.0.3",
|
|
248
252
|
"mocha": "^11.8.0",
|
|
249
253
|
"mocha-junit-reporter": "^2.2.1",
|
|
250
254
|
"mocha-multi-reporters": "^1.5.2",
|
|
@@ -128,7 +128,7 @@ if (!isACFActive) {
|
|
|
128
128
|
* For convenience, we use the `storage` function as a registry of namespaces
|
|
129
129
|
* corresponding to DatadogStorage instances. This lets us have separate
|
|
130
130
|
* storages for separate purposes.
|
|
131
|
-
* @type {
|
|
131
|
+
* @type {Record<string, DatadogStorage>}
|
|
132
132
|
*/
|
|
133
133
|
const storages = Object.create(null)
|
|
134
134
|
|
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { execSync } = require('node:child_process')
|
|
4
3
|
const fs = require('node:fs')
|
|
5
4
|
const path = require('node:path')
|
|
6
5
|
const { pathToFileURL, fileURLToPath } = require('node:url')
|
|
7
6
|
|
|
8
7
|
const instrumentations = require('../datadog-instrumentations/src/helpers/instrumentations')
|
|
8
|
+
const {
|
|
9
|
+
createEsmResolver,
|
|
10
|
+
processModule,
|
|
11
|
+
} = require('../datadog-instrumentations/src/helpers/bundler-esm-exports')
|
|
12
|
+
const { getGitMetadataBanner, isESMFile } = require('../datadog-instrumentations/src/helpers/bundler-utils')
|
|
9
13
|
const extractPackageAndModulePath = require('../datadog-instrumentations/src/helpers/extract-package-and-module-path')
|
|
10
14
|
const hooks = require('../datadog-instrumentations/src/helpers/hooks')
|
|
15
|
+
const { createBundlerRewriter } = require('../datadog-instrumentations/src/helpers/rewriter')
|
|
16
|
+
const { getRewriteTarget, isRewriteTargetName } = require('../datadog-instrumentations/src/helpers/rewriter/targets')
|
|
11
17
|
const { getValueFromEnvSources } = require('../dd-trace/src/config/helper')
|
|
12
18
|
const log = require('./src/log')
|
|
13
|
-
const { createEsmResolver } = require('./src/resolver')
|
|
14
|
-
const { isESMFile, processModule } = require('./src/utils')
|
|
15
19
|
|
|
16
20
|
const ESM_INTERCEPTED_SUFFIX = '._dd_esbuild_intercepted'
|
|
17
21
|
const INTERNAL_ESM_INTERCEPTED_PREFIX = '/_dd_esm_internal_/'
|
|
22
|
+
// User bundles may not have dc-polyfill next to the target package.
|
|
23
|
+
const DC_MODULE = require.resolve('dc-polyfill').replaceAll('\\', '/')
|
|
24
|
+
const DC_MODULE_LITERAL = JSON.stringify(DC_MODULE)
|
|
25
|
+
// Keep the marker split so source-map scanners do not treat this literal as this file's map.
|
|
26
|
+
// eslint-disable-next-line unicorn/no-useless-concat
|
|
27
|
+
const SOURCE_MAP_PREFIX = '//# sourceMapping' + 'URL=data:application/json;base64,'
|
|
18
28
|
|
|
19
29
|
let rewriter
|
|
30
|
+
let bundlerRewrite
|
|
20
31
|
|
|
21
32
|
for (const hook of Object.values(hooks)) {
|
|
22
33
|
if (hook !== null && typeof hook === 'object') {
|
|
@@ -73,40 +84,6 @@ function isESMBuild (build) {
|
|
|
73
84
|
return format === 'esm' || outputFile?.endsWith('.mjs') || outExtension === '.mjs'
|
|
74
85
|
}
|
|
75
86
|
|
|
76
|
-
function getGitMetadata () {
|
|
77
|
-
/**
|
|
78
|
-
* @type {object}
|
|
79
|
-
* @property {string | null} repositoryURL
|
|
80
|
-
* @property {string | null} commitSHA
|
|
81
|
-
*/
|
|
82
|
-
const gitMetadata = {
|
|
83
|
-
repositoryURL: null,
|
|
84
|
-
commitSHA: null,
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
gitMetadata.repositoryURL = execSync('git config --get remote.origin.url', {
|
|
89
|
-
encoding: 'utf8',
|
|
90
|
-
stdio: ['pipe', 'pipe', 'ignore'],
|
|
91
|
-
cwd: process.cwd(),
|
|
92
|
-
}).trim()
|
|
93
|
-
} catch (e) {
|
|
94
|
-
log.warn('failed to get git repository URL:', e.message)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
gitMetadata.commitSHA = execSync('git rev-parse HEAD', {
|
|
99
|
-
encoding: 'utf8',
|
|
100
|
-
stdio: ['pipe', 'pipe', 'ignore'],
|
|
101
|
-
cwd: process.cwd(),
|
|
102
|
-
}).trim()
|
|
103
|
-
} catch (e) {
|
|
104
|
-
log.warn('failed to get git commit SHA:', e.message)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return gitMetadata
|
|
108
|
-
}
|
|
109
|
-
|
|
110
87
|
module.exports.setup = function (build) {
|
|
111
88
|
if (build.initialOptions.minify && !build.initialOptions.keepNames) {
|
|
112
89
|
throw new Error(
|
|
@@ -147,25 +124,10 @@ ${build.initialOptions.banner.js}`
|
|
|
147
124
|
|
|
148
125
|
// Bake DD_GIT_* into the banner unless DD_BUNDLER_INJECT_GIT_METADATA=false (stable artifact hashes).
|
|
149
126
|
if (DD_BUNDLER_INJECT_GIT_METADATA) {
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
127
|
+
const banner = getGitMetadataBanner(log)
|
|
128
|
+
if (banner) {
|
|
152
129
|
build.initialOptions.banner ??= {}
|
|
153
|
-
build.initialOptions.banner.js
|
|
154
|
-
|
|
155
|
-
build.initialOptions.banner.js = `if (typeof process === 'object' && process !== null &&
|
|
156
|
-
process.env !== null && typeof process.env === 'object') {
|
|
157
|
-
${gitMetadata.repositoryURL ? `process.env.DD_GIT_REPOSITORY_URL = '${gitMetadata.repositoryURL}';` : ''}
|
|
158
|
-
${gitMetadata.commitSHA ? `process.env.DD_GIT_COMMIT_SHA = '${gitMetadata.commitSHA}';` : ''}
|
|
159
|
-
}
|
|
160
|
-
${build.initialOptions.banner.js}`
|
|
161
|
-
|
|
162
|
-
log.debug(
|
|
163
|
-
'Automatically injected git metadata (DD_GIT_REPOSITORY_URL: %s, DD_GIT_COMMIT_SHA: %s)',
|
|
164
|
-
gitMetadata.repositoryURL || 'not available',
|
|
165
|
-
gitMetadata.commitSHA || 'not available'
|
|
166
|
-
)
|
|
167
|
-
} else {
|
|
168
|
-
log.warn('No git metadata available - skipping injection')
|
|
130
|
+
build.initialOptions.banner.js = `${banner}${build.initialOptions.banner.js ?? ''}`
|
|
169
131
|
}
|
|
170
132
|
} else {
|
|
171
133
|
log.debug('Skipping git metadata injection (DD_BUNDLER_INJECT_GIT_METADATA=false)')
|
|
@@ -189,6 +151,7 @@ ${build.initialOptions.banner.js}`
|
|
|
189
151
|
// TODO: Should this also check for namespace === 'file'?
|
|
190
152
|
if (!modulesOfInterest.has(args.path) &&
|
|
191
153
|
args.path.startsWith('@') &&
|
|
154
|
+
!isRewriteTargetName(args.path.split('/', 2).join('/')) &&
|
|
192
155
|
!args.importer.includes('node_modules/')) {
|
|
193
156
|
// This is the Next.js convention for loading local files
|
|
194
157
|
log.debug('@LOCAL: %s', args.path)
|
|
@@ -220,6 +183,9 @@ ${build.initialOptions.banner.js}`
|
|
|
220
183
|
const extracted = extractPackageAndModulePath(fullPathToModule)
|
|
221
184
|
|
|
222
185
|
const internal = builtins.has(args.path)
|
|
186
|
+
const target = getRewriteTarget(fullPathToModule.replaceAll('\\', '/'))
|
|
187
|
+
const isModuleOfInterest = modulesOfInterest.has(args.path) ||
|
|
188
|
+
modulesOfInterest.has(`${extracted.pkg}/${extracted.path}`)
|
|
223
189
|
|
|
224
190
|
// Only the generated wrapper module, and the real module importing itself, must reach the real module unwrapped.
|
|
225
191
|
// Every other importer must get the wrapper regardless of whether it has already been loaded: onLoad runs
|
|
@@ -228,9 +194,7 @@ ${build.initialOptions.banner.js}`
|
|
|
228
194
|
// wrapper cycle that can hit the wrapper's exports in their temporal dead zone.
|
|
229
195
|
const isInterceptedImporter = args.importer.endsWith(ESM_INTERCEPTED_SUFFIX) || args.importer === fullPathToModule
|
|
230
196
|
|
|
231
|
-
if (args.namespace === 'file' && (
|
|
232
|
-
modulesOfInterest.has(args.path) || modulesOfInterest.has(`${extracted.pkg}/${extracted.path}`))
|
|
233
|
-
) {
|
|
197
|
+
if (args.namespace === 'file' && (isModuleOfInterest || target !== undefined)) {
|
|
234
198
|
// Internal module like http/fs is imported and the build output is ESM
|
|
235
199
|
if (internal && args.kind === 'import-statement' && esmBuild && !isInterceptedImporter) {
|
|
236
200
|
fullPathToModule = `${INTERNAL_ESM_INTERCEPTED_PREFIX}${fullPathToModule}${ESM_INTERCEPTED_SUFFIX}`
|
|
@@ -274,7 +238,10 @@ ${build.initialOptions.banner.js}`
|
|
|
274
238
|
const packageJson = JSON.parse(fs.readFileSync(/** @type {string} */(pathToPackageJson)).toString())
|
|
275
239
|
|
|
276
240
|
const isESM = isESMFile(fullPathToModule, pathToPackageJson, packageJson)
|
|
277
|
-
|
|
241
|
+
// ESM targets with export hooks still need the IITM wrapper to run those hooks; the wrapper's import of the
|
|
242
|
+
// real module then resolves without the suffix and is rewritten.
|
|
243
|
+
const needsExportHook = !target || (isModuleOfInterest && !target.activate)
|
|
244
|
+
if (isESM && needsExportHook && !isInterceptedImporter) {
|
|
278
245
|
fullPathToModule += ESM_INTERCEPTED_SUFFIX
|
|
279
246
|
}
|
|
280
247
|
|
|
@@ -290,6 +257,7 @@ ${build.initialOptions.banner.js}`
|
|
|
290
257
|
full: fullPathToModule,
|
|
291
258
|
raw: args.path,
|
|
292
259
|
pkgOfInterest: true,
|
|
260
|
+
rewriteOnly: !isModuleOfInterest,
|
|
293
261
|
kind: args.kind,
|
|
294
262
|
internal,
|
|
295
263
|
isESM,
|
|
@@ -324,8 +292,44 @@ ${build.initialOptions.banner.js}`
|
|
|
324
292
|
|
|
325
293
|
// Read the content of the module file of interest
|
|
326
294
|
let contents
|
|
295
|
+
let sourceMap
|
|
296
|
+
const target = getRewriteTarget(args.path.replaceAll('\\', '/'))
|
|
297
|
+
|
|
298
|
+
if (target) {
|
|
299
|
+
const source = fs.readFileSync(args.path, 'utf8')
|
|
300
|
+
bundlerRewrite ??= createBundlerRewriter(DC_MODULE)
|
|
301
|
+
const result = bundlerRewrite(source, args.path, data.isESM ? 'module' : 'commonjs', target)
|
|
302
|
+
contents = /** @type {string} */(result.code)
|
|
303
|
+
if (result.map) {
|
|
304
|
+
const map = typeof result.map === 'string' ? JSON.parse(result.map) : result.map
|
|
305
|
+
// Inline maps resolve sources relative to the loaded file, not the package root.
|
|
306
|
+
sourceMap = {
|
|
307
|
+
...map,
|
|
308
|
+
sources: [path.basename(args.path)],
|
|
309
|
+
sourcesContent: [source],
|
|
310
|
+
}
|
|
311
|
+
}
|
|
327
312
|
|
|
328
|
-
|
|
313
|
+
if (contents !== source && target.activate) {
|
|
314
|
+
const payload = JSON.stringify({
|
|
315
|
+
activate: true,
|
|
316
|
+
package: target.moduleName,
|
|
317
|
+
version: data.version,
|
|
318
|
+
path: `${target.moduleName}/${target.filePath}`,
|
|
319
|
+
})
|
|
320
|
+
let channel = `;{\n const __dd_ch = require(${DC_MODULE_LITERAL}).channel('${CHANNEL}');\n`
|
|
321
|
+
if (data.isESM) {
|
|
322
|
+
let binding = '__dd_dc'
|
|
323
|
+
let suffix = 0
|
|
324
|
+
while (contents.includes(binding)) binding = `__dd_dc${++suffix}`
|
|
325
|
+
channel = `import ${binding} from ${DC_MODULE_LITERAL};\n;{\n` +
|
|
326
|
+
` const __dd_ch = ${binding}.channel('${CHANNEL}');\n`
|
|
327
|
+
}
|
|
328
|
+
contents += `\n${channel}` +
|
|
329
|
+
` if (__dd_ch.hasSubscribers) __dd_ch.publish(${payload});\n` +
|
|
330
|
+
'}\n'
|
|
331
|
+
}
|
|
332
|
+
} else if (data.isESM) {
|
|
329
333
|
if (args.path.endsWith(ESM_INTERCEPTED_SUFFIX)) {
|
|
330
334
|
args.path = args.path.slice(0, -ESM_INTERCEPTED_SUFFIX.length)
|
|
331
335
|
|
|
@@ -362,7 +366,12 @@ register(${JSON.stringify(toRegister)}, _, set, get, ${JSON.stringify(data.raw)}
|
|
|
362
366
|
contents = fs.readFileSync(args.path, 'utf8')
|
|
363
367
|
}
|
|
364
368
|
} else {
|
|
365
|
-
|
|
369
|
+
contents = fs.readFileSync(args.path, 'utf8')
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Rewrite-only targets have no export hook. ESM export hooks run through the IITM wrapper instead.
|
|
373
|
+
if (!data.isESM && !data.rewriteOnly && !target?.activate) {
|
|
374
|
+
const fileCode = contents
|
|
366
375
|
// Don't spread `...arguments`: esbuild's minifier can rewrite the surrounding
|
|
367
376
|
// `__commonJS` factory into an arrow function whose `arguments` resolves to the
|
|
368
377
|
// ESM top-level scope (see issue #8681). Pass `(module.exports, module)`
|
|
@@ -370,7 +379,7 @@ register(${JSON.stringify(toRegister)}, _, set, get, ${JSON.stringify(data.raw)}
|
|
|
370
379
|
// resolution inside `fileCode` is preserved through the factory's closure.
|
|
371
380
|
contents = `
|
|
372
381
|
(function() {
|
|
373
|
-
|
|
382
|
+
${fileCode}
|
|
374
383
|
})(module.exports, module);
|
|
375
384
|
{
|
|
376
385
|
const dc = require('dc-polyfill');
|
|
@@ -386,6 +395,13 @@ register(${JSON.stringify(toRegister)}, _, set, get, ${JSON.stringify(data.raw)}
|
|
|
386
395
|
module.exports = payload.module;
|
|
387
396
|
}
|
|
388
397
|
`
|
|
398
|
+
if (sourceMap) {
|
|
399
|
+
sourceMap.mappings = `;;${sourceMap.mappings}`
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (sourceMap) {
|
|
404
|
+
contents += `\n${SOURCE_MAP_PREFIX}${Buffer.from(JSON.stringify(sourceMap)).toString('base64')}`
|
|
389
405
|
}
|
|
390
406
|
|
|
391
407
|
// https://esbuild.github.io/plugins/#on-load-results
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const dc = require('dc-polyfill')
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
HANDLER_STREAMING,
|
|
7
|
+
STREAM_RESPONSE,
|
|
8
|
+
promisifiedHandler,
|
|
9
|
+
copyHandlerMetadata,
|
|
10
|
+
getDataProperty,
|
|
11
|
+
} = require('./helpers/lambda-handler')
|
|
12
|
+
|
|
13
|
+
// Read through the process-global registry so two dd-trace copies (layer + bundled) resolve the
|
|
14
|
+
// same marker. The value is the wrapper itself, so a second wrap of the same handler returns the
|
|
15
|
+
// instrumented function rather than the raw one.
|
|
16
|
+
const WRAPPED = Symbol.for('dd-trace.lambda.wrapped')
|
|
17
|
+
const invocationChannel = dc.tracingChannel('datadog:aws-lambda:invoke')
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Wraps one customer handler with the shared Lambda invocation channel.
|
|
21
|
+
*
|
|
22
|
+
* @param {Function} handler Customer Lambda handler.
|
|
23
|
+
* @param {Record<string, unknown>} [config] Per-handler configuration overrides.
|
|
24
|
+
* @param {Function} [monitor] Monitors the shim adapter for impending timeouts.
|
|
25
|
+
* @returns {Function} Wrapped handler, or the existing wrapper when already marked.
|
|
26
|
+
*/
|
|
27
|
+
function wrapHandler (handler, config, monitor) {
|
|
28
|
+
if (typeof handler !== 'function') {
|
|
29
|
+
throw new TypeError('AWS Lambda handler must be a function')
|
|
30
|
+
}
|
|
31
|
+
const existing = getWrappedHandler(handler)
|
|
32
|
+
if (existing !== undefined && config?.forceWrap !== true) return existing
|
|
33
|
+
|
|
34
|
+
const isResponseStream = getDataProperty(handler, HANDLER_STREAMING) === STREAM_RESPONSE
|
|
35
|
+
const completion = promisifiedHandler(handler)
|
|
36
|
+
const invoke = monitor ? monitor(completion, true) : completion
|
|
37
|
+
|
|
38
|
+
function wrappedHandler (...args) {
|
|
39
|
+
const invocationContext = {
|
|
40
|
+
config,
|
|
41
|
+
context: args[isResponseStream ? 2 : 1],
|
|
42
|
+
event: args[0],
|
|
43
|
+
isResponseStream,
|
|
44
|
+
responseStream: isResponseStream ? args[1] : undefined,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The shim awaits its startup listeners before calling the adapter. Preserve that boundary so
|
|
48
|
+
// legacy RIC captures native context completion methods before the adapter replaces them.
|
|
49
|
+
return invocationChannel.tracePromise(
|
|
50
|
+
() => Promise.resolve().then(() => Reflect.apply(invoke, this, args)),
|
|
51
|
+
invocationContext
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Frozen customer handlers cannot carry markers; share their identity through the tracer registry.
|
|
56
|
+
const ddGlobal = globalThis[Symbol.for('dd-trace')] ??= { beforeExitHandlers: new Set() }
|
|
57
|
+
const lambda = ddGlobal.lambda ??= {}
|
|
58
|
+
const wrappers = lambda.wrappers ??= new WeakMap()
|
|
59
|
+
wrappers.set(handler, wrappedHandler)
|
|
60
|
+
wrappers.set(wrappedHandler, wrappedHandler)
|
|
61
|
+
Object.defineProperty(wrappedHandler, WRAPPED, { value: wrappedHandler })
|
|
62
|
+
copyHandlerMetadata(handler, wrappedHandler)
|
|
63
|
+
|
|
64
|
+
return wrappedHandler
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Looks up the invocation wrapper, including markers from older tracer copies.
|
|
69
|
+
*
|
|
70
|
+
* Deliberately does not set datadog-lambda-js's `_ddWrapped` property: the released shim treats
|
|
71
|
+
* that property as "already fully instrumented" and returns early, which would suppress its
|
|
72
|
+
* extractors, inferred spans, enhanced metrics, log injection, and cold-start tracing. dd-trace
|
|
73
|
+
* may only claim that marker once it reproduces those behaviors (Phases 2-3).
|
|
74
|
+
*
|
|
75
|
+
* @param {Function} handler Handler whose invocation wrapper is needed.
|
|
76
|
+
* @returns {Function|undefined} Existing invocation wrapper.
|
|
77
|
+
*/
|
|
78
|
+
function getWrappedHandler (handler) {
|
|
79
|
+
const wrappers = globalThis[Symbol.for('dd-trace')]?.lambda?.wrappers
|
|
80
|
+
return wrappers?.get(handler) || getDataProperty(handler, WRAPPED)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = {
|
|
84
|
+
WRAPPED,
|
|
85
|
+
invocationChannel,
|
|
86
|
+
getWrappedHandler,
|
|
87
|
+
wrapHandler,
|
|
88
|
+
}
|