dd-trace 5.53.0 → 5.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (368) hide show
  1. package/LICENSE-3rdparty.csv +2 -1
  2. package/ci/cypress/plugin.js +8 -0
  3. package/ci/cypress/polyfills.js +23 -0
  4. package/ci/init.js +8 -7
  5. package/index.d.ts +33 -16
  6. package/initialize.mjs +5 -6
  7. package/package.json +40 -38
  8. package/packages/datadog-code-origin/index.js +22 -4
  9. package/packages/datadog-core/src/utils/src/get.js +1 -1
  10. package/packages/datadog-core/src/utils/src/has.js +1 -1
  11. package/packages/datadog-core/src/utils/src/kebabcase.js +4 -6
  12. package/packages/datadog-core/src/utils/src/parse-tags.js +1 -1
  13. package/packages/datadog-core/src/utils/src/pick.js +2 -2
  14. package/packages/datadog-core/src/utils/src/set.js +1 -1
  15. package/packages/datadog-core/src/utils/src/uniq.js +1 -1
  16. package/packages/datadog-instrumentations/src/amqp10.js +19 -17
  17. package/packages/datadog-instrumentations/src/amqplib.js +52 -35
  18. package/packages/datadog-instrumentations/src/apollo.js +2 -2
  19. package/packages/datadog-instrumentations/src/aws-sdk.js +1 -1
  20. package/packages/datadog-instrumentations/src/cassandra-driver.js +10 -10
  21. package/packages/datadog-instrumentations/src/child_process.js +1 -2
  22. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +89 -75
  23. package/packages/datadog-instrumentations/src/cookie-parser.js +1 -1
  24. package/packages/datadog-instrumentations/src/couchbase.js +6 -9
  25. package/packages/datadog-instrumentations/src/cucumber.js +108 -68
  26. package/packages/datadog-instrumentations/src/cypress.js +2 -1
  27. package/packages/datadog-instrumentations/src/dns.js +5 -5
  28. package/packages/datadog-instrumentations/src/elasticsearch.js +9 -10
  29. package/packages/datadog-instrumentations/src/fastify.js +7 -9
  30. package/packages/datadog-instrumentations/src/fs.js +1 -1
  31. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +35 -43
  32. package/packages/datadog-instrumentations/src/graphql.js +7 -10
  33. package/packages/datadog-instrumentations/src/grpc/client.js +11 -23
  34. package/packages/datadog-instrumentations/src/grpc/server.js +7 -20
  35. package/packages/datadog-instrumentations/src/hapi.js +10 -11
  36. package/packages/datadog-instrumentations/src/helpers/extract-package-and-module-path.js +16 -10
  37. package/packages/datadog-instrumentations/src/helpers/fetch.js +4 -5
  38. package/packages/datadog-instrumentations/src/helpers/hook.js +2 -3
  39. package/packages/datadog-instrumentations/src/helpers/hooks.js +0 -1
  40. package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -41
  41. package/packages/datadog-instrumentations/src/helpers/register.js +11 -12
  42. package/packages/datadog-instrumentations/src/http/client.js +14 -20
  43. package/packages/datadog-instrumentations/src/jest.js +201 -143
  44. package/packages/datadog-instrumentations/src/kafkajs.js +52 -44
  45. package/packages/datadog-instrumentations/src/knex.js +4 -4
  46. package/packages/datadog-instrumentations/src/koa.js +2 -3
  47. package/packages/datadog-instrumentations/src/ldapjs.js +3 -4
  48. package/packages/datadog-instrumentations/src/mariadb.js +49 -65
  49. package/packages/datadog-instrumentations/src/mocha/main.js +116 -73
  50. package/packages/datadog-instrumentations/src/mocha/utils.js +36 -12
  51. package/packages/datadog-instrumentations/src/mocha/worker.js +6 -0
  52. package/packages/datadog-instrumentations/src/mocha.js +3 -1
  53. package/packages/datadog-instrumentations/src/mongodb-core.js +1 -1
  54. package/packages/datadog-instrumentations/src/mysql.js +30 -37
  55. package/packages/datadog-instrumentations/src/mysql2.js +53 -47
  56. package/packages/datadog-instrumentations/src/net.js +1 -1
  57. package/packages/datadog-instrumentations/src/next.js +1 -0
  58. package/packages/datadog-instrumentations/src/nyc.js +3 -2
  59. package/packages/datadog-instrumentations/src/openai.js +22 -24
  60. package/packages/datadog-instrumentations/src/oracledb.js +1 -1
  61. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +4 -3
  62. package/packages/datadog-instrumentations/src/pg.js +3 -5
  63. package/packages/datadog-instrumentations/src/playwright.js +123 -83
  64. package/packages/datadog-instrumentations/src/protobufjs.js +3 -4
  65. package/packages/datadog-instrumentations/src/redis.js +4 -4
  66. package/packages/datadog-instrumentations/src/restify.js +9 -13
  67. package/packages/datadog-instrumentations/src/rhea.js +42 -54
  68. package/packages/datadog-instrumentations/src/router.js +30 -32
  69. package/packages/datadog-instrumentations/src/tedious.js +2 -3
  70. package/packages/datadog-instrumentations/src/vitest.js +87 -52
  71. package/packages/datadog-plugin-amqp10/src/consumer.js +7 -3
  72. package/packages/datadog-plugin-amqp10/src/producer.js +7 -3
  73. package/packages/datadog-plugin-amqplib/src/client.js +6 -2
  74. package/packages/datadog-plugin-amqplib/src/consumer.js +7 -3
  75. package/packages/datadog-plugin-amqplib/src/producer.js +7 -3
  76. package/packages/datadog-plugin-amqplib/src/util.js +1 -1
  77. package/packages/datadog-plugin-apollo/src/gateway/request.js +5 -6
  78. package/packages/datadog-plugin-apollo/src/gateway/validate.js +2 -3
  79. package/packages/datadog-plugin-avsc/src/schema_iterator.js +12 -12
  80. package/packages/datadog-plugin-aws-sdk/src/base.js +15 -10
  81. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +2 -2
  82. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +13 -13
  83. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +3 -5
  84. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +28 -43
  85. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +2 -2
  86. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +10 -11
  87. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +4 -6
  88. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +3 -5
  89. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +3 -5
  90. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +2 -3
  91. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +11 -15
  92. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +1 -1
  93. package/packages/datadog-plugin-aws-sdk/src/util.js +5 -6
  94. package/packages/datadog-plugin-cassandra-driver/src/index.js +1 -1
  95. package/packages/datadog-plugin-child_process/src/index.js +4 -4
  96. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +23 -23
  97. package/packages/datadog-plugin-cucumber/src/index.js +60 -4
  98. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +99 -28
  99. package/packages/datadog-plugin-cypress/src/plugin.js +11 -1
  100. package/packages/datadog-plugin-cypress/src/support.js +24 -5
  101. package/packages/datadog-plugin-dd-trace-api/src/index.js +2 -1
  102. package/packages/datadog-plugin-elasticsearch/src/index.js +1 -1
  103. package/packages/datadog-plugin-express/src/code_origin.js +30 -0
  104. package/packages/datadog-plugin-express/src/index.js +10 -12
  105. package/packages/datadog-plugin-express/src/tracing.js +19 -0
  106. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +7 -3
  107. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +12 -7
  108. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +6 -2
  109. package/packages/datadog-plugin-google-cloud-vertexai/src/tracing.js +27 -10
  110. package/packages/datadog-plugin-graphql/src/execute.js +2 -2
  111. package/packages/datadog-plugin-graphql/src/index.js +10 -8
  112. package/packages/datadog-plugin-graphql/src/resolve.js +19 -12
  113. package/packages/datadog-plugin-graphql/src/tools/index.js +1 -0
  114. package/packages/datadog-plugin-graphql/src/tools/signature.js +1 -0
  115. package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
  116. package/packages/datadog-plugin-grpc/src/client.js +2 -2
  117. package/packages/datadog-plugin-grpc/src/util.js +2 -2
  118. package/packages/datadog-plugin-http/src/client.js +23 -13
  119. package/packages/datadog-plugin-http2/src/client.js +24 -25
  120. package/packages/datadog-plugin-jest/src/index.js +26 -23
  121. package/packages/datadog-plugin-jest/src/util.js +8 -8
  122. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +3 -1
  123. package/packages/datadog-plugin-kafkajs/src/consumer.js +9 -5
  124. package/packages/datadog-plugin-kafkajs/src/producer.js +8 -3
  125. package/packages/datadog-plugin-kafkajs/src/utils.js +1 -1
  126. package/packages/datadog-plugin-langchain/src/handlers/chain.js +7 -7
  127. package/packages/datadog-plugin-langchain/src/handlers/embedding.js +2 -2
  128. package/packages/datadog-plugin-langchain/src/handlers/language_models/chat_model.js +6 -4
  129. package/packages/datadog-plugin-langchain/src/handlers/language_models/llm.js +5 -4
  130. package/packages/datadog-plugin-langchain/src/tracing.js +11 -10
  131. package/packages/datadog-plugin-mariadb/src/index.js +3 -9
  132. package/packages/datadog-plugin-mocha/src/index.js +39 -14
  133. package/packages/datadog-plugin-mongodb-core/src/index.js +3 -2
  134. package/packages/datadog-plugin-mysql/src/index.js +22 -9
  135. package/packages/datadog-plugin-mysql2/src/index.js +16 -0
  136. package/packages/datadog-plugin-net/src/tcp.js +1 -1
  137. package/packages/datadog-plugin-next/src/index.js +7 -6
  138. package/packages/datadog-plugin-openai/src/services.js +6 -10
  139. package/packages/datadog-plugin-openai/src/tracing.js +12 -18
  140. package/packages/datadog-plugin-oracledb/src/index.js +1 -1
  141. package/packages/datadog-plugin-playwright/src/index.js +25 -4
  142. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +8 -9
  143. package/packages/datadog-plugin-redis/src/index.js +2 -4
  144. package/packages/datadog-plugin-rhea/src/consumer.js +8 -6
  145. package/packages/datadog-plugin-rhea/src/producer.js +5 -2
  146. package/packages/datadog-plugin-router/src/index.js +1 -1
  147. package/packages/datadog-plugin-selenium/src/index.js +1 -6
  148. package/packages/datadog-plugin-vitest/src/index.js +52 -35
  149. package/packages/datadog-shimmer/src/shimmer.js +4 -8
  150. package/packages/dd-trace/src/appsec/api_security_sampler.js +2 -2
  151. package/packages/dd-trace/src/appsec/blocked_templates.js +1 -1
  152. package/packages/dd-trace/src/appsec/blocking.js +6 -20
  153. package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +0 -1
  154. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +0 -1
  155. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +0 -1
  156. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secrets-rules.js +0 -1
  157. package/packages/dd-trace/src/appsec/iast/analyzers/hsts-header-missing-analyzer.js +7 -12
  158. package/packages/dd-trace/src/appsec/iast/analyzers/missing-header-analyzer.js +5 -8
  159. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +4 -0
  160. package/packages/dd-trace/src/appsec/iast/analyzers/path-traversal-analyzer.js +9 -12
  161. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +5 -4
  162. package/packages/dd-trace/src/appsec/iast/context/context-plugin.js +2 -3
  163. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +3 -3
  164. package/packages/dd-trace/src/appsec/iast/index.js +1 -0
  165. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +102 -7
  166. package/packages/dd-trace/src/appsec/iast/path-line.js +7 -8
  167. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +16 -24
  168. package/packages/dd-trace/src/appsec/iast/security-controls/parser.js +6 -6
  169. package/packages/dd-trace/src/appsec/iast/taint-tracking/filter.js +2 -2
  170. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations-taint-object.js +3 -3
  171. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +4 -28
  172. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +2 -8
  173. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +3 -4
  174. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs +1 -1
  175. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +7 -8
  176. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -2
  177. package/packages/dd-trace/src/appsec/iast/telemetry/span-tags.js +7 -7
  178. package/packages/dd-trace/src/appsec/iast/telemetry/verbosity.js +2 -3
  179. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/range-utils.js +10 -11
  180. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/command-sensitive-analyzer.js +1 -1
  181. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +1 -1
  182. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/sql-sensitive-analyzer.js +7 -7
  183. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +23 -28
  184. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-regex.js +3 -3
  185. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +4 -4
  186. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +6 -11
  187. package/packages/dd-trace/src/appsec/iast/vulnerabilities.js +0 -1
  188. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +9 -11
  189. package/packages/dd-trace/src/appsec/index.js +5 -5
  190. package/packages/dd-trace/src/appsec/rasp/index.js +15 -15
  191. package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -1
  192. package/packages/dd-trace/src/appsec/reporter.js +232 -41
  193. package/packages/dd-trace/src/appsec/rule_manager.js +2 -2
  194. package/packages/dd-trace/src/appsec/sdk/set_user.js +2 -2
  195. package/packages/dd-trace/src/appsec/sdk/track_event.js +3 -3
  196. package/packages/dd-trace/src/appsec/stack_trace.js +2 -4
  197. package/packages/dd-trace/src/appsec/telemetry/index.js +31 -1
  198. package/packages/dd-trace/src/appsec/telemetry/rasp.js +3 -5
  199. package/packages/dd-trace/src/appsec/telemetry/waf.js +3 -5
  200. package/packages/dd-trace/src/appsec/user_tracking.js +3 -5
  201. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +8 -4
  202. package/packages/dd-trace/src/azure_metadata.js +9 -9
  203. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +9 -8
  204. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +2 -2
  205. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +3 -2
  206. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +3 -3
  207. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +3 -2
  208. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +3 -2
  209. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +3 -2
  210. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +6 -4
  211. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +6 -5
  212. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +7 -6
  213. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +0 -2
  214. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +3 -2
  215. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +5 -4
  216. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +12 -8
  217. package/packages/dd-trace/src/ci-visibility/telemetry.js +4 -0
  218. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +3 -2
  219. package/packages/dd-trace/src/config-helper.js +89 -0
  220. package/packages/dd-trace/src/config.js +159 -129
  221. package/packages/dd-trace/src/config_stable.js +10 -7
  222. package/packages/dd-trace/src/datastreams/encoding.js +9 -9
  223. package/packages/dd-trace/src/datastreams/fnv.js +2 -2
  224. package/packages/dd-trace/src/datastreams/pathway.js +4 -4
  225. package/packages/dd-trace/src/datastreams/processor.js +5 -7
  226. package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +7 -7
  227. package/packages/dd-trace/src/datastreams/schemas/schema_sampler.js +4 -6
  228. package/packages/dd-trace/src/datastreams/size.js +1 -1
  229. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +75 -69
  230. package/packages/dd-trace/src/debugger/devtools_client/condition.js +7 -10
  231. package/packages/dd-trace/src/debugger/devtools_client/defaults.js +1 -1
  232. package/packages/dd-trace/src/debugger/devtools_client/index.js +9 -2
  233. package/packages/dd-trace/src/debugger/devtools_client/remote_config.js +18 -38
  234. package/packages/dd-trace/src/debugger/devtools_client/send.js +3 -2
  235. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +1 -2
  236. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +1 -1
  237. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +11 -14
  238. package/packages/dd-trace/src/debugger/devtools_client/snapshot/redaction.js +4 -4
  239. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +2 -10
  240. package/packages/dd-trace/src/debugger/devtools_client/state.js +10 -3
  241. package/packages/dd-trace/src/debugger/index.js +1 -0
  242. package/packages/dd-trace/src/dogstatsd.js +7 -6
  243. package/packages/dd-trace/src/encode/0.4.js +14 -11
  244. package/packages/dd-trace/src/encode/0.5.js +4 -6
  245. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +8 -8
  246. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +1 -1
  247. package/packages/dd-trace/src/encode/tags-processors.js +1 -1
  248. package/packages/dd-trace/src/exporter.js +7 -6
  249. package/packages/dd-trace/src/exporters/agent/writer.js +1 -5
  250. package/packages/dd-trace/src/exporters/common/docker.js +4 -3
  251. package/packages/dd-trace/src/exporters/common/form-data.js +6 -4
  252. package/packages/dd-trace/src/exporters/common/request.js +5 -2
  253. package/packages/dd-trace/src/exporters/common/util.js +4 -2
  254. package/packages/dd-trace/src/external-logger/src/index.js +5 -5
  255. package/packages/dd-trace/src/flare/file.js +1 -5
  256. package/packages/dd-trace/src/format.js +1 -1
  257. package/packages/dd-trace/src/git_properties.js +1 -1
  258. package/packages/dd-trace/src/id.js +15 -9
  259. package/packages/dd-trace/src/iitm.js +10 -22
  260. package/packages/dd-trace/src/index.js +4 -3
  261. package/packages/dd-trace/src/lambda/handler.js +7 -6
  262. package/packages/dd-trace/src/lambda/index.js +2 -1
  263. package/packages/dd-trace/src/lambda/runtime/patch.js +7 -6
  264. package/packages/dd-trace/src/lambda/runtime/ritm.js +4 -3
  265. package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
  266. package/packages/dd-trace/src/llmobs/index.js +21 -5
  267. package/packages/dd-trace/src/llmobs/noop.js +18 -20
  268. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +6 -6
  269. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +2 -6
  270. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +3 -3
  271. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +11 -13
  272. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +6 -6
  273. package/packages/dd-trace/src/llmobs/plugins/openai.js +2 -3
  274. package/packages/dd-trace/src/llmobs/sdk.js +4 -3
  275. package/packages/dd-trace/src/llmobs/span_processor.js +1 -1
  276. package/packages/dd-trace/src/llmobs/tagger.js +129 -102
  277. package/packages/dd-trace/src/llmobs/util.js +9 -9
  278. package/packages/dd-trace/src/llmobs/writers/base.js +1 -1
  279. package/packages/dd-trace/src/llmobs/writers/util.js +1 -1
  280. package/packages/dd-trace/src/log/index.js +9 -8
  281. package/packages/dd-trace/src/log/log.js +1 -1
  282. package/packages/dd-trace/src/log/writer.js +3 -4
  283. package/packages/dd-trace/src/msgpack/chunk.js +3 -3
  284. package/packages/dd-trace/src/msgpack/encoder.js +31 -31
  285. package/packages/dd-trace/src/noop/dogstatsd.js +6 -6
  286. package/packages/dd-trace/src/noop/span.js +4 -6
  287. package/packages/dd-trace/src/noop/tracer.js +1 -2
  288. package/packages/dd-trace/src/opentelemetry/span_processor.js +2 -2
  289. package/packages/dd-trace/src/opentelemetry/tracer.js +7 -6
  290. package/packages/dd-trace/src/opentracing/propagation/log.js +10 -13
  291. package/packages/dd-trace/src/opentracing/propagation/text_map.js +40 -37
  292. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +8 -4
  293. package/packages/dd-trace/src/opentracing/span.js +16 -20
  294. package/packages/dd-trace/src/opentracing/tracer.js +9 -6
  295. package/packages/dd-trace/src/payload-tagging/config/index.js +17 -21
  296. package/packages/dd-trace/src/payload-tagging/index.js +1 -1
  297. package/packages/dd-trace/src/payload-tagging/tagging.js +6 -6
  298. package/packages/dd-trace/src/pkg.js +1 -1
  299. package/packages/dd-trace/src/plugin_manager.js +4 -3
  300. package/packages/dd-trace/src/plugins/ci_plugin.js +87 -11
  301. package/packages/dd-trace/src/plugins/consumer.js +2 -2
  302. package/packages/dd-trace/src/plugins/inbound.js +5 -1
  303. package/packages/dd-trace/src/plugins/index.js +0 -1
  304. package/packages/dd-trace/src/plugins/outbound.js +4 -5
  305. package/packages/dd-trace/src/plugins/plugin.js +1 -1
  306. package/packages/dd-trace/src/plugins/producer.js +2 -2
  307. package/packages/dd-trace/src/plugins/storage.js +2 -2
  308. package/packages/dd-trace/src/plugins/util/ci.js +28 -20
  309. package/packages/dd-trace/src/plugins/util/git.js +166 -12
  310. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +1 -1
  311. package/packages/dd-trace/src/plugins/util/ip_extractor.js +1 -1
  312. package/packages/dd-trace/src/plugins/util/llm.js +27 -10
  313. package/packages/dd-trace/src/plugins/util/stacktrace.js +9 -2
  314. package/packages/dd-trace/src/plugins/util/test.js +315 -51
  315. package/packages/dd-trace/src/plugins/util/url.js +1 -1
  316. package/packages/dd-trace/src/plugins/util/urlfilter.js +13 -17
  317. package/packages/dd-trace/src/plugins/util/user-provided-git.js +14 -4
  318. package/packages/dd-trace/src/plugins/util/web.js +8 -8
  319. package/packages/dd-trace/src/priority_sampler.js +64 -53
  320. package/packages/dd-trace/src/profiling/config.js +51 -35
  321. package/packages/dd-trace/src/profiling/exporter_cli.js +20 -20
  322. package/packages/dd-trace/src/profiling/exporters/agent.js +1 -1
  323. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +7 -6
  324. package/packages/dd-trace/src/profiling/exporters/file.js +2 -1
  325. package/packages/dd-trace/src/profiling/index.js +2 -1
  326. package/packages/dd-trace/src/profiling/profiler.js +44 -6
  327. package/packages/dd-trace/src/profiling/profilers/events.js +14 -17
  328. package/packages/dd-trace/src/profiling/profilers/shared.js +6 -1
  329. package/packages/dd-trace/src/profiling/profilers/space.js +3 -3
  330. package/packages/dd-trace/src/profiling/profilers/wall.js +6 -7
  331. package/packages/dd-trace/src/profiling/ssi-heuristics.js +3 -5
  332. package/packages/dd-trace/src/profiling/ssi-telemetry-mock-profiler.js +3 -1
  333. package/packages/dd-trace/src/profiling/tagger.js +21 -13
  334. package/packages/dd-trace/src/profiling/webspan-utils.js +1 -1
  335. package/packages/dd-trace/src/proxy.js +9 -10
  336. package/packages/dd-trace/src/random_sampler.js +40 -0
  337. package/packages/dd-trace/src/rate_limiter.js +4 -4
  338. package/packages/dd-trace/src/remote_config/index.js +3 -7
  339. package/packages/dd-trace/src/remote_config/manager.js +25 -13
  340. package/packages/dd-trace/src/require-package-json.js +1 -1
  341. package/packages/dd-trace/src/ritm.js +8 -8
  342. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +5 -4
  343. package/packages/dd-trace/src/sampler.js +41 -4
  344. package/packages/dd-trace/src/sampling_rule.js +12 -3
  345. package/packages/dd-trace/src/scope.js +1 -1
  346. package/packages/dd-trace/src/serverless.js +11 -4
  347. package/packages/dd-trace/src/service-naming/schemas/util.js +1 -1
  348. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +2 -3
  349. package/packages/dd-trace/src/span_processor.js +5 -4
  350. package/packages/dd-trace/src/span_sampler.js +4 -1
  351. package/packages/dd-trace/src/standalone/tracesource.js +2 -3
  352. package/packages/dd-trace/src/standalone/tracesource_priority_sampler.js +1 -2
  353. package/packages/dd-trace/src/startup-log.js +6 -18
  354. package/packages/dd-trace/src/supported-configurations.json +439 -0
  355. package/packages/dd-trace/src/telemetry/dependencies.js +64 -59
  356. package/packages/dd-trace/src/telemetry/logs/log-collector.js +9 -10
  357. package/packages/dd-trace/src/telemetry/metrics.js +10 -5
  358. package/packages/dd-trace/src/telemetry/send-data.js +8 -7
  359. package/packages/dd-trace/src/telemetry/telemetry.js +31 -45
  360. package/packages/dd-trace/src/tracer.js +3 -7
  361. package/packages/dd-trace/src/util.js +1 -6
  362. package/version.js +1 -0
  363. package/packages/datadog-instrumentations/src/paperplane.js +0 -77
  364. package/packages/datadog-plugin-paperplane/src/index.js +0 -25
  365. package/packages/datadog-plugin-paperplane/src/logger.js +0 -11
  366. package/packages/datadog-plugin-paperplane/src/server.js +0 -24
  367. package/packages/dd-trace/src/appsec/iast/analyzers/header-injection-analyzer.js +0 -122
  368. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/header-sensitive-analyzer.js +0 -20
@@ -1,5 +1,6 @@
1
1
  const os = require('os')
2
2
  const fs = require('fs')
3
+ const { getEnvironmentVariable } = require('../../dd-trace/src/config-helper')
3
4
 
4
5
  class StableConfig {
5
6
  constructor () {
@@ -27,7 +28,7 @@ class StableConfig {
27
28
  try {
28
29
  libdatadog = require('@datadog/libdatadog')
29
30
  this.wasm_loaded = true
30
- } catch (e) {
31
+ } catch {
31
32
  this.warnings.push('Can\'t load libdatadog library')
32
33
  return
33
34
  }
@@ -40,6 +41,8 @@ class StableConfig {
40
41
 
41
42
  try {
42
43
  const configurator = new libconfig.JsConfigurator()
44
+ // Intentionally pass through the raw environment variables for reporting.
45
+ // eslint-disable-next-line eslint-rules/eslint-process-env
43
46
  configurator.set_envp(Object.entries(process.env).map(([key, value]) => `${key}=${value}`))
44
47
  configurator.set_args(process.argv)
45
48
  configurator.get_configuration(localConfig.toString(), fleetConfig.toString()).forEach((entry) => {
@@ -78,19 +81,19 @@ class StableConfig {
78
81
  fleetConfigPath = '/opt/datadog-agent/etc/managed/datadog-agent/stable/application_monitoring.yaml'
79
82
  break
80
83
  case 'win32':
81
- localConfigPath = 'C:\\ProgramData\\Datadog\\application_monitoring.yaml'
82
- fleetConfigPath = 'C:\\ProgramData\\Datadog\\managed\\datadog-agent\\stable\\application_monitoring.yaml'
84
+ localConfigPath = String.raw`C:\ProgramData\Datadog\application_monitoring.yaml`
85
+ fleetConfigPath = String.raw`C:\ProgramData\Datadog\managed\datadog-agent\stable\application_monitoring.yaml`
83
86
  break
84
87
  default:
85
88
  break
86
89
  }
87
90
 
88
91
  // Allow overriding the paths for testing
89
- if (process.env.DD_TEST_LOCAL_CONFIG_PATH !== undefined) {
90
- localConfigPath = process.env.DD_TEST_LOCAL_CONFIG_PATH
92
+ if (getEnvironmentVariable('DD_TEST_LOCAL_CONFIG_PATH') !== undefined) {
93
+ localConfigPath = getEnvironmentVariable('DD_TEST_LOCAL_CONFIG_PATH')
91
94
  }
92
- if (process.env.DD_TEST_FLEET_CONFIG_PATH !== undefined) {
93
- fleetConfigPath = process.env.DD_TEST_FLEET_CONFIG_PATH
95
+ if (getEnvironmentVariable('DD_TEST_FLEET_CONFIG_PATH') !== undefined) {
96
+ fleetConfigPath = getEnvironmentVariable('DD_TEST_FLEET_CONFIG_PATH')
94
97
  }
95
98
 
96
99
  return { localConfigPath, fleetConfigPath }
@@ -6,10 +6,10 @@ function encodeVarint (v) {
6
6
  // we leave the least significant bit for the sign.
7
7
  const double = Math.abs(v) * 2
8
8
  if (double > Number.MAX_SAFE_INTEGER) {
9
- return undefined
9
+ return
10
10
  }
11
- const high = Math.floor(double / 0x100000000)
12
- const low = (double & 0xffffffff) | sign
11
+ const high = Math.floor(double / 0x1_00_00_00_00)
12
+ const low = (double & 0xFF_FF_FF_FF) | sign
13
13
  return encodeUvarint64(low, high)
14
14
  }
15
15
 
@@ -21,7 +21,7 @@ function decodeVarint (b) {
21
21
  return [undefined, bytes]
22
22
  }
23
23
  const positive = (low & 1) === 0
24
- const abs = (low >>> 1) + high * 0x80000000
24
+ const abs = (low >>> 1) + high * 0x80_00_00_00
25
25
  return [positive ? abs : -abs, bytes]
26
26
  }
27
27
 
@@ -32,13 +32,13 @@ function encodeUvarint64 (low, high) {
32
32
  let i = 0
33
33
  // if first byte is 1, the number is negative in javascript, but we want to interpret it as positive
34
34
  while ((high !== 0 || low < 0 || low > 0x80) && i < maxVarLen64 - 1) {
35
- result[i] = (low & 0x7f) | 0x80
35
+ result[i] = (low & 0x7F) | 0x80
36
36
  low >>>= 7
37
- low |= (high & 0x7f) << 25
37
+ low |= (high & 0x7F) << 25
38
38
  high >>>= 7
39
39
  i++
40
40
  }
41
- result[i] = low & 0x7f
41
+ result[i] = low & 0x7F
42
42
  return result.slice(0, i + 1)
43
43
  }
44
44
 
@@ -64,11 +64,11 @@ function decodeUvarint64 (
64
64
  return [low, high, bytes]
65
65
  }
66
66
  if (s < 32) {
67
- low |= (n & 0x7f) << s
67
+ low |= (n & 0x7F) << s
68
68
  }
69
69
  if (s > 0) {
70
70
  high |=
71
- s - 32 > 0 ? (n & 0x7f) << (s - 32) : (n & 0x7f) >> (32 - s)
71
+ s - 32 > 0 ? (n & 0x7F) << (s - 32) : (n & 0x7F) >> (32 - s)
72
72
  }
73
73
  s += 7
74
74
  }
@@ -5,14 +5,14 @@ function fnv (data, hvalInit, fnvPrime, fnvSize) {
5
5
  let hval = hvalInit
6
6
  for (const byte of data) {
7
7
  hval = (hval * fnvPrime) % fnvSize
8
- hval = hval ^ BigInt(byte)
8
+ hval ^= BigInt(byte)
9
9
  }
10
10
  return hval
11
11
  }
12
12
 
13
13
  function fnv64 (data) {
14
14
  if (!Buffer.isBuffer(data)) {
15
- data = Buffer.from(data, 'utf-8')
15
+ data = Buffer.from(data, 'utf8')
16
16
  }
17
17
  const byteArray = new Uint8Array(data)
18
18
  return fnv(byteArray, FNV1_64_INIT, FNV_64_PRIME, 2n ** 64n)
@@ -77,19 +77,19 @@ function decodePathwayContextBase64 (pathwayContext) {
77
77
  return decodePathwayContext(encodedPathway)
78
78
  }
79
79
 
80
- class DsmPathwayCodec {
80
+ const DsmPathwayCodec = {
81
81
  // we use a class for encoding / decoding in case we update our encoding/decoding. A class will make updates easier
82
82
  // instead of using individual functions.
83
- static encode (dataStreamsContext, carrier) {
83
+ encode (dataStreamsContext, carrier) {
84
84
  if (!dataStreamsContext || !dataStreamsContext.hash) {
85
85
  return
86
86
  }
87
87
  carrier[CONTEXT_PROPAGATION_KEY_BASE64] = encodePathwayContextBase64(dataStreamsContext)
88
88
 
89
89
  log.debug(() => `Injected into DSM carrier: ${JSON.stringify(pick(carrier, logKeys))}.`)
90
- }
90
+ },
91
91
 
92
- static decode (carrier) {
92
+ decode (carrier) {
93
93
  log.debug(() => `Attempting extract from DSM carrier: ${JSON.stringify(pick(carrier, logKeys))}.`)
94
94
 
95
95
  if (carrier == null) return
@@ -103,10 +103,8 @@ class StatsBucket {
103
103
  forBacklog (backlogData) {
104
104
  const backlog = new Backlog(backlogData)
105
105
  const existingBacklog = this._backlogs.get(backlog.hash)
106
- if (existingBacklog !== undefined) {
107
- if (existingBacklog.offset > backlog.offset) {
108
- return existingBacklog
109
- }
106
+ if (existingBacklog !== undefined && existingBacklog.offset > backlog.offset) {
107
+ return existingBacklog
110
108
  }
111
109
  this._backlogs.set(backlog.hash, backlog)
112
110
  return backlog
@@ -205,7 +203,9 @@ class DataStreamsProcessor {
205
203
  let parentHash = ENTRY_PARENT_HASH
206
204
  let closestOppositeDirectionHash = ENTRY_PARENT_HASH
207
205
  let closestOppositeDirectionEdgeStart = nowNs
208
- if (ctx != null) {
206
+ if (ctx == null) {
207
+ log.debug(() => 'Setting DSM Checkpoint with empty parent context.')
208
+ } else {
209
209
  pathwayStartNs = ctx.pathwayStartNs
210
210
  edgeStartNs = ctx.edgeStartNs
211
211
  parentHash = ctx.hash
@@ -229,8 +229,6 @@ class DataStreamsProcessor {
229
229
  log.debug(
230
230
  () => `Setting DSM Checkpoint from extracted parent context with hash: ${parentHash} and edge tags: ${edgeTags}`
231
231
  )
232
- } else {
233
- log.debug(() => 'Setting DSM Checkpoint with empty parent context.')
234
232
  }
235
233
  const hash = computePathwayHash(this.service, this.env, edgeTags, parentHash)
236
234
  const edgeLatencyNs = nowNs - edgeStartNs
@@ -20,7 +20,7 @@ class SchemaBuilder {
20
20
  static getSchemaDefinition (schema) {
21
21
  const noNones = convertToJsonCompatible(schema)
22
22
  const definition = jsonStringify(noNones)
23
- const id = fnv64(Buffer.from(definition, 'utf-8')).toString()
23
+ const id = fnv64(Buffer.from(definition, 'utf8')).toString()
24
24
  return new Schema(definition, id)
25
25
  }
26
26
 
@@ -117,12 +117,12 @@ function convertKey (key) {
117
117
  function jsonStringify (obj, indent = 2) {
118
118
  // made to stringify json exactly similar to python / java in order for hashing to be the same
119
119
  const jsonString = JSON.stringify(obj, (_, value) => value, indent)
120
- return jsonString.replace(/^ +/gm, ' ') // Replace leading spaces with single space
121
- .replace(/\n/g, '') // Remove newlines
122
- .replace(/{ /g, '{') // Remove space after '{'
123
- .replace(/ }/g, '}') // Remove space before '}'
124
- .replace(/\[ /g, '[') // Remove space after '['
125
- .replace(/ \]/g, ']') // Remove space before ']'
120
+ return jsonString.replaceAll(/^ +/gm, ' ') // Replace leading spaces with single space
121
+ .replaceAll('\n', '') // Remove newlines
122
+ .replaceAll('{ ', '{') // Remove space after '{'
123
+ .replaceAll(' }', '}') // Remove space before '}'
124
+ .replaceAll('[ ', '[') // Remove space after '['
125
+ .replaceAll(' ]', ']') // Remove space before ']'
126
126
  }
127
127
 
128
128
  module.exports = {
@@ -8,12 +8,10 @@ class SchemaSampler {
8
8
 
9
9
  trySample (currentTimeMs) {
10
10
  if (currentTimeMs >= this.lastSampleMs + SAMPLE_INTERVAL_MILLIS) {
11
- if (currentTimeMs >= this.lastSampleMs + SAMPLE_INTERVAL_MILLIS) {
12
- this.lastSampleMs = currentTimeMs
13
- const weight = this.weight
14
- this.weight = 0
15
- return weight
16
- }
11
+ this.lastSampleMs = currentTimeMs
12
+ const weight = this.weight
13
+ this.weight = 0
14
+ return weight
17
15
  }
18
16
  return 0
19
17
  }
@@ -4,7 +4,7 @@ const { types } = require('util')
4
4
 
5
5
  function getSizeOrZero (obj) {
6
6
  if (typeof obj === 'string') {
7
- return Buffer.from(obj, 'utf-8').length
7
+ return Buffer.from(obj, 'utf8').length
8
8
  }
9
9
  if (types.isArrayBuffer(obj)) {
10
10
  return obj.byteLength
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const lock = require('mutexify/promise')()
3
+ const mutex = require('mutexify/promise')()
4
4
  const { getGeneratedPosition } = require('./source-maps')
5
5
  const session = require('./session')
6
6
  const { compile: compileCondition, compileSegments, templateRequiresEvaluation } = require('./condition')
@@ -36,8 +36,9 @@ session.on('scriptLoadingStabilized', () => {
36
36
  })
37
37
 
38
38
  module.exports = {
39
- addBreakpoint,
40
- removeBreakpoint
39
+ addBreakpoint: lock(addBreakpoint),
40
+ removeBreakpoint: lock(removeBreakpoint),
41
+ modifyBreakpoint: lock(modifyBreakpoint)
41
42
  }
42
43
 
43
44
  async function addBreakpoint (probe) {
@@ -89,98 +90,93 @@ async function addBreakpoint (probe) {
89
90
  throw new Error(`Cannot compile expression: ${probe.when.dsl}`, { cause: err })
90
91
  }
91
92
 
92
- const release = await lock()
93
-
94
- try {
95
- const locationKey = generateLocationKey(scriptId, lineNumber, columnNumber)
96
- const breakpoint = locationToBreakpoint.get(locationKey)
97
-
98
- log.debug(
99
- '[debugger:devtools_client] %s breakpoint at %s:%d:%d (probe: %s, version: %d)',
100
- breakpoint ? 'Updating' : 'Adding', url, lineNumber, columnNumber, probe.id, probe.version
101
- )
102
-
103
- if (breakpoint) {
104
- // A breakpoint already exists at this location, so we need to add the probe to the existing breakpoint
105
- await updateBreakpoint(breakpoint, probe)
106
- } else {
107
- // No breakpoint exists at this location, so we need to create a new one
108
- const location = {
109
- scriptId,
110
- lineNumber: lineNumber - 1, // Beware! lineNumber is zero-indexed
111
- columnNumber
112
- }
113
- let result
114
- try {
115
- result = await session.post('Debugger.setBreakpoint', {
116
- location,
117
- condition: probe.condition
118
- })
119
- } catch (err) {
120
- throw new Error(`Error setting breakpoint for probe ${probe.id}`, { cause: err })
121
- }
122
- probeToLocation.set(probe.id, locationKey)
123
- locationToBreakpoint.set(locationKey, { id: result.breakpointId, location, locationKey })
124
- breakpointToProbes.set(result.breakpointId, new Map([[probe.id, probe]]))
93
+ const locationKey = generateLocationKey(scriptId, lineNumber, columnNumber)
94
+ const breakpoint = locationToBreakpoint.get(locationKey)
95
+
96
+ log.debug(
97
+ '[debugger:devtools_client] %s breakpoint at %s:%d:%d (probe: %s, version: %d)',
98
+ breakpoint ? 'Updating' : 'Adding', url, lineNumber, columnNumber, probe.id, probe.version
99
+ )
100
+
101
+ if (breakpoint) {
102
+ // A breakpoint already exists at this location, so we need to add the probe to the existing breakpoint
103
+ await updateBreakpointInternal(breakpoint, probe)
104
+ } else {
105
+ // No breakpoint exists at this location, so we need to create a new one
106
+ const location = {
107
+ scriptId,
108
+ lineNumber: lineNumber - 1, // Beware! lineNumber is zero-indexed
109
+ columnNumber
110
+ }
111
+ let result
112
+ try {
113
+ result = await session.post('Debugger.setBreakpoint', {
114
+ location,
115
+ condition: probe.condition
116
+ })
117
+ } catch (err) {
118
+ throw new Error(`Error setting breakpoint for probe ${probe.id}`, { cause: err })
125
119
  }
126
- } finally {
127
- release()
120
+ probeToLocation.set(probe.id, locationKey)
121
+ locationToBreakpoint.set(locationKey, { id: result.breakpointId, location, locationKey })
122
+ breakpointToProbes.set(result.breakpointId, new Map([[probe.id, probe]]))
128
123
  }
129
124
  }
130
125
 
131
126
  async function removeBreakpoint ({ id }) {
132
127
  if (!sessionStarted) {
133
128
  // We should not get in this state, but abort if we do, so the code doesn't fail unexpected
134
- throw Error(`Cannot remove probe ${id}: Debugger not started`)
129
+ throw new Error(`Cannot remove probe ${id}: Debugger not started`)
135
130
  }
136
131
  if (!probeToLocation.has(id)) {
137
- throw Error(`Unknown probe id: ${id}`)
132
+ throw new Error(`Unknown probe id: ${id}`)
138
133
  }
139
134
 
140
135
  probes.delete(id)
141
136
 
142
- const release = await lock()
137
+ const locationKey = probeToLocation.get(id)
138
+ const breakpoint = locationToBreakpoint.get(locationKey)
139
+ const probesAtLocation = breakpointToProbes.get(breakpoint.id)
143
140
 
144
- try {
145
- const locationKey = probeToLocation.get(id)
146
- const breakpoint = locationToBreakpoint.get(locationKey)
147
- const probesAtLocation = breakpointToProbes.get(breakpoint.id)
148
-
149
- probesAtLocation.delete(id)
150
- probeToLocation.delete(id)
151
-
152
- if (probesAtLocation.size === 0) {
153
- locationToBreakpoint.delete(locationKey)
154
- breakpointToProbes.delete(breakpoint.id)
155
- if (breakpointToProbes.size === 0) {
156
- await stop() // TODO: Will this actually delete the breakpoint?
157
- } else {
158
- try {
159
- await session.post('Debugger.removeBreakpoint', { breakpointId: breakpoint.id })
160
- } catch (err) {
161
- throw new Error(`Error removing breakpoint for probe ${id}`, { cause: err })
162
- }
163
- }
141
+ probesAtLocation.delete(id)
142
+ probeToLocation.delete(id)
143
+
144
+ if (probesAtLocation.size === 0) {
145
+ locationToBreakpoint.delete(locationKey)
146
+ breakpointToProbes.delete(breakpoint.id)
147
+ // TODO: If anything below in this if-block throws, the state is out of sync.
148
+ if (breakpointToProbes.size === 0) {
149
+ await stop() // This will also remove the breakpoint
164
150
  } else {
165
- await updateBreakpoint(breakpoint)
151
+ try {
152
+ await session.post('Debugger.removeBreakpoint', { breakpointId: breakpoint.id })
153
+ } catch (err) {
154
+ throw new Error(`Error removing breakpoint for probe ${id}`, { cause: err })
155
+ }
166
156
  }
167
- } finally {
168
- release()
157
+ } else {
158
+ await updateBreakpointInternal(breakpoint)
169
159
  }
170
160
  }
171
161
 
172
- async function updateBreakpoint (breakpoint, probe) {
162
+ // TODO: Modify existing probe instead of removing it (DEBUG-2817)
163
+ async function modifyBreakpoint (probe) {
164
+ await removeBreakpoint(probe)
165
+ await addBreakpoint(probe)
166
+ }
167
+
168
+ async function updateBreakpointInternal (breakpoint, probe) {
173
169
  const probesAtLocation = breakpointToProbes.get(breakpoint.id)
174
- const conditionBeforeNewProbe = compileCompoundCondition(Array.from(probesAtLocation.values()))
170
+ const conditionBeforeNewProbe = compileCompoundCondition([...probesAtLocation.values()])
175
171
 
176
172
  // If a probe is provided, add it to the breakpoint. If not, it's because we're removing a probe, but potentially
177
- // need to update the condtion of the breakpoint.
173
+ // need to update the condition of the breakpoint.
178
174
  if (probe) {
179
175
  probesAtLocation.set(probe.id, probe)
180
176
  probeToLocation.set(probe.id, breakpoint.locationKey)
181
177
  }
182
178
 
183
- const condition = compileCompoundCondition(Array.from(probesAtLocation.values()))
179
+ const condition = compileCompoundCondition([...probesAtLocation.values()])
184
180
 
185
181
  if (condition || conditionBeforeNewProbe !== condition) {
186
182
  try {
@@ -198,7 +194,6 @@ async function updateBreakpoint (breakpoint, probe) {
198
194
  } catch (err) {
199
195
  throw new Error(`Error setting breakpoint for probe ${probe.id}`, { cause: err })
200
196
  }
201
- breakpoint.id = result.breakpointId
202
197
  breakpointToProbes.set(result.breakpointId, probesAtLocation)
203
198
  }
204
199
  }
@@ -235,6 +230,17 @@ function stop () {
235
230
  return session.post('Debugger.disable')
236
231
  }
237
232
 
233
+ function lock (fn) {
234
+ return async function (...args) {
235
+ const release = await mutex()
236
+ try {
237
+ return await fn(...args)
238
+ } finally {
239
+ release()
240
+ }
241
+ }
242
+ }
243
+
238
244
  // Only if all probes have a condition can we use a compound condition.
239
245
  // Otherwise, we need to evaluate each probe individually once the breakpoint is hit.
240
246
  function compileCompoundCondition (probes) {
@@ -51,9 +51,8 @@ function compileSegments (segments) {
51
51
  let result = '['
52
52
  for (let i = 0; i < segments.length; i++) {
53
53
  const { str, dsl, json } = segments[i]
54
- result += str !== undefined
55
- ? JSON.stringify(str)
56
- : `(() => {
54
+ result += str === undefined
55
+ ? `(() => {
57
56
  try {
58
57
  const result = ${compile(json)}
59
58
  return typeof result === 'string' ? result : $dd_inspect(result, $dd_segmentInspectOptions)
@@ -61,6 +60,7 @@ function compileSegments (segments) {
61
60
  return { expr: ${JSON.stringify(dsl)}, message: \`\${e.name}: \${e.message}\` }
62
61
  }
63
62
  })()`
63
+ : JSON.stringify(str)
64
64
  if (i !== segments.length - 1) {
65
65
  result += ','
66
66
  }
@@ -95,11 +95,9 @@ function compile (node) {
95
95
  }
96
96
  })()`
97
97
  } else if (type === 'instanceof') {
98
- if (isPrimitiveType(value[1])) {
99
- return `(typeof ${compile(value[0])} === '${value[1]}')` // TODO: Is parenthesizing necessary?
100
- } else {
101
- return `Function.prototype[Symbol.hasInstance].call(${assertIdentifier(value[1])}, ${compile(value[0])})`
102
- }
98
+ return isPrimitiveType(value[1])
99
+ ? `(typeof ${compile(value[0])} === '${value[1]}')` // TODO: Is parenthesizing necessary?
100
+ : `Function.prototype[Symbol.hasInstance].call(${assertIdentifier(value[1])}, ${compile(value[0])})`
103
101
  } else if (type === 'ref') {
104
102
  if (value === '@it') {
105
103
  return '$dd_it'
@@ -107,9 +105,8 @@ function compile (node) {
107
105
  return '$dd_key'
108
106
  } else if (value === '@value') {
109
107
  return '$dd_value'
110
- } else {
111
- return assertIdentifier(value)
112
108
  }
109
+ return assertIdentifier(value)
113
110
  } else if (Array.isArray(value)) {
114
111
  const args = value.map(compile)
115
112
  switch (type) {
@@ -3,5 +3,5 @@
3
3
  module.exports = {
4
4
  MAX_SNAPSHOTS_PER_SECOND_GLOBALLY: 25,
5
5
  MAX_SNAPSHOTS_PER_SECOND_PER_PROBE: 1,
6
- MAX_NON_SNAPSHOTS_PER_SECOND_PER_PROBE: 5_000
6
+ MAX_NON_SNAPSHOTS_PER_SECOND_PER_PROBE: 5000
7
7
  }
@@ -65,6 +65,12 @@ session.on('Debugger.paused', async ({ params }) => {
65
65
  for (let i = 0; i < params.hitBreakpoints.length; i++) {
66
66
  const probesAtLocation = breakpointToProbes.get(params.hitBreakpoints[i])
67
67
 
68
+ if (probesAtLocation === undefined) {
69
+ // This might happen due to a race condition where the breakpoint is in the process of being removed
70
+ log.error('[debugger:devtools_client] No probes found for breakpoint %s', params.hitBreakpoints[i])
71
+ continue
72
+ }
73
+
68
74
  if (probesAtLocation.size !== 1) {
69
75
  numberOfProbesOnBreakpoint = numberOfProbesOnBreakpoint + probesAtLocation.size - 1
70
76
  if (numberOfProbesOnBreakpoint > snapshotProbeIndex.length) {
@@ -103,6 +109,7 @@ session.on('Debugger.paused', async ({ params }) => {
103
109
  if (probe.condition !== undefined) {
104
110
  // TODO: Bundle all conditions and evaluate them in a single call
105
111
  // TODO: Handle errors
112
+ // eslint-disable-next-line no-await-in-loop
106
113
  const { result } = await session.post('Debugger.evaluateOnCallFrame', {
107
114
  callFrameId: params.callFrames[0].callFrameId,
108
115
  expression: probe.condition,
@@ -128,7 +135,7 @@ session.on('Debugger.paused', async ({ params }) => {
128
135
 
129
136
  const timestamp = Date.now()
130
137
 
131
- let evalResults = null
138
+ let evalResults
132
139
  const { result } = await session.post('Debugger.evaluateOnCallFrame', {
133
140
  callFrameId: params.callFrames[0].callFrameId,
134
141
  expression: templateExpressions.length === 0
@@ -155,7 +162,7 @@ session.on('Debugger.paused', async ({ params }) => {
155
162
 
156
163
  log.debug(
157
164
  '[debugger:devtools_client] Finished processing breakpoints - main thread paused for: %d ms',
158
- Number(diff) / 1000000
165
+ Number(diff) / 1_000_000
159
166
  )
160
167
 
161
168
  const logger = {
@@ -1,8 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { workerData: { rcPort } } = require('node:worker_threads')
4
- const lock = require('mutexify/promise')()
5
- const { addBreakpoint, removeBreakpoint } = require('./breakpoints')
4
+ const { addBreakpoint, removeBreakpoint, modifyBreakpoint } = require('./breakpoints')
6
5
  const { ackReceived, ackInstalled, ackError } = require('./status')
7
6
  const log = require('../../log')
8
7
 
@@ -57,45 +56,26 @@ async function processMsg (action, probe) {
57
56
  }
58
57
  if (!probe.where.sourceFile && !probe.where.lines) {
59
58
  throw new Error(
60
- // eslint-disable-next-line @stylistic/js/max-len
59
+ // eslint-disable-next-line @stylistic/max-len
61
60
  `Unsupported probe insertion point! Only line-based probes are supported (id: ${probe.id}, version: ${probe.version})`
62
61
  )
63
62
  }
64
63
 
65
- // This lock is to ensure that we don't get the following race condition:
66
- //
67
- // When a breakpoint is being removed and there are no other breakpoints, we disable the debugger by calling
68
- // `Debugger.disable` to free resources. However, if a new breakpoint is being added around the same time, we might
69
- // have a race condition where the new breakpoint thinks that the debugger is already enabled because the removal of
70
- // the other breakpoint hasn't had a chance to call `Debugger.disable` yet. Then once the code that's adding the new
71
- // breakpoints tries to call `Debugger.setBreakpoint` it fails because in the meantime `Debugger.disable` was called.
72
- //
73
- // If the code is ever refactored to not tear down the debugger if there's no active breakpoints, we can safely remove
74
- // this lock.
75
- const release = await lock()
76
-
77
- try {
78
- switch (action) {
79
- case 'unapply':
80
- await removeBreakpoint(probe)
81
- break
82
- case 'apply':
83
- await addBreakpoint(probe)
84
- ackInstalled(probe)
85
- break
86
- case 'modify':
87
- // TODO: Modify existing probe instead of removing it (DEBUG-2817)
88
- await removeBreakpoint(probe)
89
- await addBreakpoint(probe)
90
- ackInstalled(probe) // TODO: Should we also send ackInstalled when modifying a probe?
91
- break
92
- default:
93
- throw new Error(
94
- // eslint-disable-next-line @stylistic/js/max-len
95
- `Cannot process probe ${probe.id} (version: ${probe.version}) - unknown remote configuration action: ${action}`
96
- )
97
- }
98
- } finally {
99
- release()
64
+ switch (action) {
65
+ case 'unapply':
66
+ await removeBreakpoint(probe)
67
+ break
68
+ case 'apply':
69
+ await addBreakpoint(probe)
70
+ ackInstalled(probe)
71
+ break
72
+ case 'modify':
73
+ await modifyBreakpoint(probe)
74
+ ackInstalled(probe)
75
+ break
76
+ default:
77
+ throw new Error(
78
+ `Cannot process probe ${probe.id} (version: ${probe.version}) - unknown remote configuration action: ${action}`
79
+ )
100
80
  }
101
81
  }
@@ -9,6 +9,7 @@ const request = require('../../exporters/common/request')
9
9
  const { GIT_COMMIT_SHA, GIT_REPOSITORY_URL } = require('../../plugins/util/tags')
10
10
  const log = require('../../log')
11
11
  const { version } = require('../../../../../package.json')
12
+ const { getEnvironmentVariable } = require('../../config-helper')
12
13
 
13
14
  module.exports = send
14
15
 
@@ -21,8 +22,8 @@ const hostname = getHostname()
21
22
  const service = config.service
22
23
 
23
24
  const ddtags = [
24
- ['env', process.env.DD_ENV],
25
- ['version', process.env.DD_VERSION],
25
+ ['env', getEnvironmentVariable('DD_ENV')],
26
+ ['version', getEnvironmentVariable('DD_VERSION')],
26
27
  ['debugger_version', version],
27
28
  ['host_name', hostname],
28
29
  [GIT_COMMIT_SHA, config.commitSHA],
@@ -77,9 +77,8 @@ function getObjectProperties (subtype, objectId, opts, depth) {
77
77
  return getProxy(objectId, opts, depth)
78
78
  } else if (subtype === 'arraybuffer') {
79
79
  return getArrayBuffer(objectId, opts, depth)
80
- } else {
81
- return getObject(objectId, opts, depth + 1, subtype === 'array' || subtype === 'typedarray')
82
80
  }
81
+ return getObject(objectId, opts, depth + 1, subtype === 'array' || subtype === 'typedarray')
83
82
  }
84
83
 
85
84
  // TODO: The following extra information from `internalProperties` might be relevant to include for functions:
@@ -40,7 +40,7 @@ async function getLocalStateForCallFrame (
40
40
  return () => new Error('Error getting local state')
41
41
  }
42
42
 
43
- // Deplay calling `processRawState` so the caller gets a chance to resume the main thread before processing `rawState`
43
+ // Delay calling `processRawState` so the caller gets a chance to resume the main thread before processing `rawState`
44
44
  return () => {
45
45
  processedState = processedState ?? processRawState(rawState, maxLength)
46
46
  return processedState