@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
@@ -3,37 +3,26 @@
3
3
  const { AsyncLocalStorage } = require('async_hooks')
4
4
 
5
5
  /**
6
- * This is exactly the same as AsyncLocalStorage, with the exception that it
7
- * uses a WeakMap to store the store object. This is because ALS stores the
8
- * store object as a property of the resource object, which causes all sorts
9
- * of problems with logging and memory. We substitute the `store` object with
10
- * a "handle" object, which is used as a key in a WeakMap, where the values
11
- * are the real store objects.
6
+ * `AsyncLocalStorage` with a `getHandle()` escape hatch: a span stashes the
7
+ * active handle at creation (see opentracing/span.js) so a later context can
8
+ * recover its store without holding the store itself.
9
+ *
10
+ * Under AsyncContextFrame — Node's default ALS backend on every release that
11
+ * ships it — the active value lives in the context frame and is never written
12
+ * to the async resource, so the store is held directly and the handle is the
13
+ * store. Pre-ACF `async_hooks` instead pinned the value onto the resource
14
+ * object, where it was visible to logging and retained with the resource
15
+ * graph; the `!isACFActive` block below restores the original WeakMap-handle
16
+ * indirection that kept the real store off the resource on those runtimes.
12
17
  *
13
18
  * @template T
14
19
  * @typedef {Record<string, T>} Store
15
20
  */
16
21
  class DatadogStorage extends AsyncLocalStorage {
17
22
  /**
18
- * @param {Store<unknown>} [store]
19
- * @override
20
- */
21
- enterWith (store) {
22
- const handle = {}
23
- stores.set(handle, store)
24
- super.enterWith(handle)
25
- }
26
-
27
- /**
28
- * This is method is a passthrough to the real `getStore()`, so that, when we
29
- * need it, we can use the handle rather than our mapped store.
30
- *
31
- * It's only here because stores are currently used for a bunch of things,
32
- * and we don't want to hold on to all of them in spans
33
- * (see opentracing/span.js). Using a namespaced storage for spans would
34
- * solve this.
35
- *
36
- * TODO: Refactor the Scope class to use a span-only store and remove this.
23
+ * Passthrough to the real `getStore()`. A span stashes this handle and feeds
24
+ * it back to `getStore(handle)` later. Identical in both modes: under ACF the
25
+ * handle is the store; without ACF it is the WeakMap key.
37
26
  *
38
27
  * @returns {Store<unknown>}
39
28
  */
@@ -42,22 +31,13 @@ class DatadogStorage extends AsyncLocalStorage {
42
31
  }
43
32
 
44
33
  /**
45
- * Here, we replicate the behavior of the original `getStore()` method by
46
- * passing in the handle, which we retrieve by calling it on super. Handles
47
- * retrieved through `getHandle()` can also be passed in to be used as the
48
- * key. This is useful if you've stashed a handle somewhere and want to
49
- * retrieve the store with it.
50
- * @param {object} [handle]
34
+ * @param {Store<unknown>} [handle] A handle from `getHandle()`; defaults to
35
+ * the active one. Under ACF the handle is the store, so it is returned as-is.
51
36
  * @returns {Store<unknown> | undefined}
52
37
  * @override
53
38
  */
54
39
  getStore (handle) {
55
- if (!handle) {
56
- handle = super.getStore()
57
- }
58
- if (handle) {
59
- return stores.get(handle)
60
- }
40
+ return handle ?? super.getStore()
61
41
  }
62
42
  }
63
43
 
@@ -77,12 +57,37 @@ if (!isACFActive) {
77
57
  const superGetStore = AsyncLocalStorage.prototype.getStore
78
58
  const superEnterWith = AsyncLocalStorage.prototype.enterWith
79
59
 
60
+ // Without ACF, ALS writes the entered value onto the async resource. Keep the
61
+ // real store off the resource by entering a small handle and mapping it to
62
+ // the store through a WeakMap, then reversing the lookup on read.
63
+ const stores = new WeakMap()
64
+
80
65
  /**
81
- * Override the `run` method to manually call `enterWith` and `getStore`
82
- * when not using AsyncContextFrame.
83
- *
84
- * Without ACF, super.run() won't call this.enterWith(), so the WeakMap handle
85
- * is never created and getStore() would fail.
66
+ * @param {Store<unknown>} [store]
67
+ */
68
+ DatadogStorage.prototype.enterWith = function enterWith (store) {
69
+ const handle = { noop: store?.noop }
70
+ stores.set(handle, store)
71
+ superEnterWith.call(this, handle)
72
+ }
73
+
74
+ /**
75
+ * @param {object} [handle]
76
+ * @returns {Store<unknown> | undefined}
77
+ */
78
+ DatadogStorage.prototype.getStore = function getStore (handle) {
79
+ if (!handle) {
80
+ handle = superGetStore.call(this)
81
+ }
82
+ if (handle) {
83
+ return stores.get(handle)
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Without ACF, `super.run()` does not delegate to `enterWith()`, so the
89
+ * WeakMap handle is never created and `getStore()` would miss. Drive the
90
+ * handle path manually and restore the prior handle on the way out.
86
91
  *
87
92
  * @template R
88
93
  * @template {unknown[]} TArgs
@@ -103,12 +108,6 @@ if (!isACFActive) {
103
108
  }
104
109
  }
105
110
 
106
- /**
107
- * This is the map from handles to real stores, used in the class above.
108
- * @type {WeakMap<WeakKey, Store<unknown>|undefined>}
109
- */
110
- const stores = new WeakMap()
111
-
112
111
  /**
113
112
  * For convenience, we use the `storage` function as a registry of namespaces
114
113
  * corresponding to DatadogStorage instances. This lets us have separate
@@ -2,13 +2,17 @@
2
2
 
3
3
  const { execSync } = require('node:child_process')
4
4
  const fs = require('node:fs')
5
- const RAW_BUILTINS = require('node:module').builtinModules
6
5
  const path = require('node:path')
7
6
  const { pathToFileURL, fileURLToPath } = require('node:url')
8
7
 
9
8
  const instrumentations = require('../datadog-instrumentations/src/helpers/instrumentations')
10
9
  const extractPackageAndModulePath = require('../datadog-instrumentations/src/helpers/extract-package-and-module-path')
11
10
  const hooks = require('../datadog-instrumentations/src/helpers/hooks')
11
+ const {
12
+ OPTIONAL_PEER_FILTER,
13
+ matchesOptionalPeerFile,
14
+ rewriteOptionalPeerLoads,
15
+ } = require('../datadog-instrumentations/src/helpers/optional-peer-bundler')
12
16
  const { processModule, isESMFile } = require('./src/utils')
13
17
  const log = require('./src/log')
14
18
 
@@ -25,15 +29,27 @@ for (const hook of Object.values(hooks)) {
25
29
  }
26
30
  }
27
31
 
32
+ function moduleOfInterestKey (name, file) {
33
+ return file ? `${name}/${file}` : name
34
+ }
35
+
36
+ const builtinModules = new Set(require('module').builtinModules)
37
+
38
+ function addModuleOfInterest (name, file) {
39
+ if (!name) return
40
+
41
+ modulesOfInterest.add(moduleOfInterestKey(name, file))
42
+
43
+ if (builtinModules.has(name)) {
44
+ modulesOfInterest.add(moduleOfInterestKey(`node:${name}`, file))
45
+ }
46
+ }
47
+
28
48
  const modulesOfInterest = new Set()
29
49
 
30
- for (const instrumentation of Object.values(instrumentations)) {
50
+ for (const [name, instrumentation] of Object.entries(instrumentations)) {
31
51
  for (const entry of instrumentation) {
32
- if (entry.file) {
33
- modulesOfInterest.add(`${entry.name}/${entry.file}`) // e.g. "redis/my/file.js"
34
- } else {
35
- modulesOfInterest.add(entry.name) // e.g. "redis"
36
- }
52
+ addModuleOfInterest(name, entry.file)
37
53
  }
38
54
  }
39
55
 
@@ -41,7 +57,7 @@ const CHANNEL = 'dd-trace:bundler:load'
41
57
 
42
58
  const builtins = new Set()
43
59
 
44
- for (const builtin of RAW_BUILTINS) {
60
+ for (const builtin of builtinModules) {
45
61
  builtins.add(builtin)
46
62
  builtins.add(`node:${builtin}`)
47
63
  }
@@ -117,6 +133,11 @@ module.exports.setup = function (build) {
117
133
  ${build.initialOptions.banner.js}`
118
134
  }
119
135
 
136
+ // Keep the build from failing on the optional `@openfeature/core` peer of
137
+ // `@openfeature/server-sdk` when it is not installed (#8635). esbuild follows the chain
138
+ // whenever `@openfeature/server-sdk` is reachable -- the app importing it directly, or the
139
+ // bundled provider when the optional peer is present -- so mark `@openfeature/core` external
140
+ // when it is absent rather than erroring at bundle time.
120
141
  try {
121
142
  // eslint-disable-next-line n/no-unpublished-require
122
143
  require.resolve('@openfeature/core')
@@ -161,6 +182,22 @@ ${build.initialOptions.banner.js}`
161
182
  log.warn('No git metadata available - skipping injection')
162
183
  }
163
184
 
185
+ // Rewrite optional-peer loads so installed peers get bundled and survive the bundle being
186
+ // relocated without them on disk (#8980). Registered before the generic onLoad so it wins for
187
+ // these files. Absent peers stay opaque, so a build that does not opt into the feature does not
188
+ // follow their dependency chain (#8635).
189
+ build.onLoad({ filter: OPTIONAL_PEER_FILTER }, args => {
190
+ const normalizedPath = args.path.replaceAll('\\', '/')
191
+ if (!matchesOptionalPeerFile(normalizedPath)) return
192
+
193
+ log.debug('INLINE: optional-peer loader applied to %s', normalizedPath)
194
+ return {
195
+ contents: rewriteOptionalPeerLoads(fs.readFileSync(args.path, 'utf8'), path.dirname(args.path)),
196
+ loader: 'js',
197
+ resolveDir: path.dirname(args.path),
198
+ }
199
+ })
200
+
164
201
  // first time is intercepted, proxy should be created, next time the original should be loaded
165
202
  const interceptedESMModules = new Set()
166
203
 
@@ -247,7 +284,7 @@ ${build.initialOptions.banner.js}`
247
284
  }
248
285
 
249
286
  try {
250
- const packageJson = JSON.parse(fs.readFileSync(/** @type {string} */ (pathToPackageJson)).toString())
287
+ const packageJson = JSON.parse(fs.readFileSync(/** @type {string} */(pathToPackageJson)).toString())
251
288
 
252
289
  const isESM = isESMFile(fullPathToModule, pathToPackageJson, packageJson)
253
290
  if (isESM && !interceptedESMModules.has(fullPathToModule)) {
@@ -336,10 +373,15 @@ register(${JSON.stringify(toRegister)}, _, set, get, ${JSON.stringify(data.raw)}
336
373
  }
337
374
  } else {
338
375
  const fileCode = fs.readFileSync(args.path, 'utf8')
376
+ // Don't spread `...arguments`: esbuild's minifier can rewrite the surrounding
377
+ // `__commonJS` factory into an arrow function whose `arguments` resolves to the
378
+ // ESM top-level scope (see issue #8681). Pass `(module.exports, module)`
379
+ // explicitly; the IIFE declares no parameters so esbuild's static `require()`
380
+ // resolution inside `fileCode` is preserved through the factory's closure.
339
381
  contents = `
340
382
  (function() {
341
383
  ${fileCode}
342
- })(...arguments);
384
+ })(module.exports, module);
343
385
  {
344
386
  const dc = require('dc-polyfill');
345
387
  const ch = dc.channel('${CHANNEL}');
@@ -6,6 +6,9 @@ const fs = require('node:fs')
6
6
  const path = require('node:path')
7
7
  const { NODE_MAJOR, NODE_MINOR } = require('../../../version.js')
8
8
 
9
+ const LOAD_OPERATION = 0
10
+ const RESOLVE_OPERATION = 1
11
+
9
12
  const getExportsImporting = (url) => import(url).then(Object.keys)
10
13
  let getExportsModulePromise
11
14
 
@@ -19,7 +22,11 @@ const loadGetExportsModule = () => {
19
22
  const getExports = NODE_MAJOR >= 20 || (NODE_MAJOR === 18 && NODE_MINOR >= 19)
20
23
  ? async (srcUrl, context, getSource) => {
21
24
  const mod = await loadGetExportsModule()
22
- return mod.getExports(srcUrl, context, getSource)
25
+ const exportNames = mod.getExports(srcUrl, context, getSource)
26
+ if (exportNames?.next) {
27
+ return driveGetExportsGenerator(exportNames, getSource)
28
+ }
29
+ return exportNames
23
30
  }
24
31
  : getExportsImporting
25
32
 
@@ -78,14 +85,50 @@ function getSource (url, { format }) {
78
85
  }
79
86
  }
80
87
 
88
+ /**
89
+ * Drives the generator returned by import-in-the-middle >=3.1.0 export discovery.
90
+ *
91
+ * @param {Generator<Array, Set<string>>} exportsGenerator Generator returned by getExports
92
+ * @param {(url: URL, context: object) => { source: string, format: string }} getSource
93
+ * Function that loads module source
94
+ * @returns {Set<string>}
95
+ */
96
+ function driveGetExportsGenerator (exportsGenerator, getSource) {
97
+ let next = exportsGenerator.next()
98
+ while (next.done === false) {
99
+ let result
100
+ let error
101
+ let threw = false
102
+
103
+ try {
104
+ const operation = next.value
105
+ const operationType = operation[0]
106
+
107
+ if (operationType === LOAD_OPERATION) {
108
+ result = getSource(operation[1], operation[2])
109
+ } else if (operationType === RESOLVE_OPERATION) {
110
+ result = resolve(operation[1], operation[2])
111
+ } else {
112
+ throw new Error(`Unsupported import-in-the-middle getExports operation: ${operationType}`)
113
+ }
114
+ } catch (err) {
115
+ threw = true
116
+ error = err
117
+ }
118
+
119
+ next = threw ? exportsGenerator.throw(error) : exportsGenerator.next(result)
120
+ }
121
+ return next.value
122
+ }
123
+
81
124
  /**
82
125
  * Generates the pieces of code for the proxy module before the path
83
126
  *
84
127
  * @param {object} moduleData
85
128
  * @param {string} moduleData.path
86
- * @param {boolean} [moduleData.internal = false]
129
+ * @param {boolean} [moduleData.internal]
87
130
  * @param {object} moduleData.context
88
- * @param {boolean} [moduleData.excludeDefault = false]
131
+ * @param {boolean} [moduleData.excludeDefault]
89
132
  * @returns {Promise<Map>}
90
133
  */
91
134
  async function processModule ({ path, internal = false, context, excludeDefault = false }) {
@@ -12,8 +12,8 @@ const ch = tracingChannel('apm:aerospike:command')
12
12
  function wrapCreateCommand (createCommand) {
13
13
  if (typeof createCommand !== 'function') return createCommand
14
14
 
15
- return function commandWithTrace () {
16
- const CommandClass = createCommand.apply(this, arguments)
15
+ return function commandWithTrace (...args) {
16
+ const CommandClass = createCommand.apply(this, args)
17
17
 
18
18
  if (!CommandClass) return CommandClass
19
19
 
@@ -41,7 +41,7 @@ function wrapProcess (process) {
41
41
  addHook({
42
42
  name: 'aerospike',
43
43
  file: 'lib/commands/command.js',
44
- versions: ['4', '5', '6'],
44
+ versions: ['>=4'],
45
45
  },
46
46
  commandFactory => {
47
47
  return shimmer.wrapFunction(commandFactory, f => wrapCreateCommand(f))
@@ -3,34 +3,46 @@
3
3
  const { channel, tracingChannel } = require('dc-polyfill')
4
4
  const shimmer = require('../../datadog-shimmer')
5
5
  const { addHook, getHooks } = require('./helpers/instrument')
6
- const { convertVercelPromptToMessages, buildOutputMessages } = require('./helpers/ai-messages')
7
6
 
8
7
  const vercelAiTracingChannel = tracingChannel('dd-trace:vercel-ai')
9
8
  const vercelAiSpanSetAttributesChannel = channel('dd-trace:vercel-ai:span:setAttributes')
10
- const aiguardChannel = channel('dd-trace:ai:aiguard')
9
+ const doGenerateBeforeChannel = channel('dd-trace:vercel-ai:doGenerate:before')
10
+ const doGenerateAfterChannel = channel('dd-trace:vercel-ai:doGenerate:after')
11
+ const doStreamBeforeChannel = channel('dd-trace:vercel-ai:doStream:before')
12
+ const doStreamAfterChannel = channel('dd-trace:vercel-ai:doStream:after')
11
13
 
12
14
  const tracers = new WeakSet()
13
15
  const wrappedModels = new WeakSet()
14
16
 
15
17
  /**
16
- * Publishes already-converted AI guard style messages to the AIGuard channel.
18
+ * Publishes a provider-native lifecycle payload to a cancelable lifecycle channel.
17
19
  *
18
- * @param {Array<object>} messages - AI guard style messages to evaluate
20
+ * Subscribers push async work into `pending` synchronously during publication and
21
+ * abort `abortController` with an error before the pushed promise resolves to block.
22
+ *
23
+ * @param {object} lifecycleChannel
24
+ * @param {object} payload
19
25
  * @returns {Promise<void>}
20
26
  */
21
- function publishToAIGuard (messages) {
22
- return new Promise((resolve, reject) => {
23
- aiguardChannel.publish({ messages, resolve, reject })
27
+ function publishLifecycle (lifecycleChannel, payload) {
28
+ const abortController = new AbortController()
29
+ const ctx = { ...payload, abortController, pending: [] }
30
+
31
+ lifecycleChannel.publish(ctx)
32
+
33
+ return Promise.all(ctx.pending).then(() => {
34
+ if (abortController.signal.aborted) {
35
+ throw abortController.signal.reason
36
+ }
24
37
  })
25
38
  }
26
39
 
27
40
  /**
28
- * Wraps a Vercel AI language model's doGenerate and doStream methods to evaluate
29
- * messages with AIGuard.
41
+ * Wraps a Vercel AI language model's doGenerate and doStream lifecycle methods.
30
42
  *
31
43
  * @param {object} model - A Vercel AI language model instance
32
44
  */
33
- function wrapModelWithAIGuard (model) {
45
+ function wrapModelWithLifecycle (model) {
34
46
  if (!model || wrappedModels.has(model)) return
35
47
  wrappedModels.add(model)
36
48
 
@@ -39,19 +51,18 @@ function wrapModelWithAIGuard (model) {
39
51
  return function (options) {
40
52
  const originalResult = original.call(this, options)
41
53
 
42
- if (!aiguardChannel.hasSubscribers) return originalResult
54
+ if (!doGenerateBeforeChannel.hasSubscribers && !doGenerateAfterChannel.hasSubscribers) return originalResult
43
55
  if (!options.prompt?.length) return originalResult
44
56
 
45
- const inputMessages = convertVercelPromptToMessages(options.prompt)
46
- if (!inputMessages.length) return originalResult
57
+ const beforeEvaluation = doGenerateBeforeChannel.hasSubscribers
58
+ ? publishLifecycle(doGenerateBeforeChannel, { prompt: options.prompt, options })
59
+ : Promise.resolve()
47
60
 
48
- // Run AI Guard input evaluation and LLM call in parallel.
49
- // The LLM has no side effects so it is safe to discard its result if AI Guard blocks.
50
- return Promise.all([publishToAIGuard(inputMessages), originalResult])
61
+ return Promise.all([beforeEvaluation, originalResult])
51
62
  .then(([, result]) => {
52
- if (!result.content?.length) return result
53
- return publishToAIGuard(buildOutputMessages(inputMessages, result.content))
54
- .then(() => result)
63
+ if (!doGenerateAfterChannel.hasSubscribers || !result.content?.length) return result
64
+ const payload = { prompt: options.prompt, options, result }
65
+ return publishLifecycle(doGenerateAfterChannel, payload).then(() => result)
55
66
  })
56
67
  }
57
68
  })
@@ -62,16 +73,17 @@ function wrapModelWithAIGuard (model) {
62
73
  return function (options) {
63
74
  const originalResult = original.call(this, options)
64
75
 
65
- if (!aiguardChannel.hasSubscribers) return originalResult
76
+ if (!doStreamBeforeChannel.hasSubscribers && !doStreamAfterChannel.hasSubscribers) return originalResult
66
77
  if (!options.prompt?.length) return originalResult
67
78
 
68
- const inputMessages = convertVercelPromptToMessages(options.prompt)
69
- if (!inputMessages.length) return originalResult
79
+ const beforeEvaluation = doStreamBeforeChannel.hasSubscribers
80
+ ? publishLifecycle(doStreamBeforeChannel, { prompt: options.prompt, options })
81
+ : Promise.resolve()
70
82
 
71
- // Run AI Guard input evaluation and LLM call in parallel.
72
- // The LLM has no side effects so it is safe to discard its result if AI Guard blocks.
73
- return Promise.all([publishToAIGuard(inputMessages), originalResult])
83
+ return Promise.all([beforeEvaluation, originalResult])
74
84
  .then(([, result]) => {
85
+ if (!doStreamAfterChannel.hasSubscribers) return result
86
+
75
87
  const chunks = []
76
88
  const reader = result.stream.getReader()
77
89
 
@@ -84,26 +96,19 @@ function wrapModelWithAIGuard (model) {
84
96
  }
85
97
 
86
98
  return readAll().then(() => {
87
- const toolCalls = chunks.filter(c => c?.type === 'tool-call')
88
- const text = chunks.filter(c => c?.type === 'text-delta').map(c => c.textDelta).join('')
89
- const content = toolCalls.length ? toolCalls : text ? [{ type: 'text', text }] : []
90
-
91
- const evaluate = content.length
92
- ? publishToAIGuard(buildOutputMessages(inputMessages, content))
93
- : Promise.resolve()
94
-
95
- return evaluate.then(() => {
96
- // eslint-disable-next-line n/no-unsupported-features/node-builtins
97
- const stream = new ReadableStream({
98
- start (controller) {
99
- for (const chunk of chunks) {
100
- controller.enqueue(chunk)
101
- }
102
- controller.close()
103
- },
99
+ return publishLifecycle(doStreamAfterChannel, { prompt: options.prompt, options, chunks })
100
+ .then(() => {
101
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins
102
+ const stream = new ReadableStream({
103
+ start (controller) {
104
+ for (const chunk of chunks) {
105
+ controller.enqueue(chunk)
106
+ }
107
+ controller.close()
108
+ },
109
+ })
110
+ return { ...result, stream }
104
111
  })
105
- return { ...result, stream }
106
- })
107
112
  })
108
113
  })
109
114
  }
@@ -119,52 +124,57 @@ function wrapTracer (tracer) {
119
124
  tracers.add(tracer)
120
125
 
121
126
  shimmer.wrap(tracer, 'startActiveSpan', function (startActiveSpan) {
122
- return function () {
123
- const name = arguments[0]
124
- const options = arguments.length > 2 ? (arguments[1] ?? {}) : {} // startActiveSpan(name, fn)
125
- const cb = arguments[arguments.length - 1]
127
+ return function (...args) {
128
+ const name = args[0]
129
+ const options = args.length > 2 ? (args[1] ?? {}) : {} // startActiveSpan(name, fn)
130
+ const cb = args[args.length - 1]
126
131
 
127
132
  const ctx = {
128
133
  name,
129
134
  attributes: options.attributes ?? {},
130
135
  }
131
136
 
132
- arguments[arguments.length - 1] = shimmer.wrapFunction(cb, function (originalCb) {
137
+ args[args.length - 1] = shimmer.wrapFunction(cb, function (originalCb) {
133
138
  return function (span) {
134
- // the below is necessary in the case that the span is vercel ai's noopSpan.
135
- // while we don't want to patch the noopSpan more than once, we do want to treat each as a
136
- // fresh instance. However, this is really not necessary for non-noop spans, but not sure
137
- // how to differentiate.
138
- const freshSpan = Object.create(span) // TODO: does this cause memory leaks?
139
-
140
- shimmer.wrap(freshSpan, 'end', function (spanEnd) {
141
- return function () {
142
- vercelAiTracingChannel.asyncEnd.publish(ctx)
143
- return spanEnd.apply(this, arguments)
144
- }
145
- })
146
-
147
- shimmer.wrap(freshSpan, 'setAttributes', function (setAttributes) {
148
- return function (attributes) {
139
+ // A plain delegating wrapper is used instead of Object.create(span) because
140
+ // Object.create (and Proxy) cannot cross private-field brand checks — any span
141
+ // method that reads a private field (e.g. BridgeSpanBase#statusCode) would throw
142
+ // "Cannot read private member" on a prototype clone. Every method here calls
143
+ // through to the real span instance so private fields always resolve correctly.
144
+ const freshSpan = {
145
+ spanContext () { return span.spanContext() },
146
+ setAttribute (key, value) { span.setAttribute(key, value); return freshSpan },
147
+ setAttributes (attributes) {
149
148
  vercelAiSpanSetAttributesChannel.publish({ ctx, attributes })
150
- return setAttributes.apply(this, arguments)
151
- }
152
- })
153
-
154
- shimmer.wrap(freshSpan, 'recordException', function (recordException) {
155
- return function (exception) {
149
+ span.setAttributes(attributes)
150
+ return freshSpan
151
+ },
152
+ addEvent (name, attributesOrStartTime, startTime) {
153
+ span.addEvent(name, attributesOrStartTime, startTime)
154
+ return freshSpan
155
+ },
156
+ addLink (link, attrs) { span.addLink(link, attrs); return freshSpan },
157
+ addLinks (links) { span.addLinks(links); return freshSpan },
158
+ setStatus (status) { span.setStatus(status); return freshSpan },
159
+ updateName (spanName) { span.updateName(spanName); return freshSpan },
160
+ isRecording () { return span.isRecording() },
161
+ recordException (exception, timeInput) {
156
162
  ctx.error = exception
157
163
  vercelAiTracingChannel.error.publish(ctx)
158
- return recordException.apply(this, arguments)
159
- }
160
- })
164
+ span.recordException(exception, timeInput)
165
+ },
166
+ end (...endArgs) {
167
+ vercelAiTracingChannel.asyncEnd.publish(ctx)
168
+ span.end(...endArgs)
169
+ },
170
+ }
161
171
 
162
172
  return originalCb.call(this, freshSpan)
163
173
  }
164
174
  })
165
175
 
166
176
  return vercelAiTracingChannel.start.runStores(ctx, () => {
167
- const result = startActiveSpan.apply(this, arguments)
177
+ const result = startActiveSpan.apply(this, args)
168
178
  vercelAiTracingChannel.end.publish(ctx)
169
179
  return result
170
180
  })
@@ -220,7 +230,7 @@ for (const hook of getHooks('ai')) {
220
230
  // generateObject, streamObject)
221
231
  tracingChannel('orchestrion:ai:resolveLanguageModel').subscribe({
222
232
  end (ctx) {
223
- wrapModelWithAIGuard(ctx.result)
233
+ wrapModelWithLifecycle(ctx.result)
224
234
  },
225
235
  })
226
236
 
@@ -228,4 +238,49 @@ for (const hook of getHooks('ai')) {
228
238
  })
229
239
  }
230
240
 
231
- module.exports = { wrapModelWithAIGuard }
241
+ const aiSdkTelemetryChannel = tracingChannel('ai:telemetry')
242
+ const aiSdkTelemetryStreamedChunkChannel = channel('dd-trace:vercel-ai:chunk')
243
+
244
+ // for testing, and possibly actual instrumentation use, we want to
245
+ // guard against double-subscribing to the asyncEnd channel of the
246
+ // vercel ai-provided tracingChannel
247
+ let subscribed = false
248
+
249
+ // as of the v7 release, the ai sdk does not automatically aggregate streamed responses
250
+ // we will handle emitting the chunks directly for products to handle
251
+ addHook({ name: 'ai', versions: ['>=7.0.0'] }, exports => {
252
+ if (subscribed) return exports
253
+ subscribed = true
254
+
255
+ // ai sdk v7 only supported on node.js 22+
256
+ // inlining this import here so we only import in those cases
257
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins
258
+ const { TransformStream } = require('node:stream/web')
259
+
260
+ aiSdkTelemetryChannel.subscribe({
261
+ asyncEnd (ctx) {
262
+ // guard against this event being re-emitted.
263
+ if (!ctx.isStream || !ctx.result?.stream || ctx.streamConsumed) return
264
+
265
+ const transform = new TransformStream({
266
+ transform (chunk, controller) {
267
+ const done = chunk.type === 'finish'
268
+
269
+ aiSdkTelemetryStreamedChunkChannel.publish({ ctx, chunk, done })
270
+
271
+ if (done) {
272
+ aiSdkTelemetryChannel.asyncEnd.publish(ctx)
273
+ }
274
+
275
+ controller.enqueue(chunk) // pass through value
276
+ },
277
+ })
278
+
279
+ ctx.result.stream = ctx.result.stream.pipeThrough(transform)
280
+ },
281
+ })
282
+
283
+ return exports
284
+ })
285
+
286
+ module.exports = { wrapModelWithLifecycle }
@@ -35,14 +35,13 @@ addHook({ name: 'amqplib', file: 'lib/defs.js', versions: [MIN_VERSION] }, defs
35
35
  addHook({ name: 'amqplib', file: 'lib/channel_model.js', versions: [MIN_VERSION] }, x => {
36
36
  shimmer.wrap(x.Channel.prototype, 'get', getMessage => function (queue, options) {
37
37
  return getMessage.apply(this, arguments).then(message => {
38
- if (message === null) {
39
- return message
38
+ if (message !== null) {
39
+ const ctx = { method: 'basic.get', message, fields: message.fields, queue }
40
+ consumeStartCh.runStores(ctx, () => {
41
+ // finish right away
42
+ consumeFinishCh.publish(ctx)
43
+ })
40
44
  }
41
- const ctx = { method: 'basic.get', message, fields: message.fields, queue }
42
- consumeStartCh.runStores(ctx, () => {
43
- // finish right away
44
- consumeFinishCh.publish(ctx)
45
- })
46
45
  return message
47
46
  })
48
47
  })