dd-trace 5.53.0 → 5.55.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 (368) hide show
  1. package/LICENSE-3rdparty.csv +2 -1
  2. package/ci/cypress/plugin.js +8 -0
  3. package/ci/cypress/polyfills.js +23 -0
  4. package/ci/init.js +8 -7
  5. package/index.d.ts +33 -16
  6. package/initialize.mjs +5 -6
  7. package/package.json +40 -38
  8. package/packages/datadog-code-origin/index.js +22 -4
  9. package/packages/datadog-core/src/utils/src/get.js +1 -1
  10. package/packages/datadog-core/src/utils/src/has.js +1 -1
  11. package/packages/datadog-core/src/utils/src/kebabcase.js +4 -6
  12. package/packages/datadog-core/src/utils/src/parse-tags.js +1 -1
  13. package/packages/datadog-core/src/utils/src/pick.js +2 -2
  14. package/packages/datadog-core/src/utils/src/set.js +1 -1
  15. package/packages/datadog-core/src/utils/src/uniq.js +1 -1
  16. package/packages/datadog-instrumentations/src/amqp10.js +19 -17
  17. package/packages/datadog-instrumentations/src/amqplib.js +52 -35
  18. package/packages/datadog-instrumentations/src/apollo.js +2 -2
  19. package/packages/datadog-instrumentations/src/aws-sdk.js +1 -1
  20. package/packages/datadog-instrumentations/src/cassandra-driver.js +10 -10
  21. package/packages/datadog-instrumentations/src/child_process.js +1 -2
  22. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +89 -75
  23. package/packages/datadog-instrumentations/src/cookie-parser.js +1 -1
  24. package/packages/datadog-instrumentations/src/couchbase.js +6 -9
  25. package/packages/datadog-instrumentations/src/cucumber.js +108 -68
  26. package/packages/datadog-instrumentations/src/cypress.js +2 -1
  27. package/packages/datadog-instrumentations/src/dns.js +5 -5
  28. package/packages/datadog-instrumentations/src/elasticsearch.js +9 -10
  29. package/packages/datadog-instrumentations/src/fastify.js +7 -9
  30. package/packages/datadog-instrumentations/src/fs.js +1 -1
  31. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +35 -43
  32. package/packages/datadog-instrumentations/src/graphql.js +7 -10
  33. package/packages/datadog-instrumentations/src/grpc/client.js +11 -23
  34. package/packages/datadog-instrumentations/src/grpc/server.js +7 -20
  35. package/packages/datadog-instrumentations/src/hapi.js +10 -11
  36. package/packages/datadog-instrumentations/src/helpers/extract-package-and-module-path.js +16 -10
  37. package/packages/datadog-instrumentations/src/helpers/fetch.js +4 -5
  38. package/packages/datadog-instrumentations/src/helpers/hook.js +2 -3
  39. package/packages/datadog-instrumentations/src/helpers/hooks.js +0 -1
  40. package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -41
  41. package/packages/datadog-instrumentations/src/helpers/register.js +11 -12
  42. package/packages/datadog-instrumentations/src/http/client.js +14 -20
  43. package/packages/datadog-instrumentations/src/jest.js +201 -143
  44. package/packages/datadog-instrumentations/src/kafkajs.js +52 -44
  45. package/packages/datadog-instrumentations/src/knex.js +4 -4
  46. package/packages/datadog-instrumentations/src/koa.js +2 -3
  47. package/packages/datadog-instrumentations/src/ldapjs.js +3 -4
  48. package/packages/datadog-instrumentations/src/mariadb.js +49 -65
  49. package/packages/datadog-instrumentations/src/mocha/main.js +116 -73
  50. package/packages/datadog-instrumentations/src/mocha/utils.js +36 -12
  51. package/packages/datadog-instrumentations/src/mocha/worker.js +6 -0
  52. package/packages/datadog-instrumentations/src/mocha.js +3 -1
  53. package/packages/datadog-instrumentations/src/mongodb-core.js +1 -1
  54. package/packages/datadog-instrumentations/src/mysql.js +30 -37
  55. package/packages/datadog-instrumentations/src/mysql2.js +53 -47
  56. package/packages/datadog-instrumentations/src/net.js +1 -1
  57. package/packages/datadog-instrumentations/src/next.js +1 -0
  58. package/packages/datadog-instrumentations/src/nyc.js +3 -2
  59. package/packages/datadog-instrumentations/src/openai.js +22 -24
  60. package/packages/datadog-instrumentations/src/oracledb.js +1 -1
  61. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +4 -3
  62. package/packages/datadog-instrumentations/src/pg.js +3 -5
  63. package/packages/datadog-instrumentations/src/playwright.js +123 -83
  64. package/packages/datadog-instrumentations/src/protobufjs.js +3 -4
  65. package/packages/datadog-instrumentations/src/redis.js +4 -4
  66. package/packages/datadog-instrumentations/src/restify.js +9 -13
  67. package/packages/datadog-instrumentations/src/rhea.js +42 -54
  68. package/packages/datadog-instrumentations/src/router.js +30 -32
  69. package/packages/datadog-instrumentations/src/tedious.js +2 -3
  70. package/packages/datadog-instrumentations/src/vitest.js +87 -52
  71. package/packages/datadog-plugin-amqp10/src/consumer.js +7 -3
  72. package/packages/datadog-plugin-amqp10/src/producer.js +7 -3
  73. package/packages/datadog-plugin-amqplib/src/client.js +6 -2
  74. package/packages/datadog-plugin-amqplib/src/consumer.js +7 -3
  75. package/packages/datadog-plugin-amqplib/src/producer.js +7 -3
  76. package/packages/datadog-plugin-amqplib/src/util.js +1 -1
  77. package/packages/datadog-plugin-apollo/src/gateway/request.js +5 -6
  78. package/packages/datadog-plugin-apollo/src/gateway/validate.js +2 -3
  79. package/packages/datadog-plugin-avsc/src/schema_iterator.js +12 -12
  80. package/packages/datadog-plugin-aws-sdk/src/base.js +15 -10
  81. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +2 -2
  82. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +13 -13
  83. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +3 -5
  84. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +28 -43
  85. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +2 -2
  86. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +10 -11
  87. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +4 -6
  88. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +3 -5
  89. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +3 -5
  90. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +2 -3
  91. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +11 -15
  92. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +1 -1
  93. package/packages/datadog-plugin-aws-sdk/src/util.js +5 -6
  94. package/packages/datadog-plugin-cassandra-driver/src/index.js +1 -1
  95. package/packages/datadog-plugin-child_process/src/index.js +4 -4
  96. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +23 -23
  97. package/packages/datadog-plugin-cucumber/src/index.js +60 -4
  98. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +99 -28
  99. package/packages/datadog-plugin-cypress/src/plugin.js +11 -1
  100. package/packages/datadog-plugin-cypress/src/support.js +24 -5
  101. package/packages/datadog-plugin-dd-trace-api/src/index.js +2 -1
  102. package/packages/datadog-plugin-elasticsearch/src/index.js +1 -1
  103. package/packages/datadog-plugin-express/src/code_origin.js +30 -0
  104. package/packages/datadog-plugin-express/src/index.js +10 -12
  105. package/packages/datadog-plugin-express/src/tracing.js +19 -0
  106. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +7 -3
  107. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +12 -7
  108. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +6 -2
  109. package/packages/datadog-plugin-google-cloud-vertexai/src/tracing.js +27 -10
  110. package/packages/datadog-plugin-graphql/src/execute.js +2 -2
  111. package/packages/datadog-plugin-graphql/src/index.js +10 -8
  112. package/packages/datadog-plugin-graphql/src/resolve.js +19 -12
  113. package/packages/datadog-plugin-graphql/src/tools/index.js +1 -0
  114. package/packages/datadog-plugin-graphql/src/tools/signature.js +1 -0
  115. package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
  116. package/packages/datadog-plugin-grpc/src/client.js +2 -2
  117. package/packages/datadog-plugin-grpc/src/util.js +2 -2
  118. package/packages/datadog-plugin-http/src/client.js +23 -13
  119. package/packages/datadog-plugin-http2/src/client.js +24 -25
  120. package/packages/datadog-plugin-jest/src/index.js +26 -23
  121. package/packages/datadog-plugin-jest/src/util.js +8 -8
  122. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +3 -1
  123. package/packages/datadog-plugin-kafkajs/src/consumer.js +9 -5
  124. package/packages/datadog-plugin-kafkajs/src/producer.js +8 -3
  125. package/packages/datadog-plugin-kafkajs/src/utils.js +1 -1
  126. package/packages/datadog-plugin-langchain/src/handlers/chain.js +7 -7
  127. package/packages/datadog-plugin-langchain/src/handlers/embedding.js +2 -2
  128. package/packages/datadog-plugin-langchain/src/handlers/language_models/chat_model.js +6 -4
  129. package/packages/datadog-plugin-langchain/src/handlers/language_models/llm.js +5 -4
  130. package/packages/datadog-plugin-langchain/src/tracing.js +11 -10
  131. package/packages/datadog-plugin-mariadb/src/index.js +3 -9
  132. package/packages/datadog-plugin-mocha/src/index.js +39 -14
  133. package/packages/datadog-plugin-mongodb-core/src/index.js +3 -2
  134. package/packages/datadog-plugin-mysql/src/index.js +22 -9
  135. package/packages/datadog-plugin-mysql2/src/index.js +16 -0
  136. package/packages/datadog-plugin-net/src/tcp.js +1 -1
  137. package/packages/datadog-plugin-next/src/index.js +7 -6
  138. package/packages/datadog-plugin-openai/src/services.js +6 -10
  139. package/packages/datadog-plugin-openai/src/tracing.js +12 -18
  140. package/packages/datadog-plugin-oracledb/src/index.js +1 -1
  141. package/packages/datadog-plugin-playwright/src/index.js +25 -4
  142. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +8 -9
  143. package/packages/datadog-plugin-redis/src/index.js +2 -4
  144. package/packages/datadog-plugin-rhea/src/consumer.js +8 -6
  145. package/packages/datadog-plugin-rhea/src/producer.js +5 -2
  146. package/packages/datadog-plugin-router/src/index.js +1 -1
  147. package/packages/datadog-plugin-selenium/src/index.js +1 -6
  148. package/packages/datadog-plugin-vitest/src/index.js +52 -35
  149. package/packages/datadog-shimmer/src/shimmer.js +4 -8
  150. package/packages/dd-trace/src/appsec/api_security_sampler.js +2 -2
  151. package/packages/dd-trace/src/appsec/blocked_templates.js +1 -1
  152. package/packages/dd-trace/src/appsec/blocking.js +6 -20
  153. package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +0 -1
  154. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +0 -1
  155. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +0 -1
  156. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secrets-rules.js +0 -1
  157. package/packages/dd-trace/src/appsec/iast/analyzers/hsts-header-missing-analyzer.js +7 -12
  158. package/packages/dd-trace/src/appsec/iast/analyzers/missing-header-analyzer.js +5 -8
  159. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +4 -0
  160. package/packages/dd-trace/src/appsec/iast/analyzers/path-traversal-analyzer.js +9 -12
  161. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +5 -4
  162. package/packages/dd-trace/src/appsec/iast/context/context-plugin.js +2 -3
  163. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +3 -3
  164. package/packages/dd-trace/src/appsec/iast/index.js +1 -0
  165. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +102 -7
  166. package/packages/dd-trace/src/appsec/iast/path-line.js +7 -8
  167. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +16 -24
  168. package/packages/dd-trace/src/appsec/iast/security-controls/parser.js +6 -6
  169. package/packages/dd-trace/src/appsec/iast/taint-tracking/filter.js +2 -2
  170. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations-taint-object.js +3 -3
  171. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +4 -28
  172. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +2 -8
  173. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +3 -4
  174. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs +1 -1
  175. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +7 -8
  176. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -2
  177. package/packages/dd-trace/src/appsec/iast/telemetry/span-tags.js +7 -7
  178. package/packages/dd-trace/src/appsec/iast/telemetry/verbosity.js +2 -3
  179. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/range-utils.js +10 -11
  180. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/command-sensitive-analyzer.js +1 -1
  181. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +1 -1
  182. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/sql-sensitive-analyzer.js +7 -7
  183. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +23 -28
  184. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-regex.js +3 -3
  185. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +4 -4
  186. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +6 -11
  187. package/packages/dd-trace/src/appsec/iast/vulnerabilities.js +0 -1
  188. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +9 -11
  189. package/packages/dd-trace/src/appsec/index.js +5 -5
  190. package/packages/dd-trace/src/appsec/rasp/index.js +15 -15
  191. package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -1
  192. package/packages/dd-trace/src/appsec/reporter.js +232 -41
  193. package/packages/dd-trace/src/appsec/rule_manager.js +2 -2
  194. package/packages/dd-trace/src/appsec/sdk/set_user.js +2 -2
  195. package/packages/dd-trace/src/appsec/sdk/track_event.js +3 -3
  196. package/packages/dd-trace/src/appsec/stack_trace.js +2 -4
  197. package/packages/dd-trace/src/appsec/telemetry/index.js +31 -1
  198. package/packages/dd-trace/src/appsec/telemetry/rasp.js +3 -5
  199. package/packages/dd-trace/src/appsec/telemetry/waf.js +3 -5
  200. package/packages/dd-trace/src/appsec/user_tracking.js +3 -5
  201. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +8 -4
  202. package/packages/dd-trace/src/azure_metadata.js +9 -9
  203. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +9 -8
  204. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +2 -2
  205. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +3 -2
  206. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +3 -3
  207. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +3 -2
  208. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +3 -2
  209. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +3 -2
  210. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +6 -4
  211. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +6 -5
  212. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +7 -6
  213. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +0 -2
  214. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +3 -2
  215. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +5 -4
  216. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +12 -8
  217. package/packages/dd-trace/src/ci-visibility/telemetry.js +4 -0
  218. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +3 -2
  219. package/packages/dd-trace/src/config-helper.js +89 -0
  220. package/packages/dd-trace/src/config.js +159 -129
  221. package/packages/dd-trace/src/config_stable.js +10 -7
  222. package/packages/dd-trace/src/datastreams/encoding.js +9 -9
  223. package/packages/dd-trace/src/datastreams/fnv.js +2 -2
  224. package/packages/dd-trace/src/datastreams/pathway.js +4 -4
  225. package/packages/dd-trace/src/datastreams/processor.js +5 -7
  226. package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +7 -7
  227. package/packages/dd-trace/src/datastreams/schemas/schema_sampler.js +4 -6
  228. package/packages/dd-trace/src/datastreams/size.js +1 -1
  229. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +75 -69
  230. package/packages/dd-trace/src/debugger/devtools_client/condition.js +7 -10
  231. package/packages/dd-trace/src/debugger/devtools_client/defaults.js +1 -1
  232. package/packages/dd-trace/src/debugger/devtools_client/index.js +9 -2
  233. package/packages/dd-trace/src/debugger/devtools_client/remote_config.js +18 -38
  234. package/packages/dd-trace/src/debugger/devtools_client/send.js +3 -2
  235. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +1 -2
  236. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +1 -1
  237. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +11 -14
  238. package/packages/dd-trace/src/debugger/devtools_client/snapshot/redaction.js +4 -4
  239. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +2 -10
  240. package/packages/dd-trace/src/debugger/devtools_client/state.js +10 -3
  241. package/packages/dd-trace/src/debugger/index.js +1 -0
  242. package/packages/dd-trace/src/dogstatsd.js +7 -6
  243. package/packages/dd-trace/src/encode/0.4.js +14 -11
  244. package/packages/dd-trace/src/encode/0.5.js +4 -6
  245. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +8 -8
  246. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +1 -1
  247. package/packages/dd-trace/src/encode/tags-processors.js +1 -1
  248. package/packages/dd-trace/src/exporter.js +7 -6
  249. package/packages/dd-trace/src/exporters/agent/writer.js +1 -5
  250. package/packages/dd-trace/src/exporters/common/docker.js +4 -3
  251. package/packages/dd-trace/src/exporters/common/form-data.js +6 -4
  252. package/packages/dd-trace/src/exporters/common/request.js +5 -2
  253. package/packages/dd-trace/src/exporters/common/util.js +4 -2
  254. package/packages/dd-trace/src/external-logger/src/index.js +5 -5
  255. package/packages/dd-trace/src/flare/file.js +1 -5
  256. package/packages/dd-trace/src/format.js +1 -1
  257. package/packages/dd-trace/src/git_properties.js +1 -1
  258. package/packages/dd-trace/src/id.js +15 -9
  259. package/packages/dd-trace/src/iitm.js +10 -22
  260. package/packages/dd-trace/src/index.js +4 -3
  261. package/packages/dd-trace/src/lambda/handler.js +7 -6
  262. package/packages/dd-trace/src/lambda/index.js +2 -1
  263. package/packages/dd-trace/src/lambda/runtime/patch.js +7 -6
  264. package/packages/dd-trace/src/lambda/runtime/ritm.js +4 -3
  265. package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
  266. package/packages/dd-trace/src/llmobs/index.js +21 -5
  267. package/packages/dd-trace/src/llmobs/noop.js +18 -20
  268. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +6 -6
  269. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +2 -6
  270. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +3 -3
  271. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +11 -13
  272. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +6 -6
  273. package/packages/dd-trace/src/llmobs/plugins/openai.js +2 -3
  274. package/packages/dd-trace/src/llmobs/sdk.js +4 -3
  275. package/packages/dd-trace/src/llmobs/span_processor.js +1 -1
  276. package/packages/dd-trace/src/llmobs/tagger.js +129 -102
  277. package/packages/dd-trace/src/llmobs/util.js +9 -9
  278. package/packages/dd-trace/src/llmobs/writers/base.js +1 -1
  279. package/packages/dd-trace/src/llmobs/writers/util.js +1 -1
  280. package/packages/dd-trace/src/log/index.js +9 -8
  281. package/packages/dd-trace/src/log/log.js +1 -1
  282. package/packages/dd-trace/src/log/writer.js +3 -4
  283. package/packages/dd-trace/src/msgpack/chunk.js +3 -3
  284. package/packages/dd-trace/src/msgpack/encoder.js +31 -31
  285. package/packages/dd-trace/src/noop/dogstatsd.js +6 -6
  286. package/packages/dd-trace/src/noop/span.js +4 -6
  287. package/packages/dd-trace/src/noop/tracer.js +1 -2
  288. package/packages/dd-trace/src/opentelemetry/span_processor.js +2 -2
  289. package/packages/dd-trace/src/opentelemetry/tracer.js +7 -6
  290. package/packages/dd-trace/src/opentracing/propagation/log.js +10 -13
  291. package/packages/dd-trace/src/opentracing/propagation/text_map.js +40 -37
  292. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +8 -4
  293. package/packages/dd-trace/src/opentracing/span.js +16 -20
  294. package/packages/dd-trace/src/opentracing/tracer.js +9 -6
  295. package/packages/dd-trace/src/payload-tagging/config/index.js +17 -21
  296. package/packages/dd-trace/src/payload-tagging/index.js +1 -1
  297. package/packages/dd-trace/src/payload-tagging/tagging.js +6 -6
  298. package/packages/dd-trace/src/pkg.js +1 -1
  299. package/packages/dd-trace/src/plugin_manager.js +4 -3
  300. package/packages/dd-trace/src/plugins/ci_plugin.js +87 -11
  301. package/packages/dd-trace/src/plugins/consumer.js +2 -2
  302. package/packages/dd-trace/src/plugins/inbound.js +5 -1
  303. package/packages/dd-trace/src/plugins/index.js +0 -1
  304. package/packages/dd-trace/src/plugins/outbound.js +4 -5
  305. package/packages/dd-trace/src/plugins/plugin.js +1 -1
  306. package/packages/dd-trace/src/plugins/producer.js +2 -2
  307. package/packages/dd-trace/src/plugins/storage.js +2 -2
  308. package/packages/dd-trace/src/plugins/util/ci.js +28 -20
  309. package/packages/dd-trace/src/plugins/util/git.js +166 -12
  310. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +1 -1
  311. package/packages/dd-trace/src/plugins/util/ip_extractor.js +1 -1
  312. package/packages/dd-trace/src/plugins/util/llm.js +27 -10
  313. package/packages/dd-trace/src/plugins/util/stacktrace.js +9 -2
  314. package/packages/dd-trace/src/plugins/util/test.js +315 -51
  315. package/packages/dd-trace/src/plugins/util/url.js +1 -1
  316. package/packages/dd-trace/src/plugins/util/urlfilter.js +13 -17
  317. package/packages/dd-trace/src/plugins/util/user-provided-git.js +14 -4
  318. package/packages/dd-trace/src/plugins/util/web.js +8 -8
  319. package/packages/dd-trace/src/priority_sampler.js +64 -53
  320. package/packages/dd-trace/src/profiling/config.js +51 -35
  321. package/packages/dd-trace/src/profiling/exporter_cli.js +20 -20
  322. package/packages/dd-trace/src/profiling/exporters/agent.js +1 -1
  323. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +7 -6
  324. package/packages/dd-trace/src/profiling/exporters/file.js +2 -1
  325. package/packages/dd-trace/src/profiling/index.js +2 -1
  326. package/packages/dd-trace/src/profiling/profiler.js +44 -6
  327. package/packages/dd-trace/src/profiling/profilers/events.js +14 -17
  328. package/packages/dd-trace/src/profiling/profilers/shared.js +6 -1
  329. package/packages/dd-trace/src/profiling/profilers/space.js +3 -3
  330. package/packages/dd-trace/src/profiling/profilers/wall.js +6 -7
  331. package/packages/dd-trace/src/profiling/ssi-heuristics.js +3 -5
  332. package/packages/dd-trace/src/profiling/ssi-telemetry-mock-profiler.js +3 -1
  333. package/packages/dd-trace/src/profiling/tagger.js +21 -13
  334. package/packages/dd-trace/src/profiling/webspan-utils.js +1 -1
  335. package/packages/dd-trace/src/proxy.js +9 -10
  336. package/packages/dd-trace/src/random_sampler.js +40 -0
  337. package/packages/dd-trace/src/rate_limiter.js +4 -4
  338. package/packages/dd-trace/src/remote_config/index.js +3 -7
  339. package/packages/dd-trace/src/remote_config/manager.js +25 -13
  340. package/packages/dd-trace/src/require-package-json.js +1 -1
  341. package/packages/dd-trace/src/ritm.js +8 -8
  342. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +5 -4
  343. package/packages/dd-trace/src/sampler.js +41 -4
  344. package/packages/dd-trace/src/sampling_rule.js +12 -3
  345. package/packages/dd-trace/src/scope.js +1 -1
  346. package/packages/dd-trace/src/serverless.js +11 -4
  347. package/packages/dd-trace/src/service-naming/schemas/util.js +1 -1
  348. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +2 -3
  349. package/packages/dd-trace/src/span_processor.js +5 -4
  350. package/packages/dd-trace/src/span_sampler.js +4 -1
  351. package/packages/dd-trace/src/standalone/tracesource.js +2 -3
  352. package/packages/dd-trace/src/standalone/tracesource_priority_sampler.js +1 -2
  353. package/packages/dd-trace/src/startup-log.js +6 -18
  354. package/packages/dd-trace/src/supported-configurations.json +439 -0
  355. package/packages/dd-trace/src/telemetry/dependencies.js +64 -59
  356. package/packages/dd-trace/src/telemetry/logs/log-collector.js +9 -10
  357. package/packages/dd-trace/src/telemetry/metrics.js +10 -5
  358. package/packages/dd-trace/src/telemetry/send-data.js +8 -7
  359. package/packages/dd-trace/src/telemetry/telemetry.js +31 -45
  360. package/packages/dd-trace/src/tracer.js +3 -7
  361. package/packages/dd-trace/src/util.js +1 -6
  362. package/version.js +1 -0
  363. package/packages/datadog-instrumentations/src/paperplane.js +0 -77
  364. package/packages/datadog-plugin-paperplane/src/index.js +0 -25
  365. package/packages/datadog-plugin-paperplane/src/logger.js +0 -11
  366. package/packages/datadog-plugin-paperplane/src/server.js +0 -24
  367. package/packages/dd-trace/src/appsec/iast/analyzers/header-injection-analyzer.js +0 -122
  368. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/header-sensitive-analyzer.js +0 -20
@@ -1,10 +1,11 @@
1
1
  'use strict'
2
2
 
3
3
  const { createCoverageMap } = require('istanbul-lib-coverage')
4
- const { addHook, channel, AsyncResource } = require('../helpers/instrument')
4
+ const { addHook, channel } = require('../helpers/instrument')
5
5
  const shimmer = require('../../../datadog-shimmer')
6
6
  const { isMarkedAsUnskippable } = require('../../../datadog-plugin-jest/src/util')
7
7
  const log = require('../../../dd-trace/src/log')
8
+ const { getEnvironmentVariable } = require('../../../dd-trace/src/config-helper')
8
9
  const {
9
10
  getTestSuitePath,
10
11
  MOCHA_WORKER_TRACE_PAYLOAD_CODE,
@@ -37,7 +38,6 @@ const {
37
38
 
38
39
  require('./common')
39
40
 
40
- const testSessionAsyncResource = new AsyncResource('bound-anonymous-fn')
41
41
  const patched = new WeakSet()
42
42
 
43
43
  const unskippableSuites = []
@@ -65,7 +65,10 @@ const testSuiteCodeCoverageCh = channel('ci:mocha:test-suite:code-coverage')
65
65
  const libraryConfigurationCh = channel('ci:mocha:library-configuration')
66
66
  const knownTestsCh = channel('ci:mocha:known-tests')
67
67
  const skippableSuitesCh = channel('ci:mocha:test-suite:skippable')
68
+ const mochaGlobalRunCh = channel('ci:mocha:global:run')
69
+
68
70
  const testManagementTestsCh = channel('ci:mocha:test-management-tests')
71
+ const impactedTestsCh = channel('ci:mocha:modified-tests')
69
72
  const workerReportTraceCh = channel('ci:mocha:worker-report:trace')
70
73
  const testSessionStartCh = channel('ci:mocha:session:start')
71
74
  const testSessionFinishCh = channel('ci:mocha:session:finish')
@@ -99,18 +102,18 @@ function getFilteredSuites (originalSuites) {
99
102
  }
100
103
 
101
104
  function getOnStartHandler (isParallel, frameworkVersion) {
102
- return testSessionAsyncResource.bind(function () {
105
+ return function () {
103
106
  const processArgv = process.argv.slice(2).join(' ')
104
107
  const command = `mocha ${processArgv}`
105
108
  testSessionStartCh.publish({ command, frameworkVersion })
106
109
  if (!isParallel && skippedSuites.length) {
107
110
  itrSkippedSuitesCh.publish({ skippedSuites, frameworkVersion })
108
111
  }
109
- })
112
+ }
110
113
  }
111
114
 
112
115
  function getOnEndHandler (isParallel) {
113
- return testSessionAsyncResource.bind(function () {
116
+ return function () {
114
117
  let status = 'pass'
115
118
  let error
116
119
  if (this.stats) {
@@ -175,7 +178,7 @@ function getOnEndHandler (isParallel) {
175
178
  originalCoverageMap.merge(fromCoverageMapToCoverage(untestedCoverage))
176
179
  }
177
180
  testCodeCoverageLinesTotal = originalCoverageMap.getCoverageSummary().lines.pct
178
- } catch (e) {
181
+ } catch {
179
182
  // ignore errors
180
183
  }
181
184
  // restore the original coverage
@@ -195,27 +198,12 @@ function getOnEndHandler (isParallel) {
195
198
  isTestManagementEnabled: config.isTestManagementTestsEnabled,
196
199
  isParallel
197
200
  })
198
- })
201
+ }
199
202
  }
200
203
 
201
204
  function getExecutionConfiguration (runner, isParallel, onFinishRequest) {
202
- const mochaRunAsyncResource = new AsyncResource('bound-anonymous-fn')
203
-
204
- const onReceivedTestManagementTests = ({ err, testManagementTests: receivedTestManagementTests }) => {
205
- if (err) {
206
- config.testManagementTests = {}
207
- config.isTestManagementTestsEnabled = false
208
- config.testManagementAttemptToFixRetries = 0
209
- } else {
210
- config.testManagementTests = receivedTestManagementTests
211
- }
212
- if (config.isSuitesSkippingEnabled) {
213
- skippableSuitesCh.publish({
214
- onDone: mochaRunAsyncResource.bind(onReceivedSkippableSuites)
215
- })
216
- } else {
217
- onFinishRequest()
218
- }
205
+ const ctx = {
206
+ isParallel
219
207
  }
220
208
 
221
209
  const onReceivedSkippableSuites = ({ err, skippableSuites, itrCorrelationId: responseItrCorrelationId }) => {
@@ -237,9 +225,49 @@ function getExecutionConfiguration (runner, isParallel, onFinishRequest) {
237
225
 
238
226
  runner.suite.suites = suitesToRun
239
227
 
240
- skippedSuites = Array.from(filteredSuites.skippedSuites)
228
+ skippedSuites = [...filteredSuites.skippedSuites]
229
+
230
+ mochaGlobalRunCh.runStores(ctx, () => {
231
+ onFinishRequest()
232
+ })
233
+ }
241
234
 
242
- onFinishRequest()
235
+ const onReceivedImpactedTests = ({ err, modifiedTests: receivedModifiedTests }) => {
236
+ if (err) {
237
+ config.modifiedTests = []
238
+ config.isImpactedTestsEnabled = false
239
+ } else {
240
+ config.modifiedTests = receivedModifiedTests
241
+ }
242
+ if (config.isSuitesSkippingEnabled) {
243
+ ctx.onDone = onReceivedSkippableSuites
244
+ skippableSuitesCh.runStores(ctx, () => {})
245
+ } else {
246
+ mochaGlobalRunCh.runStores(ctx, () => {
247
+ onFinishRequest()
248
+ })
249
+ }
250
+ }
251
+
252
+ const onReceivedTestManagementTests = ({ err, testManagementTests: receivedTestManagementTests }) => {
253
+ if (err) {
254
+ config.testManagementTests = {}
255
+ config.isTestManagementTestsEnabled = false
256
+ config.testManagementAttemptToFixRetries = 0
257
+ } else {
258
+ config.testManagementTests = receivedTestManagementTests
259
+ }
260
+ if (config.isImpactedTestsEnabled) {
261
+ ctx.onDone = onReceivedImpactedTests
262
+ impactedTestsCh.runStores(ctx, () => {})
263
+ } else if (config.isSuitesSkippingEnabled) {
264
+ ctx.onDone = onReceivedSkippableSuites
265
+ skippableSuitesCh.runStores(ctx, () => {})
266
+ } else {
267
+ mochaGlobalRunCh.runStores(ctx, () => {
268
+ onFinishRequest()
269
+ })
270
+ }
243
271
  }
244
272
 
245
273
  const onReceivedKnownTests = ({ err, knownTests }) => {
@@ -251,55 +279,61 @@ function getExecutionConfiguration (runner, isParallel, onFinishRequest) {
251
279
  config.knownTests = knownTests
252
280
  }
253
281
  if (config.isTestManagementTestsEnabled) {
254
- testManagementTestsCh.publish({
255
- onDone: mochaRunAsyncResource.bind(onReceivedTestManagementTests)
256
- })
282
+ ctx.onDone = onReceivedTestManagementTests
283
+ testManagementTestsCh.runStores(ctx, () => {})
284
+ } if (config.isImpactedTestsEnabled) {
285
+ ctx.onDone = onReceivedImpactedTests
286
+ impactedTestsCh.runStores(ctx, () => {})
257
287
  } else if (config.isSuitesSkippingEnabled) {
258
- skippableSuitesCh.publish({
259
- onDone: mochaRunAsyncResource.bind(onReceivedSkippableSuites)
260
- })
288
+ ctx.onDone = onReceivedSkippableSuites
289
+ skippableSuitesCh.runStores(ctx, () => {})
261
290
  } else {
262
- onFinishRequest()
291
+ mochaGlobalRunCh.runStores(ctx, () => {
292
+ onFinishRequest()
293
+ })
263
294
  }
264
295
  }
265
296
 
266
297
  const onReceivedConfiguration = ({ err, libraryConfig }) => {
267
298
  if (err || !skippableSuitesCh.hasSubscribers || !knownTestsCh.hasSubscribers) {
268
- return onFinishRequest()
299
+ return mochaGlobalRunCh.runStores(ctx, () => {
300
+ onFinishRequest()
301
+ })
269
302
  }
270
-
271
303
  config.isEarlyFlakeDetectionEnabled = libraryConfig.isEarlyFlakeDetectionEnabled
272
304
  config.earlyFlakeDetectionNumRetries = libraryConfig.earlyFlakeDetectionNumRetries
273
305
  config.earlyFlakeDetectionFaultyThreshold = libraryConfig.earlyFlakeDetectionFaultyThreshold
274
306
  config.isKnownTestsEnabled = libraryConfig.isKnownTestsEnabled
275
307
  config.isTestManagementTestsEnabled = libraryConfig.isTestManagementEnabled
276
308
  config.testManagementAttemptToFixRetries = libraryConfig.testManagementAttemptToFixRetries
309
+ config.isImpactedTestsEnabled = libraryConfig.isImpactedTestsEnabled
277
310
  // ITR and auto test retries are not supported in parallel mode yet
278
311
  config.isSuitesSkippingEnabled = !isParallel && libraryConfig.isSuitesSkippingEnabled
279
312
  config.isFlakyTestRetriesEnabled = !isParallel && libraryConfig.isFlakyTestRetriesEnabled
280
313
  config.flakyTestRetriesCount = !isParallel && libraryConfig.flakyTestRetriesCount
281
314
 
282
315
  if (config.isKnownTestsEnabled) {
283
- knownTestsCh.publish({
284
- onDone: mochaRunAsyncResource.bind(onReceivedKnownTests)
285
- })
316
+ ctx.onDone = onReceivedKnownTests
317
+ knownTestsCh.runStores(ctx, () => {})
286
318
  } else if (config.isTestManagementTestsEnabled) {
287
- testManagementTestsCh.publish({
288
- onDone: mochaRunAsyncResource.bind(onReceivedTestManagementTests)
289
- })
319
+ ctx.onDone = onReceivedTestManagementTests
320
+ testManagementTestsCh.runStores(ctx, () => {})
321
+ } else if (config.isImpactedTestsEnabled) {
322
+ ctx.onDone = onReceivedImpactedTests
323
+ impactedTestsCh.runStores(ctx, () => {})
290
324
  } else if (config.isSuitesSkippingEnabled) {
291
- skippableSuitesCh.publish({
292
- onDone: mochaRunAsyncResource.bind(onReceivedSkippableSuites)
293
- })
325
+ ctx.onDone = onReceivedSkippableSuites
326
+ skippableSuitesCh.runStores(ctx, () => {})
294
327
  } else {
295
- onFinishRequest()
328
+ mochaGlobalRunCh.runStores(ctx, () => {
329
+ onFinishRequest()
330
+ })
296
331
  }
297
332
  }
298
333
 
299
- libraryConfigurationCh.publish({
300
- onDone: mochaRunAsyncResource.bind(onReceivedConfiguration),
301
- isParallel
302
- })
334
+ ctx.onDone = onReceivedConfiguration
335
+
336
+ libraryConfigurationCh.runStores(ctx, () => {})
303
337
  }
304
338
 
305
339
  // In this hook we delay the execution with options.delay to grab library configuration,
@@ -312,7 +346,7 @@ addHook({
312
346
  }, (Mocha) => {
313
347
  shimmer.wrap(Mocha.prototype, 'run', run => function () {
314
348
  // Workers do not need to request any data, just run the tests
315
- if (!testFinishCh.hasSubscribers || process.env.MOCHA_WORKER_ID || this.options.parallel) {
349
+ if (!testFinishCh.hasSubscribers || getEnvironmentVariable('MOCHA_WORKER_ID') || this.options.parallel) {
316
350
  return run.apply(this, arguments)
317
351
  }
318
352
 
@@ -441,7 +475,7 @@ addHook({
441
475
  itrCorrelationId
442
476
  }
443
477
  testFileToSuiteCtx.set(suite.file, ctx)
444
- testSuiteStartCh.runStores(ctx, () => { })
478
+ testSuiteStartCh.runStores(ctx, () => {})
445
479
  }
446
480
  })
447
481
 
@@ -485,9 +519,9 @@ addHook({
485
519
 
486
520
  const ctx = testFileToSuiteCtx.get(suite.file)
487
521
  if (ctx) {
488
- testSuiteFinishCh.publish({ status, ...ctx.currentStore }, () => { })
522
+ testSuiteFinishCh.publish({ status, ...ctx.currentStore }, () => {})
489
523
  } else {
490
- log.warn(() => `No AsyncResource found for suite ${suite.file}`)
524
+ log.warn(() => `No ctx found for suite ${suite.file}`)
491
525
  }
492
526
  })
493
527
 
@@ -505,6 +539,15 @@ addHook({
505
539
  file: 'lib/runnable.js'
506
540
  }, (runnablePackage) => runnableWrapper(runnablePackage, config))
507
541
 
542
+ function onMessage (message) {
543
+ if (Array.isArray(message)) {
544
+ const [messageCode, payload] = message
545
+ if (messageCode === MOCHA_WORKER_TRACE_PAYLOAD_CODE) {
546
+ workerReportTraceCh.publish(payload)
547
+ }
548
+ }
549
+ }
550
+
508
551
  // Only used in parallel mode (--parallel flag is passed)
509
552
  // Used to generate suite events and receive test payloads from workers
510
553
  addHook({
@@ -523,42 +566,33 @@ addHook({
523
566
  return exec.apply(this, arguments)
524
567
  }
525
568
  const [testSuiteAbsolutePath] = path
526
- const testSuiteContext = { }
527
-
528
- function onMessage (message) {
529
- if (Array.isArray(message)) {
530
- const [messageCode, payload] = message
531
- if (messageCode === MOCHA_WORKER_TRACE_PAYLOAD_CODE) {
532
- workerReportTraceCh.publish(payload)
533
- }
534
- }
535
- }
569
+ const testSuiteContext = {}
536
570
 
537
571
  this.worker.on('message', onMessage)
538
572
 
539
573
  testSuiteContext.testSuiteAbsolutePath = testSuiteAbsolutePath
540
- testSuiteStartCh.runStores(testSuiteContext, () => { })
574
+ testSuiteStartCh.runStores(testSuiteContext, () => {})
541
575
 
542
576
  try {
543
577
  const promise = exec.apply(this, arguments)
544
578
  promise.then(
545
579
  (result) => {
546
580
  const status = result.failureCount === 0 ? 'pass' : 'fail'
547
- testSuiteFinishCh.publish({ status, ...testSuiteContext.currentStore }, () => { })
581
+ testSuiteFinishCh.publish({ status, ...testSuiteContext.currentStore }, () => {})
548
582
  this.worker.off('message', onMessage)
549
583
  },
550
584
  (err) => {
551
585
  testSuiteContext.error = err
552
- testSuiteErrorCh.runStores(testSuiteContext, () => { })
553
- testSuiteFinishCh.publish({ status: 'fail', ...testSuiteContext.currentStore }, () => { })
586
+ testSuiteErrorCh.runStores(testSuiteContext, () => {})
587
+ testSuiteFinishCh.publish({ status: 'fail', ...testSuiteContext.currentStore }, () => {})
554
588
  this.worker.off('message', onMessage)
555
589
  }
556
590
  )
557
591
  return promise
558
592
  } catch (err) {
559
593
  testSuiteContext.error = err
560
- testSuiteErrorCh.runStores(testSuiteContext, () => { })
561
- testSuiteFinishCh.publish({ status: 'fail', ...testSuiteContext.currentStore }, () => { })
594
+ testSuiteErrorCh.runStores(testSuiteContext, () => {})
595
+ testSuiteFinishCh.publish({ status: 'fail', ...testSuiteContext.currentStore }, () => {})
562
596
  this.worker.off('message', onMessage)
563
597
  throw err
564
598
  }
@@ -616,7 +650,10 @@ addHook({
616
650
  const { BufferedWorkerPool } = BufferedWorkerPoolPackage
617
651
 
618
652
  shimmer.wrap(BufferedWorkerPool.prototype, 'run', run => async function (testSuiteAbsolutePath, workerArgs) {
619
- if (!testFinishCh.hasSubscribers || (!config.isKnownTestsEnabled && !config.isTestManagementTestsEnabled)) {
653
+ if (!testFinishCh.hasSubscribers ||
654
+ (!config.isKnownTestsEnabled &&
655
+ !config.isTestManagementTestsEnabled &&
656
+ !config.isImpactedTestsEnabled)) {
620
657
  return run.apply(this, arguments)
621
658
  }
622
659
 
@@ -649,6 +686,12 @@ addHook({
649
686
  }
650
687
  }
651
688
 
689
+ if (config.isImpactedTestsEnabled) {
690
+ const testSuiteImpactedTests = config.modifiedTests || {}
691
+ newWorkerArgs._ddIsImpactedTestsEnabled = true
692
+ newWorkerArgs._ddModifiedTests = testSuiteImpactedTests
693
+ }
694
+
652
695
  // We pass the known tests for the test file to the worker
653
696
  const testFileResult = await run.apply(
654
697
  this,
@@ -669,10 +712,10 @@ addHook({
669
712
  const testFullName = getTestFullName(test)
670
713
  const tests = newTests[testFullName]
671
714
 
672
- if (!tests) {
673
- newTests[testFullName] = [test]
674
- } else {
715
+ if (tests) {
675
716
  tests.push(test)
717
+ } else {
718
+ newTests[testFullName] = [test]
676
719
  }
677
720
  }
678
721
  // `testsQuarantined` is filled in the worker process, so we need to use the test results to fill it here too.
@@ -18,7 +18,7 @@ const testRetryCh = channel('ci:mocha:test:retry')
18
18
  const errorCh = channel('ci:mocha:test:error')
19
19
  const skipCh = channel('ci:mocha:test:skip')
20
20
  const testFnCh = channel('ci:mocha:test:fn')
21
-
21
+ const isModifiedCh = channel('ci:mocha:test:is-modified')
22
22
  // suite channels
23
23
  const testSuiteErrorCh = channel('ci:mocha:test-suite:error')
24
24
 
@@ -209,7 +209,8 @@ function getOnTestHandler (isMain) {
209
209
  _ddIsEfdRetry: isEfdRetry,
210
210
  _ddIsAttemptToFix: isAttemptToFix,
211
211
  _ddIsDisabled: isDisabled,
212
- _ddIsQuarantined: isQuarantined
212
+ _ddIsQuarantined: isQuarantined,
213
+ _ddIsModified: isModified
213
214
  } = test
214
215
 
215
216
  const testName = removeEfdStringFromTestName(removeAttemptToFixStringFromTestName(test.fullTitle()))
@@ -230,6 +231,7 @@ function getOnTestHandler (isMain) {
230
231
  testInfo.isAttemptToFix = isAttemptToFix
231
232
  testInfo.isDisabled = isDisabled
232
233
  testInfo.isQuarantined = isQuarantined
234
+ testInfo.isModified = isModified
233
235
  // We want to store the result of the new tests
234
236
  if (isNew) {
235
237
  const testFullName = getTestFullName(test)
@@ -246,7 +248,7 @@ function getOnTestHandler (isMain) {
246
248
 
247
249
  const ctx = testInfo
248
250
  testToContext.set(test.fn, ctx)
249
- testStartCh.runStores(ctx, () => { })
251
+ testStartCh.runStores(ctx, () => {})
250
252
  }
251
253
  }
252
254
 
@@ -271,17 +273,17 @@ function getOnTestEndHandler (config) {
271
273
 
272
274
  const testName = getTestFullName(test)
273
275
 
274
- if (!testsStatuses.get(testName)) {
275
- testsStatuses.set(testName, [status])
276
- } else {
276
+ if (testsStatuses.get(testName)) {
277
277
  testsStatuses.get(testName).push(status)
278
+ } else {
279
+ testsStatuses.set(testName, [status])
278
280
  }
279
281
  const testStatuses = testsStatuses.get(testName)
280
282
 
281
283
  const isLastAttempt = testStatuses.length === config.testManagementAttemptToFixRetries + 1
282
284
 
283
285
  if (test._ddIsAttemptToFix && isLastAttempt) {
284
- if (testStatuses.some(status => status === 'fail')) {
286
+ if (testStatuses.includes('fail')) {
285
287
  attemptToFixFailed = true
286
288
  }
287
289
  if (testStatuses.every(status => status === 'fail')) {
@@ -351,12 +353,12 @@ function getOnFailHandler (isMain) {
351
353
  if (isHook) {
352
354
  err.message = `${testOrHook.fullTitle()}: ${err.message}`
353
355
  testContext.err = err
354
- errorCh.runStores(testContext, () => { })
356
+ errorCh.runStores(testContext, () => {})
355
357
  // if it's a hook and it has failed, 'test end' will not be called
356
358
  testFinishCh.publish({ status: 'fail', hasBeenRetried: isMochaRetry(test), ...testContext.currentStore })
357
359
  } else {
358
360
  testContext.err = err
359
- errorCh.runStores(testContext, () => { })
361
+ errorCh.runStores(testContext, () => {})
360
362
  }
361
363
  }
362
364
 
@@ -370,7 +372,7 @@ function getOnFailHandler (isMain) {
370
372
  )
371
373
  testSuiteError.stack = err.stack
372
374
  testSuiteContext.error = testSuiteError
373
- testSuiteErrorCh.runStores(testSuiteContext, () => { })
375
+ testSuiteErrorCh.runStores(testSuiteContext, () => {})
374
376
  }
375
377
  }
376
378
  }
@@ -420,7 +422,7 @@ function getOnPendingHandler () {
420
422
  } else {
421
423
  testToContext.set(test, testCtx)
422
424
  }
423
- skipCh.runStores(testCtx, () => { })
425
+ skipCh.runStores(testCtx, () => {})
424
426
  }
425
427
  }
426
428
  }
@@ -452,12 +454,34 @@ function getRunTestsWrapper (runTests, config) {
452
454
  })
453
455
  }
454
456
 
457
+ if (config.isImpactedTestsEnabled) {
458
+ suite.tests.forEach((test) => {
459
+ isModifiedCh.publish({
460
+ modifiedTests: config.modifiedTests,
461
+ file: suite.file,
462
+ onDone: (isModified) => {
463
+ if (isModified) {
464
+ test._ddIsModified = true
465
+ if (!test.isPending() && !test._ddIsAttemptToFix && config.isEarlyFlakeDetectionEnabled) {
466
+ retryTest(
467
+ test,
468
+ config.earlyFlakeDetectionNumRetries,
469
+ addEfdStringToTestName,
470
+ ['_ddIsModified', '_ddIsEfdRetry']
471
+ )
472
+ }
473
+ }
474
+ }
475
+ })
476
+ })
477
+ }
478
+
455
479
  if (config.isKnownTestsEnabled) {
456
480
  // by the time we reach `this.on('test')`, it is too late. We need to add retries here
457
481
  suite.tests.forEach(test => {
458
482
  if (!test.isPending() && isNewTest(test, config.knownTests)) {
459
483
  test._ddIsNew = true
460
- if (config.isEarlyFlakeDetectionEnabled) {
484
+ if (config.isEarlyFlakeDetectionEnabled && !test._ddIsAttemptToFix && !test._ddIsModified) {
461
485
  retryTest(
462
486
  test,
463
487
  config.earlyFlakeDetectionNumRetries,
@@ -34,6 +34,12 @@ addHook({
34
34
  delete this.options._ddEfdNumRetries
35
35
  delete this.options._ddIsKnownTestsEnabled
36
36
  }
37
+ if (this.options._ddIsImpactedTestsEnabled) {
38
+ config.isImpactedTestsEnabled = true
39
+ config.modifiedTests = this.options._ddModifiedTests
40
+ delete this.options._ddIsImpactedTestsEnabled
41
+ delete this.options._ddModifiedTests
42
+ }
37
43
  if (this.options._ddIsTestManagementTestsEnabled) {
38
44
  config.isTestManagementTestsEnabled = true
39
45
  // TODO: attempt to fix does not work in parallel mode yet
@@ -1,4 +1,6 @@
1
- if (process.env.MOCHA_WORKER_ID) {
1
+ const { getEnvironmentVariable } = require('../../dd-trace/src/config-helper')
2
+
3
+ if (getEnvironmentVariable('MOCHA_WORKER_ID')) {
2
4
  require('./mocha/worker')
3
5
  } else {
4
6
  require('./mocha/main')
@@ -204,7 +204,7 @@ function instrumentPromise (operation, command, ctx, args, server, ns, ops, opti
204
204
  errorCh.publish(err)
205
205
  finishCh.publish()
206
206
 
207
- return Promise.reject(err)
207
+ throw err
208
208
  })
209
209
  })
210
210
  }
@@ -1,10 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const {
4
- channel,
5
- addHook,
6
- AsyncResource
7
- } = require('./helpers/instrument')
3
+ const { channel, addHook } = require('./helpers/instrument')
8
4
  const shimmer = require('../../datadog-shimmer')
9
5
 
10
6
  addHook({ name: 'mysql', file: 'lib/Connection.js', versions: ['>=2'] }, Connection => {
@@ -19,43 +15,38 @@ addHook({ name: 'mysql', file: 'lib/Connection.js', versions: ['>=2'] }, Connect
19
15
 
20
16
  const sql = arguments[0].sql || arguments[0]
21
17
  const conf = this.config
22
- const payload = { sql, conf }
23
-
24
- const callbackResource = new AsyncResource('bound-anonymous-fn')
25
- const asyncResource = new AsyncResource('bound-anonymous-fn')
26
-
27
- return asyncResource.runInAsyncScope(() => {
28
- startCh.publish(payload)
18
+ const ctx = { sql, conf }
29
19
 
20
+ return startCh.runStores(ctx, () => {
30
21
  if (arguments[0].sql) {
31
- arguments[0].sql = payload.sql
22
+ arguments[0].sql = ctx.sql
32
23
  } else {
33
- arguments[0] = payload.sql
24
+ arguments[0] = ctx.sql
34
25
  }
26
+
35
27
  try {
36
28
  const res = query.apply(this, arguments)
37
29
 
38
30
  if (res._callback) {
39
- const cb = callbackResource.bind(res._callback)
40
- res._callback = shimmer.wrapFunction(cb, cb => asyncResource.bind(function (error, result) {
31
+ const cb = res._callback
32
+ res._callback = shimmer.wrapFunction(cb, cb => function (error, result) {
41
33
  if (error) {
42
- errorCh.publish(error)
34
+ ctx.error = error
35
+ errorCh.publish(ctx)
43
36
  }
44
- finishCh.publish(result)
37
+ ctx.result = result
45
38
 
46
- return cb.apply(this, arguments)
47
- }))
48
- } else {
49
- const cb = asyncResource.bind(function () {
50
- finishCh.publish(undefined)
39
+ return finishCh.runStores(ctx, cb, this, error, result)
51
40
  })
52
- res.on('end', cb)
41
+ } else {
42
+ res.on('end', () => finishCh.publish(ctx))
53
43
  }
54
44
 
55
45
  return res
56
46
  } catch (err) {
57
47
  err.stack // trigger getting the stack at the original throwing point
58
- errorCh.publish(err)
48
+ ctx.error = err
49
+ errorCh.publish(ctx)
59
50
 
60
51
  throw err
61
52
  }
@@ -66,11 +57,20 @@ addHook({ name: 'mysql', file: 'lib/Connection.js', versions: ['>=2'] }, Connect
66
57
  })
67
58
 
68
59
  addHook({ name: 'mysql', file: 'lib/Pool.js', versions: ['>=2'] }, Pool => {
60
+ const connectionStartCh = channel('apm:mysql:connection:start')
61
+ const connectionFinishCh = channel('apm:mysql:connection:finish')
69
62
  const startPoolQueryCh = channel('datadog:mysql:pool:query:start')
70
63
  const finishPoolQueryCh = channel('datadog:mysql:pool:query:finish')
71
64
 
72
65
  shimmer.wrap(Pool.prototype, 'getConnection', getConnection => function (cb) {
73
- arguments[0] = AsyncResource.bind(cb)
66
+ arguments[0] = function () {
67
+ return connectionFinishCh.runStores(ctx, cb, this, ...arguments)
68
+ }
69
+
70
+ const ctx = {}
71
+
72
+ connectionStartCh.publish(ctx)
73
+
74
74
  return getConnection.apply(this, arguments)
75
75
  })
76
76
 
@@ -79,22 +79,15 @@ addHook({ name: 'mysql', file: 'lib/Pool.js', versions: ['>=2'] }, Pool => {
79
79
  return query.apply(this, arguments)
80
80
  }
81
81
 
82
- const asyncResource = new AsyncResource('bound-anonymous-fn')
83
-
84
82
  const sql = arguments[0].sql || arguments[0]
83
+ const ctx = { sql }
84
+ const finish = () => finishPoolQueryCh.publish(ctx)
85
85
 
86
- return asyncResource.runInAsyncScope(() => {
87
- startPoolQueryCh.publish({ sql })
88
-
89
- const finish = asyncResource.bind(function () {
90
- finishPoolQueryCh.publish()
91
- })
92
-
86
+ return startPoolQueryCh.runStores(ctx, () => {
93
87
  const cb = arguments[arguments.length - 1]
94
88
  if (typeof cb === 'function') {
95
89
  arguments[arguments.length - 1] = shimmer.wrapFunction(cb, cb => function () {
96
- finish()
97
- return cb.apply(this, arguments)
90
+ return finishPoolQueryCh.runStores(ctx, cb, this, ...arguments)
98
91
  })
99
92
  }
100
93