@depup/dd-trace 5.97.0-depup.0 → 6.5.0-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (712) hide show
  1. package/LICENSE-3rdparty.csv +89 -104
  2. package/README.electron.md +7 -0
  3. package/README.md +2 -2
  4. package/changes.json +1 -1
  5. package/ci/diagnose.js +2100 -0
  6. package/ci/init.js +46 -5
  7. package/ci/runbook.md +198 -0
  8. package/ci/test-optimization-validation/approval-artifacts.js +143 -0
  9. package/ci/test-optimization-validation/approval.js +299 -0
  10. package/ci/test-optimization-validation/artifact-id.js +20 -0
  11. package/ci/test-optimization-validation/bounded-json.js +121 -0
  12. package/ci/test-optimization-validation/ci-command-candidate.js +83 -0
  13. package/ci/test-optimization-validation/ci-discovery.js +181 -0
  14. package/ci/test-optimization-validation/ci-remediation.js +210 -0
  15. package/ci/test-optimization-validation/cli.js +903 -0
  16. package/ci/test-optimization-validation/command-blocker.js +81 -0
  17. package/ci/test-optimization-validation/command-output-policy.js +206 -0
  18. package/ci/test-optimization-validation/command-runner.js +707 -0
  19. package/ci/test-optimization-validation/command-suitability.js +471 -0
  20. package/ci/test-optimization-validation/executable-approval.js +48 -0
  21. package/ci/test-optimization-validation/executable.js +480 -0
  22. package/ci/test-optimization-validation/generated-file-policy.js +63 -0
  23. package/ci/test-optimization-validation/generated-files.js +351 -0
  24. package/ci/test-optimization-validation/generated-verifier.js +196 -0
  25. package/ci/test-optimization-validation/init-probe-preload.js +163 -0
  26. package/ci/test-optimization-validation/init-probe.js +246 -0
  27. package/ci/test-optimization-validation/late-initialization.js +63 -0
  28. package/ci/test-optimization-validation/local-command.js +163 -0
  29. package/ci/test-optimization-validation/manifest-loader.js +133 -0
  30. package/ci/test-optimization-validation/manifest-scaffold.js +738 -0
  31. package/ci/test-optimization-validation/manifest-schema.js +862 -0
  32. package/ci/test-optimization-validation/offline-fixtures.js +327 -0
  33. package/ci/test-optimization-validation/offline-output.js +406 -0
  34. package/ci/test-optimization-validation/payload-normalizer.js +72 -0
  35. package/ci/test-optimization-validation/plan-writer.js +1120 -0
  36. package/ci/test-optimization-validation/preflight-runner.js +114 -0
  37. package/ci/test-optimization-validation/redaction.js +331 -0
  38. package/ci/test-optimization-validation/report-writer.js +1508 -0
  39. package/ci/test-optimization-validation/safe-files.js +203 -0
  40. package/ci/test-optimization-validation/scenarios/auto-test-retries.js +159 -0
  41. package/ci/test-optimization-validation/scenarios/basic-reporting.js +657 -0
  42. package/ci/test-optimization-validation/scenarios/ci-wiring.js +780 -0
  43. package/ci/test-optimization-validation/scenarios/early-flake-detection.js +141 -0
  44. package/ci/test-optimization-validation/scenarios/helpers.js +539 -0
  45. package/ci/test-optimization-validation/scenarios/test-management.js +218 -0
  46. package/ci/test-optimization-validation/setup-runner.js +97 -0
  47. package/ci/test-optimization-validation/static-diagnosis.js +159 -0
  48. package/ci/test-optimization-validation/test-output.js +129 -0
  49. package/ci/test-optimization-validation-manifest.schema.json +1 -0
  50. package/ci/validate-test-optimization.js +3 -0
  51. package/ci/vitest-no-worker-init-setup.mjs +430 -0
  52. package/ext/exporters.js +2 -0
  53. package/ext/tags.js +3 -0
  54. package/index.d.ts +436 -252
  55. package/index.electron.js +3 -0
  56. package/init.js +18 -0
  57. package/initialize.mjs +10 -9
  58. package/loader-hook.mjs +170 -53
  59. package/openfeature.d.ts +1 -0
  60. package/openfeature.js +4 -0
  61. package/package.json +118 -80
  62. package/packages/datadog-core/src/storage.js +47 -48
  63. package/packages/datadog-esbuild/index.js +32 -1
  64. package/packages/datadog-esbuild/src/utils.js +46 -3
  65. package/packages/datadog-instrumentations/src/aerospike.js +3 -3
  66. package/packages/datadog-instrumentations/src/ai.js +137 -76
  67. package/packages/datadog-instrumentations/src/amqplib.js +6 -7
  68. package/packages/datadog-instrumentations/src/anthropic.js +10 -10
  69. package/packages/datadog-instrumentations/src/apollo-server-core.js +3 -3
  70. package/packages/datadog-instrumentations/src/apollo-server.js +10 -18
  71. package/packages/datadog-instrumentations/src/avsc.js +6 -6
  72. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js-context-methods.js +18 -0
  73. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js.js +111 -0
  74. package/packages/datadog-instrumentations/src/aws-sdk.js +172 -72
  75. package/packages/datadog-instrumentations/src/azure-cosmos.js +7 -0
  76. package/packages/datadog-instrumentations/src/azure-durable-functions.js +8 -8
  77. package/packages/datadog-instrumentations/src/azure-functions.js +3 -0
  78. package/packages/datadog-instrumentations/src/bluebird.js +2 -2
  79. package/packages/datadog-instrumentations/src/body-parser.js +5 -2
  80. package/packages/datadog-instrumentations/src/cassandra-driver.js +12 -9
  81. package/packages/datadog-instrumentations/src/child_process.js +16 -16
  82. package/packages/datadog-instrumentations/src/claude-agent-sdk.js +587 -0
  83. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +41 -24
  84. package/packages/datadog-instrumentations/src/connect.js +14 -12
  85. package/packages/datadog-instrumentations/src/cookie-parser.js +5 -4
  86. package/packages/datadog-instrumentations/src/cookie.js +9 -3
  87. package/packages/datadog-instrumentations/src/couchbase.js +73 -238
  88. package/packages/datadog-instrumentations/src/crypto.js +49 -4
  89. package/packages/datadog-instrumentations/src/cucumber-worker-threads.js +25 -0
  90. package/packages/datadog-instrumentations/src/cucumber.js +762 -189
  91. package/packages/datadog-instrumentations/src/cypress-config.js +547 -93
  92. package/packages/datadog-instrumentations/src/cypress.js +5 -3
  93. package/packages/datadog-instrumentations/src/dns.js +60 -59
  94. package/packages/datadog-instrumentations/src/elasticsearch.js +9 -12
  95. package/packages/datadog-instrumentations/src/electron/preload.js +42 -0
  96. package/packages/datadog-instrumentations/src/electron.js +240 -0
  97. package/packages/datadog-instrumentations/src/express-mongo-sanitize.js +11 -9
  98. package/packages/datadog-instrumentations/src/express-session.js +14 -13
  99. package/packages/datadog-instrumentations/src/express.js +52 -30
  100. package/packages/datadog-instrumentations/src/fastify.js +166 -87
  101. package/packages/datadog-instrumentations/src/fetch.js +5 -5
  102. package/packages/datadog-instrumentations/src/fs.js +22 -20
  103. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +5 -7
  104. package/packages/datadog-instrumentations/src/google-genai.js +4 -4
  105. package/packages/datadog-instrumentations/src/graphql.js +26 -362
  106. package/packages/datadog-instrumentations/src/grpc/client.js +48 -32
  107. package/packages/datadog-instrumentations/src/grpc/server.js +20 -2
  108. package/packages/datadog-instrumentations/src/hapi.js +2 -2
  109. package/packages/datadog-instrumentations/src/helpers/callback-instrumentor.js +74 -0
  110. package/packages/datadog-instrumentations/src/helpers/check-require-cache.js +85 -9
  111. package/packages/datadog-instrumentations/src/helpers/hook.js +31 -7
  112. package/packages/datadog-instrumentations/src/helpers/hooks.js +12 -0
  113. package/packages/datadog-instrumentations/src/helpers/instrument.js +36 -3
  114. package/packages/datadog-instrumentations/src/helpers/kafka.js +58 -0
  115. package/packages/datadog-instrumentations/src/helpers/optional-peer-bundler.js +65 -0
  116. package/packages/datadog-instrumentations/src/helpers/promise-instrumentor.js +42 -0
  117. package/packages/datadog-instrumentations/src/helpers/promise.js +2 -2
  118. package/packages/datadog-instrumentations/src/helpers/register.js +7 -5
  119. package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +13 -5
  120. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +24 -7
  121. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +6 -6
  122. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/aws-durable-execution-sdk-js.js +31 -0
  123. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/azure-cosmos.js +50 -0
  124. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/claude-agent-sdk.js +17 -0
  125. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +201 -0
  126. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +7 -0
  127. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/langgraph.js +4 -2
  128. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/mercurius.js +31 -0
  129. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-sdk.js +35 -0
  130. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +111 -0
  131. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +18 -2
  132. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +49 -224
  133. package/packages/datadog-instrumentations/src/helpers/router-helper.js +8 -8
  134. package/packages/datadog-instrumentations/src/hono.js +71 -9
  135. package/packages/datadog-instrumentations/src/http/client.js +48 -24
  136. package/packages/datadog-instrumentations/src/http/server.js +75 -29
  137. package/packages/datadog-instrumentations/src/http2/client.js +15 -12
  138. package/packages/datadog-instrumentations/src/http2/server.js +156 -23
  139. package/packages/datadog-instrumentations/src/ioredis.js +17 -14
  140. package/packages/datadog-instrumentations/src/iovalkey.js +1 -2
  141. package/packages/datadog-instrumentations/src/jest/bail-reporter.js +42 -0
  142. package/packages/datadog-instrumentations/src/jest/coverage-backfill.js +163 -0
  143. package/packages/datadog-instrumentations/src/jest.js +1809 -401
  144. package/packages/datadog-instrumentations/src/kafkajs.js +284 -170
  145. package/packages/datadog-instrumentations/src/knex.js +17 -17
  146. package/packages/datadog-instrumentations/src/koa.js +15 -14
  147. package/packages/datadog-instrumentations/src/ldapjs.js +5 -5
  148. package/packages/datadog-instrumentations/src/light-my-request.js +2 -2
  149. package/packages/datadog-instrumentations/src/limitd-client.js +4 -4
  150. package/packages/datadog-instrumentations/src/lodash.js +4 -4
  151. package/packages/datadog-instrumentations/src/mariadb.js +18 -16
  152. package/packages/datadog-instrumentations/src/memcached.js +4 -3
  153. package/packages/datadog-instrumentations/src/mercurius.js +11 -0
  154. package/packages/datadog-instrumentations/src/microgateway-core.js +2 -2
  155. package/packages/datadog-instrumentations/src/mocha/common.js +7 -4
  156. package/packages/datadog-instrumentations/src/mocha/main.js +557 -120
  157. package/packages/datadog-instrumentations/src/mocha/utils.js +531 -135
  158. package/packages/datadog-instrumentations/src/mocha/worker.js +27 -9
  159. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +254 -0
  160. package/packages/datadog-instrumentations/src/mongodb-core.js +43 -31
  161. package/packages/datadog-instrumentations/src/mongodb.js +82 -8
  162. package/packages/datadog-instrumentations/src/mongoose.js +46 -37
  163. package/packages/datadog-instrumentations/src/mquery.js +7 -7
  164. package/packages/datadog-instrumentations/src/multer.js +5 -4
  165. package/packages/datadog-instrumentations/src/mysql.js +17 -17
  166. package/packages/datadog-instrumentations/src/mysql2.js +39 -5
  167. package/packages/datadog-instrumentations/src/nats.js +182 -0
  168. package/packages/datadog-instrumentations/src/net.js +19 -11
  169. package/packages/datadog-instrumentations/src/next.js +68 -10
  170. package/packages/datadog-instrumentations/src/nyc.js +43 -8
  171. package/packages/datadog-instrumentations/src/openai.js +124 -38
  172. package/packages/datadog-instrumentations/src/oracledb.js +12 -7
  173. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +27 -6
  174. package/packages/datadog-instrumentations/src/passport-utils.js +5 -5
  175. package/packages/datadog-instrumentations/src/path-to-regexp.js +44 -0
  176. package/packages/datadog-instrumentations/src/pg.js +58 -25
  177. package/packages/datadog-instrumentations/src/pino.js +25 -41
  178. package/packages/datadog-instrumentations/src/playwright-browser-scripts.js +27 -0
  179. package/packages/datadog-instrumentations/src/playwright.js +1229 -356
  180. package/packages/datadog-instrumentations/src/process.js +3 -0
  181. package/packages/datadog-instrumentations/src/protobufjs.js +16 -16
  182. package/packages/datadog-instrumentations/src/redis.js +28 -15
  183. package/packages/datadog-instrumentations/src/restify.js +6 -5
  184. package/packages/datadog-instrumentations/src/router.js +253 -87
  185. package/packages/datadog-instrumentations/src/selenium.js +53 -28
  186. package/packages/datadog-instrumentations/src/stripe.js +47 -33
  187. package/packages/datadog-instrumentations/src/tedious.js +28 -0
  188. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1297 -0
  189. package/packages/datadog-instrumentations/src/vitest-main.js +1590 -0
  190. package/packages/datadog-instrumentations/src/vitest-util.js +251 -0
  191. package/packages/datadog-instrumentations/src/vitest-worker.js +822 -0
  192. package/packages/datadog-instrumentations/src/vitest.js +11 -1262
  193. package/packages/datadog-instrumentations/src/winston.js +4 -4
  194. package/packages/datadog-instrumentations/src/ws.js +9 -8
  195. package/packages/datadog-instrumentations/src/zlib.js +29 -0
  196. package/packages/datadog-plugin-ai/src/index.js +1 -1
  197. package/packages/datadog-plugin-ai/src/tracing.js +66 -3
  198. package/packages/datadog-plugin-ai/src/utils.js +17 -4
  199. package/packages/datadog-plugin-apollo/src/gateway/request.js +1 -21
  200. package/packages/datadog-plugin-avsc/src/schema_iterator.js +3 -3
  201. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/checkpoint.js +31 -0
  202. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/client.js +55 -0
  203. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/context.js +123 -0
  204. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/handler.js +129 -0
  205. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/index.js +19 -0
  206. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/trace-checkpoint.js +224 -0
  207. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +80 -0
  208. package/packages/datadog-plugin-aws-sdk/src/base.js +86 -50
  209. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +1 -1
  210. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +218 -4
  211. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +1 -1
  212. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +2 -1
  213. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +59 -14
  214. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +174 -75
  215. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +34 -23
  216. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +2 -1
  217. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +1 -1
  218. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +26 -26
  219. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +187 -101
  220. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +20 -18
  221. package/packages/datadog-plugin-aws-sdk/src/util.js +2 -2
  222. package/packages/datadog-plugin-azure-cosmos/src/index.js +144 -0
  223. package/packages/datadog-plugin-azure-event-hubs/src/producer.js +8 -15
  224. package/packages/datadog-plugin-azure-functions/src/index.js +7 -3
  225. package/packages/datadog-plugin-azure-service-bus/src/producer.js +5 -10
  226. package/packages/datadog-plugin-bullmq/src/consumer.js +5 -4
  227. package/packages/datadog-plugin-bullmq/src/filter.js +35 -0
  228. package/packages/datadog-plugin-bullmq/src/producer.js +121 -33
  229. package/packages/datadog-plugin-bunyan/src/index.js +28 -0
  230. package/packages/datadog-plugin-child_process/src/index.js +13 -2
  231. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +6 -6
  232. package/packages/datadog-plugin-claude-agent-sdk/src/index.js +31 -0
  233. package/packages/datadog-plugin-claude-agent-sdk/src/tracing.js +107 -0
  234. package/packages/datadog-plugin-claude-agent-sdk/src/util.js +15 -0
  235. package/packages/datadog-plugin-couchbase/src/index.js +58 -52
  236. package/packages/datadog-plugin-cucumber/src/index.js +47 -29
  237. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +929 -98
  238. package/packages/datadog-plugin-cypress/src/index.js +109 -2
  239. package/packages/datadog-plugin-cypress/src/plugin.js +6 -14
  240. package/packages/datadog-plugin-cypress/src/source-map-utils.js +48 -1
  241. package/packages/datadog-plugin-cypress/src/support.js +272 -51
  242. package/packages/datadog-plugin-dd-trace-api/src/index.js +1 -1
  243. package/packages/datadog-plugin-dns/src/lookup.js +8 -6
  244. package/packages/datadog-plugin-elasticsearch/src/index.js +28 -8
  245. package/packages/datadog-plugin-electron/src/index.js +17 -0
  246. package/packages/datadog-plugin-electron/src/ipc.js +143 -0
  247. package/packages/datadog-plugin-electron/src/net.js +82 -0
  248. package/packages/datadog-plugin-express/src/code_origin.js +1 -1
  249. package/packages/datadog-plugin-fastify/src/code_origin.js +1 -1
  250. package/packages/datadog-plugin-fs/src/index.js +2 -1
  251. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -5
  252. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +27 -18
  253. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +5 -8
  254. package/packages/datadog-plugin-graphql/src/execute.js +748 -34
  255. package/packages/datadog-plugin-graphql/src/index.js +43 -9
  256. package/packages/datadog-plugin-graphql/src/parse.js +45 -4
  257. package/packages/datadog-plugin-graphql/src/request.js +135 -0
  258. package/packages/datadog-plugin-graphql/src/tools/signature.js +32 -7
  259. package/packages/datadog-plugin-graphql/src/tools/transforms.js +118 -100
  260. package/packages/datadog-plugin-graphql/src/utils.js +261 -3
  261. package/packages/datadog-plugin-graphql/src/validate.js +54 -8
  262. package/packages/datadog-plugin-grpc/src/client.js +7 -8
  263. package/packages/datadog-plugin-grpc/src/server.js +1 -1
  264. package/packages/datadog-plugin-grpc/src/util.js +57 -22
  265. package/packages/datadog-plugin-http/src/client.js +12 -14
  266. package/packages/datadog-plugin-http/src/index.js +6 -8
  267. package/packages/datadog-plugin-http/src/server.js +63 -20
  268. package/packages/datadog-plugin-http2/src/client.js +7 -4
  269. package/packages/datadog-plugin-http2/src/server.js +48 -8
  270. package/packages/datadog-plugin-jest/src/index.js +133 -67
  271. package/packages/datadog-plugin-jest/src/util.js +37 -16
  272. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +1 -1
  273. package/packages/datadog-plugin-kafkajs/src/consumer.js +2 -9
  274. package/packages/datadog-plugin-kafkajs/src/producer.js +37 -8
  275. package/packages/datadog-plugin-langchain/src/handlers/embedding.js +2 -1
  276. package/packages/datadog-plugin-langchain/src/handlers/language_models.js +2 -1
  277. package/packages/datadog-plugin-langchain/src/tokens.js +2 -2
  278. package/packages/datadog-plugin-langgraph/src/stream.js +1 -1
  279. package/packages/datadog-plugin-memcached/src/index.js +1 -1
  280. package/packages/datadog-plugin-mocha/src/index.js +66 -20
  281. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/index.js +24 -0
  282. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +173 -0
  283. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +30 -0
  284. package/packages/datadog-plugin-mongodb-core/src/bulk-write.js +43 -0
  285. package/packages/datadog-plugin-mongodb-core/src/index.js +8 -206
  286. package/packages/datadog-plugin-mongodb-core/src/query.js +452 -0
  287. package/packages/datadog-plugin-mysql/src/index.js +9 -4
  288. package/packages/datadog-plugin-nats/src/consumer.js +43 -0
  289. package/packages/datadog-plugin-nats/src/index.js +20 -0
  290. package/packages/datadog-plugin-nats/src/producer.js +62 -0
  291. package/packages/datadog-plugin-nats/src/util.js +33 -0
  292. package/packages/datadog-plugin-next/src/index.js +12 -4
  293. package/packages/datadog-plugin-openai/src/services.js +4 -3
  294. package/packages/datadog-plugin-openai/src/tracing.js +27 -25
  295. package/packages/datadog-plugin-oracledb/src/index.js +13 -2
  296. package/packages/datadog-plugin-pg/src/index.js +13 -3
  297. package/packages/datadog-plugin-pino/src/index.js +42 -0
  298. package/packages/datadog-plugin-playwright/src/index.js +195 -72
  299. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +3 -3
  300. package/packages/datadog-plugin-redis/src/index.js +54 -25
  301. package/packages/datadog-plugin-rhea/src/producer.js +1 -1
  302. package/packages/datadog-plugin-router/src/index.js +55 -44
  303. package/packages/datadog-plugin-selenium/src/index.js +5 -36
  304. package/packages/datadog-plugin-tedious/src/index.js +1 -1
  305. package/packages/datadog-plugin-undici/src/index.js +24 -2
  306. package/packages/datadog-plugin-vitest/src/index.js +160 -90
  307. package/packages/datadog-plugin-winston/src/index.js +30 -0
  308. package/packages/datadog-plugin-ws/src/close.js +5 -2
  309. package/packages/datadog-plugin-ws/src/producer.js +4 -1
  310. package/packages/datadog-plugin-ws/src/receiver.js +4 -2
  311. package/packages/datadog-plugin-ws/src/server.js +2 -1
  312. package/packages/datadog-shimmer/src/shimmer.js +101 -39
  313. package/packages/datadog-webpack/index.js +17 -1
  314. package/packages/datadog-webpack/src/optional-peer-loader.js +17 -0
  315. package/packages/dd-trace/index.electron.js +3 -0
  316. package/packages/dd-trace/index.js +2 -36
  317. package/packages/dd-trace/src/aiguard/channels.js +7 -0
  318. package/packages/dd-trace/src/aiguard/index.js +16 -34
  319. package/packages/dd-trace/src/aiguard/integrations/evaluate.js +46 -0
  320. package/packages/dd-trace/src/aiguard/integrations/index.js +34 -0
  321. package/packages/dd-trace/src/aiguard/integrations/openai.js +80 -0
  322. package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +92 -0
  323. package/packages/dd-trace/src/aiguard/messages/openai.js +382 -0
  324. package/packages/{datadog-instrumentations/src/helpers/ai-messages.js → dd-trace/src/aiguard/messages/vercel-ai.js} +30 -27
  325. package/packages/dd-trace/src/aiguard/sdk.js +148 -55
  326. package/packages/dd-trace/src/aiguard/tags.js +26 -10
  327. package/packages/dd-trace/src/appsec/api_security/index.js +55 -0
  328. package/packages/dd-trace/src/appsec/api_security/sampler.js +147 -0
  329. package/packages/dd-trace/src/appsec/blocked_templates.js +4 -3
  330. package/packages/dd-trace/src/appsec/blocking.js +82 -42
  331. package/packages/dd-trace/src/appsec/channels.js +5 -1
  332. package/packages/dd-trace/src/appsec/downstream_requests.js +116 -62
  333. package/packages/dd-trace/src/appsec/graphql.js +20 -17
  334. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +1 -1
  335. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +81 -81
  336. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +23 -23
  337. package/packages/dd-trace/src/appsec/iast/index.js +3 -2
  338. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +4 -4
  339. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +2 -2
  340. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +2 -2
  341. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +4 -4
  342. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -2
  343. package/packages/dd-trace/src/appsec/iast/telemetry/index.js +2 -1
  344. package/packages/dd-trace/src/appsec/iast/telemetry/span-tags.js +3 -1
  345. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +54 -12
  346. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +5 -1
  347. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +31 -4
  348. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +1 -3
  349. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +83 -48
  350. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +1 -1
  351. package/packages/dd-trace/src/appsec/index.js +65 -47
  352. package/packages/dd-trace/src/appsec/lambda.js +135 -0
  353. package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -5
  354. package/packages/dd-trace/src/appsec/rasp/lfi.js +8 -4
  355. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +5 -10
  356. package/packages/dd-trace/src/appsec/rasp/ssrf.js +26 -18
  357. package/packages/dd-trace/src/appsec/recommended.json +2438 -13
  358. package/packages/dd-trace/src/appsec/reporter.js +87 -28
  359. package/packages/dd-trace/src/appsec/rule_manager.js +4 -2
  360. package/packages/dd-trace/src/appsec/sdk/set_user.js +1 -1
  361. package/packages/dd-trace/src/appsec/sdk/track_event.js +5 -5
  362. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +7 -11
  363. package/packages/dd-trace/src/appsec/sdk/utils.js +5 -3
  364. package/packages/dd-trace/src/appsec/store.js +50 -0
  365. package/packages/dd-trace/src/appsec/telemetry/api_security.js +34 -0
  366. package/packages/dd-trace/src/appsec/telemetry/index.js +27 -1
  367. package/packages/dd-trace/src/appsec/user_tracking.js +5 -4
  368. package/packages/dd-trace/src/appsec/waf/index.js +19 -9
  369. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +35 -20
  370. package/packages/dd-trace/src/appsec/waf/waf_manager.js +1 -1
  371. package/packages/dd-trace/src/azure_metadata.js +19 -7
  372. package/packages/dd-trace/src/baggage.js +32 -13
  373. package/packages/dd-trace/src/bootstrap.js +39 -0
  374. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +123 -33
  375. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +122 -24
  376. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +22 -7
  377. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +5 -2
  378. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +2 -2
  379. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +2 -2
  380. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +6 -2
  381. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -2
  382. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +160 -0
  383. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +288 -0
  384. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +84 -0
  385. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +369 -0
  386. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +60 -0
  387. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +188 -27
  388. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +3 -4
  389. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +28 -10
  390. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +22 -0
  391. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +110 -22
  392. package/packages/dd-trace/src/ci-visibility/lage.js +2 -1
  393. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +4 -5
  394. package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +4 -5
  395. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +73 -55
  396. package/packages/dd-trace/src/ci-visibility/requests/request.js +14 -50
  397. package/packages/dd-trace/src/ci-visibility/requests/upload-coverage-report.js +10 -6
  398. package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +156 -0
  399. package/packages/dd-trace/src/ci-visibility/rum.js +7 -0
  400. package/packages/dd-trace/src/ci-visibility/test-api-manual/test-api-manual-plugin.js +9 -3
  401. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +24 -6
  402. package/packages/dd-trace/src/ci-visibility/test-optimization-cache.js +70 -6
  403. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +256 -0
  404. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +451 -0
  405. package/packages/dd-trace/src/ci-visibility/test-screenshot.js +90 -0
  406. package/packages/dd-trace/src/config/config-types.d.ts +8 -6
  407. package/packages/dd-trace/src/config/defaults.js +71 -44
  408. package/packages/dd-trace/src/config/generated-config-types.d.ts +692 -131
  409. package/packages/dd-trace/src/config/git_properties.js +2 -2
  410. package/packages/dd-trace/src/config/helper.js +140 -33
  411. package/packages/dd-trace/src/config/index.js +127 -131
  412. package/packages/dd-trace/src/config/major-overrides.js +100 -0
  413. package/packages/dd-trace/src/config/normalize-service.js +31 -0
  414. package/packages/dd-trace/src/config/parsers.js +138 -10
  415. package/packages/dd-trace/src/config/remote_config.js +1 -1
  416. package/packages/dd-trace/src/config/supported-configurations.json +460 -203
  417. package/packages/dd-trace/src/constants.js +15 -0
  418. package/packages/dd-trace/src/crashtracking/crashtracker.js +18 -6
  419. package/packages/dd-trace/src/datastreams/checkpointer.js +6 -12
  420. package/packages/dd-trace/src/datastreams/context.js +4 -2
  421. package/packages/dd-trace/src/datastreams/encoding.js +39 -28
  422. package/packages/dd-trace/src/datastreams/index.js +2 -1
  423. package/packages/dd-trace/src/datastreams/manager.js +1 -1
  424. package/packages/dd-trace/src/datastreams/pathway.js +35 -30
  425. package/packages/dd-trace/src/datastreams/processor.js +31 -22
  426. package/packages/dd-trace/src/datastreams/size.js +6 -2
  427. package/packages/dd-trace/src/datastreams/writer.js +15 -6
  428. package/packages/dd-trace/src/debugger/config.js +9 -4
  429. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +49 -35
  430. package/packages/dd-trace/src/debugger/devtools_client/condition.js +5 -8
  431. package/packages/dd-trace/src/debugger/devtools_client/config.js +3 -2
  432. package/packages/dd-trace/src/debugger/devtools_client/index.js +33 -71
  433. package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +83 -0
  434. package/packages/dd-trace/src/debugger/devtools_client/send.js +27 -6
  435. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +2 -2
  436. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +5 -2
  437. package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +1 -0
  438. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +1 -1
  439. package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
  440. package/packages/dd-trace/src/debugger/index.js +13 -9
  441. package/packages/dd-trace/src/debugger/probe_sampler.js +112 -0
  442. package/packages/dd-trace/src/debugger/probe_sampler_constants.js +19 -0
  443. package/packages/dd-trace/src/dogstatsd.js +34 -28
  444. package/packages/dd-trace/src/encode/0.4.js +829 -268
  445. package/packages/dd-trace/src/encode/0.5.js +158 -22
  446. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +141 -65
  447. package/packages/dd-trace/src/encode/agentless-json.js +12 -6
  448. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +52 -15
  449. package/packages/dd-trace/src/encode/span-stats.js +19 -16
  450. package/packages/dd-trace/src/encode/tags-processors.js +30 -25
  451. package/packages/dd-trace/src/exporter.js +5 -1
  452. package/packages/dd-trace/src/exporters/agent/index.js +4 -5
  453. package/packages/dd-trace/src/exporters/agent/writer.js +1 -2
  454. package/packages/dd-trace/src/exporters/agentless/index.js +12 -13
  455. package/packages/dd-trace/src/exporters/agentless/intake.js +43 -0
  456. package/packages/dd-trace/src/exporters/agentless/writer.js +12 -11
  457. package/packages/dd-trace/src/exporters/common/agents.js +3 -1
  458. package/packages/dd-trace/src/exporters/common/buffering-exporter.js +3 -3
  459. package/packages/dd-trace/src/exporters/common/client-library-headers.js +21 -0
  460. package/packages/dd-trace/src/exporters/common/request.js +93 -44
  461. package/packages/dd-trace/src/exporters/common/retry.js +104 -0
  462. package/packages/dd-trace/src/exporters/common/url.js +48 -0
  463. package/packages/dd-trace/src/exporters/common/util.js +2 -2
  464. package/packages/dd-trace/src/exporters/common/writer.js +17 -1
  465. package/packages/dd-trace/src/exporters/electron/index.js +49 -0
  466. package/packages/dd-trace/src/exporters/span-stats/index.js +1 -2
  467. package/packages/dd-trace/src/exporters/span-stats/writer.js +1 -3
  468. package/packages/dd-trace/src/external-logger/src/index.js +2 -1
  469. package/packages/dd-trace/src/feature-registry.js +29 -0
  470. package/packages/dd-trace/src/git_metadata.js +68 -0
  471. package/packages/dd-trace/src/git_metadata_tagger.js +13 -5
  472. package/packages/dd-trace/src/guardrails/index.js +11 -6
  473. package/packages/dd-trace/src/guardrails/telemetry.js +40 -3
  474. package/packages/dd-trace/src/heap_snapshots.js +4 -4
  475. package/packages/dd-trace/src/id.js +46 -27
  476. package/packages/dd-trace/src/index.js +7 -8
  477. package/packages/dd-trace/src/lambda/handler-paths.js +52 -0
  478. package/packages/dd-trace/src/lambda/handler.js +2 -6
  479. package/packages/dd-trace/src/lambda/index.js +62 -14
  480. package/packages/dd-trace/src/lambda/runtime/patch.js +21 -46
  481. package/packages/dd-trace/src/llmobs/constants/tags.js +13 -0
  482. package/packages/dd-trace/src/llmobs/experiments/client.js +113 -0
  483. package/packages/dd-trace/src/llmobs/experiments/dataset.js +154 -0
  484. package/packages/dd-trace/src/llmobs/experiments/experiment.js +283 -0
  485. package/packages/dd-trace/src/llmobs/experiments/index.js +152 -0
  486. package/packages/dd-trace/src/llmobs/experiments/noop.js +30 -0
  487. package/packages/dd-trace/src/llmobs/experiments/result.js +34 -0
  488. package/packages/dd-trace/src/llmobs/index.js +37 -7
  489. package/packages/dd-trace/src/llmobs/noop.js +6 -0
  490. package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +403 -0
  491. package/packages/dd-trace/src/llmobs/plugins/ai/index.js +8 -395
  492. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +119 -7
  493. package/packages/dd-trace/src/llmobs/plugins/ai/vercelTelemetry.js +380 -0
  494. package/packages/dd-trace/src/llmobs/plugins/{anthropic.js → anthropic/index.js} +32 -79
  495. package/packages/dd-trace/src/llmobs/plugins/anthropic/util.js +109 -0
  496. package/packages/dd-trace/src/llmobs/plugins/base.js +4 -4
  497. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +89 -37
  498. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +270 -0
  499. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +10 -0
  500. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +5 -1
  501. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +81 -16
  502. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +3 -2
  503. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +3 -2
  504. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/embedding.js +2 -1
  505. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +1 -50
  506. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/vectorstore.js +2 -1
  507. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +14 -8
  508. package/packages/dd-trace/src/llmobs/plugins/langchain/messages.js +76 -0
  509. package/packages/dd-trace/src/llmobs/plugins/langgraph/index.js +4 -29
  510. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +68 -0
  511. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +57 -0
  512. package/packages/dd-trace/src/llmobs/plugins/openai/constants.js +8 -0
  513. package/packages/dd-trace/src/llmobs/plugins/openai/index.js +68 -64
  514. package/packages/dd-trace/src/llmobs/plugins/openai/utils.js +43 -0
  515. package/packages/dd-trace/src/llmobs/sdk.js +73 -35
  516. package/packages/dd-trace/src/llmobs/span_processor.js +90 -11
  517. package/packages/dd-trace/src/llmobs/tagger.js +197 -4
  518. package/packages/dd-trace/src/llmobs/telemetry.js +33 -2
  519. package/packages/dd-trace/src/llmobs/util.js +234 -9
  520. package/packages/dd-trace/src/llmobs/writers/base.js +11 -5
  521. package/packages/dd-trace/src/llmobs/writers/spans.js +1 -1
  522. package/packages/dd-trace/src/llmobs/writers/util.js +1 -2
  523. package/packages/dd-trace/src/log/index.js +19 -31
  524. package/packages/dd-trace/src/log/writer.js +3 -1
  525. package/packages/dd-trace/src/msgpack/chunk.js +430 -11
  526. package/packages/dd-trace/src/msgpack/index.js +101 -2
  527. package/packages/dd-trace/src/noop/proxy.js +5 -4
  528. package/packages/dd-trace/src/noop/span.js +3 -1
  529. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +322 -0
  530. package/packages/dd-trace/src/openfeature/configuration_source.js +90 -0
  531. package/packages/dd-trace/src/openfeature/encoding.js +70 -0
  532. package/packages/dd-trace/src/openfeature/eval-metrics-hook.js +103 -0
  533. package/packages/dd-trace/src/openfeature/flagging_provider.js +32 -16
  534. package/packages/dd-trace/src/openfeature/index.js +0 -2
  535. package/packages/dd-trace/src/openfeature/noop.js +41 -64
  536. package/packages/dd-trace/src/openfeature/register.js +35 -0
  537. package/packages/dd-trace/src/openfeature/remote_config.js +16 -14
  538. package/packages/dd-trace/src/openfeature/require-provider.js +18 -0
  539. package/packages/dd-trace/src/openfeature/span-enrichment-hook.js +143 -0
  540. package/packages/dd-trace/src/openfeature/span-enrichment.js +149 -0
  541. package/packages/dd-trace/src/openfeature/writers/base.js +3 -11
  542. package/packages/dd-trace/src/openfeature/writers/exposures.js +82 -70
  543. package/packages/dd-trace/src/openfeature/writers/util.js +1 -2
  544. package/packages/dd-trace/src/opentelemetry/active-span-proxy.js +42 -0
  545. package/packages/dd-trace/src/opentelemetry/bridge-span-base.js +107 -0
  546. package/packages/dd-trace/src/opentelemetry/context_manager.js +27 -13
  547. package/packages/dd-trace/src/opentelemetry/logs/index.js +6 -6
  548. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +3 -2
  549. package/packages/dd-trace/src/opentelemetry/metrics/index.js +61 -12
  550. package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +28 -14
  551. package/packages/dd-trace/src/opentelemetry/metrics/meter.js +7 -10
  552. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +3 -2
  553. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +40 -0
  554. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js +169 -0
  555. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +99 -5
  556. package/packages/dd-trace/src/opentelemetry/metrics/time.js +19 -0
  557. package/packages/dd-trace/src/opentelemetry/otlp/common.proto +2 -2
  558. package/packages/dd-trace/src/opentelemetry/otlp/logs.proto +1 -1
  559. package/packages/dd-trace/src/opentelemetry/otlp/logs_service.proto +1 -1
  560. package/packages/dd-trace/src/opentelemetry/otlp/metrics.proto +1 -1
  561. package/packages/dd-trace/src/opentelemetry/otlp/metrics_service.proto +1 -1
  562. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +56 -82
  563. package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +1 -2
  564. package/packages/dd-trace/src/opentelemetry/otlp/protobuf_loader.js +14 -2
  565. package/packages/dd-trace/src/opentelemetry/otlp/trace.proto +358 -0
  566. package/packages/dd-trace/src/opentelemetry/otlp/trace_service.proto +78 -0
  567. package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +10 -0
  568. package/packages/dd-trace/src/opentelemetry/span-helpers.js +325 -0
  569. package/packages/dd-trace/src/opentelemetry/span.js +64 -109
  570. package/packages/dd-trace/src/opentelemetry/span_context.js +1 -0
  571. package/packages/dd-trace/src/opentelemetry/span_processor.js +7 -5
  572. package/packages/dd-trace/src/opentelemetry/trace/index.js +75 -0
  573. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +75 -0
  574. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +375 -0
  575. package/packages/dd-trace/src/opentelemetry/tracer.js +20 -69
  576. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +33 -17
  577. package/packages/dd-trace/src/opentracing/propagation/log.js +28 -8
  578. package/packages/dd-trace/src/opentracing/propagation/text_map.js +278 -148
  579. package/packages/dd-trace/src/opentracing/propagation/text_map_dsm.js +11 -11
  580. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +98 -32
  581. package/packages/dd-trace/src/opentracing/span.js +127 -73
  582. package/packages/dd-trace/src/opentracing/span_context.js +68 -3
  583. package/packages/dd-trace/src/opentracing/tracer.js +46 -19
  584. package/packages/dd-trace/src/payload-tagging/config/index.js +2 -2
  585. package/packages/dd-trace/src/plugin_manager.js +36 -14
  586. package/packages/dd-trace/src/plugins/apollo.js +3 -1
  587. package/packages/dd-trace/src/plugins/ci_plugin.js +407 -91
  588. package/packages/dd-trace/src/plugins/database.js +61 -18
  589. package/packages/dd-trace/src/plugins/index.js +14 -0
  590. package/packages/dd-trace/src/plugins/log_injection.js +56 -0
  591. package/packages/dd-trace/src/plugins/log_plugin.js +4 -44
  592. package/packages/dd-trace/src/plugins/outbound.js +1 -1
  593. package/packages/dd-trace/src/plugins/plugin.js +19 -28
  594. package/packages/dd-trace/src/plugins/storage.js +2 -2
  595. package/packages/dd-trace/src/plugins/tracing.js +70 -13
  596. package/packages/dd-trace/src/plugins/util/ci.js +127 -40
  597. package/packages/dd-trace/src/plugins/util/git-cache.js +23 -23
  598. package/packages/dd-trace/src/plugins/util/git.js +6 -3
  599. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +276 -0
  600. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +29 -5
  601. package/packages/dd-trace/src/plugins/util/llm.js +6 -1
  602. package/packages/dd-trace/src/plugins/util/stacktrace.js +2 -2
  603. package/packages/dd-trace/src/plugins/util/test.js +950 -69
  604. package/packages/dd-trace/src/plugins/util/url.js +71 -5
  605. package/packages/dd-trace/src/plugins/util/user-provided-git.js +18 -16
  606. package/packages/dd-trace/src/plugins/util/web.js +116 -180
  607. package/packages/dd-trace/src/priority_sampler.js +12 -21
  608. package/packages/dd-trace/src/profiling/config.js +132 -212
  609. package/packages/dd-trace/src/profiling/constants.js +4 -7
  610. package/packages/dd-trace/src/profiling/exporter_cli.js +10 -10
  611. package/packages/dd-trace/src/profiling/exporters/agent.js +61 -28
  612. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +45 -14
  613. package/packages/dd-trace/src/profiling/exporters/file.js +16 -5
  614. package/packages/dd-trace/src/profiling/oom.js +71 -0
  615. package/packages/dd-trace/src/profiling/profiler.js +84 -105
  616. package/packages/dd-trace/src/profiling/profilers/event_plugins/crypto.js +32 -0
  617. package/packages/dd-trace/src/profiling/profilers/event_plugins/zlib.js +19 -0
  618. package/packages/dd-trace/src/profiling/profilers/events.js +57 -13
  619. package/packages/dd-trace/src/profiling/profilers/space.js +27 -16
  620. package/packages/dd-trace/src/profiling/profilers/wall.js +49 -35
  621. package/packages/dd-trace/src/profiling/ssi-heuristics.js +3 -3
  622. package/packages/dd-trace/src/propagation-hash/index.js +1 -1
  623. package/packages/dd-trace/src/proxy.js +128 -37
  624. package/packages/dd-trace/src/rate_limiter.js +1 -1
  625. package/packages/dd-trace/src/remote_config/index.js +6 -5
  626. package/packages/dd-trace/src/remote_config/scheduler.js +1 -1
  627. package/packages/dd-trace/src/ritm.js +6 -3
  628. package/packages/dd-trace/src/runtime_metrics/client.js +30 -0
  629. package/packages/dd-trace/src/runtime_metrics/index.js +14 -4
  630. package/packages/dd-trace/src/runtime_metrics/otlp_runtime_metrics.js +284 -0
  631. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +42 -41
  632. package/packages/dd-trace/src/sampling_rule.js +7 -7
  633. package/packages/dd-trace/src/scope.js +10 -15
  634. package/packages/dd-trace/src/serverless.js +6 -7
  635. package/packages/dd-trace/src/service-naming/extra-services.js +14 -0
  636. package/packages/dd-trace/src/service-naming/index.js +1 -1
  637. package/packages/dd-trace/src/service-naming/schemas/definition.js +4 -1
  638. package/packages/dd-trace/src/service-naming/schemas/util.js +48 -3
  639. package/packages/dd-trace/src/service-naming/schemas/v0/graphql.js +6 -0
  640. package/packages/dd-trace/src/service-naming/schemas/v0/messaging.js +61 -2
  641. package/packages/dd-trace/src/service-naming/schemas/v0/serverless.js +12 -0
  642. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +60 -0
  643. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +25 -1
  644. package/packages/dd-trace/src/service-naming/schemas/v0/websocket.js +5 -0
  645. package/packages/dd-trace/src/service-naming/schemas/v1/graphql.js +8 -0
  646. package/packages/dd-trace/src/service-naming/schemas/v1/messaging.js +32 -0
  647. package/packages/dd-trace/src/service-naming/schemas/v1/serverless.js +12 -0
  648. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +17 -0
  649. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +23 -3
  650. package/packages/dd-trace/src/service-naming/schemas/v1/websocket.js +6 -0
  651. package/packages/dd-trace/src/service-naming/source-resolver.js +50 -0
  652. package/packages/dd-trace/src/span_format.js +269 -81
  653. package/packages/dd-trace/src/span_processor.js +18 -13
  654. package/packages/dd-trace/src/span_stats.js +101 -79
  655. package/packages/dd-trace/src/spanleak.js +1 -2
  656. package/packages/dd-trace/src/standalone/index.js +0 -36
  657. package/packages/dd-trace/src/startup-log.js +3 -3
  658. package/packages/dd-trace/src/tagger.js +2 -4
  659. package/packages/dd-trace/src/telemetry/dependencies.js +2 -2
  660. package/packages/dd-trace/src/telemetry/endpoints.js +7 -5
  661. package/packages/dd-trace/src/telemetry/index.js +2 -2
  662. package/packages/dd-trace/src/telemetry/logs/index.js +1 -1
  663. package/packages/dd-trace/src/telemetry/send-data.js +22 -22
  664. package/packages/dd-trace/src/telemetry/session-propagation.js +1 -1
  665. package/packages/dd-trace/src/telemetry/telemetry.js +16 -14
  666. package/packages/dd-trace/src/tracer.js +23 -9
  667. package/packages/dd-trace/src/tracer_metadata.js +1 -1
  668. package/packages/dd-trace/src/util.js +57 -0
  669. package/register.js +58 -1
  670. package/vendor/dist/@apm-js-collab/code-transformer/index.js +94 -42
  671. package/vendor/dist/@datadog/sketches-js/LICENSE +10 -36
  672. package/vendor/dist/@datadog/sketches-js/index.js +1 -1
  673. package/vendor/dist/pprof-format/index.js +1 -1
  674. package/vendor/dist/protobufjs/index.js +1 -1
  675. package/vendor/dist/protobufjs/minimal/index.js +1 -1
  676. package/vendor/dist/shell-quote/index.js +1 -1
  677. package/packages/datadog-plugin-graphql/src/resolve.js +0 -178
  678. package/packages/dd-trace/src/agent/url.js +0 -28
  679. package/packages/dd-trace/src/appsec/api_security_sampler.js +0 -117
  680. package/packages/dd-trace/src/lambda/runtime/ritm.js +0 -133
  681. package/packages/dd-trace/src/log/utils.js +0 -16
  682. package/packages/dd-trace/src/msgpack/encoder.js +0 -308
  683. package/packages/dd-trace/src/plugins/structured_log_plugin.js +0 -9
  684. package/scripts/preinstall.js +0 -34
  685. package/vendor/dist/ignore/LICENSE +0 -21
  686. package/vendor/dist/ignore/index.js +0 -1
  687. package/vendor/dist/opentracing/LICENSE +0 -201
  688. package/vendor/dist/opentracing/binary_carrier.d.ts +0 -11
  689. package/vendor/dist/opentracing/constants.d.ts +0 -61
  690. package/vendor/dist/opentracing/examples/demo/demo.d.ts +0 -2
  691. package/vendor/dist/opentracing/ext/tags.d.ts +0 -90
  692. package/vendor/dist/opentracing/functions.d.ts +0 -20
  693. package/vendor/dist/opentracing/global_tracer.d.ts +0 -14
  694. package/vendor/dist/opentracing/index.d.ts +0 -12
  695. package/vendor/dist/opentracing/index.js +0 -1
  696. package/vendor/dist/opentracing/mock_tracer/index.d.ts +0 -5
  697. package/vendor/dist/opentracing/mock_tracer/mock_context.d.ts +0 -13
  698. package/vendor/dist/opentracing/mock_tracer/mock_report.d.ts +0 -16
  699. package/vendor/dist/opentracing/mock_tracer/mock_span.d.ts +0 -50
  700. package/vendor/dist/opentracing/mock_tracer/mock_tracer.d.ts +0 -26
  701. package/vendor/dist/opentracing/noop.d.ts +0 -8
  702. package/vendor/dist/opentracing/reference.d.ts +0 -33
  703. package/vendor/dist/opentracing/span.d.ts +0 -147
  704. package/vendor/dist/opentracing/span_context.d.ts +0 -26
  705. package/vendor/dist/opentracing/test/api_compatibility.d.ts +0 -16
  706. package/vendor/dist/opentracing/test/mocktracer_implemenation.d.ts +0 -3
  707. package/vendor/dist/opentracing/test/noop_implementation.d.ts +0 -4
  708. package/vendor/dist/opentracing/test/opentracing_api.d.ts +0 -3
  709. package/vendor/dist/opentracing/test/unittest.d.ts +0 -2
  710. package/vendor/dist/opentracing/tracer.d.ts +0 -127
  711. package/vendor/dist/path-to-regexp/LICENSE +0 -21
  712. package/vendor/dist/path-to-regexp/index.js +0 -1
@@ -1,10 +1,19 @@
1
1
  'use strict'
2
2
 
3
+ // Capture real timers at module load, before any test can install fake timers.
4
+ const { performance } = require('perf_hooks')
5
+ const { basename } = require('node:path')
6
+ const dateNow = Date.now
7
+
8
+ const { createCoverageMap } = require('../../../vendor/dist/istanbul-lib-coverage')
9
+ const satisfies = require('../../../vendor/dist/semifies')
10
+ const { RUM_TEST_EXECUTION_ID_COOKIE_NAME } = require('../../dd-trace/src/ci-visibility/rum')
3
11
  const {
4
12
  TEST_STATUS,
5
- TEST_IS_RUM_ACTIVE,
13
+ setRumTestTags,
6
14
  TEST_CODE_OWNERS,
7
15
  getTestEnvironmentMetadata,
16
+ getTestLevelsMetadataTags,
8
17
  CI_APP_ORIGIN,
9
18
  getTestParentSpan,
10
19
  getCodeOwnersFileEntries,
@@ -17,23 +26,30 @@ const {
17
26
  TEST_MODULE_ID,
18
27
  TEST_SESSION_ID,
19
28
  TEST_COMMAND,
29
+ TEST_LEVELS_METADATA,
20
30
  TEST_MODULE,
21
31
  TEST_SOURCE_START,
22
32
  finishAllTraceSpans,
23
- getCoveredFilenamesFromCoverage,
33
+ getCoveredFilesFromCoverage,
34
+ getExecutableFilesFromCoverage,
35
+ getRelativeCoverageFiles,
36
+ getTestCoverageLinesPercentage,
37
+ applySkippedCoverageToCoverage,
38
+ mergeCoverage,
24
39
  getTestSuitePath,
25
40
  addIntelligentTestRunnerSpanTags,
26
41
  TEST_SKIPPED_BY_ITR,
27
42
  TEST_ITR_UNSKIPPABLE,
28
43
  TEST_ITR_FORCED_RUN,
44
+ TEST_ITR_SKIPPING_ENABLED,
29
45
  ITR_CORRELATION_ID,
30
46
  TEST_SOURCE_FILE,
31
47
  TEST_IS_NEW,
32
48
  TEST_IS_RETRY,
33
49
  TEST_EARLY_FLAKE_ENABLED,
50
+ TEST_EARLY_FLAKE_ABORT_REASON,
34
51
  getTestSessionName,
35
52
  TEST_SESSION_NAME,
36
- TEST_LEVEL_EVENT_TYPES,
37
53
  TEST_RETRY_REASON,
38
54
  DD_TEST_IS_USER_PROVIDED_SERVICE,
39
55
  TEST_MANAGEMENT_IS_QUARANTINED,
@@ -47,16 +63,35 @@ const {
47
63
  getPullRequestDiff,
48
64
  getModifiedFilesFromDiff,
49
65
  getSessionRequestErrorTags,
50
- DD_CI_LIBRARY_CONFIGURATION_ERROR,
66
+ DD_CI_LIBRARY_CONFIGURATION_ERROR_SETTINGS,
67
+ DD_CI_LIBRARY_CONFIGURATION_ERROR_KNOWN_TESTS,
68
+ DD_CI_LIBRARY_CONFIGURATION_ERROR_SKIPPABLE_TESTS,
69
+ DD_CI_LIBRARY_CONFIGURATION_ERROR_TEST_MANAGEMENT_TESTS,
70
+ getSessionItrSkippingEnabledTags,
51
71
  TEST_IS_MODIFIED,
52
72
  TEST_HAS_DYNAMIC_NAME,
73
+ getIsFaultyEarlyFlakeDetection,
53
74
  DYNAMIC_NAME_RE,
54
- logDynamicNamesWarning,
75
+ recordAttemptToFixExecution,
76
+ logAttemptToFixTestExecution,
77
+ logTestOptimizationSummary,
78
+ getEfdRetryCount,
79
+ getMaxEfdRetryCount,
55
80
  getPullRequestBaseBranch,
81
+ TEST_FINAL_STATUS,
82
+ getTestOptimizationRequestResults,
56
83
  } = require('../../dd-trace/src/plugins/util/test')
57
84
  const { isMarkedAsUnskippable } = require('../../datadog-plugin-jest/src/util')
58
85
  const { ORIGIN_KEY, COMPONENT } = require('../../dd-trace/src/constants')
59
- const { getValueFromEnvSources } = require('../../dd-trace/src/config/helper')
86
+ const { RESOURCE_NAME } = require('../../../ext/tags')
87
+ const getConfig = require('../../dd-trace/src/config')
88
+ const {
89
+ SCREENSHOT_UPLOAD_RESULT_ERROR,
90
+ SCREENSHOT_UPLOAD_RESULT_UPLOADED,
91
+ getScreenshotCapturedAtMs,
92
+ getScreenshotUploadResult,
93
+ setScreenshotUploadTags,
94
+ } = require('../../dd-trace/src/ci-visibility/test-screenshot')
60
95
  const { appClosing: appClosingTelemetry } = require('../../dd-trace/src/telemetry')
61
96
  const log = require('../../dd-trace/src/log')
62
97
 
@@ -95,12 +130,13 @@ const {
95
130
  } = require('../../dd-trace/src/plugins/util/env')
96
131
  const { DD_MAJOR } = require('../../../version')
97
132
  const {
98
- resolveOriginalSourcePosition,
133
+ resolveOriginalSourceFile,
99
134
  resolveSourceLineForTest,
100
135
  shouldTrustInvocationDetailsLine,
101
136
  } = require('./source-map-utils')
102
137
 
103
138
  const TEST_FRAMEWORK_NAME = 'cypress'
139
+ let hasWarnedDeprecatedCypressVersion = false
104
140
 
105
141
  const CYPRESS_STATUS_TO_TEST_STATUS = {
106
142
  passed: 'pass',
@@ -109,6 +145,79 @@ const CYPRESS_STATUS_TO_TEST_STATUS = {
109
145
  skipped: 'skip',
110
146
  }
111
147
 
148
+ const SCREENSHOT_ATTEMPT_RE = /\(attempt \d+\)/
149
+
150
+ function getScreenshotFilePath (screenshot) {
151
+ return typeof screenshot === 'string' ? screenshot : screenshot?.path
152
+ }
153
+
154
+ function isFailureScreenshotByMetadata (screenshot, screenshotFilePath) {
155
+ if (screenshot !== null && typeof screenshot === 'object' && screenshot.testFailure !== undefined) {
156
+ return screenshot.testFailure === true
157
+ }
158
+ return screenshotFilePath.includes('(failed)')
159
+ }
160
+
161
+ function isFailureScreenshotForUpload (screenshot) {
162
+ const screenshotFilePath = getScreenshotFilePath(screenshot)
163
+ if (!screenshotFilePath) {
164
+ return false
165
+ }
166
+ if (screenshot !== null && typeof screenshot === 'object') {
167
+ // after:screenshot details omit testFailure for manual cy.screenshot() captures, so this
168
+ // path cannot safely fall back to the '(failed)' filename marker.
169
+ return screenshot.testFailure === true
170
+ }
171
+ return screenshotFilePath.includes('(failed)')
172
+ }
173
+
174
+ function isFailureScreenshot (screenshot) {
175
+ const screenshotFilePath = getScreenshotFilePath(screenshot)
176
+ // Require an explicit failure signal: prefer the `testFailure` metadata, and fall back to the
177
+ // '(failed)' filename marker only when the RunResult omits `testFailure`. This keeps manual
178
+ // cy.screenshot() captures out of the failure-screenshot upload (privacy).
179
+ return !!screenshotFilePath && isFailureScreenshotByMetadata(screenshot, screenshotFilePath)
180
+ }
181
+
182
+ function getAttemptScreenshots (cypressTest, attemptIndex) {
183
+ if (!Array.isArray(cypressTest.attempts)) {
184
+ return []
185
+ }
186
+ const attempt = cypressTest.attempts[attemptIndex]
187
+ if (!Array.isArray(attempt?.screenshots)) {
188
+ return []
189
+ }
190
+ return attempt.screenshots.filter(isFailureScreenshot)
191
+ }
192
+
193
+ function isScreenshotForTestAttempt (screenshot, titleParts, attemptIndex) {
194
+ const screenshotFilePath = getScreenshotFilePath(screenshot)
195
+ if (!screenshotFilePath || !isFailureScreenshot(screenshot)) {
196
+ return false
197
+ }
198
+ for (const titlePart of titleParts) {
199
+ if (!screenshotFilePath.includes(titlePart)) {
200
+ return false
201
+ }
202
+ }
203
+ if (attemptIndex === 0) {
204
+ return !SCREENSHOT_ATTEMPT_RE.test(screenshotFilePath)
205
+ }
206
+ return screenshotFilePath.includes(`(attempt ${attemptIndex + 1})`)
207
+ }
208
+
209
+ function getTestScreenshots (cypressTest, attemptIndex, specScreenshots) {
210
+ const attemptScreenshots = getAttemptScreenshots(cypressTest, attemptIndex)
211
+ if (attemptScreenshots.length > 0) {
212
+ return attemptScreenshots
213
+ }
214
+ if (!Array.isArray(specScreenshots)) {
215
+ return []
216
+ }
217
+ const titleParts = Array.isArray(cypressTest.title) ? cypressTest.title : []
218
+ return specScreenshots.filter(screenshot => isScreenshotForTestAttempt(screenshot, titleParts, attemptIndex))
219
+ }
220
+
112
221
  function getSessionStatus (summary) {
113
222
  if (summary.totalFailed !== undefined && summary.totalFailed > 0) {
114
223
  return 'fail'
@@ -129,6 +238,20 @@ function getCypressVersion (details) {
129
238
  return ''
130
239
  }
131
240
 
241
+ function warnDeprecatedCypressVersion (version) {
242
+ if (DD_MAJOR >= 6 || hasWarnedDeprecatedCypressVersion || !version || !satisfies(version, '<12.0.0')) {
243
+ return
244
+ }
245
+
246
+ hasWarnedDeprecatedCypressVersion = true
247
+ // console.warn does not seem to work reliably in Cypress, so use console.log instead.
248
+ // eslint-disable-next-line no-console
249
+ console.log(
250
+ 'WARNING: dd-trace support for Cypress<12.0.0 is deprecated' +
251
+ ' and will not be supported in dd-trace v6. Please upgrade Cypress to >=12.0.0.'
252
+ )
253
+ }
254
+
132
255
  function getRootDir (details) {
133
256
  if (details?.config) {
134
257
  return details.config.projectRoot || details.config.repoRoot || process.cwd()
@@ -168,13 +291,17 @@ function getSkippableTests (tracer, testConfiguration) {
168
291
  if (!tracer._tracer._exporter?.getSkippableSuites) {
169
292
  return resolve({ err: new Error('Test Optimization was not initialized correctly') })
170
293
  }
171
- tracer._tracer._exporter.getSkippableSuites(testConfiguration, (err, skippableTests, correlationId) => {
172
- resolve({
173
- err,
174
- skippableTests,
175
- correlationId,
176
- })
177
- })
294
+ tracer._tracer._exporter.getSkippableSuites(
295
+ testConfiguration,
296
+ (err, skippableTests, correlationId, skippableTestsCoverage) => {
297
+ resolve({
298
+ err,
299
+ skippableTests,
300
+ correlationId,
301
+ skippableTestsCoverage,
302
+ })
303
+ }
304
+ )
178
305
  })
179
306
  }
180
307
 
@@ -240,22 +367,114 @@ function getSuiteStatus (suiteStats) {
240
367
  return 'pass'
241
368
  }
242
369
 
370
+ function getMatchingCypressTest (cypressTests, testName, attemptIndex, testStatus, preferIndexedMatch = false) {
371
+ let matchingTestByIndex
372
+ let matchingTestByStatus
373
+ let matchingTestIndex = 0
374
+
375
+ for (const cypressTest of cypressTests) {
376
+ if (cypressTest.title.join(' ') !== testName) {
377
+ continue
378
+ }
379
+
380
+ if (matchingTestIndex === attemptIndex) {
381
+ matchingTestByIndex = cypressTest
382
+ }
383
+ matchingTestIndex++
384
+
385
+ if (!matchingTestByStatus && CYPRESS_STATUS_TO_TEST_STATUS[cypressTest.state] === testStatus) {
386
+ matchingTestByStatus = cypressTest
387
+ }
388
+ }
389
+
390
+ return preferIndexedMatch
391
+ ? matchingTestByIndex || matchingTestByStatus
392
+ : matchingTestByStatus || matchingTestByIndex
393
+ }
394
+
395
+ function isCypressHookFailure (cypressTest) {
396
+ return CYPRESS_STATUS_TO_TEST_STATUS[cypressTest.state] === 'fail' &&
397
+ /\bhook\b/.test(String(cypressTest.displayError || ''))
398
+ }
399
+
400
+ const FINAL_STATUS_RETRY_KIND = {
401
+ none: 'none',
402
+ atr: 'atr',
403
+ efd: 'efd',
404
+ atf: 'atf',
405
+ }
406
+
407
+ function getFinalStatusRetryKind ({ finishedTest, finishedTestAttempts, flakyTestRetriesCount }) {
408
+ // Infer retry kind from the executions we actually saw so ATR enabled with
409
+ // a retry count of 0 is still treated as a single final execution.
410
+ if (finishedTest.isAttemptToFix) {
411
+ return FINAL_STATUS_RETRY_KIND.atf
412
+ }
413
+
414
+ if (finishedTestAttempts.some(testAttempt => testAttempt.isEfdRetry)) {
415
+ return FINAL_STATUS_RETRY_KIND.efd
416
+ }
417
+
418
+ if (finishedTestAttempts.length > 1 && flakyTestRetriesCount > 0) {
419
+ return FINAL_STATUS_RETRY_KIND.atr
420
+ }
421
+
422
+ return FINAL_STATUS_RETRY_KIND.none
423
+ }
424
+
425
+ function getFinalStatus ({
426
+ status,
427
+ retryKind,
428
+ hasFailedAllRetries,
429
+ hasPassedAllAtfRetries,
430
+ isQuarantined,
431
+ isDisabled,
432
+ }) {
433
+ // If the test is quarantined or disabled, its final status is skip unless attempt-to-fix takes precedence.
434
+ if (status === 'skip' || (retryKind !== FINAL_STATUS_RETRY_KIND.atf && (isQuarantined || isDisabled))) {
435
+ return 'skip'
436
+ }
437
+
438
+ switch (retryKind) {
439
+ case FINAL_STATUS_RETRY_KIND.atr:
440
+ case FINAL_STATUS_RETRY_KIND.efd:
441
+ // These modes report the aggregate result across attempts.
442
+ return hasFailedAllRetries ? 'fail' : 'pass'
443
+ case FINAL_STATUS_RETRY_KIND.atf:
444
+ // Attempt-to-fix only passes if every execution passed.
445
+ return hasPassedAllAtfRetries ? 'pass' : 'fail'
446
+ default:
447
+ return status
448
+ }
449
+ }
450
+
243
451
  class CypressPlugin {
244
452
  _isInit = false
245
453
  testEnvironmentMetadata = getTestEnvironmentMetadata(TEST_FRAMEWORK_NAME)
246
454
 
247
455
  finishedTestsByFile = {}
248
456
  testStatuses = {}
457
+ hasLibraryConfiguration = false
458
+ isItrEnabled = false
249
459
  isTestsSkipped = false
250
460
  isSuitesSkippingEnabled = false
251
461
  isCodeCoverageEnabled = false
462
+ isCoverageReportUploadEnabled = false
252
463
  isFlakyTestRetriesEnabled = false
253
464
  flakyTestRetriesCount = 0
254
465
  isEarlyFlakeDetectionEnabled = false
466
+ isEarlyFlakeDetectionFaulty = false
255
467
  isKnownTestsEnabled = false
256
468
  earlyFlakeDetectionNumRetries = 0
469
+ earlyFlakeDetectionSlowTestRetries = {}
470
+ efdRetryCountByTest = {}
471
+ efdSlowAbortedTests = {}
472
+ earlyFlakeDetectionFaultyThreshold = 0
257
473
  testsToSkip = []
258
474
  skippedTests = []
475
+ skippedTestIds = new Set()
476
+ skippableTestsCoverage = {}
477
+ testSessionCoverageMap = createCoverageMap()
259
478
  hasForcedToRunSuites = false
260
479
  hasUnskippableSuites = false
261
480
  unskippableSuites = []
@@ -265,6 +484,13 @@ class CypressPlugin {
265
484
  isImpactedTestsEnabled = false
266
485
  modifiedFiles = []
267
486
  newTestsWithDynamicNames = new Set()
487
+ attemptToFixExecutions = new Map()
488
+ loggedAttemptToFixTests = new Set()
489
+ uploadedScreenshotPaths = new Set()
490
+ screenshotUploadPromisesByTraceId = new Map()
491
+ afterScreenshotHandler = undefined
492
+ lastFinishedTest = null
493
+ pendingScreenshotUploads = []
268
494
 
269
495
  constructor () {
270
496
  const {
@@ -317,16 +543,27 @@ class CypressPlugin {
317
543
  this._isInit = false
318
544
  this.finishedTestsByFile = {}
319
545
  this.testStatuses = {}
546
+ this.hasLibraryConfiguration = false
547
+ this.isItrEnabled = false
320
548
  this.isTestsSkipped = false
321
549
  this.isSuitesSkippingEnabled = false
322
550
  this.isCodeCoverageEnabled = false
551
+ this.isCoverageReportUploadEnabled = false
323
552
  this.isFlakyTestRetriesEnabled = false
324
553
  this.flakyTestRetriesCount = 0
325
554
  this.isEarlyFlakeDetectionEnabled = false
555
+ this.isEarlyFlakeDetectionFaulty = false
326
556
  this.isKnownTestsEnabled = false
327
557
  this.earlyFlakeDetectionNumRetries = 0
558
+ this.earlyFlakeDetectionSlowTestRetries = {}
559
+ this.efdRetryCountByTest = {}
560
+ this.efdSlowAbortedTests = {}
561
+ this.earlyFlakeDetectionFaultyThreshold = 0
328
562
  this.testsToSkip = []
329
563
  this.skippedTests = []
564
+ this.skippedTestIds = new Set()
565
+ this.skippableTestsCoverage = {}
566
+ this.testSessionCoverageMap = createCoverageMap()
330
567
  this.hasForcedToRunSuites = false
331
568
  this.hasUnskippableSuites = false
332
569
  this.unskippableSuites = []
@@ -337,6 +574,12 @@ class CypressPlugin {
337
574
  this.testManagementTests = undefined
338
575
  this.isImpactedTestsEnabled = false
339
576
  this.modifiedFiles = []
577
+ this.attemptToFixExecutions = new Map()
578
+ this.loggedAttemptToFixTests = new Set()
579
+ this.uploadedScreenshotPaths = new Set()
580
+ this.screenshotUploadPromisesByTraceId = new Map()
581
+ this.lastFinishedTest = null
582
+ this.pendingScreenshotUploads = []
340
583
  this.activeTestSpan = null
341
584
  this.testSuiteSpan = null
342
585
  this.testModuleSpan = null
@@ -349,6 +592,205 @@ class CypressPlugin {
349
592
  this.rumFlushWaitMillis = undefined
350
593
  this._pendingRequestErrorTags = []
351
594
  this.libraryConfigurationPromise = undefined
595
+ this._timeOrigin = 0
596
+ this._perfOrigin = 0
597
+ }
598
+
599
+ /**
600
+ * Returns a stable after:screenshot handler so auto-instrumentation can recognize
601
+ * the handler registered by the manual plugin and avoid treating it as a user hook.
602
+ *
603
+ * @returns {Function} Datadog after:screenshot handler
604
+ */
605
+ getAfterScreenshotHandler () {
606
+ if (!this.afterScreenshotHandler) {
607
+ this.afterScreenshotHandler = this.afterScreenshot.bind(this)
608
+ }
609
+ return this.afterScreenshotHandler
610
+ }
611
+
612
+ /**
613
+ * Tracks a screenshot upload by its owning test trace id so the test event can be tagged
614
+ * before the span is finished.
615
+ *
616
+ * @param {string} traceId - Test trace id used for the upload
617
+ * @param {Promise<string|undefined>} uploadPromise - Promise resolving to the upload outcome
618
+ * @returns {void}
619
+ */
620
+ addScreenshotUploadPromise (traceId, uploadPromise) {
621
+ const uploadPromises = this.screenshotUploadPromisesByTraceId.get(traceId)
622
+ if (uploadPromises) {
623
+ uploadPromises.push(uploadPromise)
624
+ } else {
625
+ this.screenshotUploadPromisesByTraceId.set(traceId, [uploadPromise])
626
+ }
627
+ }
628
+
629
+ /**
630
+ * Returns the aggregate upload outcome for all screenshots associated with a test trace id.
631
+ *
632
+ * @param {string} traceId - Test trace id used for the upload
633
+ * @returns {Promise<string|undefined>|undefined} Promise resolving to the aggregate upload outcome
634
+ */
635
+ getScreenshotUploadResultPromise (traceId) {
636
+ const uploadPromises = this.screenshotUploadPromisesByTraceId.get(traceId)
637
+ if (!uploadPromises?.length) {
638
+ return
639
+ }
640
+ return Promise.all(uploadPromises).then(getScreenshotUploadResult)
641
+ }
642
+
643
+ /**
644
+ * Returns the current time in the same coordinate system used by span
645
+ * start/finish. Captured at session span creation so it shares the same
646
+ * epoch as the trace without reaching into span internals.
647
+ *
648
+ * @returns {number}
649
+ */
650
+ _now () {
651
+ return this._timeOrigin + performance.now() - this._perfOrigin
652
+ }
653
+
654
+ /**
655
+ * Returns the directory used to normalize coverage file names.
656
+ *
657
+ * @returns {string}
658
+ */
659
+ getCoverageRootDir () {
660
+ return this.repositoryRoot || this.rootDir || process.cwd()
661
+ }
662
+
663
+ /**
664
+ * Returns whether the backend supplied skipped-test coverage data.
665
+ *
666
+ * @returns {boolean}
667
+ */
668
+ hasSkippableTestsCoverage () {
669
+ return !!(this.skippableTestsCoverage &&
670
+ typeof this.skippableTestsCoverage === 'object' &&
671
+ Object.keys(this.skippableTestsCoverage).length > 0)
672
+ }
673
+
674
+ /**
675
+ * Returns whether skipped test coverage should be backfilled into the session coverage map.
676
+ *
677
+ * @returns {boolean}
678
+ */
679
+ shouldBackfillSkippedCoverage () {
680
+ return this.isItrEnabled &&
681
+ this.isCoverageReportUploadEnabled &&
682
+ this.isTestsSkipped &&
683
+ this.hasSkippableTestsCoverage()
684
+ }
685
+
686
+ /**
687
+ * Adds a test's Istanbul coverage to the aggregated session coverage map.
688
+ *
689
+ * @param {object} coverage
690
+ * @returns {void}
691
+ */
692
+ addTestSessionCoverage (coverage) {
693
+ mergeCoverage(coverage, this.testSessionCoverageMap)
694
+ }
695
+
696
+ /**
697
+ * Applies backend skipped-test coverage to the aggregated session coverage map.
698
+ *
699
+ * @returns {boolean}
700
+ */
701
+ applySkippedCoverageToTestSessionCoverage () {
702
+ if (!this.shouldBackfillSkippedCoverage()) {
703
+ return false
704
+ }
705
+
706
+ return applySkippedCoverageToCoverage(
707
+ this.testSessionCoverageMap,
708
+ this.skippableTestsCoverage,
709
+ this.getCoverageRootDir()
710
+ )
711
+ }
712
+
713
+ /**
714
+ * Calculates the total session code coverage percentage when product rules allow reporting it.
715
+ *
716
+ * @param {boolean} hasBackfilledCoverage
717
+ * @returns {number | undefined}
718
+ */
719
+ getTestCodeCoverageLinesTotal (hasBackfilledCoverage) {
720
+ if (!this.testSessionCoverageMap.files().length || (this.isTestsSkipped && !hasBackfilledCoverage)) {
721
+ return
722
+ }
723
+
724
+ return getTestCoverageLinesPercentage(this.testSessionCoverageMap, undefined, this.getCoverageRootDir())
725
+ }
726
+
727
+ /**
728
+ * Returns repository-relative executable-line coverage files for the test session.
729
+ *
730
+ * @returns {Array<{ filename: string, bitmap: Buffer }>}
731
+ */
732
+ getTestSessionCoverageFiles () {
733
+ return getRelativeCoverageFiles(
734
+ getExecutableFilesFromCoverage(this.testSessionCoverageMap),
735
+ this.getCoverageRootDir()
736
+ )
737
+ }
738
+
739
+ /**
740
+ * Uploads executable-line coverage for the test session when backend configuration enables it.
741
+ *
742
+ * @returns {void}
743
+ */
744
+ reportTestSessionCoverage () {
745
+ const exporter = this.tracer._tracer._exporter
746
+ if (
747
+ !this.testSessionSpan ||
748
+ !this.isCoverageReportUploadEnabled ||
749
+ !exporter?.exportCoverage
750
+ ) {
751
+ return
752
+ }
753
+
754
+ const files = this.getTestSessionCoverageFiles()
755
+ if (!files.length) {
756
+ return
757
+ }
758
+
759
+ exporter.exportCoverage({
760
+ sessionId: this.testSessionSpan.context()._traceId,
761
+ files,
762
+ })
763
+ }
764
+
765
+ /**
766
+ * Warns when screenshot upload is enabled but Cypress cannot produce or send the screenshots.
767
+ *
768
+ * @param {object} cypressConfig - Cypress resolved config
769
+ * @param {object} tracer - dd-trace proxy tracer
770
+ * @param {object} testOptimizationConfig - Test Optimization config
771
+ * @returns {void}
772
+ */
773
+ warnIfMisconfiguredTestFailureScreenshots (cypressConfig, tracer, testOptimizationConfig) {
774
+ if (!testOptimizationConfig.DD_TEST_FAILURE_SCREENSHOTS_ENABLED) {
775
+ return
776
+ }
777
+
778
+ if (cypressConfig.screenshotOnRunFailure === false) {
779
+ log.warn(
780
+ '%s %s',
781
+ 'DD_TEST_FAILURE_SCREENSHOTS_ENABLED is true, but Cypress screenshotOnRunFailure is false.',
782
+ 'Datadog cannot upload failure screenshots unless Cypress is configured to capture them.'
783
+ )
784
+ return
785
+ }
786
+
787
+ if (!tracer?._tracer?._exporter?.canUploadTestScreenshots?.()) {
788
+ log.warn(
789
+ '%s %s',
790
+ 'DD_TEST_FAILURE_SCREENSHOTS_ENABLED is true, but Cypress failure screenshot upload is only supported',
791
+ 'in agentless mode.'
792
+ )
793
+ }
352
794
  }
353
795
 
354
796
  // Init function returns a promise that resolves with the Cypress configuration
@@ -359,11 +801,13 @@ class CypressPlugin {
359
801
  this._isInit = true
360
802
  this.tracer = tracer
361
803
  this.cypressConfig = cypressConfig
804
+ warnDeprecatedCypressVersion(cypressConfig.version)
362
805
 
363
806
  this.isTestIsolationEnabled = getIsTestIsolationEnabled(cypressConfig)
364
807
 
365
- const envFlushWait = Number(getValueFromEnvSources('DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS'))
366
- this.rumFlushWaitMillis = Number.isFinite(envFlushWait) ? envFlushWait : undefined
808
+ const testOptimizationConfig = getConfig().testOptimization
809
+ this.rumFlushWaitMillis = testOptimizationConfig.DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS
810
+ this.warnIfMisconfiguredTestFailureScreenshots(cypressConfig, tracer, testOptimizationConfig)
367
811
 
368
812
  if (!this.isTestIsolationEnabled) {
369
813
  log.warn('Test isolation is disabled, retries will not be enabled')
@@ -379,16 +823,21 @@ class CypressPlugin {
379
823
  if (libraryConfigurationResponse.err) {
380
824
  log.error('Cypress plugin library config response error', libraryConfigurationResponse.err)
381
825
  this._pendingRequestErrorTags.push({
382
- tag: DD_CI_LIBRARY_CONFIGURATION_ERROR,
826
+ tag: DD_CI_LIBRARY_CONFIGURATION_ERROR_SETTINGS,
383
827
  value: 'true',
384
828
  })
385
829
  } else {
830
+ this.hasLibraryConfiguration = true
386
831
  const {
387
832
  libraryConfig: {
833
+ isItrEnabled,
388
834
  isSuitesSkippingEnabled,
389
835
  isCodeCoverageEnabled,
836
+ isCoverageReportUploadEnabled,
390
837
  isEarlyFlakeDetectionEnabled,
391
838
  earlyFlakeDetectionNumRetries,
839
+ earlyFlakeDetectionSlowTestRetries,
840
+ earlyFlakeDetectionFaultyThreshold,
392
841
  isFlakyTestRetriesEnabled,
393
842
  flakyTestRetriesCount,
394
843
  isKnownTestsEnabled,
@@ -397,14 +846,24 @@ class CypressPlugin {
397
846
  isImpactedTestsEnabled,
398
847
  },
399
848
  } = libraryConfigurationResponse
849
+ this.isItrEnabled = isItrEnabled
400
850
  this.isSuitesSkippingEnabled = isSuitesSkippingEnabled
401
851
  this.isCodeCoverageEnabled = isCodeCoverageEnabled
852
+ this.isCoverageReportUploadEnabled = isCoverageReportUploadEnabled
402
853
  this.isEarlyFlakeDetectionEnabled = isEarlyFlakeDetectionEnabled
403
854
  this.earlyFlakeDetectionNumRetries = earlyFlakeDetectionNumRetries
855
+ this.earlyFlakeDetectionSlowTestRetries = earlyFlakeDetectionSlowTestRetries ?? {}
856
+ this.earlyFlakeDetectionFaultyThreshold = earlyFlakeDetectionFaultyThreshold
404
857
  this.isKnownTestsEnabled = isKnownTestsEnabled
405
858
  if (isFlakyTestRetriesEnabled && this.isTestIsolationEnabled) {
406
859
  this.isFlakyTestRetriesEnabled = true
407
860
  this.flakyTestRetriesCount = flakyTestRetriesCount ?? 0
861
+ if (typeof this.cypressConfig.retries === 'number') {
862
+ this.cypressConfig.retries = {
863
+ openMode: this.cypressConfig.retries,
864
+ runMode: this.cypressConfig.retries,
865
+ }
866
+ }
408
867
  this.cypressConfig.retries.runMode = this.flakyTestRetriesCount
409
868
  } else {
410
869
  this.flakyTestRetriesCount = 0
@@ -441,15 +900,81 @@ class CypressPlugin {
441
900
  return { isAttemptToFix, isDisabled, isQuarantined }
442
901
  }
443
902
 
903
+ /**
904
+ * Returns how many EFD retries must be scheduled before the first duration is known.
905
+ *
906
+ * @returns {number}
907
+ */
908
+ getConfiguredEfdRetryCount () {
909
+ const { earlyFlakeDetectionSlowTestRetries } = this
910
+ if (!earlyFlakeDetectionSlowTestRetries || !Object.keys(earlyFlakeDetectionSlowTestRetries).length) {
911
+ return this.earlyFlakeDetectionNumRetries
912
+ }
913
+ return getMaxEfdRetryCount(earlyFlakeDetectionSlowTestRetries)
914
+ }
915
+
916
+ /**
917
+ * Returns the selected EFD retry count for a test, or the scheduling count if it has not run yet.
918
+ *
919
+ * @param {string} testSuite
920
+ * @param {string} testName
921
+ * @returns {number}
922
+ */
923
+ getEfdRetryCountForTest (testSuite, testName) {
924
+ const testSuiteRetries = this.efdRetryCountByTest[testSuite]
925
+ if (!testSuiteRetries || testSuiteRetries[testName] === undefined) {
926
+ return this.getConfiguredEfdRetryCount()
927
+ }
928
+ return testSuiteRetries[testName]
929
+ }
930
+
931
+ /**
932
+ * Stores the selected EFD retry count for a test after its first execution duration is known.
933
+ *
934
+ * @param {string} testSuite
935
+ * @param {string} testName
936
+ * @param {number | undefined} duration
937
+ * @returns {number}
938
+ */
939
+ setEfdRetryCountForTest (testSuite, testName, duration) {
940
+ if (!this.efdRetryCountByTest[testSuite]) {
941
+ this.efdRetryCountByTest[testSuite] = {}
942
+ }
943
+ const retryCount = getEfdRetryCount(duration ?? 0, this.earlyFlakeDetectionSlowTestRetries)
944
+ this.efdRetryCountByTest[testSuite][testName] = retryCount
945
+ if (retryCount === 0) {
946
+ if (!this.efdSlowAbortedTests[testSuite]) {
947
+ this.efdSlowAbortedTests[testSuite] = {}
948
+ }
949
+ this.efdSlowAbortedTests[testSuite][testName] = true
950
+ }
951
+ return retryCount
952
+ }
953
+
954
+ /**
955
+ * Returns whether an EFD retry clone is beyond the selected retry count and should be discarded.
956
+ *
957
+ * @param {string} testSuite
958
+ * @param {string} testName
959
+ * @param {number} efdRetryIndex
960
+ * @returns {boolean}
961
+ */
962
+ shouldSkipEfdRetry (testSuite, testName, efdRetryIndex) {
963
+ const testSuiteRetries = this.efdRetryCountByTest[testSuite]
964
+ return testSuiteRetries?.[testName] !== undefined && efdRetryIndex > testSuiteRetries[testName]
965
+ }
966
+
444
967
  getTestSuiteSpan ({ testSuite, testSuiteAbsolutePath }) {
445
- const testSuiteSpanMetadata =
446
- getTestSuiteCommonTags(this.command, this.frameworkVersion, testSuite, TEST_FRAMEWORK_NAME)
968
+ const testSuiteSpanMetadata = {
969
+ ...getTestSuiteCommonTags(this.command, this.frameworkVersion, testSuite, TEST_FRAMEWORK_NAME),
970
+ ...this.getSessionRequestErrorTags(),
971
+ ...this.getSessionItrSkippingEnabledTags(),
972
+ }
447
973
 
448
974
  this.ciVisEvent(TELEMETRY_EVENT_CREATED, 'suite')
449
975
 
450
976
  if (testSuiteAbsolutePath) {
451
- const resolvedSuitePosition = resolveOriginalSourcePosition(testSuiteAbsolutePath, 1)
452
- const resolvedSuiteAbsolutePath = resolvedSuitePosition ? resolvedSuitePosition.sourceFile : testSuiteAbsolutePath
977
+ const resolvedSuiteAbsolutePath = resolveOriginalSourceFile(testSuiteAbsolutePath) || testSuiteAbsolutePath
453
978
  const testSourceFile = getTestSuitePath(resolvedSuiteAbsolutePath, this.repositoryRoot)
454
979
  testSuiteSpanMetadata[TEST_SOURCE_FILE] = testSourceFile
455
980
  testSuiteSpanMetadata[TEST_SOURCE_START] = 1
@@ -472,7 +997,6 @@ class CypressPlugin {
472
997
 
473
998
  getTestSpan ({ testName, testSuite, isUnskippable, isForcedToRun, testSourceFile, isDisabled, isQuarantined }) {
474
999
  const testSuiteTags = {
475
- [TEST_COMMAND]: this.command,
476
1000
  [TEST_MODULE]: TEST_FRAMEWORK_NAME,
477
1001
  }
478
1002
  if (this.testSuiteSpan) {
@@ -497,6 +1021,7 @@ class CypressPlugin {
497
1021
  if (testSourceFile) {
498
1022
  testSpanMetadata[TEST_SOURCE_FILE] = testSourceFile
499
1023
  }
1024
+ Object.assign(testSpanMetadata, this.getSessionItrSkippingEnabledTags())
500
1025
 
501
1026
  const codeOwners = this.getTestCodeOwners({ testSuite, testSourceFile })
502
1027
  if (codeOwners) {
@@ -546,6 +1071,15 @@ class CypressPlugin {
546
1071
  return getSessionRequestErrorTags(this.testSessionSpan)
547
1072
  }
548
1073
 
1074
+ /**
1075
+ * Returns ITR skipping-enabled tags from the test session span for propagation to child events.
1076
+ *
1077
+ * @returns {Record<string, string>}
1078
+ */
1079
+ getSessionItrSkippingEnabledTags () {
1080
+ return getSessionItrSkippingEnabledTags(this.testSessionSpan)
1081
+ }
1082
+
549
1083
  ciVisEvent (name, testLevel, tags = {}) {
550
1084
  incrementCountMetric(name, {
551
1085
  testLevel,
@@ -564,18 +1098,32 @@ class CypressPlugin {
564
1098
  this.frameworkVersion = getCypressVersion(details)
565
1099
  this.rootDir = getRootDir(details)
566
1100
 
1101
+ const {
1102
+ knownTestsResponse,
1103
+ testManagementTestsResponse,
1104
+ skippableSuitesResponse: skippableTestsRequestResponse,
1105
+ } = await getTestOptimizationRequestResults({
1106
+ isKnownTestsEnabled: this.isKnownTestsEnabled,
1107
+ isTestManagementTestsEnabled: this.isTestManagementTestsEnabled,
1108
+ isSuitesSkippingEnabled: this.isSuitesSkippingEnabled,
1109
+ getKnownTests: () => getKnownTests(this.tracer, this.testConfiguration),
1110
+ getTestManagementTests: () => getTestManagementTests(this.tracer, this.testConfiguration),
1111
+ getSkippableSuites: () => getSkippableTests(this.tracer, {
1112
+ ...this.testConfiguration,
1113
+ isCoverageReportUploadEnabled: this.isCoverageReportUploadEnabled,
1114
+ }),
1115
+ })
1116
+
567
1117
  if (this.isKnownTestsEnabled) {
568
- const knownTestsResponse = await getKnownTests(
569
- this.tracer,
570
- this.testConfiguration
571
- )
572
- if (knownTestsResponse.err) {
573
- log.error('Cypress known tests response error', knownTestsResponse.err)
1118
+ const currentKnownTestsResponse = knownTestsResponse || await getKnownTests(this.tracer, this.testConfiguration)
1119
+ if (currentKnownTestsResponse.err) {
1120
+ log.error('Cypress known tests response error', currentKnownTestsResponse.err)
1121
+ this._pendingRequestErrorTags.push({ tag: DD_CI_LIBRARY_CONFIGURATION_ERROR_KNOWN_TESTS, value: 'true' })
574
1122
  this.isEarlyFlakeDetectionEnabled = false
575
1123
  this.isKnownTestsEnabled = false
576
1124
  } else {
577
- if (knownTestsResponse.knownTests[TEST_FRAMEWORK_NAME]) {
578
- this.knownTestsByTestSuite = knownTestsResponse.knownTests[TEST_FRAMEWORK_NAME]
1125
+ if (currentKnownTestsResponse.knownTests?.[TEST_FRAMEWORK_NAME]) {
1126
+ this.knownTestsByTestSuite = currentKnownTestsResponse.knownTests[TEST_FRAMEWORK_NAME]
579
1127
  } else {
580
1128
  this.isEarlyFlakeDetectionEnabled = false
581
1129
  this.isKnownTestsEnabled = false
@@ -583,31 +1131,51 @@ class CypressPlugin {
583
1131
  }
584
1132
  }
585
1133
 
586
- if (this.isSuitesSkippingEnabled) {
587
- const skippableTestsResponse = await getSkippableTests(
588
- this.tracer,
589
- this.testConfiguration
1134
+ if (this.isKnownTestsEnabled && details.specs) {
1135
+ const testSuites = details.specs.map(({ relative }) => relative)
1136
+ const isFaulty = getIsFaultyEarlyFlakeDetection(
1137
+ testSuites,
1138
+ this.knownTestsByTestSuite,
1139
+ this.earlyFlakeDetectionFaultyThreshold
590
1140
  )
1141
+ if (isFaulty) {
1142
+ log.warn('New test detection is disabled because the number of new test files is too high.')
1143
+ this.isEarlyFlakeDetectionEnabled = false
1144
+ this.isEarlyFlakeDetectionFaulty = true
1145
+ this.isKnownTestsEnabled = false
1146
+ }
1147
+ }
1148
+
1149
+ if (this.isSuitesSkippingEnabled) {
1150
+ const skippableTestsResponse =
1151
+ skippableTestsRequestResponse || await getSkippableTests(this.tracer, {
1152
+ ...this.testConfiguration,
1153
+ isCoverageReportUploadEnabled: this.isCoverageReportUploadEnabled,
1154
+ })
591
1155
  if (skippableTestsResponse.err) {
592
1156
  log.error('Cypress skippable tests response error', skippableTestsResponse.err)
1157
+ this._pendingRequestErrorTags.push({ tag: DD_CI_LIBRARY_CONFIGURATION_ERROR_SKIPPABLE_TESTS, value: 'true' })
593
1158
  } else {
594
- const { skippableTests, correlationId } = skippableTestsResponse
1159
+ const { skippableTests, correlationId, skippableTestsCoverage } = skippableTestsResponse
595
1160
  this.testsToSkip = skippableTests || []
1161
+ this.skippableTestsCoverage = skippableTestsCoverage || {}
596
1162
  this.itrCorrelationId = correlationId
597
1163
  incrementCountMetric(TELEMETRY_ITR_SKIPPED, { testLevel: 'test' }, this.testsToSkip.length)
598
1164
  }
599
1165
  }
600
1166
 
601
1167
  if (this.isTestManagementTestsEnabled) {
602
- const testManagementTestsResponse = await getTestManagementTests(
603
- this.tracer,
604
- this.testConfiguration
605
- )
606
- if (testManagementTestsResponse.err) {
607
- log.error('Cypress test management tests response error', testManagementTestsResponse.err)
1168
+ const currentTestManagementTestsResponse =
1169
+ testManagementTestsResponse || await getTestManagementTests(this.tracer, this.testConfiguration)
1170
+ if (currentTestManagementTestsResponse.err) {
1171
+ log.error('Cypress test management tests response error', currentTestManagementTestsResponse.err)
1172
+ this._pendingRequestErrorTags.push({
1173
+ tag: DD_CI_LIBRARY_CONFIGURATION_ERROR_TEST_MANAGEMENT_TESTS,
1174
+ value: 'true',
1175
+ })
608
1176
  this.isTestManagementTestsEnabled = false
609
1177
  } else {
610
- this.testManagementTests = testManagementTestsResponse.testManagementTests
1178
+ this.testManagementTests = currentTestManagementTestsResponse.testManagementTests
611
1179
  }
612
1180
  }
613
1181
 
@@ -640,6 +1208,9 @@ class CypressPlugin {
640
1208
  if (this.isEarlyFlakeDetectionEnabled) {
641
1209
  testSessionSpanMetadata[TEST_EARLY_FLAKE_ENABLED] = 'true'
642
1210
  }
1211
+ if (this.isEarlyFlakeDetectionFaulty) {
1212
+ testSessionSpanMetadata[TEST_EARLY_FLAKE_ABORT_REASON] = 'faulty'
1213
+ }
643
1214
 
644
1215
  const trimmedCommand = DD_MAJOR < 6 ? this.command : 'cypress run'
645
1216
 
@@ -650,21 +1221,28 @@ class CypressPlugin {
650
1221
  )
651
1222
 
652
1223
  if (this.tracer._tracer._exporter?.addMetadataTags) {
653
- const metadataTags = {}
654
- for (const testLevel of TEST_LEVEL_EVENT_TYPES) {
655
- metadataTags[testLevel] = {
1224
+ const metadataTags = {
1225
+ [TEST_LEVELS_METADATA]: {
1226
+ [TEST_COMMAND]: this.command,
656
1227
  [TEST_SESSION_NAME]: testSessionName,
657
- }
1228
+ ...getTestLevelsMetadataTags(this.testEnvironmentMetadata),
1229
+ },
658
1230
  }
659
1231
  const libraryCapabilitiesTags = getLibraryCapabilitiesTags(this.constructor.id, this.frameworkVersion)
660
1232
  metadataTags.test = {
661
- ...metadataTags.test,
662
1233
  ...libraryCapabilitiesTags,
663
1234
  }
664
1235
 
665
1236
  this.tracer._tracer._exporter.addMetadataTags(metadataTags)
666
1237
  }
667
1238
 
1239
+ // Capture time references that match what startSpan records internally
1240
+ // (trace.startTime = Date.now(), trace.ticks = performance.now()).
1241
+ // This lets _now() produce values in the same coordinate system as
1242
+ // span._startTime without accessing span internals.
1243
+ this._timeOrigin = dateNow()
1244
+ this._perfOrigin = performance.now()
1245
+
668
1246
  this.testSessionSpan = this.tracer.startSpan(`${TEST_FRAMEWORK_NAME}.test_session`, {
669
1247
  childOf,
670
1248
  tags: {
@@ -691,6 +1269,11 @@ class CypressPlugin {
691
1269
  },
692
1270
  integrationName: TEST_FRAMEWORK_NAME,
693
1271
  })
1272
+ if (this.hasLibraryConfiguration) {
1273
+ const skippingEnabled = this.isSuitesSkippingEnabled ? 'true' : 'false'
1274
+ this.testSessionSpan.setTag(TEST_ITR_SKIPPING_ENABLED, skippingEnabled)
1275
+ this.testModuleSpan.setTag(TEST_ITR_SKIPPING_ENABLED, skippingEnabled)
1276
+ }
694
1277
  this.ciVisEvent(TELEMETRY_EVENT_CREATED, 'module')
695
1278
 
696
1279
  return details
@@ -703,6 +1286,9 @@ class CypressPlugin {
703
1286
  }
704
1287
  if (this.testSessionSpan && this.testModuleSpan) {
705
1288
  const testStatus = getSessionStatus(suiteStats)
1289
+ const hasBackfilledCoverage = this.applySkippedCoverageToTestSessionCoverage()
1290
+ const testCodeCoverageLinesTotal = this.getTestCodeCoverageLinesTotal(hasBackfilledCoverage)
1291
+
706
1292
  this.testModuleSpan.setTag(TEST_STATUS, testStatus)
707
1293
  this.testSessionSpan.setTag(TEST_STATUS, testStatus)
708
1294
 
@@ -713,6 +1299,7 @@ class CypressPlugin {
713
1299
  isSuitesSkipped: this.isTestsSkipped,
714
1300
  isSuitesSkippingEnabled: this.isSuitesSkippingEnabled,
715
1301
  isCodeCoverageEnabled: this.isCodeCoverageEnabled,
1302
+ testCodeCoverageLinesTotal,
716
1303
  skippingType: 'test',
717
1304
  skippingCount: this.skippedTests.length,
718
1305
  hasForcedToRunSuites: this.hasForcedToRunSuites,
@@ -720,11 +1307,16 @@ class CypressPlugin {
720
1307
  }
721
1308
  )
722
1309
 
1310
+ this.reportTestSessionCoverage()
1311
+
723
1312
  if (this.isTestManagementTestsEnabled) {
724
1313
  this.testSessionSpan.setTag(TEST_MANAGEMENT_ENABLED, 'true')
725
1314
  }
726
1315
 
727
- logDynamicNamesWarning(this.newTestsWithDynamicNames)
1316
+ logTestOptimizationSummary({
1317
+ attemptToFixExecutions: this.attemptToFixExecutions,
1318
+ newTestsWithDynamicNames: this.newTestsWithDynamicNames,
1319
+ })
728
1320
 
729
1321
  this.testModuleSpan.finish()
730
1322
  this.ciVisEvent(TELEMETRY_EVENT_FINISHED, 'module')
@@ -732,7 +1324,7 @@ class CypressPlugin {
732
1324
  this.ciVisEvent(TELEMETRY_EVENT_FINISHED, 'session')
733
1325
  incrementCountMetric(TELEMETRY_TEST_SESSION, {
734
1326
  provider: this.ciProviderName,
735
- autoInjected: !!getValueFromEnvSources('DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER'),
1327
+ autoInjected: !!getConfig().testOptimization.DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER,
736
1328
  })
737
1329
 
738
1330
  finishAllTraceSpans(this.testSessionSpan)
@@ -764,10 +1356,42 @@ class CypressPlugin {
764
1356
  })
765
1357
  }
766
1358
 
1359
+ /**
1360
+ * Uploads failure screenshots as soon as Cypress creates them.
1361
+ *
1362
+ * @param {object} details - Cypress screenshot details
1363
+ * @returns {void}
1364
+ */
1365
+ afterScreenshot (details) {
1366
+ const lastFailedTestSpan = this.lastFinishedTest?.testStatus === 'fail'
1367
+ ? this.lastFinishedTest.testSpan
1368
+ : undefined
1369
+ const testSpan = this.activeTestSpan || lastFailedTestSpan
1370
+
1371
+ if (!testSpan) {
1372
+ return
1373
+ }
1374
+
1375
+ if (!isFailureScreenshotForUpload(details)) {
1376
+ return
1377
+ }
1378
+
1379
+ const screenshotUploadPromise = this.uploadTestScreenshots({
1380
+ screenshots: [details],
1381
+ traceId: testSpan.context().toTraceId(),
1382
+ })
1383
+ if (screenshotUploadPromise) {
1384
+ this.pendingScreenshotUploads.push(screenshotUploadPromise)
1385
+ }
1386
+ }
1387
+
767
1388
  afterSpec (spec, results) {
768
- const { tests, stats } = results || {}
1389
+ const { tests, stats, screenshots } = results || {}
769
1390
  const cypressTests = tests || []
1391
+ const specScreenshots = screenshots || []
770
1392
  const finishedTests = this.finishedTestsByFile[spec.relative] || []
1393
+ const screenshotUploadPromises = []
1394
+ const testSpanFinishPromises = []
771
1395
 
772
1396
  if (!this.testSuiteSpan) {
773
1397
  // dd:testSuiteStart hasn't been triggered for whatever reason
@@ -783,13 +1407,13 @@ class CypressPlugin {
783
1407
  // and create a skipped test span for each of them
784
1408
  for (const { title } of cypressTests) {
785
1409
  const cypressTestName = title.join(' ')
786
- const isTestFinished = finishedTests.find(({ testName }) => cypressTestName === testName)
1410
+ const isTestFinished = finishedTests.some(({ testName }) => cypressTestName === testName)
787
1411
 
788
1412
  if (isTestFinished) {
789
1413
  continue
790
1414
  }
791
1415
 
792
- const isSkippedByItr = this.testsToSkip.find(test =>
1416
+ const isSkippedByItr = this.testsToSkip.some(test =>
793
1417
  cypressTestName === test.name && spec.relative === test.suite
794
1418
  )
795
1419
  const testSourceFile = spec.absolute && this.repositoryRoot
@@ -797,6 +1421,7 @@ class CypressPlugin {
797
1421
  : spec.relative
798
1422
 
799
1423
  const skippedTestSpan = this.getTestSpan({ testName: cypressTestName, testSuite: spec.relative, testSourceFile })
1424
+ skippedTestSpan.setTag(TEST_FINAL_STATUS, 'skip')
800
1425
 
801
1426
  skippedTestSpan.setTag(TEST_STATUS, 'skip')
802
1427
  if (isSkippedByItr) {
@@ -832,17 +1457,25 @@ class CypressPlugin {
832
1457
 
833
1458
  for (const [testName, finishedTestAttempts] of Object.entries(finishedTestsByTestName)) {
834
1459
  for (const [attemptIndex, finishedTest] of finishedTestAttempts.entries()) {
835
- // TODO: there could be multiple if there have been retries!
836
- // potentially we need to match the test status!
837
- const cypressTest = cypressTests.find(test => test.title.join(' ') === testName)
1460
+ // We can check if this is the last attempt regardless of the retry mechanism
1461
+ const isLastAttempt = attemptIndex === finishedTestAttempts.length - 1
1462
+ const isDatadogManagedAttempt = finishedTest.isEfdManagedTest || finishedTest.isAttemptToFix
1463
+ const cypressTest = isDatadogManagedAttempt
1464
+ ? getMatchingCypressTest(cypressTests, testName, attemptIndex, finishedTest.testStatus, isLastAttempt) ||
1465
+ cypressTests.find(test => test.title.join(' ') === testName)
1466
+ : cypressTests.find(test => test.title.join(' ') === testName)
838
1467
  if (!cypressTest) {
839
1468
  continue
840
1469
  }
841
1470
  // finishedTests can include multiple tests with the same name if they have been retried
842
1471
  // by early flake detection. Cypress is unaware of this so .attempts does not necessarily have
843
1472
  // the same length as `finishedTestAttempts`
844
- let cypressTestStatus = CYPRESS_STATUS_TO_TEST_STATUS[cypressTest.state]
845
- if (cypressTest.attempts && cypressTest.attempts[attemptIndex]) {
1473
+ const shouldUseCapturedStatus = isDatadogManagedAttempt && !(isLastAttempt && isCypressHookFailure(cypressTest))
1474
+ let cypressTestStatus = shouldUseCapturedStatus
1475
+ ? finishedTest.testStatus
1476
+ : CYPRESS_STATUS_TO_TEST_STATUS[cypressTest.state]
1477
+ if (!finishedTest.isEfdManagedTest && !finishedTest.isAttemptToFix &&
1478
+ cypressTest.attempts && cypressTest.attempts[attemptIndex]) {
846
1479
  cypressTestStatus = CYPRESS_STATUS_TO_TEST_STATUS[cypressTest.attempts[attemptIndex].state]
847
1480
  const isAtrRetry = attemptIndex > 0 &&
848
1481
  this.isFlakyTestRetriesEnabled &&
@@ -859,21 +1492,42 @@ class CypressPlugin {
859
1492
  }
860
1493
  }
861
1494
  }
1495
+ if (finishedTest.isEfdManagedTest && finishedTest.testStatus !== 'skip' && cypressTestStatus === 'skip') {
1496
+ cypressTestStatus = finishedTest.testStatus
1497
+ }
862
1498
  if (cypressTest.displayError) {
863
1499
  latestError = new Error(cypressTest.displayError)
864
1500
  }
865
- // Update test status - but NOT for quarantined tests where we intentionally
1501
+
1502
+ let failedTestTraceId
1503
+ if (cypressTestStatus === 'fail' || finishedTest.testStatus === 'fail' || cypressTest.displayError) {
1504
+ failedTestTraceId = finishedTest.testSpan.context().toTraceId()
1505
+ const testScreenshots = getTestScreenshots(cypressTest, attemptIndex, specScreenshots)
1506
+ const screenshotUploadPromise = this.uploadTestScreenshots({
1507
+ screenshots: testScreenshots,
1508
+ traceId: failedTestTraceId,
1509
+ })
1510
+ if (screenshotUploadPromise) {
1511
+ screenshotUploadPromises.push(screenshotUploadPromise)
1512
+ }
1513
+ }
1514
+
1515
+ // Update test status - but NOT for non-ATF quarantined tests where we intentionally
866
1516
  // report 'fail' to Datadog even though Cypress sees it as 'pass'
867
- const isQuarantinedTest = finishedTest.testSpan?.context()?._tags?.[TEST_MANAGEMENT_IS_QUARANTINED] === 'true'
868
- if (cypressTestStatus !== finishedTest.testStatus && !isQuarantinedTest) {
1517
+ const isQuarantinedTest = finishedTest.testSpan?.context()?.getTag(TEST_MANAGEMENT_IS_QUARANTINED) === 'true'
1518
+ if (cypressTestStatus !== finishedTest.testStatus && (!isQuarantinedTest || finishedTest.isAttemptToFix)) {
869
1519
  finishedTest.testSpan.setTag(TEST_STATUS, cypressTestStatus)
870
1520
  finishedTest.testSpan.setTag('error', latestError)
1521
+ if (finishedTest.isAttemptToFix && cypressTestStatus === 'fail') {
1522
+ finishedTest.testSpan.setTag(TEST_MANAGEMENT_ATTEMPT_TO_FIX_PASSED, 'false')
1523
+ }
871
1524
  }
872
1525
  if (this.itrCorrelationId) {
873
1526
  finishedTest.testSpan.setTag(ITR_CORRELATION_ID, this.itrCorrelationId)
874
1527
  }
875
- const resolvedSpecPosition = spec.absolute ? resolveOriginalSourcePosition(spec.absolute, 1) : null
876
- const resolvedSpecAbsolutePath = resolvedSpecPosition ? resolvedSpecPosition.sourceFile : spec.absolute
1528
+ const resolvedSpecAbsolutePath = spec.absolute
1529
+ ? resolveOriginalSourceFile(spec.absolute) || spec.absolute
1530
+ : spec.absolute
877
1531
  const testSourceFile = resolvedSpecAbsolutePath && this.repositoryRoot
878
1532
  ? getTestSuitePath(resolvedSpecAbsolutePath, this.repositoryRoot)
879
1533
  : spec.relative
@@ -886,20 +1540,130 @@ class CypressPlugin {
886
1540
  finishedTest.testSpan.setTag(TEST_CODE_OWNERS, codeOwners)
887
1541
  }
888
1542
 
889
- finishedTest.testSpan.finish(finishedTest.finishTime)
1543
+ if (isLastAttempt) {
1544
+ const testSpanTags = finishedTest.testSpan.context().getTags()
1545
+ const retryKind = getFinalStatusRetryKind({
1546
+ finishedTest,
1547
+ finishedTestAttempts,
1548
+ flakyTestRetriesCount: this.flakyTestRetriesCount,
1549
+ })
1550
+
1551
+ const hasFailedAllRetries = testSpanTags[TEST_HAS_FAILED_ALL_RETRIES] === 'true'
1552
+ const hasPassedAllAtfRetries =
1553
+ testSpanTags[TEST_MANAGEMENT_ATTEMPT_TO_FIX_PASSED] === 'true'
1554
+ const isQuarantined = testSpanTags[TEST_MANAGEMENT_IS_QUARANTINED] === 'true'
1555
+ const isDisabled = testSpanTags[TEST_MANAGEMENT_IS_DISABLED] === 'true'
1556
+
1557
+ const finalStatus = getFinalStatus({
1558
+ status: cypressTestStatus,
1559
+ retryKind,
1560
+ hasFailedAllRetries,
1561
+ hasPassedAllAtfRetries,
1562
+ isQuarantined,
1563
+ isDisabled,
1564
+ })
1565
+
1566
+ if (finalStatus) {
1567
+ finishedTest.testSpan.setTag(TEST_FINAL_STATUS, finalStatus)
1568
+ }
1569
+ }
1570
+
1571
+ const screenshotUploadResultPromise = failedTestTraceId
1572
+ ? this.getScreenshotUploadResultPromise(failedTestTraceId)
1573
+ : undefined
1574
+ if (screenshotUploadResultPromise) {
1575
+ testSpanFinishPromises.push(screenshotUploadResultPromise.then((uploadResult) => {
1576
+ setScreenshotUploadTags(finishedTest.testSpan, uploadResult)
1577
+ this.screenshotUploadPromisesByTraceId.delete(failedTestTraceId)
1578
+ finishedTest.testSpan.finish(finishedTest.finishTime)
1579
+ }))
1580
+ } else {
1581
+ finishedTest.testSpan.finish(finishedTest.finishTime)
1582
+ }
890
1583
  }
891
1584
  }
892
1585
 
893
- if (this.testSuiteSpan) {
894
- const status = getSuiteStatus(stats)
895
- this.testSuiteSpan.setTag(TEST_STATUS, status)
1586
+ const finishSuite = () => {
1587
+ if (this.testSuiteSpan) {
1588
+ const status = getSuiteStatus(stats)
1589
+ this.testSuiteSpan.setTag(TEST_STATUS, status)
1590
+
1591
+ if (latestError) {
1592
+ this.testSuiteSpan.setTag('error', latestError)
1593
+ }
1594
+ this.testSuiteSpan.finish()
1595
+ this.testSuiteSpan = null
1596
+ this.ciVisEvent(TELEMETRY_EVENT_FINISHED, 'suite')
1597
+ }
1598
+ }
1599
+
1600
+ const waitForScreenshotUploads = () => {
1601
+ if (screenshotUploadPromises.length > 0 || this.pendingScreenshotUploads.length > 0) {
1602
+ const pendingScreenshotUploads = this.pendingScreenshotUploads
1603
+ this.pendingScreenshotUploads = []
1604
+ return Promise.all([...pendingScreenshotUploads, ...screenshotUploadPromises]).then(() => null)
1605
+ }
1606
+ }
1607
+
1608
+ finishSuite()
1609
+
1610
+ const screenshotUploadsPromise = waitForScreenshotUploads()
1611
+ if (testSpanFinishPromises.length > 0) {
1612
+ const testSpansPromise = Promise.all(testSpanFinishPromises).then(() => null)
1613
+ if (screenshotUploadsPromise) {
1614
+ return Promise.all([testSpansPromise, screenshotUploadsPromise]).then(() => null)
1615
+ }
1616
+ return testSpansPromise
1617
+ }
1618
+
1619
+ return screenshotUploadsPromise
1620
+ }
1621
+
1622
+ /**
1623
+ * Uploads failure screenshots for a Cypress test attempt.
1624
+ *
1625
+ * @param {object} options - Upload options
1626
+ * @param {Array<object|string>} options.screenshots - Cypress screenshot objects or screenshot paths
1627
+ * @param {string} options.traceId - Test trace id used as the screenshot key
1628
+ * @returns {Promise<string|undefined>|undefined}
1629
+ */
1630
+ uploadTestScreenshots ({ screenshots, traceId }) {
1631
+ const exporter = this.tracer?._tracer?._exporter
1632
+ if (!screenshots.length ||
1633
+ !exporter?.canUploadTestScreenshots?.() ||
1634
+ !exporter.uploadTestScreenshot) {
1635
+ return
1636
+ }
1637
+
1638
+ const uploadPromises = []
896
1639
 
897
- if (latestError) {
898
- this.testSuiteSpan.setTag('error', latestError)
1640
+ for (const screenshot of screenshots) {
1641
+ const filePath = getScreenshotFilePath(screenshot)
1642
+ if (!filePath || this.uploadedScreenshotPaths.has(filePath)) {
1643
+ continue
899
1644
  }
900
- this.testSuiteSpan.finish()
901
- this.testSuiteSpan = null
902
- this.ciVisEvent(TELEMETRY_EVENT_FINISHED, 'suite')
1645
+ this.uploadedScreenshotPaths.add(filePath)
1646
+ // Stable per-artifact key (trace + filename) so an upload retry overwrites the
1647
+ // same stored object instead of duplicating; the Cypress filename encodes the
1648
+ // test name and attempt, so it is unique within the trace.
1649
+ const idempotencyKey = `${traceId}:${basename(filePath)}`
1650
+ const capturedAtMs = getScreenshotCapturedAtMs(screenshot, filePath)
1651
+ uploadPromises.push(new Promise(resolve => {
1652
+ exporter.uploadTestScreenshot({
1653
+ filePath,
1654
+ traceId,
1655
+ idempotencyKey,
1656
+ capturedAtMs,
1657
+ }, (err) => {
1658
+ resolve(err ? SCREENSHOT_UPLOAD_RESULT_ERROR : SCREENSHOT_UPLOAD_RESULT_UPLOADED)
1659
+ })
1660
+ }))
1661
+ }
1662
+
1663
+ if (uploadPromises.length > 0) {
1664
+ const uploadPromise = Promise.all(uploadPromises).then(getScreenshotUploadResult)
1665
+ this.addScreenshotUploadPromise(traceId, uploadPromise)
1666
+ return uploadPromise
903
1667
  }
904
1668
  }
905
1669
 
@@ -909,7 +1673,8 @@ class CypressPlugin {
909
1673
  const suitePayload = {
910
1674
  isEarlyFlakeDetectionEnabled: this.isEarlyFlakeDetectionEnabled,
911
1675
  knownTestsForSuite: this.knownTestsByTestSuite?.[testSuite] || [],
912
- earlyFlakeDetectionNumRetries: this.earlyFlakeDetectionNumRetries,
1676
+ earlyFlakeDetectionNumRetries: this.getConfiguredEfdRetryCount(),
1677
+ earlyFlakeDetectionSlowTestRetries: this.earlyFlakeDetectionSlowTestRetries,
913
1678
  isKnownTestsEnabled: this.isKnownTestsEnabled,
914
1679
  isTestManagementEnabled: this.isTestManagementTestsEnabled,
915
1680
  testManagementAttemptToFixRetries: this.testManagementAttemptToFixRetries,
@@ -919,16 +1684,17 @@ class CypressPlugin {
919
1684
  repositoryRoot: this.repositoryRoot,
920
1685
  isTestIsolationEnabled: this.isTestIsolationEnabled,
921
1686
  rumFlushWaitMillis: this.rumFlushWaitMillis,
1687
+ rumTestExecutionIdCookieName: RUM_TEST_EXECUTION_ID_COOKIE_NAME,
922
1688
  }
923
1689
 
924
- if (this.testSuiteSpan) {
925
- return suitePayload
926
- }
927
- this.testSuiteSpan = this.getTestSuiteSpan({ testSuite, testSuiteAbsolutePath })
1690
+ this.testSuiteSpan ||= this.getTestSuiteSpan({ testSuite, testSuiteAbsolutePath })
928
1691
  return suitePayload
929
1692
  },
930
1693
  'dd:beforeEach': (test) => {
931
- const { testName, testSuite } = test
1694
+ const { testId, testName, testSuite, isEfdRetry, efdRetryIndex } = test
1695
+ if (isEfdRetry && this.shouldSkipEfdRetry(testSuite, testName, efdRetryIndex)) {
1696
+ return { shouldSkip: true, shouldDiscard: true }
1697
+ }
932
1698
  const shouldSkip = this.testsToSkip.some(test => {
933
1699
  return testName === test.name && testSuite === test.suite
934
1700
  })
@@ -937,11 +1703,19 @@ class CypressPlugin {
937
1703
  const { isAttemptToFix, isDisabled, isQuarantined } = this.getTestProperties(testSuite, testName)
938
1704
  // skip test
939
1705
  if (shouldSkip && !isUnskippable) {
940
- this.skippedTests.push(test)
1706
+ const skippedTestId = `${testSuite}:${testId || testName}`
1707
+ if (!this.skippedTestIds.has(skippedTestId)) {
1708
+ this.skippedTestIds.add(skippedTestId)
1709
+ this.skippedTests.push(test)
1710
+ }
941
1711
  this.isTestsSkipped = true
942
1712
  return { shouldSkip: true }
943
1713
  }
944
1714
 
1715
+ if (isAttemptToFix) {
1716
+ logAttemptToFixTestExecution(testSuite, testName, this.loggedAttemptToFixTests)
1717
+ }
1718
+
945
1719
  // For disabled tests (not attemptToFix), skip them
946
1720
  if (!isAttemptToFix && isDisabled) {
947
1721
  return { shouldSkip: true }
@@ -962,7 +1736,7 @@ class CypressPlugin {
962
1736
 
963
1737
  return this.activeTestSpan ? { traceId: this.activeTestSpan.context().toTraceId() } : {}
964
1738
  },
965
- 'dd:afterEach': ({ test, coverage }) => {
1739
+ 'dd:afterEach': ({ test, coverage, commands }) => {
966
1740
  if (!this.activeTestSpan) {
967
1741
  log.warn('There is no active test span in dd:afterEach handler')
968
1742
  return null
@@ -981,13 +1755,22 @@ class CypressPlugin {
981
1755
  isEfdRetry,
982
1756
  isAttemptToFix,
983
1757
  isModified,
1758
+ duration,
984
1759
  isQuarantined: isQuarantinedFromSupport,
1760
+ isDisabled: isDisabledFromSupport,
985
1761
  } = test
1762
+ if (coverage && (this.isCodeCoverageEnabled || this.isCoverageReportUploadEnabled)) {
1763
+ this.addTestSessionCoverage(coverage)
1764
+ }
1765
+
986
1766
  if (coverage && this.isCodeCoverageEnabled && this.tracer._tracer._exporter?.exportCoverage) {
987
- const coverageFiles = getCoveredFilenamesFromCoverage(coverage)
988
- const relativeCoverageFiles = [...coverageFiles, testSuiteAbsolutePath].map(
989
- file => getTestSuitePath(file, this.repositoryRoot || this.rootDir)
990
- )
1767
+ const coverageFiles = getCoveredFilesFromCoverage(coverage)
1768
+ const relativeCoverageFiles = getRelativeCoverageFiles(coverageFiles, this.getCoverageRootDir())
1769
+ if (testSuiteAbsolutePath) {
1770
+ relativeCoverageFiles.push({
1771
+ filename: getTestSuitePath(testSuiteAbsolutePath, this.getCoverageRootDir()),
1772
+ })
1773
+ }
991
1774
  if (!relativeCoverageFiles.length) {
992
1775
  incrementCountMetric(TELEMETRY_CODE_COVERAGE_EMPTY)
993
1776
  }
@@ -1001,23 +1784,34 @@ class CypressPlugin {
1001
1784
  }
1002
1785
  this.tracer._tracer._exporter.exportCoverage(formattedCoverage)
1003
1786
  }
1004
- const testStatus = CYPRESS_STATUS_TO_TEST_STATUS[state]
1787
+ const isEfdManagedTest = (isNew || isModified) && this.isEarlyFlakeDetectionEnabled && !isAttemptToFix
1788
+ let testStatus = CYPRESS_STATUS_TO_TEST_STATUS[state]
1789
+ let didAbortSlowEfdRetries = false
1790
+ if (isEfdManagedTest && !isEfdRetry && this.efdRetryCountByTest[testSuite]?.[testName] === undefined) {
1791
+ const retryCount = this.setEfdRetryCountForTest(testSuite, testName, duration)
1792
+ if (retryCount === 0) {
1793
+ didAbortSlowEfdRetries = true
1794
+ this.activeTestSpan.setTag(TEST_EARLY_FLAKE_ABORT_REASON, 'slow')
1795
+ }
1796
+ }
1797
+ if (didAbortSlowEfdRetries && testStatus === 'skip' && !error && duration > 0) {
1798
+ testStatus = 'pass'
1799
+ }
1005
1800
  this.activeTestSpan.setTag(TEST_STATUS, testStatus)
1006
1801
 
1007
- // Save the test status to know if it has passed all retries
1008
- if (this.testStatuses[testName]) {
1009
- this.testStatuses[testName].push(testStatus)
1802
+ const testIdentifier = `${testSuite}\0${testName}`
1803
+ let testStatuses = this.testStatuses[testIdentifier]
1804
+ if (testStatuses) {
1805
+ testStatuses.push(testStatus)
1010
1806
  } else {
1011
- this.testStatuses[testName] = [testStatus]
1807
+ testStatuses = this.testStatuses[testIdentifier] = [testStatus]
1012
1808
  }
1013
- const testStatuses = this.testStatuses[testName]
1809
+ const activeSpanTags = this.activeTestSpan.context().getTags()
1014
1810
 
1015
1811
  if (error) {
1016
1812
  this.activeTestSpan.setTag('error', error)
1017
1813
  }
1018
- if (isRUMActive) {
1019
- this.activeTestSpan.setTag(TEST_IS_RUM_ACTIVE, 'true')
1020
- }
1814
+ setRumTestTags(this.activeTestSpan, isRUMActive)
1021
1815
  // Source-line resolution strategy:
1022
1816
  // 1. If plain JS and no source map, trust invocationDetails.line directly.
1023
1817
  // 2. Otherwise, try invocationDetails.stack line mapped through source map.
@@ -1063,9 +1857,10 @@ class CypressPlugin {
1063
1857
  }
1064
1858
  }
1065
1859
  // Check if all EFD retries failed
1066
- if ((isNew || isModified) && this.earlyFlakeDetectionNumRetries > 0) {
1067
- const isLastEfdAttempt = testStatuses.length === this.earlyFlakeDetectionNumRetries + 1
1068
- if (isLastEfdAttempt && testStatuses.every(status => status === 'fail')) {
1860
+ if (isEfdManagedTest) {
1861
+ const efdRetryCount = this.getEfdRetryCountForTest(testSuite, testName)
1862
+ const isLastEfdAttempt = testStatuses.length === efdRetryCount + 1
1863
+ if (efdRetryCount > 0 && isLastEfdAttempt && testStatuses.every(status => status === 'fail')) {
1069
1864
  this.activeTestSpan.setTag(TEST_HAS_FAILED_ALL_RETRIES, 'true')
1070
1865
  }
1071
1866
  }
@@ -1086,6 +1881,13 @@ class CypressPlugin {
1086
1881
  this.activeTestSpan.setTag(TEST_MANAGEMENT_ATTEMPT_TO_FIX_PASSED, 'true')
1087
1882
  }
1088
1883
  }
1884
+ recordAttemptToFixExecution(this.attemptToFixExecutions, {
1885
+ testSuite,
1886
+ testName,
1887
+ status: testStatus,
1888
+ isDisabled: activeSpanTags[TEST_MANAGEMENT_IS_DISABLED] === 'true',
1889
+ isQuarantined: activeSpanTags[TEST_MANAGEMENT_IS_QUARANTINED] === 'true',
1890
+ })
1089
1891
  }
1090
1892
  // ATR: set TEST_HAS_FAILED_ALL_RETRIES when all auto test retries were exhausted and every attempt failed
1091
1893
  if (this.isFlakyTestRetriesEnabled && !isAttemptToFix && !isEfdRetry &&
@@ -1099,13 +1901,42 @@ class CypressPlugin {
1099
1901
  if (isQuarantinedFromSupport) {
1100
1902
  this.activeTestSpan.setTag(TEST_MANAGEMENT_IS_QUARANTINED, 'true')
1101
1903
  }
1904
+ if (isDisabledFromSupport) {
1905
+ this.activeTestSpan.setTag(TEST_MANAGEMENT_IS_DISABLED, 'true')
1906
+ }
1907
+
1908
+ if (Array.isArray(commands) && commands.length > 0) {
1909
+ for (const command of commands) {
1910
+ const { startTime, endTime } = command
1911
+ if (typeof startTime !== 'number' || typeof endTime !== 'number' || endTime < startTime) {
1912
+ continue
1913
+ }
1914
+ const stepSpan = this.tracer.startSpan('cypress.step', {
1915
+ childOf: this.activeTestSpan,
1916
+ startTime,
1917
+ tags: {
1918
+ [COMPONENT]: 'cypress',
1919
+ 'cypress.command': command.name,
1920
+ [RESOURCE_NAME]: command.name,
1921
+ },
1922
+ })
1923
+ if (command.error) {
1924
+ const errorObj = new Error(command.error.message || String(command.error))
1925
+ if (command.error.name) errorObj.name = command.error.name
1926
+ if (command.error.stack) errorObj.stack = command.error.stack
1927
+ stepSpan.setTag('error', errorObj)
1928
+ }
1929
+ stepSpan.finish(endTime)
1930
+ }
1931
+ }
1102
1932
 
1103
1933
  const finishedTest = {
1104
1934
  testName,
1105
1935
  testStatus,
1106
- finishTime: this.activeTestSpan._getTime(), // we store the finish time here
1936
+ finishTime: this._now(),
1107
1937
  testSpan: this.activeTestSpan,
1108
1938
  isEfdRetry,
1939
+ isEfdManagedTest,
1109
1940
  isAttemptToFix,
1110
1941
  }
1111
1942
  if (this.finishedTestsByFile[testSuite]) {
@@ -1113,14 +1944,14 @@ class CypressPlugin {
1113
1944
  } else {
1114
1945
  this.finishedTestsByFile[testSuite] = [finishedTest]
1115
1946
  }
1947
+ this.lastFinishedTest = finishedTest
1116
1948
  // test spans are finished at after:spec
1117
- const activeSpanTags = this.activeTestSpan.context()._tags
1118
1949
  this.ciVisEvent(TELEMETRY_EVENT_FINISHED, 'test', {
1119
1950
  hasCodeOwners: !!activeSpanTags[TEST_CODE_OWNERS],
1120
1951
  isNew,
1121
1952
  isRum: isRUMActive,
1122
1953
  browserDriver: 'cypress',
1123
- isQuarantined: isQuarantinedFromSupport,
1954
+ isQuarantined: activeSpanTags[TEST_MANAGEMENT_IS_QUARANTINED] === 'true',
1124
1955
  isModified,
1125
1956
  isDisabled: activeSpanTags[TEST_MANAGEMENT_IS_DISABLED] === 'true',
1126
1957
  })