dd-trace 6.15.0 → 6.17.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 (378) hide show
  1. package/README.md +15 -0
  2. package/ci/diagnose.js +0 -23
  3. package/ci/test-optimization-validation/approval-artifacts.js +0 -3
  4. package/ci/test-optimization-validation/approval.js +0 -6
  5. package/ci/test-optimization-validation/artifact-id.js +0 -1
  6. package/ci/test-optimization-validation/bounded-json.js +0 -1
  7. package/ci/test-optimization-validation/cli.js +0 -12
  8. package/ci/test-optimization-validation/command-output-policy.js +0 -1
  9. package/ci/test-optimization-validation/command-runner.js +0 -3
  10. package/ci/test-optimization-validation/environment.js +0 -4
  11. package/ci/test-optimization-validation/executable-approval.js +0 -1
  12. package/ci/test-optimization-validation/executable.js +0 -5
  13. package/ci/test-optimization-validation/framework-adapters/cucumber.js +4 -8
  14. package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -3
  15. package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -6
  16. package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -4
  17. package/ci/test-optimization-validation/generated-test-contract.js +0 -5
  18. package/ci/test-optimization-validation/generated-verifier.js +0 -1
  19. package/ci/test-optimization-validation/literal-environment.js +0 -1
  20. package/ci/test-optimization-validation/manifest-scaffold.js +0 -17
  21. package/ci/test-optimization-validation/manifest-schema.js +0 -21
  22. package/ci/test-optimization-validation/offline-fixtures.js +0 -4
  23. package/ci/test-optimization-validation/package-check.js +4 -1
  24. package/ci/test-optimization-validation/plan-writer.js +0 -11
  25. package/ci/test-optimization-validation/preflight-runner.js +0 -1
  26. package/ci/test-optimization-validation/redaction.js +0 -4
  27. package/ci/test-optimization-validation/report-writer.js +0 -16
  28. package/ci/test-optimization-validation/runner-command.js +0 -3
  29. package/ci/test-optimization-validation/runner-contract.js +0 -4
  30. package/ci/test-optimization-validation/safe-files.js +0 -1
  31. package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -1
  32. package/ci/test-optimization-validation/scenarios/ci-wiring.js +1 -2
  33. package/ci/test-optimization-validation/source-text.js +0 -3
  34. package/ci/vitest-no-worker-init-setup.mjs +41 -16
  35. package/index.d.ts +169 -0
  36. package/next.d.ts +27 -0
  37. package/next.js +3 -0
  38. package/package.json +28 -23
  39. package/packages/datadog-esbuild/index.js +14 -1
  40. package/packages/datadog-esbuild/src/resolver.js +284 -0
  41. package/packages/datadog-esbuild/src/utils.js +162 -120
  42. package/packages/datadog-instrumentations/src/aerospike.js +28 -6
  43. package/packages/datadog-instrumentations/src/ai.js +39 -97
  44. package/packages/datadog-instrumentations/src/anthropic.js +76 -134
  45. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js.js +1 -3
  46. package/packages/datadog-instrumentations/src/aws-sdk.js +0 -2
  47. package/packages/datadog-instrumentations/src/azure-cosmos.js +1 -1
  48. package/packages/datadog-instrumentations/src/azure-durable-functions.js +23 -9
  49. package/packages/datadog-instrumentations/src/azure-functions.js +48 -0
  50. package/packages/datadog-instrumentations/src/bullmq.js +1 -1
  51. package/packages/datadog-instrumentations/src/claude-agent-sdk.js +1 -3
  52. package/packages/datadog-instrumentations/src/console.js +97 -0
  53. package/packages/datadog-instrumentations/src/cucumber.js +72 -12
  54. package/packages/datadog-instrumentations/src/cypress-config.js +0 -23
  55. package/packages/datadog-instrumentations/src/dd-trace-api.js +2 -2
  56. package/packages/datadog-instrumentations/src/graphql.js +1 -1
  57. package/packages/datadog-instrumentations/src/helpers/bundler-register.js +39 -14
  58. package/packages/datadog-instrumentations/src/helpers/channel.js +0 -2
  59. package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +0 -5
  60. package/packages/datadog-instrumentations/src/helpers/hooks.js +8 -0
  61. package/packages/datadog-instrumentations/src/helpers/instrument.js +25 -8
  62. package/packages/datadog-instrumentations/src/helpers/instrumentation-utils.js +69 -0
  63. package/packages/datadog-instrumentations/src/helpers/pool-acquire.js +0 -6
  64. package/packages/datadog-instrumentations/src/helpers/register.js +13 -64
  65. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +109 -29
  66. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +39 -0
  67. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/azure-durable-functions.js +17 -0
  68. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +3 -16
  69. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +12 -0
  70. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +36 -0
  71. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/supabase.js +128 -0
  72. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +6 -7
  73. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +17 -0
  74. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +388 -0
  75. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +99 -75
  76. package/packages/datadog-instrumentations/src/helpers/router-helper.js +0 -1
  77. package/packages/datadog-instrumentations/src/jest.js +141 -51
  78. package/packages/datadog-instrumentations/src/knex.js +0 -1
  79. package/packages/datadog-instrumentations/src/langchain.js +1 -1
  80. package/packages/datadog-instrumentations/src/langgraph.js +1 -1
  81. package/packages/datadog-instrumentations/src/mariadb-bundle.js +0 -24
  82. package/packages/datadog-instrumentations/src/mariadb.js +0 -2
  83. package/packages/datadog-instrumentations/src/mercurius.js +1 -1
  84. package/packages/datadog-instrumentations/src/mocha/common.js +0 -1
  85. package/packages/datadog-instrumentations/src/mocha/main.js +22 -25
  86. package/packages/datadog-instrumentations/src/mocha/utils.js +119 -49
  87. package/packages/datadog-instrumentations/src/mocha/webdriverio-protocol.js +0 -6
  88. package/packages/datadog-instrumentations/src/mocha/worker.js +14 -17
  89. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +1 -1
  90. package/packages/datadog-instrumentations/src/mysql2.js +0 -2
  91. package/packages/datadog-instrumentations/src/openai-agents.js +1 -1
  92. package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +241 -0
  93. package/packages/datadog-instrumentations/src/openai-realtime/events.js +76 -0
  94. package/packages/datadog-instrumentations/src/openai-realtime/index.js +301 -0
  95. package/packages/datadog-instrumentations/src/openai-realtime/session.js +998 -0
  96. package/packages/datadog-instrumentations/src/openai-realtime/turns.js +211 -0
  97. package/packages/datadog-instrumentations/src/openai.js +97 -80
  98. package/packages/datadog-instrumentations/src/oracledb.js +9 -3
  99. package/packages/datadog-instrumentations/src/playwright-reporter.js +3 -16
  100. package/packages/datadog-instrumentations/src/playwright.js +238 -55
  101. package/packages/datadog-instrumentations/src/postgres.js +7 -0
  102. package/packages/datadog-instrumentations/src/router.js +0 -2
  103. package/packages/datadog-instrumentations/src/rum-browser-scripts.js +0 -2
  104. package/packages/datadog-instrumentations/src/sequelize.js +0 -1
  105. package/packages/datadog-instrumentations/src/supabase.js +15 -0
  106. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +18 -18
  107. package/packages/datadog-instrumentations/src/vitest-main.js +37 -17
  108. package/packages/datadog-instrumentations/src/vitest-util.js +7 -1
  109. package/packages/datadog-instrumentations/src/vitest-worker.js +56 -23
  110. package/packages/datadog-instrumentations/src/webdriverio.js +23 -42
  111. package/packages/datadog-instrumentations/src/ws.js +0 -1
  112. package/packages/datadog-plugin-ai/src/utils.js +0 -2
  113. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/trace-checkpoint.js +0 -1
  114. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +0 -2
  115. package/packages/datadog-plugin-aws-sdk/src/base.js +0 -1
  116. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +7 -2
  117. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +0 -1
  118. package/packages/datadog-plugin-aws-sdk/src/util.js +0 -1
  119. package/packages/datadog-plugin-azure-cosmos/src/index.js +1 -1
  120. package/packages/datadog-plugin-azure-durable-functions/src/index.js +95 -1
  121. package/packages/datadog-plugin-cucumber/src/index.js +10 -0
  122. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +171 -75
  123. package/packages/datadog-plugin-cypress/src/finalization.js +0 -3
  124. package/packages/datadog-plugin-cypress/src/source-map-utils.js +0 -4
  125. package/packages/datadog-plugin-cypress/src/support.js +52 -7
  126. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -24
  127. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +2 -36
  128. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +31 -0
  129. package/packages/datadog-plugin-graphql/src/resolve-error.js +32 -11
  130. package/packages/datadog-plugin-graphql/src/utils.js +0 -5
  131. package/packages/datadog-plugin-jest/src/index.js +13 -0
  132. package/packages/datadog-plugin-kafkajs/src/producer.js +0 -1
  133. package/packages/datadog-plugin-mocha/src/index.js +39 -11
  134. package/packages/datadog-plugin-mongodb-core/src/query.js +0 -1
  135. package/packages/datadog-plugin-openai/src/index.js +16 -1
  136. package/packages/datadog-plugin-openai/src/realtime.js +144 -0
  137. package/packages/datadog-plugin-openai-agents/src/integration.js +0 -4
  138. package/packages/datadog-plugin-openai-agents/src/util.js +0 -1
  139. package/packages/datadog-plugin-playwright/src/index.js +76 -9
  140. package/packages/datadog-plugin-postgres/src/index.js +167 -0
  141. package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +0 -1
  142. package/packages/datadog-plugin-redis/src/index.js +15 -1
  143. package/packages/datadog-plugin-supabase/src/error.js +18 -0
  144. package/packages/datadog-plugin-supabase/src/index.js +21 -0
  145. package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +69 -0
  146. package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +70 -0
  147. package/packages/datadog-plugin-supabase/src/supabase-postgrest-js-postgrestbuilder-then.js +122 -0
  148. package/packages/datadog-plugin-supabase/src/supabase-realtime-js-realtimechannel-send.js +66 -0
  149. package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +93 -0
  150. package/packages/datadog-plugin-supabase/src/url.js +17 -0
  151. package/packages/datadog-plugin-vitest/src/index.js +10 -0
  152. package/packages/datadog-plugin-ws/src/util.js +0 -4
  153. package/packages/datadog-turbopack/index.js +206 -0
  154. package/packages/datadog-turbopack/src/constants.js +5 -0
  155. package/packages/datadog-turbopack/src/loader.js +484 -0
  156. package/packages/datadog-webpack/src/loader.js +0 -1
  157. package/packages/dd-trace/src/aiguard/client.js +2 -3
  158. package/packages/dd-trace/src/aiguard/evaluation.js +6 -12
  159. package/packages/dd-trace/src/aiguard/index.js +3 -2
  160. package/packages/dd-trace/src/aiguard/integrations/anthropic.js +53 -25
  161. package/packages/dd-trace/src/aiguard/integrations/evaluate.js +49 -25
  162. package/packages/dd-trace/src/aiguard/integrations/index.js +4 -3
  163. package/packages/dd-trace/src/aiguard/integrations/openai.js +132 -29
  164. package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +116 -42
  165. package/packages/dd-trace/src/aiguard/messages/anthropic.js +0 -2
  166. package/packages/dd-trace/src/aiguard/messages/openai.js +64 -1
  167. package/packages/dd-trace/src/aiguard/messages/utils.js +29 -2
  168. package/packages/dd-trace/src/aiguard/messages/vercel-ai.js +25 -0
  169. package/packages/dd-trace/src/aiguard/redaction.js +0 -1
  170. package/packages/dd-trace/src/aiguard/sdk.js +1 -1
  171. package/packages/dd-trace/src/appsec/activation.js +1 -1
  172. package/packages/dd-trace/src/appsec/api_security/normalized-route.js +0 -5
  173. package/packages/dd-trace/src/appsec/api_security/sampler.js +0 -4
  174. package/packages/dd-trace/src/appsec/blocking/index.js +3 -3
  175. package/packages/dd-trace/src/appsec/downstream_requests.js +1 -4
  176. package/packages/dd-trace/src/appsec/iast/index.js +1 -1
  177. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +5 -5
  178. package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +1 -1
  179. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +1 -1
  180. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +3 -3
  181. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/sql-sensitive-analyzer.js +8 -10
  182. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +2 -2
  183. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +2 -2
  184. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +4 -1
  185. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +7 -7
  186. package/packages/dd-trace/src/appsec/index.js +2 -2
  187. package/packages/dd-trace/src/appsec/lambda.js +71 -2
  188. package/packages/dd-trace/src/appsec/rasp/utils.js +5 -1
  189. package/packages/dd-trace/src/appsec/remote_config.js +8 -6
  190. package/packages/dd-trace/src/appsec/reporter.js +10 -6
  191. package/packages/dd-trace/src/appsec/rule_manager.js +3 -3
  192. package/packages/dd-trace/src/appsec/sdk/track_event.js +0 -2
  193. package/packages/dd-trace/src/appsec/telemetry/api_security.js +1 -3
  194. package/packages/dd-trace/src/appsec/telemetry/common.js +4 -0
  195. package/packages/dd-trace/src/appsec/telemetry/index.js +23 -5
  196. package/packages/dd-trace/src/appsec/telemetry/rasp.js +1 -20
  197. package/packages/dd-trace/src/appsec/telemetry/user.js +1 -3
  198. package/packages/dd-trace/src/appsec/telemetry/waf.js +1 -20
  199. package/packages/dd-trace/src/appsec/waf/index.js +2 -2
  200. package/packages/dd-trace/src/appsec/waf/waf_manager.js +8 -5
  201. package/packages/dd-trace/src/carrier.js +0 -5
  202. package/packages/dd-trace/src/ci-visibility/dynamic-atr-retries.js +104 -0
  203. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +0 -2
  204. package/packages/dd-trace/src/ci-visibility/efd-retry-policy.js +34 -3
  205. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +0 -1
  206. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +0 -1
  207. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +0 -1
  208. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -4
  209. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -1
  210. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -2
  211. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +37 -15
  212. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +0 -3
  213. package/packages/dd-trace/src/ci-visibility/exporters/request.js +0 -11
  214. package/packages/dd-trace/src/ci-visibility/exporters/settings-cache-key.js +0 -1
  215. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +0 -1
  216. package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +0 -6
  217. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +2 -2
  218. package/packages/dd-trace/src/ci-visibility/requests/rate-limit.js +0 -1
  219. package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +0 -5
  220. package/packages/dd-trace/src/ci-visibility/requests/video-request.js +0 -1
  221. package/packages/dd-trace/src/ci-visibility/telemetry.js +13 -0
  222. package/packages/dd-trace/src/ci-visibility/test-optimization-cache.js +0 -1
  223. package/packages/dd-trace/src/ci-visibility/test-screenshot.js +0 -2
  224. package/packages/dd-trace/src/ci-visibility/test-video.js +0 -1
  225. package/packages/dd-trace/src/config/defaults.js +3 -2
  226. package/packages/dd-trace/src/config/generated-config-types.d.ts +74 -66
  227. package/packages/dd-trace/src/config/helper.js +9 -2
  228. package/packages/dd-trace/src/config/index.js +44 -29
  229. package/packages/dd-trace/src/config/parsers.js +34 -6
  230. package/packages/dd-trace/src/config/remote_config.js +25 -109
  231. package/packages/dd-trace/src/config/supported-configurations.json +146 -9
  232. package/packages/dd-trace/src/datastreams/encoding.js +0 -1
  233. package/packages/dd-trace/src/datastreams/pathway.js +0 -1
  234. package/packages/dd-trace/src/debugger/constants.js +10 -0
  235. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +76 -17
  236. package/packages/dd-trace/src/debugger/devtools_client/config.js +2 -0
  237. package/packages/dd-trace/src/debugger/devtools_client/guardrail-metrics.js +15 -0
  238. package/packages/dd-trace/src/debugger/devtools_client/index.js +103 -27
  239. package/packages/dd-trace/src/debugger/devtools_client/json-buffer.js +50 -7
  240. package/packages/dd-trace/src/debugger/devtools_client/log.js +3 -1
  241. package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +34 -8
  242. package/packages/dd-trace/src/debugger/devtools_client/send.js +40 -14
  243. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +53 -13
  244. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +118 -71
  245. package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +0 -3
  246. package/packages/dd-trace/src/debugger/devtools_client/status.js +20 -6
  247. package/packages/dd-trace/src/debugger/guardrail-metrics.js +167 -0
  248. package/packages/dd-trace/src/debugger/index.js +50 -2
  249. package/packages/dd-trace/src/debugger/inspect-segment.js +0 -3
  250. package/packages/dd-trace/src/debugger/probe_sampler.js +133 -9
  251. package/packages/dd-trace/src/debugger/probe_sampler_constants.js +31 -1
  252. package/packages/dd-trace/src/dogstatsd.js +0 -23
  253. package/packages/dd-trace/src/encode/0.4-cross-payload.js +0 -3
  254. package/packages/dd-trace/src/encode/0.4.js +0 -7
  255. package/packages/dd-trace/src/encode/0.5.js +0 -2
  256. package/packages/dd-trace/src/encode/tags-processors.js +0 -1
  257. package/packages/dd-trace/src/evp_proxy/discovery.js +3 -5
  258. package/packages/dd-trace/src/evp_proxy/path.js +11 -4
  259. package/packages/dd-trace/src/exporters/agent/writer.js +0 -1
  260. package/packages/dd-trace/src/exporters/agentless/index.js +0 -1
  261. package/packages/dd-trace/src/exporters/agentless/intake.js +0 -1
  262. package/packages/dd-trace/src/exporters/agentless/writer.js +0 -3
  263. package/packages/dd-trace/src/exporters/common/docker.js +4 -1
  264. package/packages/dd-trace/src/exporters/common/final-flush-request-tracker.js +0 -6
  265. package/packages/dd-trace/src/exporters/common/proxy.js +3 -0
  266. package/packages/dd-trace/src/exporters/common/request.js +1 -0
  267. package/packages/dd-trace/src/exporters/common/url.js +0 -2
  268. package/packages/dd-trace/src/exporters/common/writer.js +0 -2
  269. package/packages/dd-trace/src/id.js +0 -11
  270. package/packages/dd-trace/src/llmobs/audio-codec.js +192 -0
  271. package/packages/dd-trace/src/llmobs/audio-utils.js +121 -0
  272. package/packages/dd-trace/src/llmobs/constants/audio.js +35 -0
  273. package/packages/dd-trace/src/llmobs/constants/prompts.js +14 -0
  274. package/packages/dd-trace/src/llmobs/constants/tags.js +17 -0
  275. package/packages/dd-trace/src/llmobs/eval-metric.js +0 -6
  276. package/packages/dd-trace/src/llmobs/experiments/dataset.js +0 -4
  277. package/packages/dd-trace/src/llmobs/experiments/experiment.js +0 -3
  278. package/packages/dd-trace/src/llmobs/experiments/index.js +7 -6
  279. package/packages/dd-trace/src/llmobs/experiments/util.js +1 -11
  280. package/packages/dd-trace/src/llmobs/index.js +1 -3
  281. package/packages/dd-trace/src/llmobs/noop.js +10 -0
  282. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +0 -4
  283. package/packages/dd-trace/src/llmobs/plugins/anthropic/util.js +0 -1
  284. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +0 -4
  285. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +0 -2
  286. package/packages/dd-trace/src/llmobs/plugins/openai/constants.js +0 -2
  287. package/packages/dd-trace/src/llmobs/plugins/openai/index.js +4 -6
  288. package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +285 -0
  289. package/packages/dd-trace/src/llmobs/plugins/openai/utils.js +16 -3
  290. package/packages/dd-trace/src/llmobs/prompts/cache.js +272 -0
  291. package/packages/dd-trace/src/llmobs/prompts/manager.js +639 -0
  292. package/packages/dd-trace/src/llmobs/prompts/noop.js +29 -0
  293. package/packages/dd-trace/src/llmobs/prompts/prompt.js +92 -0
  294. package/packages/dd-trace/src/llmobs/sdk.js +21 -6
  295. package/packages/dd-trace/src/llmobs/span_processor.js +81 -2
  296. package/packages/dd-trace/src/llmobs/tagger.js +30 -7
  297. package/packages/dd-trace/src/llmobs/telemetry.js +36 -4
  298. package/packages/dd-trace/src/llmobs/util.js +0 -34
  299. package/packages/dd-trace/src/llmobs/writers/base.js +0 -1
  300. package/packages/dd-trace/src/llmobs/writers/util.js +1 -2
  301. package/packages/dd-trace/src/log/channels.js +3 -0
  302. package/packages/dd-trace/src/log/index.js +23 -5
  303. package/packages/dd-trace/src/log-submission/log-submission-plugin.js +74 -6
  304. package/packages/dd-trace/src/msgpack/chunk.js +0 -1
  305. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +0 -12
  306. package/packages/dd-trace/src/openfeature/encoding.js +0 -2
  307. package/packages/dd-trace/src/openfeature/eval-metrics-hook.js +0 -1
  308. package/packages/dd-trace/src/openfeature/index.js +0 -4
  309. package/packages/dd-trace/src/openfeature/span-enrichment-hook.js +0 -1
  310. package/packages/dd-trace/src/openfeature/span-enrichment.js +0 -4
  311. package/packages/dd-trace/src/openfeature/writers/base.js +0 -6
  312. package/packages/dd-trace/src/openfeature/writers/exposures.js +0 -5
  313. package/packages/dd-trace/src/openfeature/writers/util.js +0 -4
  314. package/packages/dd-trace/src/opentelemetry/logs/logger.js +0 -1
  315. package/packages/dd-trace/src/opentelemetry/logs/logger_provider.js +0 -1
  316. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +0 -1
  317. package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +0 -2
  318. package/packages/dd-trace/src/opentelemetry/metrics/index.js +1 -1
  319. package/packages/dd-trace/src/opentelemetry/metrics/meter_provider.js +4 -4
  320. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js +0 -1
  321. package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +0 -1
  322. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +103 -35
  323. package/packages/dd-trace/src/opentelemetry/metrics/time.js +0 -1
  324. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +36 -13
  325. package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +0 -1
  326. package/packages/dd-trace/src/opentelemetry/span-helpers.js +0 -1
  327. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +0 -1
  328. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +0 -3
  329. package/packages/dd-trace/src/opentracing/propagation/text_map.js +0 -6
  330. package/packages/dd-trace/src/opentracing/span_context.js +0 -1
  331. package/packages/dd-trace/src/otel-thread-ctx.js +38 -11
  332. package/packages/dd-trace/src/payload-tagging/tagging.js +15 -3
  333. package/packages/dd-trace/src/plugin_manager.js +9 -3
  334. package/packages/dd-trace/src/plugins/ci_plugin.js +0 -1
  335. package/packages/dd-trace/src/plugins/database.js +2 -6
  336. package/packages/dd-trace/src/plugins/index.js +8 -0
  337. package/packages/dd-trace/src/plugins/plugin.js +0 -4
  338. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  339. package/packages/dd-trace/src/plugins/util/git.js +1 -3
  340. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +0 -1
  341. package/packages/dd-trace/src/plugins/util/llm.js +0 -2
  342. package/packages/dd-trace/src/plugins/util/status-validator.js +0 -1
  343. package/packages/dd-trace/src/plugins/util/test.js +25 -21
  344. package/packages/dd-trace/src/plugins/util/url.js +0 -5
  345. package/packages/dd-trace/src/priority_sampler.js +0 -6
  346. package/packages/dd-trace/src/process-tags/index.js +0 -1
  347. package/packages/dd-trace/src/profiler.js +132 -35
  348. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +0 -1
  349. package/packages/dd-trace/src/profiling/profiler.js +101 -41
  350. package/packages/dd-trace/src/profiling/ssi-heuristics.js +29 -15
  351. package/packages/dd-trace/src/propagation-hash/index.js +0 -1
  352. package/packages/dd-trace/src/proxy.js +21 -45
  353. package/packages/dd-trace/src/random_sampler.js +0 -4
  354. package/packages/dd-trace/src/rate_limiter.js +0 -4
  355. package/packages/dd-trace/src/remote_config/capabilities.js +1 -9
  356. package/packages/dd-trace/src/remote_config/index.js +0 -1
  357. package/packages/dd-trace/src/runtime_metrics/otlp_runtime_metrics.js +0 -3
  358. package/packages/dd-trace/src/sampler.js +0 -4
  359. package/packages/dd-trace/src/sampling_rule.js +0 -7
  360. package/packages/dd-trace/src/serverless/vercel.js +0 -1
  361. package/packages/dd-trace/src/serverless.js +0 -1
  362. package/packages/dd-trace/src/service-naming/index.js +0 -1
  363. package/packages/dd-trace/src/service-naming/schemas/util.js +0 -1
  364. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +7 -0
  365. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +5 -0
  366. package/packages/dd-trace/src/span_processor.js +2 -2
  367. package/packages/dd-trace/src/span_sampler.js +0 -1
  368. package/packages/dd-trace/src/standalone/product.js +2 -2
  369. package/packages/dd-trace/src/standalone/tracesource.js +0 -1
  370. package/packages/dd-trace/src/startup-log.js +1 -1
  371. package/packages/dd-trace/src/telemetry/endpoints.js +0 -8
  372. package/packages/dd-trace/src/telemetry/logs/index.js +16 -5
  373. package/packages/dd-trace/src/telemetry/logs/log-collector.js +16 -6
  374. package/packages/dd-trace/src/telemetry/metrics.js +0 -2
  375. package/packages/dd-trace/src/telemetry/telemetry.js +4 -1
  376. package/packages/dd-trace/src/util.js +13 -1
  377. package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
  378. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +0 -10
@@ -6,90 +6,30 @@ const { addHook } = require('./helpers/instrument')
6
6
 
7
7
  const anthropicTracingChannel = tracingChannel('apm:anthropic:request')
8
8
  const onStreamedChunkCh = channel('apm:anthropic:request:chunk')
9
- const messagesBeforeChannel = channel('dd-trace:anthropic:messages:before')
10
- const messagesAfterChannel = channel('dd-trace:anthropic:messages:after')
11
9
 
12
- /**
13
- * Publishes a provider-native lifecycle payload to a cancelable lifecycle channel.
14
- *
15
- * Subscribers push async work into `pending` synchronously during publication and
16
- * abort `abortController` with an error before the pushed promise resolves to block.
17
- *
18
- * @param {object} channel
19
- * @param {object} payload
20
- * @returns {Promise<void>}
21
- */
22
- function publishLifecycle (channel, payload) {
23
- const abortController = new AbortController()
24
- const ctx = { ...payload, abortController, pending: [] }
25
-
26
- channel.publish(ctx)
27
-
28
- return Promise.all(ctx.pending).then(() => {
29
- if (abortController.signal.aborted) {
30
- throw abortController.signal.reason
31
- }
32
- })
33
- }
10
+ // `prepare` is published before the SDK is invoked, so subscribers may replace `arguments[0]`.
11
+ // `intercept` follows with the native call data; a subscriber may set either callback and this
12
+ // instrumentation applies it, so the wrapping stays here and only the policy lives outside:
13
+ // beforeResult () => Promise<void>|undefined holds the result back until it settles
14
+ // onResult (body) => unknown|Promise<unknown> inspects or replaces the delivered body
15
+ const messagesPrepareChannel = channel('dd-trace:anthropic:messages:prepare')
16
+ const messagesInterceptChannel = channel('dd-trace:anthropic:messages:intercept')
34
17
 
35
18
  /**
19
+ * Returns `promise`, but not before `settled` settles, so a rejection from an interceptor
20
+ * reaches the caller instead of the SDK's value.
21
+ *
36
22
  * @template T
37
23
  * @param {Promise<T>} promise
38
- * @param {Promise<void>|undefined} verdict
24
+ * @param {Promise<void>|undefined} settled
39
25
  * @returns {Promise<T>}
40
26
  */
41
- function waitForVerdict (promise, verdict) {
42
- if (!verdict) return promise
27
+ function heldUntil (promise, settled) {
28
+ if (!settled) return promise
43
29
 
44
- // The lifecycle verdict takes precedence over an earlier SDK rejection.
30
+ // The interceptor's rejection wins over an earlier SDK rejection, so keep that one handled.
45
31
  promise.catch(() => {})
46
- return verdict.then(() => promise)
47
- }
48
-
49
- /**
50
- * @param {Array<unknown>} args
51
- * @returns {Array<unknown>|undefined}
52
- */
53
- function snapshotLifecycleArgs (args) {
54
- const options = args[0]
55
- if (!options || typeof options !== 'object') return
56
-
57
- const input = { messages: options.messages }
58
- if (options.system !== undefined) input.system = options.system
59
-
60
- // Snapshot via JSON so AI Guard evaluates exactly what the SDK serializes and sends, immune to
61
- // later caller mutation. If it can't serialize (e.g. circular), the SDK's own serialization would
62
- // fail too, so skipping evaluation is safe — nothing reaches the model.
63
- try {
64
- const snapshot = [...args]
65
- // eslint-disable-next-line unicorn/prefer-structured-clone
66
- snapshot[0] = { ...options, ...JSON.parse(JSON.stringify(input)) }
67
- return snapshot
68
- } catch {
69
- // Unserializable input — leave AI Guard inactive for this call (the SDK send would fail too).
70
- }
71
- }
72
-
73
- /**
74
- * Finishes after output evaluation so a block propagates to the caller and span.
75
- *
76
- * @param {object} ctx
77
- * @param {object} result
78
- * @param {(body: object) => Promise<void>|undefined} getVerdict
79
- * @param {object|string} [returnedResult]
80
- * @returns {object|string|Promise<object|string>}
81
- */
82
- function finishResult (ctx, result, getVerdict, returnedResult = result) {
83
- const verdict = getVerdict(result)
84
- if (!verdict) {
85
- finish(ctx, result)
86
- return returnedResult
87
- }
88
-
89
- return verdict.then(() => {
90
- finish(ctx, result)
91
- return returnedResult
92
- })
32
+ return settled.then(() => promise)
93
33
  }
94
34
 
95
35
  /**
@@ -106,22 +46,36 @@ function finishAndThrow (ctx, error) {
106
46
  * @param {object} response
107
47
  * @param {'json'|'text'} method
108
48
  * @param {object} ctx
109
- * @param {(body: object) => Promise<void>|undefined} getVerdict
49
+ * @param {object} [interceptCtx]
110
50
  */
111
- function wrapResponseReader (response, method, ctx, getVerdict) {
51
+ function wrapResponseReader (response, method, ctx, interceptCtx) {
112
52
  if (typeof response[method] !== 'function') return
113
53
 
114
54
  shimmer.wrap(response, method, original => function (...args) {
115
55
  return original.apply(this, args)
116
56
  .then(body => {
117
- if (method === 'json') return finishResult(ctx, body, getVerdict)
57
+ // `text()` callers keep their string; only the callback and the span see the parsed body.
58
+ let parsed = body
59
+ if (method === 'text') {
60
+ try {
61
+ parsed = JSON.parse(body)
62
+ } catch {
63
+ finish(ctx)
64
+ return body
65
+ }
66
+ }
118
67
 
119
- try {
120
- return finishResult(ctx, JSON.parse(body), getVerdict, body)
121
- } catch {
122
- finish(ctx)
68
+ if (!interceptCtx?.onResult) {
69
+ finish(ctx, parsed)
123
70
  return body
124
71
  }
72
+
73
+ return Promise.resolve(interceptCtx.onResult(parsed)).then(deliveredBody => {
74
+ finish(ctx, parsed)
75
+ // `json()` callers get any replacement; `text()` callers keep their original string,
76
+ // because the callback was handed the parsed object rather than the text.
77
+ return method === 'json' ? deliveredBody : body
78
+ })
125
79
  })
126
80
  .catch(error => finishAndThrow(ctx, error))
127
81
  })
@@ -130,17 +84,17 @@ function wrapResponseReader (response, method, ctx, getVerdict) {
130
84
  /**
131
85
  * @param {object} response
132
86
  * @param {object} ctx
133
- * @param {(body: object) => Promise<void>|undefined} getVerdict
87
+ * @param {object} [interceptCtx]
134
88
  */
135
- function wrapRawResponse (response, ctx, getVerdict) {
136
- wrapResponseReader(response, 'json', ctx, getVerdict)
137
- wrapResponseReader(response, 'text', ctx, getVerdict)
89
+ function wrapRawResponse (response, ctx, interceptCtx) {
90
+ wrapResponseReader(response, 'json', ctx, interceptCtx)
91
+ wrapResponseReader(response, 'text', ctx, interceptCtx)
138
92
 
139
93
  if (typeof response.clone !== 'function') return
140
94
 
141
95
  shimmer.wrap(response, 'clone', clone => function (...args) {
142
96
  const clonedResponse = clone.apply(this, args)
143
- wrapRawResponse(clonedResponse, ctx, getVerdict)
97
+ wrapRawResponse(clonedResponse, ctx, interceptCtx)
144
98
  return clonedResponse
145
99
  })
146
100
  }
@@ -172,68 +126,60 @@ function wrapStreamIterator (iterator, ctx) {
172
126
 
173
127
  function wrapCreate (create) {
174
128
  return function (...args) {
175
- const options = args[0]
176
- const stream = options?.stream
177
-
178
- // Streaming is out of scope for lifecycle evaluation.
179
- const lifecycleArgs = !stream &&
180
- (messagesBeforeChannel.hasSubscribers || messagesAfterChannel.hasSubscribers)
181
- ? snapshotLifecycleArgs(args)
182
- : undefined
129
+ const stream = args[0]?.stream
130
+ const preparing = !stream && messagesPrepareChannel.hasSubscribers
131
+ const intercepting = !stream && messagesInterceptChannel.hasSubscribers
183
132
 
184
- if (!anthropicTracingChannel.start.hasSubscribers && !lifecycleArgs) {
133
+ if (!anthropicTracingChannel.start.hasSubscribers && !preparing && !intercepting) {
185
134
  return create.apply(this, args)
186
135
  }
187
136
 
188
- const ctx = { options: lifecycleArgs?.[0] ?? options, resource: 'create', baseUrl: this._client?.baseURL }
137
+ // `args` is this wrapper's own rest array, so replacing `arguments[0]` changes what reaches
138
+ // the SDK without touching anything the caller still holds.
139
+ if (preparing) {
140
+ messagesPrepareChannel.publish({ arguments: args })
141
+ }
189
142
 
190
- return anthropicTracingChannel.start.runStores(ctx, () => {
191
- const parentSpan = lifecycleArgs ? ctx.currentStore?.span : undefined
143
+ const ctx = { options: args[0], resource: 'create', baseUrl: this._client?.baseURL }
192
144
 
145
+ return anthropicTracingChannel.start.runStores(ctx, () => {
193
146
  let apiPromise
194
147
  try {
195
- // Anthropic starts the request eagerly; the input verdict only gates result delivery.
196
- apiPromise = create.apply(this, lifecycleArgs ?? args)
148
+ // Anthropic starts the request eagerly, so subscribers can only hold back delivery.
149
+ apiPromise = create.apply(this, args)
197
150
  } catch (error) {
198
151
  finish(ctx, null, error)
199
152
  throw error
200
153
  }
201
154
 
202
- let beforeVerdict
203
- let afterVerdict
204
- let parseResult
205
- let wrappedResponse
206
-
207
- function getBeforeVerdict () {
208
- if (!lifecycleArgs || beforeVerdict) return beforeVerdict
209
- if (!messagesBeforeChannel.hasSubscribers) return
210
-
211
- beforeVerdict = publishLifecycle(messagesBeforeChannel, { args: lifecycleArgs, parentSpan })
212
- return beforeVerdict
155
+ let interceptCtx
156
+ if (intercepting) {
157
+ interceptCtx = { arguments: args, tracingContext: ctx }
158
+ messagesInterceptChannel.publish(interceptCtx)
213
159
  }
214
160
 
215
- /**
216
- * @param {object|string} body
217
- */
218
- function getAfterVerdict (body) {
219
- if (!lifecycleArgs || afterVerdict) return afterVerdict
220
- if (!messagesAfterChannel.hasSubscribers) return
221
-
222
- afterVerdict = publishLifecycle(messagesAfterChannel, { args: lifecycleArgs, body, parentSpan })
223
- return afterVerdict
224
- }
161
+ let parseResult
162
+ let wrappedResponse
225
163
 
226
164
  shimmer.wrap(apiPromise, 'parse', parse => function (...parseArgs) {
227
165
  if (parseResult) return parseResult
228
166
 
229
- const parsed = parse.apply(this, parseArgs)
230
- parseResult = waitForVerdict(parsed, getBeforeVerdict())
167
+ parseResult = heldUntil(parse.apply(this, parseArgs), interceptCtx?.beforeResult?.())
231
168
  .then(response => {
232
169
  if (stream) {
233
170
  shimmer.wrap(response, Symbol.asyncIterator, iterator => wrapStreamIterator(iterator, ctx))
234
171
  return response
235
172
  }
236
- return finishResult(ctx, response, getAfterVerdict)
173
+
174
+ if (!interceptCtx?.onResult) {
175
+ finish(ctx, response)
176
+ return response
177
+ }
178
+
179
+ return Promise.resolve(interceptCtx.onResult(response)).then(deliveredResponse => {
180
+ finish(ctx, response)
181
+ return deliveredResponse
182
+ })
237
183
  })
238
184
  .catch(error => finishAndThrow(ctx, error))
239
185
 
@@ -242,18 +188,14 @@ function wrapCreate (create) {
242
188
 
243
189
  if (typeof apiPromise.asResponse === 'function') {
244
190
  shimmer.wrap(apiPromise, 'asResponse', origAsResponse => function (...asResponseArgs) {
245
- return waitForVerdict(origAsResponse.apply(this, asResponseArgs), getBeforeVerdict())
191
+ return heldUntil(origAsResponse.apply(this, asResponseArgs), interceptCtx?.beforeResult?.())
246
192
  .then(response => {
247
- // Wrap the raw response's json()/text()/clone() readers to evaluate output on read,
248
- // but only while someone still consumes the result and not twice for the same response.
249
- const outputObserved = anthropicTracingChannel.start.hasSubscribers ||
250
- afterVerdict || messagesAfterChannel.hasSubscribers
251
- if (!stream && outputObserved && wrappedResponse !== response) {
193
+ // Wrap json()/text()/clone() so the span still closes on the raw-response path,
194
+ // and not twice for the same response.
195
+ if (!stream && wrappedResponse !== response) {
252
196
  wrappedResponse = response
253
- wrapRawResponse(response, ctx, getAfterVerdict)
197
+ wrapRawResponse(response, ctx, interceptCtx)
254
198
  }
255
-
256
- if (afterVerdict) return afterVerdict.then(() => response)
257
199
  return response
258
200
  })
259
201
  .catch(error => finishAndThrow(ctx, error))
@@ -70,7 +70,6 @@ const instrumentedProtos = new WeakSet()
70
70
  * observer attaches at most once (a promise settles only once). Instances we don't observe
71
71
  * never set `ON_SETTLE`, so for them the wrappers are a single property read and a passthrough.
72
72
  * @param {object} proto - The DurablePromise prototype (`Object.getPrototypeOf(dp)`).
73
- * @returns {void}
74
73
  */
75
74
  function instrumentDurablePromiseProto (proto) {
76
75
  if (instrumentedProtos.has(proto)) return
@@ -97,7 +96,6 @@ function instrumentDurablePromiseProto (proto) {
97
96
  * @param {object} dp - The returned DurablePromise instance.
98
97
  * @param {(err: unknown) => void} onSettle - Called once with `undefined` on success or the
99
98
  * rejection reason on failure.
100
- * @returns {void}
101
99
  */
102
100
  function observeDurablePromise (dp, onSettle) {
103
101
  if (!dp || typeof dp.then !== 'function') return
@@ -105,7 +103,7 @@ function observeDurablePromise (dp, onSettle) {
105
103
  dp[ON_SETTLE] = onSettle
106
104
  }
107
105
 
108
- for (const hook of getHooks('@aws/durable-execution-sdk-js')) {
106
+ for (const hook of getHooks('@aws/durable-execution-sdk-js').values()) {
109
107
  hook.file = null
110
108
  addHook(hook, exports => exports)
111
109
  }
@@ -77,7 +77,6 @@ const clientNameCache = new WeakMap()
77
77
 
78
78
  /**
79
79
  * @param {Function} clientCtor
80
- * @returns {string}
81
80
  */
82
81
  function getClientName (clientCtor) {
83
82
  let name = clientNameCache.get(clientCtor)
@@ -93,7 +92,6 @@ const operationCache = new WeakMap()
93
92
 
94
93
  /**
95
94
  * @param {Function} commandCtor
96
- * @returns {string}
97
95
  */
98
96
  function getOperationName (commandCtor) {
99
97
  let operation = operationCache.get(commandCtor)
@@ -2,6 +2,6 @@
2
2
 
3
3
  const { addHook, getHooks } = require('./helpers/instrument')
4
4
 
5
- for (const hook of getHooks('@azure/cosmos')) {
5
+ for (const hook of getHooks('@azure/cosmos').values()) {
6
6
  addHook(hook, exports => exports)
7
7
  }
@@ -5,6 +5,7 @@ const shimmer = require('../../datadog-shimmer')
5
5
 
6
6
  const {
7
7
  addHook,
8
+ getHooks,
8
9
  } = require('./helpers/instrument')
9
10
 
10
11
  /**
@@ -12,6 +13,10 @@ const {
12
13
  */
13
14
  const azureDurableFunctionsChannel = dc.tracingChannel('datadog:azure:durable-functions:invoke')
14
15
 
16
+ for (const hook of getHooks('durable-functions').values()) {
17
+ addHook(hook, exports => exports)
18
+ }
19
+
15
20
  addHook({ name: 'durable-functions', versions: ['>=3'], patchDefault: false }, (df) => {
16
21
  const { app } = df
17
22
 
@@ -42,9 +47,16 @@ function entityHandler (handler, entityName) {
42
47
  if (!azureDurableFunctionsChannel.hasSubscribers) return handler.apply(this, args)
43
48
 
44
49
  const entityContext = args[0]
50
+ const traceContext = entityContext?.traceContext
45
51
  return azureDurableFunctionsChannel.traceSync(
46
52
  handler,
47
- { trigger: 'Entity', functionName: entityName, operationName: entityContext?.df?.operationName },
53
+ {
54
+ trigger: 'Entity',
55
+ functionName: entityName,
56
+ operationName: entityContext?.df?.operationName,
57
+ traceparent: traceContext?.traceParent,
58
+ tracestate: traceContext?.traceState,
59
+ },
48
60
  this, ...args)
49
61
  }
50
62
  }
@@ -58,16 +70,18 @@ function activityHandler (method) {
58
70
  return function (...args) {
59
71
  if (!azureDurableFunctionsChannel.hasSubscribers) return handler.apply(this, args)
60
72
 
73
+ const traceContext = args[1]?.traceContext
74
+ const channelCtx = {
75
+ trigger: 'Activity',
76
+ functionName: activityName,
77
+ traceparent: traceContext?.traceParent,
78
+ tracestate: traceContext?.traceState,
79
+ }
80
+
61
81
  // use tracePromise if this is an async handler. otherwise, use traceSync
62
82
  return isAsync
63
- ? azureDurableFunctionsChannel.tracePromise(
64
- handler,
65
- { trigger: 'Activity', functionName: activityName },
66
- this, ...args)
67
- : azureDurableFunctionsChannel.traceSync(
68
- handler,
69
- { trigger: 'Activity', functionName: activityName },
70
- this, ...args)
83
+ ? azureDurableFunctionsChannel.tracePromise(handler, channelCtx, this, ...args)
84
+ : azureDurableFunctionsChannel.traceSync(handler, channelCtx, this, ...args)
71
85
  }
72
86
  })
73
87
  return method.apply(this, arguments)
@@ -8,6 +8,12 @@ const {
8
8
 
9
9
  const azureFunctionsChannel = dc.tracingChannel('datadog:azure:functions:invoke')
10
10
 
11
+ // Orchestrators register via app.generic; activities/entities use the durable-functions hook.
12
+ const azureDurableFunctionsChannel = dc.tracingChannel('datadog:azure:durable-functions:invoke')
13
+
14
+ const ORCHESTRATION_TRIGGER_TYPE = 'orchestrationTrigger'
15
+ const ORCHESTRATOR_COMPLETED_EVENT_TYPE = 13
16
+
11
17
  addHook({ name: '@azure/functions', versions: ['>=4'], patchDefault: false }, (azureFunction) => {
12
18
  const { app } = azureFunction
13
19
 
@@ -29,9 +35,51 @@ addHook({ name: '@azure/functions', versions: ['>=4'], patchDefault: false }, (a
29
35
  // CosmosDB triggers
30
36
  shimmer.wrap(app, 'cosmosDB', wrapHandler)
31
37
 
38
+ // Durable Functions orchestration triggers
39
+ shimmer.wrap(app, 'generic', wrapGeneric)
40
+
32
41
  return azureFunction
33
42
  })
34
43
 
44
+ function wrapGeneric (method) {
45
+ return function (name, options) {
46
+ if (options?.trigger?.type === ORCHESTRATION_TRIGGER_TYPE && typeof options.handler === 'function') {
47
+ options.handler = traceOrchestrationHandler(options.handler, name)
48
+ }
49
+ return method.apply(this, arguments)
50
+ }
51
+ }
52
+
53
+ function traceOrchestrationHandler (handler, functionName) {
54
+ return function (...args) {
55
+ if (!azureDurableFunctionsChannel.hasSubscribers) return handler.apply(this, args)
56
+
57
+ const orchestrationBinding = args[0]
58
+ // we do not want to trace if the orchestrator has already completed and is being reactivated
59
+ const history = orchestrationBinding?.history
60
+ const hasPreviousActivation = history?.some(
61
+ event => event.EventType === ORCHESTRATOR_COMPLETED_EVENT_TYPE
62
+ )
63
+
64
+ if (hasPreviousActivation) {
65
+ return handler.apply(this, args)
66
+ }
67
+
68
+ const traceContext = args[1]?.traceContext
69
+ const channelCtx = {
70
+ trigger: 'Orchestration',
71
+ functionName,
72
+ traceparent: traceContext?.traceParent,
73
+ tracestate: traceContext?.traceState,
74
+ }
75
+
76
+ return azureDurableFunctionsChannel.tracePromise(
77
+ handler,
78
+ channelCtx,
79
+ this, ...args)
80
+ }
81
+ }
82
+
35
83
  // The http methods are overloaded so we need to check which type of argument was passed in order to wrap the handler
36
84
  // The arguments are either an object with a handler property or the handler function itself
37
85
  function wrapHandler (method) {
@@ -6,6 +6,6 @@
6
6
 
7
7
  const { addHook, getHooks } = require('./helpers/instrument')
8
8
 
9
- for (const hook of getHooks('bullmq')) {
9
+ for (const hook of getHooks('bullmq').values()) {
10
10
  addHook(hook, exports => exports)
11
11
  }
@@ -353,7 +353,6 @@ function getToolResultContent (chunk, toolUseId) {
353
353
  * @param {SessionContext | null | undefined} sessionCtx
354
354
  * @param {GetLifecycle} getLifecycle
355
355
  * @param {ToolLifecycle} lifecycle
356
- * @returns {number} index in chunks where the next step should start iteration
357
356
  */
358
357
  function processTool (chunks, startIndex, toolUseId, sessionCtx, getLifecycle, lifecycle) {
359
358
  let chunkIndex = startIndex
@@ -412,7 +411,6 @@ function processTool (chunks, startIndex, toolUseId, sessionCtx, getLifecycle, l
412
411
  * @param {StepContext | null | undefined} stepCtx
413
412
  * @param {SessionContext | null | undefined} sessionCtx
414
413
  * @param {GetLifecycle} getLifecycle
415
- * @returns {number} index in chunks where the next step should start iteration
416
414
  */
417
415
  function processStep (
418
416
  chunks,
@@ -638,7 +636,7 @@ function wrapQueryAsyncIterator (asyncIterator, ctx) {
638
636
 
639
637
  let querySubscribed = false
640
638
 
641
- for (const hook of getHooks('@anthropic-ai/claude-agent-sdk')) {
639
+ for (const hook of getHooks('@anthropic-ai/claude-agent-sdk').values()) {
642
640
  hook.file = null
643
641
 
644
642
  addHook(hook, exports => {
@@ -0,0 +1,97 @@
1
+ 'use strict'
2
+
3
+ const shimmer = require('../../datadog-shimmer')
4
+ const { channel } = require('./helpers/instrument')
5
+
6
+ const configureCh = channel('ci:log-submission:console:configure')
7
+ const logSubmissionCh = channel('ci:log-submission:console')
8
+ const vitestSuiteStartCh = channel('ci:vitest:test-suite:start')
9
+ const methods = ['error', 'warn']
10
+ const methodSet = new Set(methods)
11
+ const wrappedTargets = new WeakSet()
12
+
13
+ let callDepth = 0
14
+ let configuredGetLogHolder
15
+ let isVitestConsoleSubscribed = false
16
+
17
+ /**
18
+ * @param {string} method
19
+ * @param {unknown[]} args
20
+ * @param {(() => { dd: object } | undefined) | undefined} getLogHolder
21
+ */
22
+ function publishLog (method, args, getLogHolder) {
23
+ if (!logSubmissionCh.hasSubscribers) return
24
+
25
+ try {
26
+ const logHolder = (getLogHolder || configuredGetLogHolder)?.()
27
+ if (logHolder) logSubmissionCh.publish({ args, logHolder, method })
28
+ } catch {}
29
+ }
30
+
31
+ /**
32
+ * @param {object} target
33
+ * @param {(() => { dd: object } | undefined) | undefined} [getLogHolder]
34
+ */
35
+ function wrapConsole (target, getLogHolder) {
36
+ if (!target || wrappedTargets.has(target)) return
37
+
38
+ wrappedTargets.add(target)
39
+ for (const method of methods) {
40
+ if (typeof target[method] !== 'function') continue
41
+
42
+ // Global console methods are bound at runtime, so source rewriting cannot intercept them.
43
+ try {
44
+ shimmer.wrap(target, method, original => function () {
45
+ const shouldPublish = callDepth++ === 0
46
+ try {
47
+ const result = original.apply(this, arguments)
48
+ if (shouldPublish) publishLog(method, [...arguments], getLogHolder)
49
+ return result
50
+ } finally {
51
+ callDepth--
52
+ }
53
+ })
54
+ } catch {}
55
+ }
56
+ }
57
+
58
+ /**
59
+ * @param {{ BufferedConsole?: Function, CustomConsole?: Function }} jestConsole
60
+ * @param {(() => { dd: object } | undefined) | undefined} [getLogHolder]
61
+ */
62
+ function wrapJestConsole (jestConsole, getLogHolder) {
63
+ if (!getLogHolder && !configuredGetLogHolder) return
64
+
65
+ const { BufferedConsole, CustomConsole } = jestConsole
66
+
67
+ if (BufferedConsole && !wrappedTargets.has(BufferedConsole)) {
68
+ wrappedTargets.add(BufferedConsole)
69
+ // Jest bundles and exports these adapter classes differently across versions, so wrap their runtime exports.
70
+ shimmer.wrap(BufferedConsole, 'write', original => function (buffer, method, message) {
71
+ const result = original.apply(this, arguments)
72
+ if (methodSet.has(method)) publishLog(method, [message], getLogHolder)
73
+ return result
74
+ })
75
+ }
76
+
77
+ if (CustomConsole && !wrappedTargets.has(CustomConsole)) {
78
+ wrappedTargets.add(CustomConsole)
79
+ shimmer.wrap(CustomConsole.prototype, '_logError', original => function (method, message) {
80
+ const result = original.apply(this, arguments)
81
+ if (methodSet.has(method)) publishLog(method, [message], getLogHolder)
82
+ return result
83
+ })
84
+ }
85
+ }
86
+
87
+ configureCh.subscribe(({ getLogHolder } = {}) => {
88
+ configuredGetLogHolder = getLogHolder
89
+ wrapConsole(globalThis.console)
90
+ if (!isVitestConsoleSubscribed) {
91
+ isVitestConsoleSubscribed = true
92
+ // Vitest replaces the global console after tracer startup and before the first suite starts.
93
+ vitestSuiteStartCh.subscribe(() => wrapConsole(globalThis.console))
94
+ }
95
+ })
96
+
97
+ module.exports = { wrapConsole, wrapJestConsole }