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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (633) hide show
  1. package/LICENSE-3rdparty.csv +89 -104
  2. package/README.md +9 -3
  3. package/changes.json +8 -3
  4. package/ci/init.js +25 -5
  5. package/ci/vitest-no-worker-init-setup.mjs +430 -0
  6. package/ext/exporters.js +1 -0
  7. package/ext/tags.js +3 -0
  8. package/index.d.ts +315 -244
  9. package/index.electron.js +3 -0
  10. package/initialize.mjs +9 -8
  11. package/loader-hook.mjs +154 -47
  12. package/package.json +118 -78
  13. package/packages/datadog-core/src/storage.js +47 -48
  14. package/packages/datadog-esbuild/index.js +32 -1
  15. package/packages/datadog-esbuild/src/utils.js +46 -3
  16. package/packages/datadog-instrumentations/src/aerospike.js +3 -3
  17. package/packages/datadog-instrumentations/src/ai.js +131 -76
  18. package/packages/datadog-instrumentations/src/amqplib.js +6 -7
  19. package/packages/datadog-instrumentations/src/anthropic.js +10 -10
  20. package/packages/datadog-instrumentations/src/apollo-server-core.js +3 -3
  21. package/packages/datadog-instrumentations/src/apollo-server.js +10 -18
  22. package/packages/datadog-instrumentations/src/avsc.js +6 -6
  23. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js-context-methods.js +18 -0
  24. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js.js +111 -0
  25. package/packages/datadog-instrumentations/src/aws-sdk.js +172 -72
  26. package/packages/datadog-instrumentations/src/azure-cosmos.js +7 -0
  27. package/packages/datadog-instrumentations/src/azure-durable-functions.js +8 -8
  28. package/packages/datadog-instrumentations/src/azure-functions.js +3 -0
  29. package/packages/datadog-instrumentations/src/bluebird.js +2 -2
  30. package/packages/datadog-instrumentations/src/body-parser.js +5 -2
  31. package/packages/datadog-instrumentations/src/cassandra-driver.js +12 -9
  32. package/packages/datadog-instrumentations/src/child_process.js +15 -15
  33. package/packages/datadog-instrumentations/src/claude-agent-sdk.js +587 -0
  34. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +41 -24
  35. package/packages/datadog-instrumentations/src/connect.js +14 -12
  36. package/packages/datadog-instrumentations/src/cookie-parser.js +5 -4
  37. package/packages/datadog-instrumentations/src/cookie.js +9 -3
  38. package/packages/datadog-instrumentations/src/couchbase.js +73 -238
  39. package/packages/datadog-instrumentations/src/crypto.js +49 -4
  40. package/packages/datadog-instrumentations/src/cucumber-worker-threads.js +19 -0
  41. package/packages/datadog-instrumentations/src/cucumber.js +747 -187
  42. package/packages/datadog-instrumentations/src/cypress-config.js +164 -56
  43. package/packages/datadog-instrumentations/src/cypress.js +5 -3
  44. package/packages/datadog-instrumentations/src/dns.js +60 -59
  45. package/packages/datadog-instrumentations/src/elasticsearch.js +9 -12
  46. package/packages/datadog-instrumentations/src/electron/preload.js +42 -0
  47. package/packages/datadog-instrumentations/src/electron.js +240 -0
  48. package/packages/datadog-instrumentations/src/express-mongo-sanitize.js +11 -9
  49. package/packages/datadog-instrumentations/src/express-session.js +14 -13
  50. package/packages/datadog-instrumentations/src/express.js +52 -30
  51. package/packages/datadog-instrumentations/src/fastify.js +169 -86
  52. package/packages/datadog-instrumentations/src/fetch.js +5 -5
  53. package/packages/datadog-instrumentations/src/fs.js +22 -20
  54. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +5 -7
  55. package/packages/datadog-instrumentations/src/google-genai.js +4 -4
  56. package/packages/datadog-instrumentations/src/graphql.js +26 -362
  57. package/packages/datadog-instrumentations/src/grpc/client.js +48 -32
  58. package/packages/datadog-instrumentations/src/grpc/server.js +20 -2
  59. package/packages/datadog-instrumentations/src/hapi.js +2 -2
  60. package/packages/datadog-instrumentations/src/helpers/callback-instrumentor.js +74 -0
  61. package/packages/datadog-instrumentations/src/helpers/check-require-cache.js +85 -9
  62. package/packages/datadog-instrumentations/src/helpers/hook.js +4 -1
  63. package/packages/datadog-instrumentations/src/helpers/hooks.js +12 -0
  64. package/packages/datadog-instrumentations/src/helpers/instrument.js +36 -3
  65. package/packages/datadog-instrumentations/src/helpers/kafka.js +58 -0
  66. package/packages/datadog-instrumentations/src/helpers/optional-peer-bundler.js +65 -0
  67. package/packages/datadog-instrumentations/src/helpers/promise-instrumentor.js +42 -0
  68. package/packages/datadog-instrumentations/src/helpers/promise.js +2 -2
  69. package/packages/datadog-instrumentations/src/helpers/register.js +7 -5
  70. package/packages/datadog-instrumentations/src/helpers/require-optional-peer.js +17 -0
  71. package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +13 -5
  72. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +24 -7
  73. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +6 -6
  74. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/aws-durable-execution-sdk-js.js +31 -0
  75. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/azure-cosmos.js +50 -0
  76. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/claude-agent-sdk.js +17 -0
  77. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +201 -0
  78. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +7 -0
  79. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/langgraph.js +4 -2
  80. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/mercurius.js +31 -0
  81. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-sdk.js +35 -0
  82. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +85 -0
  83. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +18 -2
  84. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +49 -224
  85. package/packages/datadog-instrumentations/src/helpers/router-helper.js +8 -8
  86. package/packages/datadog-instrumentations/src/hono.js +71 -9
  87. package/packages/datadog-instrumentations/src/http/client.js +48 -24
  88. package/packages/datadog-instrumentations/src/http/server.js +75 -29
  89. package/packages/datadog-instrumentations/src/http2/client.js +15 -12
  90. package/packages/datadog-instrumentations/src/http2/server.js +156 -23
  91. package/packages/datadog-instrumentations/src/ioredis.js +17 -14
  92. package/packages/datadog-instrumentations/src/iovalkey.js +1 -2
  93. package/packages/datadog-instrumentations/src/jest/bail-reporter.js +42 -0
  94. package/packages/datadog-instrumentations/src/jest/coverage-backfill.js +163 -0
  95. package/packages/datadog-instrumentations/src/jest.js +1783 -401
  96. package/packages/datadog-instrumentations/src/kafkajs.js +284 -170
  97. package/packages/datadog-instrumentations/src/knex.js +17 -17
  98. package/packages/datadog-instrumentations/src/koa.js +15 -14
  99. package/packages/datadog-instrumentations/src/ldapjs.js +5 -5
  100. package/packages/datadog-instrumentations/src/light-my-request.js +2 -2
  101. package/packages/datadog-instrumentations/src/limitd-client.js +4 -4
  102. package/packages/datadog-instrumentations/src/lodash.js +4 -4
  103. package/packages/datadog-instrumentations/src/mariadb.js +18 -16
  104. package/packages/datadog-instrumentations/src/memcached.js +4 -3
  105. package/packages/datadog-instrumentations/src/mercurius.js +11 -0
  106. package/packages/datadog-instrumentations/src/microgateway-core.js +2 -2
  107. package/packages/datadog-instrumentations/src/mocha/common.js +7 -4
  108. package/packages/datadog-instrumentations/src/mocha/main.js +557 -118
  109. package/packages/datadog-instrumentations/src/mocha/utils.js +531 -131
  110. package/packages/datadog-instrumentations/src/mocha/worker.js +27 -9
  111. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +254 -0
  112. package/packages/datadog-instrumentations/src/mongodb-core.js +43 -31
  113. package/packages/datadog-instrumentations/src/mongodb.js +79 -5
  114. package/packages/datadog-instrumentations/src/mongoose.js +43 -34
  115. package/packages/datadog-instrumentations/src/mquery.js +5 -5
  116. package/packages/datadog-instrumentations/src/multer.js +5 -4
  117. package/packages/datadog-instrumentations/src/mysql.js +17 -17
  118. package/packages/datadog-instrumentations/src/mysql2.js +39 -5
  119. package/packages/datadog-instrumentations/src/nats.js +182 -0
  120. package/packages/datadog-instrumentations/src/net.js +19 -11
  121. package/packages/datadog-instrumentations/src/next.js +44 -10
  122. package/packages/datadog-instrumentations/src/nyc.js +43 -6
  123. package/packages/datadog-instrumentations/src/openai.js +124 -38
  124. package/packages/datadog-instrumentations/src/oracledb.js +12 -7
  125. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +27 -6
  126. package/packages/datadog-instrumentations/src/passport-utils.js +5 -5
  127. package/packages/datadog-instrumentations/src/path-to-regexp.js +44 -0
  128. package/packages/datadog-instrumentations/src/pg.js +58 -25
  129. package/packages/datadog-instrumentations/src/pino.js +25 -41
  130. package/packages/datadog-instrumentations/src/playwright-browser-scripts.js +27 -0
  131. package/packages/datadog-instrumentations/src/playwright.js +1086 -350
  132. package/packages/datadog-instrumentations/src/protobufjs.js +16 -16
  133. package/packages/datadog-instrumentations/src/redis.js +28 -15
  134. package/packages/datadog-instrumentations/src/restify.js +6 -5
  135. package/packages/datadog-instrumentations/src/router.js +243 -87
  136. package/packages/datadog-instrumentations/src/selenium.js +1 -2
  137. package/packages/datadog-instrumentations/src/stripe.js +47 -33
  138. package/packages/datadog-instrumentations/src/tedious.js +28 -0
  139. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1297 -0
  140. package/packages/datadog-instrumentations/src/vitest-main.js +1592 -0
  141. package/packages/datadog-instrumentations/src/vitest-util.js +251 -0
  142. package/packages/datadog-instrumentations/src/vitest-worker.js +822 -0
  143. package/packages/datadog-instrumentations/src/vitest.js +11 -1262
  144. package/packages/datadog-instrumentations/src/winston.js +4 -4
  145. package/packages/datadog-instrumentations/src/ws.js +7 -7
  146. package/packages/datadog-instrumentations/src/zlib.js +29 -0
  147. package/packages/datadog-plugin-ai/src/index.js +1 -1
  148. package/packages/datadog-plugin-ai/src/tracing.js +66 -3
  149. package/packages/datadog-plugin-ai/src/utils.js +17 -4
  150. package/packages/datadog-plugin-apollo/src/gateway/request.js +1 -21
  151. package/packages/datadog-plugin-avsc/src/schema_iterator.js +3 -3
  152. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/checkpoint.js +31 -0
  153. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/client.js +55 -0
  154. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/context.js +123 -0
  155. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/handler.js +129 -0
  156. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/index.js +19 -0
  157. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/trace-checkpoint.js +224 -0
  158. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +79 -0
  159. package/packages/datadog-plugin-aws-sdk/src/base.js +86 -50
  160. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +1 -1
  161. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +218 -4
  162. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +1 -1
  163. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +2 -1
  164. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +59 -14
  165. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +174 -75
  166. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +34 -23
  167. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +2 -1
  168. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +1 -1
  169. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +26 -26
  170. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +187 -101
  171. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +20 -18
  172. package/packages/datadog-plugin-azure-cosmos/src/index.js +144 -0
  173. package/packages/datadog-plugin-azure-event-hubs/src/producer.js +8 -15
  174. package/packages/datadog-plugin-azure-functions/src/index.js +7 -3
  175. package/packages/datadog-plugin-azure-service-bus/src/producer.js +5 -10
  176. package/packages/datadog-plugin-bullmq/src/consumer.js +5 -4
  177. package/packages/datadog-plugin-bullmq/src/filter.js +35 -0
  178. package/packages/datadog-plugin-bullmq/src/producer.js +121 -33
  179. package/packages/datadog-plugin-bunyan/src/index.js +28 -0
  180. package/packages/datadog-plugin-child_process/src/index.js +13 -2
  181. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +6 -6
  182. package/packages/datadog-plugin-claude-agent-sdk/src/index.js +31 -0
  183. package/packages/datadog-plugin-claude-agent-sdk/src/tracing.js +107 -0
  184. package/packages/datadog-plugin-claude-agent-sdk/src/util.js +15 -0
  185. package/packages/datadog-plugin-couchbase/src/index.js +58 -52
  186. package/packages/datadog-plugin-cucumber/src/index.js +46 -28
  187. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +961 -92
  188. package/packages/datadog-plugin-cypress/src/index.js +104 -2
  189. package/packages/datadog-plugin-cypress/src/plugin.js +6 -14
  190. package/packages/datadog-plugin-cypress/src/source-map-utils.js +48 -1
  191. package/packages/datadog-plugin-cypress/src/support.js +180 -25
  192. package/packages/datadog-plugin-dd-trace-api/src/index.js +1 -1
  193. package/packages/datadog-plugin-dns/src/lookup.js +8 -6
  194. package/packages/datadog-plugin-elasticsearch/src/index.js +28 -8
  195. package/packages/datadog-plugin-electron/src/index.js +17 -0
  196. package/packages/datadog-plugin-electron/src/ipc.js +143 -0
  197. package/packages/datadog-plugin-electron/src/net.js +82 -0
  198. package/packages/datadog-plugin-express/src/code_origin.js +1 -1
  199. package/packages/datadog-plugin-fastify/src/code_origin.js +1 -1
  200. package/packages/datadog-plugin-fs/src/index.js +2 -1
  201. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -5
  202. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +27 -18
  203. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +5 -8
  204. package/packages/datadog-plugin-graphql/src/execute.js +706 -34
  205. package/packages/datadog-plugin-graphql/src/index.js +43 -9
  206. package/packages/datadog-plugin-graphql/src/parse.js +45 -4
  207. package/packages/datadog-plugin-graphql/src/request.js +135 -0
  208. package/packages/datadog-plugin-graphql/src/tools/signature.js +32 -7
  209. package/packages/datadog-plugin-graphql/src/tools/transforms.js +118 -100
  210. package/packages/datadog-plugin-graphql/src/utils.js +261 -3
  211. package/packages/datadog-plugin-graphql/src/validate.js +53 -7
  212. package/packages/datadog-plugin-grpc/src/client.js +7 -8
  213. package/packages/datadog-plugin-grpc/src/server.js +1 -1
  214. package/packages/datadog-plugin-grpc/src/util.js +57 -22
  215. package/packages/datadog-plugin-http/src/client.js +12 -14
  216. package/packages/datadog-plugin-http/src/index.js +6 -8
  217. package/packages/datadog-plugin-http/src/server.js +63 -20
  218. package/packages/datadog-plugin-http2/src/client.js +6 -3
  219. package/packages/datadog-plugin-http2/src/server.js +48 -8
  220. package/packages/datadog-plugin-jest/src/index.js +133 -67
  221. package/packages/datadog-plugin-jest/src/util.js +37 -16
  222. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +1 -1
  223. package/packages/datadog-plugin-kafkajs/src/consumer.js +2 -9
  224. package/packages/datadog-plugin-kafkajs/src/producer.js +37 -8
  225. package/packages/datadog-plugin-langgraph/src/stream.js +1 -1
  226. package/packages/datadog-plugin-memcached/src/index.js +1 -1
  227. package/packages/datadog-plugin-mocha/src/index.js +66 -20
  228. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/index.js +24 -0
  229. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +173 -0
  230. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +30 -0
  231. package/packages/datadog-plugin-mongodb-core/src/bulk-write.js +43 -0
  232. package/packages/datadog-plugin-mongodb-core/src/index.js +8 -206
  233. package/packages/datadog-plugin-mongodb-core/src/query.js +452 -0
  234. package/packages/datadog-plugin-mysql/src/index.js +9 -4
  235. package/packages/datadog-plugin-nats/src/consumer.js +43 -0
  236. package/packages/datadog-plugin-nats/src/index.js +20 -0
  237. package/packages/datadog-plugin-nats/src/producer.js +62 -0
  238. package/packages/datadog-plugin-nats/src/util.js +33 -0
  239. package/packages/datadog-plugin-next/src/index.js +12 -4
  240. package/packages/datadog-plugin-openai/src/services.js +4 -3
  241. package/packages/datadog-plugin-openai/src/tracing.js +27 -25
  242. package/packages/datadog-plugin-oracledb/src/index.js +13 -2
  243. package/packages/datadog-plugin-pg/src/index.js +13 -3
  244. package/packages/datadog-plugin-pino/src/index.js +42 -0
  245. package/packages/datadog-plugin-playwright/src/index.js +21 -11
  246. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +3 -3
  247. package/packages/datadog-plugin-redis/src/index.js +54 -25
  248. package/packages/datadog-plugin-rhea/src/producer.js +1 -1
  249. package/packages/datadog-plugin-router/src/index.js +46 -44
  250. package/packages/datadog-plugin-selenium/src/index.js +1 -1
  251. package/packages/datadog-plugin-tedious/src/index.js +1 -1
  252. package/packages/datadog-plugin-undici/src/index.js +24 -2
  253. package/packages/datadog-plugin-vitest/src/index.js +160 -90
  254. package/packages/datadog-plugin-winston/src/index.js +30 -0
  255. package/packages/datadog-plugin-ws/src/close.js +3 -1
  256. package/packages/datadog-plugin-ws/src/producer.js +2 -0
  257. package/packages/datadog-plugin-ws/src/receiver.js +2 -1
  258. package/packages/datadog-shimmer/src/shimmer.js +101 -39
  259. package/packages/datadog-webpack/index.js +17 -1
  260. package/packages/datadog-webpack/src/optional-peer-loader.js +17 -0
  261. package/packages/dd-trace/index.electron.js +3 -0
  262. package/packages/dd-trace/index.js +2 -36
  263. package/packages/dd-trace/src/aiguard/channels.js +7 -0
  264. package/packages/dd-trace/src/aiguard/index.js +16 -34
  265. package/packages/dd-trace/src/aiguard/integrations/evaluate.js +46 -0
  266. package/packages/dd-trace/src/aiguard/integrations/index.js +34 -0
  267. package/packages/dd-trace/src/aiguard/integrations/openai.js +80 -0
  268. package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +92 -0
  269. package/packages/dd-trace/src/aiguard/messages/openai.js +382 -0
  270. package/packages/{datadog-instrumentations/src/helpers/ai-messages.js → dd-trace/src/aiguard/messages/vercel-ai.js} +30 -27
  271. package/packages/dd-trace/src/aiguard/sdk.js +147 -54
  272. package/packages/dd-trace/src/aiguard/tags.js +26 -10
  273. package/packages/dd-trace/src/appsec/api_security/index.js +55 -0
  274. package/packages/dd-trace/src/appsec/api_security/sampler.js +147 -0
  275. package/packages/dd-trace/src/appsec/blocked_templates.js +4 -3
  276. package/packages/dd-trace/src/appsec/blocking.js +82 -42
  277. package/packages/dd-trace/src/appsec/channels.js +5 -1
  278. package/packages/dd-trace/src/appsec/downstream_requests.js +116 -62
  279. package/packages/dd-trace/src/appsec/graphql.js +20 -17
  280. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +1 -1
  281. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +81 -81
  282. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +23 -23
  283. package/packages/dd-trace/src/appsec/iast/index.js +3 -2
  284. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +4 -4
  285. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +2 -2
  286. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +4 -4
  287. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -2
  288. package/packages/dd-trace/src/appsec/iast/telemetry/index.js +2 -1
  289. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +54 -12
  290. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +5 -1
  291. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +31 -4
  292. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +1 -3
  293. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +83 -48
  294. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +1 -1
  295. package/packages/dd-trace/src/appsec/index.js +65 -47
  296. package/packages/dd-trace/src/appsec/lambda.js +135 -0
  297. package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -5
  298. package/packages/dd-trace/src/appsec/rasp/lfi.js +8 -4
  299. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +5 -10
  300. package/packages/dd-trace/src/appsec/rasp/ssrf.js +26 -18
  301. package/packages/dd-trace/src/appsec/recommended.json +2438 -13
  302. package/packages/dd-trace/src/appsec/reporter.js +87 -28
  303. package/packages/dd-trace/src/appsec/rule_manager.js +4 -2
  304. package/packages/dd-trace/src/appsec/sdk/set_user.js +1 -1
  305. package/packages/dd-trace/src/appsec/sdk/track_event.js +5 -5
  306. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +7 -11
  307. package/packages/dd-trace/src/appsec/sdk/utils.js +5 -3
  308. package/packages/dd-trace/src/appsec/store.js +50 -0
  309. package/packages/dd-trace/src/appsec/telemetry/api_security.js +34 -0
  310. package/packages/dd-trace/src/appsec/telemetry/index.js +27 -1
  311. package/packages/dd-trace/src/appsec/user_tracking.js +5 -4
  312. package/packages/dd-trace/src/appsec/waf/index.js +19 -9
  313. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +35 -20
  314. package/packages/dd-trace/src/appsec/waf/waf_manager.js +1 -1
  315. package/packages/dd-trace/src/azure_metadata.js +17 -6
  316. package/packages/dd-trace/src/baggage.js +32 -13
  317. package/packages/dd-trace/src/bootstrap.js +39 -0
  318. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +30 -5
  319. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +122 -24
  320. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +22 -7
  321. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +5 -2
  322. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +2 -2
  323. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +2 -2
  324. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +6 -2
  325. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -2
  326. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +148 -25
  327. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +3 -4
  328. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +28 -10
  329. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +22 -0
  330. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +105 -22
  331. package/packages/dd-trace/src/ci-visibility/lage.js +2 -1
  332. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +4 -5
  333. package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +4 -5
  334. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +73 -55
  335. package/packages/dd-trace/src/ci-visibility/requests/request.js +14 -50
  336. package/packages/dd-trace/src/ci-visibility/requests/upload-coverage-report.js +4 -4
  337. package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +156 -0
  338. package/packages/dd-trace/src/ci-visibility/test-api-manual/test-api-manual-plugin.js +5 -3
  339. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +24 -6
  340. package/packages/dd-trace/src/ci-visibility/test-optimization-cache.js +70 -6
  341. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +128 -0
  342. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +291 -0
  343. package/packages/dd-trace/src/config/config-types.d.ts +8 -6
  344. package/packages/dd-trace/src/config/defaults.js +71 -44
  345. package/packages/dd-trace/src/config/generated-config-types.d.ts +676 -131
  346. package/packages/dd-trace/src/config/git_properties.js +2 -2
  347. package/packages/dd-trace/src/config/helper.js +139 -33
  348. package/packages/dd-trace/src/config/index.js +117 -131
  349. package/packages/dd-trace/src/config/major-overrides.js +100 -0
  350. package/packages/dd-trace/src/config/normalize-service.js +31 -0
  351. package/packages/dd-trace/src/config/parsers.js +138 -10
  352. package/packages/dd-trace/src/config/remote_config.js +1 -1
  353. package/packages/dd-trace/src/config/supported-configurations.json +394 -203
  354. package/packages/dd-trace/src/constants.js +15 -0
  355. package/packages/dd-trace/src/crashtracking/crashtracker.js +18 -6
  356. package/packages/dd-trace/src/datastreams/checkpointer.js +6 -12
  357. package/packages/dd-trace/src/datastreams/context.js +4 -2
  358. package/packages/dd-trace/src/datastreams/encoding.js +39 -28
  359. package/packages/dd-trace/src/datastreams/index.js +2 -1
  360. package/packages/dd-trace/src/datastreams/manager.js +1 -1
  361. package/packages/dd-trace/src/datastreams/pathway.js +35 -30
  362. package/packages/dd-trace/src/datastreams/processor.js +31 -22
  363. package/packages/dd-trace/src/datastreams/size.js +6 -2
  364. package/packages/dd-trace/src/datastreams/writer.js +15 -6
  365. package/packages/dd-trace/src/debugger/config.js +9 -4
  366. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +49 -35
  367. package/packages/dd-trace/src/debugger/devtools_client/condition.js +5 -8
  368. package/packages/dd-trace/src/debugger/devtools_client/config.js +3 -2
  369. package/packages/dd-trace/src/debugger/devtools_client/index.js +33 -71
  370. package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +83 -0
  371. package/packages/dd-trace/src/debugger/devtools_client/send.js +27 -6
  372. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +2 -2
  373. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +5 -2
  374. package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +1 -0
  375. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +1 -1
  376. package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
  377. package/packages/dd-trace/src/debugger/index.js +13 -9
  378. package/packages/dd-trace/src/debugger/probe_sampler.js +112 -0
  379. package/packages/dd-trace/src/debugger/probe_sampler_constants.js +19 -0
  380. package/packages/dd-trace/src/dogstatsd.js +34 -28
  381. package/packages/dd-trace/src/encode/0.4.js +829 -268
  382. package/packages/dd-trace/src/encode/0.5.js +158 -22
  383. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +141 -65
  384. package/packages/dd-trace/src/encode/agentless-json.js +12 -6
  385. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +52 -15
  386. package/packages/dd-trace/src/encode/span-stats.js +19 -16
  387. package/packages/dd-trace/src/encode/tags-processors.js +30 -25
  388. package/packages/dd-trace/src/exporter.js +3 -1
  389. package/packages/dd-trace/src/exporters/agent/index.js +4 -5
  390. package/packages/dd-trace/src/exporters/agent/writer.js +1 -2
  391. package/packages/dd-trace/src/exporters/agentless/index.js +12 -13
  392. package/packages/dd-trace/src/exporters/agentless/intake.js +43 -0
  393. package/packages/dd-trace/src/exporters/agentless/writer.js +12 -11
  394. package/packages/dd-trace/src/exporters/common/agents.js +3 -1
  395. package/packages/dd-trace/src/exporters/common/buffering-exporter.js +3 -3
  396. package/packages/dd-trace/src/exporters/common/request.js +48 -28
  397. package/packages/dd-trace/src/exporters/common/retry.js +104 -0
  398. package/packages/dd-trace/src/exporters/common/url.js +34 -0
  399. package/packages/dd-trace/src/exporters/common/util.js +2 -2
  400. package/packages/dd-trace/src/exporters/common/writer.js +17 -1
  401. package/packages/dd-trace/src/exporters/electron/index.js +49 -0
  402. package/packages/dd-trace/src/exporters/span-stats/index.js +1 -2
  403. package/packages/dd-trace/src/exporters/span-stats/writer.js +1 -3
  404. package/packages/dd-trace/src/external-logger/src/index.js +2 -1
  405. package/packages/dd-trace/src/feature-registry.js +22 -0
  406. package/packages/dd-trace/src/git_metadata.js +68 -0
  407. package/packages/dd-trace/src/git_metadata_tagger.js +13 -5
  408. package/packages/dd-trace/src/guardrails/index.js +11 -6
  409. package/packages/dd-trace/src/guardrails/telemetry.js +40 -3
  410. package/packages/dd-trace/src/heap_snapshots.js +4 -4
  411. package/packages/dd-trace/src/id.js +46 -27
  412. package/packages/dd-trace/src/index.js +7 -8
  413. package/packages/dd-trace/src/lambda/handler-paths.js +52 -0
  414. package/packages/dd-trace/src/lambda/handler.js +2 -6
  415. package/packages/dd-trace/src/lambda/index.js +62 -14
  416. package/packages/dd-trace/src/lambda/runtime/patch.js +21 -46
  417. package/packages/dd-trace/src/llmobs/constants/tags.js +13 -0
  418. package/packages/dd-trace/src/llmobs/index.js +37 -7
  419. package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +403 -0
  420. package/packages/dd-trace/src/llmobs/plugins/ai/index.js +8 -395
  421. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +119 -7
  422. package/packages/dd-trace/src/llmobs/plugins/ai/vercelTelemetry.js +363 -0
  423. package/packages/dd-trace/src/llmobs/plugins/{anthropic.js → anthropic/index.js} +32 -79
  424. package/packages/dd-trace/src/llmobs/plugins/anthropic/util.js +109 -0
  425. package/packages/dd-trace/src/llmobs/plugins/base.js +4 -4
  426. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +89 -37
  427. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +270 -0
  428. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +10 -0
  429. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +5 -1
  430. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +81 -16
  431. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +3 -2
  432. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +3 -2
  433. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/embedding.js +2 -1
  434. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +1 -50
  435. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/vectorstore.js +2 -1
  436. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +14 -8
  437. package/packages/dd-trace/src/llmobs/plugins/langchain/messages.js +76 -0
  438. package/packages/dd-trace/src/llmobs/plugins/langgraph/index.js +3 -28
  439. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +68 -0
  440. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +57 -0
  441. package/packages/dd-trace/src/llmobs/plugins/openai/index.js +21 -51
  442. package/packages/dd-trace/src/llmobs/sdk.js +56 -35
  443. package/packages/dd-trace/src/llmobs/span_processor.js +90 -11
  444. package/packages/dd-trace/src/llmobs/tagger.js +129 -4
  445. package/packages/dd-trace/src/llmobs/telemetry.js +31 -1
  446. package/packages/dd-trace/src/llmobs/util.js +202 -9
  447. package/packages/dd-trace/src/llmobs/writers/base.js +11 -5
  448. package/packages/dd-trace/src/llmobs/writers/spans.js +1 -1
  449. package/packages/dd-trace/src/llmobs/writers/util.js +1 -2
  450. package/packages/dd-trace/src/log/index.js +19 -31
  451. package/packages/dd-trace/src/log/writer.js +3 -1
  452. package/packages/dd-trace/src/msgpack/chunk.js +430 -11
  453. package/packages/dd-trace/src/msgpack/index.js +101 -2
  454. package/packages/dd-trace/src/noop/proxy.js +5 -4
  455. package/packages/dd-trace/src/noop/span.js +3 -1
  456. package/packages/dd-trace/src/openfeature/encoding.js +70 -0
  457. package/packages/dd-trace/src/openfeature/eval-metrics-hook.js +103 -0
  458. package/packages/dd-trace/src/openfeature/flagging_provider.js +26 -1
  459. package/packages/dd-trace/src/openfeature/noop.js +40 -36
  460. package/packages/dd-trace/src/openfeature/register.js +46 -0
  461. package/packages/dd-trace/src/openfeature/remote_config.js +6 -1
  462. package/packages/dd-trace/src/openfeature/span-enrichment-hook.js +143 -0
  463. package/packages/dd-trace/src/openfeature/span-enrichment.js +149 -0
  464. package/packages/dd-trace/src/openfeature/writers/base.js +3 -11
  465. package/packages/dd-trace/src/openfeature/writers/exposures.js +82 -70
  466. package/packages/dd-trace/src/openfeature/writers/util.js +1 -2
  467. package/packages/dd-trace/src/opentelemetry/active-span-proxy.js +42 -0
  468. package/packages/dd-trace/src/opentelemetry/bridge-span-base.js +107 -0
  469. package/packages/dd-trace/src/opentelemetry/context_manager.js +27 -13
  470. package/packages/dd-trace/src/opentelemetry/logs/index.js +6 -6
  471. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +3 -2
  472. package/packages/dd-trace/src/opentelemetry/metrics/index.js +61 -12
  473. package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +28 -14
  474. package/packages/dd-trace/src/opentelemetry/metrics/meter.js +7 -10
  475. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +3 -2
  476. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +40 -0
  477. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js +169 -0
  478. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +99 -5
  479. package/packages/dd-trace/src/opentelemetry/metrics/time.js +19 -0
  480. package/packages/dd-trace/src/opentelemetry/otlp/common.proto +2 -2
  481. package/packages/dd-trace/src/opentelemetry/otlp/logs.proto +1 -1
  482. package/packages/dd-trace/src/opentelemetry/otlp/logs_service.proto +1 -1
  483. package/packages/dd-trace/src/opentelemetry/otlp/metrics.proto +1 -1
  484. package/packages/dd-trace/src/opentelemetry/otlp/metrics_service.proto +1 -1
  485. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +56 -82
  486. package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +1 -2
  487. package/packages/dd-trace/src/opentelemetry/otlp/protobuf_loader.js +14 -2
  488. package/packages/dd-trace/src/opentelemetry/otlp/trace.proto +358 -0
  489. package/packages/dd-trace/src/opentelemetry/otlp/trace_service.proto +78 -0
  490. package/packages/dd-trace/src/opentelemetry/span-helpers.js +325 -0
  491. package/packages/dd-trace/src/opentelemetry/span.js +59 -109
  492. package/packages/dd-trace/src/opentelemetry/span_context.js +1 -0
  493. package/packages/dd-trace/src/opentelemetry/span_processor.js +7 -5
  494. package/packages/dd-trace/src/opentelemetry/trace/index.js +75 -0
  495. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +75 -0
  496. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +375 -0
  497. package/packages/dd-trace/src/opentelemetry/tracer.js +20 -69
  498. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +33 -17
  499. package/packages/dd-trace/src/opentracing/propagation/log.js +28 -8
  500. package/packages/dd-trace/src/opentracing/propagation/text_map.js +278 -148
  501. package/packages/dd-trace/src/opentracing/propagation/text_map_dsm.js +11 -11
  502. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +98 -32
  503. package/packages/dd-trace/src/opentracing/span.js +127 -73
  504. package/packages/dd-trace/src/opentracing/span_context.js +68 -3
  505. package/packages/dd-trace/src/opentracing/tracer.js +46 -19
  506. package/packages/dd-trace/src/payload-tagging/config/index.js +2 -2
  507. package/packages/dd-trace/src/plugin_manager.js +36 -14
  508. package/packages/dd-trace/src/plugins/apollo.js +3 -1
  509. package/packages/dd-trace/src/plugins/ci_plugin.js +387 -85
  510. package/packages/dd-trace/src/plugins/database.js +61 -18
  511. package/packages/dd-trace/src/plugins/index.js +14 -0
  512. package/packages/dd-trace/src/plugins/log_injection.js +56 -0
  513. package/packages/dd-trace/src/plugins/log_plugin.js +4 -44
  514. package/packages/dd-trace/src/plugins/outbound.js +1 -1
  515. package/packages/dd-trace/src/plugins/plugin.js +19 -28
  516. package/packages/dd-trace/src/plugins/storage.js +2 -2
  517. package/packages/dd-trace/src/plugins/tracing.js +70 -13
  518. package/packages/dd-trace/src/plugins/util/ci.js +127 -40
  519. package/packages/dd-trace/src/plugins/util/git-cache.js +23 -23
  520. package/packages/dd-trace/src/plugins/util/git.js +3 -1
  521. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +276 -0
  522. package/packages/dd-trace/src/plugins/util/llm.js +6 -1
  523. package/packages/dd-trace/src/plugins/util/stacktrace.js +2 -2
  524. package/packages/dd-trace/src/plugins/util/test.js +894 -65
  525. package/packages/dd-trace/src/plugins/util/url.js +71 -5
  526. package/packages/dd-trace/src/plugins/util/user-provided-git.js +18 -16
  527. package/packages/dd-trace/src/plugins/util/web.js +116 -180
  528. package/packages/dd-trace/src/priority_sampler.js +12 -21
  529. package/packages/dd-trace/src/profiling/config.js +132 -212
  530. package/packages/dd-trace/src/profiling/constants.js +4 -7
  531. package/packages/dd-trace/src/profiling/exporter_cli.js +10 -10
  532. package/packages/dd-trace/src/profiling/exporters/agent.js +61 -28
  533. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +45 -14
  534. package/packages/dd-trace/src/profiling/exporters/file.js +16 -5
  535. package/packages/dd-trace/src/profiling/oom.js +71 -0
  536. package/packages/dd-trace/src/profiling/profiler.js +84 -105
  537. package/packages/dd-trace/src/profiling/profilers/event_plugins/crypto.js +32 -0
  538. package/packages/dd-trace/src/profiling/profilers/event_plugins/zlib.js +19 -0
  539. package/packages/dd-trace/src/profiling/profilers/events.js +57 -13
  540. package/packages/dd-trace/src/profiling/profilers/space.js +27 -16
  541. package/packages/dd-trace/src/profiling/profilers/wall.js +49 -35
  542. package/packages/dd-trace/src/profiling/ssi-heuristics.js +3 -3
  543. package/packages/dd-trace/src/propagation-hash/index.js +1 -1
  544. package/packages/dd-trace/src/proxy.js +50 -36
  545. package/packages/dd-trace/src/rate_limiter.js +1 -1
  546. package/packages/dd-trace/src/remote_config/index.js +6 -5
  547. package/packages/dd-trace/src/remote_config/scheduler.js +1 -1
  548. package/packages/dd-trace/src/ritm.js +6 -3
  549. package/packages/dd-trace/src/runtime_metrics/client.js +30 -0
  550. package/packages/dd-trace/src/runtime_metrics/index.js +14 -4
  551. package/packages/dd-trace/src/runtime_metrics/otlp_runtime_metrics.js +284 -0
  552. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +42 -41
  553. package/packages/dd-trace/src/sampling_rule.js +7 -7
  554. package/packages/dd-trace/src/scope.js +10 -15
  555. package/packages/dd-trace/src/serverless.js +6 -7
  556. package/packages/dd-trace/src/service-naming/extra-services.js +14 -0
  557. package/packages/dd-trace/src/service-naming/index.js +1 -1
  558. package/packages/dd-trace/src/service-naming/schemas/definition.js +4 -1
  559. package/packages/dd-trace/src/service-naming/schemas/util.js +48 -3
  560. package/packages/dd-trace/src/service-naming/schemas/v0/graphql.js +6 -0
  561. package/packages/dd-trace/src/service-naming/schemas/v0/messaging.js +61 -2
  562. package/packages/dd-trace/src/service-naming/schemas/v0/serverless.js +12 -0
  563. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +60 -0
  564. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +25 -1
  565. package/packages/dd-trace/src/service-naming/schemas/v0/websocket.js +5 -0
  566. package/packages/dd-trace/src/service-naming/schemas/v1/graphql.js +8 -0
  567. package/packages/dd-trace/src/service-naming/schemas/v1/messaging.js +32 -0
  568. package/packages/dd-trace/src/service-naming/schemas/v1/serverless.js +12 -0
  569. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +17 -0
  570. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +23 -3
  571. package/packages/dd-trace/src/service-naming/schemas/v1/websocket.js +6 -0
  572. package/packages/dd-trace/src/service-naming/source-resolver.js +50 -0
  573. package/packages/dd-trace/src/span_format.js +269 -81
  574. package/packages/dd-trace/src/span_processor.js +13 -13
  575. package/packages/dd-trace/src/span_stats.js +101 -79
  576. package/packages/dd-trace/src/spanleak.js +1 -2
  577. package/packages/dd-trace/src/standalone/index.js +3 -25
  578. package/packages/dd-trace/src/startup-log.js +3 -3
  579. package/packages/dd-trace/src/tagger.js +2 -4
  580. package/packages/dd-trace/src/telemetry/dependencies.js +2 -2
  581. package/packages/dd-trace/src/telemetry/endpoints.js +7 -5
  582. package/packages/dd-trace/src/telemetry/index.js +2 -2
  583. package/packages/dd-trace/src/telemetry/logs/index.js +1 -1
  584. package/packages/dd-trace/src/telemetry/send-data.js +20 -20
  585. package/packages/dd-trace/src/telemetry/session-propagation.js +1 -1
  586. package/packages/dd-trace/src/telemetry/telemetry.js +16 -14
  587. package/packages/dd-trace/src/tracer.js +23 -9
  588. package/packages/dd-trace/src/tracer_metadata.js +1 -1
  589. package/packages/dd-trace/src/util.js +31 -0
  590. package/register.js +58 -1
  591. package/vendor/dist/@apm-js-collab/code-transformer/index.js +94 -42
  592. package/vendor/dist/@datadog/sketches-js/LICENSE +10 -36
  593. package/vendor/dist/@datadog/sketches-js/index.js +1 -1
  594. package/vendor/dist/pprof-format/index.js +1 -1
  595. package/vendor/dist/protobufjs/index.js +1 -1
  596. package/vendor/dist/protobufjs/minimal/index.js +1 -1
  597. package/vendor/dist/shell-quote/index.js +1 -1
  598. package/packages/datadog-plugin-graphql/src/resolve.js +0 -178
  599. package/packages/dd-trace/src/agent/url.js +0 -28
  600. package/packages/dd-trace/src/appsec/api_security_sampler.js +0 -117
  601. package/packages/dd-trace/src/lambda/runtime/ritm.js +0 -133
  602. package/packages/dd-trace/src/log/utils.js +0 -16
  603. package/packages/dd-trace/src/msgpack/encoder.js +0 -308
  604. package/packages/dd-trace/src/plugins/structured_log_plugin.js +0 -9
  605. package/scripts/preinstall.js +0 -34
  606. package/vendor/dist/ignore/LICENSE +0 -21
  607. package/vendor/dist/ignore/index.js +0 -1
  608. package/vendor/dist/opentracing/LICENSE +0 -201
  609. package/vendor/dist/opentracing/binary_carrier.d.ts +0 -11
  610. package/vendor/dist/opentracing/constants.d.ts +0 -61
  611. package/vendor/dist/opentracing/examples/demo/demo.d.ts +0 -2
  612. package/vendor/dist/opentracing/ext/tags.d.ts +0 -90
  613. package/vendor/dist/opentracing/functions.d.ts +0 -20
  614. package/vendor/dist/opentracing/global_tracer.d.ts +0 -14
  615. package/vendor/dist/opentracing/index.d.ts +0 -12
  616. package/vendor/dist/opentracing/index.js +0 -1
  617. package/vendor/dist/opentracing/mock_tracer/index.d.ts +0 -5
  618. package/vendor/dist/opentracing/mock_tracer/mock_context.d.ts +0 -13
  619. package/vendor/dist/opentracing/mock_tracer/mock_report.d.ts +0 -16
  620. package/vendor/dist/opentracing/mock_tracer/mock_span.d.ts +0 -50
  621. package/vendor/dist/opentracing/mock_tracer/mock_tracer.d.ts +0 -26
  622. package/vendor/dist/opentracing/noop.d.ts +0 -8
  623. package/vendor/dist/opentracing/reference.d.ts +0 -33
  624. package/vendor/dist/opentracing/span.d.ts +0 -147
  625. package/vendor/dist/opentracing/span_context.d.ts +0 -26
  626. package/vendor/dist/opentracing/test/api_compatibility.d.ts +0 -16
  627. package/vendor/dist/opentracing/test/mocktracer_implemenation.d.ts +0 -3
  628. package/vendor/dist/opentracing/test/noop_implementation.d.ts +0 -4
  629. package/vendor/dist/opentracing/test/opentracing_api.d.ts +0 -3
  630. package/vendor/dist/opentracing/test/unittest.d.ts +0 -2
  631. package/vendor/dist/opentracing/tracer.d.ts +0 -127
  632. package/vendor/dist/path-to-regexp/LICENSE +0 -21
  633. package/vendor/dist/path-to-regexp/index.js +0 -1
@@ -9,7 +9,6 @@ const { getEnvironmentVariable } = require('../../config/helper')
9
9
  const satisfies = require('../../../../../vendor/dist/semifies')
10
10
 
11
11
  const istanbul = require('../../../../../vendor/dist/istanbul-lib-coverage')
12
- const ignore = require('../../../../../vendor/dist/ignore')
13
12
 
14
13
  const id = require('../../id')
15
14
  const {
@@ -23,17 +22,40 @@ const { SAMPLING_RULE_DECISION } = require('../../constants')
23
22
  const { AUTO_KEEP } = require('../../../../../ext/priority')
24
23
  const { version: ddTraceVersion } = require('../../../../../package.json')
25
24
  const {
25
+ CI_JOB_ID,
26
26
  GIT_BRANCH,
27
27
  GIT_COMMIT_SHA,
28
28
  GIT_REPOSITORY_URL,
29
29
  GIT_TAG,
30
+ GIT_COMMIT_AUTHOR_DATE,
30
31
  GIT_COMMIT_AUTHOR_EMAIL,
31
32
  GIT_COMMIT_AUTHOR_NAME,
33
+ GIT_COMMIT_COMMITTER_DATE,
34
+ GIT_COMMIT_COMMITTER_EMAIL,
35
+ GIT_COMMIT_COMMITTER_NAME,
32
36
  GIT_COMMIT_MESSAGE,
37
+ GIT_COMMIT_HEAD_AUTHOR_DATE,
38
+ GIT_COMMIT_HEAD_AUTHOR_EMAIL,
39
+ GIT_COMMIT_HEAD_AUTHOR_NAME,
40
+ GIT_COMMIT_HEAD_COMMITTER_DATE,
41
+ GIT_COMMIT_HEAD_COMMITTER_EMAIL,
42
+ GIT_COMMIT_HEAD_COMMITTER_NAME,
43
+ GIT_COMMIT_HEAD_MESSAGE,
33
44
  CI_WORKSPACE_PATH,
45
+ CI_PIPELINE_ID,
46
+ CI_PIPELINE_NAME,
47
+ CI_PIPELINE_NUMBER,
34
48
  CI_PIPELINE_URL,
35
49
  CI_JOB_NAME,
50
+ CI_JOB_URL,
51
+ CI_NODE_LABELS,
52
+ CI_NODE_NAME,
53
+ CI_PROVIDER_NAME,
54
+ CI_STAGE_NAME,
36
55
  GIT_COMMIT_HEAD_SHA,
56
+ GIT_PULL_REQUEST_BASE_BRANCH,
57
+ GIT_PULL_REQUEST_BASE_BRANCH_HEAD_SHA,
58
+ GIT_PULL_REQUEST_BASE_BRANCH_SHA,
37
59
  } = require('./tags')
38
60
  const { getRuntimeAndOSMetadata } = require('./env')
39
61
  const { getCIMetadata } = require('./ci')
@@ -73,6 +95,8 @@ const TEST_IS_RUM_ACTIVE = 'test.is_rum_active'
73
95
  const TEST_CODE_OWNERS = 'test.codeowners'
74
96
  const TEST_SOURCE_FILE = 'test.source.file'
75
97
  const TEST_SOURCE_START = 'test.source.start'
98
+ const TEST_FAILURE_SCREENSHOT_UPLOADED = 'test.failure_screenshot.uploaded'
99
+ const TEST_FAILURE_SCREENSHOT_UPLOAD_ERROR = 'test.failure_screenshot.upload_error'
76
100
  const LIBRARY_VERSION = 'library_version'
77
101
  const TEST_COMMAND = 'test.command'
78
102
  const TEST_MODULE = 'test.module'
@@ -90,6 +114,12 @@ const TEST_RETRY_REASON = 'test.retry_reason'
90
114
  const TEST_HAS_FAILED_ALL_RETRIES = 'test.has_failed_all_retries'
91
115
  const TEST_IS_MODIFIED = 'test.is_modified'
92
116
  const TEST_HAS_DYNAMIC_NAME = '_dd.has_dynamic_name'
117
+ const EARLY_FLAKE_DETECTION_RETRY_THRESHOLDS = [
118
+ { limitMs: 5 * 1000, key: '5s' },
119
+ { limitMs: 10 * 1000, key: '10s' },
120
+ { limitMs: 30 * 1000, key: '30s' },
121
+ { limitMs: 5 * 60 * 1000, key: '5m' },
122
+ ]
93
123
  const CI_APP_ORIGIN = 'ciapp-test'
94
124
 
95
125
  // Matches patterns that are almost certainly runtime-generated values in test names:
@@ -137,6 +167,7 @@ const JEST_WORKER_TRACE_PAYLOAD_CODE = 60
137
167
  const JEST_WORKER_COVERAGE_PAYLOAD_CODE = 61
138
168
  const JEST_WORKER_LOGS_PAYLOAD_CODE = 62
139
169
  const JEST_WORKER_TELEMETRY_PAYLOAD_CODE = 63
170
+ const JEST_WORKER_QUARANTINE_PAYLOAD_CODE = 64
140
171
 
141
172
  // cucumber worker variables
142
173
  const CUCUMBER_WORKER_TRACE_PAYLOAD_CODE = 70
@@ -163,8 +194,12 @@ const DD_CAPABILITIES_TEST_MANAGEMENT_DISABLE = '_dd.library_capabilities.test_m
163
194
  const DD_CAPABILITIES_TEST_MANAGEMENT_ATTEMPT_TO_FIX = '_dd.library_capabilities.test_management.attempt_to_fix'
164
195
  const DD_CAPABILITIES_FAILED_TEST_REPLAY = '_dd.library_capabilities.failed_test_replay'
165
196
 
166
- // Library configuration request error tag
167
- const DD_CI_LIBRARY_CONFIGURATION_ERROR = '_dd.ci.library_configuration_error'
197
+ // Library configuration request error tags
198
+ const DD_CI_LIBRARY_CONFIGURATION_ERROR_SETTINGS = '_dd.ci.library_configuration_error.settings'
199
+ const DD_CI_LIBRARY_CONFIGURATION_ERROR_SKIPPABLE_TESTS = '_dd.ci.library_configuration_error.skippable_tests'
200
+ const DD_CI_LIBRARY_CONFIGURATION_ERROR_KNOWN_TESTS = '_dd.ci.library_configuration_error.known_tests'
201
+ const DD_CI_LIBRARY_CONFIGURATION_ERROR_TEST_MANAGEMENT_TESTS =
202
+ '_dd.ci.library_configuration_error.test_management_tests'
168
203
 
169
204
  const UNSUPPORTED_TIA_FRAMEWORKS = new Set(['playwright', 'vitest'])
170
205
  const MINIMUM_FRAMEWORK_VERSION_FOR_EFD = {
@@ -194,6 +229,43 @@ const TEST_LEVEL_EVENT_TYPES = [
194
229
  'test_module_end',
195
230
  'test_session_end',
196
231
  ]
232
+ const TEST_LEVELS_METADATA = 'test_levels'
233
+ const TEST_LEVELS_METADATA_TAGS = [
234
+ CI_JOB_ID,
235
+ CI_JOB_NAME,
236
+ CI_JOB_URL,
237
+ CI_NODE_LABELS,
238
+ CI_NODE_NAME,
239
+ CI_PIPELINE_ID,
240
+ CI_PIPELINE_NAME,
241
+ CI_PIPELINE_NUMBER,
242
+ CI_PIPELINE_URL,
243
+ CI_PROVIDER_NAME,
244
+ CI_STAGE_NAME,
245
+ CI_WORKSPACE_PATH,
246
+ GIT_BRANCH,
247
+ GIT_COMMIT_AUTHOR_DATE,
248
+ GIT_COMMIT_AUTHOR_EMAIL,
249
+ GIT_COMMIT_AUTHOR_NAME,
250
+ GIT_COMMIT_COMMITTER_DATE,
251
+ GIT_COMMIT_COMMITTER_EMAIL,
252
+ GIT_COMMIT_COMMITTER_NAME,
253
+ GIT_COMMIT_HEAD_AUTHOR_DATE,
254
+ GIT_COMMIT_HEAD_AUTHOR_EMAIL,
255
+ GIT_COMMIT_HEAD_AUTHOR_NAME,
256
+ GIT_COMMIT_HEAD_COMMITTER_DATE,
257
+ GIT_COMMIT_HEAD_COMMITTER_EMAIL,
258
+ GIT_COMMIT_HEAD_COMMITTER_NAME,
259
+ GIT_COMMIT_HEAD_MESSAGE,
260
+ GIT_COMMIT_HEAD_SHA,
261
+ GIT_COMMIT_MESSAGE,
262
+ GIT_COMMIT_SHA,
263
+ GIT_PULL_REQUEST_BASE_BRANCH,
264
+ GIT_PULL_REQUEST_BASE_BRANCH_HEAD_SHA,
265
+ GIT_PULL_REQUEST_BASE_BRANCH_SHA,
266
+ GIT_REPOSITORY_URL,
267
+ GIT_TAG,
268
+ ]
197
269
  const TEST_RETRY_REASON_TYPES = {
198
270
  efd: 'early_flake_detection',
199
271
  atr: 'auto_test_retry',
@@ -217,26 +289,133 @@ const TEST_MANAGEMENT_IS_QUARANTINED = 'test.test_management.is_quarantined'
217
289
  const TEST_MANAGEMENT_ENABLED = 'test.test_management.enabled'
218
290
  const TEST_MANAGEMENT_ATTEMPT_TO_FIX_PASSED = 'test.test_management.attempt_to_fix_passed'
219
291
 
292
+ const MAX_TEST_OPTIMIZATION_SUMMARY_ITEMS = 10
293
+
220
294
  // Impacted tests
221
295
  const POSSIBLE_BASE_BRANCHES = ['main', 'master', 'preprod', 'prod', 'dev', 'development', 'trunk']
222
296
  const BASE_LIKE_BRANCH_FILTER = /^(main|master|preprod|prod|dev|development|trunk|release\/.*|hotfix\/.*)$/
223
297
 
224
298
  /**
225
299
  * Returns request error tags from a test session span for propagation to child events.
226
- * @param {{ context: () => { _tags?: Record<string, string> } } | undefined} sessionSpan
300
+ * @param {{ context: () => { getTag?: (key: string) => string } } | undefined} sessionSpan
227
301
  * @returns {Record<string, string>}
228
302
  */
229
303
  function getSessionRequestErrorTags (sessionSpan) {
230
- const tags = sessionSpan?.context()._tags
304
+ const tags = sessionSpan?.context()?.getTags?.()
305
+ const sessionRequestErrorTags = {}
306
+ if (!tags || typeof tags !== 'object') return {}
307
+ if (tags[DD_CI_LIBRARY_CONFIGURATION_ERROR_SETTINGS] === 'true') {
308
+ sessionRequestErrorTags[DD_CI_LIBRARY_CONFIGURATION_ERROR_SETTINGS] = 'true'
309
+ }
310
+ if (tags[DD_CI_LIBRARY_CONFIGURATION_ERROR_SKIPPABLE_TESTS] === 'true') {
311
+ sessionRequestErrorTags[DD_CI_LIBRARY_CONFIGURATION_ERROR_SKIPPABLE_TESTS] = 'true'
312
+ }
313
+ if (tags[DD_CI_LIBRARY_CONFIGURATION_ERROR_KNOWN_TESTS] === 'true') {
314
+ sessionRequestErrorTags[DD_CI_LIBRARY_CONFIGURATION_ERROR_KNOWN_TESTS] = 'true'
315
+ }
316
+ if (tags[DD_CI_LIBRARY_CONFIGURATION_ERROR_TEST_MANAGEMENT_TESTS] === 'true') {
317
+ sessionRequestErrorTags[DD_CI_LIBRARY_CONFIGURATION_ERROR_TEST_MANAGEMENT_TESTS] = 'true'
318
+ }
319
+ return sessionRequestErrorTags
320
+ }
321
+
322
+ /**
323
+ * Returns ITR skipping-enabled tags from a test session span for propagation to child events.
324
+ * @param {{ context: () => { getTags?: () => Record<string, string> } } | undefined} sessionSpan
325
+ * @returns {Record<string, string>}
326
+ */
327
+ function getSessionItrSkippingEnabledTags (sessionSpan) {
328
+ const tags = sessionSpan?.context()?.getTags?.()
231
329
  if (!tags || typeof tags !== 'object') return {}
232
- if (tags[DD_CI_LIBRARY_CONFIGURATION_ERROR] === 'true') {
330
+ if (tags[TEST_ITR_SKIPPING_ENABLED] !== undefined) {
233
331
  return {
234
- [DD_CI_LIBRARY_CONFIGURATION_ERROR]: 'true',
332
+ [TEST_ITR_SKIPPING_ENABLED]: tags[TEST_ITR_SKIPPING_ENABLED],
235
333
  }
236
334
  }
237
335
  return {}
238
336
  }
239
337
 
338
+ /**
339
+ * Starts supported test optimization requests together when each feature is enabled.
340
+ *
341
+ * @param {{
342
+ * isKnownTestsEnabled: boolean,
343
+ * isTestManagementTestsEnabled: boolean,
344
+ * isSuitesSkippingEnabled?: boolean,
345
+ * getKnownTests: () => Promise<object>,
346
+ * getTestManagementTests: () => Promise<object>,
347
+ * getSkippableSuites?: () => Promise<object>
348
+ * }} options - Test optimization request factories.
349
+ * @returns {Promise<{
350
+ * knownTestsResponse?: object,
351
+ * testManagementTestsResponse?: object,
352
+ * skippableSuitesResponse?: object
353
+ * }>}
354
+ */
355
+ function getTestOptimizationRequestResults ({
356
+ isKnownTestsEnabled,
357
+ isTestManagementTestsEnabled,
358
+ isSuitesSkippingEnabled,
359
+ getKnownTests,
360
+ getTestManagementTests,
361
+ getSkippableSuites,
362
+ }) {
363
+ const requestPromises = []
364
+ const responseNames = []
365
+
366
+ if (isKnownTestsEnabled) {
367
+ addTestOptimizationRequest(requestPromises, responseNames, 'knownTestsResponse', getKnownTests)
368
+ }
369
+
370
+ if (isTestManagementTestsEnabled) {
371
+ addTestOptimizationRequest(
372
+ requestPromises,
373
+ responseNames,
374
+ 'testManagementTestsResponse',
375
+ getTestManagementTests
376
+ )
377
+ }
378
+
379
+ if (isSuitesSkippingEnabled && getSkippableSuites) {
380
+ addTestOptimizationRequest(requestPromises, responseNames, 'skippableSuitesResponse', getSkippableSuites)
381
+ }
382
+
383
+ if (!requestPromises.length) {
384
+ return Promise.resolve({})
385
+ }
386
+
387
+ return Promise.allSettled(requestPromises).then(requestResults => {
388
+ const responses = {}
389
+
390
+ for (let index = 0; index < requestResults.length; index++) {
391
+ const requestResult = requestResults[index]
392
+ responses[responseNames[index]] = requestResult.status === 'fulfilled'
393
+ ? requestResult.value
394
+ : { err: requestResult.reason }
395
+ }
396
+
397
+ return responses
398
+ })
399
+ }
400
+
401
+ /**
402
+ * Starts a test optimization request.
403
+ *
404
+ * @param {Promise<object>[]} requestPromises - Test optimization request promises.
405
+ * @param {string[]} responseNames - Response keys matching request promises.
406
+ * @param {string} responseName - Response key for this request.
407
+ * @param {() => Promise<object>} getRequest - Test optimization request factory.
408
+ */
409
+ function addTestOptimizationRequest (requestPromises, responseNames, responseName, getRequest) {
410
+ responseNames.push(responseName)
411
+
412
+ try {
413
+ requestPromises.push(Promise.resolve(getRequest()))
414
+ } catch (err) {
415
+ requestPromises.push(Promise.reject(err))
416
+ }
417
+ }
418
+
240
419
  module.exports = {
241
420
  TEST_CODE_OWNERS,
242
421
  TEST_SESSION_NAME,
@@ -256,12 +435,15 @@ module.exports = {
256
435
  TEST_SKIP_REASON,
257
436
  TEST_IS_RUM_ACTIVE,
258
437
  TEST_SOURCE_FILE,
438
+ TEST_FAILURE_SCREENSHOT_UPLOADED,
439
+ TEST_FAILURE_SCREENSHOT_UPLOAD_ERROR,
259
440
  CI_APP_ORIGIN,
260
441
  LIBRARY_VERSION,
261
442
  JEST_WORKER_TRACE_PAYLOAD_CODE,
262
443
  JEST_WORKER_COVERAGE_PAYLOAD_CODE,
263
444
  JEST_WORKER_LOGS_PAYLOAD_CODE,
264
445
  JEST_WORKER_TELEMETRY_PAYLOAD_CODE,
446
+ JEST_WORKER_QUARANTINE_PAYLOAD_CODE,
265
447
  CUCUMBER_WORKER_TRACE_PAYLOAD_CODE,
266
448
  MOCHA_WORKER_TRACE_PAYLOAD_CODE,
267
449
  PLAYWRIGHT_WORKER_TRACE_PAYLOAD_CODE,
@@ -286,6 +468,7 @@ module.exports = {
286
468
  getCodeOwnersFileEntries,
287
469
  getCodeOwnersForFilename,
288
470
  getTestCommonTags,
471
+ getTestLevelsMetadataTags,
289
472
  getTestSessionCommonTags,
290
473
  getTestModuleCommonTags,
291
474
  getTestSuiteCommonTags,
@@ -306,6 +489,12 @@ module.exports = {
306
489
  ITR_CORRELATION_ID,
307
490
  addIntelligentTestRunnerSpanTags,
308
491
  getCoveredFilenamesFromCoverage,
492
+ getCoveredFilesFromCoverage,
493
+ getExecutableFilesFromCoverage,
494
+ getRelativeCoverageFiles,
495
+ getLineCoverageBitmap,
496
+ applySkippedCoverageToCoverage,
497
+ getTestCoverageLinesPercentage,
309
498
  resetCoverage,
310
499
  mergeCoverage,
311
500
  fromCoverageMapToCoverage,
@@ -314,7 +503,9 @@ module.exports = {
314
503
  removeInvalidMetadata,
315
504
  parseAnnotations,
316
505
  getIsFaultyEarlyFlakeDetection,
506
+ EARLY_FLAKE_DETECTION_RETRY_THRESHOLDS,
317
507
  getEfdRetryCount,
508
+ getMaxEfdRetryCount,
318
509
  TEST_BROWSER_DRIVER,
319
510
  TEST_BROWSER_DRIVER_VERSION,
320
511
  TEST_BROWSER_NAME,
@@ -329,6 +520,7 @@ module.exports = {
329
520
  DD_CAPABILITIES_TEST_MANAGEMENT_ATTEMPT_TO_FIX,
330
521
  DD_CAPABILITIES_FAILED_TEST_REPLAY,
331
522
  TEST_LEVEL_EVENT_TYPES,
523
+ TEST_LEVELS_METADATA,
332
524
  TEST_RETRY_REASON_TYPES,
333
525
  getNumFromKnownTests,
334
526
  getFileAndLineNumberFromError,
@@ -346,7 +538,12 @@ module.exports = {
346
538
  TEST_MANAGEMENT_ATTEMPT_TO_FIX_PASSED,
347
539
  getLibraryCapabilitiesTags,
348
540
  getSessionRequestErrorTags,
349
- DD_CI_LIBRARY_CONFIGURATION_ERROR,
541
+ DD_CI_LIBRARY_CONFIGURATION_ERROR_SETTINGS,
542
+ DD_CI_LIBRARY_CONFIGURATION_ERROR_SKIPPABLE_TESTS,
543
+ DD_CI_LIBRARY_CONFIGURATION_ERROR_KNOWN_TESTS,
544
+ DD_CI_LIBRARY_CONFIGURATION_ERROR_TEST_MANAGEMENT_TESTS,
545
+ getSessionItrSkippingEnabledTags,
546
+ getTestOptimizationRequestResults,
350
547
  checkShaDiscrepancies,
351
548
  getPullRequestDiff,
352
549
  getPullRequestBaseBranch,
@@ -357,7 +554,14 @@ module.exports = {
357
554
  GIT_REPOSITORY_URL,
358
555
  DYNAMIC_NAME_RE,
359
556
  collectDynamicNamesFromTraces,
557
+ collectTestOptimizationSummariesFromTraces,
360
558
  logDynamicNamesWarning,
559
+ recordAttemptToFixExecution,
560
+ collectAttemptToFixExecutionsFromTraces,
561
+ formatAttemptToFixSummary,
562
+ logAttemptToFixTestExecution,
563
+ formatDynamicNamesSummary,
564
+ logTestOptimizationSummary,
361
565
  }
362
566
 
363
567
  // Returns pkg manager and its version, separated by '-', e.g. npm-8.15.0 or yarn-1.22.19
@@ -569,6 +773,24 @@ function getTestParametersString (parametersByTestName, testName) {
569
773
  }
570
774
  }
571
775
 
776
+ /**
777
+ * Extracts CI and Git tags that apply to every test level.
778
+ *
779
+ * @param {TestEnvironmentMetadata} testEnvironmentMetadata
780
+ * @returns {Record<string, string|number>}
781
+ */
782
+ function getTestLevelsMetadataTags (testEnvironmentMetadata) {
783
+ const testLevelsMetadataTags = {}
784
+ for (let i = 0; i < TEST_LEVELS_METADATA_TAGS.length; i++) {
785
+ const key = TEST_LEVELS_METADATA_TAGS[i]
786
+ const value = testEnvironmentMetadata[key]
787
+ if (value !== undefined) {
788
+ testLevelsMetadataTags[key] = value
789
+ }
790
+ }
791
+ return testLevelsMetadataTags
792
+ }
793
+
572
794
  function getTestTypeFromFramework (testFramework) {
573
795
  if (testFramework === 'playwright' || testFramework === 'cypress') {
574
796
  return 'browser'
@@ -669,24 +891,146 @@ function getCodeOwnersFileEntries (rootDir) {
669
891
  const trimmed = content.trim()
670
892
  if (trimmed === '') continue
671
893
  const [pattern, ...owners] = trimmed.split(/\s+/)
672
- entries.push({ pattern, owners })
894
+ entries.push(setCodeOwnersPatternRegex({ pattern, owners }))
673
895
  }
674
896
  // Reverse because rules defined last take precedence
675
897
  return entries.reverse()
676
898
  }
677
899
 
678
- const codeOwnersPerFileName = new Map()
900
+ const codeOwnersPerEntries = new WeakMap()
901
+
902
+ /**
903
+ * @param {string} character
904
+ * @returns {string}
905
+ */
906
+ function escapeRegexCharacter (character) {
907
+ return character.replaceAll(/[|\\{}()[\]^$+*?.]/g, String.raw`\$&`)
908
+ }
909
+
910
+ /**
911
+ * @param {string} pattern
912
+ * @returns {boolean}
913
+ */
914
+ function hasUnescapedWildcard (pattern) {
915
+ for (let i = 0; i < pattern.length; i++) {
916
+ const character = pattern[i]
917
+ if (character === '\\') {
918
+ i++
919
+ } else if (character === '*' || character === '?') {
920
+ return true
921
+ }
922
+ }
923
+ return false
924
+ }
925
+
926
+ /**
927
+ * @param {string} pattern
928
+ * @returns {string}
929
+ */
930
+ function codeOwnersPatternToRegexSource (pattern) {
931
+ let source = ''
932
+ for (let i = 0; i < pattern.length; i++) {
933
+ const character = pattern[i]
934
+
935
+ if (character === '\\') {
936
+ const escapedCharacter = pattern[i + 1]
937
+ source += escapedCharacter === undefined
938
+ ? escapeRegexCharacter(character)
939
+ : escapeRegexCharacter(escapedCharacter)
940
+ i++
941
+ } else if (character === '*') {
942
+ if (pattern[i + 1] === '*') {
943
+ if (pattern[i + 2] === '/') {
944
+ source += '(?:.*/)?'
945
+ i += 2
946
+ } else {
947
+ source += '.*'
948
+ i++
949
+ }
950
+ } else {
951
+ source += '[^/]*'
952
+ }
953
+ } else if (character === '?') {
954
+ source += '[^/]'
955
+ } else {
956
+ source += escapeRegexCharacter(character)
957
+ }
958
+ }
959
+ return source
960
+ }
961
+
962
+ /**
963
+ * @param {string} pattern
964
+ * @returns {RegExp|null}
965
+ */
966
+ function getCodeOwnersPatternRegex (pattern) {
967
+ if (!pattern || pattern[0] === '!') {
968
+ return null
969
+ }
970
+
971
+ const directoryOnly = pattern.endsWith('/')
972
+ const normalizedPattern = pattern.replace(/^\/+/, '').replace(/\/+$/, '')
973
+ const anchored = pattern.startsWith('/') || normalizedPattern.includes('/')
974
+
975
+ if (!normalizedPattern) {
976
+ return null
977
+ }
978
+
979
+ const lastSlashIndex = normalizedPattern.lastIndexOf('/')
980
+ const lastSegment = lastSlashIndex === -1 ? normalizedPattern : normalizedPattern.slice(lastSlashIndex + 1)
981
+ const descendantSuffix = directoryOnly || !hasUnescapedWildcard(lastSegment) ? '(?:/.*)?' : ''
982
+ const patternSource = codeOwnersPatternToRegexSource(normalizedPattern)
983
+ const regexSource = anchored
984
+ ? `^${patternSource}${descendantSuffix}$`
985
+ : `(?:^|/)${patternSource}${descendantSuffix}$`
986
+
987
+ return new RegExp(regexSource)
988
+ }
989
+
990
+ function setCodeOwnersPatternRegex (entry) {
991
+ Object.defineProperty(entry, 'regex', {
992
+ configurable: true,
993
+ value: getCodeOwnersPatternRegex(entry.pattern),
994
+ writable: true,
995
+ })
996
+ return entry
997
+ }
998
+
999
+ /**
1000
+ * Match a repository-relative filename against a CODEOWNERS pattern.
1001
+ * See GitHub's CODEOWNERS pattern rules:
1002
+ * https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
1003
+ *
1004
+ * @param {RegExp|null} regex
1005
+ * @param {string} filename
1006
+ * @returns {boolean}
1007
+ */
1008
+ function isCodeOwnersPatternMatch (regex, filename) {
1009
+ if (!regex || !filename) {
1010
+ return false
1011
+ }
1012
+
1013
+ const normalizedFilename = filename.replaceAll('\\', '/').replace(/^\/+/, '')
1014
+ return regex.test(normalizedFilename)
1015
+ }
679
1016
 
680
1017
  function getCodeOwnersForFilename (filename, entries) {
681
1018
  if (!entries) {
682
1019
  return null
683
1020
  }
684
- if (codeOwnersPerFileName.has(filename)) {
1021
+ let codeOwnersPerFileName = codeOwnersPerEntries.get(entries)
1022
+
1023
+ if (!codeOwnersPerFileName) {
1024
+ codeOwnersPerFileName = new Map()
1025
+ codeOwnersPerEntries.set(entries, codeOwnersPerFileName)
1026
+ } else if (codeOwnersPerFileName.has(filename)) {
685
1027
  return codeOwnersPerFileName.get(filename)
686
1028
  }
1029
+
687
1030
  for (const entry of entries) {
688
1031
  try {
689
- const isResponsible = ignore().add(entry.pattern).ignores(filename)
1032
+ const regex = entry.regex === undefined ? setCodeOwnersPatternRegex(entry).regex : entry.regex
1033
+ const isResponsible = isCodeOwnersPatternMatch(regex, filename)
690
1034
  if (isResponsible) {
691
1035
  const codeOwners = JSON.stringify(entry.owners)
692
1036
  codeOwnersPerFileName.set(filename, codeOwners)
@@ -705,7 +1049,6 @@ function getTestLevelCommonTags (command, testFrameworkVersion, testFramework) {
705
1049
  return {
706
1050
  [TEST_FRAMEWORK_VERSION]: testFrameworkVersion,
707
1051
  [LIBRARY_VERSION]: ddTraceVersion,
708
- [TEST_COMMAND]: command,
709
1052
  [TEST_TYPE]: getTestTypeFromFramework(testFramework),
710
1053
  }
711
1054
  }
@@ -783,17 +1126,233 @@ function addIntelligentTestRunnerSpanTags (
783
1126
  }
784
1127
 
785
1128
  function getCoveredFilenamesFromCoverage (coverage) {
786
- const coverageMap = istanbul.createCoverageMap(coverage)
1129
+ return getCoveredFilesFromCoverage(coverage).map(({ filename }) => filename)
1130
+ }
787
1131
 
788
- return coverageMap
789
- .files()
790
- .filter(filename => {
791
- const fileCoverage = coverageMap.fileCoverageFor(filename)
792
- const lineCoverage = fileCoverage.getLineCoverage()
793
- const isAnyLineExecuted = Object.entries(lineCoverage).some(([, numExecutions]) => !!numExecutions)
1132
+ function getCoverageMap (coverage) {
1133
+ if (coverage?.files && coverage?.fileCoverageFor) {
1134
+ return coverage
1135
+ }
1136
+ return istanbul.createCoverageMap(coverage)
1137
+ }
794
1138
 
795
- return isAnyLineExecuted
796
- })
1139
+ function getCoveredFilesFromCoverage (coverage) {
1140
+ const coverageMap = getCoverageMap(coverage)
1141
+ const coverageFiles = []
1142
+
1143
+ for (const filename of coverageMap.files()) {
1144
+ const fileCoverage = coverageMap.fileCoverageFor(filename)
1145
+ const bitmap = getLineCoverageBitmap(fileCoverage.getLineCoverage(), true)
1146
+ if (bitmap) {
1147
+ coverageFiles.push({ filename, bitmap })
1148
+ }
1149
+ }
1150
+
1151
+ return coverageFiles
1152
+ }
1153
+
1154
+ function getExecutableFilesFromCoverage (coverage) {
1155
+ const coverageMap = getCoverageMap(coverage)
1156
+ const coverageFiles = []
1157
+
1158
+ for (const filename of coverageMap.files()) {
1159
+ const fileCoverage = coverageMap.fileCoverageFor(filename)
1160
+ const bitmap = getLineCoverageBitmap(fileCoverage.getLineCoverage())
1161
+ if (bitmap) {
1162
+ coverageFiles.push({ filename, bitmap })
1163
+ }
1164
+ }
1165
+
1166
+ return coverageFiles
1167
+ }
1168
+
1169
+ function getRelativeCoverageFiles (coverageFiles, rootDir) {
1170
+ return coverageFiles.map(({ filename, bitmap }) => ({
1171
+ filename: getTestSuitePath(filename, rootDir),
1172
+ bitmap,
1173
+ }))
1174
+ }
1175
+
1176
+ function getLineCoverageBitmap (lineCoverage, onlyCoveredLines = false) {
1177
+ let maxLine = 0
1178
+ const lines = []
1179
+
1180
+ for (const [line, hits] of Object.entries(lineCoverage)) {
1181
+ if (onlyCoveredLines && !hits) continue
1182
+
1183
+ const lineNumber = Number(line)
1184
+ if (!Number.isSafeInteger(lineNumber) || lineNumber <= 0) continue
1185
+
1186
+ lines.push(lineNumber)
1187
+ if (lineNumber > maxLine) {
1188
+ maxLine = lineNumber
1189
+ }
1190
+ }
1191
+
1192
+ if (maxLine === 0) return
1193
+
1194
+ const bitmap = Buffer.alloc(Math.ceil((maxLine + 1) / 8))
1195
+ for (const lineNumber of lines) {
1196
+ bitmap[lineNumber >> 3] |= 1 << (lineNumber % 8)
1197
+ }
1198
+
1199
+ return bitmap
1200
+ }
1201
+
1202
+ function mergeCoverageBitmaps (targetBitmap, bitmap) {
1203
+ if (!targetBitmap) {
1204
+ return Buffer.from(bitmap)
1205
+ }
1206
+
1207
+ if (targetBitmap.length < bitmap.length) {
1208
+ const biggerBitmap = Buffer.alloc(bitmap.length)
1209
+ targetBitmap.copy(biggerBitmap)
1210
+ targetBitmap = biggerBitmap
1211
+ }
1212
+
1213
+ for (let i = 0; i < bitmap.length; i++) {
1214
+ targetBitmap[i] |= bitmap[i]
1215
+ }
1216
+
1217
+ return targetBitmap
1218
+ }
1219
+
1220
+ function countBitmapBits (bitmap) {
1221
+ let count = 0
1222
+
1223
+ for (const byte of bitmap) {
1224
+ let value = byte
1225
+ while (value) {
1226
+ value &= value - 1
1227
+ count++
1228
+ }
1229
+ }
1230
+
1231
+ return count
1232
+ }
1233
+
1234
+ function countCoveredExecutableBits (coveredBitmap, executableBitmap) {
1235
+ if (!coveredBitmap) return 0
1236
+
1237
+ let count = 0
1238
+ const length = Math.min(coveredBitmap.length, executableBitmap.length)
1239
+
1240
+ for (let i = 0; i < length; i++) {
1241
+ let value = coveredBitmap[i] & executableBitmap[i]
1242
+ while (value) {
1243
+ value &= value - 1
1244
+ count++
1245
+ }
1246
+ }
1247
+
1248
+ return count
1249
+ }
1250
+
1251
+ function getCoverageFileBitmap (bitmap) {
1252
+ if (!bitmap) return
1253
+ if (Buffer.isBuffer(bitmap)) return bitmap
1254
+ if (ArrayBuffer.isView(bitmap)) {
1255
+ return Buffer.from(bitmap.buffer, bitmap.byteOffset, bitmap.byteLength)
1256
+ }
1257
+ if (typeof bitmap === 'string') {
1258
+ return Buffer.from(bitmap, 'base64')
1259
+ }
1260
+ }
1261
+
1262
+ function addCoverageFilesToMap (files, targetMap, rootDir) {
1263
+ for (const file of files) {
1264
+ const bitmap = getCoverageFileBitmap(file.bitmap)
1265
+ if (!bitmap) continue
1266
+
1267
+ const filename = rootDir ? getTestSuitePath(file.filename, rootDir) : file.filename
1268
+ targetMap.set(filename, mergeCoverageBitmaps(targetMap.get(filename), bitmap))
1269
+ }
1270
+ }
1271
+
1272
+ function addSkippedCoverageToMap (skippedCoverage, targetMap) {
1273
+ if (!skippedCoverage) return
1274
+
1275
+ for (const [filename, bitmap] of Object.entries(skippedCoverage)) {
1276
+ const coverageBitmap = getCoverageFileBitmap(bitmap)
1277
+ if (!coverageBitmap) continue
1278
+ targetMap.set(filename, mergeCoverageBitmaps(targetMap.get(filename), coverageBitmap))
1279
+ }
1280
+ }
1281
+
1282
+ function hasSkippedCoverage (skippedCoverage) {
1283
+ return skippedCoverage && typeof skippedCoverage === 'object' && Object.keys(skippedCoverage).length > 0
1284
+ }
1285
+
1286
+ function getTestCoverageLinesPercentage (coverage, skippedCoverage, rootDir) {
1287
+ const executableLinesByFile = new Map()
1288
+ const coveredLinesByFile = new Map()
1289
+
1290
+ addCoverageFilesToMap(getExecutableFilesFromCoverage(coverage), executableLinesByFile, rootDir)
1291
+ addCoverageFilesToMap(getCoveredFilesFromCoverage(coverage), coveredLinesByFile, rootDir)
1292
+ addSkippedCoverageToMap(skippedCoverage, coveredLinesByFile)
1293
+
1294
+ let totalExecutableLines = 0
1295
+ let totalCoveredLines = 0
1296
+
1297
+ for (const [filename, executableLines] of executableLinesByFile) {
1298
+ totalExecutableLines += countBitmapBits(executableLines)
1299
+ totalCoveredLines += countCoveredExecutableBits(coveredLinesByFile.get(filename), executableLines)
1300
+ }
1301
+
1302
+ return totalExecutableLines === 0 ? 0 : Math.floor((totalCoveredLines / totalExecutableLines) * 10_000) / 100
1303
+ }
1304
+
1305
+ function isLineCoveredByBitmap (bitmap, line) {
1306
+ if (!Number.isSafeInteger(line) || line <= 0) return false
1307
+
1308
+ const byteIndex = line >> 3
1309
+ return byteIndex < bitmap.length && !!(bitmap[byteIndex] & (1 << (line % 8)))
1310
+ }
1311
+
1312
+ function getSkippedCoverageByFilename (skippedCoverage) {
1313
+ const skippedCoverageByFilename = new Map()
1314
+ addSkippedCoverageToMap(skippedCoverage, skippedCoverageByFilename)
1315
+ return skippedCoverageByFilename
1316
+ }
1317
+
1318
+ function applySkippedCoverageToFileCoverage (fileCoverage, skippedBitmap) {
1319
+ let updated = false
1320
+ for (const [statementId, statementLocation] of Object.entries(fileCoverage.data.statementMap)) {
1321
+ const startLine = statementLocation?.start?.line
1322
+ if (!isLineCoveredByBitmap(skippedBitmap, startLine)) continue
1323
+ if (fileCoverage.data.s[statementId] > 0) continue
1324
+
1325
+ fileCoverage.data.s[statementId] = 1
1326
+ updated = true
1327
+ }
1328
+ return updated
1329
+ }
1330
+
1331
+ /**
1332
+ * Applies backend skipped-suite coverage to an Istanbul coverage map.
1333
+ * @param {object} coverage
1334
+ * @param {object} skippedCoverage
1335
+ * @param {string} [rootDir]
1336
+ * @returns {boolean}
1337
+ */
1338
+ function applySkippedCoverageToCoverage (coverage, skippedCoverage, rootDir) {
1339
+ if (!hasSkippedCoverage(skippedCoverage)) return false
1340
+
1341
+ const coverageMap = getCoverageMap(coverage)
1342
+ const skippedCoverageByFilename = getSkippedCoverageByFilename(skippedCoverage)
1343
+ let matched = false
1344
+
1345
+ for (const filename of coverageMap.files()) {
1346
+ const relativeFilename = rootDir ? getTestSuitePath(filename, rootDir) : filename
1347
+ const skippedBitmap = skippedCoverageByFilename.get(relativeFilename)
1348
+ if (!skippedBitmap) continue
1349
+
1350
+ const fileCoverage = coverageMap.fileCoverageFor(filename)
1351
+ applySkippedCoverageToFileCoverage(fileCoverage, skippedBitmap)
1352
+ matched = true
1353
+ }
1354
+
1355
+ return matched
797
1356
  }
798
1357
 
799
1358
  function resetCoverage (coverage) {
@@ -895,17 +1454,11 @@ function parseAnnotations (annotations) {
895
1454
  * Returns 0 when the test is too slow to retry (≥ 5 min).
896
1455
  *
897
1456
  * @param {number} durationMs
898
- * @param {Record<string, number>} slowTestRetries e.g. { '5s': 10, '10s': 5, '30s': 3, '5m': 2 }
1457
+ * @param {Record<string, number>} slowTestRetries e.g. { '5s': 10, '10s': 5, '30s': 3, '5m': 2 }
899
1458
  * @returns {number}
900
1459
  */
901
1460
  function getEfdRetryCount (durationMs, slowTestRetries) {
902
- const thresholds = [
903
- { limitMs: 5 * 1000, key: '5s' },
904
- { limitMs: 10 * 1000, key: '10s' },
905
- { limitMs: 30 * 1000, key: '30s' },
906
- { limitMs: 5 * 60 * 1000, key: '5m' },
907
- ]
908
- for (const { limitMs, key } of thresholds) {
1461
+ for (const { limitMs, key } of EARLY_FLAKE_DETECTION_RETRY_THRESHOLDS) {
909
1462
  if (durationMs < limitMs) {
910
1463
  return slowTestRetries[key] ?? 0
911
1464
  }
@@ -913,6 +1466,27 @@ function getEfdRetryCount (durationMs, slowTestRetries) {
913
1466
  return 0 // ≥ 5 min — abort
914
1467
  }
915
1468
 
1469
+ /**
1470
+ * Returns the maximum retry count configured by the backend for EFD.
1471
+ *
1472
+ * @param {Record<string, number> | undefined} slowTestRetries
1473
+ * @returns {number | undefined}
1474
+ */
1475
+ function getMaxEfdRetryCount (slowTestRetries) {
1476
+ if (slowTestRetries === undefined) return
1477
+
1478
+ const retryCounts = Object.values(slowTestRetries)
1479
+ if (retryCounts.length === 0) return
1480
+
1481
+ let maxRetries = 0
1482
+ for (const retryCount of retryCounts) {
1483
+ if (retryCount > maxRetries) {
1484
+ maxRetries = retryCount
1485
+ }
1486
+ }
1487
+ return maxRetries
1488
+ }
1489
+
916
1490
  function getIsFaultyEarlyFlakeDetection (projectSuites, testsBySuiteName, faultyThresholdPercentage) {
917
1491
  let newSuites = 0
918
1492
  for (const suite of projectSuites) {
@@ -932,8 +1506,8 @@ function getIsFaultyEarlyFlakeDetection (projectSuites, testsBySuiteName, faulty
932
1506
  }
933
1507
 
934
1508
  function getTestSessionName (config, trimmedCommand, envTags) {
935
- if (config.ciVisibilityTestSessionName) {
936
- return config.ciVisibilityTestSessionName
1509
+ if (config.DD_TEST_SESSION_NAME) {
1510
+ return config.DD_TEST_SESSION_NAME
937
1511
  }
938
1512
  const lageTestSessionName = getLageTestSessionName()
939
1513
  if (lageTestSessionName) {
@@ -1052,7 +1626,7 @@ function isFailedTestReplaySupported (testFramework, frameworkVersion) {
1052
1626
  : true
1053
1627
  }
1054
1628
 
1055
- function getLibraryCapabilitiesTags (testFramework, frameworkVersion) {
1629
+ function getLibraryCapabilitiesTags (testFramework, frameworkVersion, options = {}) {
1056
1630
  return {
1057
1631
  [DD_CAPABILITIES_TEST_IMPACT_ANALYSIS]: isTiaSupported(testFramework)
1058
1632
  ? '1'
@@ -1074,7 +1648,8 @@ function getLibraryCapabilitiesTags (testFramework, frameworkVersion) {
1074
1648
  isAttemptToFixSupported(testFramework, frameworkVersion)
1075
1649
  ? '5'
1076
1650
  : undefined,
1077
- [DD_CAPABILITIES_FAILED_TEST_REPLAY]: isFailedTestReplaySupported(testFramework, frameworkVersion)
1651
+ [DD_CAPABILITIES_FAILED_TEST_REPLAY]: !options.omitFailedTestReplay &&
1652
+ isFailedTestReplaySupported(testFramework, frameworkVersion)
1078
1653
  ? '1'
1079
1654
  : undefined,
1080
1655
  }
@@ -1144,10 +1719,7 @@ function getPullRequestBaseBranch (pullRequestBaseBranch) {
1144
1719
  let bestScore = Infinity
1145
1720
  for (const branch of Object.keys(metrics)) {
1146
1721
  const score = metrics[branch].ahead
1147
- if (score < bestScore) {
1148
- bestScore = score
1149
- bestBranch = branch
1150
- } else if (score === bestScore && isDefaultBranch(branch)) {
1722
+ if (score < bestScore || score === bestScore && isDefaultBranch(branch)) {
1151
1723
  bestScore = score
1152
1724
  bestBranch = branch
1153
1725
  }
@@ -1204,23 +1776,149 @@ function getModifiedFilesFromDiff (diff) {
1204
1776
  }
1205
1777
 
1206
1778
  /**
1207
- * Scans serialized worker trace payloads for tests tagged with TEST_HAS_DYNAMIC_NAME
1208
- * and populates the provided Set. Silently ignores parse errors.
1779
+ * @typedef {object} AttemptToFixExecutionResult
1780
+ * @property {string} name
1781
+ * @property {number} executions
1782
+ * @property {number} failedCount
1783
+ * @property {boolean} isDisabled
1784
+ * @property {boolean} isQuarantined
1785
+ */
1786
+
1787
+ /**
1788
+ * @typedef {Map<string, AttemptToFixExecutionResult>} AttemptToFixExecutions
1789
+ */
1790
+
1791
+ /**
1792
+ * Formats a test name for user-facing Test Optimization summaries.
1793
+ *
1794
+ * @param {string | undefined} testSuite
1795
+ * @param {string} testName
1796
+ * @returns {string}
1797
+ */
1798
+ function formatTestOptimizationName (testSuite, testName) {
1799
+ return testSuite ? `${testSuite} › ${testName}` : testName
1800
+ }
1801
+
1802
+ /**
1803
+ * Renders a bounded bullet list for Test Optimization summaries.
1804
+ *
1805
+ * @param {Array<{ text: string, suffix?: string }>} items
1806
+ * @returns {string}
1807
+ */
1808
+ function formatTestOptimizationList (items) {
1809
+ const shown = items.slice(0, MAX_TEST_OPTIMIZATION_SUMMARY_ITEMS)
1810
+ const more = items.length - shown.length
1811
+ const moreSuffix = more > 0 ? `\n ... and ${more} more` : ''
1812
+
1813
+ return shown.map(({ text, suffix }) => ` • ${text}${suffix ? ` (${suffix})` : ''}`).join('\n') + moreSuffix
1814
+ }
1815
+
1816
+ /**
1817
+ * Logs a compact message when an attempt-to-fix test execution starts.
1818
+ *
1819
+ * @param {string | undefined} testSuite
1820
+ * @param {string} testName
1821
+ * @param {Set<string>} [loggedAttemptToFixTests]
1822
+ */
1823
+ function logAttemptToFixTestExecution (testSuite, testName, loggedAttemptToFixTests) {
1824
+ if (!testName) return
1825
+
1826
+ const name = formatTestOptimizationName(testSuite, testName)
1827
+ if (loggedAttemptToFixTests) {
1828
+ if (loggedAttemptToFixTests.has(name)) return
1829
+
1830
+ loggedAttemptToFixTests.add(name)
1831
+ }
1832
+
1833
+ // eslint-disable-next-line no-console -- Intentional user-facing attempt-to-fix progress report
1834
+ console.warn(`Datadog Test Optimization: attempting to fix ${name}`)
1835
+ }
1836
+
1837
+ /**
1838
+ * Records a single attempt-to-fix execution for the end-of-session user summary.
1839
+ *
1840
+ * @param {AttemptToFixExecutions} attemptToFixExecutions
1841
+ * @param {{
1842
+ * testSuite?: string,
1843
+ * testName: string,
1844
+ * status: string,
1845
+ * isDisabled?: boolean,
1846
+ * isQuarantined?: boolean
1847
+ * }} execution
1848
+ */
1849
+ function recordAttemptToFixExecution (attemptToFixExecutions, execution) {
1850
+ if (!execution?.testName) return
1851
+
1852
+ const { testSuite, testName, status, isDisabled, isQuarantined } = execution
1853
+ const name = formatTestOptimizationName(testSuite, testName)
1854
+ let result = attemptToFixExecutions.get(name)
1855
+
1856
+ if (!result) {
1857
+ result = {
1858
+ name,
1859
+ executions: 0,
1860
+ failedCount: 0,
1861
+ isDisabled: false,
1862
+ isQuarantined: false,
1863
+ }
1864
+ attemptToFixExecutions.set(name, result)
1865
+ }
1866
+
1867
+ result.executions++
1868
+ result.isDisabled = result.isDisabled || !!isDisabled
1869
+ result.isQuarantined = result.isQuarantined || !!isQuarantined
1870
+
1871
+ if (status === 'fail') {
1872
+ result.failedCount++
1873
+ }
1874
+ }
1875
+
1876
+ function collectDynamicNameFromTraceSpan (span, newTestsWithDynamicNames) {
1877
+ const meta = span.meta
1878
+ if (meta?.[TEST_HAS_DYNAMIC_NAME] !== 'true') return
1879
+
1880
+ const suite = meta[TEST_SUITE]
1881
+ const name = meta[TEST_NAME]
1882
+ if (suite && name) {
1883
+ newTestsWithDynamicNames.add(`${suite} › ${name}`)
1884
+ }
1885
+ }
1886
+
1887
+ function collectAttemptToFixExecutionFromTraceSpan (span, attemptToFixExecutions) {
1888
+ const meta = span.meta
1889
+ if (meta?.[TEST_MANAGEMENT_IS_ATTEMPT_TO_FIX] !== 'true') return
1890
+
1891
+ recordAttemptToFixExecution(attemptToFixExecutions, {
1892
+ testSuite: meta[TEST_SUITE],
1893
+ testName: meta[TEST_NAME],
1894
+ status: meta[TEST_STATUS],
1895
+ isDisabled: meta[TEST_MANAGEMENT_IS_DISABLED] === 'true',
1896
+ isQuarantined: meta[TEST_MANAGEMENT_IS_QUARANTINED] === 'true',
1897
+ })
1898
+ }
1899
+
1900
+ /**
1901
+ * Scans serialized worker trace payloads and populates Test Optimization summary data.
1902
+ * Silently ignores parse errors.
1209
1903
  *
1210
1904
  * @param {string} data - JSON-serialized traces from a worker
1211
- * @param {Set<string>} newTestsWithDynamicNames - Set to populate with "suite › name" strings
1905
+ * @param {{
1906
+ * newTestsWithDynamicNames?: Set<string>,
1907
+ * attemptToFixExecutions?: AttemptToFixExecutions
1908
+ * }} summaries
1212
1909
  */
1213
- function collectDynamicNamesFromTraces (data, newTestsWithDynamicNames) {
1910
+ function collectTestOptimizationSummariesFromTraces (data, summaries) {
1911
+ const { newTestsWithDynamicNames, attemptToFixExecutions } = summaries
1912
+
1214
1913
  try {
1215
1914
  const traces = JSON.parse(data)
1216
1915
  for (const trace of traces) {
1217
1916
  for (const span of trace) {
1218
- if (span.meta?.[TEST_HAS_DYNAMIC_NAME] === 'true') {
1219
- const suite = span.meta[TEST_SUITE]
1220
- const name = span.meta[TEST_NAME]
1221
- if (suite && name) {
1222
- newTestsWithDynamicNames.add(`${suite} › ${name}`)
1223
- }
1917
+ if (newTestsWithDynamicNames) {
1918
+ collectDynamicNameFromTraceSpan(span, newTestsWithDynamicNames)
1919
+ }
1920
+ if (attemptToFixExecutions) {
1921
+ collectAttemptToFixExecutionFromTraceSpan(span, attemptToFixExecutions)
1224
1922
  }
1225
1923
  }
1226
1924
  }
@@ -1230,33 +1928,164 @@ function collectDynamicNamesFromTraces (data, newTestsWithDynamicNames) {
1230
1928
  }
1231
1929
 
1232
1930
  /**
1233
- * Logs a "Datadog Test Optimization" warning about new tests with dynamic names.
1234
- * Clears the Set after logging. No-op if the Set is empty.
1931
+ * Scans serialized worker trace payloads for tests tagged with TEST_HAS_DYNAMIC_NAME
1932
+ * and populates the provided Set. Silently ignores parse errors.
1235
1933
  *
1236
- * @param {Set<string>} newTestsWithDynamicNames
1934
+ * @param {string} data - JSON-serialized traces from a worker
1935
+ * @param {Set<string>} newTestsWithDynamicNames - Set to populate with "suite › name" strings
1237
1936
  */
1238
- function logDynamicNamesWarning (newTestsWithDynamicNames) {
1239
- if (newTestsWithDynamicNames.size === 0) return
1937
+ function collectDynamicNamesFromTraces (data, newTestsWithDynamicNames) {
1938
+ collectTestOptimizationSummariesFromTraces(data, { newTestsWithDynamicNames })
1939
+ }
1240
1940
 
1241
- const MAX_SHOWN = 10
1242
- const names = [...newTestsWithDynamicNames]
1243
- const shown = names.slice(0, MAX_SHOWN)
1244
- const more = names.length - shown.length
1245
- const moreSuffix = more > 0 ? `\n ... and ${more} more` : ''
1246
- const nameList = shown.map(n => ` • ${n}`).join('\n') + moreSuffix
1941
+ /**
1942
+ * Scans serialized worker trace payloads for attempt-to-fix test spans.
1943
+ *
1944
+ * @param {string} data - JSON-serialized traces from a worker
1945
+ * @param {AttemptToFixExecutions} attemptToFixExecutions
1946
+ */
1947
+ function collectAttemptToFixExecutionsFromTraces (data, attemptToFixExecutions) {
1948
+ collectTestOptimizationSummariesFromTraces(data, { attemptToFixExecutions })
1949
+ }
1247
1950
 
1248
- const line = '-'.repeat(50)
1249
- // eslint-disable-next-line no-console -- Intentional user-facing session summary
1250
- console.warn(
1251
- `\n${line}\nDatadog Test Optimization\n${line}\n` +
1951
+ function getAttemptToFixManagementNotes (result) {
1952
+ const notes = []
1953
+
1954
+ if (result.isDisabled) {
1955
+ notes.push('Test was marked as disabled but was run because it is attempt to fix.')
1956
+ }
1957
+ if (result.isQuarantined) {
1958
+ notes.push('Test was marked as quarantined but was not quarantined because it is attempt to fix.')
1959
+ }
1960
+
1961
+ return notes
1962
+ }
1963
+
1964
+ function hasAttemptToFixManagementNotes (result) {
1965
+ return result.isDisabled || result.isQuarantined
1966
+ }
1967
+
1968
+ function addAttemptToFixResultLine (lines, result) {
1969
+ lines.push(` • ${result.name}`)
1970
+
1971
+ for (const note of getAttemptToFixManagementNotes(result)) {
1972
+ lines.push(` ${note}`)
1973
+ }
1974
+ }
1975
+
1976
+ /**
1977
+ * Formats the attempt-to-fix end-of-session summary.
1978
+ *
1979
+ * @param {AttemptToFixExecutions} attemptToFixExecutions
1980
+ * @returns {string}
1981
+ */
1982
+ function formatAttemptToFixSummary (attemptToFixExecutions) {
1983
+ if (attemptToFixExecutions.size === 0) return ''
1984
+
1985
+ const results = [...attemptToFixExecutions.values()]
1986
+ const failedResults = results.filter(result => result.failedCount > 0)
1987
+ const totalExecutions = results.reduce((total, result) => total + result.executions, 0)
1988
+
1989
+ if (failedResults.length === 0) {
1990
+ const lines = [
1991
+ `Attempt to fix passed: all ${totalExecutions} execution(s) passed for ${results.length} test(s).`,
1992
+ ]
1993
+
1994
+ for (const result of results) {
1995
+ if (hasAttemptToFixManagementNotes(result)) {
1996
+ addAttemptToFixResultLine(lines, result)
1997
+ }
1998
+ }
1999
+
2000
+ return lines.join('\n')
2001
+ }
2002
+
2003
+ const totalFailedExecutions = failedResults.reduce(
2004
+ (total, result) => total + result.failedCount,
2005
+ 0
2006
+ )
2007
+ const lines = [
2008
+ `Attempt to fix failed: ${totalFailedExecutions} of ${totalExecutions} execution(s) failed ` +
2009
+ `across ${failedResults.length} of ${results.length} test(s).`,
2010
+ ]
2011
+
2012
+ for (const result of failedResults) {
2013
+ addAttemptToFixResultLine(lines, result)
2014
+ }
2015
+ for (const result of results) {
2016
+ if (result.failedCount === 0 && hasAttemptToFixManagementNotes(result)) {
2017
+ addAttemptToFixResultLine(lines, result)
2018
+ }
2019
+ }
2020
+
2021
+ return lines.join('\n')
2022
+ }
2023
+
2024
+ /**
2025
+ * Formats the dynamic-name warning section of the Test Optimization summary.
2026
+ *
2027
+ * @param {Set<string>} newTestsWithDynamicNames
2028
+ * @returns {string}
2029
+ */
2030
+ function formatDynamicNamesSummary (newTestsWithDynamicNames) {
2031
+ if (newTestsWithDynamicNames.size === 0) return ''
2032
+
2033
+ const items = [...newTestsWithDynamicNames].map(name => ({ text: name }))
2034
+ return (
1252
2035
  `${newTestsWithDynamicNames.size} test(s) detected as new but their names contain ` +
1253
2036
  'dynamic data (timestamps, UUIDs, etc.).\n' +
1254
2037
  'Tests with changing names are always treated as new on every run, ' +
1255
2038
  'causing unnecessary Early Flake Detection retries and preventing correct new test detection.\n' +
1256
2039
  'Consider using stable, deterministic test names.\n\n' +
1257
- `${nameList}\n`
2040
+ formatTestOptimizationList(items)
1258
2041
  )
1259
- newTestsWithDynamicNames.clear()
2042
+ }
2043
+
2044
+ /**
2045
+ * Logs a single Test Optimization session summary.
2046
+ *
2047
+ * @param {{
2048
+ * attemptToFixExecutions?: AttemptToFixExecutions,
2049
+ * newTestsWithDynamicNames?: Set<string>,
2050
+ * extraSections?: string[]
2051
+ * }} summary
2052
+ */
2053
+ function logTestOptimizationSummary (summary) {
2054
+ const { attemptToFixExecutions, newTestsWithDynamicNames, extraSections = [] } = summary
2055
+ const sections = []
2056
+ const attemptToFixSummary = attemptToFixExecutions
2057
+ ? formatAttemptToFixSummary(attemptToFixExecutions)
2058
+ : ''
2059
+ const dynamicNamesSummary = newTestsWithDynamicNames
2060
+ ? formatDynamicNamesSummary(newTestsWithDynamicNames)
2061
+ : ''
2062
+
2063
+ if (attemptToFixSummary) sections.push(attemptToFixSummary)
2064
+ sections.push(...extraSections.filter(Boolean))
2065
+ if (dynamicNamesSummary) sections.push(dynamicNamesSummary)
2066
+
2067
+ if (sections.length === 0) return
2068
+
2069
+ const line = '-'.repeat(50)
2070
+ // eslint-disable-next-line no-console -- Intentional user-facing session summary
2071
+ console.warn(`\n${line}\nDatadog Test Optimization\n${line}\n${sections.join('\n\n')}\n`)
2072
+
2073
+ if (attemptToFixExecutions) {
2074
+ attemptToFixExecutions.clear()
2075
+ }
2076
+ if (newTestsWithDynamicNames) {
2077
+ newTestsWithDynamicNames.clear()
2078
+ }
2079
+ }
2080
+
2081
+ /**
2082
+ * Logs a "Datadog Test Optimization" warning about new tests with dynamic names.
2083
+ * Clears the Set after logging. No-op if the Set is empty.
2084
+ *
2085
+ * @param {Set<string>} newTestsWithDynamicNames
2086
+ */
2087
+ function logDynamicNamesWarning (newTestsWithDynamicNames) {
2088
+ logTestOptimizationSummary({ newTestsWithDynamicNames })
1260
2089
  }
1261
2090
 
1262
2091
  function isModifiedTest (testPath, testStartLine, testEndLine, modifiedFiles, testFramework) {