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,9 +1,10 @@
1
1
  'use strict'
2
2
  const { createCoverageMap } = require('istanbul-lib-coverage')
3
3
 
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 log = require('../../dd-trace/src/log')
7
+ const { getEnvironmentVariable } = require('../../dd-trace/src/config-helper')
7
8
 
8
9
  const testStartCh = channel('ci:cucumber:test:start')
9
10
  const testRetryCh = channel('ci:cucumber:test:retry')
@@ -24,6 +25,8 @@ const skippableSuitesCh = channel('ci:cucumber:test-suite:skippable')
24
25
  const sessionStartCh = channel('ci:cucumber:session:start')
25
26
  const sessionFinishCh = channel('ci:cucumber:session:finish')
26
27
  const testManagementTestsCh = channel('ci:cucumber:test-management-tests')
28
+ const impactedTestsCh = channel('ci:cucumber:modified-tests')
29
+ const isModifiedCh = channel('ci:cucumber:is-modified-test')
27
30
 
28
31
  const workerReportTraceCh = channel('ci:cucumber:worker-report:trace')
29
32
 
@@ -42,7 +45,7 @@ const {
42
45
  } = require('../../dd-trace/src/plugins/util/test')
43
46
 
44
47
  const isMarkedAsUnskippable = (pickle) => {
45
- return !!pickle.tags.find(tag => tag.name === '@datadog:unskippable')
48
+ return pickle.tags.some(tag => tag.name === '@datadog:unskippable')
46
49
  }
47
50
 
48
51
  // We'll preserve the original coverage here
@@ -55,13 +58,12 @@ const lastStatusByPickleId = new Map()
55
58
  const numRetriesByPickleId = new Map()
56
59
  const numAttemptToCtx = new Map()
57
60
  const newTestsByTestFullname = new Map()
61
+ const modifiedTestsByPickleId = new Map()
58
62
 
59
63
  let eventDataCollector = null
60
64
  let pickleByFile = {}
61
65
  const pickleResultByFile = {}
62
66
 
63
- const sessionAsyncResource = new AsyncResource('bound-anonymous-fn')
64
-
65
67
  let skippableSuites = []
66
68
  let itrCorrelationId = ''
67
69
  let isForcedToRun = false
@@ -74,15 +76,17 @@ let isEarlyFlakeDetectionFaulty = false
74
76
  let isFlakyTestRetriesEnabled = false
75
77
  let isKnownTestsEnabled = false
76
78
  let isTestManagementTestsEnabled = false
79
+ let isImpactedTestsEnabled = false
77
80
  let testManagementAttemptToFixRetries = 0
78
81
  let testManagementTests = {}
82
+ let modifiedTests = {}
79
83
  let numTestRetries = 0
80
84
  let knownTests = []
81
85
  let skippedSuites = []
82
86
  let isSuitesSkipped = false
83
87
 
84
88
  function getSuiteStatusFromTestStatuses (testStatuses) {
85
- if (testStatuses.some(status => status === 'fail')) {
89
+ if (testStatuses.includes('fail')) {
86
90
  return 'fail'
87
91
  }
88
92
  if (testStatuses.every(status => status === 'skip')) {
@@ -133,7 +137,7 @@ function getTestStatusFromRetries (testStatuses) {
133
137
  if (testStatuses.every(status => status === 'fail')) {
134
138
  return 'fail'
135
139
  }
136
- if (testStatuses.some(status => status === 'pass')) {
140
+ if (testStatuses.includes('pass')) {
137
141
  return 'pass'
138
142
  }
139
143
  return 'pass'
@@ -155,9 +159,7 @@ function getErrorFromCucumberResult (cucumberResult) {
155
159
 
156
160
  function getChannelPromise (channelToPublishTo, isParallel = false) {
157
161
  return new Promise(resolve => {
158
- sessionAsyncResource.runInAsyncScope(() => {
159
- channelToPublishTo.publish({ onDone: resolve, isParallel })
160
- })
162
+ channelToPublishTo.publish({ onDone: resolve, isParallel })
161
163
  })
162
164
  }
163
165
 
@@ -242,11 +244,11 @@ function wrapRun (pl, isLatestVersion) {
242
244
  testName: this.pickle.name,
243
245
  testFileAbsolutePath,
244
246
  testSourceLine,
245
- isParallel: !!process.env.CUCUMBER_WORKER_ID
247
+ isParallel: !!getEnvironmentVariable('CUCUMBER_WORKER_ID')
246
248
  }
247
249
  const ctx = testStartPayload
248
250
  numAttemptToCtx.set(numAttempt, ctx)
249
- testStartCh.runStores(ctx, () => { })
251
+ testStartCh.runStores(ctx, () => {})
250
252
  const promises = {}
251
253
  try {
252
254
  this.eventBroadcaster.on('envelope', shimmer.wrapFunction(null, () => async (testCase) => {
@@ -258,7 +260,7 @@ function wrapRun (pl, isLatestVersion) {
258
260
  try {
259
261
  const cucumberResult = this.getWorstStepResult()
260
262
  error = getErrorFromCucumberResult(cucumberResult)
261
- } catch (e) {
263
+ } catch {
262
264
  // ignore error
263
265
  }
264
266
 
@@ -276,7 +278,7 @@ function wrapRun (pl, isLatestVersion) {
276
278
  const newCtx = { ...testStartPayload, promises }
277
279
  numAttemptToCtx.set(numAttempt, newCtx)
278
280
 
279
- testStartCh.runStores(newCtx, () => { })
281
+ testStartCh.runStores(newCtx, () => {})
280
282
  }
281
283
  }
282
284
  }))
@@ -305,6 +307,7 @@ function wrapRun (pl, isLatestVersion) {
305
307
  let hasFailedAttemptToFix = false
306
308
  let isDisabled = false
307
309
  let isQuarantined = false
310
+ let isModified = false
308
311
 
309
312
  if (isTestManagementTestsEnabled) {
310
313
  const testSuitePath = getTestSuitePath(testFileAbsolutePath, process.cwd())
@@ -329,10 +332,17 @@ function wrapRun (pl, isLatestVersion) {
329
332
  }
330
333
  }
331
334
 
332
- if (isKnownTestsEnabled && status !== 'skip' && !isAttemptToFix) {
333
- const numRetries = numRetriesByPickleId.get(this.pickle.id)
335
+ const numRetries = numRetriesByPickleId.get(this.pickle.id)
334
336
 
337
+ if (isImpactedTestsEnabled) {
338
+ isModified = modifiedTestsByPickleId.get(this.pickle.id)
339
+ }
340
+
341
+ if (isKnownTestsEnabled && status !== 'skip') {
335
342
  isNew = numRetries !== undefined
343
+ }
344
+
345
+ if (isNew || isModified) {
336
346
  isEfdRetry = numRetries > 0
337
347
  }
338
348
 
@@ -357,6 +367,7 @@ function wrapRun (pl, isLatestVersion) {
357
367
  hasFailedAttemptToFix,
358
368
  isDisabled,
359
369
  isQuarantined,
370
+ isModified,
360
371
  ...attemptCtx.currentStore
361
372
  })
362
373
  })
@@ -451,14 +462,15 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
451
462
  isKnownTestsEnabled = configurationResponse.libraryConfig?.isKnownTestsEnabled
452
463
  isTestManagementTestsEnabled = configurationResponse.libraryConfig?.isTestManagementEnabled
453
464
  testManagementAttemptToFixRetries = configurationResponse.libraryConfig?.testManagementAttemptToFixRetries
465
+ isImpactedTestsEnabled = configurationResponse.libraryConfig?.isImpactedTestsEnabled
454
466
 
455
467
  if (isKnownTestsEnabled) {
456
468
  const knownTestsResponse = await getChannelPromise(knownTestsCh)
457
- if (!knownTestsResponse.err) {
458
- knownTests = knownTestsResponse.knownTests
459
- } else {
469
+ if (knownTestsResponse.err) {
460
470
  isEarlyFlakeDetectionEnabled = false
461
471
  isKnownTestsEnabled = false
472
+ } else {
473
+ knownTests = knownTestsResponse.knownTests
462
474
  }
463
475
  }
464
476
 
@@ -488,7 +500,7 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
488
500
  this.pickleIds = picklesToRun
489
501
  }
490
502
 
491
- skippedSuites = Array.from(filteredPickles.skippedSuites)
503
+ skippedSuites = [...filteredPickles.skippedSuites]
492
504
  itrCorrelationId = skippableResponse.itrCorrelationId
493
505
  }
494
506
  }
@@ -510,23 +522,28 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
510
522
 
511
523
  if (isTestManagementTestsEnabled) {
512
524
  const testManagementTestsResponse = await getChannelPromise(testManagementTestsCh)
513
- if (!testManagementTestsResponse.err) {
514
- testManagementTests = testManagementTestsResponse.testManagementTests
515
- } else {
525
+ if (testManagementTestsResponse.err) {
516
526
  isTestManagementTestsEnabled = false
527
+ } else {
528
+ testManagementTests = testManagementTestsResponse.testManagementTests
529
+ }
530
+ }
531
+
532
+ if (isImpactedTestsEnabled) {
533
+ const impactedTestsResponse = await getChannelPromise(impactedTestsCh)
534
+ if (!impactedTestsResponse.err) {
535
+ modifiedTests = impactedTestsResponse.modifiedTests
517
536
  }
518
537
  }
519
538
 
520
539
  const processArgv = process.argv.slice(2).join(' ')
521
- const command = process.env.npm_lifecycle_script || `cucumber-js ${processArgv}`
540
+ const command = getEnvironmentVariable('npm_lifecycle_script') || `cucumber-js ${processArgv}`
522
541
 
523
542
  if (isFlakyTestRetriesEnabled && !options.retry && numTestRetries > 0) {
524
543
  options.retry = numTestRetries
525
544
  }
526
545
 
527
- sessionAsyncResource.runInAsyncScope(() => {
528
- sessionStartCh.publish({ command, frameworkVersion })
529
- })
546
+ sessionStartCh.publish({ command, frameworkVersion })
530
547
 
531
548
  if (!errorSkippableRequest && skippedSuites.length) {
532
549
  itrSkippedSuitesCh.publish({ skippedSuites, frameworkVersion })
@@ -547,26 +564,24 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
547
564
  originalCoverageMap.merge(fromCoverageMapToCoverage(untestedCoverage))
548
565
  }
549
566
  testCodeCoverageLinesTotal = originalCoverageMap.getCoverageSummary().lines.pct
550
- } catch (e) {
567
+ } catch {
551
568
  // ignore errors
552
569
  }
553
570
  // restore the original coverage
554
571
  global.__coverage__ = fromCoverageMapToCoverage(originalCoverageMap)
555
572
  }
556
573
 
557
- sessionAsyncResource.runInAsyncScope(() => {
558
- sessionFinishCh.publish({
559
- status: success ? 'pass' : 'fail',
560
- isSuitesSkipped,
561
- testCodeCoverageLinesTotal,
562
- numSkippedSuites: skippedSuites.length,
563
- hasUnskippableSuites: isUnskippable,
564
- hasForcedToRunSuites: isForcedToRun,
565
- isEarlyFlakeDetectionEnabled,
566
- isEarlyFlakeDetectionFaulty,
567
- isTestManagementTestsEnabled,
568
- isParallel
569
- })
574
+ sessionFinishCh.publish({
575
+ status: success ? 'pass' : 'fail',
576
+ isSuitesSkipped,
577
+ testCodeCoverageLinesTotal,
578
+ numSkippedSuites: skippedSuites.length,
579
+ hasUnskippableSuites: isUnskippable,
580
+ hasForcedToRunSuites: isForcedToRun,
581
+ isEarlyFlakeDetectionEnabled,
582
+ isEarlyFlakeDetectionFaulty,
583
+ isTestManagementTestsEnabled,
584
+ isParallel
570
585
  })
571
586
  eventDataCollector = null
572
587
  return success
@@ -577,12 +592,15 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
577
592
  // Handles EFD in both the main process and the worker process.
578
593
  function getWrappedRunTestCase (runTestCaseFunction, isNewerCucumberVersion = false, isWorker = false) {
579
594
  return async function () {
580
- let pickle
581
- if (isNewerCucumberVersion) {
582
- pickle = arguments[0].pickle
583
- } else {
584
- pickle = this.eventDataCollector.getPickle(arguments[0])
585
- }
595
+ const pickle = isNewerCucumberVersion
596
+ ? arguments[0].pickle
597
+ : this.eventDataCollector.getPickle(arguments[0])
598
+ const testCase = isNewerCucumberVersion
599
+ ? arguments[0].testCase
600
+ : arguments[1]
601
+ const gherkinDocument = isNewerCucumberVersion
602
+ ? arguments[0].gherkinDocument
603
+ : this.eventDataCollector.getGherkinDocument(pickle.uri)
586
604
 
587
605
  const testFileAbsolutePath = pickle.uri
588
606
  const testSuitePath = getTestSuitePath(testFileAbsolutePath, process.cwd())
@@ -604,6 +622,7 @@ function getWrappedRunTestCase (runTestCaseFunction, isNewerCucumberVersion = fa
604
622
  let isAttemptToFix = false
605
623
  let isDisabled = false
606
624
  let isQuarantined = false
625
+ let isModified = false
607
626
 
608
627
  if (isTestManagementTestsEnabled) {
609
628
  const testProperties = getTestProperties(testSuitePath, pickle.name)
@@ -616,6 +635,24 @@ function getWrappedRunTestCase (runTestCaseFunction, isNewerCucumberVersion = fa
616
635
  }
617
636
  }
618
637
 
638
+ if (isImpactedTestsEnabled) {
639
+ const setIsModified = (receivedIsModified) => { isModified = receivedIsModified }
640
+ const scenarios = gherkinDocument.feature?.children?.filter(
641
+ children => pickle.astNodeIds.includes(children.scenario.id)
642
+ ).map(scenario => scenario.scenario)
643
+ const stepIds = testCase?.testSteps?.flatMap(testStep => testStep.stepDefinitionIds)
644
+
645
+ isModifiedCh.publish({
646
+ scenarios,
647
+ testFileAbsolutePath: gherkinDocument.uri,
648
+ modifiedTests,
649
+ stepIds,
650
+ stepDefinitions: this.supportCodeLibrary.stepDefinitions,
651
+ setIsModified
652
+ })
653
+ modifiedTestsByPickleId.set(pickle.id, isModified)
654
+ }
655
+
619
656
  if (isKnownTestsEnabled && !isAttemptToFix) {
620
657
  isNew = isNewTest(testSuitePath, pickle.name)
621
658
  if (isNew) {
@@ -626,27 +663,29 @@ function getWrappedRunTestCase (runTestCaseFunction, isNewerCucumberVersion = fa
626
663
  let runTestCaseResult = await runTestCaseFunction.apply(this, arguments)
627
664
 
628
665
  const testStatuses = lastStatusByPickleId.get(pickle.id)
629
- const lastTestStatus = testStatuses[testStatuses.length - 1]
666
+ const lastTestStatus = testStatuses.at(-1)
630
667
 
631
668
  // New tests should not be marked as attempt to fix, so EFD + Attempt to fix should not be enabled at the same time
632
669
  if (isAttemptToFix && lastTestStatus !== 'skip') {
633
670
  for (let retryIndex = 0; retryIndex < testManagementAttemptToFixRetries; retryIndex++) {
634
671
  numRetriesByPickleId.set(pickle.id, retryIndex + 1)
672
+ // eslint-disable-next-line no-await-in-loop
635
673
  runTestCaseResult = await runTestCaseFunction.apply(this, arguments)
636
674
  }
637
675
  }
638
676
 
639
677
  // If it's a new test and it hasn't been skipped, we run it again
640
- if (isEarlyFlakeDetectionEnabled && lastTestStatus !== 'skip' && isNew) {
678
+ if (isEarlyFlakeDetectionEnabled && lastTestStatus !== 'skip' && (isNew || isModified)) {
641
679
  for (let retryIndex = 0; retryIndex < earlyFlakeDetectionNumRetries; retryIndex++) {
642
680
  numRetriesByPickleId.set(pickle.id, retryIndex + 1)
681
+ // eslint-disable-next-line no-await-in-loop
643
682
  runTestCaseResult = await runTestCaseFunction.apply(this, arguments)
644
683
  }
645
684
  }
646
685
  let testStatus = lastTestStatus
647
686
  let shouldBePassedByEFD = false
648
687
  let shouldBePassedByTestManagement = false
649
- if (isNew && isEarlyFlakeDetectionEnabled) {
688
+ if ((isNew || isModified) && isEarlyFlakeDetectionEnabled) {
650
689
  /**
651
690
  * If Early Flake Detection (EFD) is enabled the logic is as follows:
652
691
  * - If all attempts for a test are failing, the test has failed and we will let the test process fail.
@@ -667,10 +706,10 @@ function getWrappedRunTestCase (runTestCaseFunction, isNewerCucumberVersion = fa
667
706
  shouldBePassedByTestManagement = true
668
707
  }
669
708
 
670
- if (!pickleResultByFile[testFileAbsolutePath]) {
671
- pickleResultByFile[testFileAbsolutePath] = [testStatus]
672
- } else {
709
+ if (pickleResultByFile[testFileAbsolutePath]) {
673
710
  pickleResultByFile[testFileAbsolutePath].push(testStatus)
711
+ } else {
712
+ pickleResultByFile[testFileAbsolutePath] = [testStatus]
674
713
  }
675
714
 
676
715
  // If it's a worker, suite events are handled in `getWrappedParseWorkerMessage`
@@ -694,7 +733,7 @@ function getWrappedRunTestCase (runTestCaseFunction, isNewerCucumberVersion = fa
694
733
  testSuiteFinishCh.publish({ status: testSuiteStatus, testSuitePath })
695
734
  }
696
735
 
697
- if (isNewerCucumberVersion && isEarlyFlakeDetectionEnabled && isNew) {
736
+ if (isNewerCucumberVersion && isEarlyFlakeDetectionEnabled && (isNew || isModified)) {
698
737
  return shouldBePassedByEFD
699
738
  }
700
739
 
@@ -714,20 +753,12 @@ function getWrappedParseWorkerMessage (parseWorkerMessageFunction, isNewVersion)
714
753
  if (Array.isArray(message)) {
715
754
  const [messageCode, payload] = message
716
755
  if (messageCode === CUCUMBER_WORKER_TRACE_PAYLOAD_CODE) {
717
- sessionAsyncResource.runInAsyncScope(() => {
718
- workerReportTraceCh.publish(payload)
719
- })
756
+ workerReportTraceCh.publish(payload)
720
757
  return
721
758
  }
722
759
  }
723
760
 
724
- let envelope
725
-
726
- if (isNewVersion) {
727
- envelope = message.envelope
728
- } else {
729
- envelope = message.jsonEnvelope
730
- }
761
+ const envelope = isNewVersion ? message.envelope : message.jsonEnvelope
731
762
 
732
763
  if (!envelope) {
733
764
  return parseWorkerMessageFunction.apply(this, arguments)
@@ -737,7 +768,7 @@ function getWrappedParseWorkerMessage (parseWorkerMessageFunction, isNewVersion)
737
768
  if (typeof parsed === 'string') {
738
769
  try {
739
770
  parsed = JSON.parse(envelope)
740
- } catch (e) {
771
+ } catch {
741
772
  // ignore errors and continue
742
773
  return parseWorkerMessageFunction.apply(this, arguments)
743
774
  }
@@ -790,11 +821,11 @@ function getWrappedParseWorkerMessage (parseWorkerMessageFunction, isNewVersion)
790
821
  if (isEarlyFlakeDetectionEnabled && isNew) {
791
822
  const testFullname = `${pickle.uri}:${pickle.name}`
792
823
  let testStatuses = newTestsByTestFullname.get(testFullname)
793
- if (!testStatuses) {
824
+ if (testStatuses) {
825
+ testStatuses.push(status)
826
+ } else {
794
827
  testStatuses = [status]
795
828
  newTestsByTestFullname.set(testFullname, testStatuses)
796
- } else {
797
- testStatuses.push(status)
798
829
  }
799
830
  // We have finished all retries
800
831
  if (testStatuses.length === earlyFlakeDetectionNumRetries + 1) {
@@ -894,7 +925,7 @@ addHook({
894
925
  shimmer.wrap(
895
926
  workerPackage.Worker.prototype,
896
927
  'runTestCase',
897
- runTestCase => getWrappedRunTestCase(runTestCase, true, !!process.env.CUCUMBER_WORKER_ID)
928
+ runTestCase => getWrappedRunTestCase(runTestCase, true, !!getEnvironmentVariable('CUCUMBER_WORKER_ID'))
898
929
  )
899
930
  return workerPackage
900
931
  })
@@ -947,6 +978,11 @@ addHook({
947
978
  this.options.worldParameters._ddEarlyFlakeDetectionNumRetries = earlyFlakeDetectionNumRetries
948
979
  }
949
980
 
981
+ if (isImpactedTestsEnabled) {
982
+ this.options.worldParameters._ddImpactedTestsEnabled = isImpactedTestsEnabled
983
+ this.options.worldParameters._ddModifiedTests = modifiedTests
984
+ }
985
+
950
986
  return startWorker.apply(this, arguments)
951
987
  })
952
988
  return adapterPackage
@@ -973,6 +1009,10 @@ addHook({
973
1009
  if (isEarlyFlakeDetectionEnabled) {
974
1010
  earlyFlakeDetectionNumRetries = this.options.worldParameters._ddEarlyFlakeDetectionNumRetries
975
1011
  }
1012
+ isImpactedTestsEnabled = !!this.options.worldParameters._ddImpactedTestsEnabled
1013
+ if (isImpactedTestsEnabled) {
1014
+ modifiedTests = this.options.worldParameters._ddModifiedTests
1015
+ }
976
1016
  }
977
1017
  )
978
1018
  return workerPackage
@@ -1,8 +1,9 @@
1
1
  const { addHook } = require('./helpers/instrument')
2
+ const { DD_MAJOR } = require('../../../version')
2
3
 
3
4
  // No handler because this is only useful for testing.
4
5
  // Cypress plugin does not patch any library.
5
6
  addHook({
6
7
  name: 'cypress',
7
- versions: ['>=6.7.0']
8
+ versions: DD_MAJOR >= 6 ? ['>=10.2.0'] : ['>=6.7.0']
8
9
  }, lib => lib)
@@ -39,12 +39,12 @@ addHook({ name: names }, dns => {
39
39
  })
40
40
 
41
41
  function patchResolveShorthands (prototype) {
42
- Object.keys(rrtypes)
43
- .filter(method => !!prototype[method])
44
- .forEach(method => {
42
+ for (const method of Object.keys(rrtypes)) {
43
+ if (prototype[method]) {
45
44
  rrtypeMap.set(prototype[method], rrtypes[method])
46
45
  shimmer.wrap(prototype, method, fn => wrap('apm:dns:resolve', fn, 2, rrtypes[method]))
47
- })
46
+ }
47
+ }
48
48
  }
49
49
 
50
50
  function wrap (prefix, fn, expectedArgs, rrtype) {
@@ -62,7 +62,7 @@ function wrap (prefix, fn, expectedArgs, rrtype) {
62
62
  return fn.apply(this, arguments)
63
63
  }
64
64
 
65
- const args = Array.from(arguments)
65
+ const args = [...arguments]
66
66
  args.pop() // gets rid of the callback
67
67
  if (rrtype) {
68
68
  args.push(rrtype)
@@ -91,18 +91,17 @@ function createWrapRequest (name) {
91
91
  return cb.apply(null, arguments)
92
92
  }))
93
93
  return request.apply(this, arguments)
94
+ }
95
+ const promise = request.apply(this, arguments)
96
+ if (promise && typeof promise.then === 'function') {
97
+ const onResolve = asyncResource.bind(() => finish(params))
98
+ const onReject = asyncResource.bind(e => finish(params, e))
99
+
100
+ promise.then(onResolve, onReject)
94
101
  } else {
95
- const promise = request.apply(this, arguments)
96
- if (promise && typeof promise.then === 'function') {
97
- const onResolve = asyncResource.bind(() => finish(params))
98
- const onReject = asyncResource.bind(e => finish(params, e))
99
-
100
- promise.then(onResolve, onReject)
101
- } else {
102
- finish(params)
103
- }
104
- return promise
102
+ finish(params)
105
103
  }
104
+ return promise
106
105
  } catch (err) {
107
106
  err.stack // trigger getting the stack at the original throwing point
108
107
  errorCh.publish(err)
@@ -59,21 +59,19 @@ function wrapAddHook (addHook) {
59
59
  return parsingResource.runInAsyncScope(() => {
60
60
  return done.apply(this, arguments)
61
61
  })
62
- } else {
63
- return done.apply(this, arguments)
64
62
  }
63
+ return done.apply(this, arguments)
65
64
  }
66
65
 
67
66
  return fn.apply(this, arguments)
68
- } else {
69
- const promise = fn.apply(this, arguments)
70
-
71
- if (promise && typeof promise.catch === 'function') {
72
- return promise.catch(err => publishError(err, req))
73
- }
67
+ }
68
+ const promise = fn.apply(this, arguments)
74
69
 
75
- return promise
70
+ if (promise && typeof promise.catch === 'function') {
71
+ return promise.catch(err => publishError(err, req))
76
72
  }
73
+
74
+ return promise
77
75
  } catch (e) {
78
76
  throw publishError(e, req)
79
77
  }
@@ -366,7 +366,7 @@ function massWrap (target, methods, wrapper) {
366
366
  function wrap (target, method, wrapper) {
367
367
  try {
368
368
  shimmer.wrap(target, method, wrapper)
369
- } catch (e) {
369
+ } catch {
370
370
  // skip unavailable method
371
371
  }
372
372
  }
@@ -2,8 +2,7 @@
2
2
 
3
3
  const {
4
4
  channel,
5
- addHook,
6
- AsyncResource
5
+ addHook
7
6
  } = require('./helpers/instrument')
8
7
  const shimmer = require('../../datadog-shimmer')
9
8
 
@@ -65,42 +64,35 @@ function wrapMethod (method) {
65
64
  return function (request) {
66
65
  if (!requestStartCh.hasSubscribers) return method.apply(this, arguments)
67
66
 
68
- const innerAsyncResource = new AsyncResource('bound-anonymous-fn')
69
-
70
- return innerAsyncResource.runInAsyncScope(() => {
71
- const projectId = this.auth._cachedProjectId
67
+ const ctx = { request, api, projectId: this.auth._cachedProjectId }
68
+ return requestStartCh.runStores(ctx, () => {
72
69
  const cb = arguments[arguments.length - 1]
73
70
 
74
- requestStartCh.publish({ request, api, projectId })
75
-
76
71
  if (typeof cb === 'function') {
77
- const outerAsyncResource = new AsyncResource('bound-anonymous-fn')
78
-
79
- arguments[arguments.length - 1] = shimmer.wrapFunction(cb, cb => innerAsyncResource.bind(function (error) {
72
+ arguments[arguments.length - 1] = shimmer.wrapFunction(cb, cb => function (error) {
80
73
  if (error) {
81
- requestErrorCh.publish(error)
74
+ ctx.error = error
75
+ requestErrorCh.publish(ctx)
82
76
  }
83
77
 
84
- requestFinishCh.publish()
78
+ return requestFinishCh.runStores(ctx, cb, this, ...arguments)
79
+ })
85
80
 
86
- return outerAsyncResource.runInAsyncScope(() => cb.apply(this, arguments))
87
- }))
88
-
89
- return method.apply(this, arguments)
90
- } else {
91
81
  return method.apply(this, arguments)
92
- .then(
93
- response => {
94
- requestFinishCh.publish()
95
- return response
96
- },
97
- error => {
98
- requestErrorCh.publish(error)
99
- requestFinishCh.publish()
100
- throw error
101
- }
102
- )
103
82
  }
83
+ return method.apply(this, arguments)
84
+ .then(
85
+ response => {
86
+ requestFinishCh.publish(ctx)
87
+ return response
88
+ },
89
+ error => {
90
+ ctx.error = error
91
+ requestErrorCh.publish(ctx)
92
+ requestFinishCh.publish(ctx)
93
+ throw error
94
+ }
95
+ )
104
96
  })
105
97
  }
106
98
  }
@@ -119,16 +111,14 @@ addHook({ name: '@google-cloud/pubsub', versions: ['>=1.2'] }, (obj) => {
119
111
  shimmer.wrap(Subscription.prototype, 'emit', emit => function (eventName, message) {
120
112
  if (eventName !== 'message' || !message) return emit.apply(this, arguments)
121
113
 
122
- const asyncResource = new AsyncResource('bound-anonymous-fn')
123
-
124
- return asyncResource.runInAsyncScope(() => {
125
- try {
126
- return emit.apply(this, arguments)
127
- } catch (err) {
128
- receiveErrorCh.publish(err)
129
- throw err
130
- }
131
- })
114
+ const ctx = {}
115
+ try {
116
+ return emit.apply(this, arguments)
117
+ } catch (err) {
118
+ ctx.error = err
119
+ receiveErrorCh.publish(ctx)
120
+ throw err
121
+ }
132
122
  })
133
123
 
134
124
  return obj
@@ -136,22 +126,24 @@ addHook({ name: '@google-cloud/pubsub', versions: ['>=1.2'] }, (obj) => {
136
126
 
137
127
  addHook({ name: '@google-cloud/pubsub', versions: ['>=1.2'], file: 'build/src/lease-manager.js' }, (obj) => {
138
128
  const LeaseManager = obj.LeaseManager
129
+ const ctx = {}
139
130
 
140
131
  shimmer.wrap(LeaseManager.prototype, '_dispense', dispense => function (message) {
141
132
  if (receiveStartCh.hasSubscribers) {
142
- receiveStartCh.publish({ message })
133
+ ctx.message = message
134
+ return receiveStartCh.runStores(ctx, dispense, this, ...arguments)
143
135
  }
144
136
  return dispense.apply(this, arguments)
145
137
  })
146
138
 
147
139
  shimmer.wrap(LeaseManager.prototype, 'remove', remove => function (message) {
148
- receiveFinishCh.publish({ message })
149
- return remove.apply(this, arguments)
140
+ return receiveFinishCh.runStores(ctx, remove, this, ...arguments)
150
141
  })
151
142
 
152
143
  shimmer.wrap(LeaseManager.prototype, 'clear', clear => function () {
153
144
  for (const message of this._messages) {
154
- receiveFinishCh.publish({ message })
145
+ ctx.message = message
146
+ receiveFinishCh.publish(ctx)
155
147
  }
156
148
  return clear.apply(this, arguments)
157
149
  })