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
@@ -41,7 +41,11 @@ const {
41
41
  TEST_MANAGEMENT_ATTEMPT_TO_FIX_PASSED,
42
42
  TEST_HAS_FAILED_ALL_RETRIES,
43
43
  getLibraryCapabilitiesTags,
44
- TEST_RETRY_REASON_TYPES
44
+ TEST_RETRY_REASON_TYPES,
45
+ getPullRequestDiff,
46
+ getModifiedTestsFromDiff,
47
+ TEST_IS_MODIFIED,
48
+ getPullRequestBaseBranch
45
49
  } = require('../../dd-trace/src/plugins/util/test')
46
50
  const { isMarkedAsUnskippable } = require('../../datadog-plugin-jest/src/util')
47
51
  const { ORIGIN_KEY, COMPONENT } = require('../../dd-trace/src/constants')
@@ -67,7 +71,11 @@ const {
67
71
  GIT_BRANCH,
68
72
  CI_PROVIDER_NAME,
69
73
  CI_WORKSPACE_PATH,
70
- GIT_COMMIT_MESSAGE
74
+ GIT_COMMIT_MESSAGE,
75
+ GIT_TAG,
76
+ GIT_PULL_REQUEST_BASE_BRANCH_SHA,
77
+ GIT_COMMIT_HEAD_SHA,
78
+ GIT_PULL_REQUEST_BASE_BRANCH
71
79
  } = require('../../dd-trace/src/plugins/util/tags')
72
80
  const {
73
81
  OS_VERSION,
@@ -76,6 +84,7 @@ const {
76
84
  RUNTIME_NAME,
77
85
  RUNTIME_VERSION
78
86
  } = require('../../dd-trace/src/plugins/util/env')
87
+ const { DD_MAJOR } = require('../../../version')
79
88
 
80
89
  const TEST_FRAMEWORK_NAME = 'cypress'
81
90
 
@@ -175,6 +184,26 @@ function getTestManagementTests (tracer, testConfiguration) {
175
184
  })
176
185
  }
177
186
 
187
+ function getModifiedTests (testEnvironmentMetadata) {
188
+ const {
189
+ [GIT_PULL_REQUEST_BASE_BRANCH]: pullRequestBaseBranch,
190
+ [GIT_PULL_REQUEST_BASE_BRANCH_SHA]: pullRequestBaseBranchSha,
191
+ [GIT_COMMIT_HEAD_SHA]: commitHeadSha
192
+ } = testEnvironmentMetadata
193
+
194
+ const baseBranchSha = pullRequestBaseBranchSha || getPullRequestBaseBranch(pullRequestBaseBranch)
195
+
196
+ if (baseBranchSha) {
197
+ const diff = getPullRequestDiff(baseBranchSha, commitHeadSha)
198
+ const modifiedTests = getModifiedTestsFromDiff(diff)
199
+ if (modifiedTests) {
200
+ return modifiedTests
201
+ }
202
+ }
203
+
204
+ throw new Error('Modified tests could not be retrieved')
205
+ }
206
+
178
207
  function getSuiteStatus (suiteStats) {
179
208
  if (!suiteStats) {
180
209
  return 'skip'
@@ -205,10 +234,13 @@ class CypressPlugin {
205
234
  [GIT_BRANCH]: branch,
206
235
  [CI_PROVIDER_NAME]: ciProviderName,
207
236
  [CI_WORKSPACE_PATH]: repositoryRoot,
208
- [GIT_COMMIT_MESSAGE]: commitMessage
237
+ [GIT_COMMIT_MESSAGE]: commitMessage,
238
+ [GIT_TAG]: tag,
239
+ [GIT_PULL_REQUEST_BASE_BRANCH_SHA]: pullRequestBaseSha,
240
+ [GIT_COMMIT_HEAD_SHA]: commitHeadSha
209
241
  } = this.testEnvironmentMetadata
210
242
 
211
- this.repositoryRoot = repositoryRoot
243
+ this.repositoryRoot = repositoryRoot || process.cwd()
212
244
  this.ciProviderName = ciProviderName
213
245
  this.codeOwnersEntries = getCodeOwnersFileEntries(repositoryRoot)
214
246
 
@@ -222,7 +254,10 @@ class CypressPlugin {
222
254
  runtimeVersion,
223
255
  branch,
224
256
  testLevel: 'test',
225
- commitMessage
257
+ commitMessage,
258
+ tag,
259
+ pullRequestBaseSha,
260
+ commitHeadSha
226
261
  }
227
262
  this.finishedTestsByFile = {}
228
263
  this.testStatuses = {}
@@ -242,6 +277,8 @@ class CypressPlugin {
242
277
  this.knownTests = []
243
278
  this.isTestManagementTestsEnabled = false
244
279
  this.testManagementAttemptToFixRetries = 0
280
+ this.isImpactedTestsEnabled = false
281
+ this.modifiedTests = []
245
282
  }
246
283
 
247
284
  // Init function returns a promise that resolves with the Cypress configuration
@@ -271,7 +308,8 @@ class CypressPlugin {
271
308
  flakyTestRetriesCount,
272
309
  isKnownTestsEnabled,
273
310
  isTestManagementEnabled,
274
- testManagementAttemptToFixRetries
311
+ testManagementAttemptToFixRetries,
312
+ isImpactedTestsEnabled
275
313
  }
276
314
  } = libraryConfigurationResponse
277
315
  this.isSuitesSkippingEnabled = isSuitesSkippingEnabled
@@ -285,12 +323,25 @@ class CypressPlugin {
285
323
  }
286
324
  this.isTestManagementTestsEnabled = isTestManagementEnabled
287
325
  this.testManagementAttemptToFixRetries = testManagementAttemptToFixRetries
326
+ this.isImpactedTestsEnabled = isImpactedTestsEnabled
288
327
  }
289
328
  return this.cypressConfig
290
329
  })
291
330
  return this.libraryConfigurationPromise
292
331
  }
293
332
 
333
+ getIsTestModified (testSuiteAbsolutePath) {
334
+ const relativeTestSuitePath = getTestSuitePath(testSuiteAbsolutePath, this.repositoryRoot)
335
+ if (!this.modifiedTests) {
336
+ return false
337
+ }
338
+ const lines = this.modifiedTests[relativeTestSuitePath]
339
+ if (!lines) {
340
+ return false
341
+ }
342
+ return lines.length > 0
343
+ }
344
+
294
345
  getTestSuiteProperties (testSuite) {
295
346
  return this.testManagementTests?.cypress?.suites?.[testSuite]?.tests || {}
296
347
  }
@@ -455,6 +506,15 @@ class CypressPlugin {
455
506
  }
456
507
  }
457
508
 
509
+ if (this.isImpactedTestsEnabled) {
510
+ try {
511
+ this.modifiedTests = getModifiedTests(this.testEnvironmentMetadata)
512
+ } catch (error) {
513
+ log.error(error)
514
+ this.isImpactedTestsEnabled = false
515
+ }
516
+ }
517
+
458
518
  // `details.specs` are test files
459
519
  details.specs?.forEach(({ absolute, relative }) => {
460
520
  const isUnskippableSuite = isMarkedAsUnskippable({ path: absolute })
@@ -474,7 +534,13 @@ class CypressPlugin {
474
534
  testSessionSpanMetadata[TEST_EARLY_FLAKE_ENABLED] = 'true'
475
535
  }
476
536
 
477
- const testSessionName = getTestSessionName(this.tracer._tracer._config, this.command, this.testEnvironmentMetadata)
537
+ const trimmedCommand = DD_MAJOR < 6 ? this.command : 'cypress run'
538
+
539
+ const testSessionName = getTestSessionName(
540
+ this.tracer._tracer._config,
541
+ trimmedCommand,
542
+ this.testEnvironmentMetadata
543
+ )
478
544
 
479
545
  if (this.tracer._tracer._exporter?.addMetadataTags) {
480
546
  const metadataTags = {}
@@ -601,13 +667,9 @@ class CypressPlugin {
601
667
  const isSkippedByItr = this.testsToSkip.find(test =>
602
668
  cypressTestName === test.name && spec.relative === test.suite
603
669
  )
604
- let testSourceFile
605
-
606
- if (spec.absolute && this.repositoryRoot) {
607
- testSourceFile = getTestSuitePath(spec.absolute, this.repositoryRoot)
608
- } else {
609
- testSourceFile = spec.relative
610
- }
670
+ const testSourceFile = spec.absolute && this.repositoryRoot
671
+ ? getTestSuitePath(spec.absolute, this.repositoryRoot)
672
+ : spec.relative
611
673
 
612
674
  const skippedTestSpan = this.getTestSpan({ testName: cypressTestName, testSuite: spec.relative, testSourceFile })
613
675
 
@@ -683,12 +745,9 @@ class CypressPlugin {
683
745
  if (this.itrCorrelationId) {
684
746
  finishedTest.testSpan.setTag(ITR_CORRELATION_ID, this.itrCorrelationId)
685
747
  }
686
- let testSourceFile
687
- if (spec.absolute && this.repositoryRoot) {
688
- testSourceFile = getTestSuitePath(spec.absolute, this.repositoryRoot)
689
- } else {
690
- testSourceFile = spec.relative
691
- }
748
+ const testSourceFile = spec.absolute && this.repositoryRoot
749
+ ? getTestSuitePath(spec.absolute, this.repositoryRoot)
750
+ : spec.relative
692
751
  if (testSourceFile) {
693
752
  finishedTest.testSpan.setTag(TEST_SOURCE_FILE, testSourceFile)
694
753
  }
@@ -725,7 +784,10 @@ class CypressPlugin {
725
784
  isKnownTestsEnabled: this.isKnownTestsEnabled,
726
785
  isTestManagementEnabled: this.isTestManagementTestsEnabled,
727
786
  testManagementAttemptToFixRetries: this.testManagementAttemptToFixRetries,
728
- testManagementTests: this.getTestSuiteProperties(testSuite)
787
+ testManagementTests: this.getTestSuiteProperties(testSuite),
788
+ isImpactedTestsEnabled: this.isImpactedTestsEnabled,
789
+ isModifiedTest: this.getIsTestModified(testSuiteAbsolutePath),
790
+ repositoryRoot: this.repositoryRoot
729
791
  }
730
792
 
731
793
  if (this.testSuiteSpan) {
@@ -736,7 +798,7 @@ class CypressPlugin {
736
798
  },
737
799
  'dd:beforeEach': (test) => {
738
800
  const { testName, testSuite } = test
739
- const shouldSkip = !!this.testsToSkip.find(test => {
801
+ const shouldSkip = this.testsToSkip.some(test => {
740
802
  return testName === test.name && testSuite === test.suite
741
803
  })
742
804
  const isUnskippable = this.unskippableSuites.includes(testSuite)
@@ -783,7 +845,8 @@ class CypressPlugin {
783
845
  testName,
784
846
  isNew,
785
847
  isEfdRetry,
786
- isAttemptToFix
848
+ isAttemptToFix,
849
+ isModified
787
850
  } = test
788
851
  if (coverage && this.isCodeCoverageEnabled && this.tracer._tracer._exporter?.exportCoverage) {
789
852
  const coverageFiles = getCoveredFilenamesFromCoverage(coverage)
@@ -807,10 +870,10 @@ class CypressPlugin {
807
870
  this.activeTestSpan.setTag(TEST_STATUS, testStatus)
808
871
 
809
872
  // Save the test status to know if it has passed all retries
810
- if (!this.testStatuses[testName]) {
811
- this.testStatuses[testName] = [testStatus]
812
- } else {
873
+ if (this.testStatuses[testName]) {
813
874
  this.testStatuses[testName].push(testStatus)
875
+ } else {
876
+ this.testStatuses[testName] = [testStatus]
814
877
  }
815
878
  const testStatuses = this.testStatuses[testName]
816
879
 
@@ -830,6 +893,13 @@ class CypressPlugin {
830
893
  this.activeTestSpan.setTag(TEST_RETRY_REASON, TEST_RETRY_REASON_TYPES.efd)
831
894
  }
832
895
  }
896
+ if (isModified) {
897
+ this.activeTestSpan.setTag(TEST_IS_MODIFIED, 'true')
898
+ if (isEfdRetry) {
899
+ this.activeTestSpan.setTag(TEST_IS_RETRY, 'true')
900
+ this.activeTestSpan.setTag(TEST_RETRY_REASON, TEST_RETRY_REASON_TYPES.efd)
901
+ }
902
+ }
833
903
  if (isAttemptToFix) {
834
904
  this.activeTestSpan.setTag(TEST_MANAGEMENT_IS_ATTEMPT_TO_FIX, 'true')
835
905
  if (testStatuses.length > 1) {
@@ -838,7 +908,7 @@ class CypressPlugin {
838
908
  }
839
909
  const isLastAttempt = testStatuses.length === this.testManagementAttemptToFixRetries + 1
840
910
  if (isLastAttempt) {
841
- if (testStatuses.some(status => status === 'fail')) {
911
+ if (testStatuses.includes('fail')) {
842
912
  this.activeTestSpan.setTag(TEST_MANAGEMENT_ATTEMPT_TO_FIX_PASSED, 'false')
843
913
  }
844
914
  if (testStatuses.every(status => status === 'fail')) {
@@ -1,6 +1,7 @@
1
1
  const NoopTracer = require('../../dd-trace/src/noop/tracer')
2
2
  const cypressPlugin = require('./cypress-plugin')
3
3
  const satisfies = require('semifies')
4
+ const { DD_MAJOR } = require('../../../version')
4
5
 
5
6
  const noopTask = {
6
7
  'dd:testSuiteStart': () => {
@@ -17,10 +18,19 @@ const noopTask = {
17
18
  }
18
19
  }
19
20
 
20
- module.exports = (on, config) => {
21
+ module.exports = function CypressPlugin (on, config) {
21
22
  const tracer = require('../../dd-trace')
22
23
 
23
24
  if (satisfies(config.version, '<10.2.0')) {
25
+ if (DD_MAJOR >= 6) {
26
+ // eslint-disable-next-line no-console
27
+ console.error(
28
+ 'ERROR: dd-trace v6 has deleted support for Cypress<10.2.0.'
29
+ )
30
+ on('task', noopTask)
31
+ return config
32
+ }
33
+
24
34
  // console.warn does not seem to work in cypress, so using console.log instead
25
35
  // eslint-disable-next-line no-console
26
36
  console.log(
@@ -1,12 +1,15 @@
1
+ /* eslint-disable unicorn/no-abusive-eslint-disable */
1
2
  /* eslint-disable */
2
3
  let isEarlyFlakeDetectionEnabled = false
3
4
  let isKnownTestsEnabled = false
4
5
  let knownTestsForSuite = []
5
- let suiteTests = []
6
6
  let earlyFlakeDetectionNumRetries = 0
7
7
  let isTestManagementEnabled = false
8
8
  let testManagementAttemptToFixRetries = 0
9
9
  let testManagementTests = {}
10
+ let isImpactedTestsEnabled = false
11
+ let isModifiedTest = false
12
+
10
13
  // We need to grab the original window as soon as possible,
11
14
  // in case the test changes the origin. If the test does change the origin,
12
15
  // any call to `cy.window()` will result in a cross origin error.
@@ -48,10 +51,9 @@ function retryTest (test, suiteTests, numRetries, tags) {
48
51
  }
49
52
  }
50
53
 
51
-
52
54
  const oldRunTests = Cypress.mocha.getRunner().runTests
53
55
  Cypress.mocha.getRunner().runTests = function (suite, fn) {
54
- if (!isKnownTestsEnabled && !isTestManagementEnabled) {
56
+ if (!isKnownTestsEnabled && !isTestManagementEnabled && !isImpactedTestsEnabled) {
55
57
  return oldRunTests.apply(this, arguments)
56
58
  }
57
59
  // We copy the new tests at the beginning of the suite run (runTests), so that they're run
@@ -67,10 +69,24 @@ Cypress.mocha.getRunner().runTests = function (suite, fn) {
67
69
  retryTest(test, suite.tests, testManagementAttemptToFixRetries, ['_ddIsAttemptToFix'])
68
70
  }
69
71
  }
72
+ if (isImpactedTestsEnabled && isModifiedTest) {
73
+ test._ddIsModified = true
74
+ if (isEarlyFlakeDetectionEnabled && !isAttemptToFix) {
75
+ retryTest(
76
+ test,
77
+ suite.tests,
78
+ earlyFlakeDetectionNumRetries,
79
+ ['_ddIsModified', '_ddIsEfdRetry', isKnownTestsEnabled && isNewTest(test) && '_ddIsNew']
80
+ )
81
+ }
82
+ }
70
83
  if (isKnownTestsEnabled) {
71
84
  if (!test._ddIsNew && !test.isPending() && isNewTest(test)) {
72
85
  test._ddIsNew = true
73
- if (isEarlyFlakeDetectionEnabled && !isAttemptToFix) {
86
+ if (isImpactedTestsEnabled && isModifiedTest) {
87
+ test._ddIsModified = true
88
+ }
89
+ if (isEarlyFlakeDetectionEnabled && !isAttemptToFix && !isModifiedTest) {
74
90
  retryTest(test, suite.tests, earlyFlakeDetectionNumRetries, ['_ddIsNew', '_ddIsEfdRetry'])
75
91
  }
76
92
  }
@@ -108,6 +124,8 @@ before(function () {
108
124
  isTestManagementEnabled = suiteConfig.isTestManagementEnabled
109
125
  testManagementAttemptToFixRetries = suiteConfig.testManagementAttemptToFixRetries
110
126
  testManagementTests = suiteConfig.testManagementTests
127
+ isImpactedTestsEnabled = suiteConfig.isImpactedTestsEnabled
128
+ isModifiedTest = suiteConfig.isModifiedTest
111
129
  }
112
130
  })
113
131
  })
@@ -133,7 +151,8 @@ afterEach(function () {
133
151
  error: currentTest.err,
134
152
  isNew: currentTest._ddIsNew,
135
153
  isEfdRetry: currentTest._ddIsEfdRetry,
136
- isAttemptToFix: currentTest._ddIsAttemptToFix
154
+ isAttemptToFix: currentTest._ddIsAttemptToFix,
155
+ isModified: currentTest._ddIsModified
137
156
  }
138
157
  try {
139
158
  testInfo.testSourceLine = Cypress.mocha.getRunner().currentRunnable.invocationDetails.line
@@ -0,0 +1,30 @@
1
+ 'use strict'
2
+
3
+ const { entryTags } = require('../../datadog-code-origin')
4
+ const Plugin = require('../../dd-trace/src/plugins/plugin')
5
+ const web = require('../../dd-trace/src/plugins/util/web')
6
+
7
+ class ExpressCodeOriginForSpansPlugin extends Plugin {
8
+ static get id () {
9
+ return 'express'
10
+ }
11
+
12
+ constructor (...args) {
13
+ super(...args)
14
+
15
+ const layerTags = new WeakMap()
16
+
17
+ this.addSub('apm:express:middleware:enter', ({ req, layer }) => {
18
+ const tags = layerTags.get(layer)
19
+ if (!tags) return
20
+ web.getContext(req).span?.addTags(tags)
21
+ })
22
+
23
+ this.addSub('apm:express:route:added', ({ topOfStackFunc, layer }) => {
24
+ if (layerTags.has(layer)) return
25
+ layerTags.set(layer, entryTags(topOfStackFunc))
26
+ })
27
+ }
28
+ }
29
+
30
+ module.exports = ExpressCodeOriginForSpansPlugin
@@ -1,18 +1,16 @@
1
1
  'use strict'
2
2
 
3
- const RouterPlugin = require('../../datadog-plugin-router/src')
3
+ const ExpressTracingPlugin = require('./tracing')
4
+ const ExpressCodeOriginForSpansPlugin = require('./code_origin')
5
+ const CompositePlugin = require('../../dd-trace/src/plugins/composite')
4
6
 
5
- class ExpressPlugin extends RouterPlugin {
6
- static get id () {
7
- return 'express'
8
- }
9
-
10
- constructor (...args) {
11
- super(...args)
12
-
13
- this.addSub('apm:express:request:handle', ({ req }) => {
14
- this.setFramework(req, 'express', this.config)
15
- })
7
+ class ExpressPlugin extends CompositePlugin {
8
+ static get id () { return 'express' }
9
+ static get plugins () {
10
+ return {
11
+ tracing: ExpressTracingPlugin,
12
+ codeOriginForSpans: ExpressCodeOriginForSpansPlugin
13
+ }
16
14
  }
17
15
  }
18
16
 
@@ -0,0 +1,19 @@
1
+ 'use strict'
2
+
3
+ const RouterPlugin = require('../../datadog-plugin-router/src')
4
+
5
+ class ExpressTracingPlugin extends RouterPlugin {
6
+ static get id () {
7
+ return 'express'
8
+ }
9
+
10
+ constructor (...args) {
11
+ super(...args)
12
+
13
+ this.addSub('apm:express:request:handle', ({ req }) => {
14
+ this.setFramework(req, 'express', this.config)
15
+ })
16
+ }
17
+ }
18
+
19
+ module.exports = ExpressTracingPlugin
@@ -7,18 +7,22 @@ class GoogleCloudPubsubClientPlugin extends ClientPlugin {
7
7
  static get type () { return 'messaging' }
8
8
  static get operation () { return 'request' }
9
9
 
10
- start ({ request, api, projectId }) {
10
+ start (ctx) {
11
+ const { request, api, projectId } = ctx
12
+
11
13
  if (api === 'publish') return
12
14
 
13
15
  this.startSpan(this.operationName(), {
14
16
  service: this.config.service || this.serviceName(),
15
- resource: [api, request.name].filter(x => x).join(' '),
17
+ resource: [api, request.name].filter(Boolean).join(' '),
16
18
  kind: this.constructor.kind,
17
19
  meta: {
18
20
  'pubsub.method': api,
19
21
  'gcloud.project_id': projectId
20
22
  }
21
- })
23
+ }, ctx)
24
+
25
+ return ctx.currentStore
22
26
  }
23
27
  }
24
28
 
@@ -7,7 +7,8 @@ class GoogleCloudPubsubConsumerPlugin extends ConsumerPlugin {
7
7
  static get id () { return 'google-cloud-pubsub' }
8
8
  static get operation () { return 'receive' }
9
9
 
10
- start ({ message }) {
10
+ bindStart (ctx) {
11
+ const { message } = ctx
11
12
  const subscription = message._subscriber._subscription
12
13
  const topic = subscription.metadata && subscription.metadata.topic
13
14
  const childOf = this.tracer.extract('text_map', message.attributes) || null
@@ -23,25 +24,29 @@ class GoogleCloudPubsubConsumerPlugin extends ConsumerPlugin {
23
24
  metrics: {
24
25
  'pubsub.ack': 0
25
26
  }
26
- })
27
+ }, ctx)
28
+
27
29
  if (this.config.dsmEnabled && message?.attributes) {
28
30
  const payloadSize = getMessageSize(message)
29
31
  this.tracer.decodeDataStreamsContext(message.attributes)
30
32
  this.tracer
31
33
  .setCheckpoint(['direction:in', `topic:${topic}`, 'type:google-pubsub'], span, payloadSize)
32
34
  }
33
- }
34
35
 
35
- finish (message) {
36
- const span = this.activeSpan
36
+ return ctx.currentStore
37
+ }
37
38
 
38
- if (!span) return
39
+ bindFinish (ctx) {
40
+ const { message } = ctx
41
+ const span = ctx.currentStore.span
39
42
 
40
- if (message.message._handled) {
43
+ if (message?._handled) {
41
44
  span.setTag('pubsub.ack', 1)
42
45
  }
43
46
 
44
47
  super.finish()
48
+
49
+ return ctx.parentStore
45
50
  }
46
51
  }
47
52
 
@@ -7,7 +7,9 @@ class GoogleCloudPubsubProducerPlugin extends ProducerPlugin {
7
7
  static get id () { return 'google-cloud-pubsub' }
8
8
  static get operation () { return 'request' }
9
9
 
10
- start ({ request, api, projectId }) {
10
+ bindStart (ctx) {
11
+ const { request, api, projectId } = ctx
12
+
11
13
  if (api !== 'publish') return
12
14
 
13
15
  const messages = request.messages || []
@@ -19,7 +21,7 @@ class GoogleCloudPubsubProducerPlugin extends ProducerPlugin {
19
21
  'pubsub.method': api, // TODO: remove
20
22
  'pubsub.topic': topic
21
23
  }
22
- })
24
+ }, ctx)
23
25
 
24
26
  for (const msg of messages) {
25
27
  if (!msg.attributes) {
@@ -33,6 +35,8 @@ class GoogleCloudPubsubProducerPlugin extends ProducerPlugin {
33
35
  DsmPathwayCodec.encode(dataStreamsContext, msg.attributes)
34
36
  }
35
37
  }
38
+
39
+ return ctx.currentStore
36
40
  }
37
41
  }
38
42
 
@@ -25,18 +25,18 @@ class GoogleCloudVertexAITracingPlugin extends TracingPlugin {
25
25
  bindStart (ctx) {
26
26
  const { instance, request, resource, stream } = ctx
27
27
 
28
- const tags = this.tagRequest(request, instance, stream)
29
-
30
28
  const span = this.startSpan('vertexai.request', {
31
29
  service: this.config.service,
32
30
  resource,
33
31
  kind: 'client',
34
32
  meta: {
35
- [MEASURED]: 1,
36
- ...tags
33
+ [MEASURED]: 1
37
34
  }
38
35
  }, false)
39
36
 
37
+ const tags = this.tagRequest(request, instance, stream, span)
38
+ span.addTags(tags)
39
+
40
40
  const store = storage('legacy').getStore() || {}
41
41
  ctx.currentStore = { ...store, span }
42
42
 
@@ -51,14 +51,23 @@ class GoogleCloudVertexAITracingPlugin extends TracingPlugin {
51
51
 
52
52
  const response = result?.response
53
53
  if (response) {
54
- const tags = this.tagResponse(response)
54
+ const tags = this.tagResponse(response, span)
55
55
  span.addTags(tags)
56
56
  }
57
57
 
58
58
  span.finish()
59
59
  }
60
60
 
61
- tagRequest (request, instance, stream) {
61
+ /**
62
+ * Generate the request tags.
63
+ *
64
+ * @param {Object} request
65
+ * @param {Object} instance
66
+ * @param {boolean} stream
67
+ * @param {Span} span
68
+ * @returns {Object}
69
+ */
70
+ tagRequest (request, instance, stream, span) {
62
71
  const model = extractModel(instance)
63
72
  const tags = {
64
73
  'vertexai.request.model': model
@@ -81,7 +90,7 @@ class GoogleCloudVertexAITracingPlugin extends TracingPlugin {
81
90
  tags['vertexai.request.stream'] = true
82
91
  }
83
92
 
84
- if (!this.isPromptCompletionSampled()) return tags
93
+ if (!this.isPromptCompletionSampled(span)) return tags
85
94
 
86
95
  const systemInstructions = extractSystemInstructions(instance)
87
96
 
@@ -141,8 +150,16 @@ class GoogleCloudVertexAITracingPlugin extends TracingPlugin {
141
150
  }
142
151
  }
143
152
 
144
- tagResponse (response) {
153
+ /**
154
+ * Generate the response tags.
155
+ *
156
+ * @param {Object} response
157
+ * @param {Span} span
158
+ * @returns {Object}
159
+ */
160
+ tagResponse (response, span) {
145
161
  const tags = {}
162
+ const isSampled = this.isPromptCompletionSampled(span)
146
163
 
147
164
  const candidates = response.candidates
148
165
  for (const [candidateIdx, candidate] of candidates.entries()) {
@@ -154,7 +171,7 @@ class GoogleCloudVertexAITracingPlugin extends TracingPlugin {
154
171
  const role = candidateContent.role
155
172
  tags[`vertexai.response.candidates.${candidateIdx}.content.role`] = role
156
173
 
157
- if (!this.isPromptCompletionSampled()) continue
174
+ if (!isSampled) continue
158
175
 
159
176
  const parts = candidateContent.parts
160
177
  for (const [partIdx, part] of parts.entries()) {
@@ -70,12 +70,12 @@ function getSignature (document, operationName, operationType, calculate) {
70
70
  }
71
71
 
72
72
  return tools.defaultEngineReportingSignature(document, operationName)
73
- } catch (e) {
73
+ } catch {
74
74
  // safety net
75
75
  }
76
76
  }
77
77
 
78
- return [operationType, operationName].filter(val => val).join(' ')
78
+ return [operationType, operationName].filter(Boolean).join(' ')
79
79
  }
80
80
 
81
81
  module.exports = GraphQLExecutePlugin
@@ -47,7 +47,7 @@ function getDepth (config) {
47
47
  function getVariablesFilter (config) {
48
48
  if (typeof config.variables === 'function') {
49
49
  return config.variables
50
- } else if (config.variables instanceof Array) {
50
+ } else if (Array.isArray(config.variables)) {
51
51
  return variables => pick(variables, config.variables)
52
52
  } else if (config.hasOwnProperty('variables')) {
53
53
  log.error('Expected `variables` to be an array or function.')
@@ -55,11 +55,12 @@ function getVariablesFilter (config) {
55
55
  return null
56
56
  }
57
57
 
58
- function getHooks (config) {
59
- const noop = () => { }
60
- const execute = config.hooks?.execute || noop
61
- const parse = config.hooks?.parse || noop
62
- const validate = config.hooks?.validate || noop
58
+ const noop = () => {}
59
+
60
+ function getHooks ({ hooks }) {
61
+ const execute = hooks?.execute ?? noop
62
+ const parse = hooks?.parse ?? noop
63
+ const validate = hooks?.validate ?? noop
63
64
 
64
65
  return { execute, parse, validate }
65
66
  }