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