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.
Files changed (353) hide show
  1. package/LICENSE-3rdparty.csv +0 -1
  2. package/ci/cypress/support.js +15 -1
  3. package/ci/init.js +2 -22
  4. package/ci/test-annotations.d.ts +5 -0
  5. package/ci/test-annotations.js +5 -0
  6. package/ci/vitest-no-worker-init-annotations.mjs +4 -0
  7. package/ci/vitest-no-worker-init-node-setup.mjs +22 -0
  8. package/ci/vitest-no-worker-init-runner-setup.mjs +7 -32
  9. package/ci/vitest-no-worker-init-setup.mjs +34 -12
  10. package/ci/vitest-no-worker-init-v5-setup.mjs +6 -0
  11. package/ext/exporters.js +1 -1
  12. package/index.d.ts +124 -5
  13. package/initialize.mjs +5 -2
  14. package/lambda.d.ts +39 -0
  15. package/lambda.js +3 -0
  16. package/loader-hook.mjs +53 -0
  17. package/openfeature/exposure-hook.d.ts +66 -0
  18. package/openfeature/exposure-hook.js +5 -0
  19. package/package.json +19 -15
  20. package/packages/datadog-core/src/storage.js +1 -1
  21. package/packages/datadog-esbuild/index.js +78 -62
  22. package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
  23. package/packages/datadog-instrumentations/src/cucumber.js +56 -19
  24. package/packages/datadog-instrumentations/src/cypress-config.js +163 -15
  25. package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
  26. package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
  27. package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
  28. package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
  29. package/packages/datadog-instrumentations/src/graphql.js +29 -20
  30. package/packages/datadog-instrumentations/src/grpc/server.js +23 -6
  31. package/packages/{datadog-esbuild/src/utils.js → datadog-instrumentations/src/helpers/bundler-esm-exports.js} +282 -40
  32. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +573 -0
  33. package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
  34. package/packages/datadog-instrumentations/src/helpers/fetch.js +5 -1
  35. package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +30 -8
  36. package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
  37. package/packages/datadog-instrumentations/src/helpers/hooks.js +4 -8
  38. package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
  39. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +18 -6
  40. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +26 -1
  41. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
  42. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
  43. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +3 -1
  44. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
  45. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +40 -0
  46. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
  47. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/react-router.js +49 -0
  48. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
  49. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/typesafe.js +23 -0
  50. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +12 -0
  51. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +58 -0
  52. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +19 -2
  53. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +25 -3
  54. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
  55. package/packages/datadog-instrumentations/src/ioredis.js +101 -3
  56. package/packages/datadog-instrumentations/src/jest.js +265 -82
  57. package/packages/datadog-instrumentations/src/mariadb-bundle.js +69 -11
  58. package/packages/datadog-instrumentations/src/mariadb.js +13 -6
  59. package/packages/datadog-instrumentations/src/mocha/common.js +89 -8
  60. package/packages/datadog-instrumentations/src/mocha/main.js +11 -2
  61. package/packages/datadog-instrumentations/src/mocha/utils.js +58 -12
  62. package/packages/datadog-instrumentations/src/mocha/worker.js +1 -1
  63. package/packages/datadog-instrumentations/src/next.js +19 -6
  64. package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
  65. package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
  66. package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
  67. package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
  68. package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
  69. package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
  70. package/packages/datadog-instrumentations/src/oracledb.js +33 -0
  71. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
  72. package/packages/datadog-instrumentations/src/pg.js +2 -1
  73. package/packages/datadog-instrumentations/src/playwright.js +81 -28
  74. package/packages/datadog-instrumentations/src/react-router.js +106 -0
  75. package/packages/datadog-instrumentations/src/typesafe.js +89 -0
  76. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +84 -48
  77. package/packages/datadog-instrumentations/src/vitest-main.js +26 -0
  78. package/packages/datadog-instrumentations/src/vitest-test-annotations.js +20 -0
  79. package/packages/datadog-instrumentations/src/vitest-worker.js +39 -17
  80. package/packages/datadog-instrumentations/src/vitest.js +10 -8
  81. package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
  82. package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
  83. package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
  84. package/packages/datadog-plugin-cucumber/src/index.js +5 -0
  85. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +296 -55
  86. package/packages/datadog-plugin-cypress/src/index.js +1 -1
  87. package/packages/datadog-plugin-cypress/src/lifecycle-owner.js +20 -0
  88. package/packages/datadog-plugin-cypress/src/plugin.js +10 -0
  89. package/packages/datadog-plugin-cypress/src/retry-config-observer.js +281 -0
  90. package/packages/datadog-plugin-cypress/src/setup-handoff.js +125 -0
  91. package/packages/datadog-plugin-cypress/src/support.js +1217 -439
  92. package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
  93. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -7
  94. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -52
  95. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +4 -2
  96. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
  97. package/packages/datadog-plugin-graphql/src/execute.js +2 -2
  98. package/packages/datadog-plugin-graphql/src/utils.js +5 -5
  99. package/packages/datadog-plugin-http/src/client.js +32 -9
  100. package/packages/datadog-plugin-http2/src/client.js +38 -13
  101. package/packages/datadog-plugin-jest/src/index.js +25 -3
  102. package/packages/datadog-plugin-mocha/src/index.js +47 -6
  103. package/packages/datadog-plugin-next/src/index.js +112 -14
  104. package/packages/datadog-plugin-oracledb/src/connection-parser.js +21 -11
  105. package/packages/datadog-plugin-playwright/src/index.js +4 -0
  106. package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
  107. package/packages/datadog-plugin-react-router/src/index.js +118 -0
  108. package/packages/datadog-plugin-trpc/src/index.js +15 -0
  109. package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
  110. package/packages/datadog-plugin-trpc/src/request.js +81 -0
  111. package/packages/datadog-plugin-typesafe/src/index.js +17 -0
  112. package/packages/datadog-plugin-typesafe/src/tracing.js +31 -0
  113. package/packages/datadog-plugin-undici/src/index.js +22 -7
  114. package/packages/datadog-plugin-vitest/src/index.js +8 -0
  115. package/packages/datadog-turbopack/index.js +4 -28
  116. package/packages/datadog-turbopack/src/loader.js +14 -452
  117. package/packages/datadog-webpack/index.js +3 -55
  118. package/packages/dd-trace/src/agent/info.js +2 -1
  119. package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
  120. package/packages/dd-trace/src/aiguard/sdk.js +8 -13
  121. package/packages/dd-trace/src/aiguard/tags.js +2 -0
  122. package/packages/dd-trace/src/appsec/blocking/index.js +4 -0
  123. package/packages/dd-trace/src/appsec/graphql.js +91 -6
  124. package/packages/dd-trace/src/appsec/recommended.json +1287 -90
  125. package/packages/dd-trace/src/before-exit.js +32 -0
  126. package/packages/dd-trace/src/bootstrap.js +5 -3
  127. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +24 -18
  128. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +16 -36
  129. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
  130. package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
  131. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +10 -18
  132. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +10 -15
  133. package/packages/dd-trace/src/ci-visibility/requests/route.js +44 -0
  134. package/packages/dd-trace/src/ci-visibility/telemetry-logs.js +5 -0
  135. package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
  136. package/packages/dd-trace/src/ci-visibility/test-annotations.js +72 -0
  137. package/packages/dd-trace/src/ci-visibility/test-declaration-annotations.js +170 -0
  138. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +10 -17
  139. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
  140. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
  141. package/packages/dd-trace/src/config/config-types.d.ts +3 -0
  142. package/packages/dd-trace/src/config/defaults.js +9 -3
  143. package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -2
  144. package/packages/dd-trace/src/config/index.js +111 -43
  145. package/packages/dd-trace/src/config/parsers.js +18 -1
  146. package/packages/dd-trace/src/config/supported-configurations.json +174 -4
  147. package/packages/dd-trace/src/constants.js +1 -0
  148. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +2 -1
  149. package/packages/dd-trace/src/debugger/probe_sampler.js +6 -6
  150. package/packages/dd-trace/src/encode/0.4.js +2 -2
  151. package/packages/dd-trace/src/esm-module-load.js +58 -0
  152. package/packages/dd-trace/src/exporter.js +23 -15
  153. package/packages/dd-trace/src/exporters/agent/index.js +3 -1
  154. package/packages/dd-trace/src/exporters/agentless/index.js +3 -1
  155. package/packages/dd-trace/src/exporters/common/request.js +83 -50
  156. package/packages/dd-trace/src/exporters/common/retry.js +12 -7
  157. package/packages/dd-trace/src/exporters/common/url.js +1 -1
  158. package/packages/dd-trace/src/exporters/llmobs/index.js +135 -0
  159. package/packages/dd-trace/src/exporters/log/index.js +4 -3
  160. package/packages/dd-trace/src/id.js +1 -1
  161. package/packages/dd-trace/src/lambda/facade.js +74 -0
  162. package/packages/dd-trace/src/lambda/handler.js +3 -41
  163. package/packages/dd-trace/src/lambda/index.js +38 -15
  164. package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
  165. package/packages/dd-trace/src/lambda/wrap.js +44 -0
  166. package/packages/dd-trace/src/llmobs/constants/tags.js +3 -0
  167. package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
  168. package/packages/dd-trace/src/llmobs/experiments/index.js +2 -3
  169. package/packages/dd-trace/src/llmobs/experiments/noop.js +5 -2
  170. package/packages/dd-trace/src/llmobs/index.js +13 -2
  171. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +1 -1
  172. package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
  173. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
  174. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +27 -10
  175. package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
  176. package/packages/dd-trace/src/llmobs/plugins/typesafe/index.js +102 -0
  177. package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
  178. package/packages/dd-trace/src/llmobs/prompts/cache.js +3 -1
  179. package/packages/dd-trace/src/llmobs/sdk.js +21 -1
  180. package/packages/dd-trace/src/llmobs/span_processor.js +219 -12
  181. package/packages/dd-trace/src/llmobs/tagger.js +25 -0
  182. package/packages/dd-trace/src/llmobs/writers/util.js +3 -3
  183. package/packages/dd-trace/src/log/channels.js +4 -0
  184. package/packages/dd-trace/src/log/writer.js +13 -2
  185. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +68 -6
  186. package/packages/dd-trace/src/openfeature/configuration_source.js +41 -17
  187. package/packages/dd-trace/src/openfeature/debug-logging-hook.js +66 -3
  188. package/packages/dd-trace/src/openfeature/exposure-hook.js +185 -0
  189. package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
  190. package/packages/dd-trace/src/openfeature/flagging_provider.js +58 -14
  191. package/packages/dd-trace/src/openfeature/remote_config.js +16 -3
  192. package/packages/dd-trace/src/openfeature/writers/base.js +63 -30
  193. package/packages/dd-trace/src/openfeature/writers/exposures.js +161 -1
  194. package/packages/dd-trace/src/openfeature/writers/flag-eval-evp-hook.js +5 -0
  195. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-aggregation.js +9 -4
  196. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-payload.js +2 -0
  197. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-pii.js +2 -0
  198. package/packages/dd-trace/src/openfeature/writers/split-features.js +25 -0
  199. package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
  200. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
  201. package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
  202. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
  203. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
  204. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -2
  205. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
  206. package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
  207. package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
  208. package/packages/dd-trace/src/opentelemetry/span.js +2 -2
  209. package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
  210. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
  211. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
  212. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +5 -1
  213. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
  214. package/packages/dd-trace/src/opentracing/tracer.js +33 -13
  215. package/packages/dd-trace/src/otel-thread-ctx.js +72 -49
  216. package/packages/dd-trace/src/plugin_manager.js +34 -7
  217. package/packages/dd-trace/src/plugins/ci_plugin.js +45 -14
  218. package/packages/dd-trace/src/plugins/index.js +9 -0
  219. package/packages/dd-trace/src/plugins/plugin.js +4 -2
  220. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  221. package/packages/dd-trace/src/plugins/util/ci.js +18 -1
  222. package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
  223. package/packages/dd-trace/src/plugins/util/git.js +273 -86
  224. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +77 -50
  225. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
  226. package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
  227. package/packages/dd-trace/src/plugins/util/tags.js +6 -0
  228. package/packages/dd-trace/src/plugins/util/test.js +90 -45
  229. package/packages/dd-trace/src/plugins/util/url.js +10 -2
  230. package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -2
  231. package/packages/dd-trace/src/plugins/util/web.js +81 -10
  232. package/packages/dd-trace/src/process-tags/index.js +1 -1
  233. package/packages/dd-trace/src/profiling/config.js +6 -3
  234. package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
  235. package/packages/dd-trace/src/proxy.js +48 -57
  236. package/packages/dd-trace/src/serverless.js +3 -2
  237. package/packages/dd-trace/src/span_processor.js +41 -9
  238. package/packages/dd-trace/src/span_stats.js +28 -2
  239. package/packages/dd-trace/src/startup-log.js +8 -5
  240. package/packages/dd-trace/src/tagger.js +7 -5
  241. package/packages/dd-trace/src/telemetry/dependencies.js +4 -0
  242. package/packages/dd-trace/src/telemetry/index.js +3 -0
  243. package/packages/dd-trace/src/telemetry/logs/index.js +21 -2
  244. package/packages/dd-trace/src/telemetry/logs/log-collector.js +1 -0
  245. package/packages/dd-trace/src/telemetry/metrics.js +2 -1
  246. package/packages/dd-trace/src/telemetry/telemetry.js +10 -3
  247. package/packages/dd-trace/src/tracer.js +0 -2
  248. package/packages/dd-trace/src/util.js +1 -1
  249. package/packages/dd-trace/src/web-tags-cache.js +8 -9
  250. package/register.js +4 -2
  251. package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
  252. package/vendor/dist/{@opentelemetry/resources → @datadog/flagging-core}/LICENSE +22 -2
  253. package/vendor/dist/@datadog/flagging-core/index.js +1 -0
  254. package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
  255. package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
  256. package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
  257. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.d.ts +78 -0
  258. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.js +1 -1
  259. package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
  260. package/vendor/dist/@datadog/source-map/LICENSE +1 -0
  261. package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
  262. package/vendor/dist/@opentelemetry/core/LICENSE +209 -1
  263. package/vendor/dist/@opentelemetry/core/index.js +1 -1
  264. package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
  265. package/vendor/dist/escape-string-regexp/LICENSE +13 -0
  266. package/vendor/dist/esquery/LICENSE +2 -0
  267. package/vendor/dist/https-proxy-agent/LICENSE +80 -1
  268. package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
  269. package/vendor/dist/jest-docblock/LICENSE +16 -0
  270. package/vendor/dist/jsonpath-plus/LICENSE +13 -0
  271. package/vendor/dist/limiter/LICENSE +2 -0
  272. package/vendor/dist/lodash.sortby/LICENSE +2 -0
  273. package/vendor/dist/lru-cache/LICENSE +13 -0
  274. package/vendor/dist/meriyah/LICENSE +13 -0
  275. package/vendor/dist/module-details-from-path/LICENSE +2 -0
  276. package/vendor/dist/mutexify/promise/LICENSE +28 -0
  277. package/vendor/dist/pprof-format/LICENSE +13 -0
  278. package/vendor/dist/pprof-format/index.js +1 -1
  279. package/vendor/dist/protobufjs/LICENSE +219 -0
  280. package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
  281. package/vendor/dist/proxy-from-env/LICENSE +13 -0
  282. package/vendor/dist/retry/LICENSE +2 -0
  283. package/vendor/dist/rfdc/LICENSE +2 -0
  284. package/vendor/dist/semifies/LICENSE +3 -1
  285. package/vendor/dist/shell-quote/LICENSE +3 -1
  286. package/vendor/dist/source-map/LICENSE +1 -0
  287. package/vendor/dist/source-map/lib/util/LICENSE +1 -0
  288. package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
  289. package/vendor/dist/ttl-set/LICENSE +28 -0
  290. package/ci/diagnose.js +0 -2215
  291. package/ci/runbook.md +0 -299
  292. package/ci/test-optimization-validation/approval-artifacts.js +0 -175
  293. package/ci/test-optimization-validation/approval.js +0 -386
  294. package/ci/test-optimization-validation/artifact-id.js +0 -19
  295. package/ci/test-optimization-validation/blocker-category.js +0 -24
  296. package/ci/test-optimization-validation/bounded-json.js +0 -120
  297. package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
  298. package/ci/test-optimization-validation/ci-discovery.js +0 -192
  299. package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
  300. package/ci/test-optimization-validation/ci-remediation.js +0 -283
  301. package/ci/test-optimization-validation/cli.js +0 -954
  302. package/ci/test-optimization-validation/command-blocker.js +0 -377
  303. package/ci/test-optimization-validation/command-output-policy.js +0 -188
  304. package/ci/test-optimization-validation/command-runner.js +0 -650
  305. package/ci/test-optimization-validation/environment.js +0 -88
  306. package/ci/test-optimization-validation/executable-approval.js +0 -47
  307. package/ci/test-optimization-validation/executable.js +0 -244
  308. package/ci/test-optimization-validation/execution-lock.js +0 -70
  309. package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
  310. package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
  311. package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
  312. package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
  313. package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
  314. package/ci/test-optimization-validation/generated-file-policy.js +0 -63
  315. package/ci/test-optimization-validation/generated-files.js +0 -425
  316. package/ci/test-optimization-validation/generated-test-contract.js +0 -284
  317. package/ci/test-optimization-validation/generated-verifier.js +0 -235
  318. package/ci/test-optimization-validation/literal-environment.js +0 -56
  319. package/ci/test-optimization-validation/literal-glob.js +0 -52
  320. package/ci/test-optimization-validation/manifest-loader.js +0 -116
  321. package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
  322. package/ci/test-optimization-validation/manifest-schema.js +0 -695
  323. package/ci/test-optimization-validation/offline-fixtures.js +0 -335
  324. package/ci/test-optimization-validation/offline-output.js +0 -406
  325. package/ci/test-optimization-validation/package-check.js +0 -97
  326. package/ci/test-optimization-validation/payload-normalizer.js +0 -72
  327. package/ci/test-optimization-validation/plan-writer.js +0 -541
  328. package/ci/test-optimization-validation/preflight-runner.js +0 -186
  329. package/ci/test-optimization-validation/project-build-artifact.js +0 -31
  330. package/ci/test-optimization-validation/redaction.js +0 -319
  331. package/ci/test-optimization-validation/report-writer.js +0 -666
  332. package/ci/test-optimization-validation/result-semantics.js +0 -103
  333. package/ci/test-optimization-validation/runner-command.js +0 -264
  334. package/ci/test-optimization-validation/runner-contract.js +0 -695
  335. package/ci/test-optimization-validation/safe-files.js +0 -202
  336. package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
  337. package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
  338. package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
  339. package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
  340. package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
  341. package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
  342. package/ci/test-optimization-validation/source-text.js +0 -84
  343. package/ci/test-optimization-validation/static-diagnosis.js +0 -166
  344. package/ci/test-optimization-validation/test-output.js +0 -120
  345. package/ci/test-optimization-validation/validation-blocker.js +0 -21
  346. package/ci/validate-test-optimization.js +0 -3
  347. package/packages/datadog-esbuild/src/resolver.js +0 -284
  348. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
  349. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
  350. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
  351. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
  352. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
  353. package/vendor/dist/@opentelemetry/resources/index.js +0 -1
@@ -139,6 +139,7 @@ let testManagementAttemptToFixRetries = 0
139
139
  let testManagementTests = {}
140
140
  let modifiedFiles = {}
141
141
  let numTestRetries = 0
142
+ let frameworkRetryCount = 0
142
143
  let knownTests = {}
143
144
  let skippedSuites = []
144
145
  let isSuitesSkipped = false
@@ -258,6 +259,7 @@ function configureParallelWorkerWorldParameters (options) {
258
259
  options.worldParameters._ddIsFlakyTestRetriesEnabled = isFlakyTestRetriesEnabled
259
260
  options.worldParameters._ddHasAutomaticRetries = hasAutomaticRetries
260
261
  options.worldParameters._ddNumTestRetries = numTestRetries
262
+ options.worldParameters._ddFrameworkRetryCount = frameworkRetryCount
261
263
  options.worldParameters._ddIsDynamicAtrEnabled = isDynamicAtrEnabled
262
264
  options.worldParameters._ddDynamicAtrBuckets = dynamicAtrBuckets
263
265
 
@@ -308,6 +310,7 @@ function readParallelWorkerWorldParameters (options) {
308
310
  * [worldParameters._ddEarlyFlakeDetectionRetryPolicy]
309
311
  */
310
312
  function readParallelWorkerAtrParameters (worldParameters) {
313
+ frameworkRetryCount = worldParameters._ddFrameworkRetryCount || 0
311
314
  isFlakyTestRetriesEnabled = !!worldParameters._ddIsFlakyTestRetriesEnabled
312
315
  hasAutomaticRetries = !!worldParameters._ddHasAutomaticRetries
313
316
  numTestRetries = worldParameters._ddNumTestRetries ?? 0
@@ -392,9 +395,10 @@ function handleParallelTestCaseFinished (pickle, worstTestStepResult, usesNumeri
392
395
  const finished = (pickleResultByFile[testFileAbsolutePath] ||= [])
393
396
 
394
397
  const isAttemptToFix = isTestManagementTestsEnabled &&
395
- getTestProperties(getTestSuitePath(testFileAbsolutePath, process.cwd()), pickle.name).attemptToFix
398
+ getTestProperties(getTestSuitePath(testFileAbsolutePath, process.cwd()), pickle.name, pickle).attemptToFix
396
399
 
397
- if (!isAttemptToFix && shouldRunEarlyFlakeDetection() && (isNew || modifiedTestsByPickleId.get(pickle.id))) {
400
+ if (!getScenarioAnnotations(pickle).noAutoRetry && !isAttemptToFix && shouldRunEarlyFlakeDetection() &&
401
+ (isNew || modifiedTestsByPickleId.get(pickle.id))) {
398
402
  let testStatuses = efdStatusesByPickleId.get(pickle.id)
399
403
  if (testStatuses) {
400
404
  testStatuses.push(status)
@@ -577,11 +581,28 @@ function isNewTest (testSuite, testName) {
577
581
  return !testsForSuite.includes(testName)
578
582
  }
579
583
 
580
- function getTestProperties (testSuite, testName) {
584
+ /** @param {{ tags?: Array<{ name: string }> }} pickle */
585
+ function getScenarioAnnotations (pickle) {
586
+ const tags = pickle.tags || []
587
+ // Preserve the colon spellings accepted by earlier tracer releases.
588
+ return {
589
+ mustFail: tags.some(tag => tag.name === '@datadog_prevent_failure_suppression' ||
590
+ tag.name === '@datadog:prevent_failure_suppression'),
591
+ noAutoRetry: tags.some(tag => tag.name === '@datadog_no_auto_retry' ||
592
+ tag.name === '@datadog:no_auto_retry'),
593
+ }
594
+ }
595
+
596
+ function getTestProperties (testSuite, testName, pickle) {
581
597
  const { attempt_to_fix: attemptToFix, disabled, quarantined } =
582
598
  testManagementTests?.cucumber?.suites?.[testSuite]?.tests?.[testName]?.properties || {}
583
599
 
584
- return { attemptToFix, disabled, quarantined }
600
+ const { mustFail, noAutoRetry } = getScenarioAnnotations(pickle)
601
+ return {
602
+ attemptToFix: attemptToFix && !noAutoRetry,
603
+ disabled: disabled && !mustFail,
604
+ quarantined: quarantined && !mustFail,
605
+ }
585
606
  }
586
607
 
587
608
  function getTestStatusFromRetries (testStatuses) {
@@ -745,9 +766,10 @@ function publishRetriedAttempt (runner, state) {
745
766
  const nextAttempt = currentAttempt + 1
746
767
  const failedAttemptCtx = numAttemptToCtx.get(currentAttempt)
747
768
  const isFirstAttempt = currentAttempt === 0
748
- const isAtrRetry = !isFirstAttempt && state.hasAutomaticRetries
769
+ const noAutoRetry = getScenarioAnnotations(runner.pickle).noAutoRetry
770
+ const isAtrRetry = !isFirstAttempt && state.hasAutomaticRetries && !noAutoRetry
749
771
 
750
- if (isFirstAttempt && isDynamicAtrEnabled && isFlakyTestRetriesEnabled) {
772
+ if (!noAutoRetry && isFirstAttempt && isDynamicAtrEnabled && isFlakyTestRetriesEnabled) {
751
773
  state.hasAutomaticRetries = true
752
774
  state.dynamicAtrRetryCount = getDynamicAtrRetryCount(
753
775
  performance.now() - state.executionStart,
@@ -760,7 +782,7 @@ function publishRetriedAttempt (runner, state) {
760
782
  }
761
783
 
762
784
  // ATR: record this attempt as failed so when run().finally runs (after retry) we have all statuses
763
- if (state.hasAutomaticRetries) {
785
+ if (state.hasAutomaticRetries && !noAutoRetry) {
764
786
  const nameForKey = getCucumberTestName(runner.pickle.name, currentAttempt > 0)
765
787
  const atrKey = `${runner.pickle.uri}:${nameForKey}`
766
788
  if (atrStatusesByScenarioKey.has(atrKey)) {
@@ -814,10 +836,11 @@ function wrapRun (pl, isLatestVersion, version) {
814
836
  return run.apply(this, args)
815
837
  }
816
838
 
817
- // Cucumber 8–10 workers construct runners directly, without the newer
839
+ // Cucumber 7–10 workers construct runners directly, without the newer
818
840
  // runTestCase wrapper that reads the coordinator's configuration.
819
- if (getEnvironmentVariable('CUCUMBER_WORKER_ID') && satisfies(version, '>=8.0.0 <11.0.0')) {
820
- readParallelWorkerAtrParameters(this.worldParameters)
841
+ if (getEnvironmentVariable('CUCUMBER_WORKER_ID') && satisfies(version, '>=7.0.0 <11.0.0')) {
842
+ frameworkRetryCount = this.worldParameters._ddFrameworkRetryCount || 0
843
+ if (satisfies(version, '>=8.0.0')) readParallelWorkerAtrParameters(this.worldParameters)
821
844
  }
822
845
 
823
846
  const testFileAbsolutePath = this.pickle.uri
@@ -825,7 +848,14 @@ function wrapRun (pl, isLatestVersion, version) {
825
848
 
826
849
  const testSourceLine = this.gherkinDocument?.feature?.location?.line
827
850
 
851
+ const testAnnotations = getScenarioAnnotations(this.pickle)
852
+ // Explicit native retries already include the pickle's retry-tag-filter decision.
853
+ if (testAnnotations.noAutoRetry && frameworkRetryCount === 0) this.maxAttempts = 1
828
854
  const testStartPayload = {
855
+ testAnnotations,
856
+ assignedProperties: isTestManagementTestsEnabled
857
+ ? testManagementTests?.cucumber?.suites?.[testSuitePath]?.tests?.[this.pickle.name]?.properties
858
+ : undefined,
829
859
  testName: this.pickle.name,
830
860
  testFileAbsolutePath,
831
861
  testSourceLine,
@@ -839,7 +869,7 @@ function wrapRun (pl, isLatestVersion, version) {
839
869
  const state = { numAttempt: 0, promises, testStartPayload, hasAutomaticRetries }
840
870
  numAttemptToCtx.set(state.numAttempt, ctx)
841
871
  runnerToRetryState.set(this, state)
842
- if (isTestManagementTestsEnabled && getTestProperties(testSuitePath, this.pickle.name).attemptToFix) {
872
+ if (isTestManagementTestsEnabled && getTestProperties(testSuitePath, this.pickle.name, this.pickle).attemptToFix) {
843
873
  logAttemptToFixTestExecution(testSuitePath, this.pickle.name, loggedAttemptToFixTests)
844
874
  }
845
875
  testStartCh.runStores(ctx, () => {})
@@ -894,7 +924,7 @@ function wrapRun (pl, isLatestVersion, version) {
894
924
 
895
925
  if (isTestManagementTestsEnabled) {
896
926
  const testSuitePath = getTestSuitePath(testFileAbsolutePath, process.cwd())
897
- const testProperties = getTestProperties(testSuitePath, testName)
927
+ const testProperties = getTestProperties(testSuitePath, testName, this.pickle)
898
928
  const numRetries = numRetriesByPickleId.get(this.pickle.id)
899
929
  isAttemptToFix = testProperties.attemptToFix
900
930
  isAttemptToFixRetry = isAttemptToFix && numRetries > 0
@@ -930,7 +960,7 @@ function wrapRun (pl, isLatestVersion, version) {
930
960
  }
931
961
 
932
962
  if (
933
- shouldRunEarlyFlakeDetection() &&
963
+ !testAnnotations.noAutoRetry && shouldRunEarlyFlakeDetection() &&
934
964
  !isAttemptToFix &&
935
965
  status !== 'skip' &&
936
966
  (isNew || isModified) &&
@@ -966,7 +996,8 @@ function wrapRun (pl, isLatestVersion, version) {
966
996
 
967
997
  // ATR: accumulate statuses by stable scenario key (uri:name) so retries are grouped.
968
998
  // Cucumber appends " (attempt N)" or " (attempt N, retried)" to the scenario name; normalize for keying.
969
- if (state.hasAutomaticRetries && !isAttemptToFix && !isEfdRetry && numTestRetries > 0) {
999
+ if (!testAnnotations.noAutoRetry && state.hasAutomaticRetries &&
1000
+ !isAttemptToFix && !isEfdRetry && numTestRetries > 0) {
970
1001
  const atrKey = `${this.pickle.uri}:${testName}`
971
1002
  if (atrStatusesByScenarioKey.has(atrKey)) {
972
1003
  atrStatusesByScenarioKey.get(atrKey).push(status)
@@ -1015,7 +1046,9 @@ function wrapRun (pl, isLatestVersion, version) {
1015
1046
 
1016
1047
  // Notice that ATR is handled using cucumber native retries features.
1017
1048
  // Therefore, if we reach this point, we are certain that it's the last ATR execution
1018
- const isLastAtrRetry = state.hasAutomaticRetries && !isAttemptToFix && !isEfdRetry &&
1049
+ const isLastAtrRetry = satisfies(version, '>=8.0.0') &&
1050
+ !testAnnotations.noAutoRetry && state.hasAutomaticRetries &&
1051
+ !isAttemptToFix && !isEfdRetry &&
1019
1052
  numTestRetries > 0 && this.maxAttempts > 1
1020
1053
 
1021
1054
  const statuses = lastStatusByPickleId.get(this.pickle.id)
@@ -1044,8 +1077,8 @@ function wrapRun (pl, isLatestVersion, version) {
1044
1077
  error,
1045
1078
  isNew,
1046
1079
  isEfdRetry,
1047
- isFlakyRetry: state.numAttempt > 0 && state.hasAutomaticRetries,
1048
- isExternalRetry: state.numAttempt > 0 && !state.hasAutomaticRetries,
1080
+ isFlakyRetry: state.numAttempt > 0 && state.hasAutomaticRetries && !testAnnotations.noAutoRetry,
1081
+ isExternalRetry: state.numAttempt > 0 && (!state.hasAutomaticRetries || testAnnotations.noAutoRetry),
1049
1082
  isAttemptToFix,
1050
1083
  isAttemptToFixRetry,
1051
1084
  hasFailedAllRetries,
@@ -1267,6 +1300,7 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
1267
1300
  const command = getEnvironmentVariable('npm_lifecycle_script') || `cucumber-js ${processArgv}`
1268
1301
 
1269
1302
  const originalRetryCount = options.retry
1303
+ frameworkRetryCount = options.retry || 0
1270
1304
  hasAutomaticRetries = isFlakyTestRetriesEnabled && !options.retry && numTestRetries > 0
1271
1305
  if (hasAutomaticRetries) {
1272
1306
  options.retry = numTestRetries
@@ -1423,9 +1457,10 @@ function getWrappedRunTestCase (runTestCaseFunction, isNewerCucumberVersion = fa
1423
1457
  let isQuarantined = false
1424
1458
  let isModified = false
1425
1459
 
1460
+ const testAnnotations = getScenarioAnnotations(pickle)
1426
1461
  const originalDryRun = this.options.dryRun
1427
1462
  if (isTestManagementTestsEnabled) {
1428
- const testProperties = getTestProperties(testSuitePath, pickle.name)
1463
+ const testProperties = getTestProperties(testSuitePath, pickle.name, pickle)
1429
1464
  isAttemptToFix = testProperties.attemptToFix
1430
1465
  isDisabled = testProperties.disabled
1431
1466
  isQuarantined = testProperties.quarantined
@@ -1497,8 +1532,10 @@ function getWrappedRunTestCase (runTestCaseFunction, isNewerCucumberVersion = fa
1497
1532
  }
1498
1533
  }
1499
1534
  const originalRetry = this.options.retry
1500
- const isEfdTest = !isAttemptToFix && shouldRunEarlyFlakeDetection() && (isNew || isModified)
1535
+ const isEfdTest = !testAnnotations.noAutoRetry && !isAttemptToFix &&
1536
+ shouldRunEarlyFlakeDetection() && (isNew || isModified)
1501
1537
  const isManagedRetry = isAttemptToFix || isEfdTest
1538
+ if (testAnnotations.noAutoRetry) this.options.retry = frameworkRetryCount
1502
1539
  if (isManagedRetry) {
1503
1540
  this.options.retry = 0
1504
1541
  }
@@ -15,6 +15,7 @@ const {
15
15
  const { channel } = require('./helpers/instrument')
16
16
 
17
17
  const DD_CONFIG_WRAPPED = Symbol.for('dd-trace.cypress.config.wrapped')
18
+ const DD_SUPPORT_OWNER = Symbol.for('dd-trace.cypress.support-owner')
18
19
  const DD_CYPRESS_AFTER_SPEC_HANDLER = Symbol.for('dd-trace.cypress.after-spec.handler')
19
20
  const DD_CYPRESS_AFTER_RUN_HANDLER = Symbol.for('dd-trace.cypress.after-run.handler')
20
21
  const DD_CYPRESS_TASK_HANDLER = Symbol.for('dd-trace.cypress.task.handler')
@@ -25,6 +26,7 @@ const CONFIG_INSTRUMENTATION_NOT_INSTALLED =
25
26
  'Cypress configurations that cannot be intercepted through cypress.defineConfig were not auto-instrumented.'
26
27
  const generatedFilesForExitCleanup = new Set()
27
28
  let exitCleanupRegistered = false
29
+ let stopManualSupportSetup
28
30
 
29
31
  const setupNodeEventsCh = channel('ci:cypress:setup-node-events')
30
32
 
@@ -39,6 +41,7 @@ if (loadCh.hasSubscribers) {
39
41
 
40
42
  const noopTask = {
41
43
  'dd:testSuiteStart': () => null,
44
+ 'dd:testDeclarations': () => null,
42
45
  'dd:beforeEach': () => ({}),
43
46
  'dd:afterEach': () => null,
44
47
  'dd:addTags': () => null,
@@ -250,13 +253,20 @@ function mergeReturnedConfig (config, updatedConfig) {
250
253
  }
251
254
 
252
255
  const mergedConfig = { ...config }
253
-
254
- for (const [key, value] of Object.entries(updatedConfig)) {
255
- mergedConfig[key] = isPlainObject(value) && isPlainObject(mergedConfig[key])
256
- ? mergeReturnedConfig(mergedConfig[key], value)
257
- : value
256
+ // Retain the values already read for the reply, rather than invoking user getters again at IPC.
257
+ const returnedConfig = Object.fromEntries(Object.entries(updatedConfig))
258
+
259
+ for (const [key, value] of Object.entries(returnedConfig)) {
260
+ if (isPlainObject(value) && isPlainObject(mergedConfig[key]) && value !== mergedConfig[key]) {
261
+ mergedConfig[key] = mergeReturnedConfig(mergedConfig[key], value)
262
+ // Keep only the returned overrides, using values already read by the recursive merge.
263
+ returnedConfig[key] = mergedConfig[key][Symbol.for('dd-trace.cypress.returned-config')]
264
+ } else {
265
+ mergedConfig[key] = value
266
+ }
258
267
  }
259
268
 
269
+ Object.defineProperty(mergedConfig, Symbol.for('dd-trace.cypress.returned-config'), { value: returnedConfig })
260
270
  return mergedConfig
261
271
  }
262
272
 
@@ -289,9 +299,13 @@ function getRelativeImportPath (fromDirectory, importedFile) {
289
299
  * @param {string} directory writable directory inside the Cypress project
290
300
  * @param {string|false|undefined} originalSupportFile user's support file
291
301
  * @param {string} browserHooksSource Datadog browser-side support hooks
302
+ * @param {boolean} deferLifecycle whether manual support owns lifecycle registration
303
+ * @param {string} lifecycleOwnerSource browser lifecycle ownership detection
292
304
  * @returns {string[]} generated files
293
305
  */
294
- function createSupportWrapper (directory, originalSupportFile, browserHooksSource) {
306
+ function createSupportWrapper (
307
+ directory, originalSupportFile, browserHooksSource, deferLifecycle, lifecycleOwnerSource
308
+ ) {
295
309
  const suffix = `${process.pid}-${randomUUID()}`
296
310
  const browserHooksFile = path.join(directory, `dd-cypress-support-hooks-${suffix}.mjs`)
297
311
  const wrapperFile = path.join(directory, `dd-cypress-support-${suffix}.mjs`)
@@ -305,9 +319,47 @@ function createSupportWrapper (directory, originalSupportFile, browserHooksSourc
305
319
 
306
320
  const generatedFiles = []
307
321
  try {
308
- writeExclusiveFile(browserHooksFile, browserHooksSource)
322
+ const guardedSource = `const ddSupportRoot = Cypress.mocha.getRootSuite()
323
+ const ddSupportKey = Symbol.for('dd-trace.cypress.support-installed')
324
+ const ddHasLifecycle = (() => {
325
+ const module = { exports: {} }
326
+ ${lifecycleOwnerSource}
327
+ return module.exports
328
+ })()
329
+ ddSupportRoot[Symbol.for('dd-trace.cypress.has-lifecycle')] = ddHasLifecycle
330
+ if (!ddSupportRoot[ddSupportKey] && !ddHasLifecycle(ddSupportRoot)) {
331
+ const positions = {}
332
+ for (const key of ['_beforeAll', '_beforeEach', '_afterAll', '_afterEach']) {
333
+ positions[key] = Array.isArray(ddSupportRoot[key]) ? ddSupportRoot[key].length : 0
334
+ }
335
+ ddSupportRoot[Symbol.for('dd-trace.cypress.lifecycle-positions')] = positions
336
+ ddSupportRoot[Symbol.for('dd-trace.cypress.defer-lifecycle')] = ${deferLifecycle}
337
+ ${browserHooksSource}
338
+ ddSupportRoot[ddSupportKey] = true
339
+ }
340
+ `
341
+ writeExclusiveFile(browserHooksFile, guardedSource)
309
342
  generatedFiles.push(browserHooksFile)
310
- writeExclusiveFile(wrapperFile, `${wrapperImports.join('\n')}\n`)
343
+ const finalize = `const root = Cypress.mocha.getRootSuite()
344
+ const install = root[Symbol.for('dd-trace.cypress.install-lifecycle')]
345
+ const hasLifecycle = root[Symbol.for('dd-trace.cypress.has-lifecycle')]
346
+ if (typeof install === 'function' && (!hasLifecycle || !hasLifecycle(root))) {
347
+ const phases = ['_beforeAll', '_beforeEach', '_afterAll', '_afterEach']
348
+ const lengths = {}
349
+ for (const key of phases) lengths[key] = Array.isArray(root[key]) ? root[key].length : 0
350
+ install()
351
+ // A Node-only manual plugin needs automatic browser hooks before user hooks.
352
+ // Move only the hooks just installed; an actual manual owner never enters here.
353
+ const positions = root[Symbol.for('dd-trace.cypress.lifecycle-positions')]
354
+ for (const key of phases) {
355
+ if (positions && Array.isArray(root[key])) {
356
+ const added = root[key].splice(lengths[key])
357
+ root[key].splice(positions[key], 0, ...added)
358
+ }
359
+ }
360
+ }
361
+ `
362
+ writeExclusiveFile(wrapperFile, `${wrapperImports.join('\n')}\n${finalize}`)
311
363
  generatedFiles.push(wrapperFile)
312
364
  } catch (error) {
313
365
  for (const generatedFile of generatedFiles) removeGeneratedFile(generatedFile)
@@ -323,21 +375,26 @@ function createSupportWrapper (directory, originalSupportFile, browserHooksSourc
323
375
  * generated paths for cleanup, or undefined if injection was skipped.
324
376
  *
325
377
  * @param {object} config Cypress resolved config object
378
+ * @param {boolean} [manualLifecycle] whether the manual entry point owns lifecycle registration
326
379
  * @returns {string[]|undefined} generated file paths, or undefined if skipped
327
380
  */
328
- function injectSupportFile (config) {
381
+ function injectSupportFile (config, manualLifecycle = false) {
329
382
  const originalSupportFile = config.supportFile
330
383
 
384
+ const supportOwner = config[DD_SUPPORT_OWNER]
385
+ if (generatedFilesForExitCleanup.has(originalSupportFile) &&
386
+ (!manualLifecycle || (supportOwner?.path === originalSupportFile && supportOwner.deferLifecycle))) return
387
+ let deferLifecycle = manualLifecycle ||
388
+ (supportOwner && supportOwner.path === originalSupportFile && supportOwner.deferLifecycle)
389
+
331
390
  if (originalSupportFile) {
332
391
  try {
333
392
  const content = fs.readFileSync(originalSupportFile, 'utf8')
334
- // Naive check: skip lines starting with // or * to avoid matching commented-out imports.
335
- const hasActiveDdTraceImport = content.split('\n').some(line => {
393
+ deferLifecycle ||= content.split('\n').some(line => {
336
394
  const trimmed = line.trim()
337
395
  return trimmed.includes('dd-trace/ci/cypress/support') &&
338
396
  !trimmed.startsWith('//') && !trimmed.startsWith('*')
339
397
  })
340
- if (hasActiveDdTraceImport) return
341
398
  } catch (error) {
342
399
  logBrowserInstrumentationError(
343
400
  'Datadog could not read the Cypress support file %s: %s. %s',
@@ -351,9 +408,11 @@ function injectSupportFile (config) {
351
408
 
352
409
  let browserHooksSource
353
410
  let browserHooksPath
411
+ let lifecycleOwnerSource
354
412
  try {
355
413
  browserHooksPath = require.resolve('../../datadog-plugin-cypress/src/support')
356
414
  browserHooksSource = fs.readFileSync(browserHooksPath, 'utf8')
415
+ lifecycleOwnerSource = fs.readFileSync(require.resolve('../../datadog-plugin-cypress/src/lifecycle-owner'), 'utf8')
357
416
  } catch (error) {
358
417
  logBrowserInstrumentationError(
359
418
  'Datadog could not read its Cypress browser support hooks: %s. %s',
@@ -372,8 +431,12 @@ function injectSupportFile (config) {
372
431
  for (const directory of new Set(candidateDirectories)) {
373
432
  if (projectRoot && !isPathInside(projectRoot, directory)) continue
374
433
  try {
375
- const generatedFiles = createSupportWrapper(directory, originalSupportFile, browserHooksSource)
434
+ const generatedFiles = createSupportWrapper(
435
+ directory, originalSupportFile, browserHooksSource, !!deferLifecycle, lifecycleOwnerSource
436
+ )
376
437
  config.supportFile = generatedFiles[1]
438
+ // Shared across SDK copies, but scoped to this exact generated support path.
439
+ config[DD_SUPPORT_OWNER] = { path: config.supportFile, deferLifecycle: !!deferLifecycle }
377
440
  return generatedFiles
378
441
  } catch (error) {
379
442
  failures.push({ directory, error })
@@ -396,6 +459,90 @@ function injectSupportFile (config) {
396
459
  }
397
460
  }
398
461
 
462
+ /**
463
+ * Installs browser hooks before user support, including manual SDK imports.
464
+ *
465
+ * @param {object} config Cypress resolved config object
466
+ * @param {boolean} [manualLifecycle] whether the manual entry point owns lifecycle registration
467
+ * @returns {string[]|undefined} generated files owned until cleanup or process exit
468
+ */
469
+ function installSupportFile (config, manualLifecycle = false) {
470
+ const files = injectSupportFile(config, manualLifecycle)
471
+ if (files) registerGeneratedFilesForExitCleanup(files)
472
+ return files
473
+ }
474
+
475
+ /**
476
+ * Keeps early browser instrumentation in the actual manual setup return value.
477
+ *
478
+ * @param {object} config Cypress resolved config object
479
+ * @returns {(() => void)|undefined} cleanup for the one-shot setup observer
480
+ */
481
+ function installManualSupportFile (config) {
482
+ stopManualSupportSetup?.()
483
+ installSupportFile(config, true)
484
+ const originalSend = process.send
485
+ if (typeof originalSend !== 'function') return
486
+
487
+ let active = true
488
+ const stop = () => {
489
+ active = false
490
+ if (process.send === send) process.send = originalSend
491
+ if (stopManualSupportSetup === stop) stopManualSupportSetup = undefined
492
+ }
493
+ const send = function (message) {
494
+ let forwarded = message
495
+ if (active && (message?.event === 'setupTestingType:reply' || message?.event === 'setupTestingType:error')) {
496
+ try {
497
+ const reply = message.event === 'setupTestingType:reply' && message.args?.[0]
498
+ const supplied = reply?.setupConfig
499
+ if (reply && (supplied == null || (supplied && typeof supplied === 'object' && !Array.isArray(supplied)))) {
500
+ // Snapshot own enumerable values once, as native IPC serialization would.
501
+ const returnedConfig = Object.fromEntries(Object.entries(supplied ?? {}))
502
+ const supportOwner = supplied && Object.getOwnPropertyDescriptor(supplied, DD_SUPPORT_OWNER)
503
+ if (supportOwner && 'value' in supportOwner) {
504
+ Object.defineProperty(returnedConfig, DD_SUPPORT_OWNER, supportOwner)
505
+ }
506
+ const projectRoot = returnedConfig.projectRoot ?? config.projectRoot
507
+ const supportFile = returnedConfig.supportFile === undefined ? config.supportFile : returnedConfig.supportFile
508
+ // Leave invalid user configuration for Cypress's native validator.
509
+ if (typeof projectRoot === 'string' &&
510
+ (supportFile === undefined || supportFile === false || typeof supportFile === 'string')) {
511
+ const supportConfig = {
512
+ projectRoot,
513
+ supportFile: typeof supportFile === 'string' ? path.resolve(projectRoot, supportFile) : supportFile,
514
+ [DD_SUPPORT_OWNER]: returnedConfig[DD_SUPPORT_OWNER] ?? config[DD_SUPPORT_OWNER],
515
+ }
516
+ installSupportFile(supportConfig, true)
517
+ if (generatedFilesForExitCleanup.has(supportConfig.supportFile)) {
518
+ const args = [...message.args]
519
+ args[0] = {
520
+ ...reply,
521
+ setupConfig: {
522
+ ...returnedConfig,
523
+ supportFile: supportConfig.supportFile,
524
+ [DD_SUPPORT_OWNER]: supportConfig[DD_SUPPORT_OWNER],
525
+ },
526
+ }
527
+ forwarded = { ...message, args }
528
+ }
529
+ }
530
+ }
531
+ } catch (error) {
532
+ log.warn('Datadog could not retain the Cypress support wrapper in the setup reply: %s.', error)
533
+ } finally {
534
+ stop()
535
+ }
536
+ }
537
+ const args = [...arguments]
538
+ args[0] = forwarded
539
+ return originalSend.apply(this, args)
540
+ }
541
+ stopManualSupportSetup = stop
542
+ process.send = send
543
+ return stop
544
+ }
545
+
399
546
  /**
400
547
  * Registers screenshot handlers collected from a manual plugin call. User
401
548
  * handlers run first so a renamed screenshot path reaches the Datadog handler.
@@ -515,8 +662,7 @@ function registerDdTraceHooks (
515
662
  userAfterScreenshotHandlers,
516
663
  manualPlugin
517
664
  ) {
518
- const generatedSupportFiles = injectSupportFile(config)
519
- if (generatedSupportFiles) registerGeneratedFilesForExitCleanup(generatedSupportFiles)
665
+ const generatedSupportFiles = installSupportFile(config, manualPlugin.detected)
520
666
 
521
667
  const cleanupWrapper = () => {
522
668
  // Open mode reuses this support file across runs, including failed setup attempts.
@@ -930,6 +1076,8 @@ function wrapCliConfigFileOptions (options) {
930
1076
  }
931
1077
 
932
1078
  module.exports = {
1079
+ installManualSupportFile,
1080
+ installSupportFile,
933
1081
  wrapCliConfigFileOptions,
934
1082
  wrapConfig,
935
1083
  }
@@ -0,0 +1,114 @@
1
+ 'use strict'
2
+
3
+ // Silence is inferred only between recent provider observations. Unknown samples stay active.
4
+ class SpeechActivity {
5
+ #silence = []
6
+ /** @type {number | undefined} */
7
+ #lastOffset = undefined
8
+ /** @type {number | undefined} */
9
+ #lastReceived = undefined
10
+ #speaking = true
11
+ #overflow = false
12
+
13
+ /**
14
+ * @param {number} start
15
+ * @param {number} end
16
+ */
17
+ addSilence (start, end) {
18
+ start = Math.max(0, start)
19
+ if (end <= start || this.#overflow) return
20
+ const last = this.#silence.at(-1)
21
+ if (last && start <= last[1]) last[1] = Math.max(end, last[1])
22
+ else if (this.#silence.length < 128) this.#silence.push([start, end])
23
+ else {
24
+ this.#silence = []
25
+ this.#overflow = true
26
+ }
27
+ }
28
+
29
+ /**
30
+ * @param {unknown} score
31
+ * @param {number} offset
32
+ * @param {number} now
33
+ */
34
+ observe (score, offset, now) {
35
+ if (typeof score !== 'number' || !Number.isFinite(score) || score < 0 || score > 1) return
36
+ if (this.#lastOffset !== undefined && this.#lastReceived !== undefined) {
37
+ if (offset < this.#lastOffset || now < this.#lastReceived) return
38
+ if (!this.#speaking && now - this.#lastReceived <= 500) {
39
+ this.addSilence(this.#lastOffset, Math.min(offset, this.#lastOffset + 500))
40
+ }
41
+ if (offset - this.#lastOffset > 500 || now - this.#lastReceived > 500) this.#speaking = true
42
+ }
43
+ this.#lastOffset = offset
44
+ this.#lastReceived = now
45
+ if (score >= 0.5) this.#speaking = true
46
+ else if (score <= 0.35) this.#speaking = false
47
+ }
48
+
49
+ /** @param {number} duration */
50
+ continueAt (duration) {
51
+ const next = new SpeechActivity()
52
+ if (this.#lastOffset !== undefined && this.#lastReceived !== undefined) {
53
+ next.#lastOffset = this.#lastOffset - duration
54
+ next.#lastReceived = this.#lastReceived
55
+ next.#speaking = this.#speaking
56
+ }
57
+ return next
58
+ }
59
+
60
+ /**
61
+ * @param {number} duration
62
+ * @param {number | undefined} lastAudio
63
+ */
64
+ extendSilence (duration, lastAudio) {
65
+ if (!this.#speaking && this.#lastOffset !== undefined && this.#lastReceived !== undefined &&
66
+ lastAudio !== undefined &&
67
+ lastAudio - this.#lastReceived <= 500) {
68
+ this.addSilence(this.#lastOffset, Math.min(duration, this.#lastOffset + 500))
69
+ }
70
+ }
71
+
72
+ /**
73
+ * @param {SpeechActivity} other
74
+ * @param {number} duration
75
+ * @param {number | undefined} lastAudio
76
+ */
77
+ extend (other, duration, lastAudio) {
78
+ this.extendSilence(duration, lastAudio)
79
+ for (const [start, end] of other.#silence) this.addSilence(start + duration, end + duration)
80
+ if (other.#lastOffset !== undefined) {
81
+ this.#lastOffset = other.#lastOffset + duration
82
+ this.#lastReceived = other.#lastReceived
83
+ this.#speaking = other.#speaking
84
+ }
85
+ this.#overflow ||= other.#overflow
86
+ }
87
+
88
+ /**
89
+ * @param {number} duration
90
+ * @param {number | undefined} lastAudio
91
+ */
92
+ metadata (duration, lastAudio) {
93
+ if (this.#lastOffset === undefined || this.#overflow || duration <= 0) return
94
+ this.extendSilence(duration, lastAudio)
95
+ const intervals = []
96
+ let cursor = 0
97
+ for (const [from, to] of this.#silence) {
98
+ const start = Math.min(duration, from)
99
+ if (start > cursor) intervals.push([Math.floor(cursor), Math.ceil(start)])
100
+ cursor = Math.max(cursor, Math.min(duration, to))
101
+ }
102
+ if (cursor < duration) intervals.push([Math.floor(cursor), Math.ceil(duration)])
103
+ const merged = []
104
+ for (const [start, end] of intervals) {
105
+ const last = merged.at(-1)
106
+ if (last && start <= last[1]) last[1] = Math.max(end, last[1])
107
+ else merged.push([start, end])
108
+ }
109
+ if (merged.length > 128) return
110
+ return { version: 1, source: 'elevenlabs_vad', timing: 'estimated', intervals_ms: merged }
111
+ }
112
+ }
113
+
114
+ module.exports = SpeechActivity