@depup/dd-trace 5.97.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 (633) 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 +315 -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 +118 -78
  13. package/packages/datadog-core/src/storage.js +47 -48
  14. package/packages/datadog-esbuild/index.js +32 -1
  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 +15 -15
  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 +49 -4
  40. package/packages/datadog-instrumentations/src/cucumber-worker-threads.js +19 -0
  41. package/packages/datadog-instrumentations/src/cucumber.js +747 -187
  42. package/packages/datadog-instrumentations/src/cypress-config.js +164 -56
  43. package/packages/datadog-instrumentations/src/cypress.js +5 -3
  44. package/packages/datadog-instrumentations/src/dns.js +60 -59
  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 +52 -30
  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 +22 -20
  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/callback-instrumentor.js +74 -0
  61. package/packages/datadog-instrumentations/src/helpers/check-require-cache.js +85 -9
  62. package/packages/datadog-instrumentations/src/helpers/hook.js +4 -1
  63. package/packages/datadog-instrumentations/src/helpers/hooks.js +12 -0
  64. package/packages/datadog-instrumentations/src/helpers/instrument.js +36 -3
  65. package/packages/datadog-instrumentations/src/helpers/kafka.js +58 -0
  66. package/packages/datadog-instrumentations/src/helpers/optional-peer-bundler.js +65 -0
  67. package/packages/datadog-instrumentations/src/helpers/promise-instrumentor.js +42 -0
  68. package/packages/datadog-instrumentations/src/helpers/promise.js +2 -2
  69. package/packages/datadog-instrumentations/src/helpers/register.js +7 -5
  70. package/packages/datadog-instrumentations/src/helpers/require-optional-peer.js +17 -0
  71. package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +13 -5
  72. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +24 -7
  73. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +6 -6
  74. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/aws-durable-execution-sdk-js.js +31 -0
  75. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/azure-cosmos.js +50 -0
  76. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/claude-agent-sdk.js +17 -0
  77. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +201 -0
  78. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +7 -0
  79. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/langgraph.js +4 -2
  80. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/mercurius.js +31 -0
  81. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-sdk.js +35 -0
  82. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +85 -0
  83. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +18 -2
  84. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +49 -224
  85. package/packages/datadog-instrumentations/src/helpers/router-helper.js +8 -8
  86. package/packages/datadog-instrumentations/src/hono.js +71 -9
  87. package/packages/datadog-instrumentations/src/http/client.js +48 -24
  88. package/packages/datadog-instrumentations/src/http/server.js +75 -29
  89. package/packages/datadog-instrumentations/src/http2/client.js +15 -12
  90. package/packages/datadog-instrumentations/src/http2/server.js +156 -23
  91. package/packages/datadog-instrumentations/src/ioredis.js +17 -14
  92. package/packages/datadog-instrumentations/src/iovalkey.js +1 -2
  93. package/packages/datadog-instrumentations/src/jest/bail-reporter.js +42 -0
  94. package/packages/datadog-instrumentations/src/jest/coverage-backfill.js +163 -0
  95. package/packages/datadog-instrumentations/src/jest.js +1783 -401
  96. package/packages/datadog-instrumentations/src/kafkajs.js +284 -170
  97. package/packages/datadog-instrumentations/src/knex.js +17 -17
  98. package/packages/datadog-instrumentations/src/koa.js +15 -14
  99. package/packages/datadog-instrumentations/src/ldapjs.js +5 -5
  100. package/packages/datadog-instrumentations/src/light-my-request.js +2 -2
  101. package/packages/datadog-instrumentations/src/limitd-client.js +4 -4
  102. package/packages/datadog-instrumentations/src/lodash.js +4 -4
  103. package/packages/datadog-instrumentations/src/mariadb.js +18 -16
  104. package/packages/datadog-instrumentations/src/memcached.js +4 -3
  105. package/packages/datadog-instrumentations/src/mercurius.js +11 -0
  106. package/packages/datadog-instrumentations/src/microgateway-core.js +2 -2
  107. package/packages/datadog-instrumentations/src/mocha/common.js +7 -4
  108. package/packages/datadog-instrumentations/src/mocha/main.js +557 -118
  109. package/packages/datadog-instrumentations/src/mocha/utils.js +531 -131
  110. package/packages/datadog-instrumentations/src/mocha/worker.js +27 -9
  111. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +254 -0
  112. package/packages/datadog-instrumentations/src/mongodb-core.js +43 -31
  113. package/packages/datadog-instrumentations/src/mongodb.js +79 -5
  114. package/packages/datadog-instrumentations/src/mongoose.js +43 -34
  115. package/packages/datadog-instrumentations/src/mquery.js +5 -5
  116. package/packages/datadog-instrumentations/src/multer.js +5 -4
  117. package/packages/datadog-instrumentations/src/mysql.js +17 -17
  118. package/packages/datadog-instrumentations/src/mysql2.js +39 -5
  119. package/packages/datadog-instrumentations/src/nats.js +182 -0
  120. package/packages/datadog-instrumentations/src/net.js +19 -11
  121. package/packages/datadog-instrumentations/src/next.js +44 -10
  122. package/packages/datadog-instrumentations/src/nyc.js +43 -6
  123. package/packages/datadog-instrumentations/src/openai.js +124 -38
  124. package/packages/datadog-instrumentations/src/oracledb.js +12 -7
  125. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +27 -6
  126. package/packages/datadog-instrumentations/src/passport-utils.js +5 -5
  127. package/packages/datadog-instrumentations/src/path-to-regexp.js +44 -0
  128. package/packages/datadog-instrumentations/src/pg.js +58 -25
  129. package/packages/datadog-instrumentations/src/pino.js +25 -41
  130. package/packages/datadog-instrumentations/src/playwright-browser-scripts.js +27 -0
  131. package/packages/datadog-instrumentations/src/playwright.js +1086 -350
  132. package/packages/datadog-instrumentations/src/protobufjs.js +16 -16
  133. package/packages/datadog-instrumentations/src/redis.js +28 -15
  134. package/packages/datadog-instrumentations/src/restify.js +6 -5
  135. package/packages/datadog-instrumentations/src/router.js +243 -87
  136. package/packages/datadog-instrumentations/src/selenium.js +1 -2
  137. package/packages/datadog-instrumentations/src/stripe.js +47 -33
  138. package/packages/datadog-instrumentations/src/tedious.js +28 -0
  139. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1297 -0
  140. package/packages/datadog-instrumentations/src/vitest-main.js +1592 -0
  141. package/packages/datadog-instrumentations/src/vitest-util.js +251 -0
  142. package/packages/datadog-instrumentations/src/vitest-worker.js +822 -0
  143. package/packages/datadog-instrumentations/src/vitest.js +11 -1262
  144. package/packages/datadog-instrumentations/src/winston.js +4 -4
  145. package/packages/datadog-instrumentations/src/ws.js +7 -7
  146. package/packages/datadog-instrumentations/src/zlib.js +29 -0
  147. package/packages/datadog-plugin-ai/src/index.js +1 -1
  148. package/packages/datadog-plugin-ai/src/tracing.js +66 -3
  149. package/packages/datadog-plugin-ai/src/utils.js +17 -4
  150. package/packages/datadog-plugin-apollo/src/gateway/request.js +1 -21
  151. package/packages/datadog-plugin-avsc/src/schema_iterator.js +3 -3
  152. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/checkpoint.js +31 -0
  153. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/client.js +55 -0
  154. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/context.js +123 -0
  155. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/handler.js +129 -0
  156. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/index.js +19 -0
  157. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/trace-checkpoint.js +224 -0
  158. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +79 -0
  159. package/packages/datadog-plugin-aws-sdk/src/base.js +86 -50
  160. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +1 -1
  161. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +218 -4
  162. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +1 -1
  163. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +2 -1
  164. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +59 -14
  165. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +174 -75
  166. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +34 -23
  167. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +2 -1
  168. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +1 -1
  169. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +26 -26
  170. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +187 -101
  171. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +20 -18
  172. package/packages/datadog-plugin-azure-cosmos/src/index.js +144 -0
  173. package/packages/datadog-plugin-azure-event-hubs/src/producer.js +8 -15
  174. package/packages/datadog-plugin-azure-functions/src/index.js +7 -3
  175. package/packages/datadog-plugin-azure-service-bus/src/producer.js +5 -10
  176. package/packages/datadog-plugin-bullmq/src/consumer.js +5 -4
  177. package/packages/datadog-plugin-bullmq/src/filter.js +35 -0
  178. package/packages/datadog-plugin-bullmq/src/producer.js +121 -33
  179. package/packages/datadog-plugin-bunyan/src/index.js +28 -0
  180. package/packages/datadog-plugin-child_process/src/index.js +13 -2
  181. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +6 -6
  182. package/packages/datadog-plugin-claude-agent-sdk/src/index.js +31 -0
  183. package/packages/datadog-plugin-claude-agent-sdk/src/tracing.js +107 -0
  184. package/packages/datadog-plugin-claude-agent-sdk/src/util.js +15 -0
  185. package/packages/datadog-plugin-couchbase/src/index.js +58 -52
  186. package/packages/datadog-plugin-cucumber/src/index.js +46 -28
  187. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +961 -92
  188. package/packages/datadog-plugin-cypress/src/index.js +104 -2
  189. package/packages/datadog-plugin-cypress/src/plugin.js +6 -14
  190. package/packages/datadog-plugin-cypress/src/source-map-utils.js +48 -1
  191. package/packages/datadog-plugin-cypress/src/support.js +180 -25
  192. package/packages/datadog-plugin-dd-trace-api/src/index.js +1 -1
  193. package/packages/datadog-plugin-dns/src/lookup.js +8 -6
  194. package/packages/datadog-plugin-elasticsearch/src/index.js +28 -8
  195. package/packages/datadog-plugin-electron/src/index.js +17 -0
  196. package/packages/datadog-plugin-electron/src/ipc.js +143 -0
  197. package/packages/datadog-plugin-electron/src/net.js +82 -0
  198. package/packages/datadog-plugin-express/src/code_origin.js +1 -1
  199. package/packages/datadog-plugin-fastify/src/code_origin.js +1 -1
  200. package/packages/datadog-plugin-fs/src/index.js +2 -1
  201. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -5
  202. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +27 -18
  203. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +5 -8
  204. package/packages/datadog-plugin-graphql/src/execute.js +706 -34
  205. package/packages/datadog-plugin-graphql/src/index.js +43 -9
  206. package/packages/datadog-plugin-graphql/src/parse.js +45 -4
  207. package/packages/datadog-plugin-graphql/src/request.js +135 -0
  208. package/packages/datadog-plugin-graphql/src/tools/signature.js +32 -7
  209. package/packages/datadog-plugin-graphql/src/tools/transforms.js +118 -100
  210. package/packages/datadog-plugin-graphql/src/utils.js +261 -3
  211. package/packages/datadog-plugin-graphql/src/validate.js +53 -7
  212. package/packages/datadog-plugin-grpc/src/client.js +7 -8
  213. package/packages/datadog-plugin-grpc/src/server.js +1 -1
  214. package/packages/datadog-plugin-grpc/src/util.js +57 -22
  215. package/packages/datadog-plugin-http/src/client.js +12 -14
  216. package/packages/datadog-plugin-http/src/index.js +6 -8
  217. package/packages/datadog-plugin-http/src/server.js +63 -20
  218. package/packages/datadog-plugin-http2/src/client.js +6 -3
  219. package/packages/datadog-plugin-http2/src/server.js +48 -8
  220. package/packages/datadog-plugin-jest/src/index.js +133 -67
  221. package/packages/datadog-plugin-jest/src/util.js +37 -16
  222. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +1 -1
  223. package/packages/datadog-plugin-kafkajs/src/consumer.js +2 -9
  224. package/packages/datadog-plugin-kafkajs/src/producer.js +37 -8
  225. package/packages/datadog-plugin-langgraph/src/stream.js +1 -1
  226. package/packages/datadog-plugin-memcached/src/index.js +1 -1
  227. package/packages/datadog-plugin-mocha/src/index.js +66 -20
  228. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/index.js +24 -0
  229. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +173 -0
  230. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +30 -0
  231. package/packages/datadog-plugin-mongodb-core/src/bulk-write.js +43 -0
  232. package/packages/datadog-plugin-mongodb-core/src/index.js +8 -206
  233. package/packages/datadog-plugin-mongodb-core/src/query.js +452 -0
  234. package/packages/datadog-plugin-mysql/src/index.js +9 -4
  235. package/packages/datadog-plugin-nats/src/consumer.js +43 -0
  236. package/packages/datadog-plugin-nats/src/index.js +20 -0
  237. package/packages/datadog-plugin-nats/src/producer.js +62 -0
  238. package/packages/datadog-plugin-nats/src/util.js +33 -0
  239. package/packages/datadog-plugin-next/src/index.js +12 -4
  240. package/packages/datadog-plugin-openai/src/services.js +4 -3
  241. package/packages/datadog-plugin-openai/src/tracing.js +27 -25
  242. package/packages/datadog-plugin-oracledb/src/index.js +13 -2
  243. package/packages/datadog-plugin-pg/src/index.js +13 -3
  244. package/packages/datadog-plugin-pino/src/index.js +42 -0
  245. package/packages/datadog-plugin-playwright/src/index.js +21 -11
  246. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +3 -3
  247. package/packages/datadog-plugin-redis/src/index.js +54 -25
  248. package/packages/datadog-plugin-rhea/src/producer.js +1 -1
  249. package/packages/datadog-plugin-router/src/index.js +46 -44
  250. package/packages/datadog-plugin-selenium/src/index.js +1 -1
  251. package/packages/datadog-plugin-tedious/src/index.js +1 -1
  252. package/packages/datadog-plugin-undici/src/index.js +24 -2
  253. package/packages/datadog-plugin-vitest/src/index.js +160 -90
  254. package/packages/datadog-plugin-winston/src/index.js +30 -0
  255. package/packages/datadog-plugin-ws/src/close.js +3 -1
  256. package/packages/datadog-plugin-ws/src/producer.js +2 -0
  257. package/packages/datadog-plugin-ws/src/receiver.js +2 -1
  258. package/packages/datadog-shimmer/src/shimmer.js +101 -39
  259. package/packages/datadog-webpack/index.js +17 -1
  260. package/packages/datadog-webpack/src/optional-peer-loader.js +17 -0
  261. package/packages/dd-trace/index.electron.js +3 -0
  262. package/packages/dd-trace/index.js +2 -36
  263. package/packages/dd-trace/src/aiguard/channels.js +7 -0
  264. package/packages/dd-trace/src/aiguard/index.js +16 -34
  265. package/packages/dd-trace/src/aiguard/integrations/evaluate.js +46 -0
  266. package/packages/dd-trace/src/aiguard/integrations/index.js +34 -0
  267. package/packages/dd-trace/src/aiguard/integrations/openai.js +80 -0
  268. package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +92 -0
  269. package/packages/dd-trace/src/aiguard/messages/openai.js +382 -0
  270. package/packages/{datadog-instrumentations/src/helpers/ai-messages.js → dd-trace/src/aiguard/messages/vercel-ai.js} +30 -27
  271. package/packages/dd-trace/src/aiguard/sdk.js +147 -54
  272. package/packages/dd-trace/src/aiguard/tags.js +26 -10
  273. package/packages/dd-trace/src/appsec/api_security/index.js +55 -0
  274. package/packages/dd-trace/src/appsec/api_security/sampler.js +147 -0
  275. package/packages/dd-trace/src/appsec/blocked_templates.js +4 -3
  276. package/packages/dd-trace/src/appsec/blocking.js +82 -42
  277. package/packages/dd-trace/src/appsec/channels.js +5 -1
  278. package/packages/dd-trace/src/appsec/downstream_requests.js +116 -62
  279. package/packages/dd-trace/src/appsec/graphql.js +20 -17
  280. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +1 -1
  281. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +81 -81
  282. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +23 -23
  283. package/packages/dd-trace/src/appsec/iast/index.js +3 -2
  284. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +4 -4
  285. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +2 -2
  286. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +4 -4
  287. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -2
  288. package/packages/dd-trace/src/appsec/iast/telemetry/index.js +2 -1
  289. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +54 -12
  290. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +5 -1
  291. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +31 -4
  292. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +1 -3
  293. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +83 -48
  294. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +1 -1
  295. package/packages/dd-trace/src/appsec/index.js +65 -47
  296. package/packages/dd-trace/src/appsec/lambda.js +135 -0
  297. package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -5
  298. package/packages/dd-trace/src/appsec/rasp/lfi.js +8 -4
  299. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +5 -10
  300. package/packages/dd-trace/src/appsec/rasp/ssrf.js +26 -18
  301. package/packages/dd-trace/src/appsec/recommended.json +2438 -13
  302. package/packages/dd-trace/src/appsec/reporter.js +87 -28
  303. package/packages/dd-trace/src/appsec/rule_manager.js +4 -2
  304. package/packages/dd-trace/src/appsec/sdk/set_user.js +1 -1
  305. package/packages/dd-trace/src/appsec/sdk/track_event.js +5 -5
  306. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +7 -11
  307. package/packages/dd-trace/src/appsec/sdk/utils.js +5 -3
  308. package/packages/dd-trace/src/appsec/store.js +50 -0
  309. package/packages/dd-trace/src/appsec/telemetry/api_security.js +34 -0
  310. package/packages/dd-trace/src/appsec/telemetry/index.js +27 -1
  311. package/packages/dd-trace/src/appsec/user_tracking.js +5 -4
  312. package/packages/dd-trace/src/appsec/waf/index.js +19 -9
  313. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +35 -20
  314. package/packages/dd-trace/src/appsec/waf/waf_manager.js +1 -1
  315. package/packages/dd-trace/src/azure_metadata.js +17 -6
  316. package/packages/dd-trace/src/baggage.js +32 -13
  317. package/packages/dd-trace/src/bootstrap.js +39 -0
  318. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +30 -5
  319. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +122 -24
  320. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +22 -7
  321. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +5 -2
  322. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +2 -2
  323. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +2 -2
  324. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +6 -2
  325. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -2
  326. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +148 -25
  327. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +3 -4
  328. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +28 -10
  329. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +22 -0
  330. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +105 -22
  331. package/packages/dd-trace/src/ci-visibility/lage.js +2 -1
  332. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +4 -5
  333. package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +4 -5
  334. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +73 -55
  335. package/packages/dd-trace/src/ci-visibility/requests/request.js +14 -50
  336. package/packages/dd-trace/src/ci-visibility/requests/upload-coverage-report.js +4 -4
  337. package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +156 -0
  338. package/packages/dd-trace/src/ci-visibility/test-api-manual/test-api-manual-plugin.js +5 -3
  339. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +24 -6
  340. package/packages/dd-trace/src/ci-visibility/test-optimization-cache.js +70 -6
  341. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +128 -0
  342. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +291 -0
  343. package/packages/dd-trace/src/config/config-types.d.ts +8 -6
  344. package/packages/dd-trace/src/config/defaults.js +71 -44
  345. package/packages/dd-trace/src/config/generated-config-types.d.ts +676 -131
  346. package/packages/dd-trace/src/config/git_properties.js +2 -2
  347. package/packages/dd-trace/src/config/helper.js +139 -33
  348. package/packages/dd-trace/src/config/index.js +117 -131
  349. package/packages/dd-trace/src/config/major-overrides.js +100 -0
  350. package/packages/dd-trace/src/config/normalize-service.js +31 -0
  351. package/packages/dd-trace/src/config/parsers.js +138 -10
  352. package/packages/dd-trace/src/config/remote_config.js +1 -1
  353. package/packages/dd-trace/src/config/supported-configurations.json +394 -203
  354. package/packages/dd-trace/src/constants.js +15 -0
  355. package/packages/dd-trace/src/crashtracking/crashtracker.js +18 -6
  356. package/packages/dd-trace/src/datastreams/checkpointer.js +6 -12
  357. package/packages/dd-trace/src/datastreams/context.js +4 -2
  358. package/packages/dd-trace/src/datastreams/encoding.js +39 -28
  359. package/packages/dd-trace/src/datastreams/index.js +2 -1
  360. package/packages/dd-trace/src/datastreams/manager.js +1 -1
  361. package/packages/dd-trace/src/datastreams/pathway.js +35 -30
  362. package/packages/dd-trace/src/datastreams/processor.js +31 -22
  363. package/packages/dd-trace/src/datastreams/size.js +6 -2
  364. package/packages/dd-trace/src/datastreams/writer.js +15 -6
  365. package/packages/dd-trace/src/debugger/config.js +9 -4
  366. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +49 -35
  367. package/packages/dd-trace/src/debugger/devtools_client/condition.js +5 -8
  368. package/packages/dd-trace/src/debugger/devtools_client/config.js +3 -2
  369. package/packages/dd-trace/src/debugger/devtools_client/index.js +33 -71
  370. package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +83 -0
  371. package/packages/dd-trace/src/debugger/devtools_client/send.js +27 -6
  372. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +2 -2
  373. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +5 -2
  374. package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +1 -0
  375. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +1 -1
  376. package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
  377. package/packages/dd-trace/src/debugger/index.js +13 -9
  378. package/packages/dd-trace/src/debugger/probe_sampler.js +112 -0
  379. package/packages/dd-trace/src/debugger/probe_sampler_constants.js +19 -0
  380. package/packages/dd-trace/src/dogstatsd.js +34 -28
  381. package/packages/dd-trace/src/encode/0.4.js +829 -268
  382. package/packages/dd-trace/src/encode/0.5.js +158 -22
  383. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +141 -65
  384. package/packages/dd-trace/src/encode/agentless-json.js +12 -6
  385. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +52 -15
  386. package/packages/dd-trace/src/encode/span-stats.js +19 -16
  387. package/packages/dd-trace/src/encode/tags-processors.js +30 -25
  388. package/packages/dd-trace/src/exporter.js +3 -1
  389. package/packages/dd-trace/src/exporters/agent/index.js +4 -5
  390. package/packages/dd-trace/src/exporters/agent/writer.js +1 -2
  391. package/packages/dd-trace/src/exporters/agentless/index.js +12 -13
  392. package/packages/dd-trace/src/exporters/agentless/intake.js +43 -0
  393. package/packages/dd-trace/src/exporters/agentless/writer.js +12 -11
  394. package/packages/dd-trace/src/exporters/common/agents.js +3 -1
  395. package/packages/dd-trace/src/exporters/common/buffering-exporter.js +3 -3
  396. package/packages/dd-trace/src/exporters/common/request.js +48 -28
  397. package/packages/dd-trace/src/exporters/common/retry.js +104 -0
  398. package/packages/dd-trace/src/exporters/common/url.js +34 -0
  399. package/packages/dd-trace/src/exporters/common/util.js +2 -2
  400. package/packages/dd-trace/src/exporters/common/writer.js +17 -1
  401. package/packages/dd-trace/src/exporters/electron/index.js +49 -0
  402. package/packages/dd-trace/src/exporters/span-stats/index.js +1 -2
  403. package/packages/dd-trace/src/exporters/span-stats/writer.js +1 -3
  404. package/packages/dd-trace/src/external-logger/src/index.js +2 -1
  405. package/packages/dd-trace/src/feature-registry.js +22 -0
  406. package/packages/dd-trace/src/git_metadata.js +68 -0
  407. package/packages/dd-trace/src/git_metadata_tagger.js +13 -5
  408. package/packages/dd-trace/src/guardrails/index.js +11 -6
  409. package/packages/dd-trace/src/guardrails/telemetry.js +40 -3
  410. package/packages/dd-trace/src/heap_snapshots.js +4 -4
  411. package/packages/dd-trace/src/id.js +46 -27
  412. package/packages/dd-trace/src/index.js +7 -8
  413. package/packages/dd-trace/src/lambda/handler-paths.js +52 -0
  414. package/packages/dd-trace/src/lambda/handler.js +2 -6
  415. package/packages/dd-trace/src/lambda/index.js +62 -14
  416. package/packages/dd-trace/src/lambda/runtime/patch.js +21 -46
  417. package/packages/dd-trace/src/llmobs/constants/tags.js +13 -0
  418. package/packages/dd-trace/src/llmobs/index.js +37 -7
  419. package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +403 -0
  420. package/packages/dd-trace/src/llmobs/plugins/ai/index.js +8 -395
  421. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +119 -7
  422. package/packages/dd-trace/src/llmobs/plugins/ai/vercelTelemetry.js +363 -0
  423. package/packages/dd-trace/src/llmobs/plugins/{anthropic.js → anthropic/index.js} +32 -79
  424. package/packages/dd-trace/src/llmobs/plugins/anthropic/util.js +109 -0
  425. package/packages/dd-trace/src/llmobs/plugins/base.js +4 -4
  426. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +89 -37
  427. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +270 -0
  428. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +10 -0
  429. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +5 -1
  430. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +81 -16
  431. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +3 -2
  432. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +3 -2
  433. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/embedding.js +2 -1
  434. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +1 -50
  435. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/vectorstore.js +2 -1
  436. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +14 -8
  437. package/packages/dd-trace/src/llmobs/plugins/langchain/messages.js +76 -0
  438. package/packages/dd-trace/src/llmobs/plugins/langgraph/index.js +3 -28
  439. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +68 -0
  440. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +57 -0
  441. package/packages/dd-trace/src/llmobs/plugins/openai/index.js +21 -51
  442. package/packages/dd-trace/src/llmobs/sdk.js +56 -35
  443. package/packages/dd-trace/src/llmobs/span_processor.js +90 -11
  444. package/packages/dd-trace/src/llmobs/tagger.js +129 -4
  445. package/packages/dd-trace/src/llmobs/telemetry.js +31 -1
  446. package/packages/dd-trace/src/llmobs/util.js +202 -9
  447. package/packages/dd-trace/src/llmobs/writers/base.js +11 -5
  448. package/packages/dd-trace/src/llmobs/writers/spans.js +1 -1
  449. package/packages/dd-trace/src/llmobs/writers/util.js +1 -2
  450. package/packages/dd-trace/src/log/index.js +19 -31
  451. package/packages/dd-trace/src/log/writer.js +3 -1
  452. package/packages/dd-trace/src/msgpack/chunk.js +430 -11
  453. package/packages/dd-trace/src/msgpack/index.js +101 -2
  454. package/packages/dd-trace/src/noop/proxy.js +5 -4
  455. package/packages/dd-trace/src/noop/span.js +3 -1
  456. package/packages/dd-trace/src/openfeature/encoding.js +70 -0
  457. package/packages/dd-trace/src/openfeature/eval-metrics-hook.js +103 -0
  458. package/packages/dd-trace/src/openfeature/flagging_provider.js +26 -1
  459. package/packages/dd-trace/src/openfeature/noop.js +40 -36
  460. package/packages/dd-trace/src/openfeature/register.js +46 -0
  461. package/packages/dd-trace/src/openfeature/remote_config.js +6 -1
  462. package/packages/dd-trace/src/openfeature/span-enrichment-hook.js +143 -0
  463. package/packages/dd-trace/src/openfeature/span-enrichment.js +149 -0
  464. package/packages/dd-trace/src/openfeature/writers/base.js +3 -11
  465. package/packages/dd-trace/src/openfeature/writers/exposures.js +82 -70
  466. package/packages/dd-trace/src/openfeature/writers/util.js +1 -2
  467. package/packages/dd-trace/src/opentelemetry/active-span-proxy.js +42 -0
  468. package/packages/dd-trace/src/opentelemetry/bridge-span-base.js +107 -0
  469. package/packages/dd-trace/src/opentelemetry/context_manager.js +27 -13
  470. package/packages/dd-trace/src/opentelemetry/logs/index.js +6 -6
  471. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +3 -2
  472. package/packages/dd-trace/src/opentelemetry/metrics/index.js +61 -12
  473. package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +28 -14
  474. package/packages/dd-trace/src/opentelemetry/metrics/meter.js +7 -10
  475. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +3 -2
  476. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +40 -0
  477. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js +169 -0
  478. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +99 -5
  479. package/packages/dd-trace/src/opentelemetry/metrics/time.js +19 -0
  480. package/packages/dd-trace/src/opentelemetry/otlp/common.proto +2 -2
  481. package/packages/dd-trace/src/opentelemetry/otlp/logs.proto +1 -1
  482. package/packages/dd-trace/src/opentelemetry/otlp/logs_service.proto +1 -1
  483. package/packages/dd-trace/src/opentelemetry/otlp/metrics.proto +1 -1
  484. package/packages/dd-trace/src/opentelemetry/otlp/metrics_service.proto +1 -1
  485. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +56 -82
  486. package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +1 -2
  487. package/packages/dd-trace/src/opentelemetry/otlp/protobuf_loader.js +14 -2
  488. package/packages/dd-trace/src/opentelemetry/otlp/trace.proto +358 -0
  489. package/packages/dd-trace/src/opentelemetry/otlp/trace_service.proto +78 -0
  490. package/packages/dd-trace/src/opentelemetry/span-helpers.js +325 -0
  491. package/packages/dd-trace/src/opentelemetry/span.js +59 -109
  492. package/packages/dd-trace/src/opentelemetry/span_context.js +1 -0
  493. package/packages/dd-trace/src/opentelemetry/span_processor.js +7 -5
  494. package/packages/dd-trace/src/opentelemetry/trace/index.js +75 -0
  495. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +75 -0
  496. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +375 -0
  497. package/packages/dd-trace/src/opentelemetry/tracer.js +20 -69
  498. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +33 -17
  499. package/packages/dd-trace/src/opentracing/propagation/log.js +28 -8
  500. package/packages/dd-trace/src/opentracing/propagation/text_map.js +278 -148
  501. package/packages/dd-trace/src/opentracing/propagation/text_map_dsm.js +11 -11
  502. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +98 -32
  503. package/packages/dd-trace/src/opentracing/span.js +127 -73
  504. package/packages/dd-trace/src/opentracing/span_context.js +68 -3
  505. package/packages/dd-trace/src/opentracing/tracer.js +46 -19
  506. package/packages/dd-trace/src/payload-tagging/config/index.js +2 -2
  507. package/packages/dd-trace/src/plugin_manager.js +36 -14
  508. package/packages/dd-trace/src/plugins/apollo.js +3 -1
  509. package/packages/dd-trace/src/plugins/ci_plugin.js +387 -85
  510. package/packages/dd-trace/src/plugins/database.js +61 -18
  511. package/packages/dd-trace/src/plugins/index.js +14 -0
  512. package/packages/dd-trace/src/plugins/log_injection.js +56 -0
  513. package/packages/dd-trace/src/plugins/log_plugin.js +4 -44
  514. package/packages/dd-trace/src/plugins/outbound.js +1 -1
  515. package/packages/dd-trace/src/plugins/plugin.js +19 -28
  516. package/packages/dd-trace/src/plugins/storage.js +2 -2
  517. package/packages/dd-trace/src/plugins/tracing.js +70 -13
  518. package/packages/dd-trace/src/plugins/util/ci.js +127 -40
  519. package/packages/dd-trace/src/plugins/util/git-cache.js +23 -23
  520. package/packages/dd-trace/src/plugins/util/git.js +3 -1
  521. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +276 -0
  522. package/packages/dd-trace/src/plugins/util/llm.js +6 -1
  523. package/packages/dd-trace/src/plugins/util/stacktrace.js +2 -2
  524. package/packages/dd-trace/src/plugins/util/test.js +894 -65
  525. package/packages/dd-trace/src/plugins/util/url.js +71 -5
  526. package/packages/dd-trace/src/plugins/util/user-provided-git.js +18 -16
  527. package/packages/dd-trace/src/plugins/util/web.js +116 -180
  528. package/packages/dd-trace/src/priority_sampler.js +12 -21
  529. package/packages/dd-trace/src/profiling/config.js +132 -212
  530. package/packages/dd-trace/src/profiling/constants.js +4 -7
  531. package/packages/dd-trace/src/profiling/exporter_cli.js +10 -10
  532. package/packages/dd-trace/src/profiling/exporters/agent.js +61 -28
  533. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +45 -14
  534. package/packages/dd-trace/src/profiling/exporters/file.js +16 -5
  535. package/packages/dd-trace/src/profiling/oom.js +71 -0
  536. package/packages/dd-trace/src/profiling/profiler.js +84 -105
  537. package/packages/dd-trace/src/profiling/profilers/event_plugins/crypto.js +32 -0
  538. package/packages/dd-trace/src/profiling/profilers/event_plugins/zlib.js +19 -0
  539. package/packages/dd-trace/src/profiling/profilers/events.js +57 -13
  540. package/packages/dd-trace/src/profiling/profilers/space.js +27 -16
  541. package/packages/dd-trace/src/profiling/profilers/wall.js +49 -35
  542. package/packages/dd-trace/src/profiling/ssi-heuristics.js +3 -3
  543. package/packages/dd-trace/src/propagation-hash/index.js +1 -1
  544. package/packages/dd-trace/src/proxy.js +50 -36
  545. package/packages/dd-trace/src/rate_limiter.js +1 -1
  546. package/packages/dd-trace/src/remote_config/index.js +6 -5
  547. package/packages/dd-trace/src/remote_config/scheduler.js +1 -1
  548. package/packages/dd-trace/src/ritm.js +6 -3
  549. package/packages/dd-trace/src/runtime_metrics/client.js +30 -0
  550. package/packages/dd-trace/src/runtime_metrics/index.js +14 -4
  551. package/packages/dd-trace/src/runtime_metrics/otlp_runtime_metrics.js +284 -0
  552. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +42 -41
  553. package/packages/dd-trace/src/sampling_rule.js +7 -7
  554. package/packages/dd-trace/src/scope.js +10 -15
  555. package/packages/dd-trace/src/serverless.js +6 -7
  556. package/packages/dd-trace/src/service-naming/extra-services.js +14 -0
  557. package/packages/dd-trace/src/service-naming/index.js +1 -1
  558. package/packages/dd-trace/src/service-naming/schemas/definition.js +4 -1
  559. package/packages/dd-trace/src/service-naming/schemas/util.js +48 -3
  560. package/packages/dd-trace/src/service-naming/schemas/v0/graphql.js +6 -0
  561. package/packages/dd-trace/src/service-naming/schemas/v0/messaging.js +61 -2
  562. package/packages/dd-trace/src/service-naming/schemas/v0/serverless.js +12 -0
  563. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +60 -0
  564. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +25 -1
  565. package/packages/dd-trace/src/service-naming/schemas/v0/websocket.js +5 -0
  566. package/packages/dd-trace/src/service-naming/schemas/v1/graphql.js +8 -0
  567. package/packages/dd-trace/src/service-naming/schemas/v1/messaging.js +32 -0
  568. package/packages/dd-trace/src/service-naming/schemas/v1/serverless.js +12 -0
  569. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +17 -0
  570. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +23 -3
  571. package/packages/dd-trace/src/service-naming/schemas/v1/websocket.js +6 -0
  572. package/packages/dd-trace/src/service-naming/source-resolver.js +50 -0
  573. package/packages/dd-trace/src/span_format.js +269 -81
  574. package/packages/dd-trace/src/span_processor.js +13 -13
  575. package/packages/dd-trace/src/span_stats.js +101 -79
  576. package/packages/dd-trace/src/spanleak.js +1 -2
  577. package/packages/dd-trace/src/standalone/index.js +3 -25
  578. package/packages/dd-trace/src/startup-log.js +3 -3
  579. package/packages/dd-trace/src/tagger.js +2 -4
  580. package/packages/dd-trace/src/telemetry/dependencies.js +2 -2
  581. package/packages/dd-trace/src/telemetry/endpoints.js +7 -5
  582. package/packages/dd-trace/src/telemetry/index.js +2 -2
  583. package/packages/dd-trace/src/telemetry/logs/index.js +1 -1
  584. package/packages/dd-trace/src/telemetry/send-data.js +20 -20
  585. package/packages/dd-trace/src/telemetry/session-propagation.js +1 -1
  586. package/packages/dd-trace/src/telemetry/telemetry.js +16 -14
  587. package/packages/dd-trace/src/tracer.js +23 -9
  588. package/packages/dd-trace/src/tracer_metadata.js +1 -1
  589. package/packages/dd-trace/src/util.js +31 -0
  590. package/register.js +58 -1
  591. package/vendor/dist/@apm-js-collab/code-transformer/index.js +94 -42
  592. package/vendor/dist/@datadog/sketches-js/LICENSE +10 -36
  593. package/vendor/dist/@datadog/sketches-js/index.js +1 -1
  594. package/vendor/dist/pprof-format/index.js +1 -1
  595. package/vendor/dist/protobufjs/index.js +1 -1
  596. package/vendor/dist/protobufjs/minimal/index.js +1 -1
  597. package/vendor/dist/shell-quote/index.js +1 -1
  598. package/packages/datadog-plugin-graphql/src/resolve.js +0 -178
  599. package/packages/dd-trace/src/agent/url.js +0 -28
  600. package/packages/dd-trace/src/appsec/api_security_sampler.js +0 -117
  601. package/packages/dd-trace/src/lambda/runtime/ritm.js +0 -133
  602. package/packages/dd-trace/src/log/utils.js +0 -16
  603. package/packages/dd-trace/src/msgpack/encoder.js +0 -308
  604. package/packages/dd-trace/src/plugins/structured_log_plugin.js +0 -9
  605. package/scripts/preinstall.js +0 -34
  606. package/vendor/dist/ignore/LICENSE +0 -21
  607. package/vendor/dist/ignore/index.js +0 -1
  608. package/vendor/dist/opentracing/LICENSE +0 -201
  609. package/vendor/dist/opentracing/binary_carrier.d.ts +0 -11
  610. package/vendor/dist/opentracing/constants.d.ts +0 -61
  611. package/vendor/dist/opentracing/examples/demo/demo.d.ts +0 -2
  612. package/vendor/dist/opentracing/ext/tags.d.ts +0 -90
  613. package/vendor/dist/opentracing/functions.d.ts +0 -20
  614. package/vendor/dist/opentracing/global_tracer.d.ts +0 -14
  615. package/vendor/dist/opentracing/index.d.ts +0 -12
  616. package/vendor/dist/opentracing/index.js +0 -1
  617. package/vendor/dist/opentracing/mock_tracer/index.d.ts +0 -5
  618. package/vendor/dist/opentracing/mock_tracer/mock_context.d.ts +0 -13
  619. package/vendor/dist/opentracing/mock_tracer/mock_report.d.ts +0 -16
  620. package/vendor/dist/opentracing/mock_tracer/mock_span.d.ts +0 -50
  621. package/vendor/dist/opentracing/mock_tracer/mock_tracer.d.ts +0 -26
  622. package/vendor/dist/opentracing/noop.d.ts +0 -8
  623. package/vendor/dist/opentracing/reference.d.ts +0 -33
  624. package/vendor/dist/opentracing/span.d.ts +0 -147
  625. package/vendor/dist/opentracing/span_context.d.ts +0 -26
  626. package/vendor/dist/opentracing/test/api_compatibility.d.ts +0 -16
  627. package/vendor/dist/opentracing/test/mocktracer_implemenation.d.ts +0 -3
  628. package/vendor/dist/opentracing/test/noop_implementation.d.ts +0 -4
  629. package/vendor/dist/opentracing/test/opentracing_api.d.ts +0 -3
  630. package/vendor/dist/opentracing/test/unittest.d.ts +0 -2
  631. package/vendor/dist/opentracing/tracer.d.ts +0 -127
  632. package/vendor/dist/path-to-regexp/LICENSE +0 -21
  633. 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
@@ -8,6 +8,11 @@ const { pathToFileURL, fileURLToPath } = require('node:url')
8
8
  const instrumentations = require('../datadog-instrumentations/src/helpers/instrumentations')
9
9
  const extractPackageAndModulePath = require('../datadog-instrumentations/src/helpers/extract-package-and-module-path')
10
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')
11
16
  const { processModule, isESMFile } = require('./src/utils')
12
17
  const log = require('./src/log')
13
18
 
@@ -128,6 +133,11 @@ module.exports.setup = function (build) {
128
133
  ${build.initialOptions.banner.js}`
129
134
  }
130
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.
131
141
  try {
132
142
  // eslint-disable-next-line n/no-unpublished-require
133
143
  require.resolve('@openfeature/core')
@@ -172,6 +182,22 @@ ${build.initialOptions.banner.js}`
172
182
  log.warn('No git metadata available - skipping injection')
173
183
  }
174
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
+
175
201
  // first time is intercepted, proxy should be created, next time the original should be loaded
176
202
  const interceptedESMModules = new Set()
177
203
 
@@ -347,10 +373,15 @@ register(${JSON.stringify(toRegister)}, _, set, get, ${JSON.stringify(data.raw)}
347
373
  }
348
374
  } else {
349
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.
350
381
  contents = `
351
382
  (function() {
352
383
  ${fileCode}
353
- })(...arguments);
384
+ })(module.exports, module);
354
385
  {
355
386
  const dc = require('dc-polyfill');
356
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
  })
@@ -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))