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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (646) hide show
  1. package/LICENSE-3rdparty.csv +89 -104
  2. package/README.md +9 -3
  3. package/changes.json +8 -3
  4. package/ci/init.js +25 -5
  5. package/ci/vitest-no-worker-init-setup.mjs +430 -0
  6. package/ext/exporters.js +1 -0
  7. package/ext/tags.js +3 -0
  8. package/index.d.ts +349 -244
  9. package/index.electron.js +3 -0
  10. package/initialize.mjs +9 -8
  11. package/loader-hook.mjs +154 -47
  12. package/package.json +121 -79
  13. package/packages/datadog-core/src/storage.js +47 -48
  14. package/packages/datadog-esbuild/index.js +52 -10
  15. package/packages/datadog-esbuild/src/utils.js +46 -3
  16. package/packages/datadog-instrumentations/src/aerospike.js +3 -3
  17. package/packages/datadog-instrumentations/src/ai.js +131 -76
  18. package/packages/datadog-instrumentations/src/amqplib.js +6 -7
  19. package/packages/datadog-instrumentations/src/anthropic.js +10 -10
  20. package/packages/datadog-instrumentations/src/apollo-server-core.js +3 -3
  21. package/packages/datadog-instrumentations/src/apollo-server.js +10 -18
  22. package/packages/datadog-instrumentations/src/avsc.js +6 -6
  23. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js-context-methods.js +18 -0
  24. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js.js +111 -0
  25. package/packages/datadog-instrumentations/src/aws-sdk.js +172 -72
  26. package/packages/datadog-instrumentations/src/azure-cosmos.js +7 -0
  27. package/packages/datadog-instrumentations/src/azure-durable-functions.js +8 -8
  28. package/packages/datadog-instrumentations/src/azure-functions.js +3 -0
  29. package/packages/datadog-instrumentations/src/bluebird.js +2 -2
  30. package/packages/datadog-instrumentations/src/body-parser.js +5 -2
  31. package/packages/datadog-instrumentations/src/cassandra-driver.js +12 -9
  32. package/packages/datadog-instrumentations/src/child_process.js +22 -32
  33. package/packages/datadog-instrumentations/src/claude-agent-sdk.js +587 -0
  34. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +41 -24
  35. package/packages/datadog-instrumentations/src/connect.js +14 -12
  36. package/packages/datadog-instrumentations/src/cookie-parser.js +5 -4
  37. package/packages/datadog-instrumentations/src/cookie.js +9 -3
  38. package/packages/datadog-instrumentations/src/couchbase.js +73 -238
  39. package/packages/datadog-instrumentations/src/crypto.js +50 -6
  40. package/packages/datadog-instrumentations/src/cucumber-worker-threads.js +19 -0
  41. package/packages/datadog-instrumentations/src/cucumber.js +751 -188
  42. package/packages/datadog-instrumentations/src/cypress-config.js +432 -0
  43. package/packages/datadog-instrumentations/src/cypress.js +88 -4
  44. package/packages/datadog-instrumentations/src/dns.js +61 -61
  45. package/packages/datadog-instrumentations/src/elasticsearch.js +9 -12
  46. package/packages/datadog-instrumentations/src/electron/preload.js +42 -0
  47. package/packages/datadog-instrumentations/src/electron.js +240 -0
  48. package/packages/datadog-instrumentations/src/express-mongo-sanitize.js +11 -9
  49. package/packages/datadog-instrumentations/src/express-session.js +14 -13
  50. package/packages/datadog-instrumentations/src/express.js +56 -34
  51. package/packages/datadog-instrumentations/src/fastify.js +169 -86
  52. package/packages/datadog-instrumentations/src/fetch.js +5 -5
  53. package/packages/datadog-instrumentations/src/fs.js +47 -47
  54. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +5 -7
  55. package/packages/datadog-instrumentations/src/google-genai.js +4 -4
  56. package/packages/datadog-instrumentations/src/graphql.js +26 -362
  57. package/packages/datadog-instrumentations/src/grpc/client.js +48 -32
  58. package/packages/datadog-instrumentations/src/grpc/server.js +20 -2
  59. package/packages/datadog-instrumentations/src/hapi.js +2 -2
  60. package/packages/datadog-instrumentations/src/helpers/bundler-register.js +41 -13
  61. package/packages/datadog-instrumentations/src/helpers/callback-instrumentor.js +74 -0
  62. package/packages/datadog-instrumentations/src/helpers/check-require-cache.js +85 -9
  63. package/packages/datadog-instrumentations/src/helpers/hook.js +34 -6
  64. package/packages/datadog-instrumentations/src/helpers/hooks.js +24 -19
  65. package/packages/datadog-instrumentations/src/helpers/instrument.js +61 -14
  66. package/packages/datadog-instrumentations/src/helpers/kafka.js +58 -0
  67. package/packages/datadog-instrumentations/src/helpers/optional-peer-bundler.js +65 -0
  68. package/packages/datadog-instrumentations/src/helpers/promise-instrumentor.js +42 -0
  69. package/packages/datadog-instrumentations/src/helpers/promise.js +2 -2
  70. package/packages/datadog-instrumentations/src/helpers/register.js +109 -146
  71. package/packages/datadog-instrumentations/src/helpers/require-optional-peer.js +17 -0
  72. package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +13 -5
  73. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +24 -7
  74. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +6 -6
  75. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/aws-durable-execution-sdk-js.js +31 -0
  76. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/azure-cosmos.js +50 -0
  77. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/claude-agent-sdk.js +17 -0
  78. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +201 -0
  79. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +7 -0
  80. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/langgraph.js +4 -2
  81. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/mercurius.js +31 -0
  82. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-sdk.js +35 -0
  83. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +85 -0
  84. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +18 -2
  85. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +49 -224
  86. package/packages/datadog-instrumentations/src/helpers/router-helper.js +8 -8
  87. package/packages/datadog-instrumentations/src/hono.js +71 -9
  88. package/packages/datadog-instrumentations/src/http/client.js +50 -27
  89. package/packages/datadog-instrumentations/src/http/server.js +77 -34
  90. package/packages/datadog-instrumentations/src/http2/client.js +16 -15
  91. package/packages/datadog-instrumentations/src/http2/server.js +156 -25
  92. package/packages/datadog-instrumentations/src/ioredis.js +17 -14
  93. package/packages/datadog-instrumentations/src/iovalkey.js +1 -2
  94. package/packages/datadog-instrumentations/src/jest/bail-reporter.js +42 -0
  95. package/packages/datadog-instrumentations/src/jest/coverage-backfill.js +163 -0
  96. package/packages/datadog-instrumentations/src/jest.js +1795 -404
  97. package/packages/datadog-instrumentations/src/kafkajs.js +284 -170
  98. package/packages/datadog-instrumentations/src/knex.js +17 -17
  99. package/packages/datadog-instrumentations/src/koa.js +15 -14
  100. package/packages/datadog-instrumentations/src/ldapjs.js +5 -5
  101. package/packages/datadog-instrumentations/src/light-my-request.js +2 -2
  102. package/packages/datadog-instrumentations/src/limitd-client.js +5 -5
  103. package/packages/datadog-instrumentations/src/lodash.js +4 -4
  104. package/packages/datadog-instrumentations/src/mariadb.js +18 -16
  105. package/packages/datadog-instrumentations/src/memcached.js +4 -3
  106. package/packages/datadog-instrumentations/src/mercurius.js +11 -0
  107. package/packages/datadog-instrumentations/src/microgateway-core.js +2 -2
  108. package/packages/datadog-instrumentations/src/mocha/common.js +7 -4
  109. package/packages/datadog-instrumentations/src/mocha/main.js +557 -118
  110. package/packages/datadog-instrumentations/src/mocha/utils.js +531 -128
  111. package/packages/datadog-instrumentations/src/mocha/worker.js +27 -9
  112. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +254 -0
  113. package/packages/datadog-instrumentations/src/mongodb-core.js +43 -31
  114. package/packages/datadog-instrumentations/src/mongodb.js +79 -5
  115. package/packages/datadog-instrumentations/src/mongoose.js +43 -34
  116. package/packages/datadog-instrumentations/src/mquery.js +5 -5
  117. package/packages/datadog-instrumentations/src/multer.js +5 -4
  118. package/packages/datadog-instrumentations/src/mysql.js +17 -17
  119. package/packages/datadog-instrumentations/src/mysql2.js +39 -5
  120. package/packages/datadog-instrumentations/src/nats.js +182 -0
  121. package/packages/datadog-instrumentations/src/net.js +21 -19
  122. package/packages/datadog-instrumentations/src/next.js +44 -10
  123. package/packages/datadog-instrumentations/src/nyc.js +43 -6
  124. package/packages/datadog-instrumentations/src/openai.js +124 -38
  125. package/packages/datadog-instrumentations/src/oracledb.js +12 -7
  126. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +27 -6
  127. package/packages/datadog-instrumentations/src/passport-utils.js +5 -5
  128. package/packages/datadog-instrumentations/src/path-to-regexp.js +44 -0
  129. package/packages/datadog-instrumentations/src/pg.js +58 -25
  130. package/packages/datadog-instrumentations/src/pino.js +26 -42
  131. package/packages/datadog-instrumentations/src/playwright-browser-scripts.js +27 -0
  132. package/packages/datadog-instrumentations/src/playwright.js +1090 -351
  133. package/packages/datadog-instrumentations/src/prisma.js +1 -2
  134. package/packages/datadog-instrumentations/src/protobufjs.js +16 -16
  135. package/packages/datadog-instrumentations/src/redis.js +28 -15
  136. package/packages/datadog-instrumentations/src/restify.js +6 -5
  137. package/packages/datadog-instrumentations/src/router.js +243 -87
  138. package/packages/datadog-instrumentations/src/selenium.js +5 -3
  139. package/packages/datadog-instrumentations/src/sequelize.js +1 -1
  140. package/packages/datadog-instrumentations/src/stripe.js +47 -33
  141. package/packages/datadog-instrumentations/src/tedious.js +28 -0
  142. package/packages/datadog-instrumentations/src/url.js +1 -3
  143. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1297 -0
  144. package/packages/datadog-instrumentations/src/vitest-main.js +1592 -0
  145. package/packages/datadog-instrumentations/src/vitest-util.js +251 -0
  146. package/packages/datadog-instrumentations/src/vitest-worker.js +822 -0
  147. package/packages/datadog-instrumentations/src/vitest.js +11 -1258
  148. package/packages/datadog-instrumentations/src/vm.js +1 -3
  149. package/packages/datadog-instrumentations/src/winston.js +4 -4
  150. package/packages/datadog-instrumentations/src/ws.js +7 -7
  151. package/packages/datadog-instrumentations/src/zlib.js +29 -0
  152. package/packages/datadog-plugin-ai/src/index.js +1 -1
  153. package/packages/datadog-plugin-ai/src/tracing.js +66 -3
  154. package/packages/datadog-plugin-ai/src/utils.js +17 -4
  155. package/packages/datadog-plugin-apollo/src/gateway/request.js +1 -21
  156. package/packages/datadog-plugin-avsc/src/schema_iterator.js +3 -3
  157. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/checkpoint.js +31 -0
  158. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/client.js +55 -0
  159. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/context.js +123 -0
  160. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/handler.js +129 -0
  161. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/index.js +19 -0
  162. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/trace-checkpoint.js +224 -0
  163. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +79 -0
  164. package/packages/datadog-plugin-aws-sdk/src/base.js +90 -53
  165. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +1 -1
  166. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +218 -4
  167. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +1 -1
  168. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +2 -1
  169. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +59 -14
  170. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +174 -75
  171. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +34 -23
  172. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +2 -1
  173. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +1 -1
  174. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +26 -26
  175. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +187 -101
  176. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +20 -18
  177. package/packages/datadog-plugin-azure-cosmos/src/index.js +144 -0
  178. package/packages/datadog-plugin-azure-event-hubs/src/producer.js +8 -15
  179. package/packages/datadog-plugin-azure-functions/src/index.js +7 -3
  180. package/packages/datadog-plugin-azure-service-bus/src/producer.js +5 -10
  181. package/packages/datadog-plugin-bullmq/src/consumer.js +5 -4
  182. package/packages/datadog-plugin-bullmq/src/filter.js +35 -0
  183. package/packages/datadog-plugin-bullmq/src/producer.js +121 -33
  184. package/packages/datadog-plugin-bunyan/src/index.js +28 -0
  185. package/packages/datadog-plugin-child_process/src/index.js +13 -2
  186. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +6 -6
  187. package/packages/datadog-plugin-claude-agent-sdk/src/index.js +31 -0
  188. package/packages/datadog-plugin-claude-agent-sdk/src/tracing.js +107 -0
  189. package/packages/datadog-plugin-claude-agent-sdk/src/util.js +15 -0
  190. package/packages/datadog-plugin-couchbase/src/index.js +58 -52
  191. package/packages/datadog-plugin-cucumber/src/index.js +46 -24
  192. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +1018 -97
  193. package/packages/datadog-plugin-cypress/src/index.js +104 -2
  194. package/packages/datadog-plugin-cypress/src/plugin.js +6 -14
  195. package/packages/datadog-plugin-cypress/src/source-map-utils.js +48 -1
  196. package/packages/datadog-plugin-cypress/src/support.js +180 -25
  197. package/packages/datadog-plugin-dd-trace-api/src/index.js +1 -1
  198. package/packages/datadog-plugin-dns/src/lookup.js +8 -6
  199. package/packages/datadog-plugin-elasticsearch/src/index.js +28 -8
  200. package/packages/datadog-plugin-electron/src/index.js +17 -0
  201. package/packages/datadog-plugin-electron/src/ipc.js +143 -0
  202. package/packages/datadog-plugin-electron/src/net.js +82 -0
  203. package/packages/datadog-plugin-express/src/code_origin.js +1 -1
  204. package/packages/datadog-plugin-fastify/src/code_origin.js +1 -1
  205. package/packages/datadog-plugin-fs/src/index.js +2 -1
  206. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -5
  207. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +27 -18
  208. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +5 -8
  209. package/packages/datadog-plugin-graphql/src/execute.js +706 -34
  210. package/packages/datadog-plugin-graphql/src/index.js +43 -9
  211. package/packages/datadog-plugin-graphql/src/parse.js +45 -4
  212. package/packages/datadog-plugin-graphql/src/request.js +135 -0
  213. package/packages/datadog-plugin-graphql/src/tools/signature.js +32 -7
  214. package/packages/datadog-plugin-graphql/src/tools/transforms.js +118 -100
  215. package/packages/datadog-plugin-graphql/src/utils.js +261 -3
  216. package/packages/datadog-plugin-graphql/src/validate.js +53 -7
  217. package/packages/datadog-plugin-grpc/src/client.js +7 -8
  218. package/packages/datadog-plugin-grpc/src/server.js +1 -1
  219. package/packages/datadog-plugin-grpc/src/util.js +57 -22
  220. package/packages/datadog-plugin-http/src/client.js +12 -14
  221. package/packages/datadog-plugin-http/src/index.js +6 -8
  222. package/packages/datadog-plugin-http/src/server.js +63 -20
  223. package/packages/datadog-plugin-http2/src/client.js +6 -3
  224. package/packages/datadog-plugin-http2/src/server.js +48 -8
  225. package/packages/datadog-plugin-jest/src/index.js +136 -68
  226. package/packages/datadog-plugin-jest/src/util.js +37 -16
  227. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +31 -4
  228. package/packages/datadog-plugin-kafkajs/src/consumer.js +2 -9
  229. package/packages/datadog-plugin-kafkajs/src/producer.js +37 -8
  230. package/packages/datadog-plugin-langgraph/src/stream.js +1 -1
  231. package/packages/datadog-plugin-memcached/src/index.js +1 -1
  232. package/packages/datadog-plugin-mocha/src/index.js +66 -17
  233. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/index.js +24 -0
  234. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +173 -0
  235. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +30 -0
  236. package/packages/datadog-plugin-mongodb-core/src/bulk-write.js +43 -0
  237. package/packages/datadog-plugin-mongodb-core/src/index.js +8 -206
  238. package/packages/datadog-plugin-mongodb-core/src/query.js +452 -0
  239. package/packages/datadog-plugin-mysql/src/index.js +9 -4
  240. package/packages/datadog-plugin-nats/src/consumer.js +43 -0
  241. package/packages/datadog-plugin-nats/src/index.js +20 -0
  242. package/packages/datadog-plugin-nats/src/producer.js +62 -0
  243. package/packages/datadog-plugin-nats/src/util.js +33 -0
  244. package/packages/datadog-plugin-next/src/index.js +14 -18
  245. package/packages/datadog-plugin-openai/src/services.js +5 -3
  246. package/packages/datadog-plugin-openai/src/tracing.js +27 -25
  247. package/packages/datadog-plugin-oracledb/src/index.js +13 -2
  248. package/packages/datadog-plugin-pg/src/index.js +13 -3
  249. package/packages/datadog-plugin-pino/src/index.js +42 -0
  250. package/packages/datadog-plugin-playwright/src/index.js +21 -11
  251. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +3 -3
  252. package/packages/datadog-plugin-redis/src/index.js +54 -25
  253. package/packages/datadog-plugin-rhea/src/producer.js +1 -1
  254. package/packages/datadog-plugin-router/src/index.js +46 -44
  255. package/packages/datadog-plugin-selenium/src/index.js +1 -1
  256. package/packages/datadog-plugin-tedious/src/index.js +1 -1
  257. package/packages/datadog-plugin-undici/src/index.js +24 -2
  258. package/packages/datadog-plugin-vitest/src/index.js +160 -90
  259. package/packages/datadog-plugin-winston/src/index.js +30 -0
  260. package/packages/datadog-plugin-ws/src/close.js +3 -1
  261. package/packages/datadog-plugin-ws/src/producer.js +2 -0
  262. package/packages/datadog-plugin-ws/src/receiver.js +2 -1
  263. package/packages/datadog-shimmer/src/shimmer.js +101 -39
  264. package/packages/datadog-webpack/index.js +20 -4
  265. package/packages/datadog-webpack/src/optional-peer-loader.js +17 -0
  266. package/packages/dd-trace/index.electron.js +3 -0
  267. package/packages/dd-trace/index.js +2 -34
  268. package/packages/dd-trace/src/aiguard/channels.js +7 -0
  269. package/packages/dd-trace/src/aiguard/index.js +16 -34
  270. package/packages/dd-trace/src/aiguard/integrations/evaluate.js +46 -0
  271. package/packages/dd-trace/src/aiguard/integrations/index.js +34 -0
  272. package/packages/dd-trace/src/aiguard/integrations/openai.js +80 -0
  273. package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +92 -0
  274. package/packages/dd-trace/src/aiguard/messages/openai.js +382 -0
  275. package/packages/{datadog-instrumentations/src/helpers/ai-messages.js → dd-trace/src/aiguard/messages/vercel-ai.js} +30 -27
  276. package/packages/dd-trace/src/aiguard/sdk.js +151 -54
  277. package/packages/dd-trace/src/aiguard/tags.js +26 -10
  278. package/packages/dd-trace/src/appsec/api_security/index.js +55 -0
  279. package/packages/dd-trace/src/appsec/api_security/sampler.js +147 -0
  280. package/packages/dd-trace/src/appsec/blocked_templates.js +4 -3
  281. package/packages/dd-trace/src/appsec/blocking.js +84 -41
  282. package/packages/dd-trace/src/appsec/channels.js +5 -1
  283. package/packages/dd-trace/src/appsec/downstream_requests.js +116 -62
  284. package/packages/dd-trace/src/appsec/graphql.js +20 -17
  285. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +1 -1
  286. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +81 -81
  287. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +23 -23
  288. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +1 -1
  289. package/packages/dd-trace/src/appsec/iast/index.js +3 -2
  290. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +4 -4
  291. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +2 -2
  292. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +4 -4
  293. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -2
  294. package/packages/dd-trace/src/appsec/iast/telemetry/index.js +2 -1
  295. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +54 -12
  296. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +5 -1
  297. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +32 -5
  298. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +1 -3
  299. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +84 -49
  300. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +1 -1
  301. package/packages/dd-trace/src/appsec/index.js +65 -47
  302. package/packages/dd-trace/src/appsec/lambda.js +135 -0
  303. package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -5
  304. package/packages/dd-trace/src/appsec/rasp/lfi.js +8 -4
  305. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +5 -10
  306. package/packages/dd-trace/src/appsec/rasp/ssrf.js +26 -18
  307. package/packages/dd-trace/src/appsec/recommended.json +2438 -13
  308. package/packages/dd-trace/src/appsec/remote_config.js +1 -0
  309. package/packages/dd-trace/src/appsec/reporter.js +87 -28
  310. package/packages/dd-trace/src/appsec/rule_manager.js +4 -2
  311. package/packages/dd-trace/src/appsec/sdk/index.js +4 -0
  312. package/packages/dd-trace/src/appsec/sdk/set_user.js +1 -1
  313. package/packages/dd-trace/src/appsec/sdk/track_event.js +5 -5
  314. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +7 -11
  315. package/packages/dd-trace/src/appsec/sdk/utils.js +5 -3
  316. package/packages/dd-trace/src/appsec/store.js +50 -0
  317. package/packages/dd-trace/src/appsec/telemetry/api_security.js +34 -0
  318. package/packages/dd-trace/src/appsec/telemetry/index.js +27 -1
  319. package/packages/dd-trace/src/appsec/user_tracking.js +5 -4
  320. package/packages/dd-trace/src/appsec/waf/index.js +19 -9
  321. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +35 -20
  322. package/packages/dd-trace/src/appsec/waf/waf_manager.js +1 -1
  323. package/packages/dd-trace/src/azure_metadata.js +17 -6
  324. package/packages/dd-trace/src/baggage.js +32 -13
  325. package/packages/dd-trace/src/bootstrap.js +39 -0
  326. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +36 -6
  327. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +122 -24
  328. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +22 -7
  329. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +5 -2
  330. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +2 -2
  331. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +2 -2
  332. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +6 -2
  333. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -2
  334. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +148 -25
  335. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +3 -4
  336. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +28 -10
  337. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +22 -0
  338. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +105 -22
  339. package/packages/dd-trace/src/ci-visibility/lage.js +2 -1
  340. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +4 -5
  341. package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +4 -5
  342. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +73 -55
  343. package/packages/dd-trace/src/ci-visibility/requests/request.js +14 -50
  344. package/packages/dd-trace/src/ci-visibility/requests/upload-coverage-report.js +4 -4
  345. package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +156 -0
  346. package/packages/dd-trace/src/ci-visibility/test-api-manual/test-api-manual-plugin.js +9 -3
  347. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +24 -6
  348. package/packages/dd-trace/src/ci-visibility/test-optimization-cache.js +70 -6
  349. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +128 -0
  350. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +291 -0
  351. package/packages/dd-trace/src/config/config-types.d.ts +8 -6
  352. package/packages/dd-trace/src/config/defaults.js +341 -144
  353. package/packages/dd-trace/src/config/generated-config-types.d.ts +679 -131
  354. package/packages/dd-trace/src/config/git_properties.js +2 -2
  355. package/packages/dd-trace/src/config/helper.js +183 -28
  356. package/packages/dd-trace/src/config/index.js +565 -1515
  357. package/packages/dd-trace/src/config/major-overrides.js +100 -0
  358. package/packages/dd-trace/src/config/normalize-service.js +31 -0
  359. package/packages/dd-trace/src/config/parsers.js +384 -0
  360. package/packages/dd-trace/src/config/remote_config.js +59 -2
  361. package/packages/dd-trace/src/config/supported-configurations.json +638 -530
  362. package/packages/dd-trace/src/constants.js +15 -0
  363. package/packages/dd-trace/src/crashtracking/crashtracker.js +25 -7
  364. package/packages/dd-trace/src/crashtracking/index.js +1 -7
  365. package/packages/dd-trace/src/datastreams/checkpointer.js +6 -12
  366. package/packages/dd-trace/src/datastreams/context.js +4 -2
  367. package/packages/dd-trace/src/datastreams/encoding.js +39 -28
  368. package/packages/dd-trace/src/datastreams/index.js +2 -1
  369. package/packages/dd-trace/src/datastreams/manager.js +1 -1
  370. package/packages/dd-trace/src/datastreams/pathway.js +35 -30
  371. package/packages/dd-trace/src/datastreams/processor.js +31 -22
  372. package/packages/dd-trace/src/datastreams/size.js +6 -2
  373. package/packages/dd-trace/src/datastreams/writer.js +15 -6
  374. package/packages/dd-trace/src/debugger/config.js +9 -4
  375. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +49 -35
  376. package/packages/dd-trace/src/debugger/devtools_client/condition.js +5 -8
  377. package/packages/dd-trace/src/debugger/devtools_client/config.js +3 -2
  378. package/packages/dd-trace/src/debugger/devtools_client/index.js +33 -71
  379. package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +83 -0
  380. package/packages/dd-trace/src/debugger/devtools_client/send.js +27 -6
  381. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +2 -2
  382. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +5 -2
  383. package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +1 -0
  384. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +1 -1
  385. package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
  386. package/packages/dd-trace/src/debugger/index.js +14 -10
  387. package/packages/dd-trace/src/debugger/probe_sampler.js +112 -0
  388. package/packages/dd-trace/src/debugger/probe_sampler_constants.js +19 -0
  389. package/packages/dd-trace/src/dogstatsd.js +45 -36
  390. package/packages/dd-trace/src/encode/0.4.js +830 -269
  391. package/packages/dd-trace/src/encode/0.5.js +158 -22
  392. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +141 -65
  393. package/packages/dd-trace/src/encode/agentless-json.js +12 -6
  394. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +52 -15
  395. package/packages/dd-trace/src/encode/span-stats.js +19 -16
  396. package/packages/dd-trace/src/encode/tags-processors.js +30 -25
  397. package/packages/dd-trace/src/exporter.js +3 -1
  398. package/packages/dd-trace/src/exporters/agent/index.js +4 -5
  399. package/packages/dd-trace/src/exporters/agent/writer.js +8 -3
  400. package/packages/dd-trace/src/exporters/agentless/index.js +12 -13
  401. package/packages/dd-trace/src/exporters/agentless/intake.js +43 -0
  402. package/packages/dd-trace/src/exporters/agentless/writer.js +12 -11
  403. package/packages/dd-trace/src/exporters/common/agents.js +3 -1
  404. package/packages/dd-trace/src/exporters/common/buffering-exporter.js +3 -3
  405. package/packages/dd-trace/src/exporters/common/request.js +55 -26
  406. package/packages/dd-trace/src/exporters/common/retry.js +104 -0
  407. package/packages/dd-trace/src/exporters/common/url.js +34 -0
  408. package/packages/dd-trace/src/exporters/common/util.js +2 -2
  409. package/packages/dd-trace/src/exporters/common/writer.js +29 -3
  410. package/packages/dd-trace/src/exporters/electron/index.js +49 -0
  411. package/packages/dd-trace/src/exporters/span-stats/index.js +1 -2
  412. package/packages/dd-trace/src/exporters/span-stats/writer.js +1 -3
  413. package/packages/dd-trace/src/external-logger/src/index.js +2 -1
  414. package/packages/dd-trace/src/feature-registry.js +22 -0
  415. package/packages/dd-trace/src/git_metadata.js +68 -0
  416. package/packages/dd-trace/src/git_metadata_tagger.js +13 -5
  417. package/packages/dd-trace/src/guardrails/index.js +11 -6
  418. package/packages/dd-trace/src/guardrails/telemetry.js +40 -3
  419. package/packages/dd-trace/src/heap_snapshots.js +7 -4
  420. package/packages/dd-trace/src/id.js +46 -27
  421. package/packages/dd-trace/src/index.js +6 -4
  422. package/packages/dd-trace/src/lambda/handler-paths.js +52 -0
  423. package/packages/dd-trace/src/lambda/handler.js +2 -6
  424. package/packages/dd-trace/src/lambda/index.js +62 -14
  425. package/packages/dd-trace/src/lambda/runtime/patch.js +21 -46
  426. package/packages/dd-trace/src/llmobs/constants/tags.js +13 -0
  427. package/packages/dd-trace/src/llmobs/index.js +41 -8
  428. package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +403 -0
  429. package/packages/dd-trace/src/llmobs/plugins/ai/index.js +8 -391
  430. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +178 -18
  431. package/packages/dd-trace/src/llmobs/plugins/ai/vercelTelemetry.js +363 -0
  432. package/packages/dd-trace/src/llmobs/plugins/{anthropic.js → anthropic/index.js} +32 -79
  433. package/packages/dd-trace/src/llmobs/plugins/anthropic/util.js +109 -0
  434. package/packages/dd-trace/src/llmobs/plugins/base.js +4 -4
  435. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +92 -38
  436. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +270 -0
  437. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +10 -0
  438. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +5 -1
  439. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +81 -16
  440. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +3 -2
  441. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +3 -2
  442. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/embedding.js +2 -1
  443. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +1 -50
  444. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/vectorstore.js +2 -1
  445. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +14 -8
  446. package/packages/dd-trace/src/llmobs/plugins/langchain/messages.js +76 -0
  447. package/packages/dd-trace/src/llmobs/plugins/langgraph/index.js +3 -28
  448. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +68 -0
  449. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +57 -0
  450. package/packages/dd-trace/src/llmobs/plugins/openai/index.js +21 -51
  451. package/packages/dd-trace/src/llmobs/sdk.js +66 -41
  452. package/packages/dd-trace/src/llmobs/span_processor.js +91 -12
  453. package/packages/dd-trace/src/llmobs/tagger.js +135 -7
  454. package/packages/dd-trace/src/llmobs/telemetry.js +31 -1
  455. package/packages/dd-trace/src/llmobs/util.js +202 -9
  456. package/packages/dd-trace/src/llmobs/writers/base.js +13 -5
  457. package/packages/dd-trace/src/llmobs/writers/spans.js +1 -1
  458. package/packages/dd-trace/src/llmobs/writers/util.js +4 -2
  459. package/packages/dd-trace/src/log/index.js +28 -69
  460. package/packages/dd-trace/src/log/writer.js +10 -20
  461. package/packages/dd-trace/src/msgpack/chunk.js +430 -11
  462. package/packages/dd-trace/src/msgpack/index.js +101 -2
  463. package/packages/dd-trace/src/noop/proxy.js +13 -4
  464. package/packages/dd-trace/src/noop/span.js +3 -1
  465. package/packages/dd-trace/src/openfeature/encoding.js +70 -0
  466. package/packages/dd-trace/src/openfeature/eval-metrics-hook.js +103 -0
  467. package/packages/dd-trace/src/openfeature/flagging_provider.js +26 -1
  468. package/packages/dd-trace/src/openfeature/noop.js +40 -36
  469. package/packages/dd-trace/src/openfeature/register.js +46 -0
  470. package/packages/dd-trace/src/openfeature/remote_config.js +6 -1
  471. package/packages/dd-trace/src/openfeature/span-enrichment-hook.js +143 -0
  472. package/packages/dd-trace/src/openfeature/span-enrichment.js +149 -0
  473. package/packages/dd-trace/src/openfeature/writers/base.js +3 -11
  474. package/packages/dd-trace/src/openfeature/writers/exposures.js +82 -70
  475. package/packages/dd-trace/src/openfeature/writers/util.js +1 -2
  476. package/packages/dd-trace/src/opentelemetry/active-span-proxy.js +42 -0
  477. package/packages/dd-trace/src/opentelemetry/bridge-span-base.js +107 -0
  478. package/packages/dd-trace/src/opentelemetry/context_manager.js +27 -13
  479. package/packages/dd-trace/src/opentelemetry/logs/index.js +7 -7
  480. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +3 -2
  481. package/packages/dd-trace/src/opentelemetry/metrics/index.js +62 -13
  482. package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +28 -14
  483. package/packages/dd-trace/src/opentelemetry/metrics/meter.js +7 -10
  484. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +3 -2
  485. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +40 -0
  486. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js +169 -0
  487. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +99 -5
  488. package/packages/dd-trace/src/opentelemetry/metrics/time.js +19 -0
  489. package/packages/dd-trace/src/opentelemetry/otlp/common.proto +2 -2
  490. package/packages/dd-trace/src/opentelemetry/otlp/logs.proto +1 -1
  491. package/packages/dd-trace/src/opentelemetry/otlp/logs_service.proto +1 -1
  492. package/packages/dd-trace/src/opentelemetry/otlp/metrics.proto +1 -1
  493. package/packages/dd-trace/src/opentelemetry/otlp/metrics_service.proto +1 -1
  494. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +56 -82
  495. package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +1 -2
  496. package/packages/dd-trace/src/opentelemetry/otlp/protobuf_loader.js +14 -2
  497. package/packages/dd-trace/src/opentelemetry/otlp/trace.proto +358 -0
  498. package/packages/dd-trace/src/opentelemetry/otlp/trace_service.proto +78 -0
  499. package/packages/dd-trace/src/opentelemetry/span-helpers.js +325 -0
  500. package/packages/dd-trace/src/opentelemetry/span.js +59 -109
  501. package/packages/dd-trace/src/opentelemetry/span_context.js +1 -0
  502. package/packages/dd-trace/src/opentelemetry/span_processor.js +7 -5
  503. package/packages/dd-trace/src/opentelemetry/trace/index.js +75 -0
  504. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +75 -0
  505. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +375 -0
  506. package/packages/dd-trace/src/opentelemetry/tracer.js +20 -69
  507. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +33 -17
  508. package/packages/dd-trace/src/opentracing/propagation/log.js +28 -8
  509. package/packages/dd-trace/src/opentracing/propagation/text_map.js +280 -145
  510. package/packages/dd-trace/src/opentracing/propagation/text_map_dsm.js +11 -11
  511. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +98 -32
  512. package/packages/dd-trace/src/opentracing/span.js +127 -73
  513. package/packages/dd-trace/src/opentracing/span_context.js +68 -3
  514. package/packages/dd-trace/src/opentracing/tracer.js +46 -19
  515. package/packages/dd-trace/src/payload-tagging/config/index.js +8 -7
  516. package/packages/dd-trace/src/plugin_manager.js +44 -20
  517. package/packages/dd-trace/src/plugins/apollo.js +3 -1
  518. package/packages/dd-trace/src/plugins/ci_plugin.js +391 -85
  519. package/packages/dd-trace/src/plugins/database.js +61 -18
  520. package/packages/dd-trace/src/plugins/index.js +14 -0
  521. package/packages/dd-trace/src/plugins/log_injection.js +56 -0
  522. package/packages/dd-trace/src/plugins/log_plugin.js +4 -44
  523. package/packages/dd-trace/src/plugins/outbound.js +1 -1
  524. package/packages/dd-trace/src/plugins/plugin.js +22 -28
  525. package/packages/dd-trace/src/plugins/storage.js +2 -2
  526. package/packages/dd-trace/src/plugins/tracing.js +70 -13
  527. package/packages/dd-trace/src/plugins/util/ci.js +127 -40
  528. package/packages/dd-trace/src/plugins/util/git-cache.js +23 -23
  529. package/packages/dd-trace/src/plugins/util/git.js +3 -1
  530. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +276 -0
  531. package/packages/dd-trace/src/plugins/util/llm.js +6 -1
  532. package/packages/dd-trace/src/plugins/util/stacktrace.js +2 -2
  533. package/packages/dd-trace/src/plugins/util/test.js +894 -65
  534. package/packages/dd-trace/src/plugins/util/url.js +71 -5
  535. package/packages/dd-trace/src/plugins/util/user-provided-git.js +18 -16
  536. package/packages/dd-trace/src/plugins/util/web.js +116 -180
  537. package/packages/dd-trace/src/priority_sampler.js +12 -21
  538. package/packages/dd-trace/src/process-tags/index.js +3 -0
  539. package/packages/dd-trace/src/profiler.js +27 -2
  540. package/packages/dd-trace/src/profiling/config.js +145 -393
  541. package/packages/dd-trace/src/profiling/constants.js +4 -7
  542. package/packages/dd-trace/src/profiling/exporter_cli.js +10 -13
  543. package/packages/dd-trace/src/profiling/exporters/agent.js +61 -28
  544. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +50 -15
  545. package/packages/dd-trace/src/profiling/exporters/file.js +16 -5
  546. package/packages/dd-trace/src/profiling/oom.js +71 -0
  547. package/packages/dd-trace/src/profiling/profiler.js +123 -132
  548. package/packages/dd-trace/src/profiling/profilers/event_plugins/crypto.js +32 -0
  549. package/packages/dd-trace/src/profiling/profilers/event_plugins/zlib.js +19 -0
  550. package/packages/dd-trace/src/profiling/profilers/events.js +57 -14
  551. package/packages/dd-trace/src/profiling/profilers/space.js +27 -16
  552. package/packages/dd-trace/src/profiling/profilers/wall.js +136 -39
  553. package/packages/dd-trace/src/profiling/ssi-heuristics.js +7 -4
  554. package/packages/dd-trace/src/propagation-hash/index.js +3 -2
  555. package/packages/dd-trace/src/proxy.js +82 -39
  556. package/packages/dd-trace/src/rate_limiter.js +1 -1
  557. package/packages/dd-trace/src/remote_config/index.js +9 -5
  558. package/packages/dd-trace/src/remote_config/scheduler.js +1 -1
  559. package/packages/dd-trace/src/require-package-json.js +8 -4
  560. package/packages/dd-trace/src/ritm.js +63 -28
  561. package/packages/dd-trace/src/runtime_metrics/client.js +30 -0
  562. package/packages/dd-trace/src/runtime_metrics/index.js +17 -4
  563. package/packages/dd-trace/src/runtime_metrics/otlp_runtime_metrics.js +284 -0
  564. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +45 -41
  565. package/packages/dd-trace/src/sampler.js +1 -1
  566. package/packages/dd-trace/src/sampling_rule.js +7 -7
  567. package/packages/dd-trace/src/scope.js +10 -15
  568. package/packages/dd-trace/src/serverless.js +6 -7
  569. package/packages/dd-trace/src/service-naming/extra-services.js +14 -0
  570. package/packages/dd-trace/src/service-naming/index.js +1 -1
  571. package/packages/dd-trace/src/service-naming/schemas/definition.js +4 -1
  572. package/packages/dd-trace/src/service-naming/schemas/util.js +48 -3
  573. package/packages/dd-trace/src/service-naming/schemas/v0/graphql.js +6 -0
  574. package/packages/dd-trace/src/service-naming/schemas/v0/messaging.js +61 -2
  575. package/packages/dd-trace/src/service-naming/schemas/v0/serverless.js +12 -0
  576. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +60 -0
  577. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +25 -1
  578. package/packages/dd-trace/src/service-naming/schemas/v0/websocket.js +5 -0
  579. package/packages/dd-trace/src/service-naming/schemas/v1/graphql.js +8 -0
  580. package/packages/dd-trace/src/service-naming/schemas/v1/messaging.js +32 -0
  581. package/packages/dd-trace/src/service-naming/schemas/v1/serverless.js +12 -0
  582. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +17 -0
  583. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +23 -3
  584. package/packages/dd-trace/src/service-naming/schemas/v1/websocket.js +6 -0
  585. package/packages/dd-trace/src/service-naming/source-resolver.js +50 -0
  586. package/packages/dd-trace/src/span_format.js +269 -81
  587. package/packages/dd-trace/src/span_processor.js +13 -13
  588. package/packages/dd-trace/src/span_stats.js +101 -79
  589. package/packages/dd-trace/src/spanleak.js +1 -2
  590. package/packages/dd-trace/src/standalone/index.js +6 -25
  591. package/packages/dd-trace/src/startup-log.js +3 -3
  592. package/packages/dd-trace/src/tagger.js +2 -4
  593. package/packages/dd-trace/src/telemetry/dependencies.js +2 -2
  594. package/packages/dd-trace/src/telemetry/endpoints.js +7 -5
  595. package/packages/dd-trace/src/telemetry/index.js +2 -3
  596. package/packages/dd-trace/src/telemetry/logs/index.js +1 -1
  597. package/packages/dd-trace/src/telemetry/send-data.js +25 -39
  598. package/packages/dd-trace/src/telemetry/session-propagation.js +20 -45
  599. package/packages/dd-trace/src/telemetry/telemetry.js +42 -183
  600. package/packages/dd-trace/src/tracer.js +23 -9
  601. package/packages/dd-trace/src/tracer_metadata.js +1 -1
  602. package/packages/dd-trace/src/util.js +31 -9
  603. package/register.js +58 -1
  604. package/vendor/dist/@apm-js-collab/code-transformer/index.js +94 -42
  605. package/vendor/dist/@datadog/sketches-js/LICENSE +10 -36
  606. package/vendor/dist/@datadog/sketches-js/index.js +1 -1
  607. package/vendor/dist/pprof-format/index.js +1 -1
  608. package/vendor/dist/protobufjs/index.js +1 -1
  609. package/vendor/dist/protobufjs/minimal/index.js +1 -1
  610. package/vendor/dist/shell-quote/index.js +1 -1
  611. package/packages/datadog-plugin-graphql/src/resolve.js +0 -178
  612. package/packages/dd-trace/src/agent/url.js +0 -28
  613. package/packages/dd-trace/src/appsec/api_security_sampler.js +0 -117
  614. package/packages/dd-trace/src/lambda/runtime/ritm.js +0 -133
  615. package/packages/dd-trace/src/log/utils.js +0 -16
  616. package/packages/dd-trace/src/msgpack/encoder.js +0 -308
  617. package/packages/dd-trace/src/plugins/structured_log_plugin.js +0 -9
  618. package/scripts/preinstall.js +0 -34
  619. package/vendor/dist/ignore/LICENSE +0 -21
  620. package/vendor/dist/ignore/index.js +0 -1
  621. package/vendor/dist/opentracing/LICENSE +0 -201
  622. package/vendor/dist/opentracing/binary_carrier.d.ts +0 -11
  623. package/vendor/dist/opentracing/constants.d.ts +0 -61
  624. package/vendor/dist/opentracing/examples/demo/demo.d.ts +0 -2
  625. package/vendor/dist/opentracing/ext/tags.d.ts +0 -90
  626. package/vendor/dist/opentracing/functions.d.ts +0 -20
  627. package/vendor/dist/opentracing/global_tracer.d.ts +0 -14
  628. package/vendor/dist/opentracing/index.d.ts +0 -12
  629. package/vendor/dist/opentracing/index.js +0 -1
  630. package/vendor/dist/opentracing/mock_tracer/index.d.ts +0 -5
  631. package/vendor/dist/opentracing/mock_tracer/mock_context.d.ts +0 -13
  632. package/vendor/dist/opentracing/mock_tracer/mock_report.d.ts +0 -16
  633. package/vendor/dist/opentracing/mock_tracer/mock_span.d.ts +0 -50
  634. package/vendor/dist/opentracing/mock_tracer/mock_tracer.d.ts +0 -26
  635. package/vendor/dist/opentracing/noop.d.ts +0 -8
  636. package/vendor/dist/opentracing/reference.d.ts +0 -33
  637. package/vendor/dist/opentracing/span.d.ts +0 -147
  638. package/vendor/dist/opentracing/span_context.d.ts +0 -26
  639. package/vendor/dist/opentracing/test/api_compatibility.d.ts +0 -16
  640. package/vendor/dist/opentracing/test/mocktracer_implemenation.d.ts +0 -3
  641. package/vendor/dist/opentracing/test/noop_implementation.d.ts +0 -4
  642. package/vendor/dist/opentracing/test/opentracing_api.d.ts +0 -3
  643. package/vendor/dist/opentracing/test/unittest.d.ts +0 -2
  644. package/vendor/dist/opentracing/tracer.d.ts +0 -127
  645. package/vendor/dist/path-to-regexp/LICENSE +0 -21
  646. package/vendor/dist/path-to-regexp/index.js +0 -1
@@ -1,1264 +1,17 @@
1
1
  'use strict'
2
- const path = require('node:path')
3
2
 
4
- const shimmer = require('../../datadog-shimmer')
5
- const log = require('../../dd-trace/src/log')
6
- const {
7
- VITEST_WORKER_TRACE_PAYLOAD_CODE,
8
- VITEST_WORKER_LOGS_PAYLOAD_CODE,
9
- DYNAMIC_NAME_RE,
10
- collectDynamicNamesFromTraces,
11
- logDynamicNamesWarning,
12
- } = require('../../dd-trace/src/plugins/util/test')
13
- const { addHook, channel } = require('./helpers/instrument')
3
+ const { getEnvironmentVariable } = require('../../dd-trace/src/config/helper')
4
+ const { isTrue } = require('../../dd-trace/src/util')
14
5
 
15
- // test hooks
16
- const testStartCh = channel('ci:vitest:test:start')
17
- const testFinishTimeCh = channel('ci:vitest:test:finish-time')
18
- const testPassCh = channel('ci:vitest:test:pass')
19
- const testErrorCh = channel('ci:vitest:test:error')
20
- const testSkipCh = channel('ci:vitest:test:skip')
21
- const isNewTestCh = channel('ci:vitest:test:is-new')
22
- const isAttemptToFixCh = channel('ci:vitest:test:is-attempt-to-fix')
23
- const isDisabledCh = channel('ci:vitest:test:is-disabled')
24
- const isQuarantinedCh = channel('ci:vitest:test:is-quarantined')
25
- const isModifiedCh = channel('ci:vitest:test:is-modified')
26
- const testFnCh = channel('ci:vitest:test:fn')
6
+ const VITEST_NO_WORKER_INIT_ACTIVE_ENV = 'DD_TEST_OPT_VITEST_NO_WORKER_INIT_ACTIVE'
27
7
 
28
- // test suite hooks
29
- const testSuiteStartCh = channel('ci:vitest:test-suite:start')
30
- const testSuiteFinishCh = channel('ci:vitest:test-suite:finish')
31
- const testSuiteErrorCh = channel('ci:vitest:test-suite:error')
8
+ if (getEnvironmentVariable('DD_VITEST_WORKER') === '1') {
9
+ // In no-worker-init mode the main process reports Vitest events from reporter hooks.
10
+ // Loading worker instrumentation here would reintroduce the worker tracer path.
11
+ // eslint-disable-next-line eslint-rules/eslint-process-env
12
+ if (isTrue(process.env[VITEST_NO_WORKER_INIT_ACTIVE_ENV])) return
32
13
 
33
- // test session hooks
34
- const testSessionStartCh = channel('ci:vitest:session:start')
35
- const testSessionFinishCh = channel('ci:vitest:session:finish')
36
- const libraryConfigurationCh = channel('ci:vitest:library-configuration')
37
- const knownTestsCh = channel('ci:vitest:known-tests')
38
- const isEarlyFlakeDetectionFaultyCh = channel('ci:vitest:is-early-flake-detection-faulty')
39
- const testManagementTestsCh = channel('ci:vitest:test-management-tests')
40
- const modifiedFilesCh = channel('ci:vitest:modified-files')
41
-
42
- const workerReportTraceCh = channel('ci:vitest:worker-report:trace')
43
- const workerReportLogsCh = channel('ci:vitest:worker-report:logs')
44
- const codeCoverageReportCh = channel('ci:vitest:coverage-report')
45
-
46
- const taskToCtx = new WeakMap()
47
- const taskToStatuses = new WeakMap()
48
- const originalHookFns = new WeakMap()
49
- const newTasks = new WeakSet()
50
- const dynamicNameTasks = new WeakSet()
51
- const newTestsWithDynamicNames = new Set()
52
- const disabledTasks = new WeakSet()
53
- const quarantinedTasks = new WeakSet()
54
- const attemptToFixTasks = new WeakSet()
55
- const modifiedTasks = new WeakSet()
56
- let isRetryReasonEfd = false
57
- let isRetryReasonAttemptToFix = false
58
- const switchedStatuses = new WeakSet()
59
- const workerProcesses = new WeakSet()
60
- let isFlakyTestRetriesEnabled = false
61
- let flakyTestRetriesCount = 0
62
- let isEarlyFlakeDetectionEnabled = false
63
- let earlyFlakeDetectionNumRetries = 0
64
- let isEarlyFlakeDetectionFaulty = false
65
- let isKnownTestsEnabled = false
66
- let isTestManagementTestsEnabled = false
67
- let isImpactedTestsEnabled = false
68
- let vitestGetFn = null
69
- let vitestSetFn = null
70
- let vitestGetHooks = null
71
- let testManagementAttemptToFixRetries = 0
72
- let isDiEnabled = false
73
- let testCodeCoverageLinesTotal
74
- let coverageRootDir
75
- let isSessionStarted = false
76
- let vitestPool = null
77
-
78
- const BREAKPOINT_HIT_GRACE_PERIOD_MS = 400
79
-
80
- function getTestCommand () {
81
- return `vitest ${process.argv.slice(2).join(' ')}`
82
- }
83
-
84
- function waitForHitProbe () {
85
- return new Promise(resolve => {
86
- setTimeout(() => {
87
- resolve()
88
- }, BREAKPOINT_HIT_GRACE_PERIOD_MS)
89
- })
90
- }
91
-
92
- function isValidKnownTests (receivedKnownTests) {
93
- return !!receivedKnownTests.vitest
94
- }
95
-
96
- function getProvidedContext () {
97
- try {
98
- const {
99
- _ddIsEarlyFlakeDetectionEnabled,
100
- _ddIsDiEnabled,
101
- _ddKnownTests: knownTests,
102
- _ddEarlyFlakeDetectionNumRetries: numRepeats,
103
- _ddIsKnownTestsEnabled: isKnownTestsEnabled,
104
- _ddIsTestManagementTestsEnabled: isTestManagementTestsEnabled,
105
- _ddTestManagementAttemptToFixRetries: testManagementAttemptToFixRetries,
106
- _ddTestManagementTests: testManagementTests,
107
- _ddIsFlakyTestRetriesEnabled: isFlakyTestRetriesEnabled,
108
- _ddFlakyTestRetriesCount: flakyTestRetriesCount,
109
- _ddIsImpactedTestsEnabled: isImpactedTestsEnabled,
110
- _ddModifiedFiles: modifiedFiles,
111
- } = globalThis.__vitest_worker__.providedContext
112
-
113
- return {
114
- isDiEnabled: _ddIsDiEnabled,
115
- isEarlyFlakeDetectionEnabled: _ddIsEarlyFlakeDetectionEnabled,
116
- knownTests,
117
- numRepeats,
118
- isKnownTestsEnabled,
119
- isTestManagementTestsEnabled,
120
- testManagementAttemptToFixRetries,
121
- testManagementTests,
122
- isFlakyTestRetriesEnabled,
123
- flakyTestRetriesCount: flakyTestRetriesCount ?? 0,
124
- isImpactedTestsEnabled,
125
- modifiedFiles,
126
- }
127
- } catch {
128
- log.error('Vitest workers could not parse provided context, so some features will not work.')
129
- return {
130
- isDiEnabled: false,
131
- isEarlyFlakeDetectionEnabled: false,
132
- knownTests: {},
133
- numRepeats: 0,
134
- isKnownTestsEnabled: false,
135
- isTestManagementTestsEnabled: false,
136
- testManagementAttemptToFixRetries: 0,
137
- testManagementTests: {},
138
- isFlakyTestRetriesEnabled: false,
139
- flakyTestRetriesCount: 0,
140
- isImpactedTestsEnabled: false,
141
- modifiedFiles: {},
142
- }
143
- }
144
- }
145
-
146
- function isReporterPackage (vitestPackage) {
147
- return vitestPackage.B?.name === 'BaseSequencer'
148
- }
149
-
150
- // from 2.0.0
151
- function isReporterPackageNew (vitestPackage) {
152
- return vitestPackage.e?.name === 'BaseSequencer'
153
- }
154
-
155
- function isReporterPackageNewest (vitestPackage) {
156
- return vitestPackage.h?.name === 'BaseSequencer'
157
- }
158
-
159
- /**
160
- * Finds an export by its `.name` property in a minified vitest chunk.
161
- * Minified export keys change across versions, so we search by function/class name.
162
- * @param {object} pkg - The module exports object
163
- * @param {string} name - The `.name` value to look for
164
- * @returns {{ key: string, value: Function } | undefined}
165
- */
166
- function findExportByName (pkg, name) {
167
- for (const [key, value] of Object.entries(pkg)) {
168
- if (value?.name === name) {
169
- return { key, value }
170
- }
171
- }
172
- }
173
-
174
- function getBaseSequencerExport (vitestPackage) {
175
- return findExportByName(vitestPackage, 'BaseSequencer')
176
- }
177
-
178
- function getChannelPromise (channelToPublishTo, frameworkVersion) {
179
- return new Promise(resolve => {
180
- channelToPublishTo.publish({ onDone: resolve, frameworkVersion })
181
- })
182
- }
183
-
184
- function isCliApiPackage (vitestPackage) {
185
- return !!findExportByName(vitestPackage, 'startVitest')
186
- }
187
-
188
- function getTestRunnerExport (testPackage) {
189
- return findExportByName(testPackage, 'VitestTestRunner') || findExportByName(testPackage, 'TestRunner')
190
- }
191
-
192
- function getForksPoolWorkerExport (vitestPackage) {
193
- return findExportByName(vitestPackage, 'ForksPoolWorker')
194
- }
195
-
196
- function getThreadsPoolWorkerExport (vitestPackage) {
197
- return findExportByName(vitestPackage, 'ThreadsPoolWorker')
198
- }
199
-
200
- function getSessionStatus (state) {
201
- if (state.getCountOfFailedTests() > 0) {
202
- return 'fail'
203
- }
204
- if (state.pathsSet.size === 0) {
205
- return 'skip'
206
- }
207
- return 'pass'
208
- }
209
-
210
- // From https://github.com/vitest-dev/vitest/blob/51c04e2f44d91322b334f8ccbcdb368facc3f8ec/packages/runner/src/run.ts#L243-L250
211
- function getVitestTestStatus (test, retryCount) {
212
- if (test.result.state !== 'fail') {
213
- if (!test.repeats) {
214
- return 'pass'
215
- } else if (test.repeats && (test.retry ?? 0) === retryCount) {
216
- return 'pass'
217
- }
218
- }
219
- return 'fail'
220
- }
221
-
222
- function getTypeTasks (fileTasks, type = 'test') {
223
- const typeTasks = []
224
-
225
- function getTasks (tasks) {
226
- for (const task of tasks) {
227
- if (task.type === type) {
228
- typeTasks.push(task)
229
- } else if (task.tasks) {
230
- getTasks(task.tasks)
231
- }
232
- }
233
- }
234
-
235
- getTasks(fileTasks)
236
-
237
- return typeTasks
238
- }
239
-
240
- function getTestName (task) {
241
- let testName = task.name
242
- let currentTask = task.suite
243
-
244
- while (currentTask) {
245
- if (currentTask.name) {
246
- testName = `${currentTask.name} ${testName}`
247
- }
248
- currentTask = currentTask.suite
249
- }
250
-
251
- return testName
252
- }
253
-
254
- /**
255
- * Wraps a function so it runs inside the current test span context.
256
- * @param {object} task
257
- * @param {Function} fn
258
- * @returns {Function}
259
- */
260
- function wrapTestScopedFn (task, fn) {
261
- return shimmer.wrapFunction(fn, fn => function () {
262
- return testFnCh.runStores(taskToCtx.get(task), () => fn.apply(this, arguments))
263
- })
264
- }
265
-
266
- /**
267
- * Wraps a `beforeEach` cleanup callback so it inherits the test span context.
268
- * Vitest allows `beforeEach` to return a cleanup function, including via a promise.
269
- * @param {object} task
270
- * @param {unknown} result
271
- * @returns {unknown}
272
- */
273
- function wrapBeforeEachCleanupResult (task, result) {
274
- if (typeof result === 'function') {
275
- return wrapTestScopedFn(task, result)
276
- }
277
-
278
- if (result && typeof result.then === 'function') {
279
- return result.then(cleanupFn => wrapBeforeEachCleanupResult(task, cleanupFn))
280
- }
281
-
282
- return result
283
- }
284
-
285
- function getSortWrapper (sort, frameworkVersion) {
286
- return async function () {
287
- if (!testSessionFinishCh.hasSubscribers) {
288
- return sort.apply(this, arguments)
289
- }
290
- // There isn't any other async function that we seem to be able to hook into
291
- // So we will use the sort from BaseSequencer. This means that a custom sequencer
292
- // will not work. This will be a known limitation.
293
-
294
- try {
295
- const { err, libraryConfig } = await getChannelPromise(libraryConfigurationCh, frameworkVersion)
296
- if (!err) {
297
- isFlakyTestRetriesEnabled = libraryConfig.isFlakyTestRetriesEnabled
298
- flakyTestRetriesCount = libraryConfig.flakyTestRetriesCount
299
- isEarlyFlakeDetectionEnabled = libraryConfig.isEarlyFlakeDetectionEnabled
300
- earlyFlakeDetectionNumRetries = libraryConfig.earlyFlakeDetectionNumRetries
301
- isDiEnabled = libraryConfig.isDiEnabled
302
- isKnownTestsEnabled = libraryConfig.isKnownTestsEnabled
303
- isTestManagementTestsEnabled = libraryConfig.isTestManagementEnabled
304
- testManagementAttemptToFixRetries = libraryConfig.testManagementAttemptToFixRetries
305
- isImpactedTestsEnabled = libraryConfig.isImpactedTestsEnabled
306
- }
307
- } catch {
308
- isFlakyTestRetriesEnabled = false
309
- isEarlyFlakeDetectionEnabled = false
310
- isDiEnabled = false
311
- isKnownTestsEnabled = false
312
- isImpactedTestsEnabled = false
313
- }
314
-
315
- if (isFlakyTestRetriesEnabled && !this.ctx.config.retry && flakyTestRetriesCount > 0) {
316
- this.ctx.config.retry = flakyTestRetriesCount
317
- try {
318
- const workspaceProject = this.ctx.getCoreWorkspaceProject
319
- ? this.ctx.getCoreWorkspaceProject()
320
- : this.ctx.getRootProject()
321
- workspaceProject._provided._ddIsFlakyTestRetriesEnabled = isFlakyTestRetriesEnabled
322
- workspaceProject._provided._ddFlakyTestRetriesCount = flakyTestRetriesCount
323
- } catch {
324
- log.warn('Could not send library configuration to workers.')
325
- }
326
- }
327
-
328
- if (isKnownTestsEnabled) {
329
- const knownTestsResponse = await getChannelPromise(knownTestsCh)
330
- if (knownTestsResponse.err) {
331
- isEarlyFlakeDetectionEnabled = false
332
- } else {
333
- const knownTests = knownTestsResponse.knownTests
334
- const getFilePaths = this.ctx.getTestFilepaths || this.ctx._globTestFilepaths
335
-
336
- const testFilepaths = await getFilePaths.call(this.ctx)
337
-
338
- if (isValidKnownTests(knownTests)) {
339
- isEarlyFlakeDetectionFaultyCh.publish({
340
- knownTests: knownTests.vitest,
341
- testFilepaths,
342
- onDone: (isFaulty) => {
343
- isEarlyFlakeDetectionFaulty = isFaulty
344
- },
345
- })
346
- if (isEarlyFlakeDetectionFaulty) {
347
- isEarlyFlakeDetectionEnabled = false
348
- log.warn('New test detection is disabled because the number of new tests is too high.')
349
- } else {
350
- // TODO: use this to pass session and module IDs to the worker, instead of polluting process.env
351
- // Note: setting this.ctx.config.provide directly does not work because it's cached
352
- try {
353
- const workspaceProject = this.ctx.getCoreWorkspaceProject
354
- ? this.ctx.getCoreWorkspaceProject()
355
- : this.ctx.getRootProject()
356
- workspaceProject._provided._ddIsKnownTestsEnabled = isKnownTestsEnabled
357
- workspaceProject._provided._ddKnownTests = knownTests
358
- workspaceProject._provided._ddIsEarlyFlakeDetectionEnabled = isEarlyFlakeDetectionEnabled
359
- workspaceProject._provided._ddEarlyFlakeDetectionNumRetries = earlyFlakeDetectionNumRetries
360
- } catch {
361
- log.warn('Could not send known tests to workers so Early Flake Detection will not work.')
362
- }
363
- }
364
- } else {
365
- isEarlyFlakeDetectionFaulty = true
366
- isEarlyFlakeDetectionEnabled = false
367
- }
368
- }
369
- }
370
-
371
- if (isDiEnabled) {
372
- try {
373
- const workspaceProject = this.ctx.getCoreWorkspaceProject
374
- ? this.ctx.getCoreWorkspaceProject()
375
- : this.ctx.getRootProject()
376
- workspaceProject._provided._ddIsDiEnabled = isDiEnabled
377
- } catch {
378
- log.warn('Could not send Dynamic Instrumentation configuration to workers.')
379
- }
380
- }
381
-
382
- if (isTestManagementTestsEnabled) {
383
- const { err, testManagementTests: receivedTestManagementTests } = await getChannelPromise(testManagementTestsCh)
384
- if (err) {
385
- isTestManagementTestsEnabled = false
386
- log.error('Could not get test management tests.')
387
- } else {
388
- const testManagementTests = receivedTestManagementTests
389
- try {
390
- const workspaceProject = this.ctx.getCoreWorkspaceProject
391
- ? this.ctx.getCoreWorkspaceProject()
392
- : this.ctx.getRootProject()
393
- workspaceProject._provided._ddIsTestManagementTestsEnabled = isTestManagementTestsEnabled
394
- workspaceProject._provided._ddTestManagementAttemptToFixRetries = testManagementAttemptToFixRetries
395
- workspaceProject._provided._ddTestManagementTests = testManagementTests
396
- } catch {
397
- log.warn('Could not send test management tests to workers so Test Management will not work.')
398
- }
399
- }
400
- }
401
-
402
- if (isImpactedTestsEnabled) {
403
- const { err, modifiedFiles } = await getChannelPromise(modifiedFilesCh)
404
- if (err) {
405
- log.error('Could not get modified tests.')
406
- } else {
407
- try {
408
- const workspaceProject = this.ctx.getCoreWorkspaceProject
409
- ? this.ctx.getCoreWorkspaceProject()
410
- : this.ctx.getRootProject()
411
- workspaceProject._provided._ddIsImpactedTestsEnabled = isImpactedTestsEnabled
412
- workspaceProject._provided._ddModifiedFiles = modifiedFiles
413
- } catch {
414
- log.warn('Could not send modified tests to workers so Impacted Tests will not work.')
415
- }
416
- }
417
- }
418
-
419
- if (this.ctx.coverageProvider?.generateCoverage) {
420
- // Capture coverage root directory from config (default is 'coverage' in cwd)
421
- try {
422
- const coverageConfig = this.ctx.config?.coverage
423
- const reportsDirectory = coverageConfig?.reportsDirectory || 'coverage'
424
- const rootDir = this.ctx.config?.root || process.cwd()
425
- coverageRootDir = path.isAbsolute(reportsDirectory) ? reportsDirectory : path.join(rootDir, reportsDirectory)
426
- } catch {
427
- // Fallback to cwd if we can't get config
428
- coverageRootDir = process.cwd()
429
- }
430
-
431
- shimmer.wrap(this.ctx.coverageProvider, 'generateCoverage', generateCoverage => async function () {
432
- const totalCodeCoverage = await generateCoverage.apply(this, arguments)
433
-
434
- try {
435
- testCodeCoverageLinesTotal = totalCodeCoverage.getCoverageSummary().lines.pct
436
- } catch {
437
- // ignore errors
438
- }
439
- return totalCodeCoverage
440
- })
441
- }
442
-
443
- shimmer.wrap(this.ctx, 'exit', getFinishWrapper)
444
- shimmer.wrap(this.ctx, 'close', getFinishWrapper)
445
-
446
- return sort.apply(this, arguments)
447
- }
448
- }
449
-
450
- function getFinishWrapper (exitOrClose) {
451
- let isClosed = false
452
- return async function () {
453
- if (isClosed) { // needed because exit calls close
454
- return exitOrClose.apply(this, arguments)
455
- }
456
- isClosed = true
457
- let onFinish
458
-
459
- const flushPromise = new Promise(resolve => {
460
- onFinish = resolve
461
- })
462
- const failedSuites = this.state.getFailedFilepaths()
463
- let error
464
- if (failedSuites.length) {
465
- error = new Error(`Test suites failed: ${failedSuites.length}.`)
466
- }
467
-
468
- testSessionFinishCh.publish({
469
- status: getSessionStatus(this.state),
470
- testCodeCoverageLinesTotal,
471
- error,
472
- isEarlyFlakeDetectionEnabled,
473
- isEarlyFlakeDetectionFaulty,
474
- isTestManagementTestsEnabled,
475
- vitestPool,
476
- onFinish,
477
- })
478
-
479
- logDynamicNamesWarning(newTestsWithDynamicNames)
480
-
481
- await flushPromise
482
-
483
- // If coverage was generated, publish coverage report channel for upload
484
- if (coverageRootDir && codeCoverageReportCh.hasSubscribers) {
485
- await new Promise((resolve) => {
486
- codeCoverageReportCh.publish({ rootDir: coverageRootDir, onDone: resolve })
487
- })
488
- }
489
-
490
- return exitOrClose.apply(this, arguments)
491
- }
492
- }
493
-
494
- function getCliOrStartVitestWrapper (frameworkVersion) {
495
- return function (oldCliOrStartVitest) {
496
- return function () {
497
- if (!testSessionStartCh.hasSubscribers || isSessionStarted) {
498
- return oldCliOrStartVitest.apply(this, arguments)
499
- }
500
- isSessionStarted = true
501
- testSessionStartCh.publish({ command: getTestCommand(), frameworkVersion })
502
- return oldCliOrStartVitest.apply(this, arguments)
503
- }
504
- }
505
- }
506
-
507
- function getCreateCliWrapper (vitestPackage, frameworkVersion) {
508
- const createCliExport = findExportByName(vitestPackage, 'createCLI')
509
- if (!createCliExport) {
510
- return vitestPackage
511
- }
512
- shimmer.wrap(vitestPackage, createCliExport.key, getCliOrStartVitestWrapper(frameworkVersion))
513
-
514
- return vitestPackage
515
- }
516
-
517
- function threadHandler (thread) {
518
- const { runtime } = thread
519
- let workerProcess
520
- if (runtime === 'child_process') {
521
- vitestPool = 'child_process'
522
- workerProcess = thread.process
523
- } else if (runtime === 'worker_threads') {
524
- vitestPool = 'worker_threads'
525
- workerProcess = thread.thread
526
- } else {
527
- vitestPool = 'unknown'
528
- }
529
- if (!workerProcess) {
530
- log.error('Vitest error: could not get process or thread from TinyPool#run')
531
- return
532
- }
533
-
534
- if (workerProcesses.has(workerProcess)) {
535
- return
536
- }
537
- workerProcesses.add(workerProcess)
538
- workerProcess.on('message', (message) => {
539
- if (message.__tinypool_worker_message__ && message.data) {
540
- if (message.interprocessCode === VITEST_WORKER_TRACE_PAYLOAD_CODE) {
541
- collectDynamicNamesFromTraces(message.data, newTestsWithDynamicNames)
542
- workerReportTraceCh.publish(message.data)
543
- } else if (message.interprocessCode === VITEST_WORKER_LOGS_PAYLOAD_CODE) {
544
- workerReportLogsCh.publish(message.data)
545
- }
546
- }
547
- })
548
- }
549
-
550
- function wrapTinyPoolRun (TinyPool) {
551
- shimmer.wrap(TinyPool.prototype, 'run', run => async function () {
552
- // We have to do this before and after because the threads list gets recycled, that is, the processes are re-created
553
- // eslint-disable-next-line unicorn/no-array-for-each
554
- this.threads.forEach(threadHandler)
555
- const runResult = await run.apply(this, arguments)
556
- // eslint-disable-next-line unicorn/no-array-for-each
557
- this.threads.forEach(threadHandler)
558
- return runResult
559
- })
560
- }
561
-
562
- addHook({
563
- name: 'tinypool',
564
- // version from tinypool@0.8 was used in vitest@1.6.0
565
- versions: ['>=0.8.0'],
566
- }, (TinyPool) => {
567
- wrapTinyPoolRun(TinyPool)
568
- return TinyPool
569
- })
570
-
571
- function getWrappedOn (on) {
572
- return function (event, callback) {
573
- if (event !== 'message') {
574
- return on.apply(this, arguments)
575
- }
576
- // `arguments[1]` is the callback function, which
577
- // we modify to intercept our messages to not interfere
578
- // with vitest's own messages
579
- arguments[1] = shimmer.wrapFunction(callback, callback => function (message) {
580
- if (message.type !== 'Buffer' && Array.isArray(message)) {
581
- const [interprocessCode, data] = message
582
- if (interprocessCode === VITEST_WORKER_TRACE_PAYLOAD_CODE) {
583
- collectDynamicNamesFromTraces(data, newTestsWithDynamicNames)
584
- workerReportTraceCh.publish(data)
585
- } else if (interprocessCode === VITEST_WORKER_LOGS_PAYLOAD_CODE) {
586
- workerReportLogsCh.publish(data)
587
- }
588
- // If we execute the callback vitest crashes, as the message is not supported
589
- return
590
- }
591
- return callback.apply(this, arguments)
592
- })
593
- return on.apply(this, arguments)
594
- }
595
- }
596
-
597
- function getStartVitestWrapper (cliApiPackage, frameworkVersion) {
598
- if (!isCliApiPackage(cliApiPackage)) {
599
- return cliApiPackage
600
- }
601
- const startVitestExport = findExportByName(cliApiPackage, 'startVitest')
602
- shimmer.wrap(cliApiPackage, startVitestExport.key, getCliOrStartVitestWrapper(frameworkVersion))
603
-
604
- const forksPoolWorker = getForksPoolWorkerExport(cliApiPackage)
605
- if (forksPoolWorker) {
606
- // function is async
607
- shimmer.wrap(forksPoolWorker.value.prototype, 'start', start => function () {
608
- vitestPool = 'child_process'
609
- this.env.DD_VITEST_WORKER = '1'
610
-
611
- return start.apply(this, arguments)
612
- })
613
- shimmer.wrap(forksPoolWorker.value.prototype, 'on', getWrappedOn)
614
- }
615
-
616
- const threadsPoolWorker = getThreadsPoolWorkerExport(cliApiPackage)
617
- if (threadsPoolWorker) {
618
- // function is async
619
- shimmer.wrap(threadsPoolWorker.value.prototype, 'start', start => function () {
620
- vitestPool = 'worker_threads'
621
- this.env.DD_VITEST_WORKER = '1'
622
- return start.apply(this, arguments)
623
- })
624
- shimmer.wrap(threadsPoolWorker.value.prototype, 'on', getWrappedOn)
625
- }
626
- return cliApiPackage
14
+ require('./vitest-worker')
15
+ } else {
16
+ require('./vitest-main')
627
17
  }
628
-
629
- function wrapVitestTestRunner (VitestTestRunner) {
630
- // `onBeforeRunTask` is run before any repetition or attempt is run
631
- // `onBeforeRunTask` is an async function
632
- shimmer.wrap(VitestTestRunner.prototype, 'onBeforeRunTask', onBeforeRunTask => function (task) {
633
- const testName = getTestName(task)
634
-
635
- const {
636
- knownTests,
637
- isEarlyFlakeDetectionEnabled,
638
- isKnownTestsEnabled,
639
- numRepeats,
640
- isTestManagementTestsEnabled,
641
- testManagementAttemptToFixRetries,
642
- testManagementTests,
643
- isImpactedTestsEnabled,
644
- modifiedFiles,
645
- } = getProvidedContext()
646
-
647
- if (isTestManagementTestsEnabled) {
648
- isAttemptToFixCh.publish({
649
- testManagementTests,
650
- testSuiteAbsolutePath: task.file.filepath,
651
- testName,
652
- onDone: (isAttemptToFix) => {
653
- if (isAttemptToFix) {
654
- isRetryReasonAttemptToFix = task.repeats !== testManagementAttemptToFixRetries
655
- task.repeats = testManagementAttemptToFixRetries
656
- attemptToFixTasks.add(task)
657
- taskToStatuses.set(task, [])
658
- }
659
- },
660
- })
661
- isDisabledCh.publish({
662
- testManagementTests,
663
- testSuiteAbsolutePath: task.file.filepath,
664
- testName,
665
- onDone: (isTestDisabled) => {
666
- if (isTestDisabled) {
667
- disabledTasks.add(task)
668
- if (!attemptToFixTasks.has(task)) {
669
- // we only actually skip if the test is not being attempted to be fixed
670
- task.mode = 'skip'
671
- }
672
- }
673
- },
674
- })
675
- }
676
-
677
- if (isImpactedTestsEnabled) {
678
- isModifiedCh.publish({
679
- modifiedFiles,
680
- testSuiteAbsolutePath: task.file.filepath,
681
- onDone: (isImpacted) => {
682
- if (isImpacted) {
683
- if (isEarlyFlakeDetectionEnabled) {
684
- isRetryReasonEfd = task.repeats !== numRepeats
685
- task.repeats = numRepeats
686
- }
687
- modifiedTasks.add(task)
688
- taskToStatuses.set(task, [])
689
- }
690
- },
691
- })
692
- }
693
-
694
- if (isKnownTestsEnabled) {
695
- isNewTestCh.publish({
696
- knownTests,
697
- testSuiteAbsolutePath: task.file.filepath,
698
- testName,
699
- onDone: (isNew) => {
700
- if (isNew && !attemptToFixTasks.has(task)) {
701
- if (isEarlyFlakeDetectionEnabled && !modifiedTasks.has(task)) {
702
- isRetryReasonEfd = task.repeats !== numRepeats
703
- task.repeats = numRepeats
704
- }
705
- newTasks.add(task)
706
- taskToStatuses.set(task, [])
707
- if (DYNAMIC_NAME_RE.test(testName)) {
708
- dynamicNameTasks.add(task)
709
- }
710
- }
711
- },
712
- })
713
- }
714
-
715
- return onBeforeRunTask.apply(this, arguments)
716
- })
717
-
718
- // `onAfterRunTask` is run after all repetitions or attempts are run
719
- // `onAfterRunTask` is an async function
720
- shimmer.wrap(VitestTestRunner.prototype, 'onAfterRunTask', onAfterRunTask => function (task) {
721
- const { isEarlyFlakeDetectionEnabled, isTestManagementTestsEnabled } = getProvidedContext()
722
-
723
- if (isTestManagementTestsEnabled) {
724
- const isAttemptingToFix = attemptToFixTasks.has(task)
725
- const isDisabled = disabledTasks.has(task)
726
- const isQuarantined = quarantinedTasks.has(task)
727
-
728
- if (isAttemptingToFix && (isDisabled || isQuarantined)) {
729
- if (task.result.state === 'fail') {
730
- switchedStatuses.add(task)
731
- }
732
- task.result.state = 'pass'
733
- } else if (isQuarantined) {
734
- if (task.result.state === 'fail') {
735
- switchedStatuses.add(task)
736
- }
737
- task.result.state = 'pass'
738
- }
739
- }
740
-
741
- if (isEarlyFlakeDetectionEnabled && taskToStatuses.has(task) && !attemptToFixTasks.has(task)) {
742
- const statuses = taskToStatuses.get(task)
743
- // If the test has passed at least once, we consider it passed
744
- if (statuses.includes('pass')) {
745
- if (task.result.state === 'fail') {
746
- switchedStatuses.add(task)
747
- }
748
- task.result.state = 'pass'
749
- }
750
- }
751
-
752
- return onAfterRunTask.apply(this, arguments)
753
- })
754
-
755
- // test start (only tests that are not marked as skip or todo)
756
- // `onBeforeTryTask` is run for every repetition and attempt of the test
757
- shimmer.wrap(VitestTestRunner.prototype, 'onBeforeTryTask', onBeforeTryTask => async function (task, retryInfo) {
758
- if (!testPassCh.hasSubscribers && !testErrorCh.hasSubscribers && !testSkipCh.hasSubscribers) {
759
- return onBeforeTryTask.apply(this, arguments)
760
- }
761
- const testName = getTestName(task)
762
- let isNew = false
763
- let isQuarantined = false
764
-
765
- const {
766
- isKnownTestsEnabled,
767
- isEarlyFlakeDetectionEnabled,
768
- isDiEnabled,
769
- isTestManagementTestsEnabled,
770
- testManagementTests,
771
- isFlakyTestRetriesEnabled,
772
- } = getProvidedContext()
773
-
774
- if (isKnownTestsEnabled) {
775
- isNew = newTasks.has(task)
776
- }
777
-
778
- if (isTestManagementTestsEnabled) {
779
- isQuarantinedCh.publish({
780
- testManagementTests,
781
- testSuiteAbsolutePath: task.file.filepath,
782
- testName,
783
- onDone: (isTestQuarantined) => {
784
- isQuarantined = isTestQuarantined
785
- if (isTestQuarantined) {
786
- quarantinedTasks.add(task)
787
- }
788
- },
789
- })
790
- }
791
-
792
- const { retry: numAttempt, repeats: numRepetition } = retryInfo
793
-
794
- // We finish the previous test here because we know it has failed already
795
- if (numAttempt > 0) {
796
- const shouldWaitForHitProbe = isDiEnabled && numAttempt > 1
797
- if (shouldWaitForHitProbe) {
798
- await waitForHitProbe()
799
- }
800
-
801
- const promises = {}
802
- const shouldSetProbe = isDiEnabled && numAttempt === 1
803
- const ctx = taskToCtx.get(task)
804
- const testError = task.result?.errors?.[0]
805
- if (ctx) {
806
- testErrorCh.publish({
807
- error: testError,
808
- shouldSetProbe,
809
- promises,
810
- ...ctx.currentStore,
811
- })
812
- // We wait for the probe to be set
813
- if (promises.setProbePromise) {
814
- await promises.setProbePromise
815
- }
816
- }
817
- }
818
-
819
- const lastExecutionStatus = task.result.state
820
- const isAtf = attemptToFixTasks.has(task)
821
- const isQuarantinedOrDisabledAtf = isAtf && (quarantinedTasks.has(task) || disabledTasks.has(task))
822
- const shouldTrackStatuses = isEarlyFlakeDetectionEnabled || isAtf
823
- const shouldFlipStatus = isEarlyFlakeDetectionEnabled || isQuarantinedOrDisabledAtf
824
- const statuses = taskToStatuses.get(task)
825
-
826
- // These clauses handle task.repeats, whether EFD is enabled or not
827
- // The only thing that EFD does is to forcefully pass the test if it has passed at least once
828
- if (numRepetition > 0 && numRepetition < task.repeats) { // it may or may have not failed
829
- // Here we finish the earlier iteration,
830
- // as long as it's not the _last_ iteration (which will be finished normally)
831
-
832
- // TODO: check test duration (not to repeat if it's too slow)
833
- const ctx = taskToCtx.get(task)
834
- if (ctx) {
835
- if (lastExecutionStatus === 'fail') {
836
- const testError = task.result?.errors?.[0]
837
- testErrorCh.publish({ error: testError, ...ctx.currentStore })
838
- } else {
839
- testPassCh.publish({ task, ...ctx.currentStore })
840
- }
841
- if (shouldTrackStatuses) {
842
- statuses.push(lastExecutionStatus)
843
- }
844
- if (shouldFlipStatus) {
845
- // If we don't "reset" the result.state to "pass", once a repetition fails,
846
- // vitest will always consider the test as failed, so we can't read the actual status
847
- // This means that we change vitest's behavior:
848
- // if the last attempt passes, vitest would consider the test as failed
849
- // but after this change, it will consider the test as passed
850
- task.result.state = 'pass'
851
- }
852
- }
853
- } else if (numRepetition === task.repeats) {
854
- if (shouldTrackStatuses) {
855
- statuses.push(lastExecutionStatus)
856
- }
857
-
858
- const ctx = taskToCtx.get(task)
859
- if (lastExecutionStatus === 'fail') {
860
- const testError = task.result?.errors?.[0]
861
- testErrorCh.publish({ error: testError, ...ctx.currentStore })
862
- } else {
863
- testPassCh.publish({ task, ...ctx.currentStore })
864
- }
865
- }
866
-
867
- const isRetryReasonAtr = numAttempt > 0 &&
868
- isFlakyTestRetriesEnabled &&
869
- !isRetryReasonAttemptToFix &&
870
- !isRetryReasonEfd
871
-
872
- const ctx = {
873
- testName,
874
- testSuiteAbsolutePath: task.file.filepath,
875
- isRetry: numAttempt > 0 || numRepetition > 0,
876
- isRetryReasonEfd,
877
- isRetryReasonAttemptToFix: isRetryReasonAttemptToFix && numRepetition > 0,
878
- isNew,
879
- hasDynamicName: dynamicNameTasks.has(task),
880
- mightHitProbe: isDiEnabled && numAttempt > 0,
881
- isAttemptToFix: attemptToFixTasks.has(task),
882
- isDisabled: disabledTasks.has(task),
883
- isQuarantined,
884
- isRetryReasonAtr,
885
- isModified: modifiedTasks.has(task),
886
- }
887
- taskToCtx.set(task, ctx)
888
-
889
- testStartCh.runStores(ctx, () => {})
890
-
891
- // Wrap the test function so it runs inside the test span context.
892
- // Without this, HTTP requests during test execution become orphaned root spans.
893
- if (vitestGetFn && vitestSetFn) {
894
- const originalFn = vitestGetFn(task)
895
- if (originalFn && !originalFn.__ddTraceWrapped) {
896
- const wrappedFn = wrapTestScopedFn(task, originalFn)
897
- wrappedFn.__ddTraceWrapped = true
898
- vitestSetFn(task, wrappedFn)
899
- }
900
- }
901
-
902
- // Wrap beforeEach/afterEach hooks so they also run inside the test span context.
903
- // In vitest 4+, hooks are in a WeakMap accessed via getHooks(). In older versions, they're on suite.hooks.
904
- let currentSuite = task.suite
905
- while (currentSuite) {
906
- const hooks = vitestGetHooks ? vitestGetHooks(currentSuite) : currentSuite.hooks
907
- if (hooks) {
908
- for (const hookType of ['beforeEach', 'afterEach']) {
909
- const hookArray = hooks[hookType]
910
- if (!hookArray) continue
911
- for (let i = 0; i < hookArray.length; i++) {
912
- const currentFn = hookArray[i]
913
- const originalFn = originalHookFns.get(currentFn) || currentFn
914
- const wrappedFn = shimmer.wrapFunction(originalFn, fn => function () {
915
- const result = testFnCh.runStores(taskToCtx.get(task), () => fn.apply(this, arguments))
916
-
917
- if (hookType === 'beforeEach') {
918
- return wrapBeforeEachCleanupResult(task, result)
919
- }
920
-
921
- return result
922
- })
923
- originalHookFns.set(wrappedFn, originalFn)
924
- hookArray[i] = wrappedFn
925
- }
926
- }
927
- }
928
- currentSuite = currentSuite.suite
929
- }
930
-
931
- return onBeforeTryTask.apply(this, arguments)
932
- })
933
-
934
- // test finish (only passed tests)
935
- shimmer.wrap(VitestTestRunner.prototype, 'onAfterTryTask', onAfterTryTask =>
936
- async function (task, { retry: retryCount }) {
937
- if (!testPassCh.hasSubscribers && !testErrorCh.hasSubscribers && !testSkipCh.hasSubscribers) {
938
- return onAfterTryTask.apply(this, arguments)
939
- }
940
- const result = await onAfterTryTask.apply(this, arguments)
941
-
942
- const { testManagementAttemptToFixRetries } = getProvidedContext()
943
-
944
- const status = getVitestTestStatus(task, retryCount)
945
- const ctx = taskToCtx.get(task)
946
-
947
- const { isDiEnabled } = getProvidedContext()
948
-
949
- if (isDiEnabled && retryCount > 1) {
950
- await waitForHitProbe()
951
- }
952
-
953
- let attemptToFixPassed = false
954
- let attemptToFixFailed = false
955
- if (attemptToFixTasks.has(task)) {
956
- const statuses = taskToStatuses.get(task)
957
- if (statuses.length === testManagementAttemptToFixRetries) {
958
- if (statuses.every(status => status === 'pass')) {
959
- attemptToFixPassed = true
960
- } else if (statuses.includes('fail')) {
961
- attemptToFixFailed = true
962
- }
963
- }
964
- }
965
-
966
- if (ctx) {
967
- // We don't finish here because the test might fail in a later hook (afterEach)
968
- ctx.status = status
969
- ctx.task = task
970
- ctx.attemptToFixPassed = attemptToFixPassed
971
- ctx.attemptToFixFailed = attemptToFixFailed
972
- testFinishTimeCh.runStores(ctx, () => {})
973
- }
974
-
975
- return result
976
- })
977
- }
978
-
979
- function captureRunnerFunctions (pkg) {
980
- if (vitestGetFn) return
981
- const getFnExport = findExportByName(pkg, 'getFn')
982
- const setFnExport = findExportByName(pkg, 'setFn')
983
- if (getFnExport && setFnExport) {
984
- vitestGetFn = getFnExport.value
985
- vitestSetFn = setFnExport.value
986
- }
987
- const getHooksExport = findExportByName(pkg, 'getHooks')
988
- if (getHooksExport) {
989
- vitestGetHooks = getHooksExport.value
990
- }
991
- }
992
-
993
- addHook({
994
- name: 'vitest',
995
- versions: ['>=4.0.0'],
996
- filePattern: 'dist/chunks/test.*',
997
- }, (testPackage) => {
998
- const testRunner = getTestRunnerExport(testPackage)
999
- if (!testRunner) {
1000
- return testPackage
1001
- }
1002
-
1003
- captureRunnerFunctions(testPackage)
1004
- wrapVitestTestRunner(testRunner.value)
1005
-
1006
- return testPackage
1007
- })
1008
-
1009
- addHook({
1010
- name: '@vitest/runner',
1011
- versions: ['>=1.6.0'],
1012
- }, (runnerModule) => {
1013
- if (!vitestGetFn && runnerModule.getFn && runnerModule.setFn) {
1014
- vitestGetFn = runnerModule.getFn
1015
- vitestSetFn = runnerModule.setFn
1016
- }
1017
- if (!vitestGetHooks && runnerModule.getHooks) {
1018
- vitestGetHooks = runnerModule.getHooks
1019
- }
1020
- return runnerModule
1021
- })
1022
-
1023
- addHook({
1024
- name: 'vitest',
1025
- versions: ['>=1.6.0 <4.0.0'],
1026
- file: 'dist/runners.js',
1027
- }, (vitestPackage) => {
1028
- const { VitestTestRunner } = vitestPackage
1029
-
1030
- wrapVitestTestRunner(VitestTestRunner)
1031
-
1032
- return vitestPackage
1033
- })
1034
-
1035
- // There are multiple index* files across different versions of vitest,
1036
- // so we check for the existence of BaseSequencer to determine if we are in the right file
1037
- addHook({
1038
- name: 'vitest',
1039
- versions: ['>=1.6.0 <2.0.0'],
1040
- filePattern: 'dist/vendor/index.*',
1041
- }, (vitestPackage) => {
1042
- if (isReporterPackage(vitestPackage)) {
1043
- shimmer.wrap(vitestPackage.B.prototype, 'sort', getSortWrapper)
1044
- }
1045
-
1046
- return vitestPackage
1047
- })
1048
-
1049
- addHook({
1050
- name: 'vitest',
1051
- versions: ['>=2.0.0 <2.0.5'],
1052
- filePattern: 'dist/vendor/index.*',
1053
- }, (vitestPackage) => {
1054
- if (isReporterPackageNew(vitestPackage)) {
1055
- shimmer.wrap(vitestPackage.e.prototype, 'sort', getSortWrapper)
1056
- }
1057
-
1058
- return vitestPackage
1059
- })
1060
-
1061
- addHook({
1062
- name: 'vitest',
1063
- versions: ['>=2.0.5 <2.1.0'],
1064
- filePattern: 'dist/chunks/index.*',
1065
- }, (vitestPackage) => {
1066
- if (isReporterPackageNewest(vitestPackage)) {
1067
- shimmer.wrap(vitestPackage.h.prototype, 'sort', getSortWrapper)
1068
- }
1069
-
1070
- return vitestPackage
1071
- })
1072
-
1073
- addHook({
1074
- name: 'vitest',
1075
- versions: ['>=2.1.0 <3.0.0'],
1076
- filePattern: 'dist/chunks/RandomSequencer.*',
1077
- }, (randomSequencerPackage) => {
1078
- shimmer.wrap(randomSequencerPackage.B.prototype, 'sort', getSortWrapper)
1079
- return randomSequencerPackage
1080
- })
1081
-
1082
- addHook({
1083
- name: 'vitest',
1084
- versions: ['>=3.0.9'],
1085
- filePattern: 'dist/chunks/coverage.*',
1086
- }, (coveragePackage) => {
1087
- const baseSequencer = getBaseSequencerExport(coveragePackage)
1088
- if (baseSequencer) {
1089
- shimmer.wrap(baseSequencer.value.prototype, 'sort', getSortWrapper)
1090
- }
1091
- return coveragePackage
1092
- })
1093
-
1094
- addHook({
1095
- name: 'vitest',
1096
- versions: ['>=3.0.0 <3.0.9'],
1097
- filePattern: 'dist/chunks/resolveConfig.*',
1098
- }, (resolveConfigPackage) => {
1099
- shimmer.wrap(resolveConfigPackage.B.prototype, 'sort', getSortWrapper)
1100
- return resolveConfigPackage
1101
- })
1102
-
1103
- // Can't specify file because compiled vitest includes hashes in their files
1104
- // Following 3 wrappers are for test session start
1105
- addHook({
1106
- name: 'vitest',
1107
- versions: ['>=1.6.0 <2.0.5'],
1108
- filePattern: 'dist/vendor/cac.*',
1109
- }, getCreateCliWrapper)
1110
-
1111
- addHook({
1112
- name: 'vitest',
1113
- versions: ['>=2.0.5'],
1114
- filePattern: 'dist/chunks/cac.*',
1115
- }, getCreateCliWrapper)
1116
-
1117
- addHook({
1118
- name: 'vitest',
1119
- versions: ['>=1.6.0 <2.0.5'],
1120
- filePattern: 'dist/vendor/cli-api.*',
1121
- }, getStartVitestWrapper)
1122
-
1123
- addHook({
1124
- name: 'vitest',
1125
- versions: ['>=2.0.5'],
1126
- filePattern: 'dist/chunks/cli-api.*',
1127
- }, getStartVitestWrapper)
1128
-
1129
- // test suite start and finish
1130
- // only relevant for workers
1131
- addHook({
1132
- name: '@vitest/runner',
1133
- versions: ['>=1.6.0'],
1134
- }, (vitestPackage, frameworkVersion) => {
1135
- shimmer.wrap(vitestPackage, 'startTests', startTests => async function (testPaths) {
1136
- let testSuiteError = null
1137
- if (!testSuiteFinishCh.hasSubscribers) {
1138
- return startTests.apply(this, arguments)
1139
- }
1140
- // From >=3.0.1, the first arguments changes from a string to an object containing the filepath
1141
- const testSuiteAbsolutePath = testPaths[0]?.filepath || testPaths[0]
1142
-
1143
- const testSuiteCtx = { testSuiteAbsolutePath, frameworkVersion }
1144
- testSuiteStartCh.runStores(testSuiteCtx, () => {})
1145
- const startTestsResponse = await startTests.apply(this, arguments)
1146
-
1147
- let onFinish = null
1148
- const onFinishPromise = new Promise(resolve => {
1149
- onFinish = resolve
1150
- })
1151
-
1152
- const testTasks = getTypeTasks(startTestsResponse[0].tasks)
1153
-
1154
- // Only one test task per test, even if there are retries
1155
- for (const task of testTasks) {
1156
- const testCtx = taskToCtx.get(task)
1157
- const { result } = task
1158
- // We have to trick vitest into thinking that the test has passed
1159
- // but we want to report it as failed if it did fail
1160
- const isSwitchedStatus = switchedStatuses.has(task)
1161
-
1162
- if (result) {
1163
- const { state, duration, errors } = result
1164
- if (state === 'skip') { // programmatic skip
1165
- testSkipCh.publish({
1166
- testName: getTestName(task),
1167
- testSuiteAbsolutePath: task.file.filepath,
1168
- isNew: newTasks.has(task),
1169
- isDisabled: disabledTasks.has(task),
1170
- })
1171
- } else if (state === 'pass' && !isSwitchedStatus) {
1172
- if (testCtx) {
1173
- testPassCh.publish({ task, ...testCtx.currentStore })
1174
- }
1175
- } else if (state === 'fail' || isSwitchedStatus) {
1176
- let testError
1177
-
1178
- if (errors?.length) {
1179
- testError = errors[0]
1180
- }
1181
-
1182
- let hasFailedAllRetries = false
1183
- let attemptToFixFailed = false
1184
- if (attemptToFixTasks.has(task)) {
1185
- const statuses = taskToStatuses.get(task)
1186
- if (statuses.includes('fail')) {
1187
- attemptToFixFailed = true
1188
- }
1189
- if (statuses.every(status => status === 'fail')) {
1190
- hasFailedAllRetries = true
1191
- }
1192
- }
1193
-
1194
- // Check if all EFD retries failed
1195
- const providedContext = getProvidedContext()
1196
- if (providedContext.isEarlyFlakeDetectionEnabled && (newTasks.has(task) || modifiedTasks.has(task))) {
1197
- const statuses = taskToStatuses.get(task)
1198
- // statuses only includes repetitions (not the initial run), so we check against numRepeats (not +1)
1199
- if (statuses && statuses.length === providedContext.numRepeats &&
1200
- statuses.every(status => status === 'fail')) {
1201
- hasFailedAllRetries = true
1202
- }
1203
- }
1204
-
1205
- // ATR: set hasFailedAllRetries when all auto test retries were exhausted and every attempt failed
1206
- if (providedContext.isFlakyTestRetriesEnabled && !attemptToFixTasks.has(task) &&
1207
- !newTasks.has(task) && !modifiedTasks.has(task)) {
1208
- const maxRetries = providedContext.flakyTestRetriesCount ?? 0
1209
- if (maxRetries > 0 && task.result?.retryCount === maxRetries) {
1210
- hasFailedAllRetries = true
1211
- }
1212
- }
1213
-
1214
- if (testCtx) {
1215
- const isRetry = task.result?.retryCount > 0
1216
- // `duration` is the duration of all the retries, so it can't be used if there are retries
1217
- testErrorCh.publish({
1218
- duration: isRetry ? undefined : duration,
1219
- error: testError,
1220
- hasFailedAllRetries,
1221
- attemptToFixFailed,
1222
- ...testCtx.currentStore,
1223
- })
1224
- }
1225
- if (errors?.length) {
1226
- testSuiteError = testError // we store the error to bubble it up to the suite
1227
- }
1228
- }
1229
- } else { // test.skip or test.todo
1230
- testSkipCh.publish({
1231
- testName: getTestName(task),
1232
- testSuiteAbsolutePath: task.file.filepath,
1233
- isNew: newTasks.has(task),
1234
- isDisabled: disabledTasks.has(task),
1235
- })
1236
- }
1237
- }
1238
-
1239
- const testSuiteResult = startTestsResponse[0].result
1240
-
1241
- if (testSuiteResult.errors?.length) { // Errors from root level hooks
1242
- testSuiteError = testSuiteResult.errors[0]
1243
- } else if (testSuiteResult.state === 'fail') { // Errors from `describe` level hooks
1244
- const suiteTasks = getTypeTasks(startTestsResponse[0].tasks, 'suite')
1245
- const failedSuites = suiteTasks.filter(task => task.result?.state === 'fail')
1246
- if (failedSuites.length && failedSuites[0].result?.errors?.length) {
1247
- testSuiteError = failedSuites[0].result.errors[0]
1248
- }
1249
- }
1250
-
1251
- if (testSuiteError) {
1252
- testSuiteCtx.error = testSuiteError
1253
- testSuiteErrorCh.runStores(testSuiteCtx, () => {})
1254
- }
1255
-
1256
- testSuiteFinishCh.publish({ status: testSuiteResult.state, onFinish, ...testSuiteCtx.currentStore })
1257
-
1258
- await onFinishPromise
1259
-
1260
- return startTestsResponse
1261
- })
1262
-
1263
- return vitestPackage
1264
- })