dd-trace 5.80.0 → 5.82.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 (460) hide show
  1. package/LICENSE-3rdparty.csv +79 -88
  2. package/ext/tags.d.ts +1 -0
  3. package/ext/tags.js +1 -0
  4. package/index.d.ts +42 -35
  5. package/loader-hook.mjs +16 -4
  6. package/package.json +33 -56
  7. package/packages/datadog-core/src/utils/src/parse-tags.js +1 -1
  8. package/packages/datadog-esbuild/index.js +44 -26
  9. package/packages/datadog-esbuild/src/utils.js +14 -2
  10. package/packages/datadog-instrumentations/index.js +1 -0
  11. package/packages/datadog-instrumentations/src/aerospike.js +3 -2
  12. package/packages/datadog-instrumentations/src/ai.js +2 -2
  13. package/packages/datadog-instrumentations/src/amqp10.js +1 -1
  14. package/packages/datadog-instrumentations/src/amqplib.js +4 -4
  15. package/packages/datadog-instrumentations/src/anthropic.js +14 -2
  16. package/packages/datadog-instrumentations/src/apollo-server-core.js +2 -2
  17. package/packages/datadog-instrumentations/src/apollo-server.js +1 -1
  18. package/packages/datadog-instrumentations/src/apollo.js +3 -2
  19. package/packages/datadog-instrumentations/src/avsc.js +1 -1
  20. package/packages/datadog-instrumentations/src/aws-sdk.js +6 -2
  21. package/packages/datadog-instrumentations/src/azure-event-hubs.js +4 -3
  22. package/packages/datadog-instrumentations/src/azure-functions.js +2 -2
  23. package/packages/datadog-instrumentations/src/azure-service-bus.js +3 -4
  24. package/packages/datadog-instrumentations/src/bluebird.js +1 -1
  25. package/packages/datadog-instrumentations/src/bullmq.js +11 -0
  26. package/packages/datadog-instrumentations/src/bunyan.js +1 -1
  27. package/packages/datadog-instrumentations/src/cassandra-driver.js +1 -1
  28. package/packages/datadog-instrumentations/src/child_process.js +2 -2
  29. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +3 -3
  30. package/packages/datadog-instrumentations/src/couchbase.js +1 -1
  31. package/packages/datadog-instrumentations/src/crypto.js +1 -1
  32. package/packages/datadog-instrumentations/src/cucumber.js +12 -13
  33. package/packages/datadog-instrumentations/src/cypress.js +1 -1
  34. package/packages/datadog-instrumentations/src/dns.js +1 -1
  35. package/packages/datadog-instrumentations/src/elasticsearch.js +1 -1
  36. package/packages/datadog-instrumentations/src/express-mongo-sanitize.js +1 -1
  37. package/packages/datadog-instrumentations/src/express.js +1 -1
  38. package/packages/datadog-instrumentations/src/find-my-way.js +6 -5
  39. package/packages/datadog-instrumentations/src/fs.js +1 -1
  40. package/packages/datadog-instrumentations/src/generic-pool.js +1 -1
  41. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +137 -15
  42. package/packages/datadog-instrumentations/src/google-cloud-vertexai.js +2 -3
  43. package/packages/datadog-instrumentations/src/google-genai.js +120 -0
  44. package/packages/datadog-instrumentations/src/graphql.js +21 -1
  45. package/packages/datadog-instrumentations/src/grpc/client.js +1 -1
  46. package/packages/datadog-instrumentations/src/grpc/server.js +1 -1
  47. package/packages/datadog-instrumentations/src/helpers/bundler-register.js +1 -1
  48. package/packages/datadog-instrumentations/src/helpers/hook.js +1 -1
  49. package/packages/datadog-instrumentations/src/helpers/hooks.js +5 -1
  50. package/packages/datadog-instrumentations/src/helpers/instrument.js +11 -1
  51. package/packages/datadog-instrumentations/src/helpers/register.js +12 -5
  52. package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +27 -0
  53. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +152 -0
  54. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/bullmq.json +106 -0
  55. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +6 -0
  56. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/langchain.js +237 -0
  57. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.js +9 -0
  58. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +11 -0
  59. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +139 -0
  60. package/packages/datadog-instrumentations/src/helpers/router-helper.js +1 -1
  61. package/packages/datadog-instrumentations/src/helpers/shared-utils.js +9 -0
  62. package/packages/datadog-instrumentations/src/hono.js +55 -10
  63. package/packages/datadog-instrumentations/src/ioredis.js +1 -1
  64. package/packages/datadog-instrumentations/src/iovalkey.js +1 -1
  65. package/packages/datadog-instrumentations/src/jest.js +2 -2
  66. package/packages/datadog-instrumentations/src/kafkajs.js +3 -3
  67. package/packages/datadog-instrumentations/src/knex.js +1 -1
  68. package/packages/datadog-instrumentations/src/langchain.js +3 -109
  69. package/packages/datadog-instrumentations/src/ldapjs.js +1 -1
  70. package/packages/datadog-instrumentations/src/light-my-request.js +93 -0
  71. package/packages/datadog-instrumentations/src/limitd-client.js +1 -1
  72. package/packages/datadog-instrumentations/src/lodash.js +1 -2
  73. package/packages/datadog-instrumentations/src/mariadb.js +1 -2
  74. package/packages/datadog-instrumentations/src/memcached.js +1 -1
  75. package/packages/datadog-instrumentations/src/mocha/main.js +1 -1
  76. package/packages/datadog-instrumentations/src/mongodb-core.js +1 -1
  77. package/packages/datadog-instrumentations/src/mongodb.js +1 -1
  78. package/packages/datadog-instrumentations/src/mongoose.js +1 -1
  79. package/packages/datadog-instrumentations/src/mquery.js +1 -1
  80. package/packages/datadog-instrumentations/src/mysql.js +1 -1
  81. package/packages/datadog-instrumentations/src/mysql2.js +2 -2
  82. package/packages/datadog-instrumentations/src/net.js +1 -1
  83. package/packages/datadog-instrumentations/src/next.js +1 -1
  84. package/packages/datadog-instrumentations/src/nyc.js +1 -1
  85. package/packages/datadog-instrumentations/src/openai.js +2 -2
  86. package/packages/datadog-instrumentations/src/opensearch.js +1 -1
  87. package/packages/datadog-instrumentations/src/oracledb.js +1 -1
  88. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +1 -1
  89. package/packages/datadog-instrumentations/src/pg.js +3 -3
  90. package/packages/datadog-instrumentations/src/pino.js +1 -1
  91. package/packages/datadog-instrumentations/src/playwright.js +46 -17
  92. package/packages/datadog-instrumentations/src/prisma.js +52 -37
  93. package/packages/datadog-instrumentations/src/process.js +1 -1
  94. package/packages/datadog-instrumentations/src/promise-js.js +1 -1
  95. package/packages/datadog-instrumentations/src/promise.js +1 -1
  96. package/packages/datadog-instrumentations/src/protobufjs.js +1 -1
  97. package/packages/datadog-instrumentations/src/q.js +1 -1
  98. package/packages/datadog-instrumentations/src/redis.js +1 -1
  99. package/packages/datadog-instrumentations/src/rhea.js +1 -1
  100. package/packages/datadog-instrumentations/src/router.js +1 -1
  101. package/packages/datadog-instrumentations/src/selenium.js +4 -2
  102. package/packages/datadog-instrumentations/src/sequelize.js +1 -2
  103. package/packages/datadog-instrumentations/src/sharedb.js +1 -1
  104. package/packages/datadog-instrumentations/src/tedious.js +1 -1
  105. package/packages/datadog-instrumentations/src/undici.js +4 -4
  106. package/packages/datadog-instrumentations/src/url.js +1 -1
  107. package/packages/datadog-instrumentations/src/vitest.js +1 -1
  108. package/packages/datadog-instrumentations/src/vm.js +1 -1
  109. package/packages/datadog-instrumentations/src/when.js +1 -1
  110. package/packages/datadog-instrumentations/src/winston.js +1 -1
  111. package/packages/datadog-instrumentations/src/ws.js +38 -19
  112. package/packages/datadog-plugin-amqp10/src/index.js +1 -1
  113. package/packages/datadog-plugin-amqplib/src/index.js +1 -1
  114. package/packages/datadog-plugin-anthropic/src/index.js +1 -1
  115. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js +1 -1
  116. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +4 -4
  117. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +2 -2
  118. package/packages/datadog-plugin-aws-sdk/src/util.js +3 -3
  119. package/packages/datadog-plugin-azure-event-hubs/src/index.js +1 -1
  120. package/packages/datadog-plugin-azure-event-hubs/src/producer.js +19 -5
  121. package/packages/datadog-plugin-azure-service-bus/src/index.js +1 -1
  122. package/packages/datadog-plugin-azure-service-bus/src/producer.js +4 -0
  123. package/packages/datadog-plugin-bullmq/src/consumer.js +60 -0
  124. package/packages/datadog-plugin-bullmq/src/index.js +18 -0
  125. package/packages/datadog-plugin-bullmq/src/producer.js +178 -0
  126. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +1 -1
  127. package/packages/datadog-plugin-confluentinc-kafka-javascript/src/index.js +1 -1
  128. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +23 -2
  129. package/packages/datadog-plugin-cypress/src/plugin.js +2 -2
  130. package/packages/datadog-plugin-cypress/src/support.js +73 -31
  131. package/packages/datadog-plugin-express/src/index.js +1 -1
  132. package/packages/datadog-plugin-fastify/src/index.js +1 -1
  133. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +13 -3
  134. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +171 -12
  135. package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +1 -2
  136. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +160 -13
  137. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +217 -0
  138. package/packages/datadog-plugin-google-cloud-vertexai/src/index.js +1 -1
  139. package/packages/datadog-plugin-google-genai/src/index.js +17 -0
  140. package/packages/datadog-plugin-google-genai/src/tracing.js +41 -0
  141. package/packages/datadog-plugin-graphql/src/resolve.js +1 -1
  142. package/packages/datadog-plugin-graphql/src/tools/transforms.js +5 -4
  143. package/packages/datadog-plugin-grpc/src/index.js +1 -1
  144. package/packages/datadog-plugin-http/src/client.js +2 -1
  145. package/packages/datadog-plugin-http/src/index.js +25 -5
  146. package/packages/datadog-plugin-http2/src/client.js +2 -2
  147. package/packages/datadog-plugin-http2/src/index.js +1 -1
  148. package/packages/datadog-plugin-jest/src/util.js +1 -1
  149. package/packages/datadog-plugin-kafkajs/src/index.js +1 -1
  150. package/packages/datadog-plugin-langchain/src/index.js +1 -1
  151. package/packages/datadog-plugin-langchain/src/tracing.js +7 -3
  152. package/packages/datadog-plugin-moleculer/src/index.js +1 -1
  153. package/packages/datadog-plugin-mongodb-core/src/index.js +6 -2
  154. package/packages/datadog-plugin-next/src/index.js +11 -3
  155. package/packages/datadog-plugin-openai/src/index.js +1 -1
  156. package/packages/datadog-plugin-openai/src/stream-helpers.js +30 -10
  157. package/packages/datadog-plugin-openai/src/tracing.js +2 -2
  158. package/packages/datadog-plugin-rhea/src/index.js +1 -1
  159. package/packages/datadog-plugin-ws/src/close.js +56 -3
  160. package/packages/datadog-plugin-ws/src/index.js +4 -0
  161. package/packages/datadog-plugin-ws/src/producer.js +39 -4
  162. package/packages/datadog-plugin-ws/src/receiver.js +39 -3
  163. package/packages/datadog-plugin-ws/src/server.js +13 -1
  164. package/packages/datadog-plugin-ws/src/util.js +107 -0
  165. package/packages/datadog-shimmer/src/shimmer.js +2 -2
  166. package/packages/dd-trace/src/aiguard/sdk.js +21 -13
  167. package/packages/dd-trace/src/appsec/api_security_sampler.js +1 -1
  168. package/packages/dd-trace/src/appsec/graphql.js +2 -2
  169. package/packages/dd-trace/src/appsec/iast/analyzers/code-injection-analyzer.js +1 -1
  170. package/packages/dd-trace/src/appsec/iast/analyzers/command-injection-analyzer.js +1 -1
  171. package/packages/dd-trace/src/appsec/iast/analyzers/cookie-analyzer.js +1 -1
  172. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-base-analyzer.js +1 -1
  173. package/packages/dd-trace/src/appsec/iast/analyzers/injection-analyzer.js +1 -1
  174. package/packages/dd-trace/src/appsec/iast/analyzers/ldap-injection-analyzer.js +1 -1
  175. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +3 -3
  176. package/packages/dd-trace/src/appsec/iast/analyzers/path-traversal-analyzer.js +1 -1
  177. package/packages/dd-trace/src/appsec/iast/analyzers/ssrf-analyzer.js +1 -1
  178. package/packages/dd-trace/src/appsec/iast/analyzers/untrusted-deserialization-analyzer.js +1 -1
  179. package/packages/dd-trace/src/appsec/iast/analyzers/unvalidated-redirect-analyzer.js +1 -1
  180. package/packages/dd-trace/src/appsec/iast/analyzers/weak-cipher-analyzer.js +1 -1
  181. package/packages/dd-trace/src/appsec/iast/analyzers/weak-hash-analyzer.js +3 -2
  182. package/packages/dd-trace/src/appsec/iast/analyzers/weak-randomness-analyzer.js +1 -1
  183. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +3 -3
  184. package/packages/dd-trace/src/appsec/iast/index.js +5 -5
  185. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +1 -1
  186. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +1 -1
  187. package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +1 -2
  188. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations-taint-object.js +1 -1
  189. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +1 -1
  190. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs +1 -1
  191. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +11 -16
  192. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +1 -1
  193. package/packages/dd-trace/src/appsec/iast/telemetry/namespaces.js +1 -1
  194. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +4 -4
  195. package/packages/dd-trace/src/appsec/index.js +8 -8
  196. package/packages/dd-trace/src/appsec/rasp/command_injection.js +1 -1
  197. package/packages/dd-trace/src/appsec/rasp/index.js +1 -1
  198. package/packages/dd-trace/src/appsec/rasp/lfi.js +1 -1
  199. package/packages/dd-trace/src/appsec/rc-products.js +10 -0
  200. package/packages/dd-trace/src/appsec/recommended.json +230 -3
  201. package/packages/dd-trace/src/appsec/remote_config.js +177 -0
  202. package/packages/dd-trace/src/appsec/reporter.js +3 -7
  203. package/packages/dd-trace/src/appsec/rule_manager.js +37 -20
  204. package/packages/dd-trace/src/appsec/sdk/index.js +1 -1
  205. package/packages/dd-trace/src/appsec/sdk/set_user.js +1 -1
  206. package/packages/dd-trace/src/appsec/sdk/track_event.js +2 -2
  207. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +2 -2
  208. package/packages/dd-trace/src/appsec/user_tracking.js +2 -2
  209. package/packages/dd-trace/src/appsec/waf/index.js +17 -3
  210. package/packages/dd-trace/src/appsec/waf/waf_manager.js +11 -0
  211. package/packages/dd-trace/src/azure_metadata.js +8 -2
  212. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +8 -6
  213. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +2 -2
  214. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +1 -1
  215. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +1 -1
  216. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +4 -2
  217. package/packages/dd-trace/src/config/remote_config.js +34 -0
  218. package/packages/dd-trace/src/config.js +109 -34
  219. package/packages/dd-trace/src/config_defaults.js +16 -3
  220. package/packages/dd-trace/src/constants.js +5 -0
  221. package/packages/dd-trace/src/crashtracking/crashtracker.js +10 -1
  222. package/packages/dd-trace/src/datastreams/checkpointer.js +2 -2
  223. package/packages/dd-trace/src/datastreams/encoding.js +23 -6
  224. package/packages/dd-trace/src/datastreams/index.js +1 -1
  225. package/packages/dd-trace/src/datastreams/pathway.js +41 -2
  226. package/packages/dd-trace/src/datastreams/processor.js +3 -3
  227. package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +1 -1
  228. package/packages/dd-trace/src/datastreams/writer.js +2 -2
  229. package/packages/dd-trace/src/debugger/config.js +1 -0
  230. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +15 -5
  231. package/packages/dd-trace/src/debugger/devtools_client/condition.js +1 -1
  232. package/packages/dd-trace/src/debugger/devtools_client/config.js +3 -1
  233. package/packages/dd-trace/src/debugger/devtools_client/index.js +37 -17
  234. package/packages/dd-trace/src/debugger/devtools_client/inspector_promises_polyfill.js +2 -0
  235. package/packages/dd-trace/src/debugger/devtools_client/json-buffer.js +24 -18
  236. package/packages/dd-trace/src/debugger/devtools_client/send.js +21 -11
  237. package/packages/dd-trace/src/debugger/devtools_client/session.js +1 -1
  238. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +103 -15
  239. package/packages/dd-trace/src/debugger/devtools_client/snapshot/constants.js +25 -0
  240. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +56 -25
  241. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +64 -23
  242. package/packages/dd-trace/src/debugger/devtools_client/snapshot/symbols.js +3 -1
  243. package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +404 -0
  244. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +1 -1
  245. package/packages/dd-trace/src/debugger/devtools_client/state.js +8 -3
  246. package/packages/dd-trace/src/debugger/devtools_client/status.js +3 -3
  247. package/packages/dd-trace/src/debugger/index.js +2 -2
  248. package/packages/dd-trace/src/dogstatsd.js +3 -2
  249. package/packages/dd-trace/src/encode/0.4.js +1 -1
  250. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +2 -2
  251. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +1 -1
  252. package/packages/dd-trace/src/encode/span-stats.js +13 -2
  253. package/packages/dd-trace/src/exporter.js +2 -2
  254. package/packages/dd-trace/src/exporters/agent/index.js +1 -1
  255. package/packages/dd-trace/src/exporters/common/agent-info-exporter.js +1 -1
  256. package/packages/dd-trace/src/exporters/common/request.js +2 -2
  257. package/packages/dd-trace/src/exporters/common/writer.js +1 -1
  258. package/packages/dd-trace/src/exporters/span-stats/index.js +1 -1
  259. package/packages/dd-trace/src/external-logger/src/index.js +1 -2
  260. package/packages/dd-trace/src/flare/index.js +1 -1
  261. package/packages/dd-trace/src/guardrails/index.js +6 -3
  262. package/packages/dd-trace/src/histogram.js +1 -1
  263. package/packages/dd-trace/src/id.js +60 -0
  264. package/packages/dd-trace/src/index.js +1 -1
  265. package/packages/dd-trace/src/lambda/handler.js +4 -4
  266. package/packages/dd-trace/src/lambda/index.js +1 -1
  267. package/packages/dd-trace/src/lambda/runtime/patch.js +4 -4
  268. package/packages/dd-trace/src/lambda/runtime/ritm.js +2 -2
  269. package/packages/dd-trace/src/llmobs/constants/tags.js +8 -1
  270. package/packages/dd-trace/src/llmobs/index.js +8 -9
  271. package/packages/dd-trace/src/llmobs/plugins/ai/index.js +38 -7
  272. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +30 -9
  273. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +3 -3
  274. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +104 -0
  275. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +486 -0
  276. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +1 -1
  277. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +1 -1
  278. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/embedding.js +1 -1
  279. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/llm.js +1 -1
  280. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/vectorstore.js +1 -1
  281. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +2 -2
  282. package/packages/dd-trace/src/llmobs/plugins/openai/constants.js +16 -0
  283. package/packages/dd-trace/src/llmobs/plugins/{openai.js → openai/index.js} +63 -6
  284. package/packages/dd-trace/src/llmobs/plugins/openai/utils.js +126 -0
  285. package/packages/dd-trace/src/llmobs/plugins/vertexai.js +1 -1
  286. package/packages/dd-trace/src/llmobs/sdk.js +20 -22
  287. package/packages/dd-trace/src/llmobs/span_processor.js +15 -14
  288. package/packages/dd-trace/src/llmobs/tagger.js +4 -0
  289. package/packages/dd-trace/src/llmobs/telemetry.js +3 -4
  290. package/packages/dd-trace/src/llmobs/writers/base.js +2 -2
  291. package/packages/dd-trace/src/llmobs/writers/spans.js +1 -2
  292. package/packages/dd-trace/src/log/index.js +1 -1
  293. package/packages/dd-trace/src/noop/proxy.js +2 -2
  294. package/packages/dd-trace/src/noop/span.js +1 -1
  295. package/packages/dd-trace/src/openfeature/index.js +2 -2
  296. package/packages/dd-trace/src/openfeature/noop.js +14 -14
  297. package/packages/dd-trace/src/openfeature/remote_config.js +31 -0
  298. package/packages/dd-trace/src/openfeature/writers/base.js +5 -5
  299. package/packages/dd-trace/src/openfeature/writers/exposures.js +9 -9
  300. package/packages/dd-trace/src/opentelemetry/context_manager.js +2 -2
  301. package/packages/dd-trace/src/opentelemetry/logs/index.js +2 -2
  302. package/packages/dd-trace/src/opentelemetry/logs/logger.js +3 -2
  303. package/packages/dd-trace/src/opentelemetry/logs/logger_provider.js +4 -4
  304. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +5 -3
  305. package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +17 -16
  306. package/packages/dd-trace/src/opentelemetry/metrics/constants.js +34 -0
  307. package/packages/dd-trace/src/opentelemetry/metrics/index.js +81 -0
  308. package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +225 -0
  309. package/packages/dd-trace/src/opentelemetry/metrics/meter.js +171 -0
  310. package/packages/dd-trace/src/opentelemetry/metrics/meter_provider.js +54 -0
  311. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +62 -0
  312. package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +251 -0
  313. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +557 -0
  314. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +10 -18
  315. package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +47 -32
  316. package/packages/dd-trace/src/opentelemetry/otlp/protobuf_loader.js +1 -1
  317. package/packages/dd-trace/src/opentelemetry/span.js +3 -3
  318. package/packages/dd-trace/src/opentelemetry/tracer.js +4 -4
  319. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +1 -1
  320. package/packages/dd-trace/src/opentracing/propagation/text_map.js +24 -8
  321. package/packages/dd-trace/src/opentracing/span.js +3 -3
  322. package/packages/dd-trace/src/opentracing/tracer.js +5 -5
  323. package/packages/dd-trace/src/payload-tagging/index.js +8 -4
  324. package/packages/dd-trace/src/plugin_manager.js +5 -3
  325. package/packages/dd-trace/src/plugins/apollo.js +1 -1
  326. package/packages/dd-trace/src/plugins/ci_plugin.js +27 -27
  327. package/packages/dd-trace/src/plugins/database.js +1 -1
  328. package/packages/dd-trace/src/plugins/index.js +6 -1
  329. package/packages/dd-trace/src/plugins/log_plugin.js +1 -1
  330. package/packages/dd-trace/src/plugins/outbound.js +1 -1
  331. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  332. package/packages/dd-trace/src/plugins/util/ci.js +1 -1
  333. package/packages/dd-trace/src/plugins/util/git.js +8 -8
  334. package/packages/dd-trace/src/plugins/util/stacktrace.js +1 -1
  335. package/packages/dd-trace/src/plugins/util/test.js +27 -27
  336. package/packages/dd-trace/src/plugins/util/url.js +119 -1
  337. package/packages/dd-trace/src/plugins/util/user-provided-git.js +1 -1
  338. package/packages/dd-trace/src/plugins/util/web.js +18 -46
  339. package/packages/dd-trace/src/priority_sampler.js +15 -16
  340. package/packages/dd-trace/src/process-tags/index.js +83 -0
  341. package/packages/dd-trace/src/profiling/config.js +33 -22
  342. package/packages/dd-trace/src/profiling/exporter_cli.js +4 -4
  343. package/packages/dd-trace/src/profiling/exporters/agent.js +5 -5
  344. package/packages/dd-trace/src/profiling/index.js +1 -1
  345. package/packages/dd-trace/src/profiling/libuv-size.js +1 -1
  346. package/packages/dd-trace/src/profiling/profiler.js +4 -5
  347. package/packages/dd-trace/src/profiling/profilers/event_plugins/event.js +1 -1
  348. package/packages/dd-trace/src/profiling/profilers/events.js +11 -2
  349. package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
  350. package/packages/dd-trace/src/proxy.js +17 -18
  351. package/packages/dd-trace/src/rate_limiter.js +1 -1
  352. package/packages/dd-trace/src/remote_config/index.js +541 -137
  353. package/packages/dd-trace/src/require-package-json.js +1 -1
  354. package/packages/dd-trace/src/ritm.js +50 -27
  355. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +1 -1
  356. package/packages/dd-trace/src/serverless.js +16 -0
  357. package/packages/dd-trace/src/service-naming/schemas/v0/messaging.js +8 -0
  358. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +4 -0
  359. package/packages/dd-trace/src/service-naming/schemas/v1/messaging.js +8 -0
  360. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +4 -0
  361. package/packages/dd-trace/src/span_format.js +10 -5
  362. package/packages/dd-trace/src/span_processor.js +8 -3
  363. package/packages/dd-trace/src/span_stats.js +21 -8
  364. package/packages/dd-trace/src/spanleak.js +1 -1
  365. package/packages/dd-trace/src/standalone/index.js +1 -1
  366. package/packages/dd-trace/src/startup-log.js +3 -3
  367. package/packages/dd-trace/src/supported-configurations.json +16 -0
  368. package/packages/dd-trace/src/telemetry/dependencies.js +4 -4
  369. package/packages/dd-trace/src/telemetry/endpoints.js +8 -8
  370. package/packages/dd-trace/src/telemetry/logs/index.js +1 -1
  371. package/packages/dd-trace/src/telemetry/telemetry.js +22 -8
  372. package/packages/dd-trace/src/tracer.js +3 -3
  373. package/packages/dd-trace/src/tracer_metadata.js +19 -15
  374. package/vendor/dist/@datadog/sketches-js/LICENSE +39 -0
  375. package/vendor/dist/@datadog/sketches-js/index.js +1 -0
  376. package/vendor/dist/@datadog/source-map/LICENSE +28 -0
  377. package/vendor/dist/@datadog/source-map/index.js +1 -0
  378. package/vendor/dist/@isaacs/ttlcache/LICENSE +55 -0
  379. package/vendor/dist/@isaacs/ttlcache/index.js +1 -0
  380. package/vendor/dist/@opentelemetry/core/LICENSE +201 -0
  381. package/vendor/dist/@opentelemetry/core/index.js +1 -0
  382. package/vendor/dist/@opentelemetry/resources/LICENSE +201 -0
  383. package/vendor/dist/@opentelemetry/resources/index.js +1 -0
  384. package/vendor/dist/astring/LICENSE +19 -0
  385. package/vendor/dist/astring/index.js +1 -0
  386. package/vendor/dist/crypto-randomuuid/index.js +1 -0
  387. package/vendor/dist/escape-string-regexp/LICENSE +9 -0
  388. package/vendor/dist/escape-string-regexp/index.js +1 -0
  389. package/vendor/dist/esquery/LICENSE +24 -0
  390. package/vendor/dist/esquery/index.js +1 -0
  391. package/vendor/dist/ignore/LICENSE +21 -0
  392. package/vendor/dist/ignore/index.js +1 -0
  393. package/vendor/dist/istanbul-lib-coverage/LICENSE +24 -0
  394. package/vendor/dist/istanbul-lib-coverage/index.js +1 -0
  395. package/vendor/dist/jest-docblock/LICENSE +21 -0
  396. package/vendor/dist/jest-docblock/index.js +1 -0
  397. package/vendor/dist/jsonpath-plus/LICENSE +22 -0
  398. package/vendor/dist/jsonpath-plus/index.js +1 -0
  399. package/vendor/dist/limiter/LICENSE +19 -0
  400. package/vendor/dist/limiter/index.js +1 -0
  401. package/vendor/dist/lodash.sortby/LICENSE +47 -0
  402. package/vendor/dist/lodash.sortby/index.js +1 -0
  403. package/vendor/dist/lru-cache/LICENSE +15 -0
  404. package/vendor/dist/lru-cache/index.js +1 -0
  405. package/vendor/dist/meriyah/LICENSE +7 -0
  406. package/vendor/dist/meriyah/index.js +1 -0
  407. package/vendor/dist/module-details-from-path/LICENSE +21 -0
  408. package/vendor/dist/module-details-from-path/index.js +1 -0
  409. package/vendor/dist/mutexify/promise/LICENSE +21 -0
  410. package/vendor/dist/mutexify/promise/index.js +1 -0
  411. package/vendor/dist/opentracing/LICENSE +201 -0
  412. package/vendor/dist/opentracing/binary_carrier.d.ts +11 -0
  413. package/vendor/dist/opentracing/constants.d.ts +61 -0
  414. package/vendor/dist/opentracing/examples/demo/demo.d.ts +2 -0
  415. package/vendor/dist/opentracing/ext/tags.d.ts +90 -0
  416. package/vendor/dist/opentracing/functions.d.ts +20 -0
  417. package/vendor/dist/opentracing/global_tracer.d.ts +14 -0
  418. package/vendor/dist/opentracing/index.d.ts +12 -0
  419. package/vendor/dist/opentracing/index.js +1 -0
  420. package/vendor/dist/opentracing/mock_tracer/index.d.ts +5 -0
  421. package/vendor/dist/opentracing/mock_tracer/mock_context.d.ts +13 -0
  422. package/vendor/dist/opentracing/mock_tracer/mock_report.d.ts +16 -0
  423. package/vendor/dist/opentracing/mock_tracer/mock_span.d.ts +50 -0
  424. package/vendor/dist/opentracing/mock_tracer/mock_tracer.d.ts +26 -0
  425. package/vendor/dist/opentracing/noop.d.ts +8 -0
  426. package/vendor/dist/opentracing/reference.d.ts +33 -0
  427. package/vendor/dist/opentracing/span.d.ts +147 -0
  428. package/vendor/dist/opentracing/span_context.d.ts +26 -0
  429. package/vendor/dist/opentracing/test/api_compatibility.d.ts +16 -0
  430. package/vendor/dist/opentracing/test/mocktracer_implemenation.d.ts +3 -0
  431. package/vendor/dist/opentracing/test/noop_implementation.d.ts +4 -0
  432. package/vendor/dist/opentracing/test/opentracing_api.d.ts +3 -0
  433. package/vendor/dist/opentracing/test/unittest.d.ts +2 -0
  434. package/vendor/dist/opentracing/tracer.d.ts +127 -0
  435. package/vendor/dist/path-to-regexp/LICENSE +21 -0
  436. package/vendor/dist/path-to-regexp/index.js +1 -0
  437. package/vendor/dist/pprof-format/LICENSE +8 -0
  438. package/vendor/dist/pprof-format/index.js +1 -0
  439. package/vendor/dist/protobufjs/LICENSE +39 -0
  440. package/vendor/dist/protobufjs/index.js +1 -0
  441. package/vendor/dist/protobufjs/minimal/LICENSE +39 -0
  442. package/vendor/dist/protobufjs/minimal/index.js +1 -0
  443. package/vendor/dist/retry/LICENSE +21 -0
  444. package/vendor/dist/retry/index.js +1 -0
  445. package/vendor/dist/rfdc/LICENSE +15 -0
  446. package/vendor/dist/rfdc/index.js +1 -0
  447. package/vendor/dist/semifies/LICENSE +201 -0
  448. package/vendor/dist/semifies/index.js +1 -0
  449. package/vendor/dist/shell-quote/LICENSE +24 -0
  450. package/vendor/dist/shell-quote/index.js +1 -0
  451. package/vendor/dist/source-map/LICENSE +28 -0
  452. package/vendor/dist/source-map/index.js +1 -0
  453. package/vendor/dist/source-map/lib/util/LICENSE +28 -0
  454. package/vendor/dist/source-map/lib/util/index.js +1 -0
  455. package/vendor/dist/source-map/mappings.wasm +0 -0
  456. package/vendor/dist/tlhunter-sorted-set/LICENSE +21 -0
  457. package/vendor/dist/tlhunter-sorted-set/index.js +1 -0
  458. package/vendor/dist/ttl-set/LICENSE +21 -0
  459. package/vendor/dist/ttl-set/index.js +1 -0
  460. package/packages/dd-trace/src/remote_config/manager.js +0 -368
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const { collectionSizeSym, fieldCountSym } = require('./symbols')
3
+ const { LARGE_OBJECT_SKIP_THRESHOLD } = require('./constants')
4
+ const { collectionSizeSym, largeCollectionSkipThresholdSym, fieldCountSym, timeBudgetSym } = require('./symbols')
4
5
  const { normalizeName, REDACTED_IDENTIFIERS } = require('./redaction')
5
6
 
6
7
  module.exports = {
@@ -38,7 +39,7 @@ function getPropertyValue (prop, maxLength) {
38
39
 
39
40
  function getPropertyValueRaw (prop, maxLength) {
40
41
  // Special case for getters and setters which does not have a value property
41
- if (Object.hasOwn(prop, 'get')) {
42
+ if (prop.get) {
42
43
  const hasGet = prop.get.type !== 'undefined'
43
44
  const hasSet = prop.set.type !== 'undefined'
44
45
  if (hasGet) {
@@ -74,11 +75,13 @@ function getPropertyValueRaw (prop, maxLength) {
74
75
  }
75
76
 
76
77
  function getObjectValue (obj, maxLength) {
78
+ const timeBudgetReached = obj[timeBudgetSym] === true
79
+
77
80
  switch (obj.subtype) {
78
81
  case undefined:
79
- return toObject(obj.className, obj.properties, maxLength)
82
+ return toObject(obj.className, obj.properties, maxLength, timeBudgetReached)
80
83
  case 'array':
81
- return toArray(obj.className, obj.properties, maxLength)
84
+ return toArray(obj.className, obj.properties, maxLength, timeBudgetReached)
82
85
  case 'null':
83
86
  return { type: 'null', isNull: true }
84
87
  // case 'node': // TODO: What does this subtype represent?
@@ -89,28 +92,28 @@ function getObjectValue (obj, maxLength) {
89
92
  // in the `description` field. Unfortunately that's all we get from the Chrome DevTools Protocol.
90
93
  return { type: obj.className, value: `${new Date(obj.description).toISOString().slice(0, -5)}Z` }
91
94
  case 'map':
92
- return toMap(obj.className, obj.properties, maxLength)
95
+ return toMap(obj.className, obj.properties, maxLength, timeBudgetReached)
93
96
  case 'set':
94
- return toSet(obj.className, obj.properties, maxLength)
97
+ return toSet(obj.className, obj.properties, maxLength, timeBudgetReached)
95
98
  case 'error':
96
99
  // TODO: Convert stack trace to array to avoid string truncation or disable truncation in this case?
97
- return toObject(obj.className, obj.properties, maxLength)
100
+ return toObject(obj.className, obj.properties, maxLength, timeBudgetReached)
98
101
  case 'proxy':
99
102
  // Use `description` instead of `className` as the `type` to get type of target object (`Proxy(Error)` vs `proxy`)
100
- return toObject(obj.description, obj.properties, maxLength)
103
+ return toObject(obj.description, obj.properties, maxLength, timeBudgetReached)
101
104
  case 'promise':
102
- return toObject(obj.className, obj.properties, maxLength)
105
+ return toObject(obj.className, obj.properties, maxLength, timeBudgetReached)
103
106
  case 'typedarray':
104
- return toArray(obj.className, obj.properties, maxLength)
107
+ return toArray(obj.className, obj.properties, maxLength, timeBudgetReached)
105
108
  case 'generator':
106
109
  // Use `subtype` instead of `className` to make it obvious it's a generator
107
- return toObject(obj.subtype, obj.properties, maxLength)
110
+ return toObject(obj.subtype, obj.properties, maxLength, timeBudgetReached)
108
111
  case 'arraybuffer':
109
- return toArrayBuffer(obj.className, obj.properties, maxLength)
112
+ return toArrayBuffer(obj.className, obj.properties, maxLength, timeBudgetReached)
110
113
  case 'weakmap':
111
- return toMap(obj.className, obj.properties, maxLength)
114
+ return toMap(obj.className, obj.properties, maxLength, timeBudgetReached)
112
115
  case 'weakset':
113
- return toSet(obj.className, obj.properties, maxLength)
116
+ return toSet(obj.className, obj.properties, maxLength, timeBudgetReached)
114
117
  // case 'iterator': // TODO: I've not been able to trigger this subtype
115
118
  // case 'dataview': // TODO: Looks like the internal ArrayBuffer is only accessible via the `buffer` getter
116
119
  // case 'webassemblymemory': // TODO: Looks like the internal ArrayBuffer is only accessible via the `buffer` getter
@@ -127,8 +130,9 @@ function toFunctionOrClass (value, maxLength) {
127
130
 
128
131
  if (classMatch === null) {
129
132
  // This is a function
133
+ const timeBudgetReached = value[timeBudgetSym] === true
130
134
  // TODO: Would it make sense to detect if it's an arrow function or not?
131
- return toObject(value.className, value.properties, maxLength)
135
+ return toObject(value.className, value.properties, maxLength, timeBudgetReached)
132
136
  }
133
137
  // This is a class
134
138
  const className = classMatch[1].trim()
@@ -150,7 +154,8 @@ function toString (str, maxLength) {
150
154
  }
151
155
  }
152
156
 
153
- function toObject (type, props, maxLength) {
157
+ function toObject (type, props, maxLength, timeBudgetReached) {
158
+ if (timeBudgetReached === true) return notCapturedTimeBudget(type)
154
159
  if (props === undefined) return notCapturedDepth(type)
155
160
 
156
161
  const result = {
@@ -158,7 +163,7 @@ function toObject (type, props, maxLength) {
158
163
  fields: processProperties(props, maxLength)
159
164
  }
160
165
 
161
- if (Object.hasOwn(props, fieldCountSym)) {
166
+ if (props[fieldCountSym] !== undefined) {
162
167
  result.notCapturedReason = 'fieldCount'
163
168
  result.size = props[fieldCountSym]
164
169
  }
@@ -166,7 +171,8 @@ function toObject (type, props, maxLength) {
166
171
  return result
167
172
  }
168
173
 
169
- function toArray (type, elements, maxLength) {
174
+ function toArray (type, elements, maxLength, timeBudgetReached) {
175
+ if (timeBudgetReached === true) return notCapturedTimeBudget(type)
170
176
  if (elements === undefined) return notCapturedDepth(type)
171
177
 
172
178
  const result = {
@@ -177,12 +183,15 @@ function toArray (type, elements, maxLength) {
177
183
  }
178
184
 
179
185
  setNotCaptureReasonOnCollection(result, elements)
186
+ setNotCaptureReasonOnTooLargeCollection(result, elements)
180
187
 
181
188
  return result
182
189
  }
183
190
 
184
- function toMap (type, pairs, maxLength) {
191
+ function toMap (type, pairs, maxLength, timeBudgetReached) {
192
+ if (timeBudgetReached === true) return notCapturedTimeBudget(type)
185
193
  if (pairs === undefined) return notCapturedDepth(type)
194
+ if (pairs.length > 0 && pairs.every(({ value }) => value[timeBudgetSym] === true)) return notCapturedTimeBudget(type)
186
195
 
187
196
  const result = {
188
197
  type,
@@ -195,6 +204,14 @@ function toMap (type, pairs, maxLength) {
195
204
  // This can be skipped and we can go directly to its children, of which
196
205
  // there will always be exactly two, the first containing the key, and the
197
206
  // second containing the value of this entry of the Map.
207
+
208
+ if (value[timeBudgetSym] === true) {
209
+ return [{ notCapturedReason: 'timeout' }, { notCapturedReason: 'timeout' }]
210
+ }
211
+ if (value.properties === undefined) {
212
+ return [{ notCapturedReason: 'unknown' }, { notCapturedReason: 'unknown' }]
213
+ }
214
+
198
215
  const shouldRedact = shouldRedactMapValue(value.properties[0])
199
216
  const key = getPropertyValue(value.properties[0], maxLength)
200
217
  const val = shouldRedact
@@ -205,12 +222,17 @@ function toMap (type, pairs, maxLength) {
205
222
  }
206
223
 
207
224
  setNotCaptureReasonOnCollection(result, pairs)
225
+ setNotCaptureReasonOnTooLargeCollection(result, pairs)
208
226
 
209
227
  return result
210
228
  }
211
229
 
212
- function toSet (type, values, maxLength) {
230
+ function toSet (type, values, maxLength, timeBudgetReached) {
231
+ if (timeBudgetReached === true) return notCapturedTimeBudget(type)
213
232
  if (values === undefined) return notCapturedDepth(type)
233
+ if (values.length > 0 && values.every(({ value }) => value[timeBudgetSym] === true)) {
234
+ return notCapturedTimeBudget(type)
235
+ }
214
236
 
215
237
  const result = {
216
238
  type,
@@ -223,16 +245,22 @@ function toSet (type, values, maxLength) {
223
245
  // `internal#entry`. This can be skipped and we can go directly to its
224
246
  // children, of which there will always be exactly one, which contain the
225
247
  // actual value in this entry of the Set.
248
+
249
+ if (value[timeBudgetSym] === true) return { notCapturedReason: 'timeout' }
250
+ if (value.properties === undefined) return { notCapturedReason: 'unknown' }
251
+
226
252
  return getPropertyValue(value.properties[0], maxLength)
227
253
  })
228
254
  }
229
255
 
230
256
  setNotCaptureReasonOnCollection(result, values)
257
+ setNotCaptureReasonOnTooLargeCollection(result, values)
231
258
 
232
259
  return result
233
260
  }
234
261
 
235
- function toArrayBuffer (type, bytes, maxLength) {
262
+ function toArrayBuffer (type, bytes, maxLength, timeBudgetReached) {
263
+ if (timeBudgetReached === true) return notCapturedTimeBudget(type)
236
264
  if (bytes === undefined) return notCapturedDepth(type)
237
265
 
238
266
  const size = bytes.length
@@ -271,16 +299,25 @@ function shouldRedactMapValue (key) {
271
299
  }
272
300
 
273
301
  function getNormalizedNameFromProp (prop) {
274
- return normalizeName(prop.name, Object.hasOwn(prop, 'symbol'))
302
+ return normalizeName(prop.name, prop.symbol !== undefined)
275
303
  }
276
304
 
277
305
  function setNotCaptureReasonOnCollection (result, collection) {
278
- if (Object.hasOwn(collection, collectionSizeSym)) {
306
+ if (collection[collectionSizeSym] !== undefined) {
279
307
  result.notCapturedReason = 'collectionSize'
280
308
  result.size = collection[collectionSizeSym]
281
309
  }
282
310
  }
283
311
 
312
+ function setNotCaptureReasonOnTooLargeCollection (result, collection) {
313
+ if (collection[largeCollectionSkipThresholdSym] !== undefined) {
314
+ result.notCapturedReason = `Large collection with too many elements (skip threshold: ${
315
+ LARGE_OBJECT_SKIP_THRESHOLD
316
+ })`
317
+ result.size = collection[largeCollectionSkipThresholdSym]
318
+ }
319
+ }
320
+
284
321
  function notCapturedDepth (type) {
285
322
  return { type, notCapturedReason: 'depth' }
286
323
  }
@@ -288,3 +325,7 @@ function notCapturedDepth (type) {
288
325
  function notCapturedRedacted (type) {
289
326
  return { type, notCapturedReason: 'redactedIdent' }
290
327
  }
328
+
329
+ function notCapturedTimeBudget (type) {
330
+ return { type, notCapturedReason: 'timeout' }
331
+ }
@@ -2,5 +2,7 @@
2
2
 
3
3
  module.exports = {
4
4
  collectionSizeSym: Symbol('datadog.collectionSize'),
5
- fieldCountSym: Symbol('datadog.fieldCount')
5
+ largeCollectionSkipThresholdSym: Symbol('datadog.largeCollectionSkipThresholdSym'),
6
+ fieldCountSym: Symbol('datadog.fieldCount'),
7
+ timeBudgetSym: Symbol('datadog.timeout')
6
8
  }
@@ -0,0 +1,404 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * This module provides functionality to intelligently prune oversized JSON snapshots by selectively removing the
5
+ * largest and deepest leaf nodes while preserving the schema structure.
6
+ */
7
+
8
+ // The RFC specifies that we should prune nodes at level 5 or deeper, but the Node.js implementation has an extra level
9
+ // of depth because it doesn't use the compound key `debugger.snapshot`, but individual `debugger` and `snapshot` keys,
10
+ // so we prune at level 6 or deeper. This level contains the `locals` key.
11
+ const MIN_PRUNE_LEVEL = 6
12
+ const PRUNED_JSON = '{"pruned":true}'
13
+ const PRUNED_JSON_BYTES = Buffer.byteLength(PRUNED_JSON)
14
+
15
+ module.exports = { pruneSnapshot }
16
+
17
+ /**
18
+ * Tree node representing a JSON object in the parsed structure
19
+ */
20
+ class TreeNode {
21
+ /** @type {number} End position in JSON string (set when object closes) */
22
+ end = -1
23
+ /** @type {TreeNode[]} Child nodes */
24
+ children = []
25
+ /** @type {boolean} Has notCapturedReason: "depth" */
26
+ notCapturedDepth = false
27
+ /** @type {boolean} Has any notCapturedReason */
28
+ notCaptured = false
29
+ /** @type {number} Cached byte size */
30
+ #sizeCache = -1
31
+ /** @type {[number, number, number, number]|null} Cached priority key */
32
+ #priorityKeyCache = null
33
+
34
+ /**
35
+ * @param {number} start - Start position in JSON string
36
+ * @param {number} level - Depth in tree (root = 0)
37
+ * @param {string} json - Reference to original JSON string
38
+ * @param {TreeNode|null} [parent] - Parent node reference
39
+ */
40
+ constructor (start, level, json, parent = null) {
41
+ /** @type {number} Start position in JSON string */
42
+ this.start = start
43
+ /** @type {number} Depth in tree (root = 0) */
44
+ this.level = level
45
+ /** @type {string} Reference to original JSON string */
46
+ this.json = json
47
+ /** @type {TreeNode|null} Parent node reference */
48
+ this.parent = parent
49
+ }
50
+
51
+ get size () {
52
+ if (this.#sizeCache === -1) {
53
+ if (this.end === -1) {
54
+ throw new Error('Cannot get size: node.end has not been set yet')
55
+ }
56
+ this.#sizeCache = Buffer.byteLength(this.json.slice(this.start, this.end + 1))
57
+ }
58
+ return this.#sizeCache
59
+ }
60
+
61
+ get isLeaf () {
62
+ return this.children.length === 0
63
+ }
64
+
65
+ /**
66
+ * Priority key for sorting in queue (higher values = higher priority for pruning).
67
+ * Cached to avoid repeated computation during heap operations.
68
+ *
69
+ * @returns {[number, number, number, number]} Priority key tuple: [not_captured_depth, level, not_captured, size]
70
+ */
71
+ get priorityKey () {
72
+ if (this.#priorityKeyCache === null) {
73
+ this.#priorityKeyCache = [
74
+ this.notCapturedDepth ? 1 : 0,
75
+ this.level,
76
+ this.notCaptured ? 1 : 0,
77
+ this.size
78
+ ]
79
+ }
80
+ return this.#priorityKeyCache
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Priority queue implementation using a binary heap.
86
+ * Items with higher priority (by priorityKey) are popped first.
87
+ */
88
+ class PriorityQueue {
89
+ /** @type {TreeNode[]} Binary heap of nodes */
90
+ #heap = []
91
+
92
+ push (node) {
93
+ this.#heap.push(node)
94
+ this.#bubbleUp(this.#heap.length - 1)
95
+ }
96
+
97
+ pop () {
98
+ if (this.#heap.length === 0) return
99
+ if (this.#heap.length === 1) return /** @type {TreeNode} */ (this.#heap.pop())
100
+
101
+ const top = this.#heap[0]
102
+ this.#heap[0] = /** @type {TreeNode} */ (this.#heap.pop())
103
+ this.#bubbleDown(0)
104
+ return top
105
+ }
106
+
107
+ get size () {
108
+ return this.#heap.length
109
+ }
110
+
111
+ #bubbleUp (index) {
112
+ while (index > 0) {
113
+ const parentIndex = Math.floor((index - 1) / 2)
114
+ if (this.#compare(this.#heap[index], this.#heap[parentIndex]) <= 0) break
115
+
116
+ [this.#heap[index], this.#heap[parentIndex]] = [this.#heap[parentIndex], this.#heap[index]]
117
+ index = parentIndex
118
+ }
119
+ }
120
+
121
+ #bubbleDown (index) {
122
+ while (true) {
123
+ let largest = index
124
+ const leftChild = 2 * index + 1
125
+ const rightChild = 2 * index + 2
126
+
127
+ if (leftChild < this.#heap.length && this.#compare(this.#heap[leftChild], this.#heap[largest]) > 0) {
128
+ largest = leftChild
129
+ }
130
+ if (rightChild < this.#heap.length && this.#compare(this.#heap[rightChild], this.#heap[largest]) > 0) {
131
+ largest = rightChild
132
+ }
133
+
134
+ if (largest === index) break
135
+
136
+ [this.#heap[index], this.#heap[largest]] = [this.#heap[largest], this.#heap[index]]
137
+ index = largest
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Compare two nodes by their priority keys.
143
+ *
144
+ * @param {TreeNode} a - First node to compare
145
+ * @param {TreeNode} b - Second node to compare
146
+ * @returns {number} - > 0 if a has higher priority, < 0 if b has higher priority, 0 if equal
147
+ */
148
+ #compare (a, b) {
149
+ const keyA = a.priorityKey
150
+ const keyB = b.priorityKey
151
+ for (let i = 0; i < 4; i++) {
152
+ if (keyA[i] !== keyB[i]) {
153
+ return keyA[i] - keyB[i]
154
+ }
155
+ }
156
+ return 0
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Parse JSON string and build a tree of objects with position tracking.
162
+ * Also detects notCapturedReason properties to set node flags.
163
+ *
164
+ * @param {string} json - The JSON string to parse
165
+ * @returns {TreeNode|null} The root node of the tree, or null if parsing fails
166
+ */
167
+ function parseJsonToTree (json) {
168
+ /** @type {TreeNode[]} Stack of nodes */
169
+ const stack = []
170
+ /** @type {TreeNode|null} The root node of the tree, or null if parsing fails */
171
+ let root = null
172
+ let depth = 0
173
+
174
+ for (let index = 0; index < json.length; index++) {
175
+ switch (json.charCodeAt(index)) {
176
+ case 34: { // 34: double quote
177
+ const stringStart = index + 1
178
+ index = skipString(json, index)
179
+ const stringLength = index - stringStart
180
+
181
+ // Check if this is "notCapturedReason" property (check length first for performance)
182
+ if (stringLength === 17 && json.startsWith('notCapturedReason', stringStart)) {
183
+ // Look ahead for colon and value
184
+ let ahead = index + 1
185
+
186
+ // Skip whitespace and colon
187
+ while (ahead < json.length) {
188
+ const code = json.charCodeAt(ahead)
189
+ // 32: space, 9: tab, 10: newline, 13: carriage return, 58: colon
190
+ if (code === 32 || code === 9 || code === 10 || code === 13 || code === 58) {
191
+ ahead++
192
+ } else {
193
+ break
194
+ }
195
+ }
196
+
197
+ // Check if value is a string (34: double quote)
198
+ if (ahead < json.length && json.charCodeAt(ahead) === 34) {
199
+ const valueStart = ahead + 1
200
+ ahead = skipString(json, ahead)
201
+ const reason = json.slice(valueStart, ahead)
202
+
203
+ const currentNode = /** @type {TreeNode} */ (stack.at(-1))
204
+ currentNode.notCaptured = true
205
+ if (reason === 'depth') {
206
+ currentNode.notCapturedDepth = true
207
+ }
208
+ }
209
+ }
210
+ break
211
+ }
212
+ case 123: { // 123: opening brace
213
+ const parentNode = stack.at(-1)
214
+ const level = depth
215
+ const node = new TreeNode(index, level, json, parentNode)
216
+
217
+ if (parentNode) {
218
+ parentNode.children.push(node)
219
+ } else {
220
+ root = node
221
+ }
222
+
223
+ stack.push(node)
224
+ depth++
225
+ break
226
+ }
227
+ case 125: { // 125: closing brace
228
+ const node = stack.pop()
229
+ if (node === undefined) throw new SyntaxError('Invalid JSON: unexpected closing brace')
230
+ node.end = index
231
+ depth--
232
+ break
233
+ }
234
+ }
235
+ }
236
+
237
+ return root
238
+ }
239
+
240
+ /**
241
+ * Skip to the end of a JSON string, properly handling escape sequences.
242
+ *
243
+ * @param {string} json - The JSON string to skip
244
+ * @param {number} startIndex - The index to start skipping from
245
+ * @returns {number} The index of the closing quote
246
+ */
247
+ function skipString (json, startIndex) {
248
+ let index = startIndex + 1 // Skip opening quote
249
+
250
+ while (index < json.length) {
251
+ const code = json.charCodeAt(index)
252
+
253
+ if (code === 92) { // 92: backslash
254
+ // Skip the backslash and the next character (whatever it is)
255
+ index += 2
256
+ continue
257
+ }
258
+
259
+ if (code === 34) { // 34: double quote
260
+ // Found unescaped closing quote
261
+ return index
262
+ }
263
+
264
+ index++
265
+ }
266
+
267
+ return index
268
+ }
269
+
270
+ /**
271
+ * Collect all leaf nodes at MIN_PRUNE_LEVEL or deeper.
272
+ *
273
+ * @param {TreeNode} root - The root node of the tree
274
+ * @returns {TreeNode[]} The array of leaf nodes
275
+ */
276
+ function collectPrunableLeaves (root) {
277
+ const leaves = []
278
+
279
+ function traverse (node) {
280
+ if (!node) return
281
+
282
+ if (node.isLeaf && node.level >= MIN_PRUNE_LEVEL) {
283
+ leaves.push(node)
284
+ }
285
+
286
+ for (const child of node.children) {
287
+ traverse(child)
288
+ }
289
+ }
290
+
291
+ traverse(root)
292
+ return leaves
293
+ }
294
+
295
+ /**
296
+ * Select nodes to prune using the priority queue algorithm.
297
+ *
298
+ * @param {TreeNode} root - The root node of the tree
299
+ * @param {number} bytesToRemove - The number of bytes to remove
300
+ * @returns {Set<TreeNode>} The set of nodes marked for pruning
301
+ */
302
+ function selectNodesToPrune (root, bytesToRemove) {
303
+ const queue = new PriorityQueue()
304
+ const prunedNodes = new Set()
305
+ const promotedParents = new Set()
306
+
307
+ // Collect initial leaf nodes
308
+ const leaves = collectPrunableLeaves(root)
309
+ for (const leaf of leaves) {
310
+ queue.push(leaf)
311
+ }
312
+
313
+ let bytesRemoved = 0
314
+
315
+ while (queue.size > 0 && bytesRemoved < bytesToRemove) {
316
+ const node = /** @type {TreeNode} */ (queue.pop())
317
+
318
+ if (prunedNodes.has(node)) continue
319
+ prunedNodes.add(node)
320
+
321
+ bytesRemoved += node.size - PRUNED_JSON_BYTES
322
+
323
+ // Check if parent should be promoted to leaf
324
+ const parent = node.parent
325
+ if (parent && parent.level >= MIN_PRUNE_LEVEL && !promotedParents.has(parent)) {
326
+ // Check if all children are now pruned
327
+ const allChildrenPruned = parent.children.every(child => prunedNodes.has(child))
328
+
329
+ if (allChildrenPruned) {
330
+ // Unmark all children as pruned (parent will represent them)
331
+ for (const child of parent.children) {
332
+ prunedNodes.delete(child)
333
+ bytesRemoved -= child.size - PRUNED_JSON_BYTES
334
+ }
335
+
336
+ // Promote parent to leaf by marking it with notCapturedDepth flag
337
+ parent.notCaptured = true
338
+ parent.notCapturedDepth = true
339
+ promotedParents.add(parent)
340
+
341
+ // Add parent to queue for potential pruning
342
+ queue.push(parent)
343
+ }
344
+ }
345
+ }
346
+
347
+ return prunedNodes
348
+ }
349
+
350
+ /**
351
+ * Rebuild JSON string with pruned nodes replaced by {"pruned":true}
352
+ *
353
+ * @param {string} json - The JSON string to rebuild
354
+ * @param {Set<TreeNode>} prunedNodes - The set of nodes to replace with {"pruned":true}
355
+ * @returns {string} The rebuilt JSON string
356
+ */
357
+ function rebuildJson (json, prunedNodes) {
358
+ // Convert set to array and sort by start position (descending)
359
+ const sortedNodes = [...prunedNodes].sort((a, b) => b.start - a.start)
360
+
361
+ // Replace from end to start to maintain position indices
362
+ for (const node of sortedNodes) {
363
+ const before = json.slice(0, node.start)
364
+ const after = json.slice(node.end + 1)
365
+ json = before + PRUNED_JSON + after
366
+ }
367
+
368
+ return json
369
+ }
370
+
371
+ /**
372
+ * Main pruning function
373
+ *
374
+ * @param {string} json - The JSON string to prune
375
+ * @param {number} originalSize - Size of the original JSON string in bytes
376
+ * @param {number} maxSize - Maximum allowed size in bytes
377
+ * @returns {string|undefined} - Pruned JSON string, or undefined if pruning fails
378
+ */
379
+ function pruneSnapshot (json, originalSize, maxSize) {
380
+ const bytesToRemove = originalSize - maxSize
381
+
382
+ if (bytesToRemove <= 0) return json // No pruning needed
383
+
384
+ let prunedSize = originalSize
385
+ let attempts = 0
386
+ const maxAttempts = 6
387
+
388
+ while (prunedSize > maxSize && attempts < maxAttempts) {
389
+ attempts++
390
+
391
+ const root = parseJsonToTree(json)
392
+ if (!root) break
393
+
394
+ const targetBytesToRemove = prunedSize - maxSize
395
+ const prunedNodes = selectNodesToPrune(root, targetBytesToRemove)
396
+ if (prunedNodes.size === 0) break
397
+
398
+ json = rebuildJson(json, prunedNodes)
399
+ prunedSize = Buffer.byteLength(json)
400
+ }
401
+
402
+ // If pruning didn't help, return undefined
403
+ return prunedSize >= originalSize ? undefined : json
404
+ }
@@ -3,7 +3,7 @@
3
3
  const { join, dirname } = require('path')
4
4
  const { readFileSync } = require('fs')
5
5
  const { readFile } = require('fs/promises')
6
- const { SourceMapConsumer } = require('source-map')
6
+ const { SourceMapConsumer } = require('../../../../../vendor/dist/source-map')
7
7
 
8
8
  const cache = new Map()
9
9
  let cacheTimer = null
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { join, dirname } = require('path')
4
- const { normalize } = require('source-map/lib/util')
4
+ const { normalize } = require('../../../../../vendor/dist/source-map/lib/util')
5
5
  const { loadSourceMapSync } = require('./source-maps')
6
6
  const session = require('./session')
7
7
  const log = require('./log')
@@ -24,7 +24,7 @@ module.exports = {
24
24
  * Find the script to inspect based on a partial or absolute path. Handles both Windows and POSIX paths.
25
25
  *
26
26
  * @param {string} path - Partial or absolute path to match against loaded scripts
27
- * @returns {Object | null} - Object containing `url`, `scriptId`, `sourceMapURL`, and `source` - or null if no match
27
+ * @returns {object | null} - Object containing `url`, `scriptId`, `sourceMapURL`, and `source` - or null if no match
28
28
  */
29
29
  findScriptFromPartialPath (path) {
30
30
  if (!path) return null // This shouldn't happen, but better safe than sorry
@@ -81,9 +81,14 @@ module.exports = {
81
81
  }
82
82
 
83
83
  // If we found a valid match and it's better than our previous best
84
+ // Note: bestMatch.url cannot be null when comparing lengths because:
85
+ // - The first time we enter this block, lastBoundaryPos > maxMatchLength is always true
86
+ // - We set bestMatch.url before we could evaluate the second condition
87
+ // - Subsequent evaluations have bestMatch.url already set
84
88
  if (atBoundary && (
85
89
  lastBoundaryPos > maxMatchLength ||
86
- (lastBoundaryPos === maxMatchLength && url.length < bestMatch.url.length) // Prefer shorter paths
90
+ (lastBoundaryPos === maxMatchLength &&
91
+ url.length < /** @type {string} */ (/** @type {unknown} */ (bestMatch.url)).length) // Prefer shorter paths
87
92
  )) {
88
93
  maxMatchLength = lastBoundaryPos
89
94
  bestMatch.url = sourceUrl || url
@@ -1,10 +1,10 @@
1
1
  'use strict'
2
2
 
3
- const TTLSet = require('ttl-set')
4
- const config = require('./config')
5
- const JSONBuffer = require('./json-buffer')
3
+ const TTLSet = require('../../../../../vendor/dist/ttl-set')
6
4
  const request = require('../../exporters/common/request')
7
5
  const FormData = require('../../exporters/common/form-data')
6
+ const config = require('./config')
7
+ const JSONBuffer = require('./json-buffer')
8
8
  const log = require('./log')
9
9
 
10
10
  module.exports = {