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
|
@@ -5,6 +5,8 @@ const realSetTimeout = setTimeout
|
|
|
5
5
|
const realClearTimeout = clearTimeout
|
|
6
6
|
|
|
7
7
|
const { performance } = require('node:perf_hooks')
|
|
8
|
+
|
|
9
|
+
const { getTestAnnotations } = require('../../dd-trace/src/ci-visibility/test-annotations')
|
|
8
10
|
const satisfies = require('../../../vendor/dist/semifies')
|
|
9
11
|
|
|
10
12
|
const shimmer = require('../../datadog-shimmer')
|
|
@@ -188,7 +190,7 @@ function isAutomaticFailureVideoAttachment (attachment) {
|
|
|
188
190
|
}
|
|
189
191
|
|
|
190
192
|
function isValidKnownTests (receivedKnownTests) {
|
|
191
|
-
return !!receivedKnownTests
|
|
193
|
+
return !!receivedKnownTests?.playwright
|
|
192
194
|
}
|
|
193
195
|
|
|
194
196
|
function getTestFullyQualifiedName (test) {
|
|
@@ -279,10 +281,12 @@ function shouldRunEarlyFlakeDetection () {
|
|
|
279
281
|
}
|
|
280
282
|
|
|
281
283
|
function isTestEfdManaged (test) {
|
|
282
|
-
return
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
284
|
+
return !test._ddIsAutomaticRetryExcluded && !getTestAnnotations(test.fn).noAutoRetry && (
|
|
285
|
+
!!test._ddIsEfdManagedTest || (
|
|
286
|
+
(test._ddIsNew || test._ddIsModified) &&
|
|
287
|
+
!test._ddIsAttemptToFix &&
|
|
288
|
+
shouldRunEarlyFlakeDetection()
|
|
289
|
+
)
|
|
286
290
|
)
|
|
287
291
|
}
|
|
288
292
|
|
|
@@ -440,13 +444,31 @@ function shouldSkipEfdRetryTest (test) {
|
|
|
440
444
|
return shouldSkipEfdRetry(test._ddEfdRetryIndex, retryCount)
|
|
441
445
|
}
|
|
442
446
|
|
|
447
|
+
/** @param {object} test */
|
|
448
|
+
function getExclusionTags (test) {
|
|
449
|
+
const { mustFail, noAutoRetry } = getTestAnnotations(test.fn)
|
|
450
|
+
const properties = test._ddAssignedProperties
|
|
451
|
+
const tags = {}
|
|
452
|
+
if (mustFail) tags['test.test_management.prevent_failure_suppression'] = 'true'
|
|
453
|
+
if (noAutoRetry) tags['test.test_management.no_auto_retry'] = 'true'
|
|
454
|
+
if (properties?.attempt_to_fix) tags['test.test_management.is_attempt_to_fix'] = 'true'
|
|
455
|
+
if (properties?.disabled) tags['test.test_management.is_test_disabled'] = 'true'
|
|
456
|
+
if (properties?.quarantined) tags['test.test_management.is_quarantined'] = 'true'
|
|
457
|
+
return tags
|
|
458
|
+
}
|
|
459
|
+
|
|
443
460
|
function getTestProperties (test) {
|
|
444
461
|
const testName = getTestFullname(test)
|
|
445
462
|
const testSuite = getTestSuitePath(test._requireFile, rootDir)
|
|
446
463
|
|
|
447
464
|
const { attempt_to_fix: attemptToFix, disabled, quarantined } =
|
|
448
465
|
testManagementTests?.playwright?.suites?.[testSuite]?.tests?.[testName]?.properties || {}
|
|
449
|
-
|
|
466
|
+
const { mustFail, noAutoRetry } = getTestAnnotations(test.fn)
|
|
467
|
+
return {
|
|
468
|
+
attemptToFix: attemptToFix && !noAutoRetry && !test._ddIsAutomaticRetryExcluded,
|
|
469
|
+
disabled: disabled && !mustFail,
|
|
470
|
+
quarantined: quarantined && !mustFail,
|
|
471
|
+
}
|
|
450
472
|
}
|
|
451
473
|
|
|
452
474
|
function isNewTest (test) {
|
|
@@ -480,6 +502,7 @@ function deepCloneSuite (suite, filterTest, tags = [], configureCopiedTest) {
|
|
|
480
502
|
} else {
|
|
481
503
|
if (filterTest(entry)) {
|
|
482
504
|
const copiedTest = entry._clone()
|
|
505
|
+
copiedTest._ddAssignedProperties = entry._ddAssignedProperties
|
|
483
506
|
originalTestIdsByRetry.set(copiedTest, originalTestIdsByRetry.get(entry) ?? entry.id)
|
|
484
507
|
if (configureCopiedTest) {
|
|
485
508
|
configureCopiedTest(copiedTest, entry)
|
|
@@ -799,6 +822,7 @@ function testBeginHandler (test, browserName, shouldCreateTestSpan) {
|
|
|
799
822
|
if (shouldCreateTestSpan) {
|
|
800
823
|
const testName = getTestFullname(test)
|
|
801
824
|
const testCtx = {
|
|
825
|
+
extraTags: getExclusionTags(test),
|
|
802
826
|
testName,
|
|
803
827
|
testSuiteAbsolutePath,
|
|
804
828
|
testSourceFileAbsolutePath,
|
|
@@ -850,6 +874,7 @@ function finishTestSuiteIfDone (testSuiteAbsolutePath, projects) {
|
|
|
850
874
|
const browserName = getBrowserNameFromProjects(projects, test)
|
|
851
875
|
recordSkippedTestOptimizationExecution(test, testSuiteAbsolutePath)
|
|
852
876
|
testSkipCh.publish({
|
|
877
|
+
extraTags: getExclusionTags(test),
|
|
853
878
|
testName: getTestFullname(test),
|
|
854
879
|
testSuiteAbsolutePath,
|
|
855
880
|
testSourceFileAbsolutePath: test.location.file,
|
|
@@ -885,7 +910,7 @@ function finishTestSuiteIfDone (testSuiteAbsolutePath, projects) {
|
|
|
885
910
|
* @param {object[]} projects
|
|
886
911
|
*/
|
|
887
912
|
function hasAutomaticRetries (test, projects) {
|
|
888
|
-
if (!automaticRetryProjects.has(getTestProject(projects, test))) return false
|
|
913
|
+
if (test._ddIsAutomaticRetryExcluded || !automaticRetryProjects.has(getTestProject(projects, test))) return false
|
|
889
914
|
for (let suite = test.parent; suite; suite = suite.parent) {
|
|
890
915
|
if (suite._retries !== undefined) return false
|
|
891
916
|
}
|
|
@@ -984,7 +1009,7 @@ function testEndHandler ({
|
|
|
984
1009
|
const testProperties = getTestProperties(test)
|
|
985
1010
|
if (
|
|
986
1011
|
isDynamicAtrEnabled &&
|
|
987
|
-
isFlakyTestRetriesEnabled &&
|
|
1012
|
+
isFlakyTestRetriesEnabled && !getTestAnnotations(test.fn).noAutoRetry &&
|
|
988
1013
|
!testProperties.attemptToFix &&
|
|
989
1014
|
!test._ddIsEfdRetry &&
|
|
990
1015
|
!isEfdManagedTest &&
|
|
@@ -1057,7 +1082,9 @@ function testEndHandler ({
|
|
|
1057
1082
|
const atrRetryCount = isDynamicAtrEnabled
|
|
1058
1083
|
? dynamicAtrRetryCountByTestKey.get(dynamicAtrTestKey) ?? test.retries
|
|
1059
1084
|
: flakyTestRetriesCount
|
|
1060
|
-
if (
|
|
1085
|
+
if (!test._ddIsAutomaticRetryExcluded && !getTestAnnotations(test.fn).noAutoRetry &&
|
|
1086
|
+
isFlakyTestRetriesEnabled &&
|
|
1087
|
+
!testProperties.attemptToFix && !test._ddIsEfdRetry &&
|
|
1061
1088
|
!(test._ddIsNew || test._ddIsModified) &&
|
|
1062
1089
|
atrRetryCount != null && atrRetryCount > 0 &&
|
|
1063
1090
|
// Serial suites can add skipped results before a test's first execution.
|
|
@@ -1076,8 +1103,8 @@ function testEndHandler ({
|
|
|
1076
1103
|
? test.id ?? test._id
|
|
1077
1104
|
: undefined
|
|
1078
1105
|
const isAtrRetry = testResult?.retry > 0 &&
|
|
1079
|
-
isFlakyTestRetriesEnabled &&
|
|
1080
|
-
hasAutomaticRetries(test, projects) &&
|
|
1106
|
+
isFlakyTestRetriesEnabled && !test._ddIsAutomaticRetryExcluded &&
|
|
1107
|
+
!getTestAnnotations(test.fn).noAutoRetry && hasAutomaticRetries(test, projects) &&
|
|
1081
1108
|
!test._ddIsAttemptToFix &&
|
|
1082
1109
|
!test._ddIsEfdRetry
|
|
1083
1110
|
|
|
@@ -1102,7 +1129,7 @@ function testEndHandler ({
|
|
|
1102
1129
|
steps: testResult?.steps || [],
|
|
1103
1130
|
isRetry: testResult?.retry > 0,
|
|
1104
1131
|
error,
|
|
1105
|
-
extraTags: annotationTags,
|
|
1132
|
+
extraTags: { ...annotationTags, ...getExclusionTags(test) },
|
|
1106
1133
|
isNew: test._ddIsNew,
|
|
1107
1134
|
hasDynamicName: test._ddIsNew && DYNAMIC_NAME_RE.test(getTestFullname(test)),
|
|
1108
1135
|
isAttemptToFix: test._ddIsAttemptToFix,
|
|
@@ -1340,8 +1367,8 @@ function onDispatcherCreateWorker (dispatcher, worker) {
|
|
|
1340
1367
|
worker[kDdPlaywrightFailureVideos].push(videos)
|
|
1341
1368
|
}
|
|
1342
1369
|
const isAtrRetry = testResult?.retry > 0 &&
|
|
1343
|
-
isFlakyTestRetriesEnabled &&
|
|
1344
|
-
hasAutomaticRetries(test, projects) &&
|
|
1370
|
+
isFlakyTestRetriesEnabled && !test._ddIsAutomaticRetryExcluded &&
|
|
1371
|
+
!getTestAnnotations(test.fn).noAutoRetry && hasAutomaticRetries(test, projects) &&
|
|
1345
1372
|
!test._ddIsAttemptToFix &&
|
|
1346
1373
|
!test._ddIsEfdRetry
|
|
1347
1374
|
|
|
@@ -1367,6 +1394,7 @@ function onDispatcherCreateWorker (dispatcher, worker) {
|
|
|
1367
1394
|
(!isFinalExecution || (isSerialTest(test) && test.results.length <= test.retries))
|
|
1368
1395
|
|
|
1369
1396
|
const ddProperties = {
|
|
1397
|
+
_ddAssignedProperties: test._ddAssignedProperties,
|
|
1370
1398
|
_ddRetryTestId: retryTestId,
|
|
1371
1399
|
_ddDeferFinalStatus: deferFinalStatus,
|
|
1372
1400
|
_ddIsDisabled: test._ddIsDisabled,
|
|
@@ -1487,6 +1515,7 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
|
|
|
1487
1515
|
const playwrightConfig = config?.config || runnerConfig.config || runnerConfig
|
|
1488
1516
|
rootDir = getRootDir(this, config)
|
|
1489
1517
|
const projects = getProjectsFromRunner(this, config)
|
|
1518
|
+
sessionProjects = projects
|
|
1490
1519
|
const isFailureScreenshotEnabled = isFailureScreenshotCaptureEnabled(projects)
|
|
1491
1520
|
const isFailureVideoEnabled = isFailureVideoCaptureEnabled(projects)
|
|
1492
1521
|
const isFailureVideoUploadSupported = satisfies(playwrightVersion, MINIMUM_FAILURE_VIDEO_UPLOAD_VERSION_RANGE)
|
|
@@ -1556,11 +1585,11 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
|
|
|
1556
1585
|
isKnownTestsEnabled = false
|
|
1557
1586
|
} else {
|
|
1558
1587
|
knownTests = receivedKnownTests
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1588
|
+
if (!isValidKnownTests(receivedKnownTests)) {
|
|
1589
|
+
isEarlyFlakeDetectionFaulty = true
|
|
1590
|
+
isEarlyFlakeDetectionEnabled = false
|
|
1591
|
+
isKnownTestsEnabled = false
|
|
1592
|
+
}
|
|
1564
1593
|
}
|
|
1565
1594
|
} catch (err) {
|
|
1566
1595
|
isEarlyFlakeDetectionEnabled = false
|
|
@@ -2198,10 +2227,6 @@ function applyRetriesToTests (
|
|
|
2198
2227
|
}
|
|
2199
2228
|
|
|
2200
2229
|
function processRootSuite (createRootSuiteReturnValue) {
|
|
2201
|
-
if (!isKnownTestsEnabled && !isTestManagementTestsEnabled && !isImpactedTestsEnabled) {
|
|
2202
|
-
return createRootSuiteReturnValue
|
|
2203
|
-
}
|
|
2204
|
-
|
|
2205
2230
|
if (!createRootSuiteReturnValue) {
|
|
2206
2231
|
return createRootSuiteReturnValue
|
|
2207
2232
|
}
|
|
@@ -2213,6 +2238,28 @@ function processRootSuite (createRootSuiteReturnValue) {
|
|
|
2213
2238
|
}
|
|
2214
2239
|
|
|
2215
2240
|
const allTests = rootSuite.allTests()
|
|
2241
|
+
const excludedSerialSuites = new Set()
|
|
2242
|
+
for (const test of allTests) {
|
|
2243
|
+
if (!getTestAnnotations(test.fn).noAutoRetry) continue
|
|
2244
|
+
for (let suite = test.parent; suite; suite = suite.parent) {
|
|
2245
|
+
if (suite._parallelMode === 'serial') excludedSerialSuites.add(suite)
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
for (const test of allTests) {
|
|
2249
|
+
test._ddAssignedProperties = isTestManagementTestsEnabled
|
|
2250
|
+
? testManagementTests?.playwright?.suites
|
|
2251
|
+
?.[getTestSuitePath(test._requireFile, rootDir)]?.tests?.[getTestFullname(test)]?.properties
|
|
2252
|
+
: undefined
|
|
2253
|
+
test._ddIsAutomaticRetryExcluded = false
|
|
2254
|
+
const hasInjectedRetries = isFlakyTestRetriesEnabled && hasAutomaticRetries(test, sessionProjects)
|
|
2255
|
+
let excludeRetries = getTestAnnotations(test.fn).noAutoRetry
|
|
2256
|
+
// Serial retries need every prerequisite, so exclude the group from both ATR and EFD.
|
|
2257
|
+
for (let suite = test.parent; !excludeRetries && suite; suite = suite.parent) {
|
|
2258
|
+
excludeRetries = excludedSerialSuites.has(suite)
|
|
2259
|
+
}
|
|
2260
|
+
test._ddIsAutomaticRetryExcluded = excludeRetries
|
|
2261
|
+
if (hasInjectedRetries && excludeRetries) test.retries = 0
|
|
2262
|
+
}
|
|
2216
2263
|
|
|
2217
2264
|
if (isTestManagementTestsEnabled) {
|
|
2218
2265
|
const fileSuitesWithManagedTestsToProjects = new Map()
|
|
@@ -2271,7 +2318,8 @@ function processRootSuite (createRootSuiteReturnValue) {
|
|
|
2271
2318
|
const fileSuitesWithImpactedTestsToProjects = new Map()
|
|
2272
2319
|
for (const impactedTest of impactedTests) {
|
|
2273
2320
|
impactedTest._ddIsModified = true
|
|
2274
|
-
if (
|
|
2321
|
+
if (!impactedTest._ddIsAutomaticRetryExcluded &&
|
|
2322
|
+
shouldRunEarlyFlakeDetection() && impactedTest.expectedStatus !== 'skipped' &&
|
|
2275
2323
|
!impactedTest._ddIsAttemptToFix) {
|
|
2276
2324
|
// Prevent ATR or `--retries` from retrying tests that EFD manages.
|
|
2277
2325
|
impactedTest.retries = 0
|
|
@@ -2285,7 +2333,7 @@ function processRootSuite (createRootSuiteReturnValue) {
|
|
|
2285
2333
|
// If something changes in the file, all tests in the file are impacted, except attempt-to-fix tests managed above.
|
|
2286
2334
|
applyRetriesToTests(
|
|
2287
2335
|
fileSuitesWithImpactedTestsToProjects,
|
|
2288
|
-
(test) => !test._ddIsAttemptToFix,
|
|
2336
|
+
(test) => !test._ddIsAttemptToFix && !test._ddIsAutomaticRetryExcluded,
|
|
2289
2337
|
[
|
|
2290
2338
|
'_ddIsModified',
|
|
2291
2339
|
'_ddIsEfdRetry',
|
|
@@ -2318,7 +2366,8 @@ function processRootSuite (createRootSuiteReturnValue) {
|
|
|
2318
2366
|
const fileSuitesWithNewTestsToProjects = new Map()
|
|
2319
2367
|
for (const newTest of newTests) {
|
|
2320
2368
|
newTest._ddIsNew = true
|
|
2321
|
-
if (
|
|
2369
|
+
if (!newTest._ddIsAutomaticRetryExcluded &&
|
|
2370
|
+
shouldRunEarlyFlakeDetection() && newTest.expectedStatus !== 'skipped' &&
|
|
2322
2371
|
!newTest._ddIsModified && !newTest._ddIsAttemptToFix) {
|
|
2323
2372
|
// Prevent ATR or `--retries` from retrying tests that EFD manages.
|
|
2324
2373
|
newTest.retries = 0
|
|
@@ -2332,7 +2381,7 @@ function processRootSuite (createRootSuiteReturnValue) {
|
|
|
2332
2381
|
|
|
2333
2382
|
applyRetriesToTests(
|
|
2334
2383
|
fileSuitesWithNewTestsToProjects,
|
|
2335
|
-
(test) => !test._ddIsAttemptToFix && isNewTest(test),
|
|
2384
|
+
(test) => !test._ddIsAttemptToFix && !test._ddIsAutomaticRetryExcluded && isNewTest(test),
|
|
2336
2385
|
[
|
|
2337
2386
|
'_ddIsNew',
|
|
2338
2387
|
'_ddIsEfdRetry',
|
|
@@ -2617,6 +2666,7 @@ function instrumentWorkerMainMethods (workerMain) {
|
|
|
2617
2666
|
// Probably yet another test worker exporter is needed in addition to the ones for mocha, jest and cucumber
|
|
2618
2667
|
// it's probably hard to tell that's a playwright worker though, as I don't think there is a specific env variable
|
|
2619
2668
|
const testCtx = {
|
|
2669
|
+
extraTags: getExclusionTags(test),
|
|
2620
2670
|
testName,
|
|
2621
2671
|
testSuiteAbsolutePath,
|
|
2622
2672
|
testSourceFileAbsolutePath,
|
|
@@ -2732,7 +2782,7 @@ function instrumentWorkerMainMethods (workerMain) {
|
|
|
2732
2782
|
deferFinalStatus: test._ddDeferFinalStatus,
|
|
2733
2783
|
steps: steps.filter(step => step.testId === testId),
|
|
2734
2784
|
error,
|
|
2735
|
-
extraTags: annotationTags,
|
|
2785
|
+
extraTags: { ...annotationTags, ...getExclusionTags(test) },
|
|
2736
2786
|
isNew: test._ddIsNew,
|
|
2737
2787
|
hasDynamicName: test._ddIsNew && DYNAMIC_NAME_RE.test(getTestFullname(test)),
|
|
2738
2788
|
isRetry: retry > 0,
|
|
@@ -2769,6 +2819,8 @@ function instrumentWorkerMainMethods (workerMain) {
|
|
|
2769
2819
|
} else if (event === 'stepEnd') {
|
|
2770
2820
|
const stepInfo = stepInfoByStepId[payload.stepId]
|
|
2771
2821
|
delete stepInfoByStepId[payload.stepId]
|
|
2822
|
+
if (!stepInfo) return dispatchEvent.apply(this, arguments)
|
|
2823
|
+
|
|
2772
2824
|
steps.push({
|
|
2773
2825
|
testId: stepInfo.testId,
|
|
2774
2826
|
startTime: new Date(stepInfo.startTime),
|
|
@@ -2823,6 +2875,7 @@ function generateSummaryWrapper (generateSummary) {
|
|
|
2823
2875
|
|
|
2824
2876
|
recordSkippedTestOptimizationExecution(test, testSuiteAbsolutePath)
|
|
2825
2877
|
testSkipCh.publish({
|
|
2878
|
+
extraTags: getExclusionTags(test),
|
|
2826
2879
|
testName: getTestFullname(test),
|
|
2827
2880
|
testSuiteAbsolutePath,
|
|
2828
2881
|
testSourceFileAbsolutePath,
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { channel } = require('./helpers/instrument')
|
|
4
|
+
|
|
5
|
+
const deriveStartChannel = channel('tracing:orchestrion:react-router:derive:start')
|
|
6
|
+
const loaderStartChannel = channel('apm:react-router:loader:start')
|
|
7
|
+
const actionStartChannel = channel('apm:react-router:action:start')
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {{ pattern?: string, unstable_pattern?: string }} RouteHandlerInfo
|
|
11
|
+
* @typedef {object} HandlerContext
|
|
12
|
+
* @property {string} routeId
|
|
13
|
+
* @property {string} [pattern]
|
|
14
|
+
* @property {(result: unknown, rejected: boolean) => void} [complete]
|
|
15
|
+
* @typedef {(callHandler: () => Promise<unknown>, info: RouteHandlerInfo) => Promise<unknown>} HandlerHook
|
|
16
|
+
* @typedef {{ loader: HandlerHook, action: HandlerHook }} RouteHooks
|
|
17
|
+
* @typedef {{ id: string, instrument: (hooks: RouteHooks) => void }} InstrumentableRoute
|
|
18
|
+
* @typedef {{ instrumentations?: object[], unstable_instrumentations?: object[] }} EntryModule
|
|
19
|
+
* @typedef {{ module?: EntryModule }} Entry
|
|
20
|
+
* @typedef {{ entry?: Entry }} ServerBuild
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {() => Promise<unknown>} callHandler
|
|
25
|
+
* @param {RouteHandlerInfo} info
|
|
26
|
+
* @param {string} routeId
|
|
27
|
+
* @param {import('node:diagnostics_channel').Channel} startChannel
|
|
28
|
+
*/
|
|
29
|
+
function callRouteHandler (callHandler, info, routeId, startChannel) {
|
|
30
|
+
if (!startChannel.hasSubscribers) return callHandler()
|
|
31
|
+
|
|
32
|
+
/** @type {HandlerContext} */
|
|
33
|
+
const context = {
|
|
34
|
+
routeId,
|
|
35
|
+
pattern: info?.pattern ?? info?.unstable_pattern,
|
|
36
|
+
complete: undefined,
|
|
37
|
+
}
|
|
38
|
+
const result = startChannel.runStores(context, callHandler)
|
|
39
|
+
const complete = context.complete
|
|
40
|
+
if (!complete) return result
|
|
41
|
+
|
|
42
|
+
return result.then(
|
|
43
|
+
value => {
|
|
44
|
+
complete(value, false)
|
|
45
|
+
return value
|
|
46
|
+
},
|
|
47
|
+
error => {
|
|
48
|
+
complete(error, true)
|
|
49
|
+
throw error
|
|
50
|
+
}
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const datadogInstrumentation = {
|
|
55
|
+
/** @param {InstrumentableRoute} route */
|
|
56
|
+
route (route) {
|
|
57
|
+
const routeId = route.id
|
|
58
|
+
route.instrument({
|
|
59
|
+
/**
|
|
60
|
+
* @param {() => Promise<unknown>} callHandler
|
|
61
|
+
* @param {RouteHandlerInfo} info
|
|
62
|
+
*/
|
|
63
|
+
loader (callHandler, info) {
|
|
64
|
+
return callRouteHandler(callHandler, info, routeId, loaderStartChannel)
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* @param {() => Promise<unknown>} callHandler
|
|
68
|
+
* @param {RouteHandlerInfo} info
|
|
69
|
+
*/
|
|
70
|
+
action (callHandler, info) {
|
|
71
|
+
return callRouteHandler(callHandler, info, routeId, actionStartChannel)
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @param {ServerBuild} build */
|
|
78
|
+
function injectInstrumentation (build) {
|
|
79
|
+
const entry = build?.entry
|
|
80
|
+
const entryModule = entry?.module
|
|
81
|
+
if (!entryModule || typeof entryModule !== 'object') return build
|
|
82
|
+
|
|
83
|
+
const stable = entryModule.instrumentations
|
|
84
|
+
const unstable = entryModule.unstable_instrumentations
|
|
85
|
+
return {
|
|
86
|
+
...build,
|
|
87
|
+
entry: {
|
|
88
|
+
...entry,
|
|
89
|
+
module: {
|
|
90
|
+
...entryModule,
|
|
91
|
+
instrumentations: Array.isArray(stable) ? [datadogInstrumentation, ...stable] : [datadogInstrumentation],
|
|
92
|
+
unstable_instrumentations: Array.isArray(unstable)
|
|
93
|
+
? [datadogInstrumentation, ...unstable]
|
|
94
|
+
: [datadogInstrumentation],
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** @param {unknown} message */
|
|
101
|
+
function onDeriveStart (message) {
|
|
102
|
+
const context = /** @type {{ arguments: ServerBuild[] }} */ (message)
|
|
103
|
+
context.arguments[0] = injectInstrumentation(context.arguments[0])
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
deriveStartChannel.subscribe(onDeriveStart)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { tracingChannel } = require('dc-polyfill')
|
|
4
|
+
|
|
5
|
+
const systemOneChannel = tracingChannel('orchestrion:@typesafe-ai/sdk:TypeSafeClient_systemOne')
|
|
6
|
+
const apiPromiseChannel = tracingChannel('orchestrion:@typesafe-ai/sdk:APIPromise_constructor')
|
|
7
|
+
|
|
8
|
+
const systemOneContexts = new WeakMap()
|
|
9
|
+
|
|
10
|
+
// `systemOne` returns its `APIPromise` without awaiting it, so the span finishes once the response arrives
|
|
11
|
+
systemOneChannel.end.subscribe(ctx => {
|
|
12
|
+
if (!systemOneChannel.start.hasSubscribers) return
|
|
13
|
+
|
|
14
|
+
// Copied like the SDK copies it, since the caller may change the object for its next call before this one finishes
|
|
15
|
+
const request = ctx.arguments[0]
|
|
16
|
+
if (request && typeof request === 'object') ctx.request = { ...request }
|
|
17
|
+
|
|
18
|
+
if (!ctx.error && ctx.result && typeof ctx.result === 'object') {
|
|
19
|
+
systemOneContexts.set(ctx.result, ctx)
|
|
20
|
+
} else {
|
|
21
|
+
finish(ctx)
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
// Every `APIPromise` method (awaiting, `asResponse()`, `withResponse()`, `map()`) reads the response promise passed to
|
|
26
|
+
// the constructor, so observing it covers each of them, and calls that are never awaited.
|
|
27
|
+
apiPromiseChannel.start.subscribe(ctx => {
|
|
28
|
+
const responsePromise = ctx.arguments[0]
|
|
29
|
+
if (!systemOneChannel.start.hasSubscribers || typeof responsePromise?.then !== 'function') return
|
|
30
|
+
|
|
31
|
+
ctx.arguments[0] = responsePromise.then(response => {
|
|
32
|
+
const systemOneCtx = systemOneContexts.get(ctx.self)
|
|
33
|
+
if (systemOneCtx) readResponse(systemOneCtx, response)
|
|
34
|
+
return response
|
|
35
|
+
}, error => {
|
|
36
|
+
const systemOneCtx = systemOneContexts.get(ctx.self)
|
|
37
|
+
if (systemOneCtx) finish(systemOneCtx, undefined, error)
|
|
38
|
+
throw error
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Reads the body from a clone so the caller's response stays unread.
|
|
44
|
+
*
|
|
45
|
+
* @param {object} ctx
|
|
46
|
+
* @param {Response} response
|
|
47
|
+
*/
|
|
48
|
+
function readResponse (ctx, response) {
|
|
49
|
+
try {
|
|
50
|
+
response.clone().text().then(body => {
|
|
51
|
+
ctx.responseText = body
|
|
52
|
+
finish(ctx, parseBody(body))
|
|
53
|
+
}, error => finish(ctx, undefined, error))
|
|
54
|
+
} catch (error) {
|
|
55
|
+
finish(ctx, undefined, error)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Parses the body the way the SDK does: JSON when it parses, otherwise the text itself.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} text
|
|
63
|
+
*/
|
|
64
|
+
function parseBody (text) {
|
|
65
|
+
if (text.length === 0) return
|
|
66
|
+
try {
|
|
67
|
+
return JSON.parse(text)
|
|
68
|
+
} catch {
|
|
69
|
+
return text
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param {object} ctx
|
|
75
|
+
* @param {unknown} [result]
|
|
76
|
+
* @param {Error} [error]
|
|
77
|
+
*/
|
|
78
|
+
function finish (ctx, result, error) {
|
|
79
|
+
if (ctx.finished) return
|
|
80
|
+
ctx.finished = true
|
|
81
|
+
|
|
82
|
+
if (error) {
|
|
83
|
+
ctx.error = error
|
|
84
|
+
systemOneChannel.error.publish(ctx)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
ctx.result = result
|
|
88
|
+
systemOneChannel.asyncEnd.publish(ctx)
|
|
89
|
+
}
|