@depup/dd-trace 5.96.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 (646) 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 +349 -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 +121 -79
  13. package/packages/datadog-core/src/storage.js +47 -48
  14. package/packages/datadog-esbuild/index.js +52 -10
  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 +22 -32
  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 +50 -6
  40. package/packages/datadog-instrumentations/src/cucumber-worker-threads.js +19 -0
  41. package/packages/datadog-instrumentations/src/cucumber.js +751 -188
  42. package/packages/datadog-instrumentations/src/cypress-config.js +432 -0
  43. package/packages/datadog-instrumentations/src/cypress.js +88 -4
  44. package/packages/datadog-instrumentations/src/dns.js +61 -61
  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 +56 -34
  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 +47 -47
  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/bundler-register.js +41 -13
  61. package/packages/datadog-instrumentations/src/helpers/callback-instrumentor.js +74 -0
  62. package/packages/datadog-instrumentations/src/helpers/check-require-cache.js +85 -9
  63. package/packages/datadog-instrumentations/src/helpers/hook.js +34 -6
  64. package/packages/datadog-instrumentations/src/helpers/hooks.js +24 -19
  65. package/packages/datadog-instrumentations/src/helpers/instrument.js +61 -14
  66. package/packages/datadog-instrumentations/src/helpers/kafka.js +58 -0
  67. package/packages/datadog-instrumentations/src/helpers/optional-peer-bundler.js +65 -0
  68. package/packages/datadog-instrumentations/src/helpers/promise-instrumentor.js +42 -0
  69. package/packages/datadog-instrumentations/src/helpers/promise.js +2 -2
  70. package/packages/datadog-instrumentations/src/helpers/register.js +109 -146
  71. package/packages/datadog-instrumentations/src/helpers/require-optional-peer.js +17 -0
  72. package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +13 -5
  73. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +24 -7
  74. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +6 -6
  75. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/aws-durable-execution-sdk-js.js +31 -0
  76. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/azure-cosmos.js +50 -0
  77. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/claude-agent-sdk.js +17 -0
  78. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +201 -0
  79. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +7 -0
  80. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/langgraph.js +4 -2
  81. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/mercurius.js +31 -0
  82. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-sdk.js +35 -0
  83. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +85 -0
  84. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +18 -2
  85. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +49 -224
  86. package/packages/datadog-instrumentations/src/helpers/router-helper.js +8 -8
  87. package/packages/datadog-instrumentations/src/hono.js +71 -9
  88. package/packages/datadog-instrumentations/src/http/client.js +50 -27
  89. package/packages/datadog-instrumentations/src/http/server.js +77 -34
  90. package/packages/datadog-instrumentations/src/http2/client.js +16 -15
  91. package/packages/datadog-instrumentations/src/http2/server.js +156 -25
  92. package/packages/datadog-instrumentations/src/ioredis.js +17 -14
  93. package/packages/datadog-instrumentations/src/iovalkey.js +1 -2
  94. package/packages/datadog-instrumentations/src/jest/bail-reporter.js +42 -0
  95. package/packages/datadog-instrumentations/src/jest/coverage-backfill.js +163 -0
  96. package/packages/datadog-instrumentations/src/jest.js +1795 -404
  97. package/packages/datadog-instrumentations/src/kafkajs.js +284 -170
  98. package/packages/datadog-instrumentations/src/knex.js +17 -17
  99. package/packages/datadog-instrumentations/src/koa.js +15 -14
  100. package/packages/datadog-instrumentations/src/ldapjs.js +5 -5
  101. package/packages/datadog-instrumentations/src/light-my-request.js +2 -2
  102. package/packages/datadog-instrumentations/src/limitd-client.js +5 -5
  103. package/packages/datadog-instrumentations/src/lodash.js +4 -4
  104. package/packages/datadog-instrumentations/src/mariadb.js +18 -16
  105. package/packages/datadog-instrumentations/src/memcached.js +4 -3
  106. package/packages/datadog-instrumentations/src/mercurius.js +11 -0
  107. package/packages/datadog-instrumentations/src/microgateway-core.js +2 -2
  108. package/packages/datadog-instrumentations/src/mocha/common.js +7 -4
  109. package/packages/datadog-instrumentations/src/mocha/main.js +557 -118
  110. package/packages/datadog-instrumentations/src/mocha/utils.js +531 -128
  111. package/packages/datadog-instrumentations/src/mocha/worker.js +27 -9
  112. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +254 -0
  113. package/packages/datadog-instrumentations/src/mongodb-core.js +43 -31
  114. package/packages/datadog-instrumentations/src/mongodb.js +79 -5
  115. package/packages/datadog-instrumentations/src/mongoose.js +43 -34
  116. package/packages/datadog-instrumentations/src/mquery.js +5 -5
  117. package/packages/datadog-instrumentations/src/multer.js +5 -4
  118. package/packages/datadog-instrumentations/src/mysql.js +17 -17
  119. package/packages/datadog-instrumentations/src/mysql2.js +39 -5
  120. package/packages/datadog-instrumentations/src/nats.js +182 -0
  121. package/packages/datadog-instrumentations/src/net.js +21 -19
  122. package/packages/datadog-instrumentations/src/next.js +44 -10
  123. package/packages/datadog-instrumentations/src/nyc.js +43 -6
  124. package/packages/datadog-instrumentations/src/openai.js +124 -38
  125. package/packages/datadog-instrumentations/src/oracledb.js +12 -7
  126. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +27 -6
  127. package/packages/datadog-instrumentations/src/passport-utils.js +5 -5
  128. package/packages/datadog-instrumentations/src/path-to-regexp.js +44 -0
  129. package/packages/datadog-instrumentations/src/pg.js +58 -25
  130. package/packages/datadog-instrumentations/src/pino.js +26 -42
  131. package/packages/datadog-instrumentations/src/playwright-browser-scripts.js +27 -0
  132. package/packages/datadog-instrumentations/src/playwright.js +1090 -351
  133. package/packages/datadog-instrumentations/src/prisma.js +1 -2
  134. package/packages/datadog-instrumentations/src/protobufjs.js +16 -16
  135. package/packages/datadog-instrumentations/src/redis.js +28 -15
  136. package/packages/datadog-instrumentations/src/restify.js +6 -5
  137. package/packages/datadog-instrumentations/src/router.js +243 -87
  138. package/packages/datadog-instrumentations/src/selenium.js +5 -3
  139. package/packages/datadog-instrumentations/src/sequelize.js +1 -1
  140. package/packages/datadog-instrumentations/src/stripe.js +47 -33
  141. package/packages/datadog-instrumentations/src/tedious.js +28 -0
  142. package/packages/datadog-instrumentations/src/url.js +1 -3
  143. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1297 -0
  144. package/packages/datadog-instrumentations/src/vitest-main.js +1592 -0
  145. package/packages/datadog-instrumentations/src/vitest-util.js +251 -0
  146. package/packages/datadog-instrumentations/src/vitest-worker.js +822 -0
  147. package/packages/datadog-instrumentations/src/vitest.js +11 -1258
  148. package/packages/datadog-instrumentations/src/vm.js +1 -3
  149. package/packages/datadog-instrumentations/src/winston.js +4 -4
  150. package/packages/datadog-instrumentations/src/ws.js +7 -7
  151. package/packages/datadog-instrumentations/src/zlib.js +29 -0
  152. package/packages/datadog-plugin-ai/src/index.js +1 -1
  153. package/packages/datadog-plugin-ai/src/tracing.js +66 -3
  154. package/packages/datadog-plugin-ai/src/utils.js +17 -4
  155. package/packages/datadog-plugin-apollo/src/gateway/request.js +1 -21
  156. package/packages/datadog-plugin-avsc/src/schema_iterator.js +3 -3
  157. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/checkpoint.js +31 -0
  158. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/client.js +55 -0
  159. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/context.js +123 -0
  160. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/handler.js +129 -0
  161. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/index.js +19 -0
  162. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/trace-checkpoint.js +224 -0
  163. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +79 -0
  164. package/packages/datadog-plugin-aws-sdk/src/base.js +90 -53
  165. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +1 -1
  166. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +218 -4
  167. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +1 -1
  168. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +2 -1
  169. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +59 -14
  170. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +174 -75
  171. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +34 -23
  172. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +2 -1
  173. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +1 -1
  174. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +26 -26
  175. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +187 -101
  176. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +20 -18
  177. package/packages/datadog-plugin-azure-cosmos/src/index.js +144 -0
  178. package/packages/datadog-plugin-azure-event-hubs/src/producer.js +8 -15
  179. package/packages/datadog-plugin-azure-functions/src/index.js +7 -3
  180. package/packages/datadog-plugin-azure-service-bus/src/producer.js +5 -10
  181. package/packages/datadog-plugin-bullmq/src/consumer.js +5 -4
  182. package/packages/datadog-plugin-bullmq/src/filter.js +35 -0
  183. package/packages/datadog-plugin-bullmq/src/producer.js +121 -33
  184. package/packages/datadog-plugin-bunyan/src/index.js +28 -0
  185. package/packages/datadog-plugin-child_process/src/index.js +13 -2
  186. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +6 -6
  187. package/packages/datadog-plugin-claude-agent-sdk/src/index.js +31 -0
  188. package/packages/datadog-plugin-claude-agent-sdk/src/tracing.js +107 -0
  189. package/packages/datadog-plugin-claude-agent-sdk/src/util.js +15 -0
  190. package/packages/datadog-plugin-couchbase/src/index.js +58 -52
  191. package/packages/datadog-plugin-cucumber/src/index.js +46 -24
  192. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +1018 -97
  193. package/packages/datadog-plugin-cypress/src/index.js +104 -2
  194. package/packages/datadog-plugin-cypress/src/plugin.js +6 -14
  195. package/packages/datadog-plugin-cypress/src/source-map-utils.js +48 -1
  196. package/packages/datadog-plugin-cypress/src/support.js +180 -25
  197. package/packages/datadog-plugin-dd-trace-api/src/index.js +1 -1
  198. package/packages/datadog-plugin-dns/src/lookup.js +8 -6
  199. package/packages/datadog-plugin-elasticsearch/src/index.js +28 -8
  200. package/packages/datadog-plugin-electron/src/index.js +17 -0
  201. package/packages/datadog-plugin-electron/src/ipc.js +143 -0
  202. package/packages/datadog-plugin-electron/src/net.js +82 -0
  203. package/packages/datadog-plugin-express/src/code_origin.js +1 -1
  204. package/packages/datadog-plugin-fastify/src/code_origin.js +1 -1
  205. package/packages/datadog-plugin-fs/src/index.js +2 -1
  206. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -5
  207. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +27 -18
  208. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +5 -8
  209. package/packages/datadog-plugin-graphql/src/execute.js +706 -34
  210. package/packages/datadog-plugin-graphql/src/index.js +43 -9
  211. package/packages/datadog-plugin-graphql/src/parse.js +45 -4
  212. package/packages/datadog-plugin-graphql/src/request.js +135 -0
  213. package/packages/datadog-plugin-graphql/src/tools/signature.js +32 -7
  214. package/packages/datadog-plugin-graphql/src/tools/transforms.js +118 -100
  215. package/packages/datadog-plugin-graphql/src/utils.js +261 -3
  216. package/packages/datadog-plugin-graphql/src/validate.js +53 -7
  217. package/packages/datadog-plugin-grpc/src/client.js +7 -8
  218. package/packages/datadog-plugin-grpc/src/server.js +1 -1
  219. package/packages/datadog-plugin-grpc/src/util.js +57 -22
  220. package/packages/datadog-plugin-http/src/client.js +12 -14
  221. package/packages/datadog-plugin-http/src/index.js +6 -8
  222. package/packages/datadog-plugin-http/src/server.js +63 -20
  223. package/packages/datadog-plugin-http2/src/client.js +6 -3
  224. package/packages/datadog-plugin-http2/src/server.js +48 -8
  225. package/packages/datadog-plugin-jest/src/index.js +136 -68
  226. package/packages/datadog-plugin-jest/src/util.js +37 -16
  227. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +31 -4
  228. package/packages/datadog-plugin-kafkajs/src/consumer.js +2 -9
  229. package/packages/datadog-plugin-kafkajs/src/producer.js +37 -8
  230. package/packages/datadog-plugin-langgraph/src/stream.js +1 -1
  231. package/packages/datadog-plugin-memcached/src/index.js +1 -1
  232. package/packages/datadog-plugin-mocha/src/index.js +66 -17
  233. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/index.js +24 -0
  234. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +173 -0
  235. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +30 -0
  236. package/packages/datadog-plugin-mongodb-core/src/bulk-write.js +43 -0
  237. package/packages/datadog-plugin-mongodb-core/src/index.js +8 -206
  238. package/packages/datadog-plugin-mongodb-core/src/query.js +452 -0
  239. package/packages/datadog-plugin-mysql/src/index.js +9 -4
  240. package/packages/datadog-plugin-nats/src/consumer.js +43 -0
  241. package/packages/datadog-plugin-nats/src/index.js +20 -0
  242. package/packages/datadog-plugin-nats/src/producer.js +62 -0
  243. package/packages/datadog-plugin-nats/src/util.js +33 -0
  244. package/packages/datadog-plugin-next/src/index.js +14 -18
  245. package/packages/datadog-plugin-openai/src/services.js +5 -3
  246. package/packages/datadog-plugin-openai/src/tracing.js +27 -25
  247. package/packages/datadog-plugin-oracledb/src/index.js +13 -2
  248. package/packages/datadog-plugin-pg/src/index.js +13 -3
  249. package/packages/datadog-plugin-pino/src/index.js +42 -0
  250. package/packages/datadog-plugin-playwright/src/index.js +21 -11
  251. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +3 -3
  252. package/packages/datadog-plugin-redis/src/index.js +54 -25
  253. package/packages/datadog-plugin-rhea/src/producer.js +1 -1
  254. package/packages/datadog-plugin-router/src/index.js +46 -44
  255. package/packages/datadog-plugin-selenium/src/index.js +1 -1
  256. package/packages/datadog-plugin-tedious/src/index.js +1 -1
  257. package/packages/datadog-plugin-undici/src/index.js +24 -2
  258. package/packages/datadog-plugin-vitest/src/index.js +160 -90
  259. package/packages/datadog-plugin-winston/src/index.js +30 -0
  260. package/packages/datadog-plugin-ws/src/close.js +3 -1
  261. package/packages/datadog-plugin-ws/src/producer.js +2 -0
  262. package/packages/datadog-plugin-ws/src/receiver.js +2 -1
  263. package/packages/datadog-shimmer/src/shimmer.js +101 -39
  264. package/packages/datadog-webpack/index.js +20 -4
  265. package/packages/datadog-webpack/src/optional-peer-loader.js +17 -0
  266. package/packages/dd-trace/index.electron.js +3 -0
  267. package/packages/dd-trace/index.js +2 -34
  268. package/packages/dd-trace/src/aiguard/channels.js +7 -0
  269. package/packages/dd-trace/src/aiguard/index.js +16 -34
  270. package/packages/dd-trace/src/aiguard/integrations/evaluate.js +46 -0
  271. package/packages/dd-trace/src/aiguard/integrations/index.js +34 -0
  272. package/packages/dd-trace/src/aiguard/integrations/openai.js +80 -0
  273. package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +92 -0
  274. package/packages/dd-trace/src/aiguard/messages/openai.js +382 -0
  275. package/packages/{datadog-instrumentations/src/helpers/ai-messages.js → dd-trace/src/aiguard/messages/vercel-ai.js} +30 -27
  276. package/packages/dd-trace/src/aiguard/sdk.js +151 -54
  277. package/packages/dd-trace/src/aiguard/tags.js +26 -10
  278. package/packages/dd-trace/src/appsec/api_security/index.js +55 -0
  279. package/packages/dd-trace/src/appsec/api_security/sampler.js +147 -0
  280. package/packages/dd-trace/src/appsec/blocked_templates.js +4 -3
  281. package/packages/dd-trace/src/appsec/blocking.js +84 -41
  282. package/packages/dd-trace/src/appsec/channels.js +5 -1
  283. package/packages/dd-trace/src/appsec/downstream_requests.js +116 -62
  284. package/packages/dd-trace/src/appsec/graphql.js +20 -17
  285. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +1 -1
  286. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +81 -81
  287. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +23 -23
  288. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +1 -1
  289. package/packages/dd-trace/src/appsec/iast/index.js +3 -2
  290. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +4 -4
  291. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +2 -2
  292. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +4 -4
  293. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -2
  294. package/packages/dd-trace/src/appsec/iast/telemetry/index.js +2 -1
  295. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +54 -12
  296. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +5 -1
  297. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +32 -5
  298. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +1 -3
  299. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +84 -49
  300. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +1 -1
  301. package/packages/dd-trace/src/appsec/index.js +65 -47
  302. package/packages/dd-trace/src/appsec/lambda.js +135 -0
  303. package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -5
  304. package/packages/dd-trace/src/appsec/rasp/lfi.js +8 -4
  305. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +5 -10
  306. package/packages/dd-trace/src/appsec/rasp/ssrf.js +26 -18
  307. package/packages/dd-trace/src/appsec/recommended.json +2438 -13
  308. package/packages/dd-trace/src/appsec/remote_config.js +1 -0
  309. package/packages/dd-trace/src/appsec/reporter.js +87 -28
  310. package/packages/dd-trace/src/appsec/rule_manager.js +4 -2
  311. package/packages/dd-trace/src/appsec/sdk/index.js +4 -0
  312. package/packages/dd-trace/src/appsec/sdk/set_user.js +1 -1
  313. package/packages/dd-trace/src/appsec/sdk/track_event.js +5 -5
  314. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +7 -11
  315. package/packages/dd-trace/src/appsec/sdk/utils.js +5 -3
  316. package/packages/dd-trace/src/appsec/store.js +50 -0
  317. package/packages/dd-trace/src/appsec/telemetry/api_security.js +34 -0
  318. package/packages/dd-trace/src/appsec/telemetry/index.js +27 -1
  319. package/packages/dd-trace/src/appsec/user_tracking.js +5 -4
  320. package/packages/dd-trace/src/appsec/waf/index.js +19 -9
  321. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +35 -20
  322. package/packages/dd-trace/src/appsec/waf/waf_manager.js +1 -1
  323. package/packages/dd-trace/src/azure_metadata.js +17 -6
  324. package/packages/dd-trace/src/baggage.js +32 -13
  325. package/packages/dd-trace/src/bootstrap.js +39 -0
  326. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +36 -6
  327. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +122 -24
  328. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +22 -7
  329. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +5 -2
  330. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +2 -2
  331. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +2 -2
  332. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +6 -2
  333. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -2
  334. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +148 -25
  335. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +3 -4
  336. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +28 -10
  337. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +22 -0
  338. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +105 -22
  339. package/packages/dd-trace/src/ci-visibility/lage.js +2 -1
  340. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +4 -5
  341. package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +4 -5
  342. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +73 -55
  343. package/packages/dd-trace/src/ci-visibility/requests/request.js +14 -50
  344. package/packages/dd-trace/src/ci-visibility/requests/upload-coverage-report.js +4 -4
  345. package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +156 -0
  346. package/packages/dd-trace/src/ci-visibility/test-api-manual/test-api-manual-plugin.js +9 -3
  347. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +24 -6
  348. package/packages/dd-trace/src/ci-visibility/test-optimization-cache.js +70 -6
  349. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +128 -0
  350. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +291 -0
  351. package/packages/dd-trace/src/config/config-types.d.ts +8 -6
  352. package/packages/dd-trace/src/config/defaults.js +341 -144
  353. package/packages/dd-trace/src/config/generated-config-types.d.ts +679 -131
  354. package/packages/dd-trace/src/config/git_properties.js +2 -2
  355. package/packages/dd-trace/src/config/helper.js +183 -28
  356. package/packages/dd-trace/src/config/index.js +565 -1515
  357. package/packages/dd-trace/src/config/major-overrides.js +100 -0
  358. package/packages/dd-trace/src/config/normalize-service.js +31 -0
  359. package/packages/dd-trace/src/config/parsers.js +384 -0
  360. package/packages/dd-trace/src/config/remote_config.js +59 -2
  361. package/packages/dd-trace/src/config/supported-configurations.json +638 -530
  362. package/packages/dd-trace/src/constants.js +15 -0
  363. package/packages/dd-trace/src/crashtracking/crashtracker.js +25 -7
  364. package/packages/dd-trace/src/crashtracking/index.js +1 -7
  365. package/packages/dd-trace/src/datastreams/checkpointer.js +6 -12
  366. package/packages/dd-trace/src/datastreams/context.js +4 -2
  367. package/packages/dd-trace/src/datastreams/encoding.js +39 -28
  368. package/packages/dd-trace/src/datastreams/index.js +2 -1
  369. package/packages/dd-trace/src/datastreams/manager.js +1 -1
  370. package/packages/dd-trace/src/datastreams/pathway.js +35 -30
  371. package/packages/dd-trace/src/datastreams/processor.js +31 -22
  372. package/packages/dd-trace/src/datastreams/size.js +6 -2
  373. package/packages/dd-trace/src/datastreams/writer.js +15 -6
  374. package/packages/dd-trace/src/debugger/config.js +9 -4
  375. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +49 -35
  376. package/packages/dd-trace/src/debugger/devtools_client/condition.js +5 -8
  377. package/packages/dd-trace/src/debugger/devtools_client/config.js +3 -2
  378. package/packages/dd-trace/src/debugger/devtools_client/index.js +33 -71
  379. package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +83 -0
  380. package/packages/dd-trace/src/debugger/devtools_client/send.js +27 -6
  381. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +2 -2
  382. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +5 -2
  383. package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +1 -0
  384. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +1 -1
  385. package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
  386. package/packages/dd-trace/src/debugger/index.js +14 -10
  387. package/packages/dd-trace/src/debugger/probe_sampler.js +112 -0
  388. package/packages/dd-trace/src/debugger/probe_sampler_constants.js +19 -0
  389. package/packages/dd-trace/src/dogstatsd.js +45 -36
  390. package/packages/dd-trace/src/encode/0.4.js +830 -269
  391. package/packages/dd-trace/src/encode/0.5.js +158 -22
  392. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +141 -65
  393. package/packages/dd-trace/src/encode/agentless-json.js +12 -6
  394. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +52 -15
  395. package/packages/dd-trace/src/encode/span-stats.js +19 -16
  396. package/packages/dd-trace/src/encode/tags-processors.js +30 -25
  397. package/packages/dd-trace/src/exporter.js +3 -1
  398. package/packages/dd-trace/src/exporters/agent/index.js +4 -5
  399. package/packages/dd-trace/src/exporters/agent/writer.js +8 -3
  400. package/packages/dd-trace/src/exporters/agentless/index.js +12 -13
  401. package/packages/dd-trace/src/exporters/agentless/intake.js +43 -0
  402. package/packages/dd-trace/src/exporters/agentless/writer.js +12 -11
  403. package/packages/dd-trace/src/exporters/common/agents.js +3 -1
  404. package/packages/dd-trace/src/exporters/common/buffering-exporter.js +3 -3
  405. package/packages/dd-trace/src/exporters/common/request.js +55 -26
  406. package/packages/dd-trace/src/exporters/common/retry.js +104 -0
  407. package/packages/dd-trace/src/exporters/common/url.js +34 -0
  408. package/packages/dd-trace/src/exporters/common/util.js +2 -2
  409. package/packages/dd-trace/src/exporters/common/writer.js +29 -3
  410. package/packages/dd-trace/src/exporters/electron/index.js +49 -0
  411. package/packages/dd-trace/src/exporters/span-stats/index.js +1 -2
  412. package/packages/dd-trace/src/exporters/span-stats/writer.js +1 -3
  413. package/packages/dd-trace/src/external-logger/src/index.js +2 -1
  414. package/packages/dd-trace/src/feature-registry.js +22 -0
  415. package/packages/dd-trace/src/git_metadata.js +68 -0
  416. package/packages/dd-trace/src/git_metadata_tagger.js +13 -5
  417. package/packages/dd-trace/src/guardrails/index.js +11 -6
  418. package/packages/dd-trace/src/guardrails/telemetry.js +40 -3
  419. package/packages/dd-trace/src/heap_snapshots.js +7 -4
  420. package/packages/dd-trace/src/id.js +46 -27
  421. package/packages/dd-trace/src/index.js +6 -4
  422. package/packages/dd-trace/src/lambda/handler-paths.js +52 -0
  423. package/packages/dd-trace/src/lambda/handler.js +2 -6
  424. package/packages/dd-trace/src/lambda/index.js +62 -14
  425. package/packages/dd-trace/src/lambda/runtime/patch.js +21 -46
  426. package/packages/dd-trace/src/llmobs/constants/tags.js +13 -0
  427. package/packages/dd-trace/src/llmobs/index.js +41 -8
  428. package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +403 -0
  429. package/packages/dd-trace/src/llmobs/plugins/ai/index.js +8 -391
  430. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +178 -18
  431. package/packages/dd-trace/src/llmobs/plugins/ai/vercelTelemetry.js +363 -0
  432. package/packages/dd-trace/src/llmobs/plugins/{anthropic.js → anthropic/index.js} +32 -79
  433. package/packages/dd-trace/src/llmobs/plugins/anthropic/util.js +109 -0
  434. package/packages/dd-trace/src/llmobs/plugins/base.js +4 -4
  435. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +92 -38
  436. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +270 -0
  437. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +10 -0
  438. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +5 -1
  439. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +81 -16
  440. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +3 -2
  441. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +3 -2
  442. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/embedding.js +2 -1
  443. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +1 -50
  444. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/vectorstore.js +2 -1
  445. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +14 -8
  446. package/packages/dd-trace/src/llmobs/plugins/langchain/messages.js +76 -0
  447. package/packages/dd-trace/src/llmobs/plugins/langgraph/index.js +3 -28
  448. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +68 -0
  449. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +57 -0
  450. package/packages/dd-trace/src/llmobs/plugins/openai/index.js +21 -51
  451. package/packages/dd-trace/src/llmobs/sdk.js +66 -41
  452. package/packages/dd-trace/src/llmobs/span_processor.js +91 -12
  453. package/packages/dd-trace/src/llmobs/tagger.js +135 -7
  454. package/packages/dd-trace/src/llmobs/telemetry.js +31 -1
  455. package/packages/dd-trace/src/llmobs/util.js +202 -9
  456. package/packages/dd-trace/src/llmobs/writers/base.js +13 -5
  457. package/packages/dd-trace/src/llmobs/writers/spans.js +1 -1
  458. package/packages/dd-trace/src/llmobs/writers/util.js +4 -2
  459. package/packages/dd-trace/src/log/index.js +28 -69
  460. package/packages/dd-trace/src/log/writer.js +10 -20
  461. package/packages/dd-trace/src/msgpack/chunk.js +430 -11
  462. package/packages/dd-trace/src/msgpack/index.js +101 -2
  463. package/packages/dd-trace/src/noop/proxy.js +13 -4
  464. package/packages/dd-trace/src/noop/span.js +3 -1
  465. package/packages/dd-trace/src/openfeature/encoding.js +70 -0
  466. package/packages/dd-trace/src/openfeature/eval-metrics-hook.js +103 -0
  467. package/packages/dd-trace/src/openfeature/flagging_provider.js +26 -1
  468. package/packages/dd-trace/src/openfeature/noop.js +40 -36
  469. package/packages/dd-trace/src/openfeature/register.js +46 -0
  470. package/packages/dd-trace/src/openfeature/remote_config.js +6 -1
  471. package/packages/dd-trace/src/openfeature/span-enrichment-hook.js +143 -0
  472. package/packages/dd-trace/src/openfeature/span-enrichment.js +149 -0
  473. package/packages/dd-trace/src/openfeature/writers/base.js +3 -11
  474. package/packages/dd-trace/src/openfeature/writers/exposures.js +82 -70
  475. package/packages/dd-trace/src/openfeature/writers/util.js +1 -2
  476. package/packages/dd-trace/src/opentelemetry/active-span-proxy.js +42 -0
  477. package/packages/dd-trace/src/opentelemetry/bridge-span-base.js +107 -0
  478. package/packages/dd-trace/src/opentelemetry/context_manager.js +27 -13
  479. package/packages/dd-trace/src/opentelemetry/logs/index.js +7 -7
  480. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +3 -2
  481. package/packages/dd-trace/src/opentelemetry/metrics/index.js +62 -13
  482. package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +28 -14
  483. package/packages/dd-trace/src/opentelemetry/metrics/meter.js +7 -10
  484. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +3 -2
  485. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +40 -0
  486. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js +169 -0
  487. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +99 -5
  488. package/packages/dd-trace/src/opentelemetry/metrics/time.js +19 -0
  489. package/packages/dd-trace/src/opentelemetry/otlp/common.proto +2 -2
  490. package/packages/dd-trace/src/opentelemetry/otlp/logs.proto +1 -1
  491. package/packages/dd-trace/src/opentelemetry/otlp/logs_service.proto +1 -1
  492. package/packages/dd-trace/src/opentelemetry/otlp/metrics.proto +1 -1
  493. package/packages/dd-trace/src/opentelemetry/otlp/metrics_service.proto +1 -1
  494. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +56 -82
  495. package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +1 -2
  496. package/packages/dd-trace/src/opentelemetry/otlp/protobuf_loader.js +14 -2
  497. package/packages/dd-trace/src/opentelemetry/otlp/trace.proto +358 -0
  498. package/packages/dd-trace/src/opentelemetry/otlp/trace_service.proto +78 -0
  499. package/packages/dd-trace/src/opentelemetry/span-helpers.js +325 -0
  500. package/packages/dd-trace/src/opentelemetry/span.js +59 -109
  501. package/packages/dd-trace/src/opentelemetry/span_context.js +1 -0
  502. package/packages/dd-trace/src/opentelemetry/span_processor.js +7 -5
  503. package/packages/dd-trace/src/opentelemetry/trace/index.js +75 -0
  504. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +75 -0
  505. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +375 -0
  506. package/packages/dd-trace/src/opentelemetry/tracer.js +20 -69
  507. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +33 -17
  508. package/packages/dd-trace/src/opentracing/propagation/log.js +28 -8
  509. package/packages/dd-trace/src/opentracing/propagation/text_map.js +280 -145
  510. package/packages/dd-trace/src/opentracing/propagation/text_map_dsm.js +11 -11
  511. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +98 -32
  512. package/packages/dd-trace/src/opentracing/span.js +127 -73
  513. package/packages/dd-trace/src/opentracing/span_context.js +68 -3
  514. package/packages/dd-trace/src/opentracing/tracer.js +46 -19
  515. package/packages/dd-trace/src/payload-tagging/config/index.js +8 -7
  516. package/packages/dd-trace/src/plugin_manager.js +44 -20
  517. package/packages/dd-trace/src/plugins/apollo.js +3 -1
  518. package/packages/dd-trace/src/plugins/ci_plugin.js +391 -85
  519. package/packages/dd-trace/src/plugins/database.js +61 -18
  520. package/packages/dd-trace/src/plugins/index.js +14 -0
  521. package/packages/dd-trace/src/plugins/log_injection.js +56 -0
  522. package/packages/dd-trace/src/plugins/log_plugin.js +4 -44
  523. package/packages/dd-trace/src/plugins/outbound.js +1 -1
  524. package/packages/dd-trace/src/plugins/plugin.js +22 -28
  525. package/packages/dd-trace/src/plugins/storage.js +2 -2
  526. package/packages/dd-trace/src/plugins/tracing.js +70 -13
  527. package/packages/dd-trace/src/plugins/util/ci.js +127 -40
  528. package/packages/dd-trace/src/plugins/util/git-cache.js +23 -23
  529. package/packages/dd-trace/src/plugins/util/git.js +3 -1
  530. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +276 -0
  531. package/packages/dd-trace/src/plugins/util/llm.js +6 -1
  532. package/packages/dd-trace/src/plugins/util/stacktrace.js +2 -2
  533. package/packages/dd-trace/src/plugins/util/test.js +894 -65
  534. package/packages/dd-trace/src/plugins/util/url.js +71 -5
  535. package/packages/dd-trace/src/plugins/util/user-provided-git.js +18 -16
  536. package/packages/dd-trace/src/plugins/util/web.js +116 -180
  537. package/packages/dd-trace/src/priority_sampler.js +12 -21
  538. package/packages/dd-trace/src/process-tags/index.js +3 -0
  539. package/packages/dd-trace/src/profiler.js +27 -2
  540. package/packages/dd-trace/src/profiling/config.js +145 -393
  541. package/packages/dd-trace/src/profiling/constants.js +4 -7
  542. package/packages/dd-trace/src/profiling/exporter_cli.js +10 -13
  543. package/packages/dd-trace/src/profiling/exporters/agent.js +61 -28
  544. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +50 -15
  545. package/packages/dd-trace/src/profiling/exporters/file.js +16 -5
  546. package/packages/dd-trace/src/profiling/oom.js +71 -0
  547. package/packages/dd-trace/src/profiling/profiler.js +123 -132
  548. package/packages/dd-trace/src/profiling/profilers/event_plugins/crypto.js +32 -0
  549. package/packages/dd-trace/src/profiling/profilers/event_plugins/zlib.js +19 -0
  550. package/packages/dd-trace/src/profiling/profilers/events.js +57 -14
  551. package/packages/dd-trace/src/profiling/profilers/space.js +27 -16
  552. package/packages/dd-trace/src/profiling/profilers/wall.js +136 -39
  553. package/packages/dd-trace/src/profiling/ssi-heuristics.js +7 -4
  554. package/packages/dd-trace/src/propagation-hash/index.js +3 -2
  555. package/packages/dd-trace/src/proxy.js +82 -39
  556. package/packages/dd-trace/src/rate_limiter.js +1 -1
  557. package/packages/dd-trace/src/remote_config/index.js +9 -5
  558. package/packages/dd-trace/src/remote_config/scheduler.js +1 -1
  559. package/packages/dd-trace/src/require-package-json.js +8 -4
  560. package/packages/dd-trace/src/ritm.js +63 -28
  561. package/packages/dd-trace/src/runtime_metrics/client.js +30 -0
  562. package/packages/dd-trace/src/runtime_metrics/index.js +17 -4
  563. package/packages/dd-trace/src/runtime_metrics/otlp_runtime_metrics.js +284 -0
  564. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +45 -41
  565. package/packages/dd-trace/src/sampler.js +1 -1
  566. package/packages/dd-trace/src/sampling_rule.js +7 -7
  567. package/packages/dd-trace/src/scope.js +10 -15
  568. package/packages/dd-trace/src/serverless.js +6 -7
  569. package/packages/dd-trace/src/service-naming/extra-services.js +14 -0
  570. package/packages/dd-trace/src/service-naming/index.js +1 -1
  571. package/packages/dd-trace/src/service-naming/schemas/definition.js +4 -1
  572. package/packages/dd-trace/src/service-naming/schemas/util.js +48 -3
  573. package/packages/dd-trace/src/service-naming/schemas/v0/graphql.js +6 -0
  574. package/packages/dd-trace/src/service-naming/schemas/v0/messaging.js +61 -2
  575. package/packages/dd-trace/src/service-naming/schemas/v0/serverless.js +12 -0
  576. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +60 -0
  577. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +25 -1
  578. package/packages/dd-trace/src/service-naming/schemas/v0/websocket.js +5 -0
  579. package/packages/dd-trace/src/service-naming/schemas/v1/graphql.js +8 -0
  580. package/packages/dd-trace/src/service-naming/schemas/v1/messaging.js +32 -0
  581. package/packages/dd-trace/src/service-naming/schemas/v1/serverless.js +12 -0
  582. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +17 -0
  583. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +23 -3
  584. package/packages/dd-trace/src/service-naming/schemas/v1/websocket.js +6 -0
  585. package/packages/dd-trace/src/service-naming/source-resolver.js +50 -0
  586. package/packages/dd-trace/src/span_format.js +269 -81
  587. package/packages/dd-trace/src/span_processor.js +13 -13
  588. package/packages/dd-trace/src/span_stats.js +101 -79
  589. package/packages/dd-trace/src/spanleak.js +1 -2
  590. package/packages/dd-trace/src/standalone/index.js +6 -25
  591. package/packages/dd-trace/src/startup-log.js +3 -3
  592. package/packages/dd-trace/src/tagger.js +2 -4
  593. package/packages/dd-trace/src/telemetry/dependencies.js +2 -2
  594. package/packages/dd-trace/src/telemetry/endpoints.js +7 -5
  595. package/packages/dd-trace/src/telemetry/index.js +2 -3
  596. package/packages/dd-trace/src/telemetry/logs/index.js +1 -1
  597. package/packages/dd-trace/src/telemetry/send-data.js +25 -39
  598. package/packages/dd-trace/src/telemetry/session-propagation.js +20 -45
  599. package/packages/dd-trace/src/telemetry/telemetry.js +42 -183
  600. package/packages/dd-trace/src/tracer.js +23 -9
  601. package/packages/dd-trace/src/tracer_metadata.js +1 -1
  602. package/packages/dd-trace/src/util.js +31 -9
  603. package/register.js +58 -1
  604. package/vendor/dist/@apm-js-collab/code-transformer/index.js +94 -42
  605. package/vendor/dist/@datadog/sketches-js/LICENSE +10 -36
  606. package/vendor/dist/@datadog/sketches-js/index.js +1 -1
  607. package/vendor/dist/pprof-format/index.js +1 -1
  608. package/vendor/dist/protobufjs/index.js +1 -1
  609. package/vendor/dist/protobufjs/minimal/index.js +1 -1
  610. package/vendor/dist/shell-quote/index.js +1 -1
  611. package/packages/datadog-plugin-graphql/src/resolve.js +0 -178
  612. package/packages/dd-trace/src/agent/url.js +0 -28
  613. package/packages/dd-trace/src/appsec/api_security_sampler.js +0 -117
  614. package/packages/dd-trace/src/lambda/runtime/ritm.js +0 -133
  615. package/packages/dd-trace/src/log/utils.js +0 -16
  616. package/packages/dd-trace/src/msgpack/encoder.js +0 -308
  617. package/packages/dd-trace/src/plugins/structured_log_plugin.js +0 -9
  618. package/scripts/preinstall.js +0 -34
  619. package/vendor/dist/ignore/LICENSE +0 -21
  620. package/vendor/dist/ignore/index.js +0 -1
  621. package/vendor/dist/opentracing/LICENSE +0 -201
  622. package/vendor/dist/opentracing/binary_carrier.d.ts +0 -11
  623. package/vendor/dist/opentracing/constants.d.ts +0 -61
  624. package/vendor/dist/opentracing/examples/demo/demo.d.ts +0 -2
  625. package/vendor/dist/opentracing/ext/tags.d.ts +0 -90
  626. package/vendor/dist/opentracing/functions.d.ts +0 -20
  627. package/vendor/dist/opentracing/global_tracer.d.ts +0 -14
  628. package/vendor/dist/opentracing/index.d.ts +0 -12
  629. package/vendor/dist/opentracing/index.js +0 -1
  630. package/vendor/dist/opentracing/mock_tracer/index.d.ts +0 -5
  631. package/vendor/dist/opentracing/mock_tracer/mock_context.d.ts +0 -13
  632. package/vendor/dist/opentracing/mock_tracer/mock_report.d.ts +0 -16
  633. package/vendor/dist/opentracing/mock_tracer/mock_span.d.ts +0 -50
  634. package/vendor/dist/opentracing/mock_tracer/mock_tracer.d.ts +0 -26
  635. package/vendor/dist/opentracing/noop.d.ts +0 -8
  636. package/vendor/dist/opentracing/reference.d.ts +0 -33
  637. package/vendor/dist/opentracing/span.d.ts +0 -147
  638. package/vendor/dist/opentracing/span_context.d.ts +0 -26
  639. package/vendor/dist/opentracing/test/api_compatibility.d.ts +0 -16
  640. package/vendor/dist/opentracing/test/mocktracer_implemenation.d.ts +0 -3
  641. package/vendor/dist/opentracing/test/noop_implementation.d.ts +0 -4
  642. package/vendor/dist/opentracing/test/opentracing_api.d.ts +0 -3
  643. package/vendor/dist/opentracing/test/unittest.d.ts +0 -2
  644. package/vendor/dist/opentracing/tracer.d.ts +0 -127
  645. package/vendor/dist/path-to-regexp/LICENSE +0 -21
  646. package/vendor/dist/path-to-regexp/index.js +0 -1
@@ -1,5 +1,10 @@
1
1
  'use strict'
2
2
 
3
+ // Capture real timers at module load time, before any test can install fake timers.
4
+ const realSetTimeout = setTimeout
5
+ const realClearTimeout = clearTimeout
6
+
7
+ const { performance } = require('node:perf_hooks')
3
8
  const satisfies = require('../../../vendor/dist/semifies')
4
9
 
5
10
  const shimmer = require('../../datadog-shimmer')
@@ -9,14 +14,19 @@ const {
9
14
  PLAYWRIGHT_WORKER_TRACE_PAYLOAD_CODE,
10
15
  getIsFaultyEarlyFlakeDetection,
11
16
  DYNAMIC_NAME_RE,
12
- logDynamicNamesWarning,
17
+ getEfdRetryCount,
18
+ getMaxEfdRetryCount,
19
+ recordAttemptToFixExecution,
20
+ logAttemptToFixTestExecution,
21
+ logTestOptimizationSummary,
22
+ getTestOptimizationRequestResults,
13
23
  } = require('../../dd-trace/src/plugins/util/test')
14
24
  const log = require('../../dd-trace/src/log')
15
25
  const {
16
26
  getValueFromEnvSources,
17
27
  } = require('../../dd-trace/src/config/helper')
18
28
  const { DD_MAJOR } = require('../../../version')
19
- const { addHook, channel } = require('./helpers/instrument')
29
+ const { addHook, channel, tracingChannel } = require('./helpers/instrument')
20
30
 
21
31
  const testStartCh = channel('ci:playwright:test:start')
22
32
  const testFinishCh = channel('ci:playwright:test:finish')
@@ -37,18 +47,28 @@ const testSuiteFinishCh = channel('ci:playwright:test-suite:finish')
37
47
  const workerReportCh = channel('ci:playwright:worker:report')
38
48
  const testPageGotoCh = channel('ci:playwright:test:page-goto')
39
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
+
40
56
  const testToCtx = new WeakMap()
41
57
  const testSuiteToCtx = new Map()
42
58
  const testSuiteToTestStatuses = new Map()
43
59
  const testSuiteToErrors = new Map()
44
60
  const testsToTestStatuses = new Map()
45
61
 
46
- 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
47
64
 
48
65
  let applyRepeatEachIndex = null
49
66
 
50
67
  let startedSuites = []
51
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
+
52
72
  const STATUS_TO_TEST_STATUS = {
53
73
  passed: 'pass',
54
74
  failed: 'fail',
@@ -60,6 +80,7 @@ let remainingTestsByFile = {}
60
80
  let isKnownTestsEnabled = false
61
81
  let isEarlyFlakeDetectionEnabled = false
62
82
  let earlyFlakeDetectionNumRetries = 0
83
+ let earlyFlakeDetectionSlowTestRetries = {}
63
84
  let isEarlyFlakeDetectionFaulty = false
64
85
  let earlyFlakeDetectionFaultyThreshold = 0
65
86
  let isFlakyTestRetriesEnabled = false
@@ -70,13 +91,32 @@ let testManagementAttemptToFixRetries = 0
70
91
  let testManagementTests = {}
71
92
  let isImpactedTestsEnabled = false
72
93
  let modifiedFiles = {}
73
- const quarantinedOrDisabledTestsAttemptToFix = []
74
94
  let quarantinedButNotAttemptToFixFqns = new Set()
95
+ let testsReportedInGenerateSummary = new Set()
75
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()
76
109
  let rootDir = ''
77
110
  let sessionProjects = []
78
111
 
79
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')
80
120
 
81
121
  function isValidKnownTests (receivedKnownTests) {
82
122
  return !!receivedKnownTests.playwright
@@ -87,6 +127,259 @@ function getTestFullyQualifiedName (test) {
87
127
  return `${test._requireFile} ${fullname}`
88
128
  }
89
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
+
90
383
  function getTestProperties (test) {
91
384
  const testName = getTestFullname(test)
92
385
  const testSuite = getTestSuitePath(test._requireFile, rootDir)
@@ -114,15 +407,22 @@ function getSuiteType (test, type) {
114
407
  return suite
115
408
  }
116
409
 
410
+ function isSuiteEntry (entry) {
411
+ return entry.constructor.name === 'Suite' || entry.constructor.name === '_Suite'
412
+ }
413
+
117
414
  // Copy of Suite#_deepClone but with a function to filter tests
118
- function deepCloneSuite (suite, filterTest, tags = []) {
415
+ function deepCloneSuite (suite, filterTest, tags = [], configureCopiedTest) {
119
416
  const copy = suite._clone()
120
417
  for (const entry of suite._entries) {
121
- if (entry.constructor.name === 'Suite') {
122
- copy._addSuite(deepCloneSuite(entry, filterTest, tags))
418
+ if (isSuiteEntry(entry)) {
419
+ copy._addSuite(deepCloneSuite(entry, filterTest, tags, configureCopiedTest))
123
420
  } else {
124
421
  if (filterTest(entry)) {
125
422
  const copiedTest = entry._clone()
423
+ if (configureCopiedTest) {
424
+ configureCopiedTest(copiedTest, entry)
425
+ }
126
426
  for (const tag of tags) {
127
427
  const resolvedTag = typeof tag === 'function' ? tag(entry) : tag
128
428
 
@@ -202,6 +502,10 @@ function getProjectsFromRunner (runner, configArg) {
202
502
  }
203
503
 
204
504
  function getProjectsFromDispatcher (dispatcher) {
505
+ const bundledConfig = dispatcher._testRun?.config?.config?.projects
506
+ if (bundledConfig) {
507
+ return bundledConfig
508
+ }
205
509
  const newConfig = dispatcher._config?.config?.projects
206
510
  if (newConfig) {
207
511
  return newConfig
@@ -284,6 +588,36 @@ function testWillRetry (test, testStatus) {
284
588
  return testStatus === 'fail' && test.results.length <= test.retries
285
589
  }
286
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
+
287
621
  function getTestFullname (test) {
288
622
  let parent = test.parent
289
623
  const names = [test.title]
@@ -314,6 +648,14 @@ function testBeginHandler (test, browserName, shouldCreateTestSpan) {
314
648
  if (_type === 'beforeAll' || _type === 'afterAll') {
315
649
  return
316
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
+ }
317
659
  // this means that a skipped test is being handled
318
660
  if (!remainingTestsByFile[testSuiteAbsolutePath].length) {
319
661
  return
@@ -331,6 +673,11 @@ function testBeginHandler (test, browserName, shouldCreateTestSpan) {
331
673
  // We disable retries by default if attemptToFix is true
332
674
  if (getTestProperties(test).attemptToFix) {
333
675
  test.retries = 0
676
+ logAttemptToFixTestExecution(
677
+ getTestSuitePath(testSuiteAbsolutePath, rootDir),
678
+ getTestFullname(test),
679
+ loggedAttemptToFixTests
680
+ )
334
681
  }
335
682
 
336
683
  // this handles tests that do not go through the worker process (because they're skipped)
@@ -350,6 +697,45 @@ function testBeginHandler (test, browserName, shouldCreateTestSpan) {
350
697
  }
351
698
  }
352
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
+
353
739
  function testEndHandler ({
354
740
  test,
355
741
  annotations,
@@ -379,11 +765,21 @@ function testEndHandler ({
379
765
  return
380
766
  }
381
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)
382
777
  const testFqn = getTestFullyQualifiedName(test)
383
- const testStatuses = testsToTestStatuses.get(testFqn) || []
778
+ const testStatusKey = isEfdManagedTest ? getTestEfdKey(test) : testFqn
779
+ const testStatuses = testsToTestStatuses.get(testStatusKey) || []
384
780
 
385
781
  if (testStatuses.length === 0) {
386
- testsToTestStatuses.set(testFqn, [testStatus])
782
+ testsToTestStatuses.set(testStatusKey, [testStatus])
387
783
  if (test._ddIsNew && DYNAMIC_NAME_RE.test(getTestFullname(test))) {
388
784
  newTestsWithDynamicNames.add(`${getTestSuitePath(test._requireFile, rootDir)} › ${getTestFullname(test)}`)
389
785
  }
@@ -391,8 +787,33 @@ function testEndHandler ({
391
787
  testStatuses.push(testStatus)
392
788
  }
393
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
+
394
801
  const testProperties = getTestProperties(test)
395
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
+
396
817
  if (testStatuses.length === testManagementAttemptToFixRetries + 1 && testProperties.attemptToFix) {
397
818
  if (testStatuses.includes('fail')) {
398
819
  test._ddHasFailedAttemptToFixRetries = true
@@ -405,9 +826,10 @@ function testEndHandler ({
405
826
  }
406
827
 
407
828
  // Check if all EFD retries failed
408
- if (testStatuses.length === earlyFlakeDetectionNumRetries + 1 &&
829
+ const efdRetryCount = getEfdRetryCountForTest(test)
830
+ if (efdRetryCount > 0 && testStatuses.length === efdRetryCount + 1 &&
409
831
  (test._ddIsNew || test._ddIsModified) &&
410
- test._ddIsEfdRetry &&
832
+ isEarlyFlakeDetectionEnabled &&
411
833
  testStatuses.every(status => status === 'fail')) {
412
834
  test._ddHasFailedAllRetries = true
413
835
  }
@@ -421,6 +843,8 @@ function testEndHandler ({
421
843
  test._ddHasFailedAllRetries = true
422
844
  }
423
845
 
846
+ const willRetry = testWillRetry(test, testStatus)
847
+
424
848
  // this handles tests that do not go through the worker process (because they're skipped)
425
849
  if (shouldCreateTestSpan) {
426
850
  const testResult = results.at(-1)
@@ -429,6 +853,20 @@ function testEndHandler ({
429
853
  isFlakyTestRetriesEnabled &&
430
854
  !test._ddIsAttemptToFix &&
431
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
+
432
870
  // if there is no testCtx, the skipped test will be created later
433
871
  if (testCtx) {
434
872
  testFinishCh.publish({
@@ -448,94 +886,214 @@ function testEndHandler ({
448
886
  hasFailedAttemptToFixRetries: test._ddHasFailedAttemptToFixRetries,
449
887
  isAtrRetry,
450
888
  isModified: test._ddIsModified,
889
+ finalStatus,
890
+ earlyFlakeAbortReason: efdSlowAbortedTests.has(testEfdKey) ? 'slow' : undefined,
451
891
  ...testCtx.currentStore,
452
892
  })
453
893
  }
454
894
  }
455
895
 
456
- if (testSuiteToTestStatuses.has(testSuiteAbsolutePath)) {
457
- testSuiteToTestStatuses.get(testSuiteAbsolutePath).push(testStatus)
458
- } else {
459
- testSuiteToTestStatuses.set(testSuiteAbsolutePath, [testStatus])
460
- }
896
+ if (!willRetry) {
897
+ if (testSuiteToTestStatuses.has(testSuiteAbsolutePath)) {
898
+ testSuiteToTestStatuses.get(testSuiteAbsolutePath).push(testStatus)
899
+ } else {
900
+ testSuiteToTestStatuses.set(testSuiteAbsolutePath, [testStatus])
901
+ }
461
902
 
462
- if (error) {
463
- addErrorToTestSuite(testSuiteAbsolutePath, error)
903
+ if (error) {
904
+ addErrorToTestSuite(testSuiteAbsolutePath, error)
905
+ }
464
906
  }
465
907
 
466
- if (!testWillRetry(test, testStatus)) {
908
+ if (!willRetry) {
467
909
  remainingTestsByFile[testSuiteAbsolutePath] = remainingTestsByFile[testSuiteAbsolutePath]
468
910
  .filter(currentTest => currentTest !== test)
469
911
  }
470
912
 
471
- if (shouldFinishTestSuite(testSuiteAbsolutePath)) {
472
- const skippedTests = remainingTestsByFile[testSuiteAbsolutePath]
473
- .filter(test => test.expectedStatus === 'skipped')
913
+ finishTestSuiteIfDone(testSuiteAbsolutePath, projects)
914
+ }
474
915
 
475
- for (const test of skippedTests) {
476
- const browserName = getBrowserNameFromProjects(projects, test)
477
- testSkipCh.publish({
478
- testName: getTestFullname(test),
479
- testSuiteAbsolutePath,
480
- testSourceFileAbsolutePath: test.location.file,
481
- testSourceLine: test.location.line,
482
- browserName,
483
- isNew: test._ddIsNew,
484
- isDisabled: test._ddIsDisabled,
485
- isModified: test._ddIsModified,
486
- isQuarantined: test._ddIsQuarantined,
487
- })
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
+ }
488
940
  }
489
- remainingTestsByFile[testSuiteAbsolutePath] = []
490
941
 
491
- const testStatuses = testSuiteToTestStatuses.get(testSuiteAbsolutePath)
492
- let testSuiteStatus = 'pass'
493
- if (testStatuses.includes('fail')) {
494
- testSuiteStatus = 'fail'
495
- } else if (testStatuses.every(status => status === 'skip')) {
496
- testSuiteStatus = 'skip'
942
+ if (efdRetryTests.length && originalTests.length) {
943
+ group.tests = [...originalTests, ...efdRetryTests]
497
944
  }
498
945
 
499
- const suiteError = getTestSuiteError(testSuiteAbsolutePath)
500
- const testSuiteCtx = testSuiteToCtx.get(testSuiteAbsolutePath)
501
- testSuiteFinishCh.publish({ status: testSuiteStatus, error: suiteError, ...testSuiteCtx.currentStore })
946
+ if (originalTests.length) {
947
+ groupsWithOriginalTests.push(group)
948
+ } else {
949
+ efdRetryOnlyGroups.push(group)
950
+ }
502
951
  }
952
+
953
+ return [...groupsWithOriginalTests, ...efdRetryOnlyGroups]
503
954
  }
504
955
 
505
- 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) {
506
983
  return function () {
507
- remainingTestsByFile = getTestsBySuiteFromTestsById(this._testById)
984
+ prepareDispatcherRun(this, arguments)
508
985
  return run.apply(this, arguments)
509
986
  }
510
987
  }
511
988
 
512
- function dispatcherRunWrapperNew (run) {
513
- return function (testGroups) {
514
- // Filter out disabled tests from testGroups before they get scheduled,
515
- // unless they have attemptToFix (in which case they should still run and be retried)
516
- if (isTestManagementTestsEnabled) {
517
- for (const group of testGroups) {
518
- 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
1011
+ }
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)
1033
+ }
1034
+ testEndHandler(
1035
+ {
1036
+ test,
1037
+ annotations,
1038
+ testStatus,
1039
+ error: errors && errors[0],
1040
+ isTimeout,
1041
+ shouldCreateTestSpan,
1042
+ projects,
519
1043
  }
520
- // Remove empty groups
521
- testGroups = testGroups.filter(group => group.tests.length > 0)
1044
+ )
1045
+ const testResult = test.results.at(-1)
1046
+ const isAtrRetry = testResult?.retry > 0 &&
1047
+ isFlakyTestRetriesEnabled &&
1048
+ !test._ddIsAttemptToFix &&
1049
+ !test._ddIsEfdRetry
1050
+
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)
522
1066
  }
523
1067
 
524
- if (!this._allTests) {
525
- // Removed in https://github.com/microsoft/playwright/commit/1e52c37b254a441cccf332520f60225a5acc14c7
526
- // Not available from >=1.44.0
527
- this._ddAllTests = testGroups.flatMap(g => g.tests)
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'),
528
1084
  }
529
- remainingTestsByFile = getTestsBySuiteFromTestGroups(testGroups)
530
- return run.apply(this, arguments)
531
- }
1085
+
1086
+ setDdPropertiesForTest(worker.process, test.id, ddProperties)
1087
+ })
1088
+
1089
+ return worker
532
1090
  }
533
1091
 
534
1092
  function dispatcherHook (dispatcherExport) {
535
1093
  shimmer.wrap(dispatcherExport.Dispatcher.prototype, 'run', dispatcherRunWrapper)
536
- shimmer.wrap(dispatcherExport.Dispatcher.prototype, '_createWorker', createWorker => function () {
1094
+ shimmer.wrap(dispatcherExport.Dispatcher.prototype, '_createWorker', createWorker => function (...args) {
537
1095
  const dispatcher = this
538
- const worker = createWorker.apply(this, arguments)
1096
+ const worker = createWorker.apply(this, args)
539
1097
  const projects = getProjectsFromDispatcher(dispatcher)
540
1098
  sessionProjects = projects
541
1099
 
@@ -566,7 +1124,6 @@ function dispatcherHook (dispatcherExport) {
566
1124
  )
567
1125
  }
568
1126
  })
569
-
570
1127
  return worker
571
1128
  })
572
1129
  return dispatcherExport
@@ -574,60 +1131,10 @@ function dispatcherHook (dispatcherExport) {
574
1131
 
575
1132
  function dispatcherHookNew (dispatcherExport, runWrapper) {
576
1133
  shimmer.wrap(dispatcherExport.Dispatcher.prototype, 'run', runWrapper)
577
- shimmer.wrap(dispatcherExport.Dispatcher.prototype, '_createWorker', createWorker => function () {
1134
+ shimmer.wrap(dispatcherExport.Dispatcher.prototype, '_createWorker', createWorker => function (...args) {
578
1135
  const dispatcher = this
579
- const worker = createWorker.apply(this, arguments)
580
- const projects = getProjectsFromDispatcher(dispatcher)
581
- sessionProjects = projects
582
-
583
- worker.on('testBegin', ({ testId }) => {
584
- const test = getTestByTestId(dispatcher, testId)
585
- const browser = getBrowserNameFromProjects(projects, test)
586
- const shouldCreateTestSpan = test.expectedStatus === 'skipped'
587
- testBeginHandler(test, browser, shouldCreateTestSpan)
588
- })
589
- worker.on('testEnd', ({ testId, status, errors, annotations }) => {
590
- const test = getTestByTestId(dispatcher, testId)
591
-
592
- const isTimeout = status === 'timedOut'
593
- const shouldCreateTestSpan = test.expectedStatus === 'skipped'
594
- testEndHandler(
595
- {
596
- test,
597
- annotations,
598
- testStatus: STATUS_TO_TEST_STATUS[status],
599
- error: errors && errors[0],
600
- isTimeout,
601
- shouldCreateTestSpan,
602
- projects,
603
- }
604
- )
605
- const testResult = test.results.at(-1)
606
- const isAtrRetry = testResult?.retry > 0 &&
607
- isFlakyTestRetriesEnabled &&
608
- !test._ddIsAttemptToFix &&
609
- !test._ddIsEfdRetry
610
- // We want to send the ddProperties to the worker
611
- worker.process.send({
612
- type: 'ddProperties',
613
- testId: test.id,
614
- properties: {
615
- _ddIsDisabled: test._ddIsDisabled,
616
- _ddIsQuarantined: test._ddIsQuarantined,
617
- _ddIsAttemptToFix: test._ddIsAttemptToFix,
618
- _ddIsAttemptToFixRetry: test._ddIsAttemptToFixRetry,
619
- _ddIsNew: test._ddIsNew,
620
- _ddIsEfdRetry: test._ddIsEfdRetry,
621
- _ddHasFailedAllRetries: test._ddHasFailedAllRetries,
622
- _ddHasPassedAttemptToFixRetries: test._ddHasPassedAttemptToFixRetries,
623
- _ddHasFailedAttemptToFixRetries: test._ddHasFailedAttemptToFixRetries,
624
- _ddIsAtrRetry: isAtrRetry,
625
- _ddIsModified: test._ddIsModified,
626
- },
627
- })
628
- })
629
-
630
- return worker
1136
+ const worker = createWorker.apply(this, args)
1137
+ return onDispatcherCreateWorker(dispatcher, worker)
631
1138
  })
632
1139
  return dispatcherExport
633
1140
  }
@@ -638,7 +1145,6 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
638
1145
  let onDone
639
1146
 
640
1147
  rootDir = getRootDir(this, config)
641
-
642
1148
  const processArgv = process.argv.slice(2).join(' ')
643
1149
  const command = `playwright ${processArgv}`
644
1150
  testSessionStartCh.publish({ command, frameworkVersion: playwrightVersion, rootDir })
@@ -652,6 +1158,7 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
652
1158
  isKnownTestsEnabled = libraryConfig.isKnownTestsEnabled
653
1159
  isEarlyFlakeDetectionEnabled = libraryConfig.isEarlyFlakeDetectionEnabled
654
1160
  earlyFlakeDetectionNumRetries = libraryConfig.earlyFlakeDetectionNumRetries
1161
+ earlyFlakeDetectionSlowTestRetries = libraryConfig.earlyFlakeDetectionSlowTestRetries ?? {}
655
1162
  earlyFlakeDetectionFaultyThreshold = libraryConfig.earlyFlakeDetectionFaultyThreshold
656
1163
  isFlakyTestRetriesEnabled = libraryConfig.isFlakyTestRetriesEnabled
657
1164
  flakyTestRetriesCount = libraryConfig.flakyTestRetriesCount
@@ -667,9 +1174,24 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
667
1174
  log.error('Playwright session start error', e)
668
1175
  }
669
1176
 
670
- 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) {
671
1192
  try {
672
- const { err, knownTests: receivedKnownTests } = await getChannelPromise(knownTestsCh)
1193
+ const { err, knownTests: receivedKnownTests } =
1194
+ knownTestsResponse || await getChannelPromise(knownTestsCh)
673
1195
  if (err) {
674
1196
  isEarlyFlakeDetectionEnabled = false
675
1197
  isKnownTestsEnabled = false
@@ -688,9 +1210,10 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
688
1210
  }
689
1211
  }
690
1212
 
691
- if (isTestManagementTestsEnabled && satisfies(playwrightVersion, MINIMUM_SUPPORTED_VERSION_RANGE_EFD)) {
1213
+ if (shouldGetTestManagementTests) {
692
1214
  try {
693
- const { err, testManagementTests: receivedTestManagementTests } = await getChannelPromise(testManagementTestsCh)
1215
+ const { err, testManagementTests: receivedTestManagementTests } =
1216
+ testManagementTestsResponse || await getChannelPromise(testManagementTestsCh)
694
1217
  if (err) {
695
1218
  isTestManagementTestsEnabled = false
696
1219
  } else {
@@ -702,7 +1225,7 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
702
1225
  }
703
1226
  }
704
1227
 
705
- if (isImpactedTestsEnabled && satisfies(playwrightVersion, MINIMUM_SUPPORTED_VERSION_RANGE_EFD)) {
1228
+ if (isImpactedTestsEnabled && isTestOptimizationSupported) {
706
1229
  try {
707
1230
  const { err, modifiedFiles: receivedModifiedFiles } = await getChannelPromise(modifiedFilesCh)
708
1231
  if (err) {
@@ -740,15 +1263,16 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
740
1263
  // there were tests that did not go through `testBegin` or `testEnd`,
741
1264
  // because they were skipped
742
1265
  for (const test of tests) {
1266
+ const alreadyReported = testsReportedInGenerateSummary.has(test)
743
1267
  const browser = getBrowserNameFromProjects(projects, test)
744
- testBeginHandler(test, browser, true)
1268
+ testBeginHandler(test, browser, !alreadyReported)
745
1269
  testEndHandler({
746
1270
  test,
747
1271
  annotations: [],
748
1272
  testStatus: 'skip',
749
1273
  error: null,
750
1274
  isTimeout: false,
751
- shouldCreateTestSpan: true,
1275
+ shouldCreateTestSpan: !alreadyReported,
752
1276
  projects,
753
1277
  })
754
1278
  }
@@ -760,7 +1284,6 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
760
1284
 
761
1285
  if (isTestManagementTestsEnabled && sessionStatus === 'failed') {
762
1286
  let totalFailedTestCount = 0
763
- let totalAttemptToFixFailedTestCount = 0
764
1287
  let totalPureQuarantinedFailedTestCount = 0
765
1288
 
766
1289
  for (const [fqn, testStatuses] of testsToTestStatuses.entries()) {
@@ -774,16 +1297,7 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
774
1297
  }
775
1298
  }
776
1299
 
777
- for (const test of quarantinedOrDisabledTestsAttemptToFix) {
778
- const testFqn = getTestFullyQualifiedName(test)
779
- const testStatuses = testsToTestStatuses.get(testFqn)
780
- // Only count as failed if the final status (after retries) is 'fail'
781
- if (testStatuses && testStatuses[testStatuses.length - 1] === 'fail') {
782
- totalAttemptToFixFailedTestCount += 1
783
- }
784
- }
785
-
786
- const totalIgnorableFailures = totalAttemptToFixFailedTestCount + totalPureQuarantinedFailedTestCount
1300
+ const totalIgnorableFailures = totalPureQuarantinedFailedTestCount
787
1301
 
788
1302
  if (totalFailedTestCount > 0 && totalFailedTestCount === totalIgnorableFailures) {
789
1303
  runAllTestsReturn = 'passed'
@@ -791,7 +1305,8 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
791
1305
  }
792
1306
  }
793
1307
 
794
- logDynamicNamesWarning(newTestsWithDynamicNames)
1308
+ logTestOptimizationSummary({ attemptToFixExecutions, newTestsWithDynamicNames })
1309
+ loggedAttemptToFixTests.clear()
795
1310
 
796
1311
  const flushWait = new Promise(resolve => {
797
1312
  onDone = resolve
@@ -808,6 +1323,17 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
808
1323
  startedSuites = []
809
1324
  remainingTestsByFile = {}
810
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()
811
1337
 
812
1338
  // TODO: we can trick playwright into thinking the session passed by returning
813
1339
  // 'passed' here. We might be able to use this for both EFD and Test Management tests.
@@ -834,6 +1360,85 @@ function runnerHookNew (runnerExport, playwrightVersion) {
834
1360
  return runnerExport
835
1361
  }
836
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
+
837
1442
  if (DD_MAJOR < 6) { // <1.38.0 is only supported up to version 5
838
1443
  addHook({
839
1444
  name: '@playwright/test',
@@ -866,28 +1471,40 @@ if (DD_MAJOR < 6) { // <1.38.0 is only supported up to version 5
866
1471
  }, runnerHook)
867
1472
  }
868
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
+
869
1486
  addHook({
870
1487
  name: 'playwright',
871
1488
  file: 'lib/runner/runner.js',
872
- versions: ['>=1.38.0'],
1489
+ versions: ['>=1.38.0 <1.60.0'],
873
1490
  }, runnerHook)
874
1491
 
875
1492
  addHook({
876
1493
  name: 'playwright',
877
1494
  file: 'lib/runner/testRunner.js',
878
- versions: ['>=1.55.0'],
1495
+ versions: ['>=1.55.0 <1.60.0'],
879
1496
  }, runnerHookNew)
880
1497
 
881
1498
  addHook({
882
1499
  name: 'playwright',
883
1500
  file: 'lib/runner/dispatcher.js',
884
- versions: ['>=1.38.0'],
1501
+ versions: ['>=1.38.0 <1.60.0'],
885
1502
  }, (dispatcher) => dispatcherHookNew(dispatcher, dispatcherRunWrapperNew))
886
1503
 
887
1504
  addHook({
888
1505
  name: 'playwright',
889
1506
  file: 'lib/common/suiteUtils.js',
890
- versions: ['>=1.38.0'],
1507
+ versions: ['>=1.38.0 <1.60.0'],
891
1508
  }, suiteUtilsPackage => {
892
1509
  // We grab `applyRepeatEachIndex` to use it later
893
1510
  // `applyRepeatEachIndex` needs to be applied to a cloned suite
@@ -909,159 +1526,196 @@ addHook({
909
1526
  * - we execute `applyRepeatEachIndex` for each of these cloned file suites
910
1527
  * - we add the cloned file suites to the project suite
911
1528
  */
912
- function applyRetriesToTests (fileSuitesWithTestsToRetry, filterTest, tagsToApply, numRetries) {
1529
+ function applyRetriesToTests (
1530
+ fileSuitesWithTestsToRetry,
1531
+ filterTest,
1532
+ tagsToApply,
1533
+ numRetries,
1534
+ configureCopiedTest,
1535
+ getRetryRepeatEachIndex
1536
+ ) {
913
1537
  for (const [fileSuite, projectSuite] of fileSuitesWithTestsToRetry.entries()) {
914
1538
  for (let repeatEachIndex = 1; repeatEachIndex <= numRetries; repeatEachIndex++) {
915
- const copyFileSuite = deepCloneSuite(fileSuite, filterTest, tagsToApply)
916
- 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)
917
1548
  projectSuite._addSuite(copyFileSuite)
1549
+ for (const copiedTest of copyFileSuite.allTests()) {
1550
+ registerEfdRetryTest(copiedTest)
1551
+ }
918
1552
  }
919
1553
  }
920
1554
  }
921
1555
 
922
- addHook({
923
- name: 'playwright',
924
- file: 'lib/runner/loadUtils.js',
925
- versions: ['>=1.38.0'],
926
- }, (loadUtilsPackage) => {
927
- const oldCreateRootSuite = loadUtilsPackage.createRootSuite
1556
+ function processRootSuite (createRootSuiteReturnValue) {
1557
+ if (!isKnownTestsEnabled && !isTestManagementTestsEnabled && !isImpactedTestsEnabled) {
1558
+ return createRootSuiteReturnValue
1559
+ }
928
1560
 
929
- async function newCreateRootSuite () {
930
- if (!isKnownTestsEnabled && !isTestManagementTestsEnabled && !isImpactedTestsEnabled) {
931
- return oldCreateRootSuite.apply(this, arguments)
932
- }
1561
+ if (!createRootSuiteReturnValue) {
1562
+ return createRootSuiteReturnValue
1563
+ }
933
1564
 
934
- const createRootSuiteReturnValue = await oldCreateRootSuite.apply(this, arguments)
935
- // From v1.56.0 on, createRootSuite returns `{ rootSuite, topLevelProjects }`
936
- const rootSuite = createRootSuiteReturnValue.rootSuite || createRootSuiteReturnValue
937
-
938
- const allTests = rootSuite.allTests()
939
-
940
- if (isTestManagementTestsEnabled) {
941
- const fileSuitesWithManagedTestsToProjects = new Map()
942
- for (const test of allTests) {
943
- const testProperties = getTestProperties(test)
944
- // Disabled tests are skipped unless they have attemptToFix
945
- if (testProperties.disabled) {
946
- test._ddIsDisabled = true
947
- if (!testProperties.attemptToFix) {
948
- test.expectedStatus = 'skipped'
949
- // setting test.expectedStatus to 'skipped' does not work for every case,
950
- // so we need to filter out disabled tests in dispatcherRunWrapperNew,
951
- // so they don't get to the workers
952
- continue
953
- }
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
954
1587
  }
955
- if (testProperties.quarantined) {
956
- test._ddIsQuarantined = true
957
- if (!testProperties.attemptToFix) {
958
- // Do not skip quarantined tests, let them run and overwrite results post-run if they fail
959
- const testFqn = getTestFullyQualifiedName(test)
960
- quarantinedButNotAttemptToFixFqns.add(testFqn)
961
- }
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)
962
1595
  }
963
- if (testProperties.attemptToFix) {
964
- test._ddIsAttemptToFix = true
965
- // Prevent ATR or `--retries` from retrying attemptToFix tests
966
- test.retries = 0
967
- const fileSuite = getSuiteType(test, 'file')
968
-
969
- if (!fileSuitesWithManagedTestsToProjects.has(fileSuite)) {
970
- fileSuitesWithManagedTestsToProjects.set(fileSuite, getSuiteType(test, 'project'))
971
- }
972
- if (testProperties.disabled || testProperties.quarantined) {
973
- quarantinedOrDisabledTestsAttemptToFix.push(test)
974
- }
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'))
975
1605
  }
976
1606
  }
977
- applyRetriesToTests(
978
- fileSuitesWithManagedTestsToProjects,
979
- (test) => test._ddIsAttemptToFix,
980
- [
981
- (test) => test._ddIsQuarantined && '_ddIsQuarantined',
982
- (test) => test._ddIsDisabled && '_ddIsDisabled',
983
- '_ddIsAttemptToFix',
984
- '_ddIsAttemptToFixRetry',
985
- ],
986
- testManagementAttemptToFixRetries
987
- )
988
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
+ }
989
1620
 
990
- if (isImpactedTestsEnabled) {
991
- const impactedTests = allTests.filter(test => {
992
- let isImpacted = false
993
- isModifiedCh.publish({
994
- filePath: test._requireFile,
995
- modifiedFiles,
996
- onDone: (isModified) => { isImpacted = isModified },
997
- })
998
- 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 },
999
1628
  })
1629
+ return isImpacted
1630
+ })
1000
1631
 
1001
- const fileSuitesWithImpactedTestsToProjects = new Map()
1002
- for (const impactedTest of impactedTests) {
1003
- impactedTest._ddIsModified = true
1004
- if (isEarlyFlakeDetectionEnabled && impactedTest.expectedStatus !== 'skipped') {
1005
- const fileSuite = getSuiteType(impactedTest, 'file')
1006
- if (!fileSuitesWithImpactedTestsToProjects.has(fileSuite)) {
1007
- fileSuitesWithImpactedTestsToProjects.set(fileSuite, getSuiteType(impactedTest, 'project'))
1008
- }
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'))
1009
1640
  }
1010
1641
  }
1011
- // If something change in the file, all tests in the file are impacted, hence the () => true filter
1012
- applyRetriesToTests(
1013
- fileSuitesWithImpactedTestsToProjects,
1014
- () => true,
1015
- [
1016
- '_ddIsModified',
1017
- '_ddIsEfdRetry',
1018
- (test) => (isKnownTestsEnabled && isNewTest(test) ? '_ddIsNew' : null),
1019
- ],
1020
- earlyFlakeDetectionNumRetries
1021
- )
1022
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
+ }
1023
1660
 
1024
- if (isKnownTestsEnabled) {
1025
- const newTests = allTests.filter(isNewTest)
1661
+ if (isKnownTestsEnabled) {
1662
+ const newTests = allTests.filter(isNewTest)
1026
1663
 
1027
- const isFaulty = getIsFaultyEarlyFlakeDetection(
1028
- allTests.map(test => getTestSuitePath(test._requireFile, rootDir)),
1029
- knownTests.playwright,
1030
- earlyFlakeDetectionFaultyThreshold
1031
- )
1664
+ const isFaulty = getIsFaultyEarlyFlakeDetection(
1665
+ allTests.map(test => getTestSuitePath(test._requireFile, rootDir)),
1666
+ knownTests.playwright,
1667
+ earlyFlakeDetectionFaultyThreshold
1668
+ )
1032
1669
 
1033
- if (isFaulty) {
1034
- isEarlyFlakeDetectionEnabled = false
1035
- isKnownTestsEnabled = false
1036
- isEarlyFlakeDetectionFaulty = true
1037
- } else {
1038
- const fileSuitesWithNewTestsToProjects = new Map()
1039
- for (const newTest of newTests) {
1040
- newTest._ddIsNew = true
1041
- if (isEarlyFlakeDetectionEnabled && newTest.expectedStatus !== 'skipped' && !newTest._ddIsModified) {
1042
- // Prevent ATR or `--retries` from retrying new tests if EFD is enabled
1043
- newTest.retries = 0
1044
- const fileSuite = getSuiteType(newTest, 'file')
1045
- if (!fileSuitesWithNewTestsToProjects.has(fileSuite)) {
1046
- fileSuitesWithNewTestsToProjects.set(fileSuite, getSuiteType(newTest, 'project'))
1047
- }
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'))
1048
1685
  }
1049
1686
  }
1050
-
1051
- applyRetriesToTests(
1052
- fileSuitesWithNewTestsToProjects,
1053
- isNewTest,
1054
- ['_ddIsNew', '_ddIsEfdRetry'],
1055
- earlyFlakeDetectionNumRetries
1056
- )
1057
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
+ )
1058
1700
  }
1701
+ }
1059
1702
 
1060
- 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))
1061
1715
  }
1062
1716
 
1063
1717
  // We need to proxy the createRootSuite function because the function is not configurable
1064
- const proxy = new Proxy(loadUtilsPackage, {
1718
+ return new Proxy(loadUtilsPackage, {
1065
1719
  get (target, prop) {
1066
1720
  if (prop === 'createRootSuite') {
1067
1721
  return newCreateRootSuite
@@ -1069,32 +1723,49 @@ addHook({
1069
1723
  return target[prop]
1070
1724
  },
1071
1725
  })
1072
-
1073
- return proxy
1074
1726
  })
1075
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
+
1076
1758
  // main process hook
1077
1759
  addHook({
1078
1760
  name: 'playwright',
1079
1761
  file: 'lib/runner/processHost.js',
1080
- versions: ['>=1.38.0'],
1762
+ versions: ['>=1.38.0 <1.60.0'],
1081
1763
  }, (processHostPackage) => {
1082
1764
  shimmer.wrap(processHostPackage.ProcessHost.prototype, 'startRunner', startRunner => async function () {
1083
- this._extraEnv = {
1084
- ...this._extraEnv,
1085
- // Used to detect that we're in a playwright worker
1086
- DD_PLAYWRIGHT_WORKER: '1',
1087
- }
1765
+ prepareProcessHostStartRunner(this)
1088
1766
 
1089
1767
  const res = await startRunner.apply(this, arguments)
1090
-
1091
- // We add a new listener to `this.process`, which is represents the worker
1092
- this.process.on('message', (message) => {
1093
- // These messages are [code, payload]. The payload is test data
1094
- if (Array.isArray(message) && message[0] === PLAYWRIGHT_WORKER_TRACE_PAYLOAD_CODE) {
1095
- workerReportCh.publish(message[1])
1096
- }
1097
- })
1768
+ finishProcessHostStartRunner(this)
1098
1769
 
1099
1770
  return res
1100
1771
  })
@@ -1102,43 +1773,36 @@ addHook({
1102
1773
  return processHostPackage
1103
1774
  })
1104
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
+
1105
1797
  addHook({
1106
1798
  name: 'playwright-core',
1107
1799
  file: 'lib/client/page.js',
1108
- versions: ['>=1.38.0'],
1800
+ versions: ['>=1.38.0 <1.60.0'],
1109
1801
  }, (pagePackage) => {
1110
1802
  shimmer.wrap(pagePackage.Page.prototype, 'goto', goto => async function (url, options) {
1111
1803
  const response = await goto.apply(this, arguments)
1112
1804
 
1113
- const page = this
1114
-
1115
- try {
1116
- if (page) {
1117
- const { isRumInstrumented, isRumActive, rumSamplingRate } = await page.evaluate(() => {
1118
- const isRumInstrumented = !!window.DD_RUM
1119
- const isRumActive = window.DD_RUM && window.DD_RUM.getInternalContext
1120
- ? !!window.DD_RUM.getInternalContext()
1121
- : false
1122
- const rumSamplingRate = window.DD_RUM && window.DD_RUM.getInitConfiguration
1123
- ? window.DD_RUM.getInitConfiguration().sessionSampleRate
1124
- : null
1125
- return { isRumInstrumented, isRumActive, rumSamplingRate }
1126
- })
1127
- if (isRumInstrumented && rumSamplingRate < 100 && !isRumActive) {
1128
- log.debug("RUM was detected on the page, but it isn't active because the sampling rate is below 100%")
1129
- }
1130
-
1131
- if (isRumActive) {
1132
- testPageGotoCh.publish({
1133
- isRumActive,
1134
- page,
1135
- })
1136
- }
1137
- }
1138
- } catch (e) {
1139
- // ignore errors such as redirects, context destroyed, etc
1140
- log.error('goto hook error', e)
1141
- }
1805
+ await handlePageGoto(this)
1142
1806
 
1143
1807
  return response
1144
1808
  })
@@ -1146,20 +1810,38 @@ addHook({
1146
1810
  return pagePackage
1147
1811
  })
1148
1812
 
1149
- // Only in worker
1150
- addHook({
1151
- name: 'playwright',
1152
- file: 'lib/worker/workerMain.js',
1153
- versions: ['>=1.38.0'],
1154
- }, (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
+
1155
1821
  // we assume there's only a test running at a time
1156
1822
  let steps = []
1157
1823
  const stepInfoByStepId = {}
1158
1824
 
1159
- 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
+ }
1160
1841
  if (test.expectedStatus === 'skipped') {
1161
1842
  return _runTest.apply(this, arguments)
1162
1843
  }
1844
+ test._ddStartTime = performance.now()
1163
1845
  steps = []
1164
1846
 
1165
1847
  const {
@@ -1186,6 +1868,27 @@ addHook({
1186
1868
  browserName,
1187
1869
  }
1188
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
+
1189
1892
  // TODO - In the future we may need to implement a mechanism to send test properties
1190
1893
  // to the worker process before _runTest is called
1191
1894
  testStartCh.runStores(testCtx, () => {
@@ -1206,17 +1909,11 @@ addHook({
1206
1909
  fn: async function ({ page }) {
1207
1910
  try {
1208
1911
  if (page) {
1209
- const isRumActive = await page.evaluate(() => {
1210
- if (window.DD_RUM && window.DD_RUM.stopSession) {
1211
- window.DD_RUM.stopSession()
1212
- return true
1213
- }
1214
- return false
1215
- })
1912
+ const isRumActive = await page.evaluate(stopRumSession)
1216
1913
 
1217
1914
  if (isRumActive) {
1218
1915
  // Give some time RUM to flush data, similar to what we do in selenium
1219
- await new Promise(resolve => setTimeout(resolve, RUM_FLUSH_WAIT_TIME))
1916
+ await new Promise(resolve => realSetTimeout(resolve, RUM_FLUSH_WAIT_TIME))
1220
1917
  const url = page.url()
1221
1918
  if (url) {
1222
1919
  const domain = new URL(url).hostname
@@ -1248,6 +1945,31 @@ addHook({
1248
1945
  await res
1249
1946
 
1250
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
+ }
1251
1973
 
1252
1974
  // testInfo.errors could be better than "error",
1253
1975
  // which will only include timeout error (even though the test failed because of a different error)
@@ -1263,26 +1985,30 @@ addHook({
1263
1985
  onDone = resolve
1264
1986
  })
1265
1987
 
1266
- // Wait for ddProperties to be received and processed
1267
- // Create a promise that will be resolved when the properties are received
1268
- const ddPropertiesPromise = new Promise(resolve => {
1269
- const messageHandler = ({ type, testId, properties }) => {
1270
- if (type === 'ddProperties' && testId === test.id) {
1271
- // Apply the properties to the test object
1272
- if (properties) {
1273
- Object.assign(test, properties)
1274
- }
1275
- process.removeListener('message', messageHandler)
1276
- resolve()
1277
- }
1278
- }
1279
-
1280
- // Add the listener
1281
- 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
+ })
1282
1997
  })
1998
+ await Promise.race([ddPropertiesPromise, ddPropertiesTimeoutPromise])
1283
1999
 
1284
- // Wait for the properties to be received
1285
- 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
+ })
1286
2012
 
1287
2013
  testFinishCh.publish({
1288
2014
  testStatus: STATUS_TO_TEST_STATUS[status],
@@ -1303,6 +2029,8 @@ addHook({
1303
2029
  isAtrRetry: test._ddIsAtrRetry,
1304
2030
  isModified: test._ddIsModified,
1305
2031
  onDone,
2032
+ finalStatus,
2033
+ earlyFlakeAbortReason: test._ddEarlyFlakeAbortReason,
1306
2034
  ...testCtx.currentStore,
1307
2035
  })
1308
2036
 
@@ -1313,7 +2041,7 @@ addHook({
1313
2041
 
1314
2042
  // We reproduce what happens in `Dispatcher#_onStepBegin` and `Dispatcher#_onStepEnd`,
1315
2043
  // since `startTime` and `duration` are not available directly in the worker process
1316
- shimmer.wrap(workerPackage.WorkerMain.prototype, 'dispatchEvent', dispatchEvent => function (event, payload) {
2044
+ shimmer.wrap(workerMain, 'dispatchEvent', dispatchEvent => function (event, payload) {
1317
2045
  if (event === 'stepBegin') {
1318
2046
  stepInfoByStepId[payload.stepId] = {
1319
2047
  startTime: payload.wallTime,
@@ -1334,16 +2062,27 @@ addHook({
1334
2062
  return dispatchEvent.apply(this, arguments)
1335
2063
  })
1336
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)
1337
2075
  return workerPackage
1338
2076
  })
1339
2077
 
1340
2078
  function generateSummaryWrapper (generateSummary) {
1341
- return function () {
2079
+ return function (...args) {
1342
2080
  for (const test of this.suite.allTests()) {
1343
2081
  // https://github.com/microsoft/playwright/blob/bf92ffecff6f30a292b53430dbaee0207e0c61ad/packages/playwright/src/reporters/base.ts#L279
1344
- const didNotRun = test.outcome() === 'skipped' &&
1345
- (!test.results.length || test.expectedStatus !== 'skipped')
1346
- 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)
1347
2086
  const {
1348
2087
  _requireFile: testSuiteAbsolutePath,
1349
2088
  location: {
@@ -1370,7 +2109,7 @@ function generateSummaryWrapper (generateSummary) {
1370
2109
  })
1371
2110
  }
1372
2111
  }
1373
- return generateSummary.apply(this, arguments)
2112
+ return generateSummary.apply(this, args)
1374
2113
  }
1375
2114
  }
1376
2115
 
@@ -1381,7 +2120,7 @@ function generateSummaryWrapper (generateSummary) {
1381
2120
  addHook({
1382
2121
  name: 'playwright',
1383
2122
  file: 'lib/reporters/base.js',
1384
- versions: ['>=1.38.0'],
2123
+ versions: ['>=1.38.0 <1.60.0'],
1385
2124
  }, (reportersPackage) => {
1386
2125
  // v1.50.0 changed the name of the base reporter from BaseReporter to TerminalReporter
1387
2126
  if (reportersPackage.TerminalReporter) {