dd-trace 5.53.0 → 5.54.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 (319) hide show
  1. package/LICENSE-3rdparty.csv +2 -1
  2. package/index.d.ts +33 -16
  3. package/initialize.mjs +3 -4
  4. package/package.json +36 -34
  5. package/packages/datadog-core/src/utils/src/get.js +1 -1
  6. package/packages/datadog-core/src/utils/src/has.js +1 -1
  7. package/packages/datadog-core/src/utils/src/kebabcase.js +4 -6
  8. package/packages/datadog-core/src/utils/src/parse-tags.js +1 -1
  9. package/packages/datadog-core/src/utils/src/pick.js +2 -2
  10. package/packages/datadog-core/src/utils/src/set.js +1 -1
  11. package/packages/datadog-core/src/utils/src/uniq.js +1 -1
  12. package/packages/datadog-instrumentations/src/amqp10.js +19 -17
  13. package/packages/datadog-instrumentations/src/amqplib.js +52 -35
  14. package/packages/datadog-instrumentations/src/apollo.js +2 -2
  15. package/packages/datadog-instrumentations/src/aws-sdk.js +1 -1
  16. package/packages/datadog-instrumentations/src/cassandra-driver.js +5 -4
  17. package/packages/datadog-instrumentations/src/child_process.js +1 -2
  18. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +88 -73
  19. package/packages/datadog-instrumentations/src/couchbase.js +3 -3
  20. package/packages/datadog-instrumentations/src/cucumber.js +87 -40
  21. package/packages/datadog-instrumentations/src/cypress.js +2 -1
  22. package/packages/datadog-instrumentations/src/dns.js +1 -1
  23. package/packages/datadog-instrumentations/src/fs.js +1 -1
  24. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +28 -34
  25. package/packages/datadog-instrumentations/src/graphql.js +7 -10
  26. package/packages/datadog-instrumentations/src/grpc/client.js +11 -23
  27. package/packages/datadog-instrumentations/src/grpc/server.js +7 -20
  28. package/packages/datadog-instrumentations/src/helpers/extract-package-and-module-path.js +16 -10
  29. package/packages/datadog-instrumentations/src/helpers/hook.js +1 -1
  30. package/packages/datadog-instrumentations/src/helpers/hooks.js +0 -1
  31. package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -41
  32. package/packages/datadog-instrumentations/src/helpers/register.js +5 -7
  33. package/packages/datadog-instrumentations/src/http/client.js +14 -20
  34. package/packages/datadog-instrumentations/src/jest.js +137 -48
  35. package/packages/datadog-instrumentations/src/kafkajs.js +52 -44
  36. package/packages/datadog-instrumentations/src/knex.js +4 -4
  37. package/packages/datadog-instrumentations/src/ldapjs.js +3 -4
  38. package/packages/datadog-instrumentations/src/mariadb.js +38 -61
  39. package/packages/datadog-instrumentations/src/mocha/main.js +63 -24
  40. package/packages/datadog-instrumentations/src/mocha/utils.js +36 -12
  41. package/packages/datadog-instrumentations/src/mocha/worker.js +6 -0
  42. package/packages/datadog-instrumentations/src/mongodb-core.js +1 -1
  43. package/packages/datadog-instrumentations/src/mysql.js +20 -36
  44. package/packages/datadog-instrumentations/src/mysql2.js +53 -47
  45. package/packages/datadog-instrumentations/src/net.js +1 -1
  46. package/packages/datadog-instrumentations/src/next.js +1 -0
  47. package/packages/datadog-instrumentations/src/nyc.js +1 -1
  48. package/packages/datadog-instrumentations/src/openai.js +21 -23
  49. package/packages/datadog-instrumentations/src/oracledb.js +1 -1
  50. package/packages/datadog-instrumentations/src/pg.js +1 -2
  51. package/packages/datadog-instrumentations/src/playwright.js +112 -69
  52. package/packages/datadog-instrumentations/src/redis.js +3 -3
  53. package/packages/datadog-instrumentations/src/restify.js +2 -2
  54. package/packages/datadog-instrumentations/src/rhea.js +42 -54
  55. package/packages/datadog-instrumentations/src/router.js +22 -25
  56. package/packages/datadog-instrumentations/src/tedious.js +1 -1
  57. package/packages/datadog-instrumentations/src/vitest.js +77 -28
  58. package/packages/datadog-plugin-amqp10/src/consumer.js +7 -3
  59. package/packages/datadog-plugin-amqp10/src/producer.js +7 -3
  60. package/packages/datadog-plugin-amqplib/src/client.js +6 -2
  61. package/packages/datadog-plugin-amqplib/src/consumer.js +7 -3
  62. package/packages/datadog-plugin-amqplib/src/producer.js +7 -3
  63. package/packages/datadog-plugin-amqplib/src/util.js +1 -1
  64. package/packages/datadog-plugin-apollo/src/gateway/request.js +5 -6
  65. package/packages/datadog-plugin-apollo/src/gateway/validate.js +2 -3
  66. package/packages/datadog-plugin-aws-sdk/src/base.js +3 -2
  67. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +2 -2
  68. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +13 -13
  69. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +24 -31
  70. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +2 -2
  71. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +6 -6
  72. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +1 -1
  73. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +1 -1
  74. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -5
  75. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +1 -1
  76. package/packages/datadog-plugin-aws-sdk/src/util.js +5 -6
  77. package/packages/datadog-plugin-cassandra-driver/src/index.js +1 -1
  78. package/packages/datadog-plugin-child_process/src/index.js +4 -4
  79. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +23 -23
  80. package/packages/datadog-plugin-cucumber/src/index.js +57 -2
  81. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +97 -27
  82. package/packages/datadog-plugin-cypress/src/plugin.js +11 -1
  83. package/packages/datadog-plugin-cypress/src/support.js +24 -5
  84. package/packages/datadog-plugin-express/src/code_origin.js +30 -0
  85. package/packages/datadog-plugin-express/src/index.js +10 -12
  86. package/packages/datadog-plugin-express/src/tracing.js +19 -0
  87. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +7 -3
  88. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +12 -7
  89. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +6 -2
  90. package/packages/datadog-plugin-google-cloud-vertexai/src/tracing.js +26 -9
  91. package/packages/datadog-plugin-graphql/src/execute.js +2 -2
  92. package/packages/datadog-plugin-graphql/src/index.js +7 -6
  93. package/packages/datadog-plugin-graphql/src/resolve.js +2 -2
  94. package/packages/datadog-plugin-graphql/src/tools/index.js +1 -0
  95. package/packages/datadog-plugin-graphql/src/tools/signature.js +1 -0
  96. package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
  97. package/packages/datadog-plugin-grpc/src/client.js +2 -2
  98. package/packages/datadog-plugin-grpc/src/util.js +2 -2
  99. package/packages/datadog-plugin-http/src/client.js +18 -7
  100. package/packages/datadog-plugin-http2/src/client.js +20 -20
  101. package/packages/datadog-plugin-jest/src/index.js +23 -21
  102. package/packages/datadog-plugin-jest/src/util.js +8 -8
  103. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +3 -1
  104. package/packages/datadog-plugin-kafkajs/src/consumer.js +9 -5
  105. package/packages/datadog-plugin-kafkajs/src/producer.js +8 -3
  106. package/packages/datadog-plugin-kafkajs/src/utils.js +1 -1
  107. package/packages/datadog-plugin-langchain/src/handlers/chain.js +7 -7
  108. package/packages/datadog-plugin-langchain/src/handlers/embedding.js +2 -2
  109. package/packages/datadog-plugin-langchain/src/handlers/language_models/chat_model.js +6 -4
  110. package/packages/datadog-plugin-langchain/src/handlers/language_models/llm.js +5 -4
  111. package/packages/datadog-plugin-langchain/src/tracing.js +11 -10
  112. package/packages/datadog-plugin-mariadb/src/index.js +3 -9
  113. package/packages/datadog-plugin-mocha/src/index.js +33 -13
  114. package/packages/datadog-plugin-mongodb-core/src/index.js +1 -1
  115. package/packages/datadog-plugin-mysql/src/index.js +11 -9
  116. package/packages/datadog-plugin-mysql2/src/index.js +16 -0
  117. package/packages/datadog-plugin-net/src/tcp.js +1 -1
  118. package/packages/datadog-plugin-next/src/index.js +6 -5
  119. package/packages/datadog-plugin-openai/src/services.js +6 -10
  120. package/packages/datadog-plugin-openai/src/tracing.js +10 -14
  121. package/packages/datadog-plugin-oracledb/src/index.js +1 -1
  122. package/packages/datadog-plugin-playwright/src/index.js +22 -2
  123. package/packages/datadog-plugin-redis/src/index.js +1 -1
  124. package/packages/datadog-plugin-rhea/src/consumer.js +8 -6
  125. package/packages/datadog-plugin-rhea/src/producer.js +5 -2
  126. package/packages/datadog-plugin-router/src/index.js +1 -1
  127. package/packages/datadog-plugin-selenium/src/index.js +1 -6
  128. package/packages/datadog-plugin-vitest/src/index.js +47 -31
  129. package/packages/datadog-shimmer/src/shimmer.js +4 -8
  130. package/packages/dd-trace/src/appsec/api_security_sampler.js +2 -2
  131. package/packages/dd-trace/src/appsec/blocked_templates.js +1 -1
  132. package/packages/dd-trace/src/appsec/blocking.js +6 -20
  133. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +1 -1
  134. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +1 -1
  135. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secrets-rules.js +1 -1
  136. package/packages/dd-trace/src/appsec/iast/analyzers/header-injection-analyzer.js +4 -6
  137. package/packages/dd-trace/src/appsec/iast/analyzers/hsts-header-missing-analyzer.js +7 -12
  138. package/packages/dd-trace/src/appsec/iast/analyzers/missing-header-analyzer.js +4 -6
  139. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +4 -0
  140. package/packages/dd-trace/src/appsec/iast/analyzers/path-traversal-analyzer.js +9 -12
  141. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +5 -4
  142. package/packages/dd-trace/src/appsec/iast/context/context-plugin.js +2 -3
  143. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +3 -3
  144. package/packages/dd-trace/src/appsec/iast/index.js +1 -0
  145. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +102 -7
  146. package/packages/dd-trace/src/appsec/iast/path-line.js +7 -8
  147. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +6 -13
  148. package/packages/dd-trace/src/appsec/iast/security-controls/parser.js +6 -6
  149. package/packages/dd-trace/src/appsec/iast/taint-tracking/filter.js +2 -2
  150. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations-taint-object.js +3 -3
  151. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +4 -28
  152. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +1 -7
  153. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +3 -4
  154. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs +1 -1
  155. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +5 -7
  156. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -2
  157. package/packages/dd-trace/src/appsec/iast/telemetry/span-tags.js +6 -6
  158. package/packages/dd-trace/src/appsec/iast/telemetry/verbosity.js +1 -1
  159. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/command-sensitive-analyzer.js +1 -1
  160. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +1 -1
  161. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/sql-sensitive-analyzer.js +7 -7
  162. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +23 -24
  163. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-regex.js +3 -3
  164. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +4 -4
  165. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +6 -11
  166. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +9 -11
  167. package/packages/dd-trace/src/appsec/index.js +1 -1
  168. package/packages/dd-trace/src/appsec/rasp/index.js +15 -15
  169. package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -1
  170. package/packages/dd-trace/src/appsec/reporter.js +233 -40
  171. package/packages/dd-trace/src/appsec/rule_manager.js +2 -2
  172. package/packages/dd-trace/src/appsec/stack_trace.js +2 -4
  173. package/packages/dd-trace/src/appsec/telemetry/rasp.js +3 -5
  174. package/packages/dd-trace/src/appsec/telemetry/waf.js +3 -5
  175. package/packages/dd-trace/src/appsec/user_tracking.js +3 -5
  176. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +2 -2
  177. package/packages/dd-trace/src/azure_metadata.js +2 -7
  178. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +1 -1
  179. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +2 -2
  180. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +1 -1
  181. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +3 -3
  182. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +1 -1
  183. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +1 -1
  184. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +1 -1
  185. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +6 -4
  186. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +2 -2
  187. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +0 -2
  188. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -1
  189. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +1 -1
  190. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +8 -5
  191. package/packages/dd-trace/src/ci-visibility/telemetry.js +4 -0
  192. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
  193. package/packages/dd-trace/src/config.js +82 -51
  194. package/packages/dd-trace/src/config_stable.js +3 -3
  195. package/packages/dd-trace/src/datastreams/encoding.js +9 -9
  196. package/packages/dd-trace/src/datastreams/fnv.js +1 -1
  197. package/packages/dd-trace/src/datastreams/pathway.js +4 -4
  198. package/packages/dd-trace/src/datastreams/processor.js +5 -7
  199. package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +1 -1
  200. package/packages/dd-trace/src/datastreams/schemas/schema_sampler.js +4 -6
  201. package/packages/dd-trace/src/datastreams/size.js +1 -1
  202. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +74 -67
  203. package/packages/dd-trace/src/debugger/devtools_client/condition.js +6 -8
  204. package/packages/dd-trace/src/debugger/devtools_client/defaults.js +1 -1
  205. package/packages/dd-trace/src/debugger/devtools_client/index.js +7 -1
  206. package/packages/dd-trace/src/debugger/devtools_client/remote_config.js +18 -38
  207. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +1 -1
  208. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +8 -10
  209. package/packages/dd-trace/src/debugger/devtools_client/snapshot/redaction.js +3 -3
  210. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +2 -10
  211. package/packages/dd-trace/src/debugger/devtools_client/state.js +10 -3
  212. package/packages/dd-trace/src/dogstatsd.js +5 -4
  213. package/packages/dd-trace/src/encode/0.4.js +9 -9
  214. package/packages/dd-trace/src/encode/0.5.js +1 -1
  215. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +3 -3
  216. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +1 -1
  217. package/packages/dd-trace/src/encode/tags-processors.js +1 -1
  218. package/packages/dd-trace/src/exporter.js +6 -6
  219. package/packages/dd-trace/src/exporters/agent/writer.js +1 -5
  220. package/packages/dd-trace/src/exporters/common/docker.js +1 -1
  221. package/packages/dd-trace/src/exporters/common/form-data.js +6 -4
  222. package/packages/dd-trace/src/exporters/common/request.js +1 -1
  223. package/packages/dd-trace/src/exporters/common/util.js +1 -1
  224. package/packages/dd-trace/src/external-logger/src/index.js +5 -5
  225. package/packages/dd-trace/src/flare/file.js +1 -5
  226. package/packages/dd-trace/src/format.js +1 -1
  227. package/packages/dd-trace/src/git_properties.js +1 -1
  228. package/packages/dd-trace/src/id.js +12 -6
  229. package/packages/dd-trace/src/iitm.js +10 -22
  230. package/packages/dd-trace/src/lambda/handler.js +6 -6
  231. package/packages/dd-trace/src/lambda/runtime/patch.js +4 -4
  232. package/packages/dd-trace/src/lambda/runtime/ritm.js +1 -1
  233. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +6 -6
  234. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +2 -6
  235. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +3 -3
  236. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +6 -6
  237. package/packages/dd-trace/src/llmobs/plugins/openai.js +1 -1
  238. package/packages/dd-trace/src/llmobs/sdk.js +2 -2
  239. package/packages/dd-trace/src/llmobs/tagger.js +110 -96
  240. package/packages/dd-trace/src/llmobs/util.js +9 -9
  241. package/packages/dd-trace/src/llmobs/writers/base.js +1 -1
  242. package/packages/dd-trace/src/llmobs/writers/util.js +1 -1
  243. package/packages/dd-trace/src/log/index.js +4 -4
  244. package/packages/dd-trace/src/log/log.js +1 -1
  245. package/packages/dd-trace/src/log/writer.js +2 -2
  246. package/packages/dd-trace/src/msgpack/chunk.js +3 -3
  247. package/packages/dd-trace/src/msgpack/encoder.js +28 -28
  248. package/packages/dd-trace/src/noop/dogstatsd.js +6 -6
  249. package/packages/dd-trace/src/noop/span.js +3 -5
  250. package/packages/dd-trace/src/noop/tracer.js +1 -2
  251. package/packages/dd-trace/src/opentelemetry/span_processor.js +2 -2
  252. package/packages/dd-trace/src/opentelemetry/tracer.js +6 -5
  253. package/packages/dd-trace/src/opentracing/propagation/log.js +6 -8
  254. package/packages/dd-trace/src/opentracing/propagation/text_map.js +27 -23
  255. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +8 -4
  256. package/packages/dd-trace/src/opentracing/span.js +9 -14
  257. package/packages/dd-trace/src/opentracing/tracer.js +9 -6
  258. package/packages/dd-trace/src/payload-tagging/index.js +1 -1
  259. package/packages/dd-trace/src/payload-tagging/tagging.js +6 -6
  260. package/packages/dd-trace/src/pkg.js +1 -1
  261. package/packages/dd-trace/src/plugins/ci_plugin.js +62 -10
  262. package/packages/dd-trace/src/plugins/consumer.js +2 -2
  263. package/packages/dd-trace/src/plugins/inbound.js +5 -1
  264. package/packages/dd-trace/src/plugins/index.js +0 -1
  265. package/packages/dd-trace/src/plugins/outbound.js +4 -5
  266. package/packages/dd-trace/src/plugins/plugin.js +1 -1
  267. package/packages/dd-trace/src/plugins/producer.js +2 -2
  268. package/packages/dd-trace/src/plugins/storage.js +2 -2
  269. package/packages/dd-trace/src/plugins/util/ci.js +23 -15
  270. package/packages/dd-trace/src/plugins/util/git.js +165 -11
  271. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +1 -1
  272. package/packages/dd-trace/src/plugins/util/ip_extractor.js +1 -1
  273. package/packages/dd-trace/src/plugins/util/llm.js +27 -10
  274. package/packages/dd-trace/src/plugins/util/stacktrace.js +1 -1
  275. package/packages/dd-trace/src/plugins/util/test.js +311 -48
  276. package/packages/dd-trace/src/plugins/util/url.js +1 -1
  277. package/packages/dd-trace/src/plugins/util/urlfilter.js +13 -17
  278. package/packages/dd-trace/src/plugins/util/user-provided-git.js +12 -3
  279. package/packages/dd-trace/src/plugins/util/web.js +5 -4
  280. package/packages/dd-trace/src/priority_sampler.js +22 -22
  281. package/packages/dd-trace/src/profiling/config.js +44 -8
  282. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +5 -5
  283. package/packages/dd-trace/src/profiling/exporters/file.js +2 -1
  284. package/packages/dd-trace/src/profiling/profiler.js +37 -2
  285. package/packages/dd-trace/src/profiling/profilers/events.js +14 -17
  286. package/packages/dd-trace/src/profiling/profilers/shared.js +6 -1
  287. package/packages/dd-trace/src/profiling/profilers/space.js +3 -3
  288. package/packages/dd-trace/src/profiling/profilers/wall.js +6 -7
  289. package/packages/dd-trace/src/profiling/ssi-heuristics.js +3 -5
  290. package/packages/dd-trace/src/profiling/tagger.js +3 -5
  291. package/packages/dd-trace/src/profiling/webspan-utils.js +1 -1
  292. package/packages/dd-trace/src/proxy.js +7 -9
  293. package/packages/dd-trace/src/random_sampler.js +40 -0
  294. package/packages/dd-trace/src/rate_limiter.js +4 -4
  295. package/packages/dd-trace/src/remote_config/index.js +3 -7
  296. package/packages/dd-trace/src/remote_config/manager.js +25 -13
  297. package/packages/dd-trace/src/require-package-json.js +1 -1
  298. package/packages/dd-trace/src/ritm.js +4 -4
  299. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +2 -2
  300. package/packages/dd-trace/src/sampler.js +33 -4
  301. package/packages/dd-trace/src/sampling_rule.js +12 -3
  302. package/packages/dd-trace/src/scope.js +1 -1
  303. package/packages/dd-trace/src/service-naming/schemas/util.js +1 -1
  304. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +2 -3
  305. package/packages/dd-trace/src/span_processor.js +3 -3
  306. package/packages/dd-trace/src/span_sampler.js +4 -1
  307. package/packages/dd-trace/src/standalone/tracesource.js +1 -1
  308. package/packages/dd-trace/src/startup-log.js +2 -2
  309. package/packages/dd-trace/src/telemetry/dependencies.js +4 -4
  310. package/packages/dd-trace/src/telemetry/logs/log-collector.js +9 -10
  311. package/packages/dd-trace/src/telemetry/metrics.js +10 -5
  312. package/packages/dd-trace/src/telemetry/send-data.js +1 -1
  313. package/packages/dd-trace/src/telemetry/telemetry.js +23 -24
  314. package/packages/dd-trace/src/util.js +1 -1
  315. package/version.js +1 -0
  316. package/packages/datadog-instrumentations/src/paperplane.js +0 -77
  317. package/packages/datadog-plugin-paperplane/src/index.js +0 -25
  318. package/packages/datadog-plugin-paperplane/src/logger.js +0 -11
  319. package/packages/datadog-plugin-paperplane/src/server.js +0 -24
@@ -15,7 +15,9 @@ const {
15
15
  getIsFaultyEarlyFlakeDetection,
16
16
  JEST_WORKER_LOGS_PAYLOAD_CODE,
17
17
  addAttemptToFixStringToTestName,
18
- removeAttemptToFixStringFromTestName
18
+ removeAttemptToFixStringFromTestName,
19
+ getTestEndLine,
20
+ isModifiedTest
19
21
  } = require('../../dd-trace/src/plugins/util/test')
20
22
  const {
21
23
  getFormattedJestTestParameters,
@@ -47,6 +49,7 @@ const skippableSuitesCh = channel('ci:jest:test-suite:skippable')
47
49
  const libraryConfigurationCh = channel('ci:jest:library-configuration')
48
50
  const knownTestsCh = channel('ci:jest:known-tests')
49
51
  const testManagementTestsCh = channel('ci:jest:test-management-tests')
52
+ const impactedTestsCh = channel('ci:jest:modified-tests')
50
53
 
51
54
  const itrSkippedSuitesCh = channel('ci:jest:itr:skipped-suites')
52
55
 
@@ -54,8 +57,8 @@ const itrSkippedSuitesCh = channel('ci:jest:itr:skipped-suites')
54
57
  // https://github.com/jestjs/jest/blob/1d682f21c7a35da4d3ab3a1436a357b980ebd0fa/packages/jest-worker/src/types.ts#L37
55
58
  const CHILD_MESSAGE_CALL = 1
56
59
  // Maximum time we'll wait for the tracer to flush
57
- const FLUSH_TIMEOUT = 10000
58
- // eslint-disable-next-line
60
+ const FLUSH_TIMEOUT = 10_000
61
+
59
62
  // https://github.com/jestjs/jest/blob/41f842a46bb2691f828c3a5f27fc1d6290495b82/packages/jest-circus/src/types.ts#L9C8-L9C54
60
63
  const RETRY_TIMES = Symbol.for('RETRY_TIMES')
61
64
 
@@ -77,6 +80,8 @@ let isKnownTestsEnabled = false
77
80
  let isTestManagementTestsEnabled = false
78
81
  let testManagementTests = {}
79
82
  let testManagementAttemptToFixRetries = 0
83
+ let isImpactedTestsEnabled = false
84
+ let modifiedTests = {}
80
85
 
81
86
  const sessionAsyncResource = new AsyncResource('bound-anonymous-fn')
82
87
 
@@ -150,6 +155,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
150
155
  this.isDiEnabled = this.testEnvironmentOptions._ddIsDiEnabled
151
156
  this.isKnownTestsEnabled = this.testEnvironmentOptions._ddIsKnownTestsEnabled
152
157
  this.isTestManagementTestsEnabled = this.testEnvironmentOptions._ddIsTestManagementTestsEnabled
158
+ this.isImpactedTestsEnabled = this.testEnvironmentOptions._ddIsImpactedTestsEnabled
153
159
 
154
160
  if (this.isKnownTestsEnabled) {
155
161
  try {
@@ -158,7 +164,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
158
164
  this.knownTestsForThisSuite = hasKnownTests
159
165
  ? (knownTests?.jest?.[this.testSuite] || [])
160
166
  : this.getKnownTestsForSuite(this.testEnvironmentOptions._ddKnownTests)
161
- } catch (e) {
167
+ } catch {
162
168
  // If there has been an error parsing the tests, we'll disable Early Flake Deteciton
163
169
  this.isEarlyFlakeDetectionEnabled = false
164
170
  this.isKnownTestsEnabled = false
@@ -184,6 +190,18 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
184
190
  this.isTestManagementTestsEnabled = false
185
191
  }
186
192
  }
193
+
194
+ if (this.isImpactedTestsEnabled) {
195
+ try {
196
+ const hasImpactedTests = Object.keys(modifiedTests).length > 0
197
+ this.modifiedTestsForThisSuite = hasImpactedTests
198
+ ? this.getModifiedTestForThisSuite(modifiedTests)
199
+ : this.getModifiedTestForThisSuite(this.testEnvironmentOptions._ddModifiedTests)
200
+ } catch (e) {
201
+ log.error('Error parsing impacted tests', e)
202
+ this.isImpactedTestsEnabled = false
203
+ }
204
+ }
187
205
  }
188
206
 
189
207
  getHasSnapshotTests () {
@@ -194,7 +212,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
194
212
  try {
195
213
  const { _snapshotData } = this.getVmContext().expect.getState().snapshotState
196
214
  hasSnapshotTests = Object.keys(_snapshotData).length > 0
197
- } catch (e) {
215
+ } catch {
198
216
  // if we can't be sure, we'll err on the side of caution and assume it has snapshots
199
217
  }
200
218
  this.hasSnapshotTests = hasSnapshotTests
@@ -255,6 +273,19 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
255
273
  return result
256
274
  }
257
275
 
276
+ getModifiedTestForThisSuite (modifiedTests) {
277
+ if (this.modifiedTestsForThisSuite) {
278
+ return this.modifiedTestsForThisSuite
279
+ }
280
+ let modifiedTestsForThisSuite = modifiedTests
281
+ // If jest is using workers, modified tests are serialized to json.
282
+ // If jest runs in band, they are not.
283
+ if (typeof modifiedTestsForThisSuite === 'string') {
284
+ modifiedTestsForThisSuite = JSON.parse(modifiedTestsForThisSuite)
285
+ }
286
+ return modifiedTestsForThisSuite
287
+ }
288
+
258
289
  // Generic function to handle test retries
259
290
  retryTest (testName, retryCount, addRetryStringToTestName, retryType, event) {
260
291
  // Retrying snapshots has proven to be problematic, so we'll skip them for now
@@ -288,18 +319,16 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
288
319
 
289
320
  const setNameToParams = (name, params) => { this.nameToParams[name] = [...params] }
290
321
 
291
- if (event.name === 'setup') {
292
- if (this.global.test) {
293
- shimmer.wrap(this.global.test, 'each', each => function () {
294
- const testParameters = getFormattedJestTestParameters(arguments)
295
- const eachBind = each.apply(this, arguments)
296
- return function () {
297
- const [testName] = arguments
298
- setNameToParams(testName, testParameters)
299
- return eachBind.apply(this, arguments)
300
- }
301
- })
302
- }
322
+ if (event.name === 'setup' && this.global.test) {
323
+ shimmer.wrap(this.global.test, 'each', each => function () {
324
+ const testParameters = getFormattedJestTestParameters(arguments)
325
+ const eachBind = each.apply(this, arguments)
326
+ return function () {
327
+ const [testName] = arguments
328
+ setNameToParams(testName, testParameters)
329
+ return eachBind.apply(this, arguments)
330
+ }
331
+ })
303
332
  }
304
333
  if (event.name === 'test_start') {
305
334
  let isNewTest = false
@@ -326,12 +355,26 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
326
355
  }
327
356
  }
328
357
 
358
+ let isModified = false
359
+ if (this.isImpactedTestsEnabled) {
360
+ const testStartLine = getTestLineStart(event.test.asyncError, this.testSuite)
361
+ const testEndLine = getTestEndLine(event.test.fn, testStartLine)
362
+ isModified = isModifiedTest(
363
+ this.testSourceFile,
364
+ testStartLine,
365
+ testEndLine,
366
+ this.modifiedTestsForThisSuite,
367
+ 'jest'
368
+ )
369
+ }
370
+
329
371
  if (this.isKnownTestsEnabled) {
330
372
  isNewTest = retriedTestsToNumAttempts.has(originalTestName)
331
- if (isNewTest) {
332
- numEfdRetry = retriedTestsToNumAttempts.get(originalTestName)
333
- retriedTestsToNumAttempts.set(originalTestName, numEfdRetry + 1)
334
- }
373
+ }
374
+
375
+ if (this.isEarlyFlakeDetectionEnabled && (isNewTest || isModified)) {
376
+ numEfdRetry = retriedTestsToNumAttempts.get(originalTestName)
377
+ retriedTestsToNumAttempts.set(originalTestName, numEfdRetry + 1)
335
378
  }
336
379
 
337
380
  const isJestRetry = event.test?.invocations > 1
@@ -348,22 +391,25 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
348
391
  isAttemptToFixRetry: numOfAttemptsToFixRetries > 0,
349
392
  isJestRetry,
350
393
  isDisabled,
351
- isQuarantined
394
+ isQuarantined,
395
+ isModified
352
396
  }
353
397
  testContexts.set(event.test, ctx)
354
398
 
355
399
  testStartCh.runStores(ctx, () => {
356
400
  for (const hook of event.test.parent.hooks) {
357
401
  let hookFn = hook.fn
358
- if (!originalHookFns.has(hook)) {
359
- originalHookFns.set(hook, hookFn)
360
- } else {
402
+ if (originalHookFns.has(hook)) {
361
403
  hookFn = originalHookFns.get(hook)
404
+ } else {
405
+ originalHookFns.set(hook, hookFn)
362
406
  }
407
+ // The rule has a bug, see https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2164
408
+ // eslint-disable-next-line unicorn/consistent-function-scoping
363
409
  const wrapperHook = function () {
364
410
  return testFnCh.runStores(ctx, () => hookFn.apply(this, arguments))
365
411
  }
366
- // If we don't do this, the timeout will be not be triggered
412
+ // If we don't do this, the timeout will not be triggered
367
413
  Object.defineProperty(wrapperHook, 'length', { value: hookFn.length })
368
414
  hook.fn = wrapperHook
369
415
  }
@@ -395,6 +441,27 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
395
441
  )
396
442
  }
397
443
  }
444
+ if (this.isImpactedTestsEnabled) {
445
+ const testStartLine = getTestLineStart(event.asyncError, this.testSuite)
446
+ const testEndLine = getTestEndLine(event.fn, testStartLine)
447
+ const isModified = isModifiedTest(
448
+ this.testSourceFile,
449
+ testStartLine,
450
+ testEndLine,
451
+ this.modifiedTestsForThisSuite,
452
+ 'jest'
453
+ )
454
+ if (isModified && !retriedTestsToNumAttempts.has(originalTestName) && this.isEarlyFlakeDetectionEnabled) {
455
+ retriedTestsToNumAttempts.set(originalTestName, 0)
456
+ this.retryTest(
457
+ event.testName,
458
+ earlyFlakeDetectionNumRetries,
459
+ addEfdStringToTestName,
460
+ 'Early flake detection',
461
+ event
462
+ )
463
+ }
464
+ }
398
465
  if (this.isKnownTestsEnabled) {
399
466
  const isNew = !this.knownTestsForThisSuite?.includes(originalTestName)
400
467
  if (isNew && !isSkipped && !retriedTestsToNumAttempts.has(originalTestName)) {
@@ -438,7 +505,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
438
505
  // If it is, we'll set the failedAllTests flag to true if all the tests failed
439
506
  // If all tests passed, we'll set the attemptToFixPassed flag to true
440
507
  if (testStatuses.length === testManagementAttemptToFixRetries + 1) {
441
- if (testStatuses.some(status => status === 'fail')) {
508
+ if (testStatuses.includes('fail')) {
442
509
  attemptToFixFailed = true
443
510
  }
444
511
  if (testStatuses.every(status => status === 'fail')) {
@@ -659,6 +726,7 @@ function cliWrapper (cli, jestVersion) {
659
726
  isKnownTestsEnabled = libraryConfig.isKnownTestsEnabled
660
727
  isTestManagementTestsEnabled = libraryConfig.isTestManagementEnabled
661
728
  testManagementAttemptToFixRetries = libraryConfig.testManagementAttemptToFixRetries
729
+ isImpactedTestsEnabled = libraryConfig.isImpactedTestsEnabled
662
730
  }
663
731
  } catch (err) {
664
732
  log.error('Jest library configuration error', err)
@@ -675,12 +743,12 @@ function cliWrapper (cli, jestVersion) {
675
743
 
676
744
  try {
677
745
  const { err, knownTests: receivedKnownTests } = await knownTestsPromise
678
- if (!err) {
679
- knownTests = receivedKnownTests
680
- } else {
746
+ if (err) {
681
747
  // We disable EFD if there has been an error in the known tests request
682
748
  isEarlyFlakeDetectionEnabled = false
683
749
  isKnownTestsEnabled = false
750
+ } else {
751
+ knownTests = receivedKnownTests
684
752
  }
685
753
  } catch (err) {
686
754
  log.error('Jest known tests error', err)
@@ -725,6 +793,25 @@ function cliWrapper (cli, jestVersion) {
725
793
  }
726
794
  }
727
795
 
796
+ if (isImpactedTestsEnabled) {
797
+ const impactedTestsPromise = new Promise((resolve) => {
798
+ onDone = resolve
799
+ })
800
+
801
+ sessionAsyncResource.runInAsyncScope(() => {
802
+ impactedTestsCh.publish({ onDone })
803
+ })
804
+
805
+ try {
806
+ const { err, modifiedTests: receivedModifiedTests } = await impactedTestsPromise
807
+ if (!err) {
808
+ modifiedTests = receivedModifiedTests
809
+ }
810
+ } catch (err) {
811
+ log.error('Jest impacted tests error', err)
812
+ }
813
+ }
814
+
728
815
  const processArgv = process.argv.slice(2).join(' ')
729
816
  sessionAsyncResource.runInAsyncScope(() => {
730
817
  testSessionStartCh.publish({ command: `jest ${processArgv}`, frameworkVersion: jestVersion })
@@ -748,19 +835,15 @@ function cliWrapper (cli, jestVersion) {
748
835
  if (isUserCodeCoverageEnabled) {
749
836
  try {
750
837
  const { pct, total } = coverageMap.getCoverageSummary().lines
751
- testCodeCoverageLinesTotal = total !== 0 ? pct : 0
752
- } catch (e) {
838
+ testCodeCoverageLinesTotal = total === 0 ? 0 : pct
839
+ } catch {
753
840
  // ignore errors
754
841
  }
755
842
  }
756
843
  let status, error
757
844
 
758
845
  if (success) {
759
- if (numTotalTests === 0 && numTotalTestSuites === 0) {
760
- status = 'skip'
761
- } else {
762
- status = 'pass'
763
- }
846
+ status = numTotalTests === 0 && numTotalTestSuites === 0 ? 'skip' : 'pass'
764
847
  } else {
765
848
  status = 'fail'
766
849
  error = new Error(`Failed test suites: ${numFailedTestSuites}. Failed tests: ${numFailedTests}`)
@@ -878,7 +961,7 @@ function cliWrapper (cli, jestVersion) {
878
961
  }
879
962
 
880
963
  function coverageReporterWrapper (coverageReporter) {
881
- const CoverageReporter = coverageReporter.default ? coverageReporter.default : coverageReporter
964
+ const CoverageReporter = coverageReporter.default ?? coverageReporter
882
965
 
883
966
  /**
884
967
  * If ITR is active, we're running fewer tests, so of course the total code coverage is reduced.
@@ -917,7 +1000,7 @@ addHook({
917
1000
  }, cliWrapper)
918
1001
 
919
1002
  function jestAdapterWrapper (jestAdapter, jestVersion) {
920
- const adapter = jestAdapter.default ? jestAdapter.default : jestAdapter
1003
+ const adapter = jestAdapter.default ?? jestAdapter
921
1004
  const newAdapter = shimmer.wrapFunction(adapter, adapter => function () {
922
1005
  const environment = arguments[2]
923
1006
  if (!environment) {
@@ -1065,6 +1148,7 @@ addHook({
1065
1148
  _ddIsTestManagementTestsEnabled,
1066
1149
  _ddTestManagementTests,
1067
1150
  _ddTestManagementAttemptToFixRetries,
1151
+ _ddModifiedTests,
1068
1152
  ...restOfTestEnvironmentOptions
1069
1153
  } = testEnvironmentOptions
1070
1154
 
@@ -1086,7 +1170,7 @@ addHook({
1086
1170
  versions: ['>=24.8.0'],
1087
1171
  file: 'build/SearchSource.js'
1088
1172
  }, (searchSourcePackage, frameworkVersion) => {
1089
- const SearchSource = searchSourcePackage.default ? searchSourcePackage.default : searchSourcePackage
1173
+ const SearchSource = searchSourcePackage.default ?? searchSourcePackage
1090
1174
 
1091
1175
  shimmer.wrap(SearchSource.prototype, 'getTestPaths', getTestPaths => async function () {
1092
1176
  const testPaths = await getTestPaths.apply(this, arguments)
@@ -1140,7 +1224,7 @@ addHook({
1140
1224
  versions: ['24.8.0 - 24.9.0']
1141
1225
  }, jestConfigSyncWrapper)
1142
1226
 
1143
- const LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE = [
1227
+ const LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE = new Set([
1144
1228
  'selenium-webdriver',
1145
1229
  'selenium-webdriver/chrome',
1146
1230
  'selenium-webdriver/edge',
@@ -1149,11 +1233,11 @@ const LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE = [
1149
1233
  'selenium-webdriver/ie',
1150
1234
  'selenium-webdriver/chromium',
1151
1235
  'winston'
1152
- ]
1236
+ ])
1153
1237
 
1154
1238
  function shouldBypassJestRequireEngine (moduleName) {
1155
1239
  return (
1156
- LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE.includes(moduleName)
1240
+ LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE.has(moduleName)
1157
1241
  )
1158
1242
  }
1159
1243
 
@@ -1161,7 +1245,7 @@ addHook({
1161
1245
  name: 'jest-runtime',
1162
1246
  versions: ['>=24.8.0']
1163
1247
  }, (runtimePackage) => {
1164
- const Runtime = runtimePackage.default ? runtimePackage.default : runtimePackage
1248
+ const Runtime = runtimePackage.default ?? runtimePackage
1165
1249
 
1166
1250
  shimmer.wrap(Runtime.prototype, 'requireModuleOrMock', requireModuleOrMock => function (from, moduleName) {
1167
1251
  // TODO: do this for every library that we instrument
@@ -1188,17 +1272,17 @@ addHook({
1188
1272
  }, (childProcessWorker) => {
1189
1273
  const ChildProcessWorker = childProcessWorker.default
1190
1274
  shimmer.wrap(ChildProcessWorker.prototype, 'send', send => function (request) {
1191
- if (!isKnownTestsEnabled && !isTestManagementTestsEnabled) {
1275
+ if (!isKnownTestsEnabled && !isTestManagementTestsEnabled && !isImpactedTestsEnabled) {
1192
1276
  return send.apply(this, arguments)
1193
1277
  }
1194
1278
  const [type] = request
1195
- // eslint-disable-next-line
1279
+
1196
1280
  // https://github.com/jestjs/jest/blob/1d682f21c7a35da4d3ab3a1436a357b980ebd0fa/packages/jest-worker/src/workers/ChildProcessWorker.ts#L424
1197
1281
  if (type === CHILD_MESSAGE_CALL) {
1198
1282
  // This is the message that the main process sends to the worker to run a test suite (=test file).
1199
1283
  // In here we modify the config.testEnvironmentOptions to include the known tests for the suite.
1200
1284
  // This way the suite only knows about the tests that are part of it.
1201
- const args = request[request.length - 1]
1285
+ const args = request.at(-1)
1202
1286
  if (args.length > 1) {
1203
1287
  return send.apply(this, arguments)
1204
1288
  }
@@ -1211,12 +1295,17 @@ addHook({
1211
1295
 
1212
1296
  const suiteTestManagementTests = testManagementTests?.jest?.suites?.[testSuite]?.tests || {}
1213
1297
 
1298
+ const suiteModifiedTests = Object.keys(modifiedTests).length > 0
1299
+ ? modifiedTests
1300
+ : {}
1301
+
1214
1302
  args[0].config = {
1215
1303
  ...config,
1216
1304
  testEnvironmentOptions: {
1217
1305
  ...config.testEnvironmentOptions,
1218
1306
  _ddKnownTests: suiteKnownTests,
1219
- _ddTestManagementTests: suiteTestManagementTests
1307
+ _ddTestManagementTests: suiteTestManagementTests,
1308
+ _ddModifiedTests: suiteModifiedTests
1220
1309
  }
1221
1310
  }
1222
1311
  }
@@ -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
 
@@ -60,33 +59,37 @@ addHook({ name: 'kafkajs', file: 'src/index.js', versions: ['>=1.4'] }, (BaseKaf
60
59
 
61
60
  producer.send = function () {
62
61
  const wrappedSend = (clusterId) => {
63
- const innerAsyncResource = new AsyncResource('bound-anonymous-fn')
62
+ const { topic, messages = [] } = arguments[0]
63
+
64
+ const ctx = {
65
+ bootstrapServers,
66
+ clusterId,
67
+ disableHeaderInjection: disabledHeaderWeakSet.has(producer),
68
+ messages,
69
+ topic
70
+ }
64
71
 
65
- return innerAsyncResource.runInAsyncScope(() => {
66
- if (!producerStartCh.hasSubscribers) {
67
- return send.apply(this, arguments)
72
+ for (const message of messages) {
73
+ if (message !== null && typeof message === 'object' && !ctx.disableHeaderInjection) {
74
+ message.headers = message.headers || {}
68
75
  }
76
+ }
69
77
 
78
+ return producerStartCh.runStores(ctx, () => {
70
79
  try {
71
- const { topic, messages = [] } = arguments[0]
72
- producerStartCh.publish({
73
- topic,
74
- messages,
75
- bootstrapServers,
76
- clusterId,
77
- disableHeaderInjection: disabledHeaderWeakSet.has(producer)
78
- })
79
80
  const result = send.apply(this, arguments)
80
81
  result.then(
81
- innerAsyncResource.bind(res => {
82
- producerFinishCh.publish(undefined)
83
- producerCommitCh.publish(res)
84
- }),
85
- innerAsyncResource.bind(err => {
82
+ (res) => {
83
+ ctx.result = res
84
+ producerFinishCh.publish(ctx)
85
+ producerCommitCh.publish(ctx)
86
+ },
87
+ (err) => {
88
+ ctx.error = err
86
89
  if (err) {
87
90
  // Fixes bug where we would inject message headers for kafka brokers that don't support headers
88
91
  // (version <0.11). On the error, we disable header injection.
89
- // Tnfortunately the error name / type is not more specific.
92
+ // Unfortunately the error name / type is not more specific.
90
93
  // This approach is implemented by other tracers as well.
91
94
  if (err.name === 'KafkaJSProtocolError' && err.type === 'UNKNOWN') {
92
95
  disabledHeaderWeakSet.add(producer)
@@ -96,28 +99,28 @@ addHook({ name: 'kafkajs', file: 'src/index.js', versions: ['>=1.4'] }, (BaseKaf
96
99
  }
97
100
  producerErrorCh.publish(err)
98
101
  }
99
- producerFinishCh.publish(undefined)
102
+ producerFinishCh.publish(ctx)
100
103
  })
101
- )
102
104
 
103
105
  return result
104
106
  } catch (e) {
105
- producerErrorCh.publish(e)
106
- producerFinishCh.publish(undefined)
107
+ ctx.error = e
108
+ producerErrorCh.publish(ctx)
109
+ producerFinishCh.publish(ctx)
107
110
  throw e
108
111
  }
109
112
  })
110
113
  }
111
114
 
112
- if (!isPromise(kafkaClusterIdPromise)) {
113
- // promise is already resolved
114
- return wrappedSend(kafkaClusterIdPromise)
115
- } else {
115
+ if (isPromise(kafkaClusterIdPromise)) {
116
116
  // promise is not resolved
117
117
  return kafkaClusterIdPromise.then((clusterId) => {
118
118
  return wrappedSend(clusterId)
119
119
  })
120
120
  }
121
+
122
+ // promise is already resolved
123
+ return wrappedSend(kafkaClusterIdPromise)
121
124
  }
122
125
  return producer
123
126
  })
@@ -170,15 +173,15 @@ addHook({ name: 'kafkajs', file: 'src/index.js', versions: ['>=1.4'] }, (BaseKaf
170
173
  })
171
174
  }
172
175
 
173
- if (!isPromise(kafkaClusterIdPromise)) {
174
- // promise is already resolved
175
- return wrapConsume(kafkaClusterIdPromise)
176
- } else {
176
+ if (isPromise(kafkaClusterIdPromise)) {
177
177
  // promise is not resolved
178
178
  return kafkaClusterIdPromise.then((clusterId) => {
179
179
  return wrapConsume(clusterId)
180
180
  })
181
181
  }
182
+
183
+ // promise is already resolved
184
+ return wrapConsume(kafkaClusterIdPromise)
182
185
  }
183
186
  return consumer
184
187
  })
@@ -188,30 +191,35 @@ addHook({ name: 'kafkajs', file: 'src/index.js', versions: ['>=1.4'] }, (BaseKaf
188
191
  const wrappedCallback = (fn, startCh, finishCh, errorCh, extractArgs, clusterId) => {
189
192
  return typeof fn === 'function'
190
193
  ? function (...args) {
191
- const innerAsyncResource = new AsyncResource('bound-anonymous-fn')
192
- return innerAsyncResource.runInAsyncScope(() => {
193
- const extractedArgs = extractArgs(args, clusterId)
194
+ const extractedArgs = extractArgs(args, clusterId)
195
+ const ctx = {
196
+ extractedArgs
197
+ }
194
198
 
195
- startCh.publish(extractedArgs)
199
+ return startCh.runStores(ctx, () => {
196
200
  try {
197
201
  const result = fn.apply(this, args)
198
202
  if (result && typeof result.then === 'function') {
199
203
  result.then(
200
- innerAsyncResource.bind(() => finishCh.publish(undefined)),
201
- innerAsyncResource.bind(err => {
204
+ (res) => {
205
+ ctx.result = res
206
+ finishCh.publish(ctx)
207
+ },
208
+ (err) => {
209
+ ctx.error = err
202
210
  if (err) {
203
- errorCh.publish(err)
211
+ errorCh.publish(ctx)
204
212
  }
205
- finishCh.publish(undefined)
213
+ finishCh.publish(ctx)
206
214
  })
207
- )
208
215
  } else {
209
- finishCh.publish(undefined)
216
+ finishCh.publish(ctx)
210
217
  }
211
218
  return result
212
219
  } catch (e) {
213
- errorCh.publish(e)
214
- finishCh.publish(undefined)
220
+ ctx.error = e
221
+ errorCh.publish(ctx)
222
+ finishCh.publish(ctx)
215
223
  throw e
216
224
  }
217
225
  })
@@ -22,6 +22,10 @@ function patch (file) {
22
22
  })
23
23
  }
24
24
 
25
+ function finish () {
26
+ finishRawQueryCh.publish()
27
+ }
28
+
25
29
  addHook({
26
30
  name: 'knex',
27
31
  versions: ['>=2'],
@@ -41,10 +45,6 @@ addHook({
41
45
 
42
46
  const asyncResource = new AsyncResource('bound-anonymous-fn')
43
47
 
44
- function finish () {
45
- finishRawQueryCh.publish()
46
- }
47
-
48
48
  return asyncResource.runInAsyncScope(() => {
49
49
  startRawQueryCh.publish({ sql, dialect: this.dialect })
50
50
 
@@ -8,6 +8,7 @@ const {
8
8
  const shimmer = require('../../datadog-shimmer')
9
9
 
10
10
  function isString (value) {
11
+ // eslint-disable-next-line unicorn/no-instanceof-builtins
11
12
  return typeof value === 'string' || value instanceof String
12
13
  }
13
14
 
@@ -61,10 +62,8 @@ addHook({ name: 'ldapjs', versions: ['>=2'] }, ldapjs => {
61
62
  let filter
62
63
  if (isString(options)) {
63
64
  filter = options
64
- } else if (options !== null && typeof options === 'object' && options.filter) {
65
- if (isString(options.filter)) {
66
- filter = options.filter
67
- }
65
+ } else if (options !== null && typeof options === 'object' && options.filter && isString(options.filter)) {
66
+ filter = options.filter
68
67
  }
69
68
  ldapSearchCh.publish({ base, filter })
70
69
  }