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
|
@@ -7,6 +7,7 @@ const { setTimeout: sleep } = require('node:timers/promises')
|
|
|
7
7
|
const request = require('../exporters/common/request')
|
|
8
8
|
const { getClientLibraryHeaders } = require('../exporters/common/client-library-headers')
|
|
9
9
|
const log = require('../log')
|
|
10
|
+
const { reportIgnoredFlagSelection } = require('./flag-selection')
|
|
10
11
|
|
|
11
12
|
const MAX_ATTEMPTS = 3
|
|
12
13
|
const FIRST_RETRY_MIN_MS = 2000
|
|
@@ -14,10 +15,13 @@ const FIRST_RETRY_MAX_MS = 10_000
|
|
|
14
15
|
const SECOND_RETRY_MIN_MS = 5000
|
|
15
16
|
const SECOND_RETRY_MAX_MS = 30_000
|
|
16
17
|
const RETRY_JITTER = 0.2
|
|
18
|
+
const POLL_FAILED_WITHOUT_CONFIGURATION = 'Feature Flags: agentless configuration poll failed (%s); ' +
|
|
19
|
+
'no configuration has been applied yet, so flag evaluations return their default values'
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* @typedef {object} AgentlessSourceConfig
|
|
20
23
|
* @property {URL} endpoint
|
|
24
|
+
* @property {boolean} [flagSelectionSent]
|
|
21
25
|
* @property {number} pollIntervalMs
|
|
22
26
|
* @property {number} requestTimeoutMs
|
|
23
27
|
* @property {string | undefined} apiKey
|
|
@@ -45,12 +49,17 @@ class AgentlessConfigurationSource {
|
|
|
45
49
|
|
|
46
50
|
#applicationFailureLogged = false
|
|
47
51
|
|
|
52
|
+
/** @type {string | undefined} */
|
|
53
|
+
#appliedCreatedAt
|
|
54
|
+
|
|
48
55
|
/** @type {AgentlessSourceConfig} */
|
|
49
56
|
#config
|
|
50
57
|
|
|
51
58
|
/** @type {string | undefined} */
|
|
52
59
|
#etag
|
|
53
60
|
|
|
61
|
+
#failedPolls = 0
|
|
62
|
+
|
|
54
63
|
/** @type {Set<string>} */
|
|
55
64
|
#failureWarnings = new Set()
|
|
56
65
|
|
|
@@ -74,8 +83,11 @@ class AgentlessConfigurationSource {
|
|
|
74
83
|
}
|
|
75
84
|
|
|
76
85
|
stop () {
|
|
77
|
-
this.#abortController
|
|
86
|
+
if (!this.#abortController) return
|
|
87
|
+
|
|
88
|
+
this.#abortController.abort()
|
|
78
89
|
this.#abortController = undefined
|
|
90
|
+
log.debug('Feature Flags: agentless configuration polling stopped')
|
|
79
91
|
}
|
|
80
92
|
|
|
81
93
|
/**
|
|
@@ -132,10 +144,13 @@ class AgentlessConfigurationSource {
|
|
|
132
144
|
|
|
133
145
|
if (attempt === MAX_ATTEMPTS) {
|
|
134
146
|
this.#warnFailure(response.statusCode, response.error, attempt)
|
|
147
|
+
this.#logPollFailure('retries exhausted')
|
|
135
148
|
return
|
|
136
149
|
}
|
|
137
150
|
|
|
138
151
|
const delay = retryDelay(this.#config.pollIntervalMs, attempt, Math.random())
|
|
152
|
+
log.debug('Feature Flags: agentless configuration poll attempt %d/%d is retryable; retrying in %dms',
|
|
153
|
+
attempt, MAX_ATTEMPTS, delay)
|
|
139
154
|
if (!await wait(delay, abortController.signal)) return
|
|
140
155
|
}
|
|
141
156
|
}
|
|
@@ -187,23 +202,40 @@ class AgentlessConfigurationSource {
|
|
|
187
202
|
*/
|
|
188
203
|
#apply (response) {
|
|
189
204
|
const statusCode = response.statusCode
|
|
190
|
-
if (statusCode === 304)
|
|
205
|
+
if (statusCode === 304) {
|
|
206
|
+
// A custom endpoint can answer 304 without having been sent an ETag, so it confirms nothing
|
|
207
|
+
// until a configuration has been applied.
|
|
208
|
+
if (this.#appliedCreatedAt === undefined) {
|
|
209
|
+
this.#logPollFailure('HTTP 304 received before any configuration was applied')
|
|
210
|
+
} else {
|
|
211
|
+
this.#logPollRecovery()
|
|
212
|
+
}
|
|
213
|
+
return
|
|
214
|
+
}
|
|
191
215
|
|
|
192
216
|
if (statusCode === 401 || statusCode === 403) {
|
|
193
217
|
this.#warnFailure(statusCode, undefined, 1)
|
|
218
|
+
this.#logPollFailure('authentication failed, not retried')
|
|
194
219
|
return
|
|
195
220
|
}
|
|
196
221
|
|
|
197
|
-
if (statusCode !== 200)
|
|
222
|
+
if (statusCode !== 200) {
|
|
223
|
+
this.#logPollFailure('HTTP status is not retryable')
|
|
224
|
+
return
|
|
225
|
+
}
|
|
198
226
|
|
|
199
227
|
let configuration
|
|
200
228
|
try {
|
|
201
229
|
configuration = parseConfiguration(response.body)
|
|
202
|
-
} catch {
|
|
230
|
+
} catch (error) {
|
|
203
231
|
if (!this.#malformedPayloadLogged) {
|
|
204
232
|
this.#malformedPayloadLogged = true
|
|
205
233
|
log.error('Feature Flagging agentless endpoint returned malformed UFC payload')
|
|
206
234
|
}
|
|
235
|
+
// JSON.parse messages quote the payload, so only report our own validation reasons.
|
|
236
|
+
log.debug('Feature Flags: agentless configuration payload rejected: %s',
|
|
237
|
+
error instanceof SyntaxError ? 'response body is not valid JSON' : error.message)
|
|
238
|
+
this.#logPollFailure('malformed UFC payload')
|
|
207
239
|
return
|
|
208
240
|
}
|
|
209
241
|
|
|
@@ -214,19 +246,49 @@ class AgentlessConfigurationSource {
|
|
|
214
246
|
this.#applicationFailureLogged = true
|
|
215
247
|
log.warn('Feature Flagging agentless UFC payload could not be applied: %s', errorMessage(error))
|
|
216
248
|
}
|
|
249
|
+
this.#logPollFailure('configuration could not be applied')
|
|
217
250
|
return
|
|
218
251
|
}
|
|
219
252
|
|
|
253
|
+
if (this.#config.flagSelectionSent) reportIgnoredFlagSelection(response.headers)
|
|
254
|
+
|
|
220
255
|
const etag = response.headers?.etag
|
|
221
256
|
const value = Array.isArray(etag) ? etag[0] : etag
|
|
222
257
|
this.#etag = value?.trim() || undefined
|
|
258
|
+
this.#appliedCreatedAt = configuration.createdAt
|
|
223
259
|
|
|
224
260
|
// eslint-disable-next-line eslint-rules/eslint-log-printf-style
|
|
225
261
|
log.debug(() => {
|
|
226
|
-
const flagCount = Object.keys(configuration.flags
|
|
262
|
+
const flagCount = Object.keys(configuration.flags).length
|
|
263
|
+
// A custom endpoint is requested as configured, so DD_ENV is only sent when the URL carries dd_env.
|
|
264
|
+
const requestedEnv = this.#config.endpoint.searchParams.get('dd_env')
|
|
227
265
|
return 'Feature Flags: agentless configuration applied successfully ' +
|
|
228
|
-
`(${flagCount} flag(s)
|
|
266
|
+
`(${flagCount} flag(s) received; per-flag validity is checked at evaluation, ` +
|
|
267
|
+
`configuration environment=${configuration.environment.name}, ` +
|
|
268
|
+
`createdAt=${configuration.createdAt}, etag=${this.#etag ?? 'none'}, ` +
|
|
269
|
+
`sdk env=${this.#config.env ?? 'unset'}, requested dd_env=${requestedEnv ?? 'not sent'})`
|
|
229
270
|
})
|
|
271
|
+
this.#logPollRecovery()
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* @param {string} reason
|
|
276
|
+
*/
|
|
277
|
+
#logPollFailure (reason) {
|
|
278
|
+
this.#failedPolls++
|
|
279
|
+
if (this.#appliedCreatedAt === undefined) {
|
|
280
|
+
log.debug(POLL_FAILED_WITHOUT_CONFIGURATION, reason)
|
|
281
|
+
} else {
|
|
282
|
+
log.debug('Feature Flags: agentless configuration poll failed (%s); keeping the configuration created at %s',
|
|
283
|
+
reason, this.#appliedCreatedAt)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
#logPollRecovery () {
|
|
288
|
+
if (this.#failedPolls === 0) return
|
|
289
|
+
|
|
290
|
+
log.debug('Feature Flags: agentless configuration poll succeeded after %d failed poll(s)', this.#failedPolls)
|
|
291
|
+
this.#failedPolls = 0
|
|
230
292
|
}
|
|
231
293
|
|
|
232
294
|
/**
|
|
@@ -2,15 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
const { createSiteUrl } = require('../exporters/common/url')
|
|
4
4
|
const log = require('../log')
|
|
5
|
+
const { warnRemoteConfigFlagSelection, withFlagSelection } = require('./flag-selection')
|
|
5
6
|
|
|
6
7
|
const DEFAULT_AGENTLESS_PATH = '/api/v2/feature-flagging/config/rules-based/server'
|
|
7
8
|
const MAX_POLL_INTERVAL_SECONDS = 60 * 60
|
|
9
|
+
const AGENTLESS_START_MESSAGE = 'Feature Flags: starting agentless configuration source at %s ' +
|
|
10
|
+
'(%s endpoint, poll interval %ds, request timeout %ds, DD-API-KEY header %s)'
|
|
11
|
+
const REMOTE_CONFIG_DISABLED_WARNING = 'Feature Flags: configuration source is remote_config but Remote ' +
|
|
12
|
+
'Configuration is disabled; flag evaluations will return their default values. Set ' +
|
|
13
|
+
'DD_REMOTE_CONFIGURATION_ENABLED=true or DD_FEATURE_FLAGS_CONFIGURATION_SOURCE=agentless'
|
|
14
|
+
const MISSING_API_KEY_MESSAGE = 'DD_API_KEY is required for the default Datadog Feature Flagging endpoint; ' +
|
|
15
|
+
'set DD_API_KEY, set DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL, or set ' +
|
|
16
|
+
'DD_FEATURE_FLAGS_CONFIGURATION_SOURCE=remote_config to load flags through the Datadog Agent'
|
|
8
17
|
|
|
9
18
|
/**
|
|
10
19
|
* @typedef {import('@datadog/openfeature-node-server').UniversalFlagConfigurationV1} UniversalFlagConfiguration
|
|
11
20
|
*/
|
|
12
21
|
|
|
13
22
|
/**
|
|
23
|
+
* Creates the agentless source when it is the selected configuration source.
|
|
24
|
+
*
|
|
25
|
+
* Throws when the agentless source is selected but cannot start, so the provider can fail initialization.
|
|
26
|
+
*
|
|
14
27
|
* @param {import('../config/config-base')} config
|
|
15
28
|
* @param {(configuration: UniversalFlagConfiguration) => void} applyConfiguration
|
|
16
29
|
*/
|
|
@@ -21,35 +34,46 @@ function create (config, applyConfiguration) {
|
|
|
21
34
|
DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_POLL_INTERVAL_SECONDS: pollIntervalSeconds,
|
|
22
35
|
DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_REQUEST_TIMEOUT_SECONDS: requestTimeoutSeconds,
|
|
23
36
|
DD_FEATURE_FLAGS_ENABLED: enabled,
|
|
37
|
+
flagSelection,
|
|
24
38
|
} = config.featureFlags
|
|
25
39
|
|
|
26
40
|
if (!enabled) return
|
|
27
41
|
|
|
28
42
|
if (source !== 'agentless') {
|
|
29
43
|
log.debug('Feature Flags: configuration source is %s, not agentless; skipping agentless setup', source)
|
|
44
|
+
if (source === 'remote_config') {
|
|
45
|
+
if (!config.remoteConfig?.DD_REMOTE_CONFIGURATION_ENABLED) log.warn(REMOTE_CONFIG_DISABLED_WARNING)
|
|
46
|
+
warnRemoteConfigFlagSelection(flagSelection)
|
|
47
|
+
}
|
|
30
48
|
return
|
|
31
49
|
}
|
|
32
50
|
|
|
33
51
|
const hasCustomEndpoint = Boolean(baseUrl?.trim())
|
|
34
52
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
throw new Error('DD_API_KEY is required for the default Datadog Feature Flagging endpoint')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const AgentlessConfigurationSource = require('./agentless_configuration_source')
|
|
41
|
-
const resolvedEndpoint = endpoint(config, baseUrl)
|
|
42
|
-
log.debug('Feature Flags: starting agentless configuration source at %s', redactedUrl(resolvedEndpoint))
|
|
43
|
-
return new AgentlessConfigurationSource({
|
|
44
|
-
endpoint: resolvedEndpoint,
|
|
45
|
-
pollIntervalMs: Math.min(pollIntervalSeconds, MAX_POLL_INTERVAL_SECONDS) * 1000,
|
|
46
|
-
requestTimeoutMs: requestTimeoutSeconds * 1000,
|
|
47
|
-
apiKey: hasCustomEndpoint ? undefined : config.DD_API_KEY,
|
|
48
|
-
env: config.env,
|
|
49
|
-
}, applyConfiguration)
|
|
50
|
-
} catch (error) {
|
|
51
|
-
log.error('Unable to configure Feature Flagging configuration source', error)
|
|
53
|
+
if (!hasCustomEndpoint && !config.DD_API_KEY?.trim()) {
|
|
54
|
+
throw new Error(MISSING_API_KEY_MESSAGE)
|
|
52
55
|
}
|
|
56
|
+
|
|
57
|
+
const AgentlessConfigurationSource = require('./agentless_configuration_source')
|
|
58
|
+
const resolvedEndpoint = endpoint(config, baseUrl)
|
|
59
|
+
const selectedEndpoint = withFlagSelection(resolvedEndpoint, flagSelection)
|
|
60
|
+
const effectivePollIntervalSeconds = Math.min(pollIntervalSeconds, MAX_POLL_INTERVAL_SECONDS)
|
|
61
|
+
log.debug(
|
|
62
|
+
AGENTLESS_START_MESSAGE,
|
|
63
|
+
redactedUrl(resolvedEndpoint),
|
|
64
|
+
hasCustomEndpoint ? 'custom' : 'default',
|
|
65
|
+
effectivePollIntervalSeconds,
|
|
66
|
+
requestTimeoutSeconds,
|
|
67
|
+
hasCustomEndpoint ? 'not sent' : 'sent'
|
|
68
|
+
)
|
|
69
|
+
return new AgentlessConfigurationSource({
|
|
70
|
+
endpoint: selectedEndpoint ?? resolvedEndpoint,
|
|
71
|
+
flagSelectionSent: selectedEndpoint !== undefined,
|
|
72
|
+
pollIntervalMs: effectivePollIntervalSeconds * 1000,
|
|
73
|
+
requestTimeoutMs: requestTimeoutSeconds * 1000,
|
|
74
|
+
apiKey: hasCustomEndpoint ? undefined : config.DD_API_KEY,
|
|
75
|
+
env: config.env,
|
|
76
|
+
}, applyConfiguration)
|
|
53
77
|
}
|
|
54
78
|
|
|
55
79
|
/**
|
|
@@ -1,18 +1,81 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { inspect } = require('node:util')
|
|
4
|
+
|
|
3
5
|
const log = require('../log')
|
|
6
|
+
const { debugChannel } = require('../log/channels')
|
|
7
|
+
|
|
8
|
+
// Debug output must show raw values and contexts in full rather than inspect's default depth and length limits.
|
|
9
|
+
const INSPECT_OPTIONS = {
|
|
10
|
+
breakLength: Infinity,
|
|
11
|
+
compact: true,
|
|
12
|
+
customInspect: false,
|
|
13
|
+
depth: Infinity,
|
|
14
|
+
maxArrayLength: Infinity,
|
|
15
|
+
maxStringLength: Infinity,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const PROVIDER_RESOLUTION = 'datadog.debugLogging.providerResolution'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {import('@datadog/openfeature-node-server').UniversalFlagConfigurationV1} UniversalFlagConfiguration
|
|
22
|
+
*/
|
|
4
23
|
|
|
5
24
|
/**
|
|
6
25
|
* Logs full evaluation details under DD_TRACE_DEBUG, matching EvalMetricsHook's use of `finally`.
|
|
7
26
|
*/
|
|
8
27
|
class DebugLoggingHook {
|
|
28
|
+
#getConfiguration
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {() => UniversalFlagConfiguration | undefined} [getConfiguration] - Current configuration
|
|
32
|
+
*/
|
|
33
|
+
constructor (getConfiguration) {
|
|
34
|
+
this.#getConfiguration = getConfiguration
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Keeps the provider resolution so `finally` can tell it apart from a result replaced by a failing later hook.
|
|
39
|
+
*
|
|
40
|
+
* @param {{ hookData?: { set: (key: string, value: unknown) => void } }} hookContext - Hook context
|
|
41
|
+
* @param {object} evaluationDetails - Provider resolution details
|
|
42
|
+
*/
|
|
43
|
+
after (hookContext, evaluationDetails) {
|
|
44
|
+
if (!debugChannel.hasSubscribers) return
|
|
45
|
+
// A formatted snapshot preserves primitive fields and nested values before application hooks can mutate them.
|
|
46
|
+
hookContext?.hookData?.set(PROVIDER_RESOLUTION, inspect(evaluationDetails, INSPECT_OPTIONS))
|
|
47
|
+
}
|
|
48
|
+
|
|
9
49
|
/**
|
|
10
|
-
* @param {{
|
|
11
|
-
*
|
|
50
|
+
* @param {{
|
|
51
|
+
* flagKey: string,
|
|
52
|
+
* flagValueType?: string,
|
|
53
|
+
* defaultValue?: unknown,
|
|
54
|
+
* context?: object,
|
|
55
|
+
* hookData?: { get: (key: string) => unknown }
|
|
56
|
+
* }} hookContext - Hook context containing the flag key and evaluation inputs
|
|
57
|
+
* @param {object} evaluationDetails - Evaluation details observed by this hook
|
|
12
58
|
*/
|
|
13
59
|
finally (hookContext, evaluationDetails) {
|
|
14
60
|
try {
|
|
15
|
-
|
|
61
|
+
// eslint-disable-next-line eslint-rules/eslint-log-printf-style
|
|
62
|
+
log.debug(() => {
|
|
63
|
+
const configuration = this.#getConfiguration?.()
|
|
64
|
+
const configurationIdentity = configuration
|
|
65
|
+
? `configuration observed at logging time: createdAt=${configuration.createdAt}, ` +
|
|
66
|
+
`configuration environment=${configuration.environment?.name}`
|
|
67
|
+
: 'no configuration observed at logging time'
|
|
68
|
+
const details = inspect(evaluationDetails, INSPECT_OPTIONS)
|
|
69
|
+
let message = `Feature Flags: evaluated ${hookContext?.flagKey} (type=${hookContext?.flagValueType}, ` +
|
|
70
|
+
`default=${inspect(hookContext?.defaultValue, INSPECT_OPTIONS)}, ` +
|
|
71
|
+
`context=${inspect(hookContext?.context, INSPECT_OPTIONS)}, ${configurationIdentity}): ` +
|
|
72
|
+
`finally hook saw ${details}`
|
|
73
|
+
const resolution = hookContext?.hookData?.get(PROVIDER_RESOLUTION)
|
|
74
|
+
if (resolution !== undefined && resolution !== details) {
|
|
75
|
+
message += `; earlier resolution seen by provider hook: ${resolution}`
|
|
76
|
+
}
|
|
77
|
+
return message
|
|
78
|
+
})
|
|
16
79
|
} catch (error) {
|
|
17
80
|
try {
|
|
18
81
|
// Defense in depth; the OpenFeature SDK already guards finally hooks.
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const log = require('../log')
|
|
4
|
+
|
|
5
|
+
const METADATA_FEATURE_PREFIX = '__dd_feature.'
|
|
6
|
+
const METADATA_ALLOCATION_KEY = '__dd_allocation_key'
|
|
7
|
+
const METADATA_DO_LOG = '__dd_do_log'
|
|
8
|
+
const METADATA_EXPOSURE_CACHE_HIT = '__dd_exposure_cache_hit'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An OpenFeature hook that hands each completed flag evaluation to a callback,
|
|
12
|
+
* with the Datadog exposure decision, so an application can record exposures in
|
|
13
|
+
* its own data store.
|
|
14
|
+
*
|
|
15
|
+
* This hook is optional. The provider puts the same data in the flag metadata,
|
|
16
|
+
* so any OpenFeature hook can read it. This class reads it for you.
|
|
17
|
+
*
|
|
18
|
+
* Register it with `OpenFeature.addHooks(new ExposureHook(callback))` or on a
|
|
19
|
+
* client. The callback runs for every evaluation, including errors and repeats.
|
|
20
|
+
* Use `shouldSend()` to keep the new or changed exposures.
|
|
21
|
+
*
|
|
22
|
+
* When the provider's own hooks run and `DD_FEATURE_FLAGS_EXPOSURES_DATADOG_LOGGING_ENABLED`
|
|
23
|
+
* is on, these are exactly the exposures that Datadog sends. With that setting
|
|
24
|
+
* off, Datadog receives no exposures, and `shouldSend()` gives the same results.
|
|
25
|
+
*
|
|
26
|
+
* The callback runs on the evaluation thread: hand the data to a background
|
|
27
|
+
* queue instead of doing I/O in the callback. An exception from the callback
|
|
28
|
+
* does not affect the evaluation. The first one is logged at warn level, later
|
|
29
|
+
* ones at debug level.
|
|
30
|
+
*/
|
|
31
|
+
class ExposureHook {
|
|
32
|
+
#callback
|
|
33
|
+
#warned = false
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {(evaluation: ExposureEvaluation) => void} callback
|
|
37
|
+
*/
|
|
38
|
+
constructor (callback) {
|
|
39
|
+
if (typeof callback !== 'function') {
|
|
40
|
+
throw new TypeError('ExposureHook requires a callback function')
|
|
41
|
+
}
|
|
42
|
+
this.#callback = callback
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Runs in the final hook stage, so a later hook's error is seen.
|
|
47
|
+
*
|
|
48
|
+
* @param {import('@openfeature/core').HookContext} hookContext
|
|
49
|
+
* @param {import('@openfeature/core').EvaluationDetails<import('@openfeature/core').FlagValue>} evaluationDetails
|
|
50
|
+
*/
|
|
51
|
+
finally (hookContext, evaluationDetails) {
|
|
52
|
+
if (evaluationDetails == null) return
|
|
53
|
+
try {
|
|
54
|
+
const result = /** @type {unknown} */ (this.#callback(new ExposureEvaluation(hookContext, evaluationDetails)))
|
|
55
|
+
// An async callback reports its failure through the returned promise, which the catch below never sees.
|
|
56
|
+
if (isThenable(result)) result.then(undefined, error => this.#logFailure(error))
|
|
57
|
+
} catch (error) {
|
|
58
|
+
this.#logFailure(error)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** @param {unknown} error */
|
|
63
|
+
#logFailure (error) {
|
|
64
|
+
try {
|
|
65
|
+
if (this.#warned) {
|
|
66
|
+
log.debug('Exposure callback failed', error)
|
|
67
|
+
} else {
|
|
68
|
+
this.#warned = true
|
|
69
|
+
log.warn('Exposure callback failed; later failures are logged at debug level', error)
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
// Formatting a value the callback threw can itself throw; the evaluation must still succeed.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param {unknown} value
|
|
79
|
+
* @returns {value is PromiseLike<unknown>}
|
|
80
|
+
*/
|
|
81
|
+
function isThenable (value) {
|
|
82
|
+
return typeof (/** @type {{ then?: unknown } | null | undefined} */ (value))?.then === 'function'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** A completed evaluation and its Datadog exposure decision. */
|
|
86
|
+
class ExposureEvaluation {
|
|
87
|
+
/** @type {import('@openfeature/core').EvaluationDetails<import('@openfeature/core').FlagValue>} */
|
|
88
|
+
#details
|
|
89
|
+
|
|
90
|
+
/** @type {import('@openfeature/core').EvaluationContext | undefined} */
|
|
91
|
+
#context
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {import('@openfeature/core').HookContext} hookContext
|
|
95
|
+
* @param {import('@openfeature/core').EvaluationDetails<import('@openfeature/core').FlagValue>} details
|
|
96
|
+
*/
|
|
97
|
+
constructor (hookContext, details) {
|
|
98
|
+
this.flagKey = hookContext?.flagKey ?? details.flagKey
|
|
99
|
+
this.#details = details
|
|
100
|
+
// A wrapper may expose an unreadable context; the exposure decision below never reads it.
|
|
101
|
+
try {
|
|
102
|
+
this.#context = hookContext?.context
|
|
103
|
+
} catch {
|
|
104
|
+
this.#context = undefined
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The flag key, variant, value, error and flag metadata of the evaluation. */
|
|
109
|
+
get details () {
|
|
110
|
+
return this.#details
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The selected variant key, or undefined when the default value was returned. */
|
|
114
|
+
get variant () {
|
|
115
|
+
return this.#details.variant
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The key of the selected allocation, or undefined when none was selected. */
|
|
119
|
+
get allocation () {
|
|
120
|
+
const allocationKey = this.#details.flagMetadata?.[METADATA_ALLOCATION_KEY]
|
|
121
|
+
return typeof allocationKey === 'string' ? allocationKey : undefined
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The evaluation context, including the targeting key. */
|
|
125
|
+
get context () {
|
|
126
|
+
return this.#context
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The targeting key of the evaluation context, if readable. */
|
|
130
|
+
get targetingKey () {
|
|
131
|
+
const targetingKey = this.#context?.targetingKey
|
|
132
|
+
return typeof targetingKey === 'string' ? targetingKey : undefined
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* True when the evaluation succeeded and selected an allocation that logs
|
|
137
|
+
* exposures, whether or not this subject was already exposed.
|
|
138
|
+
*/
|
|
139
|
+
isExposure () {
|
|
140
|
+
return this.#details.errorCode === undefined &&
|
|
141
|
+
this.#details.variant != null &&
|
|
142
|
+
typeof this.allocation === 'string' &&
|
|
143
|
+
this.#details.flagMetadata?.[METADATA_DO_LOG] === true
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* True when this exposure repeats one already recorded for this subject:
|
|
148
|
+
* same allocation, variant and serial id. False for a new or changed
|
|
149
|
+
* exposure, and for an evaluation that is not an exposure.
|
|
150
|
+
*/
|
|
151
|
+
isCacheHit () {
|
|
152
|
+
return this.isExposure() && this.#details.flagMetadata?.[METADATA_EXPOSURE_CACHE_HIT] === true
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* True for a new or changed exposure: the decision the provider uses for
|
|
157
|
+
* Datadog.
|
|
158
|
+
*/
|
|
159
|
+
shouldSend () {
|
|
160
|
+
return this.isExposure() && this.#details.flagMetadata?.[METADATA_EXPOSURE_CACHE_HIT] === false
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The HOOK features of the selected split, such as `holdout.key` and
|
|
165
|
+
* `holdout.assignment_group`. Values are a string, number or boolean.
|
|
166
|
+
* Read-only; empty when the split has none.
|
|
167
|
+
*/
|
|
168
|
+
getFeatures () {
|
|
169
|
+
const metadata = this.#details.flagMetadata
|
|
170
|
+
const features = Object.create(null)
|
|
171
|
+
if (metadata != null) {
|
|
172
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
173
|
+
if (!key.startsWith(METADATA_FEATURE_PREFIX)) continue
|
|
174
|
+
if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') continue
|
|
175
|
+
features[key.slice(METADATA_FEATURE_PREFIX.length)] = value
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return Object.freeze(features)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
module.exports = {
|
|
183
|
+
ExposureEvaluation,
|
|
184
|
+
ExposureHook,
|
|
185
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const log = require('../log')
|
|
4
|
+
const telemetryMetrics = require('../telemetry/metrics')
|
|
5
|
+
|
|
6
|
+
// Fastly answers URLs over 8 KB with 414 URI Too Long: https://docs.fastly.com/products/network-services-resource-limits
|
|
7
|
+
const MAX_RULES_URL_BYTES = 8192
|
|
8
|
+
const NOT_SENT = 'featureFlags.flagSelection was not sent (%s: %s). Loading the full flag configuration.'
|
|
9
|
+
const IGNORED = 'featureFlags.flagSelection was ignored by the server (%s). Loaded the full flag configuration.'
|
|
10
|
+
const REMOTE_CONFIG_UNSUPPORTED = 'featureFlags.flagSelection is not supported when flags are delivered through ' +
|
|
11
|
+
'Remote Config. Loading the full flag configuration.'
|
|
12
|
+
const MALFORMED_LIMIT = 'featureFlags.flagSelection must be an object with optional tags and keyPatterns string arrays'
|
|
13
|
+
const URL_LIMIT = `the request URL is at most ${MAX_RULES_URL_BYTES} bytes`
|
|
14
|
+
const IGNORED_REASONS = new Set([
|
|
15
|
+
'malformed_selection',
|
|
16
|
+
'too_many_values',
|
|
17
|
+
'invalid_key_pattern',
|
|
18
|
+
'invalid_tag',
|
|
19
|
+
'tag_load_failed',
|
|
20
|
+
])
|
|
21
|
+
|
|
22
|
+
const tracerMetrics = telemetryMetrics.manager.namespace('tracers')
|
|
23
|
+
const countedDroppedReasons = new Set()
|
|
24
|
+
const reportedIgnoredReasons = new Set()
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {'malformed_selection' | 'too_many_values' | 'invalid_key_pattern' | 'invalid_tag'} DropReason
|
|
28
|
+
* @typedef {{ selection?: { tags: string[], keyPatterns: string[] }, error?: DropReason }} CanonicalizeResult
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
let flaggingCore
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {unknown} option - Raw `featureFlags.flagSelection` value; must not be null or undefined.
|
|
35
|
+
* @returns {CanonicalizeResult}
|
|
36
|
+
*/
|
|
37
|
+
function canonicalize (option) {
|
|
38
|
+
try {
|
|
39
|
+
flaggingCore ??= require('../../../../vendor/dist/@datadog/flagging-core')
|
|
40
|
+
return flaggingCore.canonicalizeFlagSelection(option)
|
|
41
|
+
} catch {
|
|
42
|
+
// Canonicalization failed or the vendored bundle could not load: nothing can be sent.
|
|
43
|
+
return { error: 'malformed_selection' }
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {DropReason} reason
|
|
49
|
+
*/
|
|
50
|
+
function limitDescription (reason) {
|
|
51
|
+
switch (reason) {
|
|
52
|
+
case 'malformed_selection':
|
|
53
|
+
return MALFORMED_LIMIT
|
|
54
|
+
case 'too_many_values':
|
|
55
|
+
return `each list accepts at most ${flaggingCore.MAX_FLAG_SELECTION_VALUES} values`
|
|
56
|
+
case 'invalid_key_pattern':
|
|
57
|
+
return `each key pattern is at most ${flaggingCore.MAX_FLAG_SELECTION_KEY_PATTERN_BYTES} UTF-8 bytes`
|
|
58
|
+
case 'invalid_tag':
|
|
59
|
+
return `each tag is at most ${flaggingCore.MAX_FLAG_SELECTION_TAG_BYTES} UTF-8 bytes`
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {DropReason} reason
|
|
65
|
+
* @param {string} limit
|
|
66
|
+
*/
|
|
67
|
+
function reportDropped (reason, limit) {
|
|
68
|
+
log.error(NOT_SENT, reason, limit)
|
|
69
|
+
if (countedDroppedReasons.has(reason)) return
|
|
70
|
+
countedDroppedReasons.add(reason)
|
|
71
|
+
tracerMetrics.count('flag_selection.dropped', { reason }).inc()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Percent-encodes everything outside the RFC 3986 unreserved set; `encodeURIComponent` keeps `!'()*`.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} value
|
|
78
|
+
*/
|
|
79
|
+
function encodeQueryValue (value) {
|
|
80
|
+
return encodeURIComponent(value)
|
|
81
|
+
.replaceAll(/[!'()*]/g, char => `%${char.charCodeAt(0).toString(16).toUpperCase()}`)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Adds the canonical selection to the rules endpoint query, or reports why it is not sent.
|
|
86
|
+
*
|
|
87
|
+
* @param {URL} endpoint
|
|
88
|
+
* @param {unknown} option - Raw `featureFlags.flagSelection` value.
|
|
89
|
+
* @returns {URL | undefined} The endpoint with the selection, or undefined when no selection is sent.
|
|
90
|
+
*/
|
|
91
|
+
function withFlagSelection (endpoint, option) {
|
|
92
|
+
if (option === undefined || option === null) return
|
|
93
|
+
|
|
94
|
+
const { selection, error } = canonicalize(option)
|
|
95
|
+
if (error) {
|
|
96
|
+
reportDropped(error, limitDescription(error))
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
if (!selection) return
|
|
100
|
+
|
|
101
|
+
let parameters
|
|
102
|
+
try {
|
|
103
|
+
parameters = [
|
|
104
|
+
...selection.tags.map(tag => `selected_flag_tags=${encodeQueryValue(tag)}`),
|
|
105
|
+
...selection.keyPatterns.map(pattern => `selected_flag_key_patterns=${encodeQueryValue(pattern)}`),
|
|
106
|
+
].join('&')
|
|
107
|
+
} catch {
|
|
108
|
+
// flagging-core validates entries by index but canonicalizes through the iterator, which can yield bad text.
|
|
109
|
+
reportDropped('malformed_selection', MALFORMED_LIMIT)
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
const url = new URL(endpoint)
|
|
113
|
+
const query = url.search.slice(1)
|
|
114
|
+
url.search = query ? `${query}&${parameters}` : parameters
|
|
115
|
+
|
|
116
|
+
if (Buffer.byteLength(url.href) > MAX_RULES_URL_BYTES) {
|
|
117
|
+
reportDropped('too_many_values', URL_LIMIT)
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
return url
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @param {import('node:http').IncomingHttpHeaders | undefined} headers - Headers of an applied 200 response.
|
|
125
|
+
*/
|
|
126
|
+
function reportIgnoredFlagSelection (headers) {
|
|
127
|
+
const value = headers?.['dd-flag-selection-ignored']
|
|
128
|
+
if (value === undefined || value === '') return
|
|
129
|
+
|
|
130
|
+
// Anything but an exact known reason is reported as unknown, so header content never reaches logs or telemetry.
|
|
131
|
+
const reason = typeof value === 'string' && IGNORED_REASONS.has(value) ? value : 'unknown'
|
|
132
|
+
if (reportedIgnoredReasons.has(reason)) return
|
|
133
|
+
reportedIgnoredReasons.add(reason)
|
|
134
|
+
log.error(IGNORED, reason)
|
|
135
|
+
tracerMetrics.count('flag_selection.ignored', { reason }).inc()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @param {unknown} option - Raw `featureFlags.flagSelection` value.
|
|
140
|
+
*/
|
|
141
|
+
function warnRemoteConfigFlagSelection (option) {
|
|
142
|
+
if (option === undefined || option === null) return
|
|
143
|
+
|
|
144
|
+
const { selection, error } = canonicalize(option)
|
|
145
|
+
if (selection || error) log.warn(REMOTE_CONFIG_UNSUPPORTED)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
module.exports = {
|
|
149
|
+
reportIgnoredFlagSelection,
|
|
150
|
+
warnRemoteConfigFlagSelection,
|
|
151
|
+
withFlagSelection,
|
|
152
|
+
}
|