@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,21 +1,30 @@
1
1
  'use strict'
2
2
 
3
3
  const { createCoverageMap } = require('../../../../vendor/dist/istanbul-lib-coverage')
4
+ const satisfies = require('../../../../vendor/dist/semifies')
5
+ const { DD_MAJOR } = require('../../../../version')
4
6
  const { addHook, channel } = require('../helpers/instrument')
5
7
  const shimmer = require('../../../datadog-shimmer')
6
8
  const { isMarkedAsUnskippable } = require('../../../datadog-plugin-jest/src/util')
9
+ const { writeCoverageBackfillToCache } = require('../../../dd-trace/src/ci-visibility/test-optimization-cache')
7
10
  const log = require('../../../dd-trace/src/log')
8
11
  const { getEnvironmentVariable } = require('../../../dd-trace/src/config/helper')
9
12
  const {
10
13
  getTestSuitePath,
11
14
  MOCHA_WORKER_TRACE_PAYLOAD_CODE,
12
15
  fromCoverageMapToCoverage,
13
- getCoveredFilenamesFromCoverage,
16
+ getCoveredFilesFromCoverage,
17
+ getExecutableFilesFromCoverage,
18
+ applySkippedCoverageToCoverage,
14
19
  mergeCoverage,
15
20
  resetCoverage,
16
21
  getIsFaultyEarlyFlakeDetection,
17
- collectDynamicNamesFromTraces,
18
- logDynamicNamesWarning,
22
+ getRelativeCoverageFiles,
23
+ getTestCoverageLinesPercentage,
24
+ collectTestOptimizationSummariesFromTraces,
25
+ logTestOptimizationSummary,
26
+ getTestOptimizationRequestResults,
27
+ isModifiedTest,
19
28
  } = require('../../../dd-trace/src/plugins/util/test')
20
29
 
21
30
  const {
@@ -27,26 +36,33 @@ const {
27
36
  getOnTestEndHandler,
28
37
  getOnTestRetryHandler,
29
38
  getOnHookEndHandler,
39
+ patchFailedTestReplayHookUp,
30
40
  getOnFailHandler,
31
41
  getOnPendingHandler,
32
42
  testFileToSuiteCtx,
33
43
  newTests,
44
+ efdTests,
34
45
  testsQuarantined,
35
46
  getTestFullName,
36
47
  getRunTestsWrapper,
37
- testsAttemptToFix,
38
- testsStatuses,
39
48
  newTestsWithDynamicNames,
49
+ attemptToFixExecutions,
50
+ loggedAttemptToFixTests,
40
51
  } = require('./utils')
41
52
 
42
53
  require('./common')
43
54
 
55
+ const MINIMUM_MOCHA_VERSION = DD_MAJOR >= 6 ? '>=8.0.0' : '>=5.2.0'
56
+
44
57
  const patched = new WeakSet()
58
+ let hasWarnedDeprecatedMochaVersion = false
45
59
 
46
60
  const unskippableSuites = []
47
61
  let suitesToSkip = []
48
62
  let isSuitesSkipped = false
49
63
  let skippedSuites = []
64
+ let skippableSuitesCoverage = {}
65
+ let skippedSuitesCoverage = {}
50
66
  let itrCorrelationId = ''
51
67
  let isForcedToRun = false
52
68
  const config = {}
@@ -79,6 +95,20 @@ const itrSkippedSuitesCh = channel('ci:mocha:itr:skipped-suites')
79
95
 
80
96
  const getCodeCoverageCh = channel('ci:nyc:get-coverage')
81
97
 
98
+ function warnDeprecatedMochaVersion (frameworkVersion) {
99
+ if (DD_MAJOR >= 6 || hasWarnedDeprecatedMochaVersion || !frameworkVersion ||
100
+ !satisfies(frameworkVersion, '<8.0.0')) {
101
+ return
102
+ }
103
+
104
+ hasWarnedDeprecatedMochaVersion = true
105
+ // eslint-disable-next-line no-console
106
+ console.warn(
107
+ 'dd-trace support for Mocha<8.0.0 is deprecated and will be removed in dd-trace v6. ' +
108
+ 'Please upgrade Mocha to >=8.0.0.'
109
+ )
110
+ }
111
+
82
112
  // Tests from workers do not come with `isFailed` method
83
113
  function isTestFailed (test) {
84
114
  if (test.isFailed) {
@@ -90,10 +120,56 @@ function isTestFailed (test) {
90
120
  return false
91
121
  }
92
122
 
123
+ function getRootSuiteStatus (rootTests) {
124
+ let status = 'pass'
125
+ if (rootTests.every(t => t.isPending())) {
126
+ status = 'skip'
127
+ } else {
128
+ for (const test of rootTests) {
129
+ if (test.state === 'failed' || test.timedOut || test._ddHookFailed) {
130
+ status = 'fail'
131
+ }
132
+ }
133
+ }
134
+ return status
135
+ }
136
+
137
+ function haveRootTestsFinished (rootTests) {
138
+ for (const test of rootTests) {
139
+ if (!test.isPending() && !test.state && !test.timedOut && !test._ddHookFailed) {
140
+ return false
141
+ }
142
+ }
143
+ return true
144
+ }
145
+
146
+ function getSuitePath (suite) {
147
+ return getTestSuitePath(suite.file, process.cwd())
148
+ }
149
+
150
+ function getSuitesToSkip (originalSuites) {
151
+ return getSuitesToSkipFromPaths(originalSuites.map(getSuitePath))
152
+ }
153
+
154
+ function getSuitesToSkipFromPaths (localSuites) {
155
+ const localSuitesSet = new Set(localSuites)
156
+ const suitesToSkipForRun = []
157
+
158
+ for (const suite of suitesToSkip) {
159
+ if (localSuitesSet.has(suite)) {
160
+ suitesToSkipForRun.push(suite)
161
+ }
162
+ }
163
+
164
+ return suitesToSkipForRun
165
+ }
166
+
93
167
  function getFilteredSuites (originalSuites) {
168
+ const suitesToSkipForRun = getSuitesToSkip(originalSuites)
169
+
94
170
  return originalSuites.reduce((acc, suite) => {
95
- const testPath = getTestSuitePath(suite.file, process.cwd())
96
- const shouldSkip = suitesToSkip.includes(testPath)
171
+ const testPath = getSuitePath(suite)
172
+ const shouldSkip = suitesToSkipForRun.includes(testPath)
97
173
  const isUnskippable = unskippableSuites.includes(suite.file)
98
174
  if (shouldSkip && !isUnskippable) {
99
175
  acc.skippedSuites.add(testPath)
@@ -101,7 +177,67 @@ function getFilteredSuites (originalSuites) {
101
177
  acc.suitesToRun.push(suite)
102
178
  }
103
179
  return acc
104
- }, { suitesToRun: [], skippedSuites: new Set() })
180
+ }, { suitesToRun: [], skippedSuites: new Set(), suitesToSkipForRun })
181
+ }
182
+
183
+ function hasSkippableSuitesCoverage () {
184
+ return skippableSuitesCoverage &&
185
+ typeof skippableSuitesCoverage === 'object' &&
186
+ Object.keys(skippableSuitesCoverage).length > 0
187
+ }
188
+
189
+ function isTiaCoverageBackfillEnabled () {
190
+ return config.isItrEnabled && config.isCoverageReportUploadEnabled
191
+ }
192
+
193
+ function getCoverageRootDir () {
194
+ return config.repositoryRoot || process.cwd()
195
+ }
196
+
197
+ /**
198
+ * Recomputes whether a parallel worker result belongs to a modified suite.
199
+ *
200
+ * In parallel mode, `_ddIsModified` is set on Mocha Test objects inside the worker.
201
+ * The main process receives `Test.prototype.serialize()` output for test events,
202
+ * and that fixed serialization drops custom properties. We still need modified-test
203
+ * bookkeeping in the main process for EFD failure suppression, so infer it again
204
+ * from the suite path.
205
+ *
206
+ * @param {string} testSuiteAbsolutePath
207
+ * @returns {boolean}
208
+ */
209
+ function isModifiedTestSuite (testSuiteAbsolutePath) {
210
+ const testPath = getTestSuitePath(testSuiteAbsolutePath, getCoverageRootDir())
211
+ return isModifiedTest(testPath, null, null, config.modifiedFiles, 'mocha')
212
+ }
213
+
214
+ function shouldReportCodeCoverageLinesPct (hasBackfilledCoverage) {
215
+ return !isSuitesSkipped || hasBackfilledCoverage
216
+ }
217
+
218
+ function getSkippedSuitesCoverageForRun () {
219
+ return isSuitesSkipped && isTiaCoverageBackfillEnabled() && hasSkippableSuitesCoverage()
220
+ ? skippableSuitesCoverage
221
+ : {}
222
+ }
223
+
224
+ function applySkippedCoverageToMochaCoverageMap () {
225
+ if (!isTiaCoverageBackfillEnabled()) return false
226
+ return applySkippedCoverageToCoverage(originalCoverageMap, skippedSuitesCoverage, getCoverageRootDir())
227
+ }
228
+
229
+ function getMochaTestSessionCoverageFiles () {
230
+ return getRelativeCoverageFiles(getExecutableFilesFromCoverage(originalCoverageMap), getCoverageRootDir())
231
+ }
232
+
233
+ function resetSuiteSkippingRunState () {
234
+ isSuitesSkipped = false
235
+ skippedSuites = []
236
+ skippableSuitesCoverage = {}
237
+ skippedSuitesCoverage = {}
238
+ untestedCoverage = undefined
239
+ config.repositoryRoot = undefined
240
+ writeCoverageBackfillToCache({})
105
241
  }
106
242
 
107
243
  function getOnStartHandler (frameworkVersion) {
@@ -136,36 +272,28 @@ function getOnEndHandler (isParallel) {
136
272
  * The rationale behind is the following: you may still be able to block your CI pipeline by gating
137
273
  * on flakiness (the test will be considered flaky), but you may choose to unblock the pipeline too.
138
274
  */
139
- for (const tests of Object.values(newTests)) {
140
- const failingNewTests = tests.filter(test => isTestFailed(test))
141
- const areAllNewTestsFailing = failingNewTests.length === tests.length
142
- if (failingNewTests.length && !areAllNewTestsFailing) {
143
- this.stats.failures -= failingNewTests.length
144
- this.failures -= failingNewTests.length
275
+ for (const tests of Object.values(efdTests)) {
276
+ const failingEfdTests = tests.filter(test => isTestFailed(test))
277
+ const areAllEfdTestsFailing = failingEfdTests.length === tests.length
278
+ const nonQuarantinedFailingEfdTests = failingEfdTests.filter(test => !testsQuarantined.has(test))
279
+ if (nonQuarantinedFailingEfdTests.length && !areAllEfdTestsFailing) {
280
+ this.stats.failures -= nonQuarantinedFailingEfdTests.length
281
+ this.failures -= nonQuarantinedFailingEfdTests.length
145
282
  }
146
283
  }
147
284
  }
148
285
 
149
- // We substract the errors of attempt to fix tests (quarantined or disabled) from the total number of failures
150
- // We subtract the errors from quarantined tests from the total number of failures
286
+ // We subtract the errors from quarantined tests from the total number of failures.
287
+ // Attempt-to-fix tests ignore quarantine/disabled suppression and keep their framework result.
151
288
  if (config.isTestManagementTestsEnabled) {
152
289
  let numFailedQuarantinedTests = 0
153
- let numFailedRetriedQuarantinedOrDisabledTests = 0
154
- for (const test of testsAttemptToFix) {
155
- const testName = getTestFullName(test)
156
- const testProperties = getTestProperties(test, config.testManagementTests)
157
- if (isTestFailed(test) && (testProperties.isQuarantined || testProperties.isDisabled)) {
158
- const numFailedTests = testsStatuses.get(testName).filter(status => status === 'fail').length
159
- numFailedRetriedQuarantinedOrDisabledTests += numFailedTests
160
- }
161
- }
162
290
  for (const test of testsQuarantined) {
163
291
  if (isTestFailed(test)) {
164
292
  numFailedQuarantinedTests++
165
293
  }
166
294
  }
167
- this.stats.failures -= numFailedQuarantinedTests + numFailedRetriedQuarantinedOrDisabledTests
168
- this.failures -= numFailedQuarantinedTests + numFailedRetriedQuarantinedOrDisabledTests
295
+ this.stats.failures -= numFailedQuarantinedTests
296
+ this.failures -= numFailedQuarantinedTests
169
297
  }
170
298
 
171
299
  // Recompute status after EFD and quarantine adjustments have reduced failure counts
@@ -184,12 +312,24 @@ function getOnEndHandler (isParallel) {
184
312
  testFileToSuiteCtx.clear()
185
313
 
186
314
  let testCodeCoverageLinesTotal
187
- if (global.__coverage__) {
315
+ let testSessionCoverageFiles
316
+ if (global.__coverage__ || untestedCoverage) {
188
317
  try {
318
+ let hasBackfilledCoverage = false
189
319
  if (untestedCoverage) {
190
320
  originalCoverageMap.merge(fromCoverageMapToCoverage(untestedCoverage))
191
321
  }
192
- testCodeCoverageLinesTotal = originalCoverageMap.getCoverageSummary().lines.pct
322
+ hasBackfilledCoverage = applySkippedCoverageToMochaCoverageMap()
323
+ if (shouldReportCodeCoverageLinesPct(hasBackfilledCoverage)) {
324
+ testCodeCoverageLinesTotal = getTestCoverageLinesPercentage(
325
+ originalCoverageMap,
326
+ undefined,
327
+ getCoverageRootDir()
328
+ )
329
+ }
330
+ if (isTiaCoverageBackfillEnabled()) {
331
+ testSessionCoverageFiles = getMochaTestSessionCoverageFiles()
332
+ }
193
333
  } catch {
194
334
  // ignore errors
195
335
  }
@@ -201,6 +341,7 @@ function getOnEndHandler (isParallel) {
201
341
  status,
202
342
  isSuitesSkipped,
203
343
  testCodeCoverageLinesTotal,
344
+ testSessionCoverageFiles,
204
345
  numSkippedSuites: skippedSuites.length,
205
346
  hasForcedToRunSuites: isForcedToRun,
206
347
  hasUnskippableSuites: !!unskippableSuites.length,
@@ -211,26 +352,74 @@ function getOnEndHandler (isParallel) {
211
352
  isParallel,
212
353
  })
213
354
 
214
- logDynamicNamesWarning(newTestsWithDynamicNames)
355
+ logTestOptimizationSummary({ attemptToFixExecutions, newTestsWithDynamicNames })
356
+ loggedAttemptToFixTests.clear()
357
+ }
358
+ }
359
+
360
+ function getRunStoresPromise (channelToPublishTo, ctx) {
361
+ return new Promise(resolve => {
362
+ channelToPublishTo.runStores({ ...ctx, onDone: resolve }, () => {})
363
+ })
364
+ }
365
+
366
+ function applyKnownTestsResponse ({ err, knownTests }) {
367
+ if (err) {
368
+ config.knownTests = []
369
+ config.isEarlyFlakeDetectionEnabled = false
370
+ config.isKnownTestsEnabled = false
371
+ } else {
372
+ config.knownTests = knownTests
373
+ }
374
+ }
375
+
376
+ function applyTestManagementTestsResponse ({ err, testManagementTests: receivedTestManagementTests }) {
377
+ if (err) {
378
+ config.testManagementTests = {}
379
+ config.isTestManagementTestsEnabled = false
380
+ config.testManagementAttemptToFixRetries = 0
381
+ } else {
382
+ config.testManagementTests = receivedTestManagementTests
215
383
  }
216
384
  }
217
385
 
218
- function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFinishRequest) {
386
+ function isFailedTestReplayEnabled () {
387
+ return config.isTestDynamicInstrumentationEnabled && config.isDiEnabled
388
+ }
389
+
390
+ function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFinishRequest, localSuites) {
219
391
  const ctx = {
220
392
  isParallel,
221
393
  frameworkVersion,
222
394
  }
223
-
224
- const onReceivedSkippableSuites = ({ err, skippableSuites, itrCorrelationId: responseItrCorrelationId }) => {
395
+ let skippableSuitesResponse
396
+ resetSuiteSkippingRunState()
397
+
398
+ const onReceivedSkippableSuites = ({
399
+ err,
400
+ skippableSuites,
401
+ itrCorrelationId: responseItrCorrelationId,
402
+ skippableSuitesCoverage: responseSkippableSuitesCoverage,
403
+ }) => {
225
404
  if (err) {
226
405
  suitesToSkip = []
406
+ skippableSuitesCoverage = {}
227
407
  } else {
228
408
  suitesToSkip = skippableSuites
229
409
  itrCorrelationId = responseItrCorrelationId
410
+ skippableSuitesCoverage = responseSkippableSuitesCoverage || {}
230
411
  }
412
+ if (localSuites) {
413
+ suitesToSkip = getSuitesToSkipFromPaths(localSuites)
414
+ mochaGlobalRunCh.runStores(ctx, () => {
415
+ onFinishRequest()
416
+ })
417
+ return
418
+ }
419
+
231
420
  // We remove the suites that we skip through ITR
232
421
  const filteredSuites = getFilteredSuites(runner.suite.suites)
233
- const { suitesToRun } = filteredSuites
422
+ const { suitesToRun, suitesToSkipForRun } = filteredSuites
234
423
 
235
424
  isSuitesSkipped = suitesToRun.length !== runner.suite.suites.length
236
425
 
@@ -239,12 +428,25 @@ function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFini
239
428
  runner.suite.suites = suitesToRun
240
429
 
241
430
  skippedSuites = [...filteredSuites.skippedSuites]
431
+ suitesToSkip = suitesToSkipForRun
432
+ skippedSuitesCoverage = getSkippedSuitesCoverageForRun()
433
+ writeCoverageBackfillToCache(skippedSuitesCoverage, getCoverageRootDir())
242
434
 
243
435
  mochaGlobalRunCh.runStores(ctx, () => {
244
436
  onFinishRequest()
245
437
  })
246
438
  }
247
439
 
440
+ const requestSkippableSuites = () => {
441
+ if (skippableSuitesResponse) {
442
+ onReceivedSkippableSuites(skippableSuitesResponse)
443
+ return
444
+ }
445
+
446
+ ctx.onDone = onReceivedSkippableSuites
447
+ skippableSuitesCh.runStores(ctx, () => {})
448
+ }
449
+
248
450
  const onReceivedImpactedTests = ({ err, modifiedFiles: receivedModifiedFiles }) => {
249
451
  if (err) {
250
452
  config.modifiedFiles = []
@@ -253,8 +455,7 @@ function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFini
253
455
  config.modifiedFiles = receivedModifiedFiles
254
456
  }
255
457
  if (config.isSuitesSkippingEnabled) {
256
- ctx.onDone = onReceivedSkippableSuites
257
- skippableSuitesCh.runStores(ctx, () => {})
458
+ requestSkippableSuites()
258
459
  } else {
259
460
  mochaGlobalRunCh.runStores(ctx, () => {
260
461
  onFinishRequest()
@@ -262,20 +463,12 @@ function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFini
262
463
  }
263
464
  }
264
465
 
265
- const onReceivedTestManagementTests = ({ err, testManagementTests: receivedTestManagementTests }) => {
266
- if (err) {
267
- config.testManagementTests = {}
268
- config.isTestManagementTestsEnabled = false
269
- config.testManagementAttemptToFixRetries = 0
270
- } else {
271
- config.testManagementTests = receivedTestManagementTests
272
- }
466
+ const continueAfterTestRequests = () => {
273
467
  if (config.isImpactedTestsEnabled) {
274
468
  ctx.onDone = onReceivedImpactedTests
275
469
  modifiedFilesCh.runStores(ctx, () => {})
276
470
  } else if (config.isSuitesSkippingEnabled) {
277
- ctx.onDone = onReceivedSkippableSuites
278
- skippableSuitesCh.runStores(ctx, () => {})
471
+ requestSkippableSuites()
279
472
  } else {
280
473
  mochaGlobalRunCh.runStores(ctx, () => {
281
474
  onFinishRequest()
@@ -283,64 +476,54 @@ function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFini
283
476
  }
284
477
  }
285
478
 
286
- const onReceivedKnownTests = ({ err, knownTests }) => {
287
- if (err) {
288
- config.knownTests = []
289
- config.isEarlyFlakeDetectionEnabled = false
290
- config.isKnownTestsEnabled = false
291
- } else {
292
- config.knownTests = knownTests
293
- }
294
- if (config.isTestManagementTestsEnabled) {
295
- ctx.onDone = onReceivedTestManagementTests
296
- testManagementTestsCh.runStores(ctx, () => {})
297
- } else if (config.isImpactedTestsEnabled) {
298
- ctx.onDone = onReceivedImpactedTests
299
- modifiedFilesCh.runStores(ctx, () => {})
300
- } else if (config.isSuitesSkippingEnabled) {
301
- ctx.onDone = onReceivedSkippableSuites
302
- skippableSuitesCh.runStores(ctx, () => {})
303
- } else {
304
- mochaGlobalRunCh.runStores(ctx, () => {
305
- onFinishRequest()
306
- })
307
- }
308
- }
309
-
310
- const onReceivedConfiguration = ({ err, libraryConfig }) => {
479
+ const onReceivedConfiguration = ({ err, isTestDynamicInstrumentationEnabled, libraryConfig, repositoryRoot }) => {
311
480
  if (err || !skippableSuitesCh.hasSubscribers || !knownTestsCh.hasSubscribers) {
312
481
  return mochaGlobalRunCh.runStores(ctx, () => {
313
482
  onFinishRequest()
314
483
  })
315
484
  }
485
+ config.repositoryRoot = repositoryRoot
316
486
  config.isEarlyFlakeDetectionEnabled = libraryConfig.isEarlyFlakeDetectionEnabled
317
487
  config.earlyFlakeDetectionNumRetries = libraryConfig.earlyFlakeDetectionNumRetries
488
+ config.earlyFlakeDetectionSlowTestRetries = libraryConfig.earlyFlakeDetectionSlowTestRetries ?? {}
318
489
  config.earlyFlakeDetectionFaultyThreshold = libraryConfig.earlyFlakeDetectionFaultyThreshold
319
490
  config.isKnownTestsEnabled = libraryConfig.isKnownTestsEnabled
320
491
  config.isTestManagementTestsEnabled = libraryConfig.isTestManagementEnabled
321
492
  config.testManagementAttemptToFixRetries = libraryConfig.testManagementAttemptToFixRetries
322
493
  config.isImpactedTestsEnabled = libraryConfig.isImpactedTestsEnabled
323
- config.isSuitesSkippingEnabled = libraryConfig.isSuitesSkippingEnabled
494
+ config.isItrEnabled = libraryConfig.isItrEnabled
495
+ config.isCodeCoverageEnabled = libraryConfig.isCodeCoverageEnabled
496
+ config.isCoverageReportUploadEnabled = libraryConfig.isCoverageReportUploadEnabled
497
+ config.isSuitesSkippingEnabled = config.isItrEnabled && libraryConfig.isSuitesSkippingEnabled
324
498
  config.isFlakyTestRetriesEnabled = libraryConfig.isFlakyTestRetriesEnabled
325
499
  config.flakyTestRetriesCount = libraryConfig.flakyTestRetriesCount
500
+ config.isDiEnabled = libraryConfig.isDiEnabled
501
+ config.isTestDynamicInstrumentationEnabled = isTestDynamicInstrumentationEnabled
502
+
503
+ getTestOptimizationRequestResults({
504
+ isKnownTestsEnabled: config.isKnownTestsEnabled,
505
+ isTestManagementTestsEnabled: config.isTestManagementTestsEnabled,
506
+ isSuitesSkippingEnabled: config.isSuitesSkippingEnabled,
507
+ getKnownTests: () => getRunStoresPromise(knownTestsCh, ctx),
508
+ getTestManagementTests: () => getRunStoresPromise(testManagementTestsCh, ctx),
509
+ getSkippableSuites: () => getRunStoresPromise(skippableSuitesCh, ctx),
510
+ }).then(requestResults => {
511
+ const {
512
+ knownTestsResponse,
513
+ testManagementTestsResponse,
514
+ skippableSuitesResponse: requestSkippableSuitesResponse,
515
+ } = requestResults
516
+
517
+ if (knownTestsResponse) {
518
+ applyKnownTestsResponse(knownTestsResponse)
519
+ }
520
+ if (testManagementTestsResponse) {
521
+ applyTestManagementTestsResponse(testManagementTestsResponse)
522
+ }
523
+ skippableSuitesResponse = requestSkippableSuitesResponse
326
524
 
327
- if (config.isKnownTestsEnabled) {
328
- ctx.onDone = onReceivedKnownTests
329
- knownTestsCh.runStores(ctx, () => {})
330
- } else if (config.isTestManagementTestsEnabled) {
331
- ctx.onDone = onReceivedTestManagementTests
332
- testManagementTestsCh.runStores(ctx, () => {})
333
- } else if (config.isImpactedTestsEnabled) {
334
- ctx.onDone = onReceivedImpactedTests
335
- modifiedFilesCh.runStores(ctx, () => {})
336
- } else if (config.isSuitesSkippingEnabled) {
337
- ctx.onDone = onReceivedSkippableSuites
338
- skippableSuitesCh.runStores(ctx, () => {})
339
- } else {
340
- mochaGlobalRunCh.runStores(ctx, () => {
341
- onFinishRequest()
342
- })
343
- }
525
+ continueAfterTestRequests()
526
+ })
344
527
  }
345
528
 
346
529
  ctx.onDone = onReceivedConfiguration
@@ -353,20 +536,22 @@ function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFini
353
536
  // It is called but skipped in parallel mode.
354
537
  addHook({
355
538
  name: 'mocha',
356
- versions: ['>=5.2.0'],
539
+ versions: [MINIMUM_MOCHA_VERSION],
357
540
  file: 'lib/mocha.js',
358
541
  }, (Mocha, frameworkVersion) => {
359
- shimmer.wrap(Mocha.prototype, 'run', run => function () {
542
+ warnDeprecatedMochaVersion(frameworkVersion)
543
+
544
+ shimmer.wrap(Mocha.prototype, 'run', run => function (...args) {
360
545
  // Workers do not need to request any data, just run the tests
361
546
  if (!testFinishCh.hasSubscribers || getEnvironmentVariable('MOCHA_WORKER_ID') || this.options.parallel) {
362
- return run.apply(this, arguments)
547
+ return run.apply(this, args)
363
548
  }
364
549
 
365
550
  // `options.delay` does not work in parallel mode, so we can't delay the execution this way
366
551
  // This needs to be both here and in `runMocha` hook. Read the comment in `runMocha` hook for more info.
367
552
  this.options.delay = true
368
553
 
369
- const runner = run.apply(this, arguments)
554
+ const runner = run.apply(this, args)
370
555
 
371
556
  // eslint-disable-next-line unicorn/no-array-for-each
372
557
  this.files.forEach((path) => {
@@ -377,6 +562,9 @@ addHook({
377
562
  })
378
563
 
379
564
  getExecutionConfiguration(runner, false, frameworkVersion, () => {
565
+ if (isFailedTestReplayEnabled()) {
566
+ patchFailedTestReplayHookUp(runner.constructor)
567
+ }
380
568
  if (config.isKnownTestsEnabled) {
381
569
  const testSuites = this.files.map(file => getTestSuitePath(file, process.cwd()))
382
570
  const isFaulty = getIsFaultyEarlyFlakeDetection(
@@ -409,15 +597,15 @@ addHook({
409
597
 
410
598
  addHook({
411
599
  name: 'mocha',
412
- versions: ['>=5.2.0'],
600
+ versions: [MINIMUM_MOCHA_VERSION],
413
601
  file: 'lib/cli/run-helpers.js',
414
602
  }, (run) => {
415
603
  // `runMocha` is an async function
416
- shimmer.wrap(run, 'runMocha', runMocha => function () {
604
+ shimmer.wrap(run, 'runMocha', runMocha => function (...args) {
417
605
  if (!testFinishCh.hasSubscribers) {
418
- return runMocha.apply(this, arguments)
606
+ return runMocha.apply(this, args)
419
607
  }
420
- const mocha = arguments[0]
608
+ const mocha = args[0]
421
609
 
422
610
  /**
423
611
  * This attaches `run` to the global context, which we'll call after
@@ -431,7 +619,7 @@ addHook({
431
619
  mocha.options.delay = true
432
620
  }
433
621
 
434
- return runMocha.apply(this, arguments)
622
+ return runMocha.apply(this, args)
435
623
  })
436
624
  return run
437
625
  })
@@ -440,7 +628,7 @@ addHook({
440
628
  // This hook is used to generate session, module, suite and test events
441
629
  addHook({
442
630
  name: 'mocha',
443
- versions: ['>=5.2.0'],
631
+ versions: [MINIMUM_MOCHA_VERSION],
444
632
  file: 'lib/runner.js',
445
633
  }, function (Runner, frameworkVersion) {
446
634
  if (patched.has(Runner)) return Runner
@@ -449,32 +637,216 @@ addHook({
449
637
 
450
638
  shimmer.wrap(Runner.prototype, 'runTests', runTests => getRunTestsWrapper(runTests, config))
451
639
 
452
- shimmer.wrap(Runner.prototype, 'run', run => function () {
640
+ shimmer.wrap(Runner.prototype, 'run', run => function (...args) {
453
641
  if (!testFinishCh.hasSubscribers) {
454
- return run.apply(this, arguments)
642
+ return run.apply(this, args)
455
643
  }
456
644
 
457
645
  const { suitesByTestFile, numSuitesByTestFile } = getSuitesByTestFile(this.suite)
646
+ // Root-level tests (direct children of root, no describe wrapper) keyed by file.
647
+ // Populated during the root 'suite' event so the normal finish path can include them
648
+ // in mixed-file status calculation.
649
+ const rootTestsByFile = new Map()
650
+ // Counts how many original tests per pure-root file still need their final attempt.
651
+ // Hits zero when the last test's lifecycle completes, triggering the suite finish.
652
+ const rootPendingCountByFile = new Map()
653
+ const rootFinalizationPendingCountByFile = new Map()
654
+ const rootFallbackPendingFiles = new Set()
655
+ const rootFinalizationPendingTests = new WeakSet()
656
+ let pendingRootFinalizations = 0
657
+ let hasEnded = false
658
+ let hasFinishedRun = false
659
+ let endRunner
660
+
661
+ function updateRootTestForFinalAttempt (test) {
662
+ if (!test._retriedTest) return
663
+
664
+ const rootTests = rootTestsByFile.get(test.file)
665
+ if (!rootTests) return
666
+
667
+ const retriedTestIndex = rootTests.indexOf(test._retriedTest)
668
+ if (retriedTestIndex !== -1) {
669
+ rootTests[retriedTestIndex] = test
670
+ }
671
+ }
672
+
673
+ function finishRunIfReady () {
674
+ if (hasFinishedRun) return
675
+ if (hasEnded && pendingRootFinalizations === 0) {
676
+ hasFinishedRun = true
677
+ onEnd.call(endRunner)
678
+ }
679
+ }
680
+
681
+ function incrementPendingRootFinalization (test) {
682
+ if (!rootPendingCountByFile.has(test.file) || rootFinalizationPendingTests.has(test)) return
683
+
684
+ rootFinalizationPendingTests.add(test)
685
+ pendingRootFinalizations++
686
+ rootFinalizationPendingCountByFile.set(
687
+ test.file,
688
+ (rootFinalizationPendingCountByFile.get(test.file) || 0) + 1
689
+ )
690
+ }
691
+
692
+ function decrementPendingRootFinalization (test) {
693
+ if (!rootFinalizationPendingTests.has(test)) return
694
+
695
+ rootFinalizationPendingTests.delete(test)
696
+ pendingRootFinalizations--
697
+
698
+ const remaining = rootFinalizationPendingCountByFile.get(test.file) - 1
699
+ if (remaining > 0) {
700
+ rootFinalizationPendingCountByFile.set(test.file, remaining)
701
+ } else {
702
+ rootFinalizationPendingCountByFile.delete(test.file)
703
+ }
704
+
705
+ if (!rootFinalizationPendingCountByFile.has(test.file) && rootFallbackPendingFiles.delete(test.file)) {
706
+ finishRootSuiteFallbackForFile(test.file)
707
+ }
708
+
709
+ finishRunIfReady()
710
+ }
711
+
712
+ function finishRootSuiteForFile (file) {
713
+ const remaining = rootPendingCountByFile.get(file) - 1
714
+ if (remaining > 0) {
715
+ rootPendingCountByFile.set(file, remaining)
716
+ return
717
+ }
718
+ rootPendingCountByFile.delete(file)
719
+
720
+ const ctx = testFileToSuiteCtx.get(file)
721
+ if (!ctx) {
722
+ log.warn('No ctx found for suite', file)
723
+ return
724
+ }
725
+
726
+ const rootTests = rootTestsByFile.get(file) || []
727
+ const status = getRootSuiteStatus(rootTests)
728
+
729
+ if (global.__coverage__) {
730
+ const coverageFiles = getCoveredFilesFromCoverage(global.__coverage__)
731
+ testSuiteCodeCoverageCh.publish({ coverageFiles, suiteFile: file })
732
+ mergeCoverage(global.__coverage__, originalCoverageMap)
733
+ resetCoverage(global.__coverage__)
734
+ }
735
+
736
+ testSuiteFinishCh.publish({ status, ...ctx.currentStore }, () => {})
737
+ }
738
+
739
+ function finishRootSuiteFallbackForFile (file) {
740
+ const ctx = testFileToSuiteCtx.get(file)
741
+ if (!ctx || !rootPendingCountByFile.has(file)) return
742
+
743
+ const rootTests = rootTestsByFile.get(file) || []
744
+ const status = haveRootTestsFinished(rootTests) ? getRootSuiteStatus(rootTests) : 'fail'
745
+ rootPendingCountByFile.delete(file)
746
+ testSuiteFinishCh.publish({ status, ...ctx.currentStore }, () => {})
747
+ }
748
+
749
+ function finishRootSuiteAfterFinalAttempt (test) {
750
+ if (!test._ddIsFinalAttempt || !rootPendingCountByFile.has(test.file)) return
751
+
752
+ updateRootTestForFinalAttempt(test)
753
+ finishRootSuiteForFile(test.file)
754
+ }
755
+
756
+ const onEnd = getOnEndHandler(false)
458
757
 
459
758
  this.once('start', getOnStartHandler(frameworkVersion))
460
759
 
461
- this.once('end', getOnEndHandler(false))
760
+ this.once('end', function () {
761
+ hasEnded = true
762
+ endRunner = this
763
+ finishRunIfReady()
764
+ })
765
+
766
+ // The job of this listener is to
767
+ // initialize the suite span tag in correct order
768
+ // (that is suiteA -> testA ... -> suiteB -> testB
769
+ // instead of suiteA -> suiteB -> testA -> ... -> testB)
770
+ // when the suite has tests that are in the top level
771
+ // (no describe(...))
772
+ this.on('test', function (test) {
773
+ const ctx = testFileToSuiteCtx.get(test.file)
774
+ if (ctx?._pendingRootStart) {
775
+ ctx._pendingRootStart = false
776
+ testSuiteStartCh.runStores(ctx, () => {})
777
+ }
778
+ })
462
779
 
463
780
  this.on('test', getOnTestHandler(true))
464
781
 
465
- this.on('test end', getOnTestEndHandler(config))
782
+ this.on('test end', getOnTestEndHandler(config, {
783
+ onStart: incrementPendingRootFinalization,
784
+ onFinish: function (test) {
785
+ finishRootSuiteAfterFinalAttempt(test)
786
+ decrementPendingRootFinalization(test)
787
+ },
788
+ }))
466
789
 
467
790
  this.on('retry', getOnTestRetryHandler(config))
468
791
 
469
792
  // If the hook passes, 'hook end' will be emitted. Otherwise, 'fail' will be emitted
470
- this.on('hook end', getOnHookEndHandler())
793
+ this.on('hook end', getOnHookEndHandler(config, {
794
+ onStart: incrementPendingRootFinalization,
795
+ onFinish: function (test) {
796
+ finishRootSuiteAfterFinalAttempt(test)
797
+ decrementPendingRootFinalization(test)
798
+ },
799
+ }))
800
+
801
+ this.on('hook end', function (hook) {
802
+ const test = hook.ctx?.currentTest
803
+ if (!test) return
804
+ finishRootSuiteAfterFinalAttempt(test)
805
+ })
806
+
807
+ this.on('fail', getOnFailHandler(true, config))
471
808
 
472
- this.on('fail', getOnFailHandler(true))
809
+ this.on('fail', function (testOrHook) {
810
+ if (testOrHook.type !== 'hook') return
811
+ const test = testOrHook.ctx?.currentTest
812
+ if (!test) return
813
+ finishRootSuiteAfterFinalAttempt(test)
814
+ })
473
815
 
474
816
  this.on('pending', getOnPendingHandler())
475
817
 
476
818
  this.on('suite', function (suite) {
477
819
  if (suite.root || !suite.tests.length) {
820
+ // This branch can be triggered when we have top level it(...) inside test files.
821
+ // In that case, they all (even if they are from different files) are going to be
822
+ // children of the root suite.
823
+ // Note: We could have suites that contain top level it(...) and also it(...) nested
824
+ // inside describe(...) ("mixed case"). Duplication is avoided by the context guard
825
+ // below. Since 'suite' fires for root first, in the mixed case the ctx is created
826
+ // here and the describe-based handler finds it already set.
827
+ if (suite.root && suite.tests.length > 0) {
828
+ const files = new Set(suite.tests.map(test => test.file).filter(Boolean))
829
+ for (const file of files) {
830
+ const testsForFile = suite.tests.filter(t => t.file === file)
831
+ rootTestsByFile.set(file, testsForFile)
832
+ // Only track the countdown for pure root-level files.
833
+ // Mixed files are finished by the normal 'suite end' path.
834
+ if (!suitesByTestFile[file]) {
835
+ rootPendingCountByFile.set(file, testsForFile.length)
836
+ }
837
+ if (testFileToSuiteCtx.get(file)) continue
838
+ const isUnskippable = unskippableSuites.includes(file)
839
+ isForcedToRun = isUnskippable && suitesToSkip.includes(getTestSuitePath(file, process.cwd()))
840
+ const ctx = {
841
+ testSuiteAbsolutePath: file,
842
+ isUnskippable,
843
+ isForcedToRun,
844
+ itrCorrelationId,
845
+ _pendingRootStart: true, // Now the suite start fires lazily on the first test event for this file
846
+ }
847
+ testFileToSuiteCtx.set(file, ctx)
848
+ }
849
+ }
478
850
  return
479
851
  }
480
852
  let ctx = testFileToSuiteCtx.get(suite.file)
@@ -494,6 +866,40 @@ addHook({
494
866
 
495
867
  this.on('suite end', function (suite) {
496
868
  if (suite.root) {
869
+ // Normal case: pure root-level files are finished by the 'test end' / 'hook end'
870
+ // listeners via finishRootSuiteForFile. Two edge cases remain here:
871
+ //
872
+ // 1. All-pending: no 'test' event fired, _pendingRootStart is still true.
873
+ // Start and immediately finish with 'skip'.
874
+ //
875
+ // 2. Aborted mid-run (e.g. a beforeEach hook failure): Mocha skips remaining
876
+ // tests and jumps straight to 'suite end'. rootPendingCountByFile still has
877
+ // a nonzero count for the file because the last tests never ran. Finish it
878
+ // as failed now.
879
+ //
880
+ // 3. Async finalization lagged behind Mocha's synchronous events (e.g. DI retry
881
+ // wait): all tests have Mocha terminal state, but the final-attempt callback
882
+ // did not run before root 'suite end'. Finish from the observed test states.
883
+ const processedFiles = new Set()
884
+ for (const test of suite.tests) {
885
+ if (!test.file || processedFiles.has(test.file)) continue
886
+ processedFiles.add(test.file)
887
+ if (suitesByTestFile[test.file]) continue // mixed: handled by normal path
888
+ const ctx = testFileToSuiteCtx.get(test.file)
889
+ if (!ctx) continue
890
+ if (ctx._pendingRootStart) {
891
+ ctx._pendingRootStart = false
892
+ testSuiteStartCh.runStores(ctx, () => {})
893
+ testSuiteFinishCh.publish({ status: 'skip', ...ctx.currentStore }, () => {})
894
+ } else if (rootPendingCountByFile.has(test.file)) {
895
+ if (rootFinalizationPendingCountByFile.has(test.file)) {
896
+ rootFallbackPendingFiles.add(test.file)
897
+ continue
898
+ }
899
+
900
+ finishRootSuiteFallbackForFile(test.file)
901
+ }
902
+ }
497
903
  return
498
904
  }
499
905
  const suitesInTestFile = suitesByTestFile[suite.file]
@@ -503,8 +909,9 @@ addHook({
503
909
  return
504
910
  }
505
911
 
912
+ const rootTests = rootTestsByFile.get(suite.file) || []
506
913
  let status = 'pass'
507
- if (suitesInTestFile.every(suite => suite.pending)) {
914
+ if (suitesInTestFile.every(suite => suite.pending) && rootTests.every(test => test.isPending())) {
508
915
  status = 'skip'
509
916
  } else {
510
917
  // has to check every test in the test file
@@ -516,10 +923,15 @@ addHook({
516
923
  }
517
924
  })
518
925
  })
926
+ for (const test of rootTests) {
927
+ if (test.state === 'failed' || test.timedOut) {
928
+ status = 'fail'
929
+ }
930
+ }
519
931
  }
520
932
 
521
933
  if (global.__coverage__) {
522
- const coverageFiles = getCoveredFilenamesFromCoverage(global.__coverage__)
934
+ const coverageFiles = getCoveredFilesFromCoverage(global.__coverage__)
523
935
 
524
936
  testSuiteCodeCoverageCh.publish({
525
937
  coverageFiles,
@@ -539,7 +951,7 @@ addHook({
539
951
  }
540
952
  })
541
953
 
542
- return run.apply(this, arguments)
954
+ return run.apply(this, args)
543
955
  })
544
956
 
545
957
  return Runner
@@ -549,7 +961,7 @@ addHook({
549
961
  // Used to set the correct async resource to the test.
550
962
  addHook({
551
963
  name: 'mocha',
552
- versions: ['>=5.2.0'],
964
+ versions: [MINIMUM_MOCHA_VERSION],
553
965
  file: 'lib/runnable.js',
554
966
  }, (runnablePackage) => runnableWrapper(runnablePackage, config))
555
967
 
@@ -557,7 +969,10 @@ function onMessage (message) {
557
969
  if (Array.isArray(message)) {
558
970
  const [messageCode, payload] = message
559
971
  if (messageCode === MOCHA_WORKER_TRACE_PAYLOAD_CODE) {
560
- collectDynamicNamesFromTraces(payload, newTestsWithDynamicNames)
972
+ collectTestOptimizationSummariesFromTraces(payload, {
973
+ newTestsWithDynamicNames,
974
+ attemptToFixExecutions,
975
+ })
561
976
  workerReportTraceCh.publish(payload)
562
977
  }
563
978
  }
@@ -638,11 +1053,11 @@ addHook({
638
1053
  }
639
1054
  }
640
1055
 
1056
+ const localSuites = files.map(file => getTestSuitePath(file, process.cwd()))
641
1057
  getExecutionConfiguration(this, true, frameworkVersion, () => {
642
1058
  if (config.isKnownTestsEnabled) {
643
- const testSuites = files.map(file => getTestSuitePath(file, process.cwd()))
644
1059
  const isFaulty = getIsFaultyEarlyFlakeDetection(
645
- testSuites,
1060
+ localSuites,
646
1061
  config.knownTests?.mocha || {},
647
1062
  config.earlyFlakeDetectionFaultyThreshold
648
1063
  )
@@ -667,11 +1082,13 @@ addHook({
667
1082
  }
668
1083
  isSuitesSkipped = skippedFiles.length > 0
669
1084
  skippedSuites = skippedFiles
1085
+ skippedSuitesCoverage = getSkippedSuitesCoverageForRun()
1086
+ writeCoverageBackfillToCache(skippedSuitesCoverage, getCoverageRootDir())
670
1087
  run.apply(this, [cb, { files: filteredFiles }])
671
1088
  } else {
672
1089
  run.apply(this, arguments)
673
1090
  }
674
- })
1091
+ }, localSuites)
675
1092
 
676
1093
  return this
677
1094
  })
@@ -692,9 +1109,10 @@ addHook({
692
1109
  shimmer.wrap(BufferedWorkerPool.prototype, 'run', run => async function (testSuiteAbsolutePath, workerArgs) {
693
1110
  if (!testFinishCh.hasSubscribers ||
694
1111
  (!config.isKnownTestsEnabled &&
695
- !config.isTestManagementTestsEnabled &&
696
- !config.isImpactedTestsEnabled &&
697
- !config.isFlakyTestRetriesEnabled)) {
1112
+ !config.isTestManagementTestsEnabled &&
1113
+ !config.isImpactedTestsEnabled &&
1114
+ !config.isFlakyTestRetriesEnabled &&
1115
+ !isFailedTestReplayEnabled())) {
698
1116
  return run.apply(this, arguments)
699
1117
  }
700
1118
 
@@ -706,6 +1124,7 @@ addHook({
706
1124
  if (config.knownTests?.mocha) {
707
1125
  const testSuiteKnownTests = config.knownTests.mocha[testPath] || []
708
1126
  newWorkerArgs._ddEfdNumRetries = config.earlyFlakeDetectionNumRetries
1127
+ newWorkerArgs._ddEfdSlowTestRetries = config.earlyFlakeDetectionSlowTestRetries
709
1128
  newWorkerArgs._ddIsEfdEnabled = config.isEarlyFlakeDetectionEnabled
710
1129
  newWorkerArgs._ddIsKnownTestsEnabled = true
711
1130
  newWorkerArgs._ddKnownTests = {
@@ -744,6 +1163,10 @@ addHook({
744
1163
  newWorkerArgs._ddFlakyTestRetriesCount = config.flakyTestRetriesCount
745
1164
  }
746
1165
 
1166
+ if (isFailedTestReplayEnabled()) {
1167
+ newWorkerArgs._ddIsFailedTestReplayEnabled = true
1168
+ }
1169
+
747
1170
  // We pass the known tests for the test file to the worker
748
1171
  const testFileResult = await run.apply(
749
1172
  this,
@@ -757,10 +1180,15 @@ addHook({
757
1180
  .events
758
1181
  .filter(event => event.eventName === 'test end')
759
1182
  .map(event => event.data)
1183
+ const isModified = config.isImpactedTestsEnabled && isModifiedTestSuite(testSuiteAbsolutePath)
760
1184
 
761
1185
  for (const test of tests) {
1186
+ const testProperties = getTestProperties(test, config.testManagementTests)
1187
+ const isAttemptToFix = config.isTestManagementTestsEnabled && testProperties.isAttemptToFix
1188
+
762
1189
  // `newTests` is filled in the worker process, so we need to use the test results to fill it here too.
763
- if (config.isKnownTestsEnabled && isNewTest(test, config.knownTests)) {
1190
+ const isNew = config.isKnownTestsEnabled && isNewTest(test, config.knownTests)
1191
+ if (isNew) {
764
1192
  const testFullName = getTestFullName(test)
765
1193
  const tests = newTests[testFullName]
766
1194
 
@@ -770,8 +1198,19 @@ addHook({
770
1198
  newTests[testFullName] = [test]
771
1199
  }
772
1200
  }
1201
+ // `efdTests` is filled in the worker process, so we need to use the test results to fill it here too.
1202
+ if (!isAttemptToFix && (isNew || isModified)) {
1203
+ const testFullName = getTestFullName(test)
1204
+ const tests = efdTests[testFullName]
1205
+
1206
+ if (tests) {
1207
+ tests.push(test)
1208
+ } else {
1209
+ efdTests[testFullName] = [test]
1210
+ }
1211
+ }
773
1212
  // `testsQuarantined` is filled in the worker process, so we need to use the test results to fill it here too.
774
- if (config.isTestManagementTestsEnabled && getTestProperties(test, config.testManagementTests).isQuarantined) {
1213
+ if (config.isTestManagementTestsEnabled && testProperties.isQuarantined && !testProperties.isAttemptToFix) {
775
1214
  testsQuarantined.add(test)
776
1215
  }
777
1216
  }