@depup/dd-trace 5.96.0-depup.0 → 6.4.0-depup.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 (646) hide show
  1. package/LICENSE-3rdparty.csv +89 -104
  2. package/README.md +9 -3
  3. package/changes.json +8 -3
  4. package/ci/init.js +25 -5
  5. package/ci/vitest-no-worker-init-setup.mjs +430 -0
  6. package/ext/exporters.js +1 -0
  7. package/ext/tags.js +3 -0
  8. package/index.d.ts +349 -244
  9. package/index.electron.js +3 -0
  10. package/initialize.mjs +9 -8
  11. package/loader-hook.mjs +154 -47
  12. package/package.json +121 -79
  13. package/packages/datadog-core/src/storage.js +47 -48
  14. package/packages/datadog-esbuild/index.js +52 -10
  15. package/packages/datadog-esbuild/src/utils.js +46 -3
  16. package/packages/datadog-instrumentations/src/aerospike.js +3 -3
  17. package/packages/datadog-instrumentations/src/ai.js +131 -76
  18. package/packages/datadog-instrumentations/src/amqplib.js +6 -7
  19. package/packages/datadog-instrumentations/src/anthropic.js +10 -10
  20. package/packages/datadog-instrumentations/src/apollo-server-core.js +3 -3
  21. package/packages/datadog-instrumentations/src/apollo-server.js +10 -18
  22. package/packages/datadog-instrumentations/src/avsc.js +6 -6
  23. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js-context-methods.js +18 -0
  24. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js.js +111 -0
  25. package/packages/datadog-instrumentations/src/aws-sdk.js +172 -72
  26. package/packages/datadog-instrumentations/src/azure-cosmos.js +7 -0
  27. package/packages/datadog-instrumentations/src/azure-durable-functions.js +8 -8
  28. package/packages/datadog-instrumentations/src/azure-functions.js +3 -0
  29. package/packages/datadog-instrumentations/src/bluebird.js +2 -2
  30. package/packages/datadog-instrumentations/src/body-parser.js +5 -2
  31. package/packages/datadog-instrumentations/src/cassandra-driver.js +12 -9
  32. package/packages/datadog-instrumentations/src/child_process.js +22 -32
  33. package/packages/datadog-instrumentations/src/claude-agent-sdk.js +587 -0
  34. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +41 -24
  35. package/packages/datadog-instrumentations/src/connect.js +14 -12
  36. package/packages/datadog-instrumentations/src/cookie-parser.js +5 -4
  37. package/packages/datadog-instrumentations/src/cookie.js +9 -3
  38. package/packages/datadog-instrumentations/src/couchbase.js +73 -238
  39. package/packages/datadog-instrumentations/src/crypto.js +50 -6
  40. package/packages/datadog-instrumentations/src/cucumber-worker-threads.js +19 -0
  41. package/packages/datadog-instrumentations/src/cucumber.js +751 -188
  42. package/packages/datadog-instrumentations/src/cypress-config.js +432 -0
  43. package/packages/datadog-instrumentations/src/cypress.js +88 -4
  44. package/packages/datadog-instrumentations/src/dns.js +61 -61
  45. package/packages/datadog-instrumentations/src/elasticsearch.js +9 -12
  46. package/packages/datadog-instrumentations/src/electron/preload.js +42 -0
  47. package/packages/datadog-instrumentations/src/electron.js +240 -0
  48. package/packages/datadog-instrumentations/src/express-mongo-sanitize.js +11 -9
  49. package/packages/datadog-instrumentations/src/express-session.js +14 -13
  50. package/packages/datadog-instrumentations/src/express.js +56 -34
  51. package/packages/datadog-instrumentations/src/fastify.js +169 -86
  52. package/packages/datadog-instrumentations/src/fetch.js +5 -5
  53. package/packages/datadog-instrumentations/src/fs.js +47 -47
  54. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +5 -7
  55. package/packages/datadog-instrumentations/src/google-genai.js +4 -4
  56. package/packages/datadog-instrumentations/src/graphql.js +26 -362
  57. package/packages/datadog-instrumentations/src/grpc/client.js +48 -32
  58. package/packages/datadog-instrumentations/src/grpc/server.js +20 -2
  59. package/packages/datadog-instrumentations/src/hapi.js +2 -2
  60. package/packages/datadog-instrumentations/src/helpers/bundler-register.js +41 -13
  61. package/packages/datadog-instrumentations/src/helpers/callback-instrumentor.js +74 -0
  62. package/packages/datadog-instrumentations/src/helpers/check-require-cache.js +85 -9
  63. package/packages/datadog-instrumentations/src/helpers/hook.js +34 -6
  64. package/packages/datadog-instrumentations/src/helpers/hooks.js +24 -19
  65. package/packages/datadog-instrumentations/src/helpers/instrument.js +61 -14
  66. package/packages/datadog-instrumentations/src/helpers/kafka.js +58 -0
  67. package/packages/datadog-instrumentations/src/helpers/optional-peer-bundler.js +65 -0
  68. package/packages/datadog-instrumentations/src/helpers/promise-instrumentor.js +42 -0
  69. package/packages/datadog-instrumentations/src/helpers/promise.js +2 -2
  70. package/packages/datadog-instrumentations/src/helpers/register.js +109 -146
  71. package/packages/datadog-instrumentations/src/helpers/require-optional-peer.js +17 -0
  72. package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +13 -5
  73. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +24 -7
  74. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +6 -6
  75. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/aws-durable-execution-sdk-js.js +31 -0
  76. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/azure-cosmos.js +50 -0
  77. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/claude-agent-sdk.js +17 -0
  78. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +201 -0
  79. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +7 -0
  80. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/langgraph.js +4 -2
  81. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/mercurius.js +31 -0
  82. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-sdk.js +35 -0
  83. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +85 -0
  84. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +18 -2
  85. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +49 -224
  86. package/packages/datadog-instrumentations/src/helpers/router-helper.js +8 -8
  87. package/packages/datadog-instrumentations/src/hono.js +71 -9
  88. package/packages/datadog-instrumentations/src/http/client.js +50 -27
  89. package/packages/datadog-instrumentations/src/http/server.js +77 -34
  90. package/packages/datadog-instrumentations/src/http2/client.js +16 -15
  91. package/packages/datadog-instrumentations/src/http2/server.js +156 -25
  92. package/packages/datadog-instrumentations/src/ioredis.js +17 -14
  93. package/packages/datadog-instrumentations/src/iovalkey.js +1 -2
  94. package/packages/datadog-instrumentations/src/jest/bail-reporter.js +42 -0
  95. package/packages/datadog-instrumentations/src/jest/coverage-backfill.js +163 -0
  96. package/packages/datadog-instrumentations/src/jest.js +1795 -404
  97. package/packages/datadog-instrumentations/src/kafkajs.js +284 -170
  98. package/packages/datadog-instrumentations/src/knex.js +17 -17
  99. package/packages/datadog-instrumentations/src/koa.js +15 -14
  100. package/packages/datadog-instrumentations/src/ldapjs.js +5 -5
  101. package/packages/datadog-instrumentations/src/light-my-request.js +2 -2
  102. package/packages/datadog-instrumentations/src/limitd-client.js +5 -5
  103. package/packages/datadog-instrumentations/src/lodash.js +4 -4
  104. package/packages/datadog-instrumentations/src/mariadb.js +18 -16
  105. package/packages/datadog-instrumentations/src/memcached.js +4 -3
  106. package/packages/datadog-instrumentations/src/mercurius.js +11 -0
  107. package/packages/datadog-instrumentations/src/microgateway-core.js +2 -2
  108. package/packages/datadog-instrumentations/src/mocha/common.js +7 -4
  109. package/packages/datadog-instrumentations/src/mocha/main.js +557 -118
  110. package/packages/datadog-instrumentations/src/mocha/utils.js +531 -128
  111. package/packages/datadog-instrumentations/src/mocha/worker.js +27 -9
  112. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +254 -0
  113. package/packages/datadog-instrumentations/src/mongodb-core.js +43 -31
  114. package/packages/datadog-instrumentations/src/mongodb.js +79 -5
  115. package/packages/datadog-instrumentations/src/mongoose.js +43 -34
  116. package/packages/datadog-instrumentations/src/mquery.js +5 -5
  117. package/packages/datadog-instrumentations/src/multer.js +5 -4
  118. package/packages/datadog-instrumentations/src/mysql.js +17 -17
  119. package/packages/datadog-instrumentations/src/mysql2.js +39 -5
  120. package/packages/datadog-instrumentations/src/nats.js +182 -0
  121. package/packages/datadog-instrumentations/src/net.js +21 -19
  122. package/packages/datadog-instrumentations/src/next.js +44 -10
  123. package/packages/datadog-instrumentations/src/nyc.js +43 -6
  124. package/packages/datadog-instrumentations/src/openai.js +124 -38
  125. package/packages/datadog-instrumentations/src/oracledb.js +12 -7
  126. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +27 -6
  127. package/packages/datadog-instrumentations/src/passport-utils.js +5 -5
  128. package/packages/datadog-instrumentations/src/path-to-regexp.js +44 -0
  129. package/packages/datadog-instrumentations/src/pg.js +58 -25
  130. package/packages/datadog-instrumentations/src/pino.js +26 -42
  131. package/packages/datadog-instrumentations/src/playwright-browser-scripts.js +27 -0
  132. package/packages/datadog-instrumentations/src/playwright.js +1090 -351
  133. package/packages/datadog-instrumentations/src/prisma.js +1 -2
  134. package/packages/datadog-instrumentations/src/protobufjs.js +16 -16
  135. package/packages/datadog-instrumentations/src/redis.js +28 -15
  136. package/packages/datadog-instrumentations/src/restify.js +6 -5
  137. package/packages/datadog-instrumentations/src/router.js +243 -87
  138. package/packages/datadog-instrumentations/src/selenium.js +5 -3
  139. package/packages/datadog-instrumentations/src/sequelize.js +1 -1
  140. package/packages/datadog-instrumentations/src/stripe.js +47 -33
  141. package/packages/datadog-instrumentations/src/tedious.js +28 -0
  142. package/packages/datadog-instrumentations/src/url.js +1 -3
  143. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1297 -0
  144. package/packages/datadog-instrumentations/src/vitest-main.js +1592 -0
  145. package/packages/datadog-instrumentations/src/vitest-util.js +251 -0
  146. package/packages/datadog-instrumentations/src/vitest-worker.js +822 -0
  147. package/packages/datadog-instrumentations/src/vitest.js +11 -1258
  148. package/packages/datadog-instrumentations/src/vm.js +1 -3
  149. package/packages/datadog-instrumentations/src/winston.js +4 -4
  150. package/packages/datadog-instrumentations/src/ws.js +7 -7
  151. package/packages/datadog-instrumentations/src/zlib.js +29 -0
  152. package/packages/datadog-plugin-ai/src/index.js +1 -1
  153. package/packages/datadog-plugin-ai/src/tracing.js +66 -3
  154. package/packages/datadog-plugin-ai/src/utils.js +17 -4
  155. package/packages/datadog-plugin-apollo/src/gateway/request.js +1 -21
  156. package/packages/datadog-plugin-avsc/src/schema_iterator.js +3 -3
  157. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/checkpoint.js +31 -0
  158. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/client.js +55 -0
  159. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/context.js +123 -0
  160. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/handler.js +129 -0
  161. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/index.js +19 -0
  162. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/trace-checkpoint.js +224 -0
  163. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +79 -0
  164. package/packages/datadog-plugin-aws-sdk/src/base.js +90 -53
  165. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +1 -1
  166. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +218 -4
  167. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +1 -1
  168. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +2 -1
  169. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +59 -14
  170. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +174 -75
  171. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +34 -23
  172. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +2 -1
  173. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +1 -1
  174. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +26 -26
  175. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +187 -101
  176. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +20 -18
  177. package/packages/datadog-plugin-azure-cosmos/src/index.js +144 -0
  178. package/packages/datadog-plugin-azure-event-hubs/src/producer.js +8 -15
  179. package/packages/datadog-plugin-azure-functions/src/index.js +7 -3
  180. package/packages/datadog-plugin-azure-service-bus/src/producer.js +5 -10
  181. package/packages/datadog-plugin-bullmq/src/consumer.js +5 -4
  182. package/packages/datadog-plugin-bullmq/src/filter.js +35 -0
  183. package/packages/datadog-plugin-bullmq/src/producer.js +121 -33
  184. package/packages/datadog-plugin-bunyan/src/index.js +28 -0
  185. package/packages/datadog-plugin-child_process/src/index.js +13 -2
  186. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +6 -6
  187. package/packages/datadog-plugin-claude-agent-sdk/src/index.js +31 -0
  188. package/packages/datadog-plugin-claude-agent-sdk/src/tracing.js +107 -0
  189. package/packages/datadog-plugin-claude-agent-sdk/src/util.js +15 -0
  190. package/packages/datadog-plugin-couchbase/src/index.js +58 -52
  191. package/packages/datadog-plugin-cucumber/src/index.js +46 -24
  192. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +1018 -97
  193. package/packages/datadog-plugin-cypress/src/index.js +104 -2
  194. package/packages/datadog-plugin-cypress/src/plugin.js +6 -14
  195. package/packages/datadog-plugin-cypress/src/source-map-utils.js +48 -1
  196. package/packages/datadog-plugin-cypress/src/support.js +180 -25
  197. package/packages/datadog-plugin-dd-trace-api/src/index.js +1 -1
  198. package/packages/datadog-plugin-dns/src/lookup.js +8 -6
  199. package/packages/datadog-plugin-elasticsearch/src/index.js +28 -8
  200. package/packages/datadog-plugin-electron/src/index.js +17 -0
  201. package/packages/datadog-plugin-electron/src/ipc.js +143 -0
  202. package/packages/datadog-plugin-electron/src/net.js +82 -0
  203. package/packages/datadog-plugin-express/src/code_origin.js +1 -1
  204. package/packages/datadog-plugin-fastify/src/code_origin.js +1 -1
  205. package/packages/datadog-plugin-fs/src/index.js +2 -1
  206. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -5
  207. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +27 -18
  208. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +5 -8
  209. package/packages/datadog-plugin-graphql/src/execute.js +706 -34
  210. package/packages/datadog-plugin-graphql/src/index.js +43 -9
  211. package/packages/datadog-plugin-graphql/src/parse.js +45 -4
  212. package/packages/datadog-plugin-graphql/src/request.js +135 -0
  213. package/packages/datadog-plugin-graphql/src/tools/signature.js +32 -7
  214. package/packages/datadog-plugin-graphql/src/tools/transforms.js +118 -100
  215. package/packages/datadog-plugin-graphql/src/utils.js +261 -3
  216. package/packages/datadog-plugin-graphql/src/validate.js +53 -7
  217. package/packages/datadog-plugin-grpc/src/client.js +7 -8
  218. package/packages/datadog-plugin-grpc/src/server.js +1 -1
  219. package/packages/datadog-plugin-grpc/src/util.js +57 -22
  220. package/packages/datadog-plugin-http/src/client.js +12 -14
  221. package/packages/datadog-plugin-http/src/index.js +6 -8
  222. package/packages/datadog-plugin-http/src/server.js +63 -20
  223. package/packages/datadog-plugin-http2/src/client.js +6 -3
  224. package/packages/datadog-plugin-http2/src/server.js +48 -8
  225. package/packages/datadog-plugin-jest/src/index.js +136 -68
  226. package/packages/datadog-plugin-jest/src/util.js +37 -16
  227. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +31 -4
  228. package/packages/datadog-plugin-kafkajs/src/consumer.js +2 -9
  229. package/packages/datadog-plugin-kafkajs/src/producer.js +37 -8
  230. package/packages/datadog-plugin-langgraph/src/stream.js +1 -1
  231. package/packages/datadog-plugin-memcached/src/index.js +1 -1
  232. package/packages/datadog-plugin-mocha/src/index.js +66 -17
  233. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/index.js +24 -0
  234. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +173 -0
  235. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +30 -0
  236. package/packages/datadog-plugin-mongodb-core/src/bulk-write.js +43 -0
  237. package/packages/datadog-plugin-mongodb-core/src/index.js +8 -206
  238. package/packages/datadog-plugin-mongodb-core/src/query.js +452 -0
  239. package/packages/datadog-plugin-mysql/src/index.js +9 -4
  240. package/packages/datadog-plugin-nats/src/consumer.js +43 -0
  241. package/packages/datadog-plugin-nats/src/index.js +20 -0
  242. package/packages/datadog-plugin-nats/src/producer.js +62 -0
  243. package/packages/datadog-plugin-nats/src/util.js +33 -0
  244. package/packages/datadog-plugin-next/src/index.js +14 -18
  245. package/packages/datadog-plugin-openai/src/services.js +5 -3
  246. package/packages/datadog-plugin-openai/src/tracing.js +27 -25
  247. package/packages/datadog-plugin-oracledb/src/index.js +13 -2
  248. package/packages/datadog-plugin-pg/src/index.js +13 -3
  249. package/packages/datadog-plugin-pino/src/index.js +42 -0
  250. package/packages/datadog-plugin-playwright/src/index.js +21 -11
  251. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +3 -3
  252. package/packages/datadog-plugin-redis/src/index.js +54 -25
  253. package/packages/datadog-plugin-rhea/src/producer.js +1 -1
  254. package/packages/datadog-plugin-router/src/index.js +46 -44
  255. package/packages/datadog-plugin-selenium/src/index.js +1 -1
  256. package/packages/datadog-plugin-tedious/src/index.js +1 -1
  257. package/packages/datadog-plugin-undici/src/index.js +24 -2
  258. package/packages/datadog-plugin-vitest/src/index.js +160 -90
  259. package/packages/datadog-plugin-winston/src/index.js +30 -0
  260. package/packages/datadog-plugin-ws/src/close.js +3 -1
  261. package/packages/datadog-plugin-ws/src/producer.js +2 -0
  262. package/packages/datadog-plugin-ws/src/receiver.js +2 -1
  263. package/packages/datadog-shimmer/src/shimmer.js +101 -39
  264. package/packages/datadog-webpack/index.js +20 -4
  265. package/packages/datadog-webpack/src/optional-peer-loader.js +17 -0
  266. package/packages/dd-trace/index.electron.js +3 -0
  267. package/packages/dd-trace/index.js +2 -34
  268. package/packages/dd-trace/src/aiguard/channels.js +7 -0
  269. package/packages/dd-trace/src/aiguard/index.js +16 -34
  270. package/packages/dd-trace/src/aiguard/integrations/evaluate.js +46 -0
  271. package/packages/dd-trace/src/aiguard/integrations/index.js +34 -0
  272. package/packages/dd-trace/src/aiguard/integrations/openai.js +80 -0
  273. package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +92 -0
  274. package/packages/dd-trace/src/aiguard/messages/openai.js +382 -0
  275. package/packages/{datadog-instrumentations/src/helpers/ai-messages.js → dd-trace/src/aiguard/messages/vercel-ai.js} +30 -27
  276. package/packages/dd-trace/src/aiguard/sdk.js +151 -54
  277. package/packages/dd-trace/src/aiguard/tags.js +26 -10
  278. package/packages/dd-trace/src/appsec/api_security/index.js +55 -0
  279. package/packages/dd-trace/src/appsec/api_security/sampler.js +147 -0
  280. package/packages/dd-trace/src/appsec/blocked_templates.js +4 -3
  281. package/packages/dd-trace/src/appsec/blocking.js +84 -41
  282. package/packages/dd-trace/src/appsec/channels.js +5 -1
  283. package/packages/dd-trace/src/appsec/downstream_requests.js +116 -62
  284. package/packages/dd-trace/src/appsec/graphql.js +20 -17
  285. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +1 -1
  286. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +81 -81
  287. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +23 -23
  288. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +1 -1
  289. package/packages/dd-trace/src/appsec/iast/index.js +3 -2
  290. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +4 -4
  291. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +2 -2
  292. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +4 -4
  293. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -2
  294. package/packages/dd-trace/src/appsec/iast/telemetry/index.js +2 -1
  295. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +54 -12
  296. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +5 -1
  297. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +32 -5
  298. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +1 -3
  299. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +84 -49
  300. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +1 -1
  301. package/packages/dd-trace/src/appsec/index.js +65 -47
  302. package/packages/dd-trace/src/appsec/lambda.js +135 -0
  303. package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -5
  304. package/packages/dd-trace/src/appsec/rasp/lfi.js +8 -4
  305. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +5 -10
  306. package/packages/dd-trace/src/appsec/rasp/ssrf.js +26 -18
  307. package/packages/dd-trace/src/appsec/recommended.json +2438 -13
  308. package/packages/dd-trace/src/appsec/remote_config.js +1 -0
  309. package/packages/dd-trace/src/appsec/reporter.js +87 -28
  310. package/packages/dd-trace/src/appsec/rule_manager.js +4 -2
  311. package/packages/dd-trace/src/appsec/sdk/index.js +4 -0
  312. package/packages/dd-trace/src/appsec/sdk/set_user.js +1 -1
  313. package/packages/dd-trace/src/appsec/sdk/track_event.js +5 -5
  314. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +7 -11
  315. package/packages/dd-trace/src/appsec/sdk/utils.js +5 -3
  316. package/packages/dd-trace/src/appsec/store.js +50 -0
  317. package/packages/dd-trace/src/appsec/telemetry/api_security.js +34 -0
  318. package/packages/dd-trace/src/appsec/telemetry/index.js +27 -1
  319. package/packages/dd-trace/src/appsec/user_tracking.js +5 -4
  320. package/packages/dd-trace/src/appsec/waf/index.js +19 -9
  321. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +35 -20
  322. package/packages/dd-trace/src/appsec/waf/waf_manager.js +1 -1
  323. package/packages/dd-trace/src/azure_metadata.js +17 -6
  324. package/packages/dd-trace/src/baggage.js +32 -13
  325. package/packages/dd-trace/src/bootstrap.js +39 -0
  326. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +36 -6
  327. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +122 -24
  328. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +22 -7
  329. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +5 -2
  330. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +2 -2
  331. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +2 -2
  332. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +6 -2
  333. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -2
  334. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +148 -25
  335. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +3 -4
  336. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +28 -10
  337. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +22 -0
  338. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +105 -22
  339. package/packages/dd-trace/src/ci-visibility/lage.js +2 -1
  340. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +4 -5
  341. package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +4 -5
  342. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +73 -55
  343. package/packages/dd-trace/src/ci-visibility/requests/request.js +14 -50
  344. package/packages/dd-trace/src/ci-visibility/requests/upload-coverage-report.js +4 -4
  345. package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +156 -0
  346. package/packages/dd-trace/src/ci-visibility/test-api-manual/test-api-manual-plugin.js +9 -3
  347. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +24 -6
  348. package/packages/dd-trace/src/ci-visibility/test-optimization-cache.js +70 -6
  349. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +128 -0
  350. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +291 -0
  351. package/packages/dd-trace/src/config/config-types.d.ts +8 -6
  352. package/packages/dd-trace/src/config/defaults.js +341 -144
  353. package/packages/dd-trace/src/config/generated-config-types.d.ts +679 -131
  354. package/packages/dd-trace/src/config/git_properties.js +2 -2
  355. package/packages/dd-trace/src/config/helper.js +183 -28
  356. package/packages/dd-trace/src/config/index.js +565 -1515
  357. package/packages/dd-trace/src/config/major-overrides.js +100 -0
  358. package/packages/dd-trace/src/config/normalize-service.js +31 -0
  359. package/packages/dd-trace/src/config/parsers.js +384 -0
  360. package/packages/dd-trace/src/config/remote_config.js +59 -2
  361. package/packages/dd-trace/src/config/supported-configurations.json +638 -530
  362. package/packages/dd-trace/src/constants.js +15 -0
  363. package/packages/dd-trace/src/crashtracking/crashtracker.js +25 -7
  364. package/packages/dd-trace/src/crashtracking/index.js +1 -7
  365. package/packages/dd-trace/src/datastreams/checkpointer.js +6 -12
  366. package/packages/dd-trace/src/datastreams/context.js +4 -2
  367. package/packages/dd-trace/src/datastreams/encoding.js +39 -28
  368. package/packages/dd-trace/src/datastreams/index.js +2 -1
  369. package/packages/dd-trace/src/datastreams/manager.js +1 -1
  370. package/packages/dd-trace/src/datastreams/pathway.js +35 -30
  371. package/packages/dd-trace/src/datastreams/processor.js +31 -22
  372. package/packages/dd-trace/src/datastreams/size.js +6 -2
  373. package/packages/dd-trace/src/datastreams/writer.js +15 -6
  374. package/packages/dd-trace/src/debugger/config.js +9 -4
  375. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +49 -35
  376. package/packages/dd-trace/src/debugger/devtools_client/condition.js +5 -8
  377. package/packages/dd-trace/src/debugger/devtools_client/config.js +3 -2
  378. package/packages/dd-trace/src/debugger/devtools_client/index.js +33 -71
  379. package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +83 -0
  380. package/packages/dd-trace/src/debugger/devtools_client/send.js +27 -6
  381. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +2 -2
  382. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +5 -2
  383. package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +1 -0
  384. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +1 -1
  385. package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
  386. package/packages/dd-trace/src/debugger/index.js +14 -10
  387. package/packages/dd-trace/src/debugger/probe_sampler.js +112 -0
  388. package/packages/dd-trace/src/debugger/probe_sampler_constants.js +19 -0
  389. package/packages/dd-trace/src/dogstatsd.js +45 -36
  390. package/packages/dd-trace/src/encode/0.4.js +830 -269
  391. package/packages/dd-trace/src/encode/0.5.js +158 -22
  392. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +141 -65
  393. package/packages/dd-trace/src/encode/agentless-json.js +12 -6
  394. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +52 -15
  395. package/packages/dd-trace/src/encode/span-stats.js +19 -16
  396. package/packages/dd-trace/src/encode/tags-processors.js +30 -25
  397. package/packages/dd-trace/src/exporter.js +3 -1
  398. package/packages/dd-trace/src/exporters/agent/index.js +4 -5
  399. package/packages/dd-trace/src/exporters/agent/writer.js +8 -3
  400. package/packages/dd-trace/src/exporters/agentless/index.js +12 -13
  401. package/packages/dd-trace/src/exporters/agentless/intake.js +43 -0
  402. package/packages/dd-trace/src/exporters/agentless/writer.js +12 -11
  403. package/packages/dd-trace/src/exporters/common/agents.js +3 -1
  404. package/packages/dd-trace/src/exporters/common/buffering-exporter.js +3 -3
  405. package/packages/dd-trace/src/exporters/common/request.js +55 -26
  406. package/packages/dd-trace/src/exporters/common/retry.js +104 -0
  407. package/packages/dd-trace/src/exporters/common/url.js +34 -0
  408. package/packages/dd-trace/src/exporters/common/util.js +2 -2
  409. package/packages/dd-trace/src/exporters/common/writer.js +29 -3
  410. package/packages/dd-trace/src/exporters/electron/index.js +49 -0
  411. package/packages/dd-trace/src/exporters/span-stats/index.js +1 -2
  412. package/packages/dd-trace/src/exporters/span-stats/writer.js +1 -3
  413. package/packages/dd-trace/src/external-logger/src/index.js +2 -1
  414. package/packages/dd-trace/src/feature-registry.js +22 -0
  415. package/packages/dd-trace/src/git_metadata.js +68 -0
  416. package/packages/dd-trace/src/git_metadata_tagger.js +13 -5
  417. package/packages/dd-trace/src/guardrails/index.js +11 -6
  418. package/packages/dd-trace/src/guardrails/telemetry.js +40 -3
  419. package/packages/dd-trace/src/heap_snapshots.js +7 -4
  420. package/packages/dd-trace/src/id.js +46 -27
  421. package/packages/dd-trace/src/index.js +6 -4
  422. package/packages/dd-trace/src/lambda/handler-paths.js +52 -0
  423. package/packages/dd-trace/src/lambda/handler.js +2 -6
  424. package/packages/dd-trace/src/lambda/index.js +62 -14
  425. package/packages/dd-trace/src/lambda/runtime/patch.js +21 -46
  426. package/packages/dd-trace/src/llmobs/constants/tags.js +13 -0
  427. package/packages/dd-trace/src/llmobs/index.js +41 -8
  428. package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +403 -0
  429. package/packages/dd-trace/src/llmobs/plugins/ai/index.js +8 -391
  430. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +178 -18
  431. package/packages/dd-trace/src/llmobs/plugins/ai/vercelTelemetry.js +363 -0
  432. package/packages/dd-trace/src/llmobs/plugins/{anthropic.js → anthropic/index.js} +32 -79
  433. package/packages/dd-trace/src/llmobs/plugins/anthropic/util.js +109 -0
  434. package/packages/dd-trace/src/llmobs/plugins/base.js +4 -4
  435. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +92 -38
  436. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +270 -0
  437. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +10 -0
  438. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +5 -1
  439. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +81 -16
  440. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +3 -2
  441. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +3 -2
  442. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/embedding.js +2 -1
  443. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +1 -50
  444. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/vectorstore.js +2 -1
  445. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +14 -8
  446. package/packages/dd-trace/src/llmobs/plugins/langchain/messages.js +76 -0
  447. package/packages/dd-trace/src/llmobs/plugins/langgraph/index.js +3 -28
  448. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +68 -0
  449. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +57 -0
  450. package/packages/dd-trace/src/llmobs/plugins/openai/index.js +21 -51
  451. package/packages/dd-trace/src/llmobs/sdk.js +66 -41
  452. package/packages/dd-trace/src/llmobs/span_processor.js +91 -12
  453. package/packages/dd-trace/src/llmobs/tagger.js +135 -7
  454. package/packages/dd-trace/src/llmobs/telemetry.js +31 -1
  455. package/packages/dd-trace/src/llmobs/util.js +202 -9
  456. package/packages/dd-trace/src/llmobs/writers/base.js +13 -5
  457. package/packages/dd-trace/src/llmobs/writers/spans.js +1 -1
  458. package/packages/dd-trace/src/llmobs/writers/util.js +4 -2
  459. package/packages/dd-trace/src/log/index.js +28 -69
  460. package/packages/dd-trace/src/log/writer.js +10 -20
  461. package/packages/dd-trace/src/msgpack/chunk.js +430 -11
  462. package/packages/dd-trace/src/msgpack/index.js +101 -2
  463. package/packages/dd-trace/src/noop/proxy.js +13 -4
  464. package/packages/dd-trace/src/noop/span.js +3 -1
  465. package/packages/dd-trace/src/openfeature/encoding.js +70 -0
  466. package/packages/dd-trace/src/openfeature/eval-metrics-hook.js +103 -0
  467. package/packages/dd-trace/src/openfeature/flagging_provider.js +26 -1
  468. package/packages/dd-trace/src/openfeature/noop.js +40 -36
  469. package/packages/dd-trace/src/openfeature/register.js +46 -0
  470. package/packages/dd-trace/src/openfeature/remote_config.js +6 -1
  471. package/packages/dd-trace/src/openfeature/span-enrichment-hook.js +143 -0
  472. package/packages/dd-trace/src/openfeature/span-enrichment.js +149 -0
  473. package/packages/dd-trace/src/openfeature/writers/base.js +3 -11
  474. package/packages/dd-trace/src/openfeature/writers/exposures.js +82 -70
  475. package/packages/dd-trace/src/openfeature/writers/util.js +1 -2
  476. package/packages/dd-trace/src/opentelemetry/active-span-proxy.js +42 -0
  477. package/packages/dd-trace/src/opentelemetry/bridge-span-base.js +107 -0
  478. package/packages/dd-trace/src/opentelemetry/context_manager.js +27 -13
  479. package/packages/dd-trace/src/opentelemetry/logs/index.js +7 -7
  480. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +3 -2
  481. package/packages/dd-trace/src/opentelemetry/metrics/index.js +62 -13
  482. package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +28 -14
  483. package/packages/dd-trace/src/opentelemetry/metrics/meter.js +7 -10
  484. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +3 -2
  485. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +40 -0
  486. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js +169 -0
  487. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +99 -5
  488. package/packages/dd-trace/src/opentelemetry/metrics/time.js +19 -0
  489. package/packages/dd-trace/src/opentelemetry/otlp/common.proto +2 -2
  490. package/packages/dd-trace/src/opentelemetry/otlp/logs.proto +1 -1
  491. package/packages/dd-trace/src/opentelemetry/otlp/logs_service.proto +1 -1
  492. package/packages/dd-trace/src/opentelemetry/otlp/metrics.proto +1 -1
  493. package/packages/dd-trace/src/opentelemetry/otlp/metrics_service.proto +1 -1
  494. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +56 -82
  495. package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +1 -2
  496. package/packages/dd-trace/src/opentelemetry/otlp/protobuf_loader.js +14 -2
  497. package/packages/dd-trace/src/opentelemetry/otlp/trace.proto +358 -0
  498. package/packages/dd-trace/src/opentelemetry/otlp/trace_service.proto +78 -0
  499. package/packages/dd-trace/src/opentelemetry/span-helpers.js +325 -0
  500. package/packages/dd-trace/src/opentelemetry/span.js +59 -109
  501. package/packages/dd-trace/src/opentelemetry/span_context.js +1 -0
  502. package/packages/dd-trace/src/opentelemetry/span_processor.js +7 -5
  503. package/packages/dd-trace/src/opentelemetry/trace/index.js +75 -0
  504. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +75 -0
  505. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +375 -0
  506. package/packages/dd-trace/src/opentelemetry/tracer.js +20 -69
  507. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +33 -17
  508. package/packages/dd-trace/src/opentracing/propagation/log.js +28 -8
  509. package/packages/dd-trace/src/opentracing/propagation/text_map.js +280 -145
  510. package/packages/dd-trace/src/opentracing/propagation/text_map_dsm.js +11 -11
  511. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +98 -32
  512. package/packages/dd-trace/src/opentracing/span.js +127 -73
  513. package/packages/dd-trace/src/opentracing/span_context.js +68 -3
  514. package/packages/dd-trace/src/opentracing/tracer.js +46 -19
  515. package/packages/dd-trace/src/payload-tagging/config/index.js +8 -7
  516. package/packages/dd-trace/src/plugin_manager.js +44 -20
  517. package/packages/dd-trace/src/plugins/apollo.js +3 -1
  518. package/packages/dd-trace/src/plugins/ci_plugin.js +391 -85
  519. package/packages/dd-trace/src/plugins/database.js +61 -18
  520. package/packages/dd-trace/src/plugins/index.js +14 -0
  521. package/packages/dd-trace/src/plugins/log_injection.js +56 -0
  522. package/packages/dd-trace/src/plugins/log_plugin.js +4 -44
  523. package/packages/dd-trace/src/plugins/outbound.js +1 -1
  524. package/packages/dd-trace/src/plugins/plugin.js +22 -28
  525. package/packages/dd-trace/src/plugins/storage.js +2 -2
  526. package/packages/dd-trace/src/plugins/tracing.js +70 -13
  527. package/packages/dd-trace/src/plugins/util/ci.js +127 -40
  528. package/packages/dd-trace/src/plugins/util/git-cache.js +23 -23
  529. package/packages/dd-trace/src/plugins/util/git.js +3 -1
  530. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +276 -0
  531. package/packages/dd-trace/src/plugins/util/llm.js +6 -1
  532. package/packages/dd-trace/src/plugins/util/stacktrace.js +2 -2
  533. package/packages/dd-trace/src/plugins/util/test.js +894 -65
  534. package/packages/dd-trace/src/plugins/util/url.js +71 -5
  535. package/packages/dd-trace/src/plugins/util/user-provided-git.js +18 -16
  536. package/packages/dd-trace/src/plugins/util/web.js +116 -180
  537. package/packages/dd-trace/src/priority_sampler.js +12 -21
  538. package/packages/dd-trace/src/process-tags/index.js +3 -0
  539. package/packages/dd-trace/src/profiler.js +27 -2
  540. package/packages/dd-trace/src/profiling/config.js +145 -393
  541. package/packages/dd-trace/src/profiling/constants.js +4 -7
  542. package/packages/dd-trace/src/profiling/exporter_cli.js +10 -13
  543. package/packages/dd-trace/src/profiling/exporters/agent.js +61 -28
  544. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +50 -15
  545. package/packages/dd-trace/src/profiling/exporters/file.js +16 -5
  546. package/packages/dd-trace/src/profiling/oom.js +71 -0
  547. package/packages/dd-trace/src/profiling/profiler.js +123 -132
  548. package/packages/dd-trace/src/profiling/profilers/event_plugins/crypto.js +32 -0
  549. package/packages/dd-trace/src/profiling/profilers/event_plugins/zlib.js +19 -0
  550. package/packages/dd-trace/src/profiling/profilers/events.js +57 -14
  551. package/packages/dd-trace/src/profiling/profilers/space.js +27 -16
  552. package/packages/dd-trace/src/profiling/profilers/wall.js +136 -39
  553. package/packages/dd-trace/src/profiling/ssi-heuristics.js +7 -4
  554. package/packages/dd-trace/src/propagation-hash/index.js +3 -2
  555. package/packages/dd-trace/src/proxy.js +82 -39
  556. package/packages/dd-trace/src/rate_limiter.js +1 -1
  557. package/packages/dd-trace/src/remote_config/index.js +9 -5
  558. package/packages/dd-trace/src/remote_config/scheduler.js +1 -1
  559. package/packages/dd-trace/src/require-package-json.js +8 -4
  560. package/packages/dd-trace/src/ritm.js +63 -28
  561. package/packages/dd-trace/src/runtime_metrics/client.js +30 -0
  562. package/packages/dd-trace/src/runtime_metrics/index.js +17 -4
  563. package/packages/dd-trace/src/runtime_metrics/otlp_runtime_metrics.js +284 -0
  564. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +45 -41
  565. package/packages/dd-trace/src/sampler.js +1 -1
  566. package/packages/dd-trace/src/sampling_rule.js +7 -7
  567. package/packages/dd-trace/src/scope.js +10 -15
  568. package/packages/dd-trace/src/serverless.js +6 -7
  569. package/packages/dd-trace/src/service-naming/extra-services.js +14 -0
  570. package/packages/dd-trace/src/service-naming/index.js +1 -1
  571. package/packages/dd-trace/src/service-naming/schemas/definition.js +4 -1
  572. package/packages/dd-trace/src/service-naming/schemas/util.js +48 -3
  573. package/packages/dd-trace/src/service-naming/schemas/v0/graphql.js +6 -0
  574. package/packages/dd-trace/src/service-naming/schemas/v0/messaging.js +61 -2
  575. package/packages/dd-trace/src/service-naming/schemas/v0/serverless.js +12 -0
  576. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +60 -0
  577. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +25 -1
  578. package/packages/dd-trace/src/service-naming/schemas/v0/websocket.js +5 -0
  579. package/packages/dd-trace/src/service-naming/schemas/v1/graphql.js +8 -0
  580. package/packages/dd-trace/src/service-naming/schemas/v1/messaging.js +32 -0
  581. package/packages/dd-trace/src/service-naming/schemas/v1/serverless.js +12 -0
  582. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +17 -0
  583. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +23 -3
  584. package/packages/dd-trace/src/service-naming/schemas/v1/websocket.js +6 -0
  585. package/packages/dd-trace/src/service-naming/source-resolver.js +50 -0
  586. package/packages/dd-trace/src/span_format.js +269 -81
  587. package/packages/dd-trace/src/span_processor.js +13 -13
  588. package/packages/dd-trace/src/span_stats.js +101 -79
  589. package/packages/dd-trace/src/spanleak.js +1 -2
  590. package/packages/dd-trace/src/standalone/index.js +6 -25
  591. package/packages/dd-trace/src/startup-log.js +3 -3
  592. package/packages/dd-trace/src/tagger.js +2 -4
  593. package/packages/dd-trace/src/telemetry/dependencies.js +2 -2
  594. package/packages/dd-trace/src/telemetry/endpoints.js +7 -5
  595. package/packages/dd-trace/src/telemetry/index.js +2 -3
  596. package/packages/dd-trace/src/telemetry/logs/index.js +1 -1
  597. package/packages/dd-trace/src/telemetry/send-data.js +25 -39
  598. package/packages/dd-trace/src/telemetry/session-propagation.js +20 -45
  599. package/packages/dd-trace/src/telemetry/telemetry.js +42 -183
  600. package/packages/dd-trace/src/tracer.js +23 -9
  601. package/packages/dd-trace/src/tracer_metadata.js +1 -1
  602. package/packages/dd-trace/src/util.js +31 -9
  603. package/register.js +58 -1
  604. package/vendor/dist/@apm-js-collab/code-transformer/index.js +94 -42
  605. package/vendor/dist/@datadog/sketches-js/LICENSE +10 -36
  606. package/vendor/dist/@datadog/sketches-js/index.js +1 -1
  607. package/vendor/dist/pprof-format/index.js +1 -1
  608. package/vendor/dist/protobufjs/index.js +1 -1
  609. package/vendor/dist/protobufjs/minimal/index.js +1 -1
  610. package/vendor/dist/shell-quote/index.js +1 -1
  611. package/packages/datadog-plugin-graphql/src/resolve.js +0 -178
  612. package/packages/dd-trace/src/agent/url.js +0 -28
  613. package/packages/dd-trace/src/appsec/api_security_sampler.js +0 -117
  614. package/packages/dd-trace/src/lambda/runtime/ritm.js +0 -133
  615. package/packages/dd-trace/src/log/utils.js +0 -16
  616. package/packages/dd-trace/src/msgpack/encoder.js +0 -308
  617. package/packages/dd-trace/src/plugins/structured_log_plugin.js +0 -9
  618. package/scripts/preinstall.js +0 -34
  619. package/vendor/dist/ignore/LICENSE +0 -21
  620. package/vendor/dist/ignore/index.js +0 -1
  621. package/vendor/dist/opentracing/LICENSE +0 -201
  622. package/vendor/dist/opentracing/binary_carrier.d.ts +0 -11
  623. package/vendor/dist/opentracing/constants.d.ts +0 -61
  624. package/vendor/dist/opentracing/examples/demo/demo.d.ts +0 -2
  625. package/vendor/dist/opentracing/ext/tags.d.ts +0 -90
  626. package/vendor/dist/opentracing/functions.d.ts +0 -20
  627. package/vendor/dist/opentracing/global_tracer.d.ts +0 -14
  628. package/vendor/dist/opentracing/index.d.ts +0 -12
  629. package/vendor/dist/opentracing/index.js +0 -1
  630. package/vendor/dist/opentracing/mock_tracer/index.d.ts +0 -5
  631. package/vendor/dist/opentracing/mock_tracer/mock_context.d.ts +0 -13
  632. package/vendor/dist/opentracing/mock_tracer/mock_report.d.ts +0 -16
  633. package/vendor/dist/opentracing/mock_tracer/mock_span.d.ts +0 -50
  634. package/vendor/dist/opentracing/mock_tracer/mock_tracer.d.ts +0 -26
  635. package/vendor/dist/opentracing/noop.d.ts +0 -8
  636. package/vendor/dist/opentracing/reference.d.ts +0 -33
  637. package/vendor/dist/opentracing/span.d.ts +0 -147
  638. package/vendor/dist/opentracing/span_context.d.ts +0 -26
  639. package/vendor/dist/opentracing/test/api_compatibility.d.ts +0 -16
  640. package/vendor/dist/opentracing/test/mocktracer_implemenation.d.ts +0 -3
  641. package/vendor/dist/opentracing/test/noop_implementation.d.ts +0 -4
  642. package/vendor/dist/opentracing/test/opentracing_api.d.ts +0 -3
  643. package/vendor/dist/opentracing/test/unittest.d.ts +0 -2
  644. package/vendor/dist/opentracing/tracer.d.ts +0 -127
  645. package/vendor/dist/path-to-regexp/LICENSE +0 -21
  646. package/vendor/dist/path-to-regexp/index.js +0 -1
@@ -1,15 +1,15 @@
1
1
  'use strict'
2
2
 
3
3
  const METHODS = [...require('http').METHODS.map(v => v.toLowerCase()), 'all']
4
- const pathToRegExp = require('../../../vendor/dist/path-to-regexp')
5
4
  const shimmer = require('../../datadog-shimmer')
6
- const { addHook, channel } = require('./helpers/instrument')
5
+ const { addHook, channel, createErrorPublisher } = require('./helpers/instrument')
6
+ const { getCompileToRegexp } = require('./path-to-regexp')
7
7
 
8
8
  const {
9
9
  getRouterMountPaths,
10
10
  joinPath,
11
- getLayerMatchers,
12
- setLayerMatchers,
11
+ setLayerMeta,
12
+ getLayerMeta,
13
13
  isAppMounted,
14
14
  setRouterMountPath,
15
15
  extractMountPaths,
@@ -19,59 +19,169 @@ const {
19
19
  } = require('./helpers/router-helper')
20
20
 
21
21
  function isFastStar (layer, matchers) {
22
- return layer.regexp?.fast_star ?? matchers.some(matcher => matcher.path === '*')
22
+ return layer.regexp?.fast_star ?? matchers.hasStarPath
23
23
  }
24
24
 
25
25
  function isFastSlash (layer, matchers) {
26
- return layer.regexp?.fast_slash ?? matchers.some(matcher => matcher.path === '/')
26
+ return layer.regexp?.fast_slash ?? matchers.hasSlashPath
27
27
  }
28
28
 
29
- // TODO: Move this function to a shared file between Express and Router
30
- function createWrapRouterMethod (name) {
29
+ /**
30
+ * Cache the per-layer dispatch metadata in a side table instead of replacing
31
+ * `layer.handle`. Phase-sorting hosts (loopback's `_findLayerByHandler`) map a
32
+ * layer back to the user handler by scanning the handle, so the handle has to
33
+ * stay the user's function.
34
+ *
35
+ * @param {{ handle: Function, name?: string, path?: string,
36
+ * regexp?: { fast_star?: boolean, fast_slash?: boolean } }} layer
37
+ * @param {Array<{ path?: string, regex?: RegExp }> & { hasStarPath?: boolean, hasSlashPath?: boolean }} matchers
38
+ */
39
+ function annotateLayer (layer, matchers) {
40
+ const handle = layer.handle
41
+ const name = handle._name || layer.name || handle.name
42
+
43
+ let captureRoute
44
+ let needMultiMatch = false
45
+ if (matchers.length !== 0 && !isFastStar(layer, matchers) && !isFastSlash(layer, matchers)) {
46
+ if (matchers.length === 1) {
47
+ captureRoute = matchers[0].path
48
+ } else {
49
+ needMultiMatch = true
50
+ }
51
+ }
52
+
53
+ setLayerMeta(layer, { name, captureRoute, needMultiMatch, matchers })
54
+ }
55
+
56
+ /**
57
+ * Resolve the route for a dispatched layer. Single-pattern layers carry a
58
+ * constant route; only multi-pattern stacks need the per-request `layer.path`
59
+ * match the host already computed.
60
+ *
61
+ * @param {{ captureRoute?: string, needMultiMatch: boolean,
62
+ * matchers: Array<{ path?: string, regex?: RegExp }> }} meta
63
+ * @param {{ path?: string }} layer
64
+ * @returns {string | undefined}
65
+ */
66
+ function resolveLayerRoute (meta, layer) {
67
+ if (!meta.needMultiMatch) return meta.captureRoute
68
+
69
+ for (const matcher of meta.matchers) {
70
+ if (matcher.regex?.test(layer.path)) return matcher.path
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Build the request/error dispatch wrappers for one host (`express` / `router`).
76
+ * They wrap the layer's prototype dispatch and read the side-table metadata, so
77
+ * `layer.handle` is never replaced. The arity guard mirrors the host's own
78
+ * (`handle_request` skips 4-arg handlers, `handle_error` skips the rest), so a
79
+ * span is published only for the layer the host actually runs.
80
+ *
81
+ * @param {string} name Channel namespace (`apm:<name>:middleware:*`).
82
+ */
83
+ function createLayerDispatchWrappers (name) {
31
84
  const enterChannel = channel(`apm:${name}:middleware:enter`)
32
85
  const exitChannel = channel(`apm:${name}:middleware:exit`)
33
86
  const finishChannel = channel(`apm:${name}:middleware:finish`)
34
87
  const errorChannel = channel(`apm:${name}:middleware:error`)
35
88
  const nextChannel = channel(`apm:${name}:middleware:next`)
36
- const routeAddedChannel = channel(`apm:${name}:route:added`)
89
+ // Bound per name so express and a bare router keep independent guards.
90
+ const publishError = createErrorPublisher(errorChannel)
91
+
92
+ function wrapNext (req, originalNext) {
93
+ // Per layer dispatch, N per request. Named `next`/arity-1 mirrors the
94
+ // router continuation so wrapCallback skips its name/length rewrite.
95
+ let published = false
96
+ return shimmer.wrapCallback(originalNext, original => function next (error) {
97
+ // A handler that calls `next()` and then rejects (`next(); await bg()`)
98
+ // makes the host call this continuation twice. Publish once so the second
99
+ // pass cannot tag the already-finished span's parent with a late error.
100
+ if (!published) {
101
+ published = true
102
+
103
+ if (error && error !== 'route' && error !== 'router') {
104
+ publishError({ req, error })
105
+ }
106
+
107
+ nextChannel.publish({ req })
108
+ finishChannel.publish({ req })
109
+ }
37
110
 
38
- const regexpCache = Object.create(null)
111
+ original.apply(this, arguments)
112
+ })
113
+ }
39
114
 
40
- function wrapLayerHandle (layer, original) {
41
- original._name = original._name || layer.name
115
+ // Every host dispatch turns a synchronous throw into `next(error)`, and the
116
+ // hosts that await the handler (router >=2, express 5, express 4 +
117
+ // express-async-errors) do the same for a rejected promise. Passing
118
+ // `wrappedNext` through captures both without a tracer-side try/catch; only
119
+ // `exit` needs the `finally`. express 4's native dispatch converts only the
120
+ // synchronous throw — exactly what the pre-refactor handle wrap caught.
121
+ function wrapLayerRequest (originalRequest) {
122
+ return function (req, res, next) {
123
+ if (!enterChannel.hasSubscribers) return originalRequest.call(this, req, res, next)
42
124
 
43
- return shimmer.wrapFunction(original, original => function () {
44
- if (!enterChannel.hasSubscribers) return original.apply(this, arguments)
125
+ const meta = getLayerMeta(this)
126
+ if (meta === undefined || this.handle.length > 3) return originalRequest.call(this, req, res, next)
45
127
 
46
- const matchers = getLayerMatchers(layer)
47
- const lastIndex = arguments.length - 1
48
- const name = original._name || original.name
49
- const req = arguments[arguments.length > 3 ? 1 : 0]
50
- const next = arguments[lastIndex]
128
+ const wrappedNext = typeof next === 'function' ? wrapNext(req, next) : next
129
+ enterChannel.publish({ name: meta.name, req, route: resolveLayerRoute(meta, this), layer: this })
51
130
 
52
- if (typeof next === 'function') {
53
- arguments[lastIndex] = wrapNext(req, next)
131
+ try {
132
+ return originalRequest.call(this, req, res, wrappedNext)
133
+ } finally {
134
+ exitChannel.publish({ req })
54
135
  }
136
+ }
137
+ }
55
138
 
56
- let route
139
+ function wrapLayerError (originalError) {
140
+ return function (error, req, res, next) {
141
+ if (!enterChannel.hasSubscribers) return originalError.call(this, error, req, res, next)
57
142
 
58
- if (matchers) {
59
- // Try to guess which path actually matched
60
- for (const matcher of matchers) {
61
- if (matcher.test(layer)) {
62
- route = matcher.path
143
+ const meta = getLayerMeta(this)
144
+ if (meta === undefined || this.handle.length !== 4) return originalError.call(this, error, req, res, next)
63
145
 
64
- break
65
- }
66
- }
146
+ const wrappedNext = typeof next === 'function' ? wrapNext(req, next) : next
147
+ enterChannel.publish({ name: meta.name, req, route: resolveLayerRoute(meta, this), layer: this })
148
+
149
+ try {
150
+ return originalError.call(this, error, req, res, wrappedNext)
151
+ } finally {
152
+ exitChannel.publish({ req })
67
153
  }
154
+ }
155
+ }
68
156
 
69
- enterChannel.publish({ name, req, route, layer })
157
+ // express <4.6.0 has no `Layer` prototype dispatch: the router invokes
158
+ // `layer.handle` directly and routes errors by its arity. There the handle is
159
+ // replaced in place, with the arity preserved so the host still routes
160
+ // correctly. Newer express, express 5, and the router package keep `handle`
161
+ // pristine and are traced through the prototype wraps above.
162
+ function wrapLegacyHandle (layer, original) {
163
+ // `annotateLayer` always runs first in `wrapStack`, so the captured meta is
164
+ // never undefined here (unlike the prototype wraps, where `this` can be any
165
+ // layer the host dispatches).
166
+ const meta = getLayerMeta(layer)
167
+ const wrapped = shimmer.wrapFunction(original, inner => function (...args) {
168
+ if (!enterChannel.hasSubscribers) return inner.apply(this, args)
169
+
170
+ const isErrorHandler = original.length === 4
171
+ const req = args[isErrorHandler ? 1 : 0]
172
+ const nextIndex = isErrorHandler ? 3 : 2
173
+ if (typeof args[nextIndex] === 'function') args[nextIndex] = wrapNext(req, args[nextIndex])
174
+
175
+ enterChannel.publish({ name: meta.name, req, route: resolveLayerRoute(meta, layer), layer })
70
176
 
71
177
  try {
72
- return original.apply(this, arguments)
178
+ return inner.apply(this, args)
73
179
  } catch (error) {
74
- errorChannel.publish({ req, error })
180
+ // Unlike the prototype hosts, this router catches a synchronous throw
181
+ // outside the layer and calls its own `next(error)`, never `wrappedNext`.
182
+ // Mirror `wrapNext` here so the throwing layer still tags its error and
183
+ // finishes, rather than lingering on the stack until request finish.
184
+ publishError({ req, error })
75
185
  nextChannel.publish({ req })
76
186
  finishChannel.publish({ req })
77
187
 
@@ -80,17 +190,45 @@ function createWrapRouterMethod (name) {
80
190
  exitChannel.publish({ req })
81
191
  }
82
192
  })
193
+ Object.defineProperty(wrapped, 'length', { value: original.length, configurable: true })
194
+ return wrapped
83
195
  }
84
196
 
197
+ return { wrapLayerRequest, wrapLayerError, wrapLegacyHandle }
198
+ }
199
+
200
+ /**
201
+ * @param {{ handle_request?: unknown, handleRequest?: unknown }} layer
202
+ */
203
+ function hasLayerDispatch (layer) {
204
+ return typeof layer.handle_request === 'function' || typeof layer.handleRequest === 'function'
205
+ }
206
+
207
+ // TODO: Move this function to a shared file between Express and Router
208
+ /**
209
+ * @param {string} name Channel namespace (`apm:<name>:middleware:*`).
210
+ * @param {((pattern: string | RegExp) => RegExp | undefined) | undefined} compile
211
+ * Host-resolved path-to-regexp compile adapter, or undefined when the host
212
+ * instance ships no path-to-regexp. Captured here so each express/router
213
+ * instance keeps the dialect it actually loaded.
214
+ * @param {((layer: object, original: Function) => Function) | undefined} [wrapLegacyHandle]
215
+ * Fallback that replaces `layer.handle` for hosts without a `Layer` prototype
216
+ * dispatch (express <4.6.0). Omitted for hosts that always ship one.
217
+ */
218
+ function createWrapRouterMethod (name, compile, wrapLegacyHandle) {
219
+ const routeAddedChannel = channel(`apm:${name}:route:added`)
220
+
85
221
  function wrapStack (layers, matchers) {
86
222
  for (const layer of layers) {
87
- if (layer.__handle) { // express-async-errors
88
- layer.__handle = wrapLayerHandle(layer, layer.__handle)
89
- } else {
90
- layer.handle = wrapLayerHandle(layer, layer.handle)
91
- }
223
+ annotateLayer(layer, matchers)
92
224
 
93
- setLayerMatchers(layer, matchers)
225
+ if (wrapLegacyHandle !== undefined && !hasLayerDispatch(layer)) {
226
+ if (layer.__handle) { // express-async-errors
227
+ layer.__handle = wrapLegacyHandle(layer, layer.__handle)
228
+ } else {
229
+ layer.handle = wrapLegacyHandle(layer, layer.handle)
230
+ }
231
+ }
94
232
 
95
233
  if (layer.route) {
96
234
  for (const method of METHODS) {
@@ -104,19 +242,6 @@ function createWrapRouterMethod (name) {
104
242
  }
105
243
  }
106
244
 
107
- function wrapNext (req, next) {
108
- return shimmer.wrapFunction(next, next => function (error) {
109
- if (error && error !== 'route' && error !== 'router') {
110
- errorChannel.publish({ req, error })
111
- }
112
-
113
- nextChannel.publish({ req })
114
- finishChannel.publish({ req })
115
-
116
- next.apply(this, arguments)
117
- })
118
- }
119
-
120
245
  function extractMatchers (fn) {
121
246
  const arg = Array.isArray(fn) ? fn.flat(Infinity) : [fn]
122
247
 
@@ -124,25 +249,35 @@ function createWrapRouterMethod (name) {
124
249
  return []
125
250
  }
126
251
 
127
- return arg.map(pattern => ({
128
- path: pattern instanceof RegExp ? `(${pattern})` : pattern,
129
- test: layer => {
130
- const matchers = getLayerMatchers(layer)
131
- return !isFastStar(layer, matchers) &&
132
- !isFastSlash(layer, matchers) &&
133
- cachedPathToRegExp(pattern).test(layer.path)
134
- },
135
- }))
136
- }
137
-
138
- function cachedPathToRegExp (pattern) {
139
- const maybeCached = regexpCache[pattern]
140
- if (maybeCached) {
141
- return maybeCached
252
+ if (arg.length === 1) {
253
+ const pattern = arg[0]
254
+ const path = pattern instanceof RegExp ? `(${pattern})` : pattern
255
+ const matchers = [{ path }]
256
+ matchers.hasStarPath = path === '*'
257
+ matchers.hasSlashPath = path === '/'
258
+ return matchers
142
259
  }
143
- const regexp = pathToRegExp(pattern)
144
- regexpCache[pattern] = regexp
145
- return regexp
260
+
261
+ // hasStarPath/hasSlashPath cache the lookups isFastStar/isFastSlash
262
+ // would otherwise re-run on every request.
263
+ let hasStarPath = false
264
+ let hasSlashPath = false
265
+ const matchers = arg.map(pattern => {
266
+ const isRegExp = pattern instanceof RegExp
267
+ const path = isRegExp ? `(${pattern})` : pattern
268
+ if (path === '*') {
269
+ hasStarPath = true
270
+ } else if (path === '/') {
271
+ hasSlashPath = true
272
+ }
273
+ return {
274
+ path,
275
+ regex: isRegExp ? pattern : compile?.(pattern),
276
+ }
277
+ })
278
+ matchers.hasStarPath = hasStarPath
279
+ matchers.hasSlashPath = hasSlashPath
280
+ return matchers
146
281
  }
147
282
 
148
283
  function wrapMethod (original) {
@@ -218,33 +353,44 @@ function createWrapRouterMethod (name) {
218
353
  return wrapMethod
219
354
  }
220
355
 
221
- const wrapRouterMethod = createWrapRouterMethod('router')
222
-
223
356
  addHook({ name: 'router', versions: ['>=1 <2'] }, Router => {
357
+ const wrapRouterMethod = createWrapRouterMethod('router', getCompileToRegexp())
358
+
224
359
  shimmer.wrap(Router.prototype, 'use', wrapRouterMethod)
225
360
  shimmer.wrap(Router.prototype, 'route', wrapRouterMethod)
226
361
 
227
362
  return Router
228
363
  })
229
364
 
365
+ addHook({ name: 'router', file: 'lib/layer.js', versions: ['>=1 <2'] }, Layer => {
366
+ const { wrapLayerRequest, wrapLayerError } = createLayerDispatchWrappers('router')
367
+
368
+ shimmer.wrap(Layer.prototype, 'handle_request', wrapLayerRequest)
369
+ shimmer.wrap(Layer.prototype, 'handle_error', wrapLayerError)
370
+
371
+ return Layer
372
+ })
373
+
230
374
  const queryParserReadCh = channel('datadog:query:read:finish')
231
375
 
232
376
  addHook({ name: 'router', versions: ['>=2'] }, Router => {
377
+ const wrapRouterMethod = createWrapRouterMethod('router', getCompileToRegexp())
378
+
233
379
  const WrappedRouter = shimmer.wrapFunction(Router, function (originalRouter) {
234
- return function wrappedMethod () {
235
- const router = originalRouter.apply(this, arguments)
380
+ return function wrappedMethod (...args) {
381
+ const router = originalRouter.apply(this, args)
236
382
 
237
383
  shimmer.wrap(router, 'handle', function wrapHandle (originalHandle) {
238
384
  return function wrappedHandle (req, res, next) {
239
- const abortController = new AbortController()
240
-
241
385
  if (queryParserReadCh.hasSubscribers && req) {
386
+ const abortController = new AbortController()
387
+
242
388
  queryParserReadCh.publish({ req, res, query: req.query, abortController })
243
389
 
244
390
  if (abortController.signal.aborted) return
245
391
  }
246
392
 
247
- return originalHandle.apply(this, arguments)
393
+ return originalHandle.call(this, req, res, next)
248
394
  }
249
395
  })
250
396
 
@@ -262,7 +408,8 @@ const routerParamStartCh = channel('datadog:router:param:start')
262
408
  const visitedParams = new WeakSet()
263
409
 
264
410
  function wrapHandleRequest (original) {
265
- return function wrappedHandleRequest (req, res, next) {
411
+ return function wrappedHandleRequest (...args) {
412
+ const req = args[0]
266
413
  if (routerParamStartCh.hasSubscribers && !visitedParams.has(req.params) && Object.keys(req.params).length) {
267
414
  visitedParams.add(req.params)
268
415
 
@@ -270,7 +417,7 @@ function wrapHandleRequest (original) {
270
417
 
271
418
  routerParamStartCh.publish({
272
419
  req,
273
- res,
420
+ res: args[1],
274
421
  params: req?.params,
275
422
  abortController,
276
423
  })
@@ -278,21 +425,30 @@ function wrapHandleRequest (original) {
278
425
  if (abortController.signal.aborted) return
279
426
  }
280
427
 
281
- return original.apply(this, arguments)
428
+ return Reflect.apply(original, this, args)
282
429
  }
283
430
  }
284
431
 
285
432
  addHook({
286
433
  name: 'router', file: 'lib/layer.js', versions: ['>=2'],
287
434
  }, Layer => {
435
+ const { wrapLayerRequest, wrapLayerError } = createLayerDispatchWrappers('router')
436
+
437
+ // `handleRequest` carries two concerns: the middleware dispatch span and the
438
+ // param-start publish (`wrapHandleRequest`). Wrap the dispatch first so it
439
+ // sits inner and param-start still fires before `middleware:enter`, matching
440
+ // the order from when the handle itself was wrapped.
441
+ shimmer.wrap(Layer.prototype, 'handleRequest', wrapLayerRequest)
442
+ shimmer.wrap(Layer.prototype, 'handleError', wrapLayerError)
288
443
  shimmer.wrap(Layer.prototype, 'handleRequest', wrapHandleRequest)
289
444
  return Layer
290
445
  })
291
446
 
292
447
  function wrapParam (original) {
293
- return function wrappedProcessParams () {
294
- arguments[1] = shimmer.wrapFunction(arguments[1], (originalFn) => {
295
- return function wrappedFn (req, res) {
448
+ return function wrappedProcessParams (...args) {
449
+ args[1] = shimmer.wrapFunction(args[1], (originalFn) => {
450
+ return function wrappedFn (...fnArgs) {
451
+ const req = fnArgs[0]
296
452
  if (routerParamStartCh.hasSubscribers && Object.keys(req.params).length && !visitedParams.has(req.params)) {
297
453
  visitedParams.add(req.params)
298
454
 
@@ -300,7 +456,7 @@ function wrapParam (original) {
300
456
 
301
457
  routerParamStartCh.publish({
302
458
  req,
303
- res,
459
+ res: fnArgs[1],
304
460
  params: req?.params,
305
461
  abortController,
306
462
  })
@@ -308,11 +464,11 @@ function wrapParam (original) {
308
464
  if (abortController.signal.aborted) return
309
465
  }
310
466
 
311
- return originalFn.apply(this, arguments)
467
+ return Reflect.apply(originalFn, this, fnArgs)
312
468
  }
313
469
  })
314
470
 
315
- return original.apply(this, arguments)
471
+ return original.apply(this, args)
316
472
  }
317
473
  }
318
474
 
@@ -323,4 +479,4 @@ addHook({
323
479
  return router
324
480
  })
325
481
 
326
- module.exports = { createWrapRouterMethod }
482
+ module.exports = { createWrapRouterMethod, createLayerDispatchWrappers }
@@ -1,5 +1,8 @@
1
1
  'use strict'
2
2
 
3
+ // Capture real timers at module load time, before any test can install fake timers.
4
+ const realSetTimeout = setTimeout
5
+
3
6
  const shimmer = require('../../datadog-shimmer')
4
7
  const { getValueFromEnvSources } = require('../../dd-trace/src/config/helper')
5
8
  const { addHook, channel } = require('./helpers/instrument')
@@ -16,8 +19,7 @@ if (window.DD_RUM && window.DD_RUM.stopSession) {
16
19
  `
17
20
  const IS_RUM_ACTIVE_SCRIPT = 'return !!window.DD_RUM'
18
21
 
19
- const DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS =
20
- Number(getValueFromEnvSources('DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS')) || 500
22
+ const DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS = getValueFromEnvSources('DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS')
21
23
  const DD_CIVISIBILITY_TEST_EXECUTION_ID_COOKIE_NAME = 'datadog-ci-visibility-test-execution-id'
22
24
 
23
25
  // TODO: can we increase the supported version range?
@@ -66,7 +68,7 @@ addHook({
66
68
  if (isRumActive) {
67
69
  // We'll have time for RUM to flush the events (there's no callback to know when it's done)
68
70
  await new Promise(resolve => {
69
- setTimeout(() => {
71
+ realSetTimeout(() => {
70
72
  resolve()
71
73
  }, DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS)
72
74
  })
@@ -6,7 +6,7 @@ const {
6
6
  addHook,
7
7
  } = require('./helpers/instrument')
8
8
 
9
- addHook({ name: 'sequelize', versions: ['>=4'], file: ['lib/sequelize.js'] }, Sequelize => {
9
+ addHook({ name: 'sequelize', versions: ['>=4'], file: 'lib/sequelize.js' }, Sequelize => {
10
10
  const startCh = channel('datadog:sequelize:query:start')
11
11
  const finishCh = channel('datadog:sequelize:query:finish')
12
12
 
@@ -8,8 +8,8 @@ const paymentIntentCreateFinishCh = channel('datadog:stripe:paymentIntent:create
8
8
  const constructEventFinishCh = channel('datadog:stripe:constructEvent:finish')
9
9
 
10
10
  function wrapSessionCreate (create) {
11
- return function wrappedSessionCreate () {
12
- const promise = create.apply(this, arguments)
11
+ return function wrappedSessionCreate (...args) {
12
+ const promise = create.apply(this, args)
13
13
 
14
14
  if (!checkoutSessionCreateFinishCh.hasSubscribers) return promise
15
15
 
@@ -21,8 +21,8 @@ function wrapSessionCreate (create) {
21
21
  }
22
22
 
23
23
  function wrapPaymentIntentCreate (create) {
24
- return function wrappedPaymentIntentCreate () {
25
- const promise = create.apply(this, arguments)
24
+ return function wrappedPaymentIntentCreate (...args) {
25
+ const promise = create.apply(this, args)
26
26
 
27
27
  if (!paymentIntentCreateFinishCh.hasSubscribers) return promise
28
28
 
@@ -34,8 +34,8 @@ function wrapPaymentIntentCreate (create) {
34
34
  }
35
35
 
36
36
  function wrapConstructEvent (constructEvent) {
37
- return function wrappedConstructEvent () {
38
- const result = constructEvent.apply(this, arguments)
37
+ return function wrappedConstructEvent (...args) {
38
+ const result = constructEvent.apply(this, args)
39
39
 
40
40
  // no need to check for hasSubscribers,
41
41
  // if it's false, the publish function will be noop
@@ -46,8 +46,8 @@ function wrapConstructEvent (constructEvent) {
46
46
  }
47
47
 
48
48
  function wrapConstructEventAsync (constructEventAsync) {
49
- return function wrappedConstructEventAsync () {
50
- const promise = constructEventAsync.apply(this, arguments)
49
+ return function wrappedConstructEventAsync (...args) {
50
+ const promise = constructEventAsync.apply(this, args)
51
51
 
52
52
  if (!constructEventFinishCh.hasSubscribers) return promise
53
53
 
@@ -58,35 +58,49 @@ function wrapConstructEventAsync (constructEventAsync) {
58
58
  }
59
59
  }
60
60
 
61
- function wrapStripe (Stripe) {
62
- return function wrappedStripe () {
63
- let stripe = Stripe.apply(this, arguments)
64
-
65
- // to support both with and without "new" operator syntax
66
- if (this instanceof Stripe) {
67
- stripe = this
68
- }
69
-
70
- if (typeof stripe.checkout?.sessions?.create === 'function') {
71
- shimmer.wrap(stripe.checkout.sessions, 'create', wrapSessionCreate)
72
- }
73
- if (typeof stripe.paymentIntents?.create === 'function') {
74
- shimmer.wrap(stripe.paymentIntents, 'create', wrapPaymentIntentCreate)
75
- }
76
- if (typeof stripe.webhooks?.constructEvent === 'function') {
77
- shimmer.wrap(stripe.webhooks, 'constructEvent', wrapConstructEvent)
78
- }
79
- if (typeof stripe.webhooks?.constructEventAsync === 'function') {
80
- shimmer.wrap(stripe.webhooks, 'constructEventAsync', wrapConstructEventAsync)
81
- }
61
+ function instrumentStripeInstance (stripe) {
62
+ if (typeof stripe.checkout?.sessions?.create === 'function') {
63
+ shimmer.wrap(stripe.checkout.sessions, 'create', wrapSessionCreate)
64
+ }
65
+ if (typeof stripe.paymentIntents?.create === 'function') {
66
+ shimmer.wrap(stripe.paymentIntents, 'create', wrapPaymentIntentCreate)
67
+ }
68
+ if (typeof stripe.webhooks?.constructEvent === 'function') {
69
+ shimmer.wrap(stripe.webhooks, 'constructEvent', wrapConstructEvent)
70
+ }
71
+ if (typeof stripe.webhooks?.constructEventAsync === 'function') {
72
+ shimmer.wrap(stripe.webhooks, 'constructEventAsync', wrapConstructEventAsync)
73
+ }
74
+ }
75
+
76
+ // stripe <22: the constructor mutates this (when invoked with 'new') and
77
+ // returns nothing; without 'new' it delegates to 'new Stripe(...)' and returns
78
+ // that result. We need to instrument whichever object actually got populated
79
+ function wrapLegacyStripe (Stripe) {
80
+ return function wrappedStripe (...args) {
81
+ const result = Stripe.apply(this, args)
82
+ const stripe = this instanceof Stripe ? this : result
83
+ instrumentStripeInstance(stripe)
84
+ return stripe
85
+ }
86
+ }
82
87
 
88
+ // stripe >=22: the constructor is a factory that always returns a fresh Stripe
89
+ // instance regardless of 'new', so we just instrument and forward the result
90
+ function wrapStripe (Stripe) {
91
+ return function wrappedStripe (...args) {
92
+ const stripe = Stripe.apply(this, args)
93
+ instrumentStripeInstance(stripe)
83
94
  return stripe
84
95
  }
85
96
  }
86
97
 
87
98
  addHook({
88
99
  name: 'stripe',
89
- versions: ['9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '>=20.0.0'],
90
- }, Stripe => {
91
- return shimmer.wrapFunction(Stripe, wrapStripe)
92
- })
100
+ versions: ['>=9 <22'],
101
+ }, Stripe => shimmer.wrapFunction(Stripe, wrapLegacyStripe))
102
+
103
+ addHook({
104
+ name: 'stripe',
105
+ versions: ['>=22'],
106
+ }, Stripe => shimmer.wrapFunction(Stripe, wrapStripe))
@@ -4,12 +4,40 @@ const shimmer = require('../../datadog-shimmer')
4
4
  const {
5
5
  channel,
6
6
  addHook,
7
+ AsyncResource,
7
8
  } = require('./helpers/instrument')
8
9
 
10
+ // Listeners added to the BulkLoad row stream (`bulkLoad.getRowStream()`) by the caller would
11
+ // otherwise run in whatever async context emits the stream event, losing the span that was active
12
+ // when the listener was registered. Bind each registered listener to its registration context so
13
+ // `'finish'`/`'error'`/`'data'` handlers run in the caller's span, as they did before the tracer
14
+ // moved to AsyncLocalStorage. tedious' own internal listeners are attached before `getRowStream`
15
+ // returns, so only caller listeners are bound.
16
+ const ROW_STREAM_LISTENER_METHODS = ['addListener', 'on', 'once', 'prependListener', 'prependOnceListener']
17
+
18
+ function bindRowStreamListeners (rowStream) {
19
+ for (const method of ROW_STREAM_LISTENER_METHODS) {
20
+ shimmer.wrap(rowStream, method, register => function (eventName, listener) {
21
+ if (typeof listener !== 'function') {
22
+ return register.apply(this, arguments)
23
+ }
24
+ return register.call(this, eventName, AsyncResource.bind(listener))
25
+ })
26
+ }
27
+ return rowStream
28
+ }
29
+
9
30
  addHook({ name: 'tedious', versions: ['>=1.0.0'] }, tedious => {
10
31
  const startCh = channel('apm:tedious:request:start')
11
32
  const finishCh = channel('apm:tedious:request:finish')
12
33
  const errorCh = channel('apm:tedious:request:error')
34
+
35
+ if (typeof tedious.BulkLoad?.prototype?.getRowStream === 'function') {
36
+ shimmer.wrap(tedious.BulkLoad.prototype, 'getRowStream', getRowStream => function () {
37
+ return bindRowStreamListeners(getRowStream.apply(this, arguments))
38
+ })
39
+ }
40
+
13
41
  shimmer.wrap(tedious.Connection.prototype, 'makeRequest', makeRequest => function (request) {
14
42
  if (!startCh.hasSubscribers) {
15
43
  return makeRequest.apply(this, arguments)