@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
@@ -8,10 +8,10 @@ const anthropicTracingChannel = tracingChannel('apm:anthropic:request')
8
8
  const onStreamedChunkCh = channel('apm:anthropic:request:chunk')
9
9
 
10
10
  function wrapStreamIterator (iterator, ctx) {
11
- return function () {
12
- const itr = iterator.apply(this, arguments)
13
- shimmer.wrap(itr, 'next', next => function () {
14
- return next.apply(this, arguments)
11
+ return function (...args) {
12
+ const itr = iterator.apply(this, args)
13
+ shimmer.wrap(itr, 'next', next => function (...args) {
14
+ return next.apply(this, args)
15
15
  .then(res => {
16
16
  const { done, value: chunk } = res
17
17
  onStreamedChunkCh.publish({ ctx, chunk, done })
@@ -33,12 +33,12 @@ function wrapStreamIterator (iterator, ctx) {
33
33
  }
34
34
 
35
35
  function wrapCreate (create) {
36
- return function () {
36
+ return function (...args) {
37
37
  if (!anthropicTracingChannel.start.hasSubscribers) {
38
- return create.apply(this, arguments)
38
+ return create.apply(this, args)
39
39
  }
40
40
 
41
- const options = arguments[0]
41
+ const options = args[0]
42
42
  const stream = options.stream
43
43
 
44
44
  const ctx = { options, resource: 'create', baseUrl: this._client?.baseURL }
@@ -46,14 +46,14 @@ function wrapCreate (create) {
46
46
  return anthropicTracingChannel.start.runStores(ctx, () => {
47
47
  let apiPromise
48
48
  try {
49
- apiPromise = create.apply(this, arguments)
49
+ apiPromise = create.apply(this, args)
50
50
  } catch (error) {
51
51
  finish(ctx, null, error)
52
52
  throw error
53
53
  }
54
54
 
55
- shimmer.wrap(apiPromise, 'parse', parse => function () {
56
- return parse.apply(this, arguments)
55
+ shimmer.wrap(apiPromise, 'parse', parse => function (...args) {
56
+ return parse.apply(this, args)
57
57
  .then(response => {
58
58
  if (stream) {
59
59
  shimmer.wrap(response, Symbol.asyncIterator, iterator => wrapStreamIterator(iterator, ctx))
@@ -10,9 +10,9 @@ addHook({ name: 'apollo-server-core', file: 'dist/runHttpQuery.js', versions: ['
10
10
  const HttpQueryError = runHttpQueryModule.HttpQueryError
11
11
 
12
12
  shimmer.wrap(runHttpQueryModule, 'runHttpQuery', function wrapRunHttpQuery (originalRunHttpQuery) {
13
- return function runHttpQuery () {
13
+ return function runHttpQuery (...args) {
14
14
  if (!requestChannel.start.hasSubscribers) {
15
- return originalRunHttpQuery.apply(this, arguments)
15
+ return originalRunHttpQuery.apply(this, args)
16
16
  }
17
17
 
18
18
  const abortController = new AbortController()
@@ -22,7 +22,7 @@ addHook({ name: 'apollo-server-core', file: 'dist/runHttpQuery.js', versions: ['
22
22
  originalRunHttpQuery,
23
23
  { abortController, abortData },
24
24
  this,
25
- ...arguments)
25
+ ...args)
26
26
 
27
27
  const abortPromise = new Promise((resolve, reject) => {
28
28
  abortController.signal.addEventListener('abort', (event) => {
@@ -13,9 +13,9 @@ const requestChannel = dc.tracingChannel('datadog:apollo:request')
13
13
  let HeaderMap
14
14
 
15
15
  function wrapExecuteHTTPGraphQLRequest (originalExecuteHTTPGraphQLRequest) {
16
- return function executeHTTPGraphQLRequest () {
16
+ return function executeHTTPGraphQLRequest (...args) {
17
17
  if (!HeaderMap || !requestChannel.start.hasSubscribers) {
18
- return originalExecuteHTTPGraphQLRequest.apply(this, arguments)
18
+ return originalExecuteHTTPGraphQLRequest.apply(this, args)
19
19
  }
20
20
 
21
21
  const abortController = new AbortController()
@@ -25,7 +25,7 @@ function wrapExecuteHTTPGraphQLRequest (originalExecuteHTTPGraphQLRequest) {
25
25
  originalExecuteHTTPGraphQLRequest,
26
26
  { abortController, abortData },
27
27
  this,
28
- ...arguments)
28
+ ...args)
29
29
 
30
30
  const abortPromise = new Promise((resolve, reject) => {
31
31
  abortController.signal.addEventListener('abort', (event) => {
@@ -89,10 +89,10 @@ function wrapEmit (emit) {
89
89
  }
90
90
 
91
91
  function wrapListen (originalListen) {
92
- return function wrappedListen () {
92
+ return function wrappedListen (...args) {
93
93
  shimmer.wrap(this, 'emit', wrapEmit)
94
94
 
95
- return originalListen.apply(this, arguments)
95
+ return originalListen.apply(this, args)
96
96
  }
97
97
  }
98
98
 
@@ -112,24 +112,16 @@ function apolloDrainHttpServerHook (drainModule) {
112
112
  return drainModule
113
113
  }
114
114
 
115
- addHook({ name: '@apollo/server', file: 'dist/cjs/ApolloServer.js', versions: ['4'] }, apolloServerHook)
115
+ addHook({ name: '@apollo/server', file: 'dist/cjs/ApolloServer.js', versions: ['>=4'] }, apolloServerHook)
116
116
 
117
117
  addHook({ name: '@apollo/server', file: 'dist/cjs/express4/index.js', versions: ['4'] }, apolloExpress4Hook)
118
118
 
119
- addHook({ name: '@apollo/server', file: 'dist/cjs/utils/HeaderMap.js', versions: ['4'] }, apolloHeaderMapHook)
120
-
121
119
  addHook(
122
- { name: '@apollo/server', file: 'dist/cjs/plugin/drainHttpServer/index.js', versions: ['>=5.0.0'] },
123
- apolloDrainHttpServerHook
120
+ { name: '@apollo/server', file: 'dist/cjs/utils/HeaderMap.js', versions: ['>=4'] },
121
+ apolloHeaderMapHook
124
122
  )
125
123
 
126
124
  addHook(
127
- { name: '@apollo/server', file: 'dist/cjs/runHttpQuery.js', versions: ['>=5.0.0'] },
128
- (runHttpQueryModule) => {
129
- shimmer.wrap(runHttpQueryModule, 'runHttpQuery', function wrapRunHttpQuery (originalRunHttpQuery) {
130
- return wrapExecuteHTTPGraphQLRequest(originalRunHttpQuery)
131
- })
132
-
133
- return runHttpQueryModule
134
- }
125
+ { name: '@apollo/server', file: 'dist/cjs/plugin/drainHttpServer/index.js', versions: ['>=5.0.0'] },
126
+ apolloDrainHttpServerHook
135
127
  )
@@ -8,21 +8,21 @@ const serializeChannel = dc.channel('apm:avsc:serialize-start')
8
8
  const deserializeChannel = dc.channel('apm:avsc:deserialize-end')
9
9
 
10
10
  function wrapSerialization (Type) {
11
- shimmer.wrap(Type.prototype, 'toBuffer', original => function () {
11
+ shimmer.wrap(Type.prototype, 'toBuffer', original => function (...args) {
12
12
  if (!serializeChannel.hasSubscribers) {
13
- return original.apply(this, arguments)
13
+ return original.apply(this, args)
14
14
  }
15
15
  serializeChannel.publish({ messageClass: this })
16
- return original.apply(this, arguments)
16
+ return original.apply(this, args)
17
17
  })
18
18
  }
19
19
 
20
20
  function wrapDeserialization (Type) {
21
- shimmer.wrap(Type.prototype, 'fromBuffer', original => function () {
21
+ shimmer.wrap(Type.prototype, 'fromBuffer', original => function (...args) {
22
22
  if (!deserializeChannel.hasSubscribers) {
23
- return original.apply(this, arguments)
23
+ return original.apply(this, args)
24
24
  }
25
- const result = original.apply(this, arguments)
25
+ const result = original.apply(this, args)
26
26
  deserializeChannel.publish({ messageClass: result })
27
27
  return result
28
28
  })
@@ -0,0 +1,18 @@
1
+ 'use strict'
2
+
3
+ // Methods on `DurableContextImpl` that return a lazy DurablePromise. The rewriter
4
+ // instrumentation generates a `kind: 'Sync'` Orchestrion hook for each so Orchestrion
5
+ // does not eagerly side-chain `.then()`; the runtime instrumentation side-chains the
6
+ // returned DurablePromise itself and publishes a `:settle` channel once it settles,
7
+ // preserving the SDK's lazy semantics. Shared between both so the lists cannot drift.
8
+ module.exports = [
9
+ 'step',
10
+ 'invoke',
11
+ 'runInChildContext',
12
+ 'wait',
13
+ 'waitForCondition',
14
+ 'waitForCallback',
15
+ 'createCallback',
16
+ 'map',
17
+ 'parallel',
18
+ ]
@@ -0,0 +1,111 @@
1
+ 'use strict'
2
+
3
+ const { channel, tracingChannel } = require('dc-polyfill')
4
+ const shimmer = require('../../datadog-shimmer')
5
+ const { addHook, getHooks } = require('./helpers/instrument')
6
+ const LAZY_DURABLE_PROMISE_METHODS = require('./aws-durable-execution-sdk-js-context-methods')
7
+
8
+ for (const method of LAZY_DURABLE_PROMISE_METHODS) {
9
+ const orchestrionCh = tracingChannel(`orchestrion:@aws/durable-execution-sdk-js:DurableContextImpl_${method}`)
10
+ const settleCh = channel(`apm:aws-durable-execution-sdk-js:${method}:settle`)
11
+
12
+ orchestrionCh.end.subscribe(ctx => {
13
+ if (!settleCh.hasSubscribers) return
14
+ observeDurablePromise(ctx.result, error => {
15
+ if (error !== undefined) ctx.error = error
16
+ settleCh.publish(ctx)
17
+ })
18
+ })
19
+ }
20
+
21
+ // runHandler(event, context, executionContext, mode, checkpointToken, handler) creates the
22
+ // DurableContext internally and passes it to the user handler, and drives suspension through
23
+ // executionContext.terminationManager.terminate(). The cross-invocation checkpoint plugin needs
24
+ // both: the DurableContext (to reach the checkpoint manager) and a signal that the execution is
25
+ // suspending. Capture the former off the handler call and surface the latter on a channel.
26
+ const HANDLER_ARG_INDEX = 5
27
+ const EXECUTION_CONTEXT_ARG_INDEX = 2
28
+
29
+ const withDurableExecutionCh = tracingChannel('orchestrion:@aws/durable-execution-sdk-js:withDurableExecution')
30
+ const terminateCh = channel('apm:aws-durable-execution-sdk-js:terminate')
31
+
32
+ withDurableExecutionCh.start.subscribe(ctx => {
33
+ // Only wrap while the plugin is listening (cross-invocation tracing enabled).
34
+ if (!terminateCh.hasSubscribers) return
35
+
36
+ // ctx.arguments is an array-like `arguments` object, not a true Array.
37
+ const args = ctx.arguments
38
+ if (!args) return
39
+
40
+ if (typeof args[HANDLER_ARG_INDEX] === 'function') {
41
+ shimmer.wrap(args, HANDLER_ARG_INDEX, handler => function (event, durableContext) {
42
+ ctx.durableContext = durableContext
43
+ return handler.apply(this, arguments)
44
+ })
45
+ }
46
+
47
+ const terminationManager = args[EXECUTION_CONTEXT_ARG_INDEX]?.terminationManager
48
+ if (typeof terminationManager?.terminate === 'function') {
49
+ shimmer.wrap(terminationManager, 'terminate', terminate => function (options) {
50
+ // Publish before the original runs so the plugin can enqueue the checkpoint while the
51
+ // checkpoint manager is still accepting writes (it flips to "terminating" inside terminate()).
52
+ ctx.terminationReason = options?.reason
53
+ terminateCh.publish(ctx)
54
+ return terminate.apply(this, arguments)
55
+ })
56
+ }
57
+ })
58
+
59
+ // Per-instance settle callback read by the shared prototype wrappers installed by
60
+ // `instrumentDurablePromiseProto`. Stored on the DurablePromise instance so the prototype
61
+ // wrappers stay allocation-free and the promise carries its own observer.
62
+ const ON_SETTLE = Symbol('_dd.durableExecution.onSettle')
63
+
64
+ const instrumentedProtos = new WeakSet()
65
+
66
+ /**
67
+ * Wraps `then`/`catch`/`finally` on a DurablePromise prototype once so every instance shares
68
+ * the same wrappers instead of being re-wrapped individually. The wrappers side-chain a settle
69
+ * observer the first time user code chains off the promise, then clear `ON_SETTLE` so the
70
+ * observer attaches at most once (a promise settles only once). Instances we don't observe
71
+ * never set `ON_SETTLE`, so for them the wrappers are a single property read and a passthrough.
72
+ * @param {object} proto - The DurablePromise prototype (`Object.getPrototypeOf(dp)`).
73
+ * @returns {void}
74
+ */
75
+ function instrumentDurablePromiseProto (proto) {
76
+ if (instrumentedProtos.has(proto)) return
77
+ instrumentedProtos.add(proto)
78
+
79
+ // Capture the genuine `.then` before wrapping so the settle observer side-chains without
80
+ // recursing back into the wrapper below.
81
+ const originalThen = proto.then
82
+
83
+ shimmer.massWrap(proto, ['then', 'catch', 'finally'], original => function (...args) {
84
+ const onSettle = this[ON_SETTLE]
85
+ if (onSettle !== undefined) {
86
+ this[ON_SETTLE] = undefined
87
+ originalThen.call(this, () => onSettle(), err => onSettle(err))
88
+ }
89
+ return original.apply(this, args)
90
+ })
91
+ }
92
+
93
+ /**
94
+ * Registers a settle observer on a returned DurablePromise. Callers pair `kind: 'Sync'` with this
95
+ * helper so `onSettle` only fires after user code first awaits / chains, preserving the SDK's
96
+ * lazy semantics.
97
+ * @param {object} dp - The returned DurablePromise instance.
98
+ * @param {(err: unknown) => void} onSettle - Called once with `undefined` on success or the
99
+ * rejection reason on failure.
100
+ * @returns {void}
101
+ */
102
+ function observeDurablePromise (dp, onSettle) {
103
+ if (!dp || typeof dp.then !== 'function') return
104
+ instrumentDurablePromiseProto(Object.getPrototypeOf(dp))
105
+ dp[ON_SETTLE] = onSettle
106
+ }
107
+
108
+ for (const hook of getHooks('@aws/durable-execution-sdk-js')) {
109
+ hook.file = null
110
+ addHook(hook, exports => exports)
111
+ }
@@ -4,76 +4,181 @@ const shimmer = require('../../datadog-shimmer')
4
4
  const { channel, addHook } = require('./helpers/instrument')
5
5
 
6
6
  const patchedClientConfigProtocols = new WeakSet()
7
+ const patchedCommandPrototypes = new WeakSet()
8
+
9
+ // Resource identifiers that already match the channel-suffix slug. Anything
10
+ // else falls back to `'default'`. Hoisted out of the per-call hot path so we
11
+ // don't allocate a fresh Array literal + run `.includes` on every AWS send.
12
+ const KNOWN_CHANNEL_SUFFIXES = new Set([
13
+ 'cloudwatchlogs',
14
+ 'dynamodb',
15
+ 'eventbridge',
16
+ 'kinesis',
17
+ 'lambda',
18
+ 'redshift',
19
+ 's3',
20
+ 'sfn',
21
+ 'sns',
22
+ 'sqs',
23
+ 'states',
24
+ 'stepfunctions',
25
+ 'bedrockruntime',
26
+ ])
27
+
28
+ /**
29
+ * @typedef {object} ChannelBag
30
+ * @property {ReturnType<typeof channel>} start
31
+ * @property {ReturnType<typeof channel>} complete
32
+ * @property {ReturnType<typeof channel>} region
33
+ * @property {ReturnType<typeof channel>} responseStart
34
+ * @property {ReturnType<typeof channel>} responseFinish
35
+ * @property {ReturnType<typeof channel>} deserialize
36
+ * @property {ReturnType<typeof channel>} streamedChunk
37
+ */
38
+
39
+ /** @type {Map<string, ChannelBag>} */
40
+ const channelBags = new Map()
41
+
42
+ /**
43
+ * Returns the cached set of diagnostic-channel handles for a given AWS
44
+ * service slug. Each `channel(...)` call hashes the channel name into a
45
+ * shared registry and allocates a per-call template-literal string; doing
46
+ * that ~8 times per AWS send was a measurable per-request cost.
47
+ *
48
+ * @param {string} suffix
49
+ * @returns {ChannelBag}
50
+ */
51
+ function getChannelBag (suffix) {
52
+ let bag = channelBags.get(suffix)
53
+ if (bag === undefined) {
54
+ bag = {
55
+ start: channel(`apm:aws:request:start:${suffix}`),
56
+ complete: channel(`apm:aws:request:complete:${suffix}`),
57
+ region: channel(`apm:aws:request:region:${suffix}`),
58
+ responseStart: channel(`apm:aws:response:start:${suffix}`),
59
+ responseFinish: channel(`apm:aws:response:finish:${suffix}`),
60
+ deserialize: channel(`apm:aws:response:deserialize:${suffix}`),
61
+ streamedChunk: channel(`apm:aws:response:streamed-chunk:${suffix}`),
62
+ }
63
+ channelBags.set(suffix, bag)
64
+ }
65
+ return bag
66
+ }
67
+
68
+ /** @type {WeakMap<Function, string>} */
69
+ const clientNameCache = new WeakMap()
70
+
71
+ /**
72
+ * @param {Function} clientCtor
73
+ * @returns {string}
74
+ */
75
+ function getClientName (clientCtor) {
76
+ let name = clientNameCache.get(clientCtor)
77
+ if (name === undefined) {
78
+ name = clientCtor.name.replace(/Client$/, '')
79
+ clientNameCache.set(clientCtor, name)
80
+ }
81
+ return name
82
+ }
83
+
84
+ /** @type {WeakMap<Function, string>} */
85
+ const operationCache = new WeakMap()
86
+
87
+ /**
88
+ * @param {Function} commandCtor
89
+ * @returns {string}
90
+ */
91
+ function getOperationName (commandCtor) {
92
+ let operation = operationCache.get(commandCtor)
93
+ if (operation === undefined) {
94
+ const commandName = commandCtor.name
95
+ operation = `${commandName[0].toLowerCase()}${commandName.slice(1).replace(/Command$/, '')}`
96
+ operationCache.set(commandCtor, operation)
97
+ }
98
+ return operation
99
+ }
7
100
 
8
101
  function wrapRequest (send) {
102
+ // V8 deopts both this function and `send.apply(this, arguments)` once
103
+ // `arguments[0] = wrapCb(...)` materialises the arguments object on the
104
+ // hot path. Pass the (at most one-arg) call site through explicitly --
105
+ // `Request.send` only accepts an optional callback in both v2 and v3 SDKs.
9
106
  return function wrappedRequest (cb) {
10
107
  if (!this.service) return send.apply(this, arguments)
11
108
 
12
109
  const serviceIdentifier = this.service.serviceIdentifier
13
110
  const channelSuffix = getChannelSuffix(serviceIdentifier)
14
- const startCh = channel(`apm:aws:request:start:${channelSuffix}`)
15
- if (!startCh.hasSubscribers) return send.apply(this, arguments)
111
+ const channels = getChannelBag(channelSuffix)
112
+ if (!channels.start.hasSubscribers) return send.apply(this, arguments)
16
113
 
114
+ const cbExists = typeof cb === 'function'
17
115
  const ctx = {
18
116
  serviceIdentifier,
19
117
  operation: this.operation,
20
118
  awsRegion: this.service.config && this.service.config.region,
21
119
  awsService: this.service.api && this.service.api.className,
22
120
  request: this,
23
- cbExists: typeof cb === 'function',
121
+ cbExists,
24
122
  }
25
123
 
124
+ // AWS SDK v2 mixes in its own `SequentialExecutor` (no `once`), so stick
125
+ // to `on('complete')`. The event fires exactly once per Request — even
126
+ // across retries — so we don't get duplicate publishes.
26
127
  this.on('complete', response => {
27
128
  ctx.response = response
28
- channel(`apm:aws:request:complete:${channelSuffix}`).publish(ctx)
129
+ channels.complete.publish(ctx)
29
130
  })
30
131
 
31
- if (ctx.cbExists) {
32
- arguments[0] = wrapCb(cb, channelSuffix, ctx)
132
+ if (cbExists) {
133
+ return channels.start.runStores(ctx, send, this, wrapCb(cb, channels, ctx))
33
134
  }
34
-
35
- return startCh.runStores(ctx, send, this, ...arguments)
135
+ return channels.start.runStores(ctx, send, this)
36
136
  }
37
137
  }
38
138
 
39
- function wrapDeserialize (deserialize, channelSuffix, responseIndex = 0) {
40
- const headersCh = channel(`apm:aws:response:deserialize:${channelSuffix}`)
41
-
42
- return function () {
43
- const response = arguments[responseIndex]
139
+ function wrapDeserialize (deserialize, headersCh, responseIndex = 0) {
140
+ return function (...args) {
141
+ const response = args[responseIndex]
44
142
  if (headersCh.hasSubscribers) {
45
143
  headersCh.publish({ headers: response.headers })
46
144
  }
47
145
 
48
- return deserialize.apply(this, arguments)
146
+ return deserialize.apply(this, args)
49
147
  }
50
148
  }
51
149
 
52
150
  function wrapSmithySend (send) {
53
151
  return function (command, ...args) {
54
152
  const cb = args.at(-1)
153
+ const cbExists = typeof cb === 'function'
55
154
  const serviceIdentifier = this.config.serviceId.toLowerCase()
56
155
  const channelSuffix = getChannelSuffix(serviceIdentifier)
57
- const commandName = command.constructor.name
58
- const clientName = this.constructor.name.replace(/Client$/, '')
59
- const operation = `${commandName[0].toLowerCase()}${commandName.slice(1).replace(/Command$/, '')}`
156
+ const channels = getChannelBag(channelSuffix)
157
+ const clientName = getClientName(this.constructor)
158
+ const operation = getOperationName(command.constructor)
60
159
  const request = {
61
160
  operation,
62
161
  params: command.input,
63
162
  }
64
163
 
65
- const startCh = channel(`apm:aws:request:start:${channelSuffix}`)
66
- const regionCh = channel(`apm:aws:request:region:${channelSuffix}`)
67
- const responseStartChannel = channel(`apm:aws:response:start:${channelSuffix}`)
68
- const responseFinishChannel = channel(`apm:aws:response:finish:${channelSuffix}`)
69
-
70
164
  if (typeof command.deserialize === 'function') {
71
- shimmer.wrap(command, 'deserialize', deserialize => wrapDeserialize(deserialize, channelSuffix))
165
+ const proto = Object.getPrototypeOf(command)
166
+ // Wrap once per Command class via the prototype when `deserialize` is
167
+ // inherited; fall back to per-instance wrap when a command shadows it
168
+ // as an own property (rare in @aws-sdk v3).
169
+ if (proto && proto.deserialize === command.deserialize) {
170
+ if (!patchedCommandPrototypes.has(proto)) {
171
+ shimmer.wrap(proto, 'deserialize', deserialize => wrapDeserialize(deserialize, channels.deserialize))
172
+ patchedCommandPrototypes.add(proto)
173
+ }
174
+ } else {
175
+ shimmer.wrap(command, 'deserialize', deserialize => wrapDeserialize(deserialize, channels.deserialize))
176
+ }
72
177
  } else if (this.config?.protocol?.deserializeResponse && !patchedClientConfigProtocols.has(this.config.protocol)) {
73
178
  shimmer.wrap(
74
179
  this.config.protocol,
75
180
  'deserializeResponse',
76
- deserializeResponse => wrapDeserialize(deserializeResponse, channelSuffix, 2)
181
+ deserializeResponse => wrapDeserialize(deserializeResponse, channels.deserialize, 2)
77
182
  )
78
183
 
79
184
  patchedClientConfigProtocols.add(this.config.protocol)
@@ -84,27 +189,28 @@ function wrapSmithySend (send) {
84
189
  operation,
85
190
  awsService: clientName,
86
191
  request,
192
+ cbExists,
87
193
  }
88
194
 
89
- return startCh.runStores(ctx, () => {
195
+ return channels.start.runStores(ctx, () => {
90
196
  // When the region is not set this never resolves so we can't await.
91
197
  this.config.region().then(region => {
92
198
  ctx.region = region
93
- regionCh.publish(ctx)
199
+ channels.region.publish(ctx)
94
200
  })
95
201
 
96
- if (typeof cb === 'function') {
97
- args[args.length - 1] = shimmer.wrapFunction(cb, cb => function (err, result) {
202
+ if (cbExists) {
203
+ args[args.length - 1] = shimmer.wrapCallback(cb, cb => function (err, result) {
98
204
  addResponse(ctx, err, result)
99
205
 
100
- handleCompletion(result, ctx, channelSuffix)
206
+ handleCompletion(result, ctx, channels)
101
207
 
102
208
  const responseCtx = { request, response: ctx.response }
103
209
 
104
- responseStartChannel.runStores(responseCtx, () => {
210
+ channels.responseStart.runStores(responseCtx, () => {
105
211
  cb.apply(this, arguments)
106
212
 
107
- responseFinishChannel.publish(responseCtx)
213
+ channels.responseFinish.publish(responseCtx)
108
214
  })
109
215
  })
110
216
  } else { // always a promise
@@ -112,12 +218,12 @@ function wrapSmithySend (send) {
112
218
  .then(
113
219
  result => {
114
220
  addResponse(ctx, null, result)
115
- handleCompletion(result, ctx, channelSuffix)
221
+ handleCompletion(result, ctx, channels)
116
222
  return result
117
223
  },
118
224
  error => {
119
225
  addResponse(ctx, error)
120
- handleCompletion(null, ctx, channelSuffix)
226
+ handleCompletion(null, ctx, channels)
121
227
  throw error
122
228
  }
123
229
  )
@@ -128,35 +234,33 @@ function wrapSmithySend (send) {
128
234
  }
129
235
  }
130
236
 
131
- function handleCompletion (result, ctx, channelSuffix) {
132
- const completeChannel = channel(`apm:aws:request:complete:${channelSuffix}`)
133
- const streamedChunkChannel = channel(`apm:aws:response:streamed-chunk:${channelSuffix}`)
134
-
135
- const iterator = result?.body?.[Symbol.asyncIterator]
237
+ function handleCompletion (result, ctx, channels) {
238
+ const streamable = result?.body ?? result?.stream
239
+ const iterator = streamable?.[Symbol.asyncIterator]
136
240
  if (!iterator) {
137
- completeChannel.publish(ctx)
241
+ channels.complete.publish(ctx)
138
242
  return
139
243
  }
140
244
 
141
- shimmer.wrap(result.body, Symbol.asyncIterator, function (asyncIterator) {
142
- return function () {
143
- const iterator = asyncIterator.apply(this, arguments)
245
+ shimmer.wrap(streamable, Symbol.asyncIterator, function (asyncIterator) {
246
+ return function (...args) {
247
+ const iterator = asyncIterator.apply(this, args)
144
248
  shimmer.wrap(iterator, 'next', function (next) {
145
- return function () {
146
- return next.apply(this, arguments)
249
+ return function (...args) {
250
+ return next.apply(this, args)
147
251
  .then(result => {
148
252
  const { done, value: chunk } = result
149
- streamedChunkChannel.publish({ ctx, chunk, done })
253
+ channels.streamedChunk.publish({ ctx, chunk, done })
150
254
 
151
255
  if (done) {
152
- completeChannel.publish(ctx)
256
+ channels.complete.publish(ctx)
153
257
  }
154
258
 
155
259
  return result
156
260
  })
157
261
  .catch(err => {
158
262
  addResponse(ctx, err)
159
- completeChannel.publish(ctx)
263
+ channels.complete.publish(ctx)
160
264
  throw err
161
265
  })
162
266
  }
@@ -167,30 +271,29 @@ function handleCompletion (result, ctx, channelSuffix) {
167
271
  })
168
272
  }
169
273
 
170
- function wrapCb (cb, serviceName, ctx) {
274
+ function wrapCb (cb, channels, ctx) {
171
275
  // eslint-disable-next-line n/handle-callback-err
172
- return shimmer.wrapFunction(cb, cb => function wrappedCb (err, response) {
276
+ return shimmer.wrapCallback(cb, cb => function wrappedCb (err, response) {
173
277
  ctx = { request: ctx.request, response }
174
- return channel(`apm:aws:response:start:${serviceName}`).runStores(ctx, () => {
175
- const finishChannel = channel(`apm:aws:response:finish:${serviceName}`)
278
+ return channels.responseStart.runStores(ctx, () => {
176
279
  try {
177
280
  let result = cb.apply(this, arguments)
178
281
  if (result && result.then) {
179
282
  result = result.then(x => {
180
- finishChannel.publish(ctx)
283
+ channels.responseFinish.publish(ctx)
181
284
  return x
182
285
  }, e => {
183
286
  ctx.error = e
184
- finishChannel.publish(ctx)
287
+ channels.responseFinish.publish(ctx)
185
288
  throw e
186
289
  })
187
290
  } else {
188
- finishChannel.publish(ctx)
291
+ channels.responseFinish.publish(ctx)
189
292
  }
190
293
  return result
191
294
  } catch (e) {
192
295
  ctx.error = e
193
- finishChannel.publish(ctx)
296
+ channels.responseFinish.publish(ctx)
194
297
  throw e
195
298
  }
196
299
  })
@@ -211,23 +314,7 @@ function addResponse (ctx, error, result) {
211
314
  function getChannelSuffix (name) {
212
315
  // some resource identifiers have spaces between ex: bedrock runtime
213
316
  name = String(name).replaceAll(' ', '')
214
- return [
215
- 'cloudwatchlogs',
216
- 'dynamodb',
217
- 'eventbridge',
218
- 'kinesis',
219
- 'lambda',
220
- 'redshift',
221
- 's3',
222
- 'sfn',
223
- 'sns',
224
- 'sqs',
225
- 'states',
226
- 'stepfunctions',
227
- 'bedrockruntime',
228
- ].includes(name)
229
- ? name
230
- : 'default'
317
+ return KNOWN_CHANNEL_SUFFIXES.has(name) ? name : 'default'
231
318
  }
232
319
 
233
320
  addHook({ name: '@smithy/smithy-client', versions: ['>=1.0.3'] }, smithy => {
@@ -240,6 +327,19 @@ addHook({ name: '@aws-sdk/smithy-client', versions: ['>=3'] }, smithy => {
240
327
  return smithy
241
328
  })
242
329
 
330
+ // `@aws-sdk/client-*` >= 3.1046.0 dropped `@smithy/smithy-client` and now
331
+ // extends from `@smithy/core/client` directly. The `Client.send` contract is
332
+ // unchanged, but the host module moved -- patch the new home so the v3 hooks
333
+ // keep firing.
334
+ addHook({
335
+ name: '@smithy/core',
336
+ file: 'dist-cjs/submodules/client/index.js',
337
+ versions: ['>=3.24.0'],
338
+ }, smithyCoreClient => {
339
+ shimmer.wrap(smithyCoreClient.Client.prototype, 'send', wrapSmithySend)
340
+ return smithyCoreClient
341
+ })
342
+
243
343
  addHook({ name: 'aws-sdk', versions: ['>=2.3.0'] }, AWS => {
244
344
  shimmer.wrap(AWS.config, 'setPromisesDependency', setPromisesDependency => {
245
345
  return function wrappedSetPromisesDependency (dep) {