@depup/dd-trace 5.97.0-depup.0 → 6.5.0-depup.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 (712) hide show
  1. package/LICENSE-3rdparty.csv +89 -104
  2. package/README.electron.md +7 -0
  3. package/README.md +2 -2
  4. package/changes.json +1 -1
  5. package/ci/diagnose.js +2100 -0
  6. package/ci/init.js +46 -5
  7. package/ci/runbook.md +198 -0
  8. package/ci/test-optimization-validation/approval-artifacts.js +143 -0
  9. package/ci/test-optimization-validation/approval.js +299 -0
  10. package/ci/test-optimization-validation/artifact-id.js +20 -0
  11. package/ci/test-optimization-validation/bounded-json.js +121 -0
  12. package/ci/test-optimization-validation/ci-command-candidate.js +83 -0
  13. package/ci/test-optimization-validation/ci-discovery.js +181 -0
  14. package/ci/test-optimization-validation/ci-remediation.js +210 -0
  15. package/ci/test-optimization-validation/cli.js +903 -0
  16. package/ci/test-optimization-validation/command-blocker.js +81 -0
  17. package/ci/test-optimization-validation/command-output-policy.js +206 -0
  18. package/ci/test-optimization-validation/command-runner.js +707 -0
  19. package/ci/test-optimization-validation/command-suitability.js +471 -0
  20. package/ci/test-optimization-validation/executable-approval.js +48 -0
  21. package/ci/test-optimization-validation/executable.js +480 -0
  22. package/ci/test-optimization-validation/generated-file-policy.js +63 -0
  23. package/ci/test-optimization-validation/generated-files.js +351 -0
  24. package/ci/test-optimization-validation/generated-verifier.js +196 -0
  25. package/ci/test-optimization-validation/init-probe-preload.js +163 -0
  26. package/ci/test-optimization-validation/init-probe.js +246 -0
  27. package/ci/test-optimization-validation/late-initialization.js +63 -0
  28. package/ci/test-optimization-validation/local-command.js +163 -0
  29. package/ci/test-optimization-validation/manifest-loader.js +133 -0
  30. package/ci/test-optimization-validation/manifest-scaffold.js +738 -0
  31. package/ci/test-optimization-validation/manifest-schema.js +862 -0
  32. package/ci/test-optimization-validation/offline-fixtures.js +327 -0
  33. package/ci/test-optimization-validation/offline-output.js +406 -0
  34. package/ci/test-optimization-validation/payload-normalizer.js +72 -0
  35. package/ci/test-optimization-validation/plan-writer.js +1120 -0
  36. package/ci/test-optimization-validation/preflight-runner.js +114 -0
  37. package/ci/test-optimization-validation/redaction.js +331 -0
  38. package/ci/test-optimization-validation/report-writer.js +1508 -0
  39. package/ci/test-optimization-validation/safe-files.js +203 -0
  40. package/ci/test-optimization-validation/scenarios/auto-test-retries.js +159 -0
  41. package/ci/test-optimization-validation/scenarios/basic-reporting.js +657 -0
  42. package/ci/test-optimization-validation/scenarios/ci-wiring.js +780 -0
  43. package/ci/test-optimization-validation/scenarios/early-flake-detection.js +141 -0
  44. package/ci/test-optimization-validation/scenarios/helpers.js +539 -0
  45. package/ci/test-optimization-validation/scenarios/test-management.js +218 -0
  46. package/ci/test-optimization-validation/setup-runner.js +97 -0
  47. package/ci/test-optimization-validation/static-diagnosis.js +159 -0
  48. package/ci/test-optimization-validation/test-output.js +129 -0
  49. package/ci/test-optimization-validation-manifest.schema.json +1 -0
  50. package/ci/validate-test-optimization.js +3 -0
  51. package/ci/vitest-no-worker-init-setup.mjs +430 -0
  52. package/ext/exporters.js +2 -0
  53. package/ext/tags.js +3 -0
  54. package/index.d.ts +436 -252
  55. package/index.electron.js +3 -0
  56. package/init.js +18 -0
  57. package/initialize.mjs +10 -9
  58. package/loader-hook.mjs +170 -53
  59. package/openfeature.d.ts +1 -0
  60. package/openfeature.js +4 -0
  61. package/package.json +118 -80
  62. package/packages/datadog-core/src/storage.js +47 -48
  63. package/packages/datadog-esbuild/index.js +32 -1
  64. package/packages/datadog-esbuild/src/utils.js +46 -3
  65. package/packages/datadog-instrumentations/src/aerospike.js +3 -3
  66. package/packages/datadog-instrumentations/src/ai.js +137 -76
  67. package/packages/datadog-instrumentations/src/amqplib.js +6 -7
  68. package/packages/datadog-instrumentations/src/anthropic.js +10 -10
  69. package/packages/datadog-instrumentations/src/apollo-server-core.js +3 -3
  70. package/packages/datadog-instrumentations/src/apollo-server.js +10 -18
  71. package/packages/datadog-instrumentations/src/avsc.js +6 -6
  72. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js-context-methods.js +18 -0
  73. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js.js +111 -0
  74. package/packages/datadog-instrumentations/src/aws-sdk.js +172 -72
  75. package/packages/datadog-instrumentations/src/azure-cosmos.js +7 -0
  76. package/packages/datadog-instrumentations/src/azure-durable-functions.js +8 -8
  77. package/packages/datadog-instrumentations/src/azure-functions.js +3 -0
  78. package/packages/datadog-instrumentations/src/bluebird.js +2 -2
  79. package/packages/datadog-instrumentations/src/body-parser.js +5 -2
  80. package/packages/datadog-instrumentations/src/cassandra-driver.js +12 -9
  81. package/packages/datadog-instrumentations/src/child_process.js +16 -16
  82. package/packages/datadog-instrumentations/src/claude-agent-sdk.js +587 -0
  83. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +41 -24
  84. package/packages/datadog-instrumentations/src/connect.js +14 -12
  85. package/packages/datadog-instrumentations/src/cookie-parser.js +5 -4
  86. package/packages/datadog-instrumentations/src/cookie.js +9 -3
  87. package/packages/datadog-instrumentations/src/couchbase.js +73 -238
  88. package/packages/datadog-instrumentations/src/crypto.js +49 -4
  89. package/packages/datadog-instrumentations/src/cucumber-worker-threads.js +25 -0
  90. package/packages/datadog-instrumentations/src/cucumber.js +762 -189
  91. package/packages/datadog-instrumentations/src/cypress-config.js +547 -93
  92. package/packages/datadog-instrumentations/src/cypress.js +5 -3
  93. package/packages/datadog-instrumentations/src/dns.js +60 -59
  94. package/packages/datadog-instrumentations/src/elasticsearch.js +9 -12
  95. package/packages/datadog-instrumentations/src/electron/preload.js +42 -0
  96. package/packages/datadog-instrumentations/src/electron.js +240 -0
  97. package/packages/datadog-instrumentations/src/express-mongo-sanitize.js +11 -9
  98. package/packages/datadog-instrumentations/src/express-session.js +14 -13
  99. package/packages/datadog-instrumentations/src/express.js +52 -30
  100. package/packages/datadog-instrumentations/src/fastify.js +166 -87
  101. package/packages/datadog-instrumentations/src/fetch.js +5 -5
  102. package/packages/datadog-instrumentations/src/fs.js +22 -20
  103. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +5 -7
  104. package/packages/datadog-instrumentations/src/google-genai.js +4 -4
  105. package/packages/datadog-instrumentations/src/graphql.js +26 -362
  106. package/packages/datadog-instrumentations/src/grpc/client.js +48 -32
  107. package/packages/datadog-instrumentations/src/grpc/server.js +20 -2
  108. package/packages/datadog-instrumentations/src/hapi.js +2 -2
  109. package/packages/datadog-instrumentations/src/helpers/callback-instrumentor.js +74 -0
  110. package/packages/datadog-instrumentations/src/helpers/check-require-cache.js +85 -9
  111. package/packages/datadog-instrumentations/src/helpers/hook.js +31 -7
  112. package/packages/datadog-instrumentations/src/helpers/hooks.js +12 -0
  113. package/packages/datadog-instrumentations/src/helpers/instrument.js +36 -3
  114. package/packages/datadog-instrumentations/src/helpers/kafka.js +58 -0
  115. package/packages/datadog-instrumentations/src/helpers/optional-peer-bundler.js +65 -0
  116. package/packages/datadog-instrumentations/src/helpers/promise-instrumentor.js +42 -0
  117. package/packages/datadog-instrumentations/src/helpers/promise.js +2 -2
  118. package/packages/datadog-instrumentations/src/helpers/register.js +7 -5
  119. package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +13 -5
  120. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +24 -7
  121. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +6 -6
  122. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/aws-durable-execution-sdk-js.js +31 -0
  123. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/azure-cosmos.js +50 -0
  124. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/claude-agent-sdk.js +17 -0
  125. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +201 -0
  126. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +7 -0
  127. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/langgraph.js +4 -2
  128. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/mercurius.js +31 -0
  129. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-sdk.js +35 -0
  130. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +111 -0
  131. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +18 -2
  132. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +49 -224
  133. package/packages/datadog-instrumentations/src/helpers/router-helper.js +8 -8
  134. package/packages/datadog-instrumentations/src/hono.js +71 -9
  135. package/packages/datadog-instrumentations/src/http/client.js +48 -24
  136. package/packages/datadog-instrumentations/src/http/server.js +75 -29
  137. package/packages/datadog-instrumentations/src/http2/client.js +15 -12
  138. package/packages/datadog-instrumentations/src/http2/server.js +156 -23
  139. package/packages/datadog-instrumentations/src/ioredis.js +17 -14
  140. package/packages/datadog-instrumentations/src/iovalkey.js +1 -2
  141. package/packages/datadog-instrumentations/src/jest/bail-reporter.js +42 -0
  142. package/packages/datadog-instrumentations/src/jest/coverage-backfill.js +163 -0
  143. package/packages/datadog-instrumentations/src/jest.js +1809 -401
  144. package/packages/datadog-instrumentations/src/kafkajs.js +284 -170
  145. package/packages/datadog-instrumentations/src/knex.js +17 -17
  146. package/packages/datadog-instrumentations/src/koa.js +15 -14
  147. package/packages/datadog-instrumentations/src/ldapjs.js +5 -5
  148. package/packages/datadog-instrumentations/src/light-my-request.js +2 -2
  149. package/packages/datadog-instrumentations/src/limitd-client.js +4 -4
  150. package/packages/datadog-instrumentations/src/lodash.js +4 -4
  151. package/packages/datadog-instrumentations/src/mariadb.js +18 -16
  152. package/packages/datadog-instrumentations/src/memcached.js +4 -3
  153. package/packages/datadog-instrumentations/src/mercurius.js +11 -0
  154. package/packages/datadog-instrumentations/src/microgateway-core.js +2 -2
  155. package/packages/datadog-instrumentations/src/mocha/common.js +7 -4
  156. package/packages/datadog-instrumentations/src/mocha/main.js +557 -120
  157. package/packages/datadog-instrumentations/src/mocha/utils.js +531 -135
  158. package/packages/datadog-instrumentations/src/mocha/worker.js +27 -9
  159. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +254 -0
  160. package/packages/datadog-instrumentations/src/mongodb-core.js +43 -31
  161. package/packages/datadog-instrumentations/src/mongodb.js +82 -8
  162. package/packages/datadog-instrumentations/src/mongoose.js +46 -37
  163. package/packages/datadog-instrumentations/src/mquery.js +7 -7
  164. package/packages/datadog-instrumentations/src/multer.js +5 -4
  165. package/packages/datadog-instrumentations/src/mysql.js +17 -17
  166. package/packages/datadog-instrumentations/src/mysql2.js +39 -5
  167. package/packages/datadog-instrumentations/src/nats.js +182 -0
  168. package/packages/datadog-instrumentations/src/net.js +19 -11
  169. package/packages/datadog-instrumentations/src/next.js +68 -10
  170. package/packages/datadog-instrumentations/src/nyc.js +43 -8
  171. package/packages/datadog-instrumentations/src/openai.js +124 -38
  172. package/packages/datadog-instrumentations/src/oracledb.js +12 -7
  173. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +27 -6
  174. package/packages/datadog-instrumentations/src/passport-utils.js +5 -5
  175. package/packages/datadog-instrumentations/src/path-to-regexp.js +44 -0
  176. package/packages/datadog-instrumentations/src/pg.js +58 -25
  177. package/packages/datadog-instrumentations/src/pino.js +25 -41
  178. package/packages/datadog-instrumentations/src/playwright-browser-scripts.js +27 -0
  179. package/packages/datadog-instrumentations/src/playwright.js +1229 -356
  180. package/packages/datadog-instrumentations/src/process.js +3 -0
  181. package/packages/datadog-instrumentations/src/protobufjs.js +16 -16
  182. package/packages/datadog-instrumentations/src/redis.js +28 -15
  183. package/packages/datadog-instrumentations/src/restify.js +6 -5
  184. package/packages/datadog-instrumentations/src/router.js +253 -87
  185. package/packages/datadog-instrumentations/src/selenium.js +53 -28
  186. package/packages/datadog-instrumentations/src/stripe.js +47 -33
  187. package/packages/datadog-instrumentations/src/tedious.js +28 -0
  188. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1297 -0
  189. package/packages/datadog-instrumentations/src/vitest-main.js +1590 -0
  190. package/packages/datadog-instrumentations/src/vitest-util.js +251 -0
  191. package/packages/datadog-instrumentations/src/vitest-worker.js +822 -0
  192. package/packages/datadog-instrumentations/src/vitest.js +11 -1262
  193. package/packages/datadog-instrumentations/src/winston.js +4 -4
  194. package/packages/datadog-instrumentations/src/ws.js +9 -8
  195. package/packages/datadog-instrumentations/src/zlib.js +29 -0
  196. package/packages/datadog-plugin-ai/src/index.js +1 -1
  197. package/packages/datadog-plugin-ai/src/tracing.js +66 -3
  198. package/packages/datadog-plugin-ai/src/utils.js +17 -4
  199. package/packages/datadog-plugin-apollo/src/gateway/request.js +1 -21
  200. package/packages/datadog-plugin-avsc/src/schema_iterator.js +3 -3
  201. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/checkpoint.js +31 -0
  202. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/client.js +55 -0
  203. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/context.js +123 -0
  204. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/handler.js +129 -0
  205. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/index.js +19 -0
  206. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/trace-checkpoint.js +224 -0
  207. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +80 -0
  208. package/packages/datadog-plugin-aws-sdk/src/base.js +86 -50
  209. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +1 -1
  210. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +218 -4
  211. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +1 -1
  212. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +2 -1
  213. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +59 -14
  214. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +174 -75
  215. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +34 -23
  216. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +2 -1
  217. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +1 -1
  218. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +26 -26
  219. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +187 -101
  220. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +20 -18
  221. package/packages/datadog-plugin-aws-sdk/src/util.js +2 -2
  222. package/packages/datadog-plugin-azure-cosmos/src/index.js +144 -0
  223. package/packages/datadog-plugin-azure-event-hubs/src/producer.js +8 -15
  224. package/packages/datadog-plugin-azure-functions/src/index.js +7 -3
  225. package/packages/datadog-plugin-azure-service-bus/src/producer.js +5 -10
  226. package/packages/datadog-plugin-bullmq/src/consumer.js +5 -4
  227. package/packages/datadog-plugin-bullmq/src/filter.js +35 -0
  228. package/packages/datadog-plugin-bullmq/src/producer.js +121 -33
  229. package/packages/datadog-plugin-bunyan/src/index.js +28 -0
  230. package/packages/datadog-plugin-child_process/src/index.js +13 -2
  231. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +6 -6
  232. package/packages/datadog-plugin-claude-agent-sdk/src/index.js +31 -0
  233. package/packages/datadog-plugin-claude-agent-sdk/src/tracing.js +107 -0
  234. package/packages/datadog-plugin-claude-agent-sdk/src/util.js +15 -0
  235. package/packages/datadog-plugin-couchbase/src/index.js +58 -52
  236. package/packages/datadog-plugin-cucumber/src/index.js +47 -29
  237. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +929 -98
  238. package/packages/datadog-plugin-cypress/src/index.js +109 -2
  239. package/packages/datadog-plugin-cypress/src/plugin.js +6 -14
  240. package/packages/datadog-plugin-cypress/src/source-map-utils.js +48 -1
  241. package/packages/datadog-plugin-cypress/src/support.js +272 -51
  242. package/packages/datadog-plugin-dd-trace-api/src/index.js +1 -1
  243. package/packages/datadog-plugin-dns/src/lookup.js +8 -6
  244. package/packages/datadog-plugin-elasticsearch/src/index.js +28 -8
  245. package/packages/datadog-plugin-electron/src/index.js +17 -0
  246. package/packages/datadog-plugin-electron/src/ipc.js +143 -0
  247. package/packages/datadog-plugin-electron/src/net.js +82 -0
  248. package/packages/datadog-plugin-express/src/code_origin.js +1 -1
  249. package/packages/datadog-plugin-fastify/src/code_origin.js +1 -1
  250. package/packages/datadog-plugin-fs/src/index.js +2 -1
  251. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -5
  252. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +27 -18
  253. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +5 -8
  254. package/packages/datadog-plugin-graphql/src/execute.js +748 -34
  255. package/packages/datadog-plugin-graphql/src/index.js +43 -9
  256. package/packages/datadog-plugin-graphql/src/parse.js +45 -4
  257. package/packages/datadog-plugin-graphql/src/request.js +135 -0
  258. package/packages/datadog-plugin-graphql/src/tools/signature.js +32 -7
  259. package/packages/datadog-plugin-graphql/src/tools/transforms.js +118 -100
  260. package/packages/datadog-plugin-graphql/src/utils.js +261 -3
  261. package/packages/datadog-plugin-graphql/src/validate.js +54 -8
  262. package/packages/datadog-plugin-grpc/src/client.js +7 -8
  263. package/packages/datadog-plugin-grpc/src/server.js +1 -1
  264. package/packages/datadog-plugin-grpc/src/util.js +57 -22
  265. package/packages/datadog-plugin-http/src/client.js +12 -14
  266. package/packages/datadog-plugin-http/src/index.js +6 -8
  267. package/packages/datadog-plugin-http/src/server.js +63 -20
  268. package/packages/datadog-plugin-http2/src/client.js +7 -4
  269. package/packages/datadog-plugin-http2/src/server.js +48 -8
  270. package/packages/datadog-plugin-jest/src/index.js +133 -67
  271. package/packages/datadog-plugin-jest/src/util.js +37 -16
  272. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +1 -1
  273. package/packages/datadog-plugin-kafkajs/src/consumer.js +2 -9
  274. package/packages/datadog-plugin-kafkajs/src/producer.js +37 -8
  275. package/packages/datadog-plugin-langchain/src/handlers/embedding.js +2 -1
  276. package/packages/datadog-plugin-langchain/src/handlers/language_models.js +2 -1
  277. package/packages/datadog-plugin-langchain/src/tokens.js +2 -2
  278. package/packages/datadog-plugin-langgraph/src/stream.js +1 -1
  279. package/packages/datadog-plugin-memcached/src/index.js +1 -1
  280. package/packages/datadog-plugin-mocha/src/index.js +66 -20
  281. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/index.js +24 -0
  282. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +173 -0
  283. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +30 -0
  284. package/packages/datadog-plugin-mongodb-core/src/bulk-write.js +43 -0
  285. package/packages/datadog-plugin-mongodb-core/src/index.js +8 -206
  286. package/packages/datadog-plugin-mongodb-core/src/query.js +452 -0
  287. package/packages/datadog-plugin-mysql/src/index.js +9 -4
  288. package/packages/datadog-plugin-nats/src/consumer.js +43 -0
  289. package/packages/datadog-plugin-nats/src/index.js +20 -0
  290. package/packages/datadog-plugin-nats/src/producer.js +62 -0
  291. package/packages/datadog-plugin-nats/src/util.js +33 -0
  292. package/packages/datadog-plugin-next/src/index.js +12 -4
  293. package/packages/datadog-plugin-openai/src/services.js +4 -3
  294. package/packages/datadog-plugin-openai/src/tracing.js +27 -25
  295. package/packages/datadog-plugin-oracledb/src/index.js +13 -2
  296. package/packages/datadog-plugin-pg/src/index.js +13 -3
  297. package/packages/datadog-plugin-pino/src/index.js +42 -0
  298. package/packages/datadog-plugin-playwright/src/index.js +195 -72
  299. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +3 -3
  300. package/packages/datadog-plugin-redis/src/index.js +54 -25
  301. package/packages/datadog-plugin-rhea/src/producer.js +1 -1
  302. package/packages/datadog-plugin-router/src/index.js +55 -44
  303. package/packages/datadog-plugin-selenium/src/index.js +5 -36
  304. package/packages/datadog-plugin-tedious/src/index.js +1 -1
  305. package/packages/datadog-plugin-undici/src/index.js +24 -2
  306. package/packages/datadog-plugin-vitest/src/index.js +160 -90
  307. package/packages/datadog-plugin-winston/src/index.js +30 -0
  308. package/packages/datadog-plugin-ws/src/close.js +5 -2
  309. package/packages/datadog-plugin-ws/src/producer.js +4 -1
  310. package/packages/datadog-plugin-ws/src/receiver.js +4 -2
  311. package/packages/datadog-plugin-ws/src/server.js +2 -1
  312. package/packages/datadog-shimmer/src/shimmer.js +101 -39
  313. package/packages/datadog-webpack/index.js +17 -1
  314. package/packages/datadog-webpack/src/optional-peer-loader.js +17 -0
  315. package/packages/dd-trace/index.electron.js +3 -0
  316. package/packages/dd-trace/index.js +2 -36
  317. package/packages/dd-trace/src/aiguard/channels.js +7 -0
  318. package/packages/dd-trace/src/aiguard/index.js +16 -34
  319. package/packages/dd-trace/src/aiguard/integrations/evaluate.js +46 -0
  320. package/packages/dd-trace/src/aiguard/integrations/index.js +34 -0
  321. package/packages/dd-trace/src/aiguard/integrations/openai.js +80 -0
  322. package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +92 -0
  323. package/packages/dd-trace/src/aiguard/messages/openai.js +382 -0
  324. package/packages/{datadog-instrumentations/src/helpers/ai-messages.js → dd-trace/src/aiguard/messages/vercel-ai.js} +30 -27
  325. package/packages/dd-trace/src/aiguard/sdk.js +148 -55
  326. package/packages/dd-trace/src/aiguard/tags.js +26 -10
  327. package/packages/dd-trace/src/appsec/api_security/index.js +55 -0
  328. package/packages/dd-trace/src/appsec/api_security/sampler.js +147 -0
  329. package/packages/dd-trace/src/appsec/blocked_templates.js +4 -3
  330. package/packages/dd-trace/src/appsec/blocking.js +82 -42
  331. package/packages/dd-trace/src/appsec/channels.js +5 -1
  332. package/packages/dd-trace/src/appsec/downstream_requests.js +116 -62
  333. package/packages/dd-trace/src/appsec/graphql.js +20 -17
  334. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +1 -1
  335. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +81 -81
  336. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +23 -23
  337. package/packages/dd-trace/src/appsec/iast/index.js +3 -2
  338. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +4 -4
  339. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +2 -2
  340. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +2 -2
  341. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +4 -4
  342. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -2
  343. package/packages/dd-trace/src/appsec/iast/telemetry/index.js +2 -1
  344. package/packages/dd-trace/src/appsec/iast/telemetry/span-tags.js +3 -1
  345. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +54 -12
  346. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +5 -1
  347. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +31 -4
  348. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +1 -3
  349. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +83 -48
  350. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +1 -1
  351. package/packages/dd-trace/src/appsec/index.js +65 -47
  352. package/packages/dd-trace/src/appsec/lambda.js +135 -0
  353. package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -5
  354. package/packages/dd-trace/src/appsec/rasp/lfi.js +8 -4
  355. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +5 -10
  356. package/packages/dd-trace/src/appsec/rasp/ssrf.js +26 -18
  357. package/packages/dd-trace/src/appsec/recommended.json +2438 -13
  358. package/packages/dd-trace/src/appsec/reporter.js +87 -28
  359. package/packages/dd-trace/src/appsec/rule_manager.js +4 -2
  360. package/packages/dd-trace/src/appsec/sdk/set_user.js +1 -1
  361. package/packages/dd-trace/src/appsec/sdk/track_event.js +5 -5
  362. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +7 -11
  363. package/packages/dd-trace/src/appsec/sdk/utils.js +5 -3
  364. package/packages/dd-trace/src/appsec/store.js +50 -0
  365. package/packages/dd-trace/src/appsec/telemetry/api_security.js +34 -0
  366. package/packages/dd-trace/src/appsec/telemetry/index.js +27 -1
  367. package/packages/dd-trace/src/appsec/user_tracking.js +5 -4
  368. package/packages/dd-trace/src/appsec/waf/index.js +19 -9
  369. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +35 -20
  370. package/packages/dd-trace/src/appsec/waf/waf_manager.js +1 -1
  371. package/packages/dd-trace/src/azure_metadata.js +19 -7
  372. package/packages/dd-trace/src/baggage.js +32 -13
  373. package/packages/dd-trace/src/bootstrap.js +39 -0
  374. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +123 -33
  375. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +122 -24
  376. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +22 -7
  377. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +5 -2
  378. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +2 -2
  379. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +2 -2
  380. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +6 -2
  381. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -2
  382. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +160 -0
  383. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +288 -0
  384. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +84 -0
  385. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +369 -0
  386. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +60 -0
  387. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +188 -27
  388. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +3 -4
  389. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +28 -10
  390. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +22 -0
  391. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +110 -22
  392. package/packages/dd-trace/src/ci-visibility/lage.js +2 -1
  393. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +4 -5
  394. package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +4 -5
  395. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +73 -55
  396. package/packages/dd-trace/src/ci-visibility/requests/request.js +14 -50
  397. package/packages/dd-trace/src/ci-visibility/requests/upload-coverage-report.js +10 -6
  398. package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +156 -0
  399. package/packages/dd-trace/src/ci-visibility/rum.js +7 -0
  400. package/packages/dd-trace/src/ci-visibility/test-api-manual/test-api-manual-plugin.js +9 -3
  401. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +24 -6
  402. package/packages/dd-trace/src/ci-visibility/test-optimization-cache.js +70 -6
  403. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +256 -0
  404. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +451 -0
  405. package/packages/dd-trace/src/ci-visibility/test-screenshot.js +90 -0
  406. package/packages/dd-trace/src/config/config-types.d.ts +8 -6
  407. package/packages/dd-trace/src/config/defaults.js +71 -44
  408. package/packages/dd-trace/src/config/generated-config-types.d.ts +692 -131
  409. package/packages/dd-trace/src/config/git_properties.js +2 -2
  410. package/packages/dd-trace/src/config/helper.js +140 -33
  411. package/packages/dd-trace/src/config/index.js +127 -131
  412. package/packages/dd-trace/src/config/major-overrides.js +100 -0
  413. package/packages/dd-trace/src/config/normalize-service.js +31 -0
  414. package/packages/dd-trace/src/config/parsers.js +138 -10
  415. package/packages/dd-trace/src/config/remote_config.js +1 -1
  416. package/packages/dd-trace/src/config/supported-configurations.json +460 -203
  417. package/packages/dd-trace/src/constants.js +15 -0
  418. package/packages/dd-trace/src/crashtracking/crashtracker.js +18 -6
  419. package/packages/dd-trace/src/datastreams/checkpointer.js +6 -12
  420. package/packages/dd-trace/src/datastreams/context.js +4 -2
  421. package/packages/dd-trace/src/datastreams/encoding.js +39 -28
  422. package/packages/dd-trace/src/datastreams/index.js +2 -1
  423. package/packages/dd-trace/src/datastreams/manager.js +1 -1
  424. package/packages/dd-trace/src/datastreams/pathway.js +35 -30
  425. package/packages/dd-trace/src/datastreams/processor.js +31 -22
  426. package/packages/dd-trace/src/datastreams/size.js +6 -2
  427. package/packages/dd-trace/src/datastreams/writer.js +15 -6
  428. package/packages/dd-trace/src/debugger/config.js +9 -4
  429. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +49 -35
  430. package/packages/dd-trace/src/debugger/devtools_client/condition.js +5 -8
  431. package/packages/dd-trace/src/debugger/devtools_client/config.js +3 -2
  432. package/packages/dd-trace/src/debugger/devtools_client/index.js +33 -71
  433. package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +83 -0
  434. package/packages/dd-trace/src/debugger/devtools_client/send.js +27 -6
  435. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +2 -2
  436. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +5 -2
  437. package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +1 -0
  438. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +1 -1
  439. package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
  440. package/packages/dd-trace/src/debugger/index.js +13 -9
  441. package/packages/dd-trace/src/debugger/probe_sampler.js +112 -0
  442. package/packages/dd-trace/src/debugger/probe_sampler_constants.js +19 -0
  443. package/packages/dd-trace/src/dogstatsd.js +34 -28
  444. package/packages/dd-trace/src/encode/0.4.js +829 -268
  445. package/packages/dd-trace/src/encode/0.5.js +158 -22
  446. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +141 -65
  447. package/packages/dd-trace/src/encode/agentless-json.js +12 -6
  448. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +52 -15
  449. package/packages/dd-trace/src/encode/span-stats.js +19 -16
  450. package/packages/dd-trace/src/encode/tags-processors.js +30 -25
  451. package/packages/dd-trace/src/exporter.js +5 -1
  452. package/packages/dd-trace/src/exporters/agent/index.js +4 -5
  453. package/packages/dd-trace/src/exporters/agent/writer.js +1 -2
  454. package/packages/dd-trace/src/exporters/agentless/index.js +12 -13
  455. package/packages/dd-trace/src/exporters/agentless/intake.js +43 -0
  456. package/packages/dd-trace/src/exporters/agentless/writer.js +12 -11
  457. package/packages/dd-trace/src/exporters/common/agents.js +3 -1
  458. package/packages/dd-trace/src/exporters/common/buffering-exporter.js +3 -3
  459. package/packages/dd-trace/src/exporters/common/client-library-headers.js +21 -0
  460. package/packages/dd-trace/src/exporters/common/request.js +93 -44
  461. package/packages/dd-trace/src/exporters/common/retry.js +104 -0
  462. package/packages/dd-trace/src/exporters/common/url.js +48 -0
  463. package/packages/dd-trace/src/exporters/common/util.js +2 -2
  464. package/packages/dd-trace/src/exporters/common/writer.js +17 -1
  465. package/packages/dd-trace/src/exporters/electron/index.js +49 -0
  466. package/packages/dd-trace/src/exporters/span-stats/index.js +1 -2
  467. package/packages/dd-trace/src/exporters/span-stats/writer.js +1 -3
  468. package/packages/dd-trace/src/external-logger/src/index.js +2 -1
  469. package/packages/dd-trace/src/feature-registry.js +29 -0
  470. package/packages/dd-trace/src/git_metadata.js +68 -0
  471. package/packages/dd-trace/src/git_metadata_tagger.js +13 -5
  472. package/packages/dd-trace/src/guardrails/index.js +11 -6
  473. package/packages/dd-trace/src/guardrails/telemetry.js +40 -3
  474. package/packages/dd-trace/src/heap_snapshots.js +4 -4
  475. package/packages/dd-trace/src/id.js +46 -27
  476. package/packages/dd-trace/src/index.js +7 -8
  477. package/packages/dd-trace/src/lambda/handler-paths.js +52 -0
  478. package/packages/dd-trace/src/lambda/handler.js +2 -6
  479. package/packages/dd-trace/src/lambda/index.js +62 -14
  480. package/packages/dd-trace/src/lambda/runtime/patch.js +21 -46
  481. package/packages/dd-trace/src/llmobs/constants/tags.js +13 -0
  482. package/packages/dd-trace/src/llmobs/experiments/client.js +113 -0
  483. package/packages/dd-trace/src/llmobs/experiments/dataset.js +154 -0
  484. package/packages/dd-trace/src/llmobs/experiments/experiment.js +283 -0
  485. package/packages/dd-trace/src/llmobs/experiments/index.js +152 -0
  486. package/packages/dd-trace/src/llmobs/experiments/noop.js +30 -0
  487. package/packages/dd-trace/src/llmobs/experiments/result.js +34 -0
  488. package/packages/dd-trace/src/llmobs/index.js +37 -7
  489. package/packages/dd-trace/src/llmobs/noop.js +6 -0
  490. package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +403 -0
  491. package/packages/dd-trace/src/llmobs/plugins/ai/index.js +8 -395
  492. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +119 -7
  493. package/packages/dd-trace/src/llmobs/plugins/ai/vercelTelemetry.js +380 -0
  494. package/packages/dd-trace/src/llmobs/plugins/{anthropic.js → anthropic/index.js} +32 -79
  495. package/packages/dd-trace/src/llmobs/plugins/anthropic/util.js +109 -0
  496. package/packages/dd-trace/src/llmobs/plugins/base.js +4 -4
  497. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +89 -37
  498. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +270 -0
  499. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +10 -0
  500. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +5 -1
  501. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +81 -16
  502. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +3 -2
  503. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +3 -2
  504. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/embedding.js +2 -1
  505. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +1 -50
  506. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/vectorstore.js +2 -1
  507. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +14 -8
  508. package/packages/dd-trace/src/llmobs/plugins/langchain/messages.js +76 -0
  509. package/packages/dd-trace/src/llmobs/plugins/langgraph/index.js +4 -29
  510. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +68 -0
  511. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +57 -0
  512. package/packages/dd-trace/src/llmobs/plugins/openai/constants.js +8 -0
  513. package/packages/dd-trace/src/llmobs/plugins/openai/index.js +68 -64
  514. package/packages/dd-trace/src/llmobs/plugins/openai/utils.js +43 -0
  515. package/packages/dd-trace/src/llmobs/sdk.js +73 -35
  516. package/packages/dd-trace/src/llmobs/span_processor.js +90 -11
  517. package/packages/dd-trace/src/llmobs/tagger.js +197 -4
  518. package/packages/dd-trace/src/llmobs/telemetry.js +33 -2
  519. package/packages/dd-trace/src/llmobs/util.js +234 -9
  520. package/packages/dd-trace/src/llmobs/writers/base.js +11 -5
  521. package/packages/dd-trace/src/llmobs/writers/spans.js +1 -1
  522. package/packages/dd-trace/src/llmobs/writers/util.js +1 -2
  523. package/packages/dd-trace/src/log/index.js +19 -31
  524. package/packages/dd-trace/src/log/writer.js +3 -1
  525. package/packages/dd-trace/src/msgpack/chunk.js +430 -11
  526. package/packages/dd-trace/src/msgpack/index.js +101 -2
  527. package/packages/dd-trace/src/noop/proxy.js +5 -4
  528. package/packages/dd-trace/src/noop/span.js +3 -1
  529. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +322 -0
  530. package/packages/dd-trace/src/openfeature/configuration_source.js +90 -0
  531. package/packages/dd-trace/src/openfeature/encoding.js +70 -0
  532. package/packages/dd-trace/src/openfeature/eval-metrics-hook.js +103 -0
  533. package/packages/dd-trace/src/openfeature/flagging_provider.js +32 -16
  534. package/packages/dd-trace/src/openfeature/index.js +0 -2
  535. package/packages/dd-trace/src/openfeature/noop.js +41 -64
  536. package/packages/dd-trace/src/openfeature/register.js +35 -0
  537. package/packages/dd-trace/src/openfeature/remote_config.js +16 -14
  538. package/packages/dd-trace/src/openfeature/require-provider.js +18 -0
  539. package/packages/dd-trace/src/openfeature/span-enrichment-hook.js +143 -0
  540. package/packages/dd-trace/src/openfeature/span-enrichment.js +149 -0
  541. package/packages/dd-trace/src/openfeature/writers/base.js +3 -11
  542. package/packages/dd-trace/src/openfeature/writers/exposures.js +82 -70
  543. package/packages/dd-trace/src/openfeature/writers/util.js +1 -2
  544. package/packages/dd-trace/src/opentelemetry/active-span-proxy.js +42 -0
  545. package/packages/dd-trace/src/opentelemetry/bridge-span-base.js +107 -0
  546. package/packages/dd-trace/src/opentelemetry/context_manager.js +27 -13
  547. package/packages/dd-trace/src/opentelemetry/logs/index.js +6 -6
  548. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +3 -2
  549. package/packages/dd-trace/src/opentelemetry/metrics/index.js +61 -12
  550. package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +28 -14
  551. package/packages/dd-trace/src/opentelemetry/metrics/meter.js +7 -10
  552. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +3 -2
  553. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +40 -0
  554. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js +169 -0
  555. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +99 -5
  556. package/packages/dd-trace/src/opentelemetry/metrics/time.js +19 -0
  557. package/packages/dd-trace/src/opentelemetry/otlp/common.proto +2 -2
  558. package/packages/dd-trace/src/opentelemetry/otlp/logs.proto +1 -1
  559. package/packages/dd-trace/src/opentelemetry/otlp/logs_service.proto +1 -1
  560. package/packages/dd-trace/src/opentelemetry/otlp/metrics.proto +1 -1
  561. package/packages/dd-trace/src/opentelemetry/otlp/metrics_service.proto +1 -1
  562. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +56 -82
  563. package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +1 -2
  564. package/packages/dd-trace/src/opentelemetry/otlp/protobuf_loader.js +14 -2
  565. package/packages/dd-trace/src/opentelemetry/otlp/trace.proto +358 -0
  566. package/packages/dd-trace/src/opentelemetry/otlp/trace_service.proto +78 -0
  567. package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +10 -0
  568. package/packages/dd-trace/src/opentelemetry/span-helpers.js +325 -0
  569. package/packages/dd-trace/src/opentelemetry/span.js +64 -109
  570. package/packages/dd-trace/src/opentelemetry/span_context.js +1 -0
  571. package/packages/dd-trace/src/opentelemetry/span_processor.js +7 -5
  572. package/packages/dd-trace/src/opentelemetry/trace/index.js +75 -0
  573. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +75 -0
  574. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +375 -0
  575. package/packages/dd-trace/src/opentelemetry/tracer.js +20 -69
  576. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +33 -17
  577. package/packages/dd-trace/src/opentracing/propagation/log.js +28 -8
  578. package/packages/dd-trace/src/opentracing/propagation/text_map.js +278 -148
  579. package/packages/dd-trace/src/opentracing/propagation/text_map_dsm.js +11 -11
  580. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +98 -32
  581. package/packages/dd-trace/src/opentracing/span.js +127 -73
  582. package/packages/dd-trace/src/opentracing/span_context.js +68 -3
  583. package/packages/dd-trace/src/opentracing/tracer.js +46 -19
  584. package/packages/dd-trace/src/payload-tagging/config/index.js +2 -2
  585. package/packages/dd-trace/src/plugin_manager.js +36 -14
  586. package/packages/dd-trace/src/plugins/apollo.js +3 -1
  587. package/packages/dd-trace/src/plugins/ci_plugin.js +407 -91
  588. package/packages/dd-trace/src/plugins/database.js +61 -18
  589. package/packages/dd-trace/src/plugins/index.js +14 -0
  590. package/packages/dd-trace/src/plugins/log_injection.js +56 -0
  591. package/packages/dd-trace/src/plugins/log_plugin.js +4 -44
  592. package/packages/dd-trace/src/plugins/outbound.js +1 -1
  593. package/packages/dd-trace/src/plugins/plugin.js +19 -28
  594. package/packages/dd-trace/src/plugins/storage.js +2 -2
  595. package/packages/dd-trace/src/plugins/tracing.js +70 -13
  596. package/packages/dd-trace/src/plugins/util/ci.js +127 -40
  597. package/packages/dd-trace/src/plugins/util/git-cache.js +23 -23
  598. package/packages/dd-trace/src/plugins/util/git.js +6 -3
  599. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +276 -0
  600. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +29 -5
  601. package/packages/dd-trace/src/plugins/util/llm.js +6 -1
  602. package/packages/dd-trace/src/plugins/util/stacktrace.js +2 -2
  603. package/packages/dd-trace/src/plugins/util/test.js +950 -69
  604. package/packages/dd-trace/src/plugins/util/url.js +71 -5
  605. package/packages/dd-trace/src/plugins/util/user-provided-git.js +18 -16
  606. package/packages/dd-trace/src/plugins/util/web.js +116 -180
  607. package/packages/dd-trace/src/priority_sampler.js +12 -21
  608. package/packages/dd-trace/src/profiling/config.js +132 -212
  609. package/packages/dd-trace/src/profiling/constants.js +4 -7
  610. package/packages/dd-trace/src/profiling/exporter_cli.js +10 -10
  611. package/packages/dd-trace/src/profiling/exporters/agent.js +61 -28
  612. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +45 -14
  613. package/packages/dd-trace/src/profiling/exporters/file.js +16 -5
  614. package/packages/dd-trace/src/profiling/oom.js +71 -0
  615. package/packages/dd-trace/src/profiling/profiler.js +84 -105
  616. package/packages/dd-trace/src/profiling/profilers/event_plugins/crypto.js +32 -0
  617. package/packages/dd-trace/src/profiling/profilers/event_plugins/zlib.js +19 -0
  618. package/packages/dd-trace/src/profiling/profilers/events.js +57 -13
  619. package/packages/dd-trace/src/profiling/profilers/space.js +27 -16
  620. package/packages/dd-trace/src/profiling/profilers/wall.js +49 -35
  621. package/packages/dd-trace/src/profiling/ssi-heuristics.js +3 -3
  622. package/packages/dd-trace/src/propagation-hash/index.js +1 -1
  623. package/packages/dd-trace/src/proxy.js +128 -37
  624. package/packages/dd-trace/src/rate_limiter.js +1 -1
  625. package/packages/dd-trace/src/remote_config/index.js +6 -5
  626. package/packages/dd-trace/src/remote_config/scheduler.js +1 -1
  627. package/packages/dd-trace/src/ritm.js +6 -3
  628. package/packages/dd-trace/src/runtime_metrics/client.js +30 -0
  629. package/packages/dd-trace/src/runtime_metrics/index.js +14 -4
  630. package/packages/dd-trace/src/runtime_metrics/otlp_runtime_metrics.js +284 -0
  631. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +42 -41
  632. package/packages/dd-trace/src/sampling_rule.js +7 -7
  633. package/packages/dd-trace/src/scope.js +10 -15
  634. package/packages/dd-trace/src/serverless.js +6 -7
  635. package/packages/dd-trace/src/service-naming/extra-services.js +14 -0
  636. package/packages/dd-trace/src/service-naming/index.js +1 -1
  637. package/packages/dd-trace/src/service-naming/schemas/definition.js +4 -1
  638. package/packages/dd-trace/src/service-naming/schemas/util.js +48 -3
  639. package/packages/dd-trace/src/service-naming/schemas/v0/graphql.js +6 -0
  640. package/packages/dd-trace/src/service-naming/schemas/v0/messaging.js +61 -2
  641. package/packages/dd-trace/src/service-naming/schemas/v0/serverless.js +12 -0
  642. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +60 -0
  643. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +25 -1
  644. package/packages/dd-trace/src/service-naming/schemas/v0/websocket.js +5 -0
  645. package/packages/dd-trace/src/service-naming/schemas/v1/graphql.js +8 -0
  646. package/packages/dd-trace/src/service-naming/schemas/v1/messaging.js +32 -0
  647. package/packages/dd-trace/src/service-naming/schemas/v1/serverless.js +12 -0
  648. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +17 -0
  649. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +23 -3
  650. package/packages/dd-trace/src/service-naming/schemas/v1/websocket.js +6 -0
  651. package/packages/dd-trace/src/service-naming/source-resolver.js +50 -0
  652. package/packages/dd-trace/src/span_format.js +269 -81
  653. package/packages/dd-trace/src/span_processor.js +18 -13
  654. package/packages/dd-trace/src/span_stats.js +101 -79
  655. package/packages/dd-trace/src/spanleak.js +1 -2
  656. package/packages/dd-trace/src/standalone/index.js +0 -36
  657. package/packages/dd-trace/src/startup-log.js +3 -3
  658. package/packages/dd-trace/src/tagger.js +2 -4
  659. package/packages/dd-trace/src/telemetry/dependencies.js +2 -2
  660. package/packages/dd-trace/src/telemetry/endpoints.js +7 -5
  661. package/packages/dd-trace/src/telemetry/index.js +2 -2
  662. package/packages/dd-trace/src/telemetry/logs/index.js +1 -1
  663. package/packages/dd-trace/src/telemetry/send-data.js +22 -22
  664. package/packages/dd-trace/src/telemetry/session-propagation.js +1 -1
  665. package/packages/dd-trace/src/telemetry/telemetry.js +16 -14
  666. package/packages/dd-trace/src/tracer.js +23 -9
  667. package/packages/dd-trace/src/tracer_metadata.js +1 -1
  668. package/packages/dd-trace/src/util.js +57 -0
  669. package/register.js +58 -1
  670. package/vendor/dist/@apm-js-collab/code-transformer/index.js +94 -42
  671. package/vendor/dist/@datadog/sketches-js/LICENSE +10 -36
  672. package/vendor/dist/@datadog/sketches-js/index.js +1 -1
  673. package/vendor/dist/pprof-format/index.js +1 -1
  674. package/vendor/dist/protobufjs/index.js +1 -1
  675. package/vendor/dist/protobufjs/minimal/index.js +1 -1
  676. package/vendor/dist/shell-quote/index.js +1 -1
  677. package/packages/datadog-plugin-graphql/src/resolve.js +0 -178
  678. package/packages/dd-trace/src/agent/url.js +0 -28
  679. package/packages/dd-trace/src/appsec/api_security_sampler.js +0 -117
  680. package/packages/dd-trace/src/lambda/runtime/ritm.js +0 -133
  681. package/packages/dd-trace/src/log/utils.js +0 -16
  682. package/packages/dd-trace/src/msgpack/encoder.js +0 -308
  683. package/packages/dd-trace/src/plugins/structured_log_plugin.js +0 -9
  684. package/scripts/preinstall.js +0 -34
  685. package/vendor/dist/ignore/LICENSE +0 -21
  686. package/vendor/dist/ignore/index.js +0 -1
  687. package/vendor/dist/opentracing/LICENSE +0 -201
  688. package/vendor/dist/opentracing/binary_carrier.d.ts +0 -11
  689. package/vendor/dist/opentracing/constants.d.ts +0 -61
  690. package/vendor/dist/opentracing/examples/demo/demo.d.ts +0 -2
  691. package/vendor/dist/opentracing/ext/tags.d.ts +0 -90
  692. package/vendor/dist/opentracing/functions.d.ts +0 -20
  693. package/vendor/dist/opentracing/global_tracer.d.ts +0 -14
  694. package/vendor/dist/opentracing/index.d.ts +0 -12
  695. package/vendor/dist/opentracing/index.js +0 -1
  696. package/vendor/dist/opentracing/mock_tracer/index.d.ts +0 -5
  697. package/vendor/dist/opentracing/mock_tracer/mock_context.d.ts +0 -13
  698. package/vendor/dist/opentracing/mock_tracer/mock_report.d.ts +0 -16
  699. package/vendor/dist/opentracing/mock_tracer/mock_span.d.ts +0 -50
  700. package/vendor/dist/opentracing/mock_tracer/mock_tracer.d.ts +0 -26
  701. package/vendor/dist/opentracing/noop.d.ts +0 -8
  702. package/vendor/dist/opentracing/reference.d.ts +0 -33
  703. package/vendor/dist/opentracing/span.d.ts +0 -147
  704. package/vendor/dist/opentracing/span_context.d.ts +0 -26
  705. package/vendor/dist/opentracing/test/api_compatibility.d.ts +0 -16
  706. package/vendor/dist/opentracing/test/mocktracer_implemenation.d.ts +0 -3
  707. package/vendor/dist/opentracing/test/noop_implementation.d.ts +0 -4
  708. package/vendor/dist/opentracing/test/opentracing_api.d.ts +0 -3
  709. package/vendor/dist/opentracing/test/unittest.d.ts +0 -2
  710. package/vendor/dist/opentracing/tracer.d.ts +0 -127
  711. package/vendor/dist/path-to-regexp/LICENSE +0 -21
  712. package/vendor/dist/path-to-regexp/index.js +0 -1
@@ -2,7 +2,9 @@
2
2
 
3
3
  // Capture real timers at module load time, before any test can install fake timers.
4
4
  const realSetTimeout = setTimeout
5
+ const realClearTimeout = clearTimeout
5
6
 
7
+ const { performance } = require('node:perf_hooks')
6
8
  const satisfies = require('../../../vendor/dist/semifies')
7
9
 
8
10
  const shimmer = require('../../datadog-shimmer')
@@ -12,20 +14,29 @@ const {
12
14
  PLAYWRIGHT_WORKER_TRACE_PAYLOAD_CODE,
13
15
  getIsFaultyEarlyFlakeDetection,
14
16
  DYNAMIC_NAME_RE,
15
- logDynamicNamesWarning,
17
+ getEfdRetryCount,
18
+ getMaxEfdRetryCount,
19
+ recordAttemptToFixExecution,
20
+ logAttemptToFixTestExecution,
21
+ logTestOptimizationSummary,
22
+ getTestOptimizationRequestResults,
16
23
  } = require('../../dd-trace/src/plugins/util/test')
17
24
  const log = require('../../dd-trace/src/log')
18
25
  const {
19
26
  getValueFromEnvSources,
20
27
  } = require('../../dd-trace/src/config/helper')
28
+ const {
29
+ RUM_TEST_EXECUTION_ID_COOKIE_NAME: RUM_COOKIE_NAME,
30
+ } = require('../../dd-trace/src/ci-visibility/rum')
21
31
  const { DD_MAJOR } = require('../../../version')
22
- const { addHook, channel } = require('./helpers/instrument')
32
+ const { addHook, channel, tracingChannel } = require('./helpers/instrument')
23
33
 
24
34
  const testStartCh = channel('ci:playwright:test:start')
25
35
  const testFinishCh = channel('ci:playwright:test:finish')
26
36
  const testSkipCh = channel('ci:playwright:test:skip')
27
37
 
28
38
  const testSessionStartCh = channel('ci:playwright:session:start')
39
+ const testSessionConfigurationCh = channel('ci:playwright:session:configuration')
29
40
  const testSessionFinishCh = channel('ci:playwright:session:finish')
30
41
 
31
42
  const libraryConfigurationCh = channel('ci:playwright:library-configuration')
@@ -40,18 +51,33 @@ const testSuiteFinishCh = channel('ci:playwright:test-suite:finish')
40
51
  const workerReportCh = channel('ci:playwright:worker:report')
41
52
  const testPageGotoCh = channel('ci:playwright:test:page-goto')
42
53
 
54
+ const dispatcherRunCh = tracingChannel('orchestrion:playwright:Dispatcher_run')
55
+ const dispatcherCreateWorkerCh = tracingChannel('orchestrion:playwright:Dispatcher_createWorker')
56
+ const processHostStartRunnerCh = tracingChannel('orchestrion:playwright:ProcessHost_startRunner')
57
+ const createRootSuiteCh = tracingChannel('orchestrion:playwright:createRootSuite')
58
+ const artifactsRecorderScreenshotPathCh =
59
+ tracingChannel('orchestrion:playwright:ArtifactsRecorder_createScreenshotAttachmentPath')
60
+ const snapshotRecorderScreenshotPathCh = tracingChannel('orchestrion:playwright:SnapshotRecorder_createAttachmentPath')
61
+ const pageGotoCh = tracingChannel('orchestrion:playwright-core:Page_goto')
62
+
43
63
  const testToCtx = new WeakMap()
44
64
  const testSuiteToCtx = new Map()
45
65
  const testSuiteToTestStatuses = new Map()
46
66
  const testSuiteToErrors = new Map()
47
67
  const testsToTestStatuses = new Map()
48
68
 
49
- const RUM_FLUSH_WAIT_TIME = Number(getValueFromEnvSources('DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS')) || 500
69
+ const RUM_FLUSH_WAIT_TIME = getValueFromEnvSources('DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS')
70
+ const DD_PROPERTIES_TIMEOUT = 5000
71
+ const isFailureScreenshotUploadEnabled =
72
+ getValueFromEnvSources('DD_TEST_FAILURE_SCREENSHOTS_ENABLED') === true
50
73
 
51
74
  let applyRepeatEachIndex = null
52
75
 
53
76
  let startedSuites = []
54
77
 
78
+ // Browser-side callbacks live in a coverage-excluded file so coverage counters can't reach chromium.
79
+ const { detectRum, stopRumSession } = require('./playwright-browser-scripts')
80
+
55
81
  const STATUS_TO_TEST_STATUS = {
56
82
  passed: 'pass',
57
83
  failed: 'fail',
@@ -63,6 +89,7 @@ let remainingTestsByFile = {}
63
89
  let isKnownTestsEnabled = false
64
90
  let isEarlyFlakeDetectionEnabled = false
65
91
  let earlyFlakeDetectionNumRetries = 0
92
+ let earlyFlakeDetectionSlowTestRetries = {}
66
93
  let isEarlyFlakeDetectionFaulty = false
67
94
  let earlyFlakeDetectionFaultyThreshold = 0
68
95
  let isFlakyTestRetriesEnabled = false
@@ -73,13 +100,45 @@ let testManagementAttemptToFixRetries = 0
73
100
  let testManagementTests = {}
74
101
  let isImpactedTestsEnabled = false
75
102
  let modifiedFiles = {}
76
- const quarantinedOrDisabledTestsAttemptToFix = []
77
103
  let quarantinedButNotAttemptToFixFqns = new Set()
104
+ let testsReportedInGenerateSummary = new Set()
78
105
  const newTestsWithDynamicNames = new Set()
106
+ const attemptToFixExecutions = new Map()
107
+ const loggedAttemptToFixTests = new Set()
108
+ const efdManagedTestKeys = new Set()
109
+ const efdRetryCountByTestKey = new Map()
110
+ const efdRetryCountRequestsByTestKey = new Map()
111
+ const efdRetryTestsById = new Map()
112
+ const efdScheduledOriginalTestKeys = new Set()
113
+ const efdStartedOriginalTestKeys = new Set()
114
+ const efdSlowAbortedTests = new Set()
115
+ const ddPropertiesByTestId = new Map()
116
+ const ddPropertiesRequestsByTestId = new Map()
117
+ const disabledTestIds = new Set()
79
118
  let rootDir = ''
80
119
  let sessionProjects = []
81
120
 
82
121
  const MINIMUM_SUPPORTED_VERSION_RANGE_EFD = '>=1.38.0' // TODO: remove this once we drop support for v5
122
+ const EFD_RETRY_COUNT_REQUEST = 'ddEfdRetryCountRequest'
123
+ const EFD_RETRY_COUNT_RESPONSE = 'ddEfdRetryCountResponse'
124
+ const DD_PROPERTIES_REQUEST = 'ddPropertiesRequest'
125
+ const DD_PROPERTIES_RESPONSE = 'ddProperties'
126
+ const kDdPlaywrightDisabledTestIds = Symbol('ddPlaywrightDisabledTestIds')
127
+ const kDdPlaywrightFailureScreenshots = Symbol('ddPlaywrightFailureScreenshots')
128
+ const kDdPlaywrightWorkerHostInstrumented = Symbol('ddPlaywrightWorkerHostInstrumented')
129
+ const kDdPlaywrightWorkerInstrumented = Symbol('ddPlaywrightWorkerInstrumented')
130
+ const PLAYWRIGHT_FAILURE_SCREENSHOT_PATH_RE = /(?:^|[\\/])test-failed-\d+\.png$/
131
+ const automaticFailureScreenshotPaths = new Set()
132
+
133
+ /**
134
+ * Returns whether Playwright's internal screenshot recorder created an attachment.
135
+ *
136
+ * @param {object} attachment - Playwright attachment payload
137
+ * @returns {boolean}
138
+ */
139
+ function isAutomaticFailureScreenshotAttachment (attachment) {
140
+ return typeof attachment?.path === 'string' && automaticFailureScreenshotPaths.delete(attachment.path)
141
+ }
83
142
 
84
143
  function isValidKnownTests (receivedKnownTests) {
85
144
  return !!receivedKnownTests.playwright
@@ -90,6 +149,259 @@ function getTestFullyQualifiedName (test) {
90
149
  return `${test._requireFile} ${fullname}`
91
150
  }
92
151
 
152
+ /**
153
+ * @param {object} test
154
+ * @returns {string|undefined}
155
+ */
156
+ function getTestProjectKey (test) {
157
+ const { _projectIndex, _projectId } = test
158
+ if (_projectIndex !== undefined) {
159
+ return `index:${_projectIndex}`
160
+ }
161
+ if (_projectId !== undefined) {
162
+ return `id:${_projectId}`
163
+ }
164
+
165
+ const projectSuite = getSuiteType(test, 'project')
166
+ const projectName = projectSuite?._fullProject?.project?.name ||
167
+ projectSuite?._fullProject?.name ||
168
+ projectSuite?.title
169
+ if (projectName) {
170
+ return `name:${projectName}`
171
+ }
172
+ }
173
+
174
+ /**
175
+ * @param {object} test
176
+ * @returns {number|undefined}
177
+ */
178
+ function getTestEfdRepeatEachIndex (test) {
179
+ if (Object.hasOwn(test, '_ddEfdOriginalRepeatEachIndex')) {
180
+ return test._ddEfdOriginalRepeatEachIndex
181
+ }
182
+ return test.repeatEachIndex
183
+ }
184
+
185
+ /**
186
+ * @param {object} test
187
+ * @returns {string|undefined}
188
+ */
189
+ function getTestRepeatEachKey (test) {
190
+ const repeatEachIndex = getTestEfdRepeatEachIndex(test)
191
+ if (repeatEachIndex !== undefined) {
192
+ return `repeat:${repeatEachIndex}`
193
+ }
194
+ }
195
+
196
+ /**
197
+ * @param {object} test
198
+ * @returns {string}
199
+ */
200
+ function getTestEfdKey (test) {
201
+ const projectKey = getTestProjectKey(test)
202
+ const repeatEachKey = getTestRepeatEachKey(test)
203
+ const testFqn = getTestFullyQualifiedName(test)
204
+ return [projectKey, repeatEachKey, testFqn].filter(Boolean).join(' ')
205
+ }
206
+
207
+ function getConfiguredEfdRetryCount () {
208
+ if (!earlyFlakeDetectionSlowTestRetries || !Object.keys(earlyFlakeDetectionSlowTestRetries).length) {
209
+ return earlyFlakeDetectionNumRetries
210
+ }
211
+ return getMaxEfdRetryCount(earlyFlakeDetectionSlowTestRetries)
212
+ }
213
+
214
+ function markEfdManagedTest (test) {
215
+ test._ddIsEfdManagedTest = true
216
+ test._ddEfdSlowTestRetries = earlyFlakeDetectionSlowTestRetries
217
+ efdManagedTestKeys.add(getTestEfdKey(test))
218
+ }
219
+
220
+ function markEfdRetryTest (test, retryIndex, originalTest) {
221
+ test._ddIsEfdRetry = true
222
+ test._ddEfdRetryIndex = retryIndex
223
+ if (originalTest) {
224
+ test._ddEfdOriginalRepeatEachIndex = getTestEfdRepeatEachIndex(originalTest)
225
+ }
226
+ }
227
+
228
+ function registerEfdRetryTest (test) {
229
+ if (!test._ddIsEfdRetry) {
230
+ return
231
+ }
232
+
233
+ efdRetryTestsById.set(test.id, {
234
+ retryIndex: test._ddEfdRetryIndex,
235
+ testEfdKey: getTestEfdKey(test),
236
+ })
237
+ }
238
+
239
+ function getTestEfdSlowTestRetries (test) {
240
+ return test._ddEfdSlowTestRetries || earlyFlakeDetectionSlowTestRetries
241
+ }
242
+
243
+ function isTestEfdManaged (test) {
244
+ return !!test._ddIsEfdManagedTest || (
245
+ (test._ddIsNew || test._ddIsModified) &&
246
+ !test._ddIsAttemptToFix &&
247
+ isEarlyFlakeDetectionEnabled
248
+ )
249
+ }
250
+
251
+ function getFileSuiteRepeatEachIndex (fileSuite) {
252
+ const test = fileSuite.allTests()[0]
253
+ return test ? getTestEfdRepeatEachIndex(test) || 0 : 0
254
+ }
255
+
256
+ function getEfdRetryRepeatEachIndex (fileSuite, projectSuite, retryIndex, retryCount) {
257
+ const nativeRepeatEach = projectSuite._fullProject?.project?.repeatEach || 1
258
+ const originalRepeatEachIndex = getFileSuiteRepeatEachIndex(fileSuite)
259
+ return nativeRepeatEach + (originalRepeatEachIndex * retryCount) + retryIndex - 1
260
+ }
261
+
262
+ function getEfdRetryCountForTest (test) {
263
+ return efdRetryCountByTestKey.get(getTestEfdKey(test)) ?? getConfiguredEfdRetryCount()
264
+ }
265
+
266
+ function setEfdRetryCountForTest (test, retryCount) {
267
+ const testEfdKey = getTestEfdKey(test)
268
+ efdRetryCountByTestKey.set(testEfdKey, retryCount)
269
+
270
+ const requests = efdRetryCountRequestsByTestKey.get(testEfdKey)
271
+ if (requests) {
272
+ efdRetryCountRequestsByTestKey.delete(testEfdKey)
273
+ for (const resolveRequest of requests) {
274
+ resolveRequest(retryCount)
275
+ }
276
+ }
277
+ }
278
+
279
+ function sendEfdRetryCountToWorker (workerProcess, testId, retryIndex, retryCount) {
280
+ workerProcess.send({
281
+ type: EFD_RETRY_COUNT_RESPONSE,
282
+ testId,
283
+ isEfdRetry: retryIndex !== undefined,
284
+ retryIndex,
285
+ retryCount,
286
+ })
287
+ }
288
+
289
+ function sendEfdRetryCountToWorkerWhenAvailable (workerProcess, testId) {
290
+ const efdRetryTest = efdRetryTestsById.get(testId)
291
+ if (!efdRetryTest) {
292
+ sendEfdRetryCountToWorker(workerProcess, testId)
293
+ return
294
+ }
295
+
296
+ const { retryIndex, testEfdKey } = efdRetryTest
297
+
298
+ if (!testEfdKey || !efdManagedTestKeys.has(testEfdKey)) {
299
+ sendEfdRetryCountToWorker(workerProcess, testId)
300
+ return
301
+ }
302
+
303
+ const retryCount = efdRetryCountByTestKey.get(testEfdKey)
304
+ if (retryCount !== undefined) {
305
+ sendEfdRetryCountToWorker(workerProcess, testId, retryIndex, retryCount)
306
+ return
307
+ }
308
+
309
+ if (!efdStartedOriginalTestKeys.has(testEfdKey) && !efdScheduledOriginalTestKeys.has(testEfdKey)) {
310
+ sendEfdRetryCountToWorker(workerProcess, testId, retryIndex, 0)
311
+ return
312
+ }
313
+
314
+ if (!efdRetryCountRequestsByTestKey.has(testEfdKey)) {
315
+ efdRetryCountRequestsByTestKey.set(testEfdKey, [])
316
+ }
317
+ efdRetryCountRequestsByTestKey.get(testEfdKey).push((retryCount) => {
318
+ sendEfdRetryCountToWorker(workerProcess, testId, retryIndex, retryCount)
319
+ })
320
+ }
321
+
322
+ function sendDdPropertiesToWorker (workerProcess, testId, properties) {
323
+ workerProcess.send({
324
+ type: DD_PROPERTIES_RESPONSE,
325
+ testId,
326
+ properties,
327
+ })
328
+ }
329
+
330
+ function setDdPropertiesForTest (workerProcess, testId, properties) {
331
+ ddPropertiesByTestId.set(testId, properties)
332
+
333
+ const requests = ddPropertiesRequestsByTestId.get(testId)
334
+ if (requests) {
335
+ ddPropertiesRequestsByTestId.delete(testId)
336
+ for (const resolveRequest of requests) {
337
+ resolveRequest(properties)
338
+ }
339
+ }
340
+
341
+ sendDdPropertiesToWorker(workerProcess, testId, properties)
342
+ }
343
+
344
+ function sendDdPropertiesToWorkerWhenAvailable (workerProcess, testId) {
345
+ const properties = ddPropertiesByTestId.get(testId)
346
+ if (properties) {
347
+ sendDdPropertiesToWorker(workerProcess, testId, properties)
348
+ return
349
+ }
350
+
351
+ if (!ddPropertiesRequestsByTestId.has(testId)) {
352
+ ddPropertiesRequestsByTestId.set(testId, [])
353
+ }
354
+ ddPropertiesRequestsByTestId.get(testId).push((properties) => {
355
+ sendDdPropertiesToWorker(workerProcess, testId, properties)
356
+ })
357
+ }
358
+
359
+ /**
360
+ * @param {object} test
361
+ * @returns {boolean}
362
+ */
363
+ function shouldRequestEfdRetryCount (test) {
364
+ // The main process remains the source of truth. repeatEachIndex is only used as
365
+ // a cheap worker-side filter so first executions do not block on coordination.
366
+ return test._ddIsEfdRetry || test.repeatEachIndex > 0
367
+ }
368
+
369
+ function waitForEfdRetryCount (test) {
370
+ if (!process.send || !shouldRequestEfdRetryCount(test)) {
371
+ return Promise.resolve()
372
+ }
373
+
374
+ const testEfdKey = getTestEfdKey(test)
375
+ return new Promise(resolve => {
376
+ const messageHandler = (message) => {
377
+ if (message?.type === EFD_RETRY_COUNT_RESPONSE && message.testId === test.id) {
378
+ if (message.isEfdRetry) {
379
+ test._ddIsEfdRetry = true
380
+ test._ddEfdRetryIndex = message.retryIndex
381
+ test._ddEfdRetryCount = message.retryCount
382
+ efdRetryCountByTestKey.set(testEfdKey, message.retryCount)
383
+ }
384
+ process.removeListener('message', messageHandler)
385
+ resolve()
386
+ }
387
+ }
388
+
389
+ process.on('message', messageHandler)
390
+ process.send({
391
+ type: EFD_RETRY_COUNT_REQUEST,
392
+ testId: test.id,
393
+ })
394
+ })
395
+ }
396
+
397
+ function shouldSkipEfdRetry (test) {
398
+ if (!test._ddIsEfdRetry) {
399
+ return false
400
+ }
401
+ const retryCount = test._ddEfdRetryCount ?? efdRetryCountByTestKey.get(getTestEfdKey(test))
402
+ return retryCount !== undefined && test._ddEfdRetryIndex > retryCount
403
+ }
404
+
93
405
  function getTestProperties (test) {
94
406
  const testName = getTestFullname(test)
95
407
  const testSuite = getTestSuitePath(test._requireFile, rootDir)
@@ -117,15 +429,22 @@ function getSuiteType (test, type) {
117
429
  return suite
118
430
  }
119
431
 
432
+ function isSuiteEntry (entry) {
433
+ return entry.constructor.name === 'Suite' || entry.constructor.name === '_Suite'
434
+ }
435
+
120
436
  // Copy of Suite#_deepClone but with a function to filter tests
121
- function deepCloneSuite (suite, filterTest, tags = []) {
437
+ function deepCloneSuite (suite, filterTest, tags = [], configureCopiedTest) {
122
438
  const copy = suite._clone()
123
439
  for (const entry of suite._entries) {
124
- if (entry.constructor.name === 'Suite') {
125
- copy._addSuite(deepCloneSuite(entry, filterTest, tags))
440
+ if (isSuiteEntry(entry)) {
441
+ copy._addSuite(deepCloneSuite(entry, filterTest, tags, configureCopiedTest))
126
442
  } else {
127
443
  if (filterTest(entry)) {
128
444
  const copiedTest = entry._clone()
445
+ if (configureCopiedTest) {
446
+ configureCopiedTest(copiedTest, entry)
447
+ }
129
448
  for (const tag of tags) {
130
449
  const resolvedTag = typeof tag === 'function' ? tag(entry) : tag
131
450
 
@@ -204,7 +523,28 @@ function getProjectsFromRunner (runner, configArg) {
204
523
  })
205
524
  }
206
525
 
526
+ /**
527
+ * Returns whether at least one Playwright project captures automatic screenshots for failed tests.
528
+ *
529
+ * @param {Array<object>} projects - Playwright projects with resolved use options
530
+ * @returns {boolean} Whether failure screenshot capture is enabled
531
+ */
532
+ function isFailureScreenshotCaptureEnabled (projects) {
533
+ for (const project of projects) {
534
+ const screenshot = project.use?.screenshot
535
+ const mode = typeof screenshot === 'object' && screenshot !== null ? screenshot.mode : screenshot
536
+ if (mode === 'on' || mode === 'only-on-failure' || mode === 'on-first-failure') {
537
+ return true
538
+ }
539
+ }
540
+ return false
541
+ }
542
+
207
543
  function getProjectsFromDispatcher (dispatcher) {
544
+ const bundledConfig = dispatcher._testRun?.config?.config?.projects
545
+ if (bundledConfig) {
546
+ return bundledConfig
547
+ }
208
548
  const newConfig = dispatcher._config?.config?.projects
209
549
  if (newConfig) {
210
550
  return newConfig
@@ -287,6 +627,36 @@ function testWillRetry (test, testStatus) {
287
627
  return testStatus === 'fail' && test.results.length <= test.retries
288
628
  }
289
629
 
630
+ function getFinalStatus ({
631
+ isFinalExecution,
632
+ isDisabled,
633
+ isQuarantined,
634
+ isAtrRetry,
635
+ isEfdManagedTest,
636
+ isAttemptToFix,
637
+ hasFailedAllRetries,
638
+ hasFailedAttemptToFixRetries,
639
+ hasPassedAnyEfdAttempt,
640
+ testStatus,
641
+ }) {
642
+ if (!isFinalExecution) {
643
+ return
644
+ }
645
+ if (isDisabled || isQuarantined || testStatus === 'skip') {
646
+ return 'skip'
647
+ }
648
+ if (isAtrRetry) {
649
+ return hasFailedAllRetries ? 'fail' : 'pass'
650
+ }
651
+ if (isEfdManagedTest) {
652
+ return hasPassedAnyEfdAttempt ? 'pass' : 'fail'
653
+ }
654
+ if (isAttemptToFix) {
655
+ return hasFailedAttemptToFixRetries ? 'fail' : 'pass'
656
+ }
657
+ return testStatus
658
+ }
659
+
290
660
  function getTestFullname (test) {
291
661
  let parent = test.parent
292
662
  const names = [test.title]
@@ -317,6 +687,14 @@ function testBeginHandler (test, browserName, shouldCreateTestSpan) {
317
687
  if (_type === 'beforeAll' || _type === 'afterAll') {
318
688
  return
319
689
  }
690
+ if (shouldSkipEfdRetry(test)) {
691
+ test._ddShouldSkipEfdRetry = true
692
+ return
693
+ }
694
+ test._ddStartTime = performance.now()
695
+ if (isTestEfdManaged(test) && !test._ddIsEfdRetry) {
696
+ efdStartedOriginalTestKeys.add(getTestEfdKey(test))
697
+ }
320
698
  // this means that a skipped test is being handled
321
699
  if (!remainingTestsByFile[testSuiteAbsolutePath].length) {
322
700
  return
@@ -334,6 +712,11 @@ function testBeginHandler (test, browserName, shouldCreateTestSpan) {
334
712
  // We disable retries by default if attemptToFix is true
335
713
  if (getTestProperties(test).attemptToFix) {
336
714
  test.retries = 0
715
+ logAttemptToFixTestExecution(
716
+ getTestSuitePath(testSuiteAbsolutePath, rootDir),
717
+ getTestFullname(test),
718
+ loggedAttemptToFixTests
719
+ )
337
720
  }
338
721
 
339
722
  // this handles tests that do not go through the worker process (because they're skipped)
@@ -353,6 +736,45 @@ function testBeginHandler (test, browserName, shouldCreateTestSpan) {
353
736
  }
354
737
  }
355
738
 
739
+ function finishTestSuiteIfDone (testSuiteAbsolutePath, projects) {
740
+ if (!shouldFinishTestSuite(testSuiteAbsolutePath)) {
741
+ return
742
+ }
743
+
744
+ const skippedTests = remainingTestsByFile[testSuiteAbsolutePath]
745
+ .filter(test => test.expectedStatus === 'skipped')
746
+
747
+ for (const test of skippedTests) {
748
+ const browserName = getBrowserNameFromProjects(projects, test)
749
+ testSkipCh.publish({
750
+ testName: getTestFullname(test),
751
+ testSuiteAbsolutePath,
752
+ testSourceFileAbsolutePath: test.location.file,
753
+ testSourceLine: test.location.line,
754
+ browserName,
755
+ isNew: test._ddIsNew,
756
+ isDisabled: test._ddIsDisabled,
757
+ isModified: test._ddIsModified,
758
+ isQuarantined: test._ddIsQuarantined,
759
+ })
760
+ }
761
+ remainingTestsByFile[testSuiteAbsolutePath] = []
762
+
763
+ const testStatuses = testSuiteToTestStatuses.get(testSuiteAbsolutePath)
764
+ let testSuiteStatus = 'pass'
765
+ if (testStatuses?.includes('fail')) {
766
+ testSuiteStatus = 'fail'
767
+ } else if (testStatuses?.every(status => status === 'skip')) {
768
+ testSuiteStatus = 'skip'
769
+ }
770
+
771
+ const suiteError = getTestSuiteError(testSuiteAbsolutePath)
772
+ const testSuiteCtx = testSuiteToCtx.get(testSuiteAbsolutePath)
773
+ if (testSuiteCtx) {
774
+ testSuiteFinishCh.publish({ status: testSuiteStatus, error: suiteError, ...testSuiteCtx.currentStore })
775
+ }
776
+ }
777
+
356
778
  function testEndHandler ({
357
779
  test,
358
780
  annotations,
@@ -382,11 +804,21 @@ function testEndHandler ({
382
804
  return
383
805
  }
384
806
 
807
+ if (test._ddShouldSkipEfdRetry || shouldSkipEfdRetry(test)) {
808
+ test._ddShouldSkipEfdRetry = true
809
+ remainingTestsByFile[testSuiteAbsolutePath] = remainingTestsByFile[testSuiteAbsolutePath]
810
+ .filter(currentTest => currentTest !== test)
811
+ finishTestSuiteIfDone(testSuiteAbsolutePath, projects)
812
+ return
813
+ }
814
+
815
+ const isEfdManagedTest = isTestEfdManaged(test)
385
816
  const testFqn = getTestFullyQualifiedName(test)
386
- const testStatuses = testsToTestStatuses.get(testFqn) || []
817
+ const testStatusKey = isEfdManagedTest ? getTestEfdKey(test) : testFqn
818
+ const testStatuses = testsToTestStatuses.get(testStatusKey) || []
387
819
 
388
820
  if (testStatuses.length === 0) {
389
- testsToTestStatuses.set(testFqn, [testStatus])
821
+ testsToTestStatuses.set(testStatusKey, [testStatus])
390
822
  if (test._ddIsNew && DYNAMIC_NAME_RE.test(getTestFullname(test))) {
391
823
  newTestsWithDynamicNames.add(`${getTestSuitePath(test._requireFile, rootDir)} › ${getTestFullname(test)}`)
392
824
  }
@@ -394,8 +826,33 @@ function testEndHandler ({
394
826
  testStatuses.push(testStatus)
395
827
  }
396
828
 
829
+ const testEfdKey = getTestEfdKey(test)
830
+ if (isEfdManagedTest && !test._ddIsEfdRetry && !efdRetryCountByTestKey.has(testEfdKey)) {
831
+ const testResult = results.at(-1)
832
+ const duration = testResult?.duration > 0 ? testResult.duration : performance.now() - test._ddStartTime
833
+ const retryCount = getEfdRetryCount(duration, getTestEfdSlowTestRetries(test))
834
+ setEfdRetryCountForTest(test, retryCount)
835
+ if (retryCount === 0) {
836
+ efdSlowAbortedTests.add(testEfdKey)
837
+ }
838
+ }
839
+
397
840
  const testProperties = getTestProperties(test)
398
841
 
842
+ if (testProperties.attemptToFix) {
843
+ test._ddHasFailedAttemptToFixRetries = false
844
+ test._ddHasFailedAllRetries = false
845
+ test._ddHasPassedAttemptToFixRetries = false
846
+
847
+ recordAttemptToFixExecution(attemptToFixExecutions, {
848
+ testSuite: getTestSuitePath(test._requireFile, rootDir),
849
+ testName: getTestFullname(test),
850
+ status: testStatus,
851
+ isDisabled: testProperties.disabled,
852
+ isQuarantined: testProperties.quarantined,
853
+ })
854
+ }
855
+
399
856
  if (testStatuses.length === testManagementAttemptToFixRetries + 1 && testProperties.attemptToFix) {
400
857
  if (testStatuses.includes('fail')) {
401
858
  test._ddHasFailedAttemptToFixRetries = true
@@ -408,9 +865,10 @@ function testEndHandler ({
408
865
  }
409
866
 
410
867
  // Check if all EFD retries failed
411
- if (testStatuses.length === earlyFlakeDetectionNumRetries + 1 &&
868
+ const efdRetryCount = getEfdRetryCountForTest(test)
869
+ if (efdRetryCount > 0 && testStatuses.length === efdRetryCount + 1 &&
412
870
  (test._ddIsNew || test._ddIsModified) &&
413
- test._ddIsEfdRetry &&
871
+ isEarlyFlakeDetectionEnabled &&
414
872
  testStatuses.every(status => status === 'fail')) {
415
873
  test._ddHasFailedAllRetries = true
416
874
  }
@@ -424,6 +882,8 @@ function testEndHandler ({
424
882
  test._ddHasFailedAllRetries = true
425
883
  }
426
884
 
885
+ const willRetry = testWillRetry(test, testStatus)
886
+
427
887
  // this handles tests that do not go through the worker process (because they're skipped)
428
888
  if (shouldCreateTestSpan) {
429
889
  const testResult = results.at(-1)
@@ -432,6 +892,20 @@ function testEndHandler ({
432
892
  isFlakyTestRetriesEnabled &&
433
893
  !test._ddIsAttemptToFix &&
434
894
  !test._ddIsEfdRetry
895
+
896
+ const finalStatus = getFinalStatus({
897
+ isFinalExecution: !willRetry,
898
+ isDisabled: test._ddIsDisabled,
899
+ isQuarantined: test._ddIsQuarantined,
900
+ isAtrRetry,
901
+ isEfdManagedTest,
902
+ isAttemptToFix: test._ddIsAttemptToFix,
903
+ hasFailedAllRetries: test._ddHasFailedAllRetries,
904
+ hasFailedAttemptToFixRetries: test._ddHasFailedAttemptToFixRetries,
905
+ hasPassedAnyEfdAttempt: testStatuses.includes('pass'),
906
+ testStatus,
907
+ })
908
+
435
909
  // if there is no testCtx, the skipped test will be created later
436
910
  if (testCtx) {
437
911
  testFinishCh.publish({
@@ -451,94 +925,239 @@ function testEndHandler ({
451
925
  hasFailedAttemptToFixRetries: test._ddHasFailedAttemptToFixRetries,
452
926
  isAtrRetry,
453
927
  isModified: test._ddIsModified,
928
+ finalStatus,
929
+ earlyFlakeAbortReason: efdSlowAbortedTests.has(testEfdKey) ? 'slow' : undefined,
454
930
  ...testCtx.currentStore,
455
931
  })
456
932
  }
457
933
  }
458
934
 
459
- if (testSuiteToTestStatuses.has(testSuiteAbsolutePath)) {
460
- testSuiteToTestStatuses.get(testSuiteAbsolutePath).push(testStatus)
461
- } else {
462
- testSuiteToTestStatuses.set(testSuiteAbsolutePath, [testStatus])
463
- }
935
+ if (!willRetry) {
936
+ if (testSuiteToTestStatuses.has(testSuiteAbsolutePath)) {
937
+ testSuiteToTestStatuses.get(testSuiteAbsolutePath).push(testStatus)
938
+ } else {
939
+ testSuiteToTestStatuses.set(testSuiteAbsolutePath, [testStatus])
940
+ }
464
941
 
465
- if (error) {
466
- addErrorToTestSuite(testSuiteAbsolutePath, error)
942
+ if (error) {
943
+ addErrorToTestSuite(testSuiteAbsolutePath, error)
944
+ }
467
945
  }
468
946
 
469
- if (!testWillRetry(test, testStatus)) {
947
+ if (!willRetry) {
470
948
  remainingTestsByFile[testSuiteAbsolutePath] = remainingTestsByFile[testSuiteAbsolutePath]
471
949
  .filter(currentTest => currentTest !== test)
472
950
  }
473
951
 
474
- if (shouldFinishTestSuite(testSuiteAbsolutePath)) {
475
- const skippedTests = remainingTestsByFile[testSuiteAbsolutePath]
476
- .filter(test => test.expectedStatus === 'skipped')
952
+ finishTestSuiteIfDone(testSuiteAbsolutePath, projects)
953
+ }
477
954
 
478
- for (const test of skippedTests) {
479
- const browserName = getBrowserNameFromProjects(projects, test)
480
- testSkipCh.publish({
481
- testName: getTestFullname(test),
482
- testSuiteAbsolutePath,
483
- testSourceFileAbsolutePath: test.location.file,
484
- testSourceLine: test.location.line,
485
- browserName,
486
- isNew: test._ddIsNew,
487
- isDisabled: test._ddIsDisabled,
488
- isModified: test._ddIsModified,
489
- isQuarantined: test._ddIsQuarantined,
490
- })
955
+ function dispatcherRunWrapper (run) {
956
+ return function (...args) {
957
+ remainingTestsByFile = getTestsBySuiteFromTestsById(this._testById)
958
+ return run.apply(this, args)
959
+ }
960
+ }
961
+
962
+ function deferEfdRetryGroups (testGroups) {
963
+ const groupsWithOriginalTests = []
964
+ const efdRetryOnlyGroups = []
965
+
966
+ for (const group of testGroups) {
967
+ const originalTests = []
968
+ const efdRetryTests = []
969
+
970
+ for (const test of group.tests) {
971
+ if (test._ddIsEfdRetry) {
972
+ efdRetryTests.push(test)
973
+ } else {
974
+ originalTests.push(test)
975
+ if (isTestEfdManaged(test)) {
976
+ efdScheduledOriginalTestKeys.add(getTestEfdKey(test))
977
+ }
978
+ }
491
979
  }
492
- remainingTestsByFile[testSuiteAbsolutePath] = []
493
980
 
494
- const testStatuses = testSuiteToTestStatuses.get(testSuiteAbsolutePath)
495
- let testSuiteStatus = 'pass'
496
- if (testStatuses.includes('fail')) {
497
- testSuiteStatus = 'fail'
498
- } else if (testStatuses.every(status => status === 'skip')) {
499
- testSuiteStatus = 'skip'
981
+ if (efdRetryTests.length && originalTests.length) {
982
+ group.tests = [...originalTests, ...efdRetryTests]
500
983
  }
501
984
 
502
- const suiteError = getTestSuiteError(testSuiteAbsolutePath)
503
- const testSuiteCtx = testSuiteToCtx.get(testSuiteAbsolutePath)
504
- testSuiteFinishCh.publish({ status: testSuiteStatus, error: suiteError, ...testSuiteCtx.currentStore })
985
+ if (originalTests.length) {
986
+ groupsWithOriginalTests.push(group)
987
+ } else {
988
+ efdRetryOnlyGroups.push(group)
989
+ }
505
990
  }
991
+
992
+ return [...groupsWithOriginalTests, ...efdRetryOnlyGroups]
506
993
  }
507
994
 
508
- function dispatcherRunWrapper (run) {
995
+ function prepareDispatcherRun (dispatcher, args) {
996
+ let testGroups = args[0]
997
+
998
+ // Filter out disabled tests from testGroups before they get scheduled,
999
+ // unless they have attemptToFix (in which case they should still run and be retried)
1000
+ if (isTestManagementTestsEnabled) {
1001
+ for (const group of testGroups) {
1002
+ group.tests = group.tests.filter(test => !test._ddIsDisabled || test._ddIsAttemptToFix)
1003
+ }
1004
+ // Remove empty groups
1005
+ testGroups = testGroups.filter(group => group.tests.length > 0)
1006
+ }
1007
+
1008
+ if (isEarlyFlakeDetectionEnabled) {
1009
+ testGroups = deferEfdRetryGroups(testGroups)
1010
+ }
1011
+
1012
+ if (!dispatcher._allTests) {
1013
+ // Removed in https://github.com/microsoft/playwright/commit/1e52c37b254a441cccf332520f60225a5acc14c7
1014
+ // Not available from >=1.44.0
1015
+ dispatcher._ddAllTests = testGroups.flatMap(g => g.tests)
1016
+ }
1017
+ remainingTestsByFile = getTestsBySuiteFromTestGroups(testGroups)
1018
+ args[0] = testGroups
1019
+ }
1020
+
1021
+ function dispatcherRunWrapperNew (run) {
509
1022
  return function () {
510
- remainingTestsByFile = getTestsBySuiteFromTestsById(this._testById)
1023
+ prepareDispatcherRun(this, arguments)
511
1024
  return run.apply(this, arguments)
512
1025
  }
513
1026
  }
514
1027
 
515
- function dispatcherRunWrapperNew (run) {
516
- return function (testGroups) {
517
- // Filter out disabled tests from testGroups before they get scheduled,
518
- // unless they have attemptToFix (in which case they should still run and be retried)
519
- if (isTestManagementTestsEnabled) {
520
- for (const group of testGroups) {
521
- group.tests = group.tests.filter(test => !test._ddIsDisabled || test._ddIsAttemptToFix)
1028
+ function onDispatcherCreateWorker (dispatcher, worker) {
1029
+ if (!worker) {
1030
+ return worker
1031
+ }
1032
+
1033
+ const projects = getProjectsFromDispatcher(dispatcher)
1034
+ sessionProjects = projects
1035
+ const automaticFailureScreenshotPathsByTestId = new Map()
1036
+
1037
+ if (disabledTestIds.size && !worker[kDdPlaywrightWorkerHostInstrumented] &&
1038
+ typeof worker.runTestGroup === 'function') {
1039
+ Object.defineProperty(worker, kDdPlaywrightWorkerHostInstrumented, { value: true })
1040
+ shimmer.wrap(worker, 'runTestGroup', runTestGroup => function (runPayload) {
1041
+ // Serial retries can restore disabled tests that were filtered from the initial dispatcher groups.
1042
+ let disabledIds
1043
+ for (const { testId } of runPayload.entries) {
1044
+ if (disabledTestIds.has(testId)) {
1045
+ disabledIds ??= []
1046
+ disabledIds.push(testId)
1047
+ }
1048
+ }
1049
+ if (disabledIds) {
1050
+ runPayload._ddDisabledTestIds = disabledIds
1051
+ }
1052
+ return runTestGroup.apply(this, arguments)
1053
+ })
1054
+ }
1055
+
1056
+ worker.on('testBegin', ({ testId }) => {
1057
+ const test = getTestByTestId(dispatcher, testId)
1058
+ if (!test) return
1059
+
1060
+ const browser = getBrowserNameFromProjects(projects, test)
1061
+ const shouldCreateTestSpan = test.expectedStatus === 'skipped'
1062
+ testBeginHandler(test, browser, shouldCreateTestSpan)
1063
+ })
1064
+ worker.on('attach', ({ testId, path, _ddIsAutomaticFailureScreenshot }) => {
1065
+ if (!_ddIsAutomaticFailureScreenshot) return
1066
+
1067
+ let screenshotPaths = automaticFailureScreenshotPathsByTestId.get(testId)
1068
+ if (!screenshotPaths) {
1069
+ screenshotPaths = new Set()
1070
+ automaticFailureScreenshotPathsByTestId.set(testId, screenshotPaths)
1071
+ }
1072
+ screenshotPaths.add(path)
1073
+ })
1074
+ worker.on('testEnd', ({ testId, status, errors, annotations }) => {
1075
+ const test = getTestByTestId(dispatcher, testId)
1076
+ if (!test) return
1077
+
1078
+ const isTimeout = status === 'timedOut'
1079
+ const testStatus = STATUS_TO_TEST_STATUS[status]
1080
+ const shouldCreateTestSpan = test.expectedStatus === 'skipped'
1081
+ if (shouldCreateTestSpan && !testToCtx.has(test)) {
1082
+ testBeginHandler(test, getBrowserNameFromProjects(projects, test), true)
1083
+ }
1084
+ testEndHandler(
1085
+ {
1086
+ test,
1087
+ annotations,
1088
+ testStatus,
1089
+ error: errors && errors[0],
1090
+ isTimeout,
1091
+ shouldCreateTestSpan,
1092
+ projects,
1093
+ }
1094
+ )
1095
+ const testResult = test.results.at(-1)
1096
+ const automaticFailureScreenshotPaths = automaticFailureScreenshotPathsByTestId.get(testId)
1097
+ automaticFailureScreenshotPathsByTestId.delete(testId)
1098
+ if (testStatus === 'fail' && automaticFailureScreenshotPaths?.size && testResult?.attachments?.length) {
1099
+ const screenshots = []
1100
+ for (const attachment of testResult.attachments) {
1101
+ if (automaticFailureScreenshotPaths.has(attachment.path)) {
1102
+ screenshots.push(attachment)
1103
+ }
1104
+ }
1105
+ if (screenshots.length) {
1106
+ worker[kDdPlaywrightFailureScreenshots] ??= []
1107
+ worker[kDdPlaywrightFailureScreenshots].push(screenshots)
522
1108
  }
523
- // Remove empty groups
524
- testGroups = testGroups.filter(group => group.tests.length > 0)
525
1109
  }
1110
+ const isAtrRetry = testResult?.retry > 0 &&
1111
+ isFlakyTestRetriesEnabled &&
1112
+ !test._ddIsAttemptToFix &&
1113
+ !test._ddIsEfdRetry
526
1114
 
527
- if (!this._allTests) {
528
- // Removed in https://github.com/microsoft/playwright/commit/1e52c37b254a441cccf332520f60225a5acc14c7
529
- // Not available from >=1.44.0
530
- this._ddAllTests = testGroups.flatMap(g => g.tests)
1115
+ // EFD retries (new or modified tests) are implemented as clones with retries=0,
1116
+ // so testWillRetry always returns false for them. Instead, we track how many
1117
+ // executions have been reported via testsToTestStatuses (updated by testEndHandler
1118
+ // above) and mark the execution final once the count reaches the expected total.
1119
+ // This mirrors how ATF finality is detected and centralizes the decision in the
1120
+ // main process, so workers only need to act on the _ddIsFinalExecution flag.
1121
+ const isEfdManagedTest = isTestEfdManaged(test)
1122
+ let isFinalExecution
1123
+ if (isEfdManagedTest) {
1124
+ const efdTestStatuses = testsToTestStatuses.get(getTestEfdKey(test)) || []
1125
+ isFinalExecution = efdTestStatuses.length === getEfdRetryCountForTest(test) + 1
1126
+ } else if (test._ddIsAttemptToFix) {
1127
+ isFinalExecution = !!(test._ddHasPassedAttemptToFixRetries || test._ddHasFailedAttemptToFixRetries)
1128
+ } else {
1129
+ isFinalExecution = !testWillRetry(test, testStatus)
531
1130
  }
532
- remainingTestsByFile = getTestsBySuiteFromTestGroups(testGroups)
533
- return run.apply(this, arguments)
534
- }
1131
+
1132
+ const ddProperties = {
1133
+ _ddIsDisabled: test._ddIsDisabled,
1134
+ _ddIsQuarantined: test._ddIsQuarantined,
1135
+ _ddIsAttemptToFix: test._ddIsAttemptToFix,
1136
+ _ddIsAttemptToFixRetry: test._ddIsAttemptToFixRetry,
1137
+ _ddIsNew: test._ddIsNew,
1138
+ _ddIsEfdRetry: test._ddIsEfdRetry,
1139
+ _ddHasFailedAllRetries: test._ddHasFailedAllRetries,
1140
+ _ddHasPassedAttemptToFixRetries: test._ddHasPassedAttemptToFixRetries,
1141
+ _ddHasFailedAttemptToFixRetries: test._ddHasFailedAttemptToFixRetries,
1142
+ _ddIsAtrRetry: isAtrRetry,
1143
+ _ddIsModified: test._ddIsModified,
1144
+ _ddIsFinalExecution: isFinalExecution,
1145
+ _ddIsEfdManagedTest: isEfdManagedTest,
1146
+ _ddEarlyFlakeAbortReason: efdSlowAbortedTests.has(getTestEfdKey(test)) ? 'slow' : undefined,
1147
+ _ddHasPassedAnyEfdAttempt: (testsToTestStatuses.get(getTestEfdKey(test)) || []).includes('pass'),
1148
+ }
1149
+
1150
+ setDdPropertiesForTest(worker.process, test.id, ddProperties)
1151
+ })
1152
+
1153
+ return worker
535
1154
  }
536
1155
 
537
1156
  function dispatcherHook (dispatcherExport) {
538
1157
  shimmer.wrap(dispatcherExport.Dispatcher.prototype, 'run', dispatcherRunWrapper)
539
- shimmer.wrap(dispatcherExport.Dispatcher.prototype, '_createWorker', createWorker => function () {
1158
+ shimmer.wrap(dispatcherExport.Dispatcher.prototype, '_createWorker', createWorker => function (...args) {
540
1159
  const dispatcher = this
541
- const worker = createWorker.apply(this, arguments)
1160
+ const worker = createWorker.apply(this, args)
542
1161
  const projects = getProjectsFromDispatcher(dispatcher)
543
1162
  sessionProjects = projects
544
1163
 
@@ -569,7 +1188,6 @@ function dispatcherHook (dispatcherExport) {
569
1188
  )
570
1189
  }
571
1190
  })
572
-
573
1191
  return worker
574
1192
  })
575
1193
  return dispatcherExport
@@ -577,60 +1195,10 @@ function dispatcherHook (dispatcherExport) {
577
1195
 
578
1196
  function dispatcherHookNew (dispatcherExport, runWrapper) {
579
1197
  shimmer.wrap(dispatcherExport.Dispatcher.prototype, 'run', runWrapper)
580
- shimmer.wrap(dispatcherExport.Dispatcher.prototype, '_createWorker', createWorker => function () {
1198
+ shimmer.wrap(dispatcherExport.Dispatcher.prototype, '_createWorker', createWorker => function (...args) {
581
1199
  const dispatcher = this
582
- const worker = createWorker.apply(this, arguments)
583
- const projects = getProjectsFromDispatcher(dispatcher)
584
- sessionProjects = projects
585
-
586
- worker.on('testBegin', ({ testId }) => {
587
- const test = getTestByTestId(dispatcher, testId)
588
- const browser = getBrowserNameFromProjects(projects, test)
589
- const shouldCreateTestSpan = test.expectedStatus === 'skipped'
590
- testBeginHandler(test, browser, shouldCreateTestSpan)
591
- })
592
- worker.on('testEnd', ({ testId, status, errors, annotations }) => {
593
- const test = getTestByTestId(dispatcher, testId)
594
-
595
- const isTimeout = status === 'timedOut'
596
- const shouldCreateTestSpan = test.expectedStatus === 'skipped'
597
- testEndHandler(
598
- {
599
- test,
600
- annotations,
601
- testStatus: STATUS_TO_TEST_STATUS[status],
602
- error: errors && errors[0],
603
- isTimeout,
604
- shouldCreateTestSpan,
605
- projects,
606
- }
607
- )
608
- const testResult = test.results.at(-1)
609
- const isAtrRetry = testResult?.retry > 0 &&
610
- isFlakyTestRetriesEnabled &&
611
- !test._ddIsAttemptToFix &&
612
- !test._ddIsEfdRetry
613
- // We want to send the ddProperties to the worker
614
- worker.process.send({
615
- type: 'ddProperties',
616
- testId: test.id,
617
- properties: {
618
- _ddIsDisabled: test._ddIsDisabled,
619
- _ddIsQuarantined: test._ddIsQuarantined,
620
- _ddIsAttemptToFix: test._ddIsAttemptToFix,
621
- _ddIsAttemptToFixRetry: test._ddIsAttemptToFixRetry,
622
- _ddIsNew: test._ddIsNew,
623
- _ddIsEfdRetry: test._ddIsEfdRetry,
624
- _ddHasFailedAllRetries: test._ddHasFailedAllRetries,
625
- _ddHasPassedAttemptToFixRetries: test._ddHasPassedAttemptToFixRetries,
626
- _ddHasFailedAttemptToFixRetries: test._ddHasFailedAttemptToFixRetries,
627
- _ddIsAtrRetry: isAtrRetry,
628
- _ddIsModified: test._ddIsModified,
629
- },
630
- })
631
- })
632
-
633
- return worker
1200
+ const worker = createWorker.apply(this, args)
1201
+ return onDispatcherCreateWorker(dispatcher, worker)
634
1202
  })
635
1203
  return dispatcherExport
636
1204
  }
@@ -641,10 +1209,16 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
641
1209
  let onDone
642
1210
 
643
1211
  rootDir = getRootDir(this, config)
644
-
1212
+ const projects = getProjectsFromRunner(this, config)
1213
+ const isFailureScreenshotEnabled = isFailureScreenshotCaptureEnabled(projects)
645
1214
  const processArgv = process.argv.slice(2).join(' ')
646
1215
  const command = `playwright ${processArgv}`
647
- testSessionStartCh.publish({ command, frameworkVersion: playwrightVersion, rootDir })
1216
+ testSessionStartCh.publish({
1217
+ command,
1218
+ frameworkVersion: playwrightVersion,
1219
+ rootDir,
1220
+ isFailureScreenshotEnabled,
1221
+ })
648
1222
 
649
1223
  try {
650
1224
  const { err, libraryConfig } = await getChannelPromise(
@@ -655,6 +1229,7 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
655
1229
  isKnownTestsEnabled = libraryConfig.isKnownTestsEnabled
656
1230
  isEarlyFlakeDetectionEnabled = libraryConfig.isEarlyFlakeDetectionEnabled
657
1231
  earlyFlakeDetectionNumRetries = libraryConfig.earlyFlakeDetectionNumRetries
1232
+ earlyFlakeDetectionSlowTestRetries = libraryConfig.earlyFlakeDetectionSlowTestRetries ?? {}
658
1233
  earlyFlakeDetectionFaultyThreshold = libraryConfig.earlyFlakeDetectionFaultyThreshold
659
1234
  isFlakyTestRetriesEnabled = libraryConfig.isFlakyTestRetriesEnabled
660
1235
  flakyTestRetriesCount = libraryConfig.flakyTestRetriesCount
@@ -670,9 +1245,26 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
670
1245
  log.error('Playwright session start error', e)
671
1246
  }
672
1247
 
673
- if (isKnownTestsEnabled && satisfies(playwrightVersion, MINIMUM_SUPPORTED_VERSION_RANGE_EFD)) {
1248
+ testSessionConfigurationCh.publish({ isFailureScreenshotEnabled })
1249
+
1250
+ const isTestOptimizationSupported = satisfies(playwrightVersion, MINIMUM_SUPPORTED_VERSION_RANGE_EFD)
1251
+ const shouldGetKnownTests = isKnownTestsEnabled && isTestOptimizationSupported
1252
+ const shouldGetTestManagementTests = isTestManagementTestsEnabled && isTestOptimizationSupported
1253
+
1254
+ const {
1255
+ knownTestsResponse,
1256
+ testManagementTestsResponse,
1257
+ } = await getTestOptimizationRequestResults({
1258
+ isKnownTestsEnabled: shouldGetKnownTests,
1259
+ isTestManagementTestsEnabled: shouldGetTestManagementTests,
1260
+ getKnownTests: () => getChannelPromise(knownTestsCh),
1261
+ getTestManagementTests: () => getChannelPromise(testManagementTestsCh),
1262
+ })
1263
+
1264
+ if (shouldGetKnownTests) {
674
1265
  try {
675
- const { err, knownTests: receivedKnownTests } = await getChannelPromise(knownTestsCh)
1266
+ const { err, knownTests: receivedKnownTests } =
1267
+ knownTestsResponse || await getChannelPromise(knownTestsCh)
676
1268
  if (err) {
677
1269
  isEarlyFlakeDetectionEnabled = false
678
1270
  isKnownTestsEnabled = false
@@ -691,9 +1283,10 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
691
1283
  }
692
1284
  }
693
1285
 
694
- if (isTestManagementTestsEnabled && satisfies(playwrightVersion, MINIMUM_SUPPORTED_VERSION_RANGE_EFD)) {
1286
+ if (shouldGetTestManagementTests) {
695
1287
  try {
696
- const { err, testManagementTests: receivedTestManagementTests } = await getChannelPromise(testManagementTestsCh)
1288
+ const { err, testManagementTests: receivedTestManagementTests } =
1289
+ testManagementTestsResponse || await getChannelPromise(testManagementTestsCh)
697
1290
  if (err) {
698
1291
  isTestManagementTestsEnabled = false
699
1292
  } else {
@@ -705,7 +1298,7 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
705
1298
  }
706
1299
  }
707
1300
 
708
- if (isImpactedTestsEnabled && satisfies(playwrightVersion, MINIMUM_SUPPORTED_VERSION_RANGE_EFD)) {
1301
+ if (isImpactedTestsEnabled && isTestOptimizationSupported) {
709
1302
  try {
710
1303
  const { err, modifiedFiles: receivedModifiedFiles } = await getChannelPromise(modifiedFilesCh)
711
1304
  if (err) {
@@ -719,8 +1312,6 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
719
1312
  }
720
1313
  }
721
1314
 
722
- const projects = getProjectsFromRunner(this, config)
723
-
724
1315
  // ATR and `--retries` are now compatible with Test Management.
725
1316
  // Test Management tests have their retries set to 0 at the test level,
726
1317
  // preventing them from being retried by ATR or `--retries`.
@@ -743,15 +1334,16 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
743
1334
  // there were tests that did not go through `testBegin` or `testEnd`,
744
1335
  // because they were skipped
745
1336
  for (const test of tests) {
1337
+ const alreadyReported = testsReportedInGenerateSummary.has(test)
746
1338
  const browser = getBrowserNameFromProjects(projects, test)
747
- testBeginHandler(test, browser, true)
1339
+ testBeginHandler(test, browser, !alreadyReported)
748
1340
  testEndHandler({
749
1341
  test,
750
1342
  annotations: [],
751
1343
  testStatus: 'skip',
752
1344
  error: null,
753
1345
  isTimeout: false,
754
- shouldCreateTestSpan: true,
1346
+ shouldCreateTestSpan: !alreadyReported,
755
1347
  projects,
756
1348
  })
757
1349
  }
@@ -763,12 +1355,11 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
763
1355
 
764
1356
  if (isTestManagementTestsEnabled && sessionStatus === 'failed') {
765
1357
  let totalFailedTestCount = 0
766
- let totalAttemptToFixFailedTestCount = 0
767
1358
  let totalPureQuarantinedFailedTestCount = 0
768
1359
 
769
1360
  for (const [fqn, testStatuses] of testsToTestStatuses.entries()) {
770
1361
  // Only count as failed if the final status (after retries) is 'fail'
771
- const lastStatus = testStatuses[testStatuses.length - 1]
1362
+ const lastStatus = testStatuses.at(-1)
772
1363
  if (lastStatus === 'fail') {
773
1364
  totalFailedTestCount += 1
774
1365
  if (quarantinedButNotAttemptToFixFqns.has(fqn)) {
@@ -777,16 +1368,7 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
777
1368
  }
778
1369
  }
779
1370
 
780
- for (const test of quarantinedOrDisabledTestsAttemptToFix) {
781
- const testFqn = getTestFullyQualifiedName(test)
782
- const testStatuses = testsToTestStatuses.get(testFqn)
783
- // Only count as failed if the final status (after retries) is 'fail'
784
- if (testStatuses && testStatuses[testStatuses.length - 1] === 'fail') {
785
- totalAttemptToFixFailedTestCount += 1
786
- }
787
- }
788
-
789
- const totalIgnorableFailures = totalAttemptToFixFailedTestCount + totalPureQuarantinedFailedTestCount
1371
+ const totalIgnorableFailures = totalPureQuarantinedFailedTestCount
790
1372
 
791
1373
  if (totalFailedTestCount > 0 && totalFailedTestCount === totalIgnorableFailures) {
792
1374
  runAllTestsReturn = 'passed'
@@ -794,7 +1376,8 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
794
1376
  }
795
1377
  }
796
1378
 
797
- logDynamicNamesWarning(newTestsWithDynamicNames)
1379
+ logTestOptimizationSummary({ attemptToFixExecutions, newTestsWithDynamicNames })
1380
+ loggedAttemptToFixTests.clear()
798
1381
 
799
1382
  const flushWait = new Promise(resolve => {
800
1383
  onDone = resolve
@@ -811,6 +1394,17 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
811
1394
  startedSuites = []
812
1395
  remainingTestsByFile = {}
813
1396
  quarantinedButNotAttemptToFixFqns = new Set()
1397
+ testsReportedInGenerateSummary = new Set()
1398
+ efdManagedTestKeys.clear()
1399
+ efdRetryCountByTestKey.clear()
1400
+ efdRetryCountRequestsByTestKey.clear()
1401
+ efdRetryTestsById.clear()
1402
+ efdScheduledOriginalTestKeys.clear()
1403
+ efdStartedOriginalTestKeys.clear()
1404
+ efdSlowAbortedTests.clear()
1405
+ ddPropertiesByTestId.clear()
1406
+ ddPropertiesRequestsByTestId.clear()
1407
+ disabledTestIds.clear()
814
1408
 
815
1409
  // TODO: we can trick playwright into thinking the session passed by returning
816
1410
  // 'passed' here. We might be able to use this for both EFD and Test Management tests.
@@ -837,6 +1431,102 @@ function runnerHookNew (runnerExport, playwrightVersion) {
837
1431
  return runnerExport
838
1432
  }
839
1433
 
1434
+ function runnerIndexHook (runnerExport, playwrightVersion) {
1435
+ let wrappedTestRunner
1436
+ runnerExport = shimmer.wrap(runnerExport, 'testRunner', function (originalGetter) {
1437
+ return function () {
1438
+ if (!wrappedTestRunner) {
1439
+ wrappedTestRunner = runnerHookNew(originalGetter.call(this), playwrightVersion)
1440
+ }
1441
+ return wrappedTestRunner
1442
+ }
1443
+ })
1444
+
1445
+ const baseReporter = runnerExport.base?.TerminalReporter
1446
+ if (baseReporter) {
1447
+ shimmer.wrap(baseReporter.prototype, 'generateSummary', generateSummaryWrapper)
1448
+ }
1449
+
1450
+ return runnerExport
1451
+ }
1452
+
1453
+ function commonIndexHook (commonExport) {
1454
+ applyRepeatEachIndex = commonExport.suiteUtils?.applyRepeatEachIndex
1455
+
1456
+ let wrappedStartProcessRunner
1457
+ commonExport = shimmer.wrap(commonExport, 'startProcessRunner', function (originalGetter) {
1458
+ return function () {
1459
+ if (!wrappedStartProcessRunner) {
1460
+ const startProcessRunner = originalGetter.call(this)
1461
+ wrappedStartProcessRunner = function (create) {
1462
+ return startProcessRunner.call(this, function () {
1463
+ const processRunner = create.apply(this, arguments)
1464
+ instrumentWorkerMainMethods(processRunner)
1465
+ return processRunner
1466
+ })
1467
+ }
1468
+ }
1469
+ return wrappedStartProcessRunner
1470
+ }
1471
+ })
1472
+
1473
+ return commonExport
1474
+ }
1475
+
1476
+ dispatcherRunCh.subscribe({
1477
+ start (ctx) {
1478
+ prepareDispatcherRun(ctx.self, ctx.arguments)
1479
+ },
1480
+ })
1481
+
1482
+ dispatcherCreateWorkerCh.subscribe({
1483
+ end (ctx) {
1484
+ onDispatcherCreateWorker(ctx.self, ctx.result)
1485
+ },
1486
+ })
1487
+
1488
+ processHostStartRunnerCh.subscribe({
1489
+ start (ctx) {
1490
+ prepareProcessHostStartRunner(ctx.self)
1491
+ },
1492
+ asyncEnd (ctx) {
1493
+ finishProcessHostStartRunner(ctx.self)
1494
+ },
1495
+ })
1496
+
1497
+ createRootSuiteCh.subscribe({
1498
+ asyncEnd (ctx) {
1499
+ if (ctx.error) {
1500
+ return
1501
+ }
1502
+ processRootSuite(ctx.result || ctx.arguments?.[0])
1503
+ },
1504
+ })
1505
+
1506
+ pageGotoCh.subscribe({
1507
+ asyncEnd (ctx) {
1508
+ // The Page.goto rewriter waits for this so tests closing immediately after navigation still get RUM tags.
1509
+ ctx.asyncEndPromise = handlePageGoto(ctx.self)
1510
+ },
1511
+ })
1512
+
1513
+ /**
1514
+ * Records a path created by Playwright's automatic screenshot recorder.
1515
+ *
1516
+ * @param {object} ctx - Orchestrion context
1517
+ * @returns {void}
1518
+ */
1519
+ function recordAutomaticFailureScreenshotPath (ctx) {
1520
+ if (isFailureScreenshotUploadEnabled &&
1521
+ typeof ctx.result === 'string' &&
1522
+ PLAYWRIGHT_FAILURE_SCREENSHOT_PATH_RE.test(ctx.result)) {
1523
+ automaticFailureScreenshotPaths.add(ctx.result)
1524
+ }
1525
+ }
1526
+
1527
+ artifactsRecorderScreenshotPathCh.subscribe({ end: recordAutomaticFailureScreenshotPath })
1528
+ snapshotRecorderScreenshotPathCh.subscribe({ end: recordAutomaticFailureScreenshotPath })
1529
+
840
1530
  if (DD_MAJOR < 6) { // <1.38.0 is only supported up to version 5
841
1531
  addHook({
842
1532
  name: '@playwright/test',
@@ -869,28 +1559,40 @@ if (DD_MAJOR < 6) { // <1.38.0 is only supported up to version 5
869
1559
  }, runnerHook)
870
1560
  }
871
1561
 
1562
+ addHook({
1563
+ name: 'playwright',
1564
+ file: 'lib/runner/index.js',
1565
+ versions: ['>=1.60.0'],
1566
+ }, runnerIndexHook)
1567
+
1568
+ addHook({
1569
+ name: 'playwright',
1570
+ file: 'lib/common/index.js',
1571
+ versions: ['>=1.60.0'],
1572
+ }, commonIndexHook)
1573
+
872
1574
  addHook({
873
1575
  name: 'playwright',
874
1576
  file: 'lib/runner/runner.js',
875
- versions: ['>=1.38.0'],
1577
+ versions: ['>=1.38.0 <1.60.0'],
876
1578
  }, runnerHook)
877
1579
 
878
1580
  addHook({
879
1581
  name: 'playwright',
880
1582
  file: 'lib/runner/testRunner.js',
881
- versions: ['>=1.55.0'],
1583
+ versions: ['>=1.55.0 <1.60.0'],
882
1584
  }, runnerHookNew)
883
1585
 
884
1586
  addHook({
885
1587
  name: 'playwright',
886
1588
  file: 'lib/runner/dispatcher.js',
887
- versions: ['>=1.38.0'],
1589
+ versions: ['>=1.38.0 <1.60.0'],
888
1590
  }, (dispatcher) => dispatcherHookNew(dispatcher, dispatcherRunWrapperNew))
889
1591
 
890
1592
  addHook({
891
1593
  name: 'playwright',
892
1594
  file: 'lib/common/suiteUtils.js',
893
- versions: ['>=1.38.0'],
1595
+ versions: ['>=1.38.0 <1.60.0'],
894
1596
  }, suiteUtilsPackage => {
895
1597
  // We grab `applyRepeatEachIndex` to use it later
896
1598
  // `applyRepeatEachIndex` needs to be applied to a cloned suite
@@ -912,159 +1614,196 @@ addHook({
912
1614
  * - we execute `applyRepeatEachIndex` for each of these cloned file suites
913
1615
  * - we add the cloned file suites to the project suite
914
1616
  */
915
- function applyRetriesToTests (fileSuitesWithTestsToRetry, filterTest, tagsToApply, numRetries) {
1617
+ function applyRetriesToTests (
1618
+ fileSuitesWithTestsToRetry,
1619
+ filterTest,
1620
+ tagsToApply,
1621
+ numRetries,
1622
+ configureCopiedTest,
1623
+ getRetryRepeatEachIndex
1624
+ ) {
916
1625
  for (const [fileSuite, projectSuite] of fileSuitesWithTestsToRetry.entries()) {
917
1626
  for (let repeatEachIndex = 1; repeatEachIndex <= numRetries; repeatEachIndex++) {
918
- const copyFileSuite = deepCloneSuite(fileSuite, filterTest, tagsToApply)
919
- applyRepeatEachIndex(projectSuite._fullProject, copyFileSuite, repeatEachIndex + 1)
1627
+ const copyFileSuite = deepCloneSuite(fileSuite, filterTest, tagsToApply, (copiedTest, originalTest) => {
1628
+ if (configureCopiedTest) {
1629
+ configureCopiedTest(copiedTest, originalTest, repeatEachIndex)
1630
+ }
1631
+ })
1632
+ const retryRepeatEachIndex = getRetryRepeatEachIndex
1633
+ ? getRetryRepeatEachIndex(fileSuite, projectSuite, repeatEachIndex, numRetries)
1634
+ : repeatEachIndex + 1
1635
+ applyRepeatEachIndex(projectSuite._fullProject, copyFileSuite, retryRepeatEachIndex)
920
1636
  projectSuite._addSuite(copyFileSuite)
1637
+ for (const copiedTest of copyFileSuite.allTests()) {
1638
+ registerEfdRetryTest(copiedTest)
1639
+ }
921
1640
  }
922
1641
  }
923
1642
  }
924
1643
 
925
- addHook({
926
- name: 'playwright',
927
- file: 'lib/runner/loadUtils.js',
928
- versions: ['>=1.38.0'],
929
- }, (loadUtilsPackage) => {
930
- const oldCreateRootSuite = loadUtilsPackage.createRootSuite
1644
+ function processRootSuite (createRootSuiteReturnValue) {
1645
+ if (!isKnownTestsEnabled && !isTestManagementTestsEnabled && !isImpactedTestsEnabled) {
1646
+ return createRootSuiteReturnValue
1647
+ }
931
1648
 
932
- async function newCreateRootSuite () {
933
- if (!isKnownTestsEnabled && !isTestManagementTestsEnabled && !isImpactedTestsEnabled) {
934
- return oldCreateRootSuite.apply(this, arguments)
935
- }
1649
+ if (!createRootSuiteReturnValue) {
1650
+ return createRootSuiteReturnValue
1651
+ }
936
1652
 
937
- const createRootSuiteReturnValue = await oldCreateRootSuite.apply(this, arguments)
938
- // From v1.56.0 on, createRootSuite returns `{ rootSuite, topLevelProjects }`
939
- const rootSuite = createRootSuiteReturnValue.rootSuite || createRootSuiteReturnValue
940
-
941
- const allTests = rootSuite.allTests()
942
-
943
- if (isTestManagementTestsEnabled) {
944
- const fileSuitesWithManagedTestsToProjects = new Map()
945
- for (const test of allTests) {
946
- const testProperties = getTestProperties(test)
947
- // Disabled tests are skipped unless they have attemptToFix
948
- if (testProperties.disabled) {
949
- test._ddIsDisabled = true
950
- if (!testProperties.attemptToFix) {
951
- test.expectedStatus = 'skipped'
952
- // setting test.expectedStatus to 'skipped' does not work for every case,
953
- // so we need to filter out disabled tests in dispatcherRunWrapperNew,
954
- // so they don't get to the workers
955
- continue
956
- }
1653
+ // From v1.56.0 on, createRootSuite returns `{ rootSuite, topLevelProjects }`
1654
+ const rootSuite = createRootSuiteReturnValue.rootSuite || createRootSuiteReturnValue
1655
+ if (typeof rootSuite?.allTests !== 'function') {
1656
+ return createRootSuiteReturnValue
1657
+ }
1658
+
1659
+ const allTests = rootSuite.allTests()
1660
+
1661
+ if (isTestManagementTestsEnabled) {
1662
+ const fileSuitesWithManagedTestsToProjects = new Map()
1663
+ for (const test of allTests) {
1664
+ const testProperties = getTestProperties(test)
1665
+ // Disabled tests are skipped unless they have attemptToFix
1666
+ if (testProperties.disabled) {
1667
+ test._ddIsDisabled = true
1668
+ if (!testProperties.attemptToFix) {
1669
+ disabledTestIds.add(test.id)
1670
+ test.expectedStatus = 'skipped'
1671
+ // setting test.expectedStatus to 'skipped' does not work for every case,
1672
+ // so we need to filter out disabled tests in dispatcherRunWrapperNew,
1673
+ // so they don't get to the workers
1674
+ continue
957
1675
  }
958
- if (testProperties.quarantined) {
959
- test._ddIsQuarantined = true
960
- if (!testProperties.attemptToFix) {
961
- // Do not skip quarantined tests, let them run and overwrite results post-run if they fail
962
- const testFqn = getTestFullyQualifiedName(test)
963
- quarantinedButNotAttemptToFixFqns.add(testFqn)
964
- }
1676
+ }
1677
+ if (testProperties.quarantined) {
1678
+ test._ddIsQuarantined = true
1679
+ if (!testProperties.attemptToFix) {
1680
+ // Do not skip quarantined tests, let them run and overwrite results post-run if they fail
1681
+ const testFqn = getTestFullyQualifiedName(test)
1682
+ quarantinedButNotAttemptToFixFqns.add(testFqn)
965
1683
  }
966
- if (testProperties.attemptToFix) {
967
- test._ddIsAttemptToFix = true
968
- // Prevent ATR or `--retries` from retrying attemptToFix tests
969
- test.retries = 0
970
- const fileSuite = getSuiteType(test, 'file')
971
-
972
- if (!fileSuitesWithManagedTestsToProjects.has(fileSuite)) {
973
- fileSuitesWithManagedTestsToProjects.set(fileSuite, getSuiteType(test, 'project'))
974
- }
975
- if (testProperties.disabled || testProperties.quarantined) {
976
- quarantinedOrDisabledTestsAttemptToFix.push(test)
977
- }
1684
+ }
1685
+ if (testProperties.attemptToFix) {
1686
+ test._ddIsAttemptToFix = true
1687
+ // Prevent ATR or `--retries` from retrying attemptToFix tests
1688
+ test.retries = 0
1689
+ const fileSuite = getSuiteType(test, 'file')
1690
+
1691
+ if (!fileSuitesWithManagedTestsToProjects.has(fileSuite)) {
1692
+ fileSuitesWithManagedTestsToProjects.set(fileSuite, getSuiteType(test, 'project'))
978
1693
  }
979
1694
  }
980
- applyRetriesToTests(
981
- fileSuitesWithManagedTestsToProjects,
982
- (test) => test._ddIsAttemptToFix,
983
- [
984
- (test) => test._ddIsQuarantined && '_ddIsQuarantined',
985
- (test) => test._ddIsDisabled && '_ddIsDisabled',
986
- '_ddIsAttemptToFix',
987
- '_ddIsAttemptToFixRetry',
988
- ],
989
- testManagementAttemptToFixRetries
990
- )
991
1695
  }
1696
+ applyRetriesToTests(
1697
+ fileSuitesWithManagedTestsToProjects,
1698
+ (test) => test._ddIsAttemptToFix,
1699
+ [
1700
+ (test) => test._ddIsQuarantined && '_ddIsQuarantined',
1701
+ (test) => test._ddIsDisabled && '_ddIsDisabled',
1702
+ '_ddIsAttemptToFix',
1703
+ '_ddIsAttemptToFixRetry',
1704
+ ],
1705
+ testManagementAttemptToFixRetries
1706
+ )
1707
+ }
992
1708
 
993
- if (isImpactedTestsEnabled) {
994
- const impactedTests = allTests.filter(test => {
995
- let isImpacted = false
996
- isModifiedCh.publish({
997
- filePath: test._requireFile,
998
- modifiedFiles,
999
- onDone: (isModified) => { isImpacted = isModified },
1000
- })
1001
- return isImpacted
1709
+ if (isImpactedTestsEnabled) {
1710
+ const impactedTests = allTests.filter(test => {
1711
+ let isImpacted = false
1712
+ isModifiedCh.publish({
1713
+ filePath: test._requireFile,
1714
+ modifiedFiles,
1715
+ onDone: (isModified) => { isImpacted = isModified },
1002
1716
  })
1717
+ return isImpacted
1718
+ })
1003
1719
 
1004
- const fileSuitesWithImpactedTestsToProjects = new Map()
1005
- for (const impactedTest of impactedTests) {
1006
- impactedTest._ddIsModified = true
1007
- if (isEarlyFlakeDetectionEnabled && impactedTest.expectedStatus !== 'skipped') {
1008
- const fileSuite = getSuiteType(impactedTest, 'file')
1009
- if (!fileSuitesWithImpactedTestsToProjects.has(fileSuite)) {
1010
- fileSuitesWithImpactedTestsToProjects.set(fileSuite, getSuiteType(impactedTest, 'project'))
1011
- }
1720
+ const fileSuitesWithImpactedTestsToProjects = new Map()
1721
+ for (const impactedTest of impactedTests) {
1722
+ impactedTest._ddIsModified = true
1723
+ if (isEarlyFlakeDetectionEnabled && impactedTest.expectedStatus !== 'skipped') {
1724
+ markEfdManagedTest(impactedTest)
1725
+ const fileSuite = getSuiteType(impactedTest, 'file')
1726
+ if (!fileSuitesWithImpactedTestsToProjects.has(fileSuite)) {
1727
+ fileSuitesWithImpactedTestsToProjects.set(fileSuite, getSuiteType(impactedTest, 'project'))
1012
1728
  }
1013
1729
  }
1014
- // If something change in the file, all tests in the file are impacted, hence the () => true filter
1015
- applyRetriesToTests(
1016
- fileSuitesWithImpactedTestsToProjects,
1017
- () => true,
1018
- [
1019
- '_ddIsModified',
1020
- '_ddIsEfdRetry',
1021
- (test) => (isKnownTestsEnabled && isNewTest(test) ? '_ddIsNew' : null),
1022
- ],
1023
- earlyFlakeDetectionNumRetries
1024
- )
1025
1730
  }
1731
+ // If something change in the file, all tests in the file are impacted, hence the () => true filter
1732
+ applyRetriesToTests(
1733
+ fileSuitesWithImpactedTestsToProjects,
1734
+ () => true,
1735
+ [
1736
+ '_ddIsModified',
1737
+ '_ddIsEfdRetry',
1738
+ (test) => (isKnownTestsEnabled && isNewTest(test) ? '_ddIsNew' : null),
1739
+ ],
1740
+ getConfiguredEfdRetryCount(),
1741
+ (copiedTest, originalTest, retryIndex) => {
1742
+ markEfdRetryTest(copiedTest, retryIndex, originalTest)
1743
+ markEfdManagedTest(copiedTest)
1744
+ },
1745
+ getEfdRetryRepeatEachIndex
1746
+ )
1747
+ }
1026
1748
 
1027
- if (isKnownTestsEnabled) {
1028
- const newTests = allTests.filter(isNewTest)
1749
+ if (isKnownTestsEnabled) {
1750
+ const newTests = allTests.filter(isNewTest)
1029
1751
 
1030
- const isFaulty = getIsFaultyEarlyFlakeDetection(
1031
- allTests.map(test => getTestSuitePath(test._requireFile, rootDir)),
1032
- knownTests.playwright,
1033
- earlyFlakeDetectionFaultyThreshold
1034
- )
1752
+ const isFaulty = getIsFaultyEarlyFlakeDetection(
1753
+ allTests.map(test => getTestSuitePath(test._requireFile, rootDir)),
1754
+ knownTests.playwright,
1755
+ earlyFlakeDetectionFaultyThreshold
1756
+ )
1035
1757
 
1036
- if (isFaulty) {
1037
- isEarlyFlakeDetectionEnabled = false
1038
- isKnownTestsEnabled = false
1039
- isEarlyFlakeDetectionFaulty = true
1040
- } else {
1041
- const fileSuitesWithNewTestsToProjects = new Map()
1042
- for (const newTest of newTests) {
1043
- newTest._ddIsNew = true
1044
- if (isEarlyFlakeDetectionEnabled && newTest.expectedStatus !== 'skipped' && !newTest._ddIsModified) {
1045
- // Prevent ATR or `--retries` from retrying new tests if EFD is enabled
1046
- newTest.retries = 0
1047
- const fileSuite = getSuiteType(newTest, 'file')
1048
- if (!fileSuitesWithNewTestsToProjects.has(fileSuite)) {
1049
- fileSuitesWithNewTestsToProjects.set(fileSuite, getSuiteType(newTest, 'project'))
1050
- }
1758
+ if (isFaulty) {
1759
+ isEarlyFlakeDetectionEnabled = false
1760
+ isKnownTestsEnabled = false
1761
+ isEarlyFlakeDetectionFaulty = true
1762
+ } else {
1763
+ const fileSuitesWithNewTestsToProjects = new Map()
1764
+ for (const newTest of newTests) {
1765
+ newTest._ddIsNew = true
1766
+ if (isEarlyFlakeDetectionEnabled && newTest.expectedStatus !== 'skipped' && !newTest._ddIsModified) {
1767
+ // Prevent ATR or `--retries` from retrying new tests if EFD is enabled
1768
+ newTest.retries = 0
1769
+ markEfdManagedTest(newTest)
1770
+ const fileSuite = getSuiteType(newTest, 'file')
1771
+ if (!fileSuitesWithNewTestsToProjects.has(fileSuite)) {
1772
+ fileSuitesWithNewTestsToProjects.set(fileSuite, getSuiteType(newTest, 'project'))
1051
1773
  }
1052
1774
  }
1053
-
1054
- applyRetriesToTests(
1055
- fileSuitesWithNewTestsToProjects,
1056
- isNewTest,
1057
- ['_ddIsNew', '_ddIsEfdRetry'],
1058
- earlyFlakeDetectionNumRetries
1059
- )
1060
1775
  }
1776
+
1777
+ applyRetriesToTests(
1778
+ fileSuitesWithNewTestsToProjects,
1779
+ isNewTest,
1780
+ ['_ddIsNew', '_ddIsEfdRetry'],
1781
+ getConfiguredEfdRetryCount(),
1782
+ (copiedTest, originalTest, retryIndex) => {
1783
+ markEfdRetryTest(copiedTest, retryIndex, originalTest)
1784
+ markEfdManagedTest(copiedTest)
1785
+ },
1786
+ getEfdRetryRepeatEachIndex
1787
+ )
1061
1788
  }
1789
+ }
1062
1790
 
1063
- return createRootSuiteReturnValue
1791
+ return createRootSuiteReturnValue
1792
+ }
1793
+
1794
+ addHook({
1795
+ name: 'playwright',
1796
+ file: 'lib/runner/loadUtils.js',
1797
+ versions: ['>=1.38.0 <1.60.0'],
1798
+ }, (loadUtilsPackage) => {
1799
+ const oldCreateRootSuite = loadUtilsPackage.createRootSuite
1800
+
1801
+ async function newCreateRootSuite () {
1802
+ return processRootSuite(await oldCreateRootSuite.apply(this, arguments))
1064
1803
  }
1065
1804
 
1066
1805
  // We need to proxy the createRootSuite function because the function is not configurable
1067
- const proxy = new Proxy(loadUtilsPackage, {
1806
+ return new Proxy(loadUtilsPackage, {
1068
1807
  get (target, prop) {
1069
1808
  if (prop === 'createRootSuite') {
1070
1809
  return newCreateRootSuite
@@ -1072,32 +1811,52 @@ addHook({
1072
1811
  return target[prop]
1073
1812
  },
1074
1813
  })
1075
-
1076
- return proxy
1077
1814
  })
1078
1815
 
1816
+ function prepareProcessHostStartRunner (processHost) {
1817
+ processHost._extraEnv = {
1818
+ ...processHost._extraEnv,
1819
+ // Used to detect that we're in a playwright worker
1820
+ DD_PLAYWRIGHT_WORKER: '1',
1821
+ }
1822
+ }
1823
+
1824
+ function finishProcessHostStartRunner (processHost) {
1825
+ if (!processHost.process) {
1826
+ return
1827
+ }
1828
+
1829
+ // We add a new listener to `processHost.process`, which represents the worker
1830
+ processHost.process.on('message', (message) => {
1831
+ if (message?.type === EFD_RETRY_COUNT_REQUEST) {
1832
+ sendEfdRetryCountToWorkerWhenAvailable(processHost.process, message.testId)
1833
+ return
1834
+ }
1835
+ if (message?.type === DD_PROPERTIES_REQUEST) {
1836
+ sendDdPropertiesToWorkerWhenAvailable(processHost.process, message.testId)
1837
+ return
1838
+ }
1839
+ // These messages are [code, payload]. The payload is test data
1840
+ if (Array.isArray(message) && message[0] === PLAYWRIGHT_WORKER_TRACE_PAYLOAD_CODE) {
1841
+ workerReportCh.publish({
1842
+ serializedTraces: message[1],
1843
+ screenshots: processHost[kDdPlaywrightFailureScreenshots]?.shift(),
1844
+ })
1845
+ }
1846
+ })
1847
+ }
1848
+
1079
1849
  // main process hook
1080
1850
  addHook({
1081
1851
  name: 'playwright',
1082
1852
  file: 'lib/runner/processHost.js',
1083
- versions: ['>=1.38.0'],
1853
+ versions: ['>=1.38.0 <1.60.0'],
1084
1854
  }, (processHostPackage) => {
1085
1855
  shimmer.wrap(processHostPackage.ProcessHost.prototype, 'startRunner', startRunner => async function () {
1086
- this._extraEnv = {
1087
- ...this._extraEnv,
1088
- // Used to detect that we're in a playwright worker
1089
- DD_PLAYWRIGHT_WORKER: '1',
1090
- }
1856
+ prepareProcessHostStartRunner(this)
1091
1857
 
1092
1858
  const res = await startRunner.apply(this, arguments)
1093
-
1094
- // We add a new listener to `this.process`, which is represents the worker
1095
- this.process.on('message', (message) => {
1096
- // These messages are [code, payload]. The payload is test data
1097
- if (Array.isArray(message) && message[0] === PLAYWRIGHT_WORKER_TRACE_PAYLOAD_CODE) {
1098
- workerReportCh.publish(message[1])
1099
- }
1100
- })
1859
+ finishProcessHostStartRunner(this)
1101
1860
 
1102
1861
  return res
1103
1862
  })
@@ -1105,43 +1864,77 @@ addHook({
1105
1864
  return processHostPackage
1106
1865
  })
1107
1866
 
1867
+ async function handlePageGoto (page) {
1868
+ if (!testPageGotoCh.hasSubscribers || !page || typeof page.evaluate !== 'function') {
1869
+ return
1870
+ }
1871
+
1872
+ let rumState
1873
+ try {
1874
+ rumState = await page.evaluate(detectRum)
1875
+ } catch (error) {
1876
+ // Redirects and closed contexts can make page evaluation fail after a successful navigation.
1877
+ log.error('Playwright RUM detection error', error)
1878
+ return
1879
+ }
1880
+
1881
+ if (!rumState) {
1882
+ return
1883
+ }
1884
+
1885
+ const { isRumInstrumented, isRumActive, rumSamplingRate } = rumState
1886
+ if (isRumInstrumented && rumSamplingRate < 100 && !isRumActive) {
1887
+ log.debug("RUM was detected on the page, but it isn't active because the sampling rate is below 100%")
1888
+ }
1889
+ if (!isRumActive) {
1890
+ return
1891
+ }
1892
+
1893
+ let browserVersion
1894
+ try {
1895
+ browserVersion = page.context().browser()?.version()
1896
+ } catch (error) {
1897
+ log.error('Playwright browser metadata error', error)
1898
+ }
1899
+
1900
+ const context = {
1901
+ isRumActive,
1902
+ browserVersion,
1903
+ testExecutionId: undefined,
1904
+ }
1905
+ try {
1906
+ testPageGotoCh.publish(context)
1907
+ } catch (error) {
1908
+ log.error('Playwright RUM correlation channel error', error)
1909
+ return
1910
+ }
1911
+
1912
+ if (!context.testExecutionId) {
1913
+ return
1914
+ }
1915
+
1916
+ try {
1917
+ const domain = new URL(page.url()).hostname
1918
+ await page.context().addCookies([{
1919
+ name: RUM_COOKIE_NAME,
1920
+ value: context.testExecutionId,
1921
+ domain,
1922
+ path: '/',
1923
+ }])
1924
+ } catch (error) {
1925
+ log.error('Playwright RUM correlation cookie error', error)
1926
+ }
1927
+ }
1928
+
1108
1929
  addHook({
1109
1930
  name: 'playwright-core',
1110
1931
  file: 'lib/client/page.js',
1111
- versions: ['>=1.38.0'],
1932
+ versions: ['>=1.38.0 <1.60.0'],
1112
1933
  }, (pagePackage) => {
1113
1934
  shimmer.wrap(pagePackage.Page.prototype, 'goto', goto => async function (url, options) {
1114
1935
  const response = await goto.apply(this, arguments)
1115
1936
 
1116
- const page = this
1117
-
1118
- try {
1119
- if (page) {
1120
- const { isRumInstrumented, isRumActive, rumSamplingRate } = await page.evaluate(() => {
1121
- const isRumInstrumented = !!window.DD_RUM
1122
- const isRumActive = window.DD_RUM && window.DD_RUM.getInternalContext
1123
- ? !!window.DD_RUM.getInternalContext()
1124
- : false
1125
- const rumSamplingRate = window.DD_RUM && window.DD_RUM.getInitConfiguration
1126
- ? window.DD_RUM.getInitConfiguration().sessionSampleRate
1127
- : null
1128
- return { isRumInstrumented, isRumActive, rumSamplingRate }
1129
- })
1130
- if (isRumInstrumented && rumSamplingRate < 100 && !isRumActive) {
1131
- log.debug("RUM was detected on the page, but it isn't active because the sampling rate is below 100%")
1132
- }
1133
-
1134
- if (isRumActive) {
1135
- testPageGotoCh.publish({
1136
- isRumActive,
1137
- page,
1138
- })
1139
- }
1140
- }
1141
- } catch (e) {
1142
- // ignore errors such as redirects, context destroyed, etc
1143
- log.error('goto hook error', e)
1144
- }
1937
+ await handlePageGoto(this)
1145
1938
 
1146
1939
  return response
1147
1940
  })
@@ -1149,20 +1942,38 @@ addHook({
1149
1942
  return pagePackage
1150
1943
  })
1151
1944
 
1152
- // Only in worker
1153
- addHook({
1154
- name: 'playwright',
1155
- file: 'lib/worker/workerMain.js',
1156
- versions: ['>=1.38.0'],
1157
- }, (workerPackage) => {
1945
+ function instrumentWorkerMainMethods (workerMain) {
1946
+ if (!workerMain || workerMain[kDdPlaywrightWorkerInstrumented] ||
1947
+ typeof workerMain._runTest !== 'function' || typeof workerMain.dispatchEvent !== 'function') {
1948
+ return workerMain
1949
+ }
1950
+
1951
+ Object.defineProperty(workerMain, kDdPlaywrightWorkerInstrumented, { value: true })
1952
+
1158
1953
  // we assume there's only a test running at a time
1159
1954
  let steps = []
1160
1955
  const stepInfoByStepId = {}
1161
1956
 
1162
- shimmer.wrap(workerPackage.WorkerMain.prototype, '_runTest', _runTest => async function (test) {
1957
+ shimmer.wrap(workerMain, 'runTestGroup', runTestGroup => function (runPayload) {
1958
+ const disabledIds = runPayload._ddDisabledTestIds
1959
+ this[kDdPlaywrightDisabledTestIds] = disabledIds ? new Set(disabledIds) : undefined
1960
+ return runTestGroup.apply(this, arguments)
1961
+ })
1962
+
1963
+ shimmer.wrap(workerMain, '_runTest', _runTest => async function (test) {
1964
+ if (this[kDdPlaywrightDisabledTestIds]?.has(test.id)) {
1965
+ test._ddIsDisabled = true
1966
+ test.expectedStatus = 'skipped'
1967
+ }
1968
+ await waitForEfdRetryCount(test)
1969
+ if (shouldSkipEfdRetry(test)) {
1970
+ test._ddShouldSkipEfdRetry = true
1971
+ test.expectedStatus = 'skipped'
1972
+ }
1163
1973
  if (test.expectedStatus === 'skipped') {
1164
1974
  return _runTest.apply(this, arguments)
1165
1975
  }
1976
+ test._ddStartTime = performance.now()
1166
1977
  steps = []
1167
1978
 
1168
1979
  const {
@@ -1189,6 +2000,27 @@ addHook({
1189
2000
  browserName,
1190
2001
  }
1191
2002
  testToCtx.set(test, testCtx)
2003
+
2004
+ // Wait for ddProperties to be received and processed. The main process sends
2005
+ // this during Playwright's testEnd event, which can happen before _runTest
2006
+ // resolves in 1.60 when retry clones run across multiple workers.
2007
+ let hasDdProperties = false
2008
+ const ddPropertiesDeferred = {}
2009
+ const ddPropertiesPromise = new Promise(resolve => {
2010
+ ddPropertiesDeferred.resolve = resolve
2011
+ })
2012
+ const ddPropertiesMessageHandler = ({ type, testId, properties }) => {
2013
+ if (type === DD_PROPERTIES_RESPONSE && testId === test.id) {
2014
+ hasDdProperties = true
2015
+ if (properties) {
2016
+ Object.assign(test, properties)
2017
+ }
2018
+ process.removeListener('message', ddPropertiesMessageHandler)
2019
+ ddPropertiesDeferred.resolve()
2020
+ }
2021
+ }
2022
+ process.on('message', ddPropertiesMessageHandler)
2023
+
1192
2024
  // TODO - In the future we may need to implement a mechanism to send test properties
1193
2025
  // to the worker process before _runTest is called
1194
2026
  testStartCh.runStores(testCtx, () => {
@@ -1209,13 +2041,7 @@ addHook({
1209
2041
  fn: async function ({ page }) {
1210
2042
  try {
1211
2043
  if (page) {
1212
- const isRumActive = await page.evaluate(() => {
1213
- if (window.DD_RUM && window.DD_RUM.stopSession) {
1214
- window.DD_RUM.stopSession()
1215
- return true
1216
- }
1217
- return false
1218
- })
2044
+ const isRumActive = await page.evaluate(stopRumSession)
1219
2045
 
1220
2046
  if (isRumActive) {
1221
2047
  // Give some time RUM to flush data, similar to what we do in selenium
@@ -1224,10 +2050,11 @@ addHook({
1224
2050
  if (url) {
1225
2051
  const domain = new URL(url).hostname
1226
2052
  await page.context().addCookies([{
1227
- name: 'datadog-ci-visibility-test-execution-id',
2053
+ name: RUM_COOKIE_NAME,
1228
2054
  value: '',
1229
2055
  domain,
1230
2056
  path: '/',
2057
+ expires: 0,
1231
2058
  }])
1232
2059
  } else {
1233
2060
  log.error('RUM is active but page.url() is not available')
@@ -1251,6 +2078,31 @@ addHook({
1251
2078
  await res
1252
2079
 
1253
2080
  const { status, error, annotations, retry, testId } = testInfo
2081
+ const testEfdKey = getTestEfdKey(test)
2082
+ const isEfdManagedTest = isTestEfdManaged(test)
2083
+ if (isEfdManagedTest && !test._ddIsEfdRetry && !efdRetryCountByTestKey.has(testEfdKey)) {
2084
+ const duration = test.results?.at(-1)?.duration > 0
2085
+ ? test.results.at(-1).duration
2086
+ : performance.now() - test._ddStartTime
2087
+ const retryCount = getEfdRetryCount(
2088
+ duration,
2089
+ getTestEfdSlowTestRetries(test)
2090
+ )
2091
+ setEfdRetryCountForTest(test, retryCount)
2092
+ if (retryCount === 0) {
2093
+ efdSlowAbortedTests.add(testEfdKey)
2094
+ }
2095
+ }
2096
+
2097
+ if (!hasDdProperties && process.send) {
2098
+ process.send({
2099
+ type: DD_PROPERTIES_REQUEST,
2100
+ testId: test.id,
2101
+ })
2102
+ } else if (!hasDdProperties) {
2103
+ process.removeListener('message', ddPropertiesMessageHandler)
2104
+ ddPropertiesDeferred.resolve()
2105
+ }
1254
2106
 
1255
2107
  // testInfo.errors could be better than "error",
1256
2108
  // which will only include timeout error (even though the test failed because of a different error)
@@ -1266,26 +2118,30 @@ addHook({
1266
2118
  onDone = resolve
1267
2119
  })
1268
2120
 
1269
- // Wait for ddProperties to be received and processed
1270
- // Create a promise that will be resolved when the properties are received
1271
- const ddPropertiesPromise = new Promise(resolve => {
1272
- const messageHandler = ({ type, testId, properties }) => {
1273
- if (type === 'ddProperties' && testId === test.id) {
1274
- // Apply the properties to the test object
1275
- if (properties) {
1276
- Object.assign(test, properties)
1277
- }
1278
- process.removeListener('message', messageHandler)
1279
- resolve()
1280
- }
1281
- }
1282
-
1283
- // Add the listener
1284
- process.on('message', messageHandler)
2121
+ // Wait for the properties to be received, but do not block the worker forever if IPC fails.
2122
+ const ddPropertiesTimeoutPromise = new Promise(resolve => {
2123
+ const ddPropertiesTimeout = realSetTimeout(() => {
2124
+ process.removeListener('message', ddPropertiesMessageHandler)
2125
+ resolve()
2126
+ }, DD_PROPERTIES_TIMEOUT)
2127
+ ddPropertiesPromise.then(() => {
2128
+ realClearTimeout(ddPropertiesTimeout)
2129
+ })
1285
2130
  })
2131
+ await Promise.race([ddPropertiesPromise, ddPropertiesTimeoutPromise])
1286
2132
 
1287
- // Wait for the properties to be received
1288
- await ddPropertiesPromise
2133
+ const finalStatus = getFinalStatus({
2134
+ isFinalExecution: test._ddIsFinalExecution,
2135
+ isDisabled: test._ddIsDisabled,
2136
+ isQuarantined: test._ddIsQuarantined,
2137
+ isAtrRetry: test._ddIsAtrRetry,
2138
+ isEfdManagedTest: test._ddIsEfdManagedTest,
2139
+ isAttemptToFix: test._ddIsAttemptToFix,
2140
+ hasFailedAllRetries: test._ddHasFailedAllRetries,
2141
+ hasFailedAttemptToFixRetries: test._ddHasFailedAttemptToFixRetries,
2142
+ hasPassedAnyEfdAttempt: test._ddHasPassedAnyEfdAttempt,
2143
+ testStatus: STATUS_TO_TEST_STATUS[status],
2144
+ })
1289
2145
 
1290
2146
  testFinishCh.publish({
1291
2147
  testStatus: STATUS_TO_TEST_STATUS[status],
@@ -1306,6 +2162,8 @@ addHook({
1306
2162
  isAtrRetry: test._ddIsAtrRetry,
1307
2163
  isModified: test._ddIsModified,
1308
2164
  onDone,
2165
+ finalStatus,
2166
+ earlyFlakeAbortReason: test._ddEarlyFlakeAbortReason,
1309
2167
  ...testCtx.currentStore,
1310
2168
  })
1311
2169
 
@@ -1316,8 +2174,10 @@ addHook({
1316
2174
 
1317
2175
  // We reproduce what happens in `Dispatcher#_onStepBegin` and `Dispatcher#_onStepEnd`,
1318
2176
  // since `startTime` and `duration` are not available directly in the worker process
1319
- shimmer.wrap(workerPackage.WorkerMain.prototype, 'dispatchEvent', dispatchEvent => function (event, payload) {
1320
- if (event === 'stepBegin') {
2177
+ shimmer.wrap(workerMain, 'dispatchEvent', dispatchEvent => function (event, payload) {
2178
+ if (event === 'testBegin' || event === 'testEnd') {
2179
+ automaticFailureScreenshotPaths.clear()
2180
+ } else if (event === 'stepBegin') {
1321
2181
  stepInfoByStepId[payload.stepId] = {
1322
2182
  startTime: payload.wallTime,
1323
2183
  title: payload.title,
@@ -1333,20 +2193,33 @@ addHook({
1333
2193
  duration: payload.wallTime - stepInfo.startTime,
1334
2194
  error: payload.error,
1335
2195
  })
2196
+ } else if (event === 'attach' && isAutomaticFailureScreenshotAttachment(payload)) {
2197
+ payload._ddIsAutomaticFailureScreenshot = true
1336
2198
  }
1337
2199
  return dispatchEvent.apply(this, arguments)
1338
2200
  })
1339
2201
 
2202
+ return workerMain
2203
+ }
2204
+
2205
+ // Only in worker
2206
+ addHook({
2207
+ name: 'playwright',
2208
+ file: 'lib/worker/workerMain.js',
2209
+ versions: ['>=1.38.0 <1.60.0'],
2210
+ }, (workerPackage) => {
2211
+ instrumentWorkerMainMethods(workerPackage.WorkerMain.prototype)
1340
2212
  return workerPackage
1341
2213
  })
1342
2214
 
1343
2215
  function generateSummaryWrapper (generateSummary) {
1344
- return function () {
2216
+ return function (...args) {
1345
2217
  for (const test of this.suite.allTests()) {
1346
2218
  // https://github.com/microsoft/playwright/blob/bf92ffecff6f30a292b53430dbaee0207e0c61ad/packages/playwright/src/reporters/base.ts#L279
1347
- const didNotRun = test.outcome() === 'skipped' &&
1348
- (!test.results.length || test.expectedStatus !== 'skipped')
1349
- if (didNotRun) {
2219
+ const shouldReportAsSkipped = test.outcome() === 'skipped' &&
2220
+ (disabledTestIds.has(test.id) || !test.results.length || test.expectedStatus !== 'skipped')
2221
+ if (shouldReportAsSkipped && !testsReportedInGenerateSummary.has(test)) {
2222
+ testsReportedInGenerateSummary.add(test)
1350
2223
  const {
1351
2224
  _requireFile: testSuiteAbsolutePath,
1352
2225
  location: {
@@ -1373,7 +2246,7 @@ function generateSummaryWrapper (generateSummary) {
1373
2246
  })
1374
2247
  }
1375
2248
  }
1376
- return generateSummary.apply(this, arguments)
2249
+ return generateSummary.apply(this, args)
1377
2250
  }
1378
2251
  }
1379
2252
 
@@ -1384,7 +2257,7 @@ function generateSummaryWrapper (generateSummary) {
1384
2257
  addHook({
1385
2258
  name: 'playwright',
1386
2259
  file: 'lib/reporters/base.js',
1387
- versions: ['>=1.38.0'],
2260
+ versions: ['>=1.38.0 <1.60.0'],
1388
2261
  }, (reportersPackage) => {
1389
2262
  // v1.50.0 changed the name of the base reporter from BaseReporter to TerminalReporter
1390
2263
  if (reportersPackage.TerminalReporter) {