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
@@ -0,0 +1,144 @@
1
+ 'use strict'
2
+
3
+ const { MEASURED } = require('../../../ext/tags')
4
+ const { ERROR_MESSAGE, ERROR_TYPE } = require('../../dd-trace/src/constants')
5
+ const { storage } = require('../../datadog-core')
6
+ const TracingPlugin = require('../../dd-trace/src/plugins/tracing')
7
+
8
+ /**
9
+ * APM spans for the phases of one OpenAI Realtime turn.
10
+ *
11
+ * The turn is replayed as a back-dated tree once it is complete, so every span here is created with
12
+ * an explicit `startTime` and finished with an explicit `finishTime` rather than measuring wall
13
+ * clock. Nesting falls out of the synchronous scoping of the instrumentation's `traceSync` calls:
14
+ * the phase spans are created inside the turn root's callback, so `startSpan` picks the root up as
15
+ * their parent from the active store.
16
+ */
17
+ class RealtimeTracingPlugin extends TracingPlugin {
18
+ // `component` defaults to the plugin id, which differs per phase here, so pin both explicitly to
19
+ // keep `component:openai` consistent with every other span the integration emits.
20
+ static component = 'openai'
21
+ static system = 'openai'
22
+
23
+ /**
24
+ * Whether a failed response marks this span errored. True for the model's own work and for the
25
+ * turn as a whole; false for the speaking windows, which describe when audio moved rather than
26
+ * whether the model succeeded.
27
+ */
28
+ static flagsFailure = true
29
+
30
+ /**
31
+ * The APM resource name for this phase. Implemented by every subclass.
32
+ *
33
+ * @param {object} ctx
34
+ * @throws {Error} When a subclass has not implemented it.
35
+ */
36
+ resource (ctx) {
37
+ throw new Error(`resource must be implemented by ${this.constructor.name}`)
38
+ }
39
+
40
+ /**
41
+ * @param {object} ctx
42
+ * @returns {object}
43
+ */
44
+ bindStart (ctx) {
45
+ this.startSpan('openai.request', {
46
+ service: this.config.service,
47
+ resource: this.resource(ctx),
48
+ type: 'openai',
49
+ kind: 'client',
50
+ meta: {
51
+ [MEASURED]: 1,
52
+ 'openai.request.model': ctx.turn.model,
53
+ },
54
+ startTime: ctx.startTime,
55
+ }, ctx)
56
+
57
+ return ctx.currentStore
58
+ }
59
+
60
+ /**
61
+ * @param {object} ctx
62
+ */
63
+ end (ctx) {
64
+ const span = ctx.currentStore?.span
65
+ if (span === undefined) return
66
+
67
+ if (ctx.turn.failed && this.constructor.flagsFailure) {
68
+ span.setTag('error', 1)
69
+
70
+ // The provider's own account of the failure, when `response.done` carried one. Without it the
71
+ // span says only that a realtime call broke. The LLM Observability error event reads these
72
+ // same tags, so setting them here serves both.
73
+ const { error } = ctx.turn
74
+ if (error !== undefined) {
75
+ if (error.type !== undefined) span.setTag(ERROR_TYPE, error.type)
76
+ const message = error.message ?? error.code
77
+ if (message !== undefined) span.setTag(ERROR_MESSAGE, message)
78
+ }
79
+ }
80
+ span.finish(ctx.finishTime)
81
+ }
82
+ }
83
+
84
+ /** The whole perceived turn, and the root of this turn's trace. */
85
+ class RealtimeTurnTracingPlugin extends RealtimeTracingPlugin {
86
+ static id = 'openai_realtime_turn'
87
+ static operation = 'turn'
88
+ static prefix = 'tracing:apm:openai:realtime:turn'
89
+
90
+ constructor (...args) {
91
+ super(...args)
92
+
93
+ // Captured at `response.created`, replayed at finalize: by then the active context belongs to
94
+ // the WebSocket message handler, not to the caller who opened the connection. The LLM
95
+ // Observability plugin composes its own store on top of whatever this sets.
96
+ this.addSub('dd-trace:openai:realtime:capture-context', turn => {
97
+ const store = storage('legacy').getStore()
98
+ const previous = turn.runInContext
99
+ turn.runInContext = previous === undefined
100
+ ? fn => storage('legacy').run(store, fn)
101
+ : fn => previous(() => storage('legacy').run(store, fn))
102
+ })
103
+ }
104
+
105
+ resource () {
106
+ return 'createRealtimeTurn'
107
+ }
108
+ }
109
+
110
+ /** The model's generation work: opens at the end of user speech, closes at `response.done`. */
111
+ class RealtimeResponseTracingPlugin extends RealtimeTracingPlugin {
112
+ static id = 'openai_realtime_response'
113
+ static operation = 'response'
114
+ static prefix = 'tracing:apm:openai:realtime:response'
115
+
116
+ resource () {
117
+ return 'createRealtimeResponse'
118
+ }
119
+ }
120
+
121
+ /**
122
+ * A speaking window — the human's or the agent's. One plugin covers both: they differ only by
123
+ * resource and name, which is data, not a type.
124
+ */
125
+ class RealtimeSpeechTracingPlugin extends RealtimeTracingPlugin {
126
+ static id = 'openai_realtime_speech'
127
+ static operation = 'speech'
128
+ static prefix = 'tracing:apm:openai:realtime:speech'
129
+ // A speaking window happened regardless of whether the model's response failed.
130
+ static flagsFailure = false
131
+
132
+ /**
133
+ * @param {{ phase: { operation: string } }} ctx
134
+ */
135
+ resource (ctx) {
136
+ return ctx.phase.operation
137
+ }
138
+ }
139
+
140
+ module.exports = [
141
+ RealtimeTurnTracingPlugin,
142
+ RealtimeResponseTracingPlugin,
143
+ RealtimeSpeechTracingPlugin,
144
+ ]
@@ -578,7 +578,6 @@ class OpenAIAgentsIntegration {
578
578
  *
579
579
  * @param {string | undefined | null} spanId agents-core spanId to start from
580
580
  * @param {string} ancestorId agents-core ancestor spanId
581
- * @returns {boolean}
582
581
  */
583
582
  #hasUntracedPathToAncestor (spanId, ancestorId) {
584
583
  let currentId = spanId
@@ -596,7 +595,6 @@ class OpenAIAgentsIntegration {
596
595
  * mistaken for top-level, or an error would finalize the workflow span early.
597
596
  *
598
597
  * @param {object} oaiSpan
599
- * @returns {boolean}
600
598
  */
601
599
  #isTopLevelSpan (oaiSpan) {
602
600
  let currentId = oaiSpan.parentId
@@ -681,7 +679,6 @@ class OpenAIAgentsIntegration {
681
679
  * Read the mutable tracer configuration so remote/runtime enablement is
682
680
  * reflected without reconstructing the plugin.
683
681
  *
684
- * @returns {boolean}
685
682
  */
686
683
  #isLLMObsEnabled () {
687
684
  return this.#llmobsEnabled && !!this.#config.llmobs?.DD_LLMOBS_ENABLED
@@ -690,7 +687,6 @@ class OpenAIAgentsIntegration {
690
687
  /**
691
688
  * Resolve model provider from the model invocation's async-local context.
692
689
  *
693
- * @returns {string}
694
690
  */
695
691
  #getCurrentModelProvider () {
696
692
  const baseURL = legacyStorage.getStore()?.[MODEL_BASE_URL_STORE_KEY]
@@ -14,7 +14,6 @@ const AGENTS_ERROR_TYPE = 'AgentsCoreError'
14
14
  * missing).
15
15
  *
16
16
  * @param {object} oaiSpan
17
- * @returns {string}
18
17
  */
19
18
  function deriveSpanName (oaiSpan) {
20
19
  const spanData = oaiSpan.spanData
@@ -56,6 +56,7 @@ const {
56
56
  TEST_HAS_DYNAMIC_NAME,
57
57
  DYNAMIC_NAME_RE,
58
58
  TEST_FINAL_STATUS,
59
+ setExpectedEmptyTestSessionTags,
59
60
  } = require('../../dd-trace/src/plugins/util/test')
60
61
  const { RESOURCE_NAME } = require('../../../ext/tags')
61
62
  const { COMPONENT } = require('../../dd-trace/src/constants')
@@ -69,13 +70,16 @@ const log = require('../../dd-trace/src/log')
69
70
 
70
71
  const PLAYWRIGHT_FAILURE_SCREENSHOT_RE = /^test-failed-\d+\.png$/
71
72
  const PLAYWRIGHT_VIDEO_CONTENT_TYPES = new Set(['video/mp4', 'video/webm'])
73
+ const EMPTY_SHARD_SKIP_REASON = 'No tests were assigned to this shard'
74
+ const EMPTY_SHARD_REASON = 'zero_test_shard'
75
+ const RETRY_TEST_ID = '_dd.playwright.retry_test_id'
76
+ const DEFER_FINAL_STATUS = '_dd.playwright.defer_final_status'
72
77
  const noop = () => {}
73
78
 
74
79
  /**
75
80
  * Returns whether an attachment is an automatic Playwright failure screenshot.
76
81
  *
77
82
  * @param {object} attachment - Playwright test attachment
78
- * @returns {boolean}
79
83
  */
80
84
  function isPlaywrightFailureScreenshot (attachment) {
81
85
  return attachment?.name === 'screenshot' &&
@@ -88,7 +92,6 @@ function isPlaywrightFailureScreenshot (attachment) {
88
92
  * Returns whether an attachment is a Playwright test video.
89
93
  *
90
94
  * @param {object} attachment - Playwright test attachment
91
- * @returns {boolean}
92
95
  */
93
96
  function isPlaywrightFailureVideo (attachment) {
94
97
  return attachment?.name === 'video' &&
@@ -102,6 +105,7 @@ class PlaywrightPlugin extends CiPlugin {
102
105
  #isFinalizingAfterError = false
103
106
  #finishPendingTestFinishes
104
107
  #pendingTestFinishCallbacks = new Map()
108
+ #pendingRetryTestFinishes = new Map()
105
109
 
106
110
  constructor (...args) {
107
111
  super(...args)
@@ -182,9 +186,13 @@ class PlaywrightPlugin extends CiPlugin {
182
186
  isEarlyFlakeDetectionEnabled,
183
187
  isEarlyFlakeDetectionFaulty,
184
188
  isTestManagementTestsEnabled,
189
+ isExpectedEmptyShard,
185
190
  error,
186
191
  onDone,
187
192
  }) => {
193
+ for (const finish of this.#pendingRetryTestFinishes.values()) finish(true)
194
+ this.#pendingRetryTestFinishes.clear()
195
+
188
196
  if (error) {
189
197
  this.#isFinalizingAfterError = true
190
198
  for (const testSuiteSpan of this._testSuiteSpansByTestSuiteAbsolutePath.values()) {
@@ -204,6 +212,15 @@ class PlaywrightPlugin extends CiPlugin {
204
212
  this.testModuleSpan.setTag(TEST_STATUS, status)
205
213
  this.testSessionSpan.setTag(TEST_STATUS, status)
206
214
 
215
+ if (isExpectedEmptyShard) {
216
+ setExpectedEmptyTestSessionTags(
217
+ this.testSessionSpan,
218
+ this.testModuleSpan,
219
+ EMPTY_SHARD_SKIP_REASON,
220
+ EMPTY_SHARD_REASON
221
+ )
222
+ }
223
+
207
224
  if (isEarlyFlakeDetectionEnabled) {
208
225
  this.testSessionSpan.setTag(TEST_EARLY_FLAKE_ENABLED, 'true')
209
226
  }
@@ -372,12 +389,37 @@ class PlaywrightPlugin extends CiPlugin {
372
389
  formattedTraces.push(formattedTrace)
373
390
  }
374
391
 
392
+ const retryTestId = formattedTestSpan?.meta[RETRY_TEST_ID]
393
+ const deferFinalStatus = formattedTestSpan?.meta[DEFER_FINAL_STATUS] === 'true'
394
+ if (retryTestId !== undefined) {
395
+ delete formattedTestSpan.meta[RETRY_TEST_ID]
396
+ delete formattedTestSpan.meta[DEFER_FINAL_STATUS]
397
+ }
398
+ let readyToExport = false
399
+ let isFinalExecution
375
400
  const exportTraces = () => {
401
+ readyToExport = true
402
+ if (deferFinalStatus && isFinalExecution === undefined) return
376
403
  for (const trace of formattedTraces) {
377
404
  this.tracer._exporter.export(trace)
378
405
  }
379
406
  }
380
407
 
408
+ if (retryTestId !== undefined) {
409
+ // Keep at most one execution while another attempt is possible. Media uploads
410
+ // can finish before or after finality is known, so track readiness separately.
411
+ const finishPrevious = this.#pendingRetryTestFinishes.get(retryTestId)
412
+ finishPrevious?.(false)
413
+ this.#pendingRetryTestFinishes.delete(retryTestId)
414
+ if (deferFinalStatus) {
415
+ this.#pendingRetryTestFinishes.set(retryTestId, (isFinal) => {
416
+ isFinalExecution = isFinal
417
+ if (!isFinal) delete formattedTestSpan.meta[TEST_FINAL_STATUS]
418
+ if (readyToExport) exportTraces()
419
+ })
420
+ }
421
+ }
422
+
381
423
  if (!formattedTestSpan || (!screenshots && !videos) || this.#isFinalizingAfterError) {
382
424
  exportTraces()
383
425
  return
@@ -501,6 +543,8 @@ class PlaywrightPlugin extends CiPlugin {
501
543
  isAtrRetry,
502
544
  isModified,
503
545
  finalStatus,
546
+ retryTestId,
547
+ deferFinalStatus,
504
548
  earlyFlakeAbortReason,
505
549
  onDone,
506
550
  }) => {
@@ -510,6 +554,8 @@ class PlaywrightPlugin extends CiPlugin {
510
554
  }
511
555
 
512
556
  const isRUMActive = span.context().getTag(TEST_IS_RUM_ACTIVE)
557
+ const isDeferredMainTest = !this._tracerConfig.DD_PLAYWRIGHT_WORKER &&
558
+ retryTestId !== undefined && deferFinalStatus
513
559
 
514
560
  span.setTag(TEST_STATUS, testStatus)
515
561
 
@@ -565,9 +611,14 @@ class PlaywrightPlugin extends CiPlugin {
565
611
  span.setTag(TEST_RETRY_REASON, TEST_RETRY_REASON_TYPES.efd)
566
612
  }
567
613
  }
568
- if (finalStatus) {
614
+ if (finalStatus && !isDeferredMainTest) {
569
615
  span.setTag(TEST_FINAL_STATUS, finalStatus)
570
616
  }
617
+ if (retryTestId !== undefined && this._tracerConfig.DD_PLAYWRIGHT_WORKER) {
618
+ // This identifier is removed by the main process before exporting the trace.
619
+ span.setTag(RETRY_TEST_ID, retryTestId)
620
+ if (deferFinalStatus) span.setTag(DEFER_FINAL_STATUS, 'true')
621
+ }
571
622
  if (earlyFlakeAbortReason) {
572
623
  span.setTag(TEST_EARLY_FLAKE_ABORT_REASON, earlyFlakeAbortReason)
573
624
  }
@@ -591,10 +642,6 @@ class PlaywrightPlugin extends CiPlugin {
591
642
  }
592
643
  stepSpan.finish(stepStartTime + stepDuration)
593
644
  }
594
- if (finalStatus === 'fail') {
595
- this.numFailedTests++
596
- }
597
-
598
645
  this.telemetry.ciVisEvent(
599
646
  TELEMETRY_EVENT_FINISHED,
600
647
  'test',
@@ -608,6 +655,28 @@ class PlaywrightPlugin extends CiPlugin {
608
655
  isModified,
609
656
  }
610
657
  )
658
+ if (retryTestId !== undefined && !this._tracerConfig.DD_PLAYWRIGHT_WORKER) {
659
+ const finishPrevious = this.#pendingRetryTestFinishes.get(retryTestId)
660
+ finishPrevious?.(false)
661
+ this.#pendingRetryTestFinishes.delete(retryTestId)
662
+ if (isDeferredMainTest) {
663
+ // Legacy spans have no worker report. Retain the last execution until a
664
+ // successor arrives or session end confirms that its retry was canceled.
665
+ const finishTime = span._getTime()
666
+ finishAllTraceSpans(span)
667
+ this.#pendingRetryTestFinishes.set(retryTestId, (isFinal) => {
668
+ if (isFinal) {
669
+ span.setTag(TEST_FINAL_STATUS, finalStatus)
670
+ if (finalStatus === 'fail') this.numFailedTests++
671
+ }
672
+ span.finish(finishTime)
673
+ })
674
+ return
675
+ }
676
+ }
677
+ if (finalStatus === 'fail') {
678
+ this.numFailedTests++
679
+ }
611
680
  span.finish()
612
681
 
613
682
  finishAllTraceSpans(span)
@@ -682,7 +751,6 @@ class PlaywrightPlugin extends CiPlugin {
682
751
  * @param {string} options.traceId - Test trace id used as the screenshot key
683
752
  * @param {AbortSignal} options.signal - Signal used to cancel uploads during error finalization
684
753
  * @param {(result: string|undefined) => void} onDone - Completion callback
685
- * @returns {boolean} Whether at least one upload was started
686
754
  */
687
755
  uploadTestScreenshots ({ screenshots, traceId, signal }, onDone) {
688
756
  const exporter = this.tracer?._exporter
@@ -735,7 +803,6 @@ class PlaywrightPlugin extends CiPlugin {
735
803
  * @param {string} options.traceId - Test trace id used as the video key
736
804
  * @param {AbortSignal} options.signal - Signal used to cancel uploads during error finalization
737
805
  * @param {(result: string|undefined) => void} onDone - Completion callback
738
- * @returns {boolean} Whether at least one upload was started
739
806
  */
740
807
  uploadTestVideos ({ videos, traceId, signal }, onDone) {
741
808
  const exporter = this.tracer?._exporter
@@ -0,0 +1,167 @@
1
+ 'use strict'
2
+
3
+ const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
4
+ const DatabasePlugin = require('../../dd-trace/src/plugins/database')
5
+ const Plugin = require('../../dd-trace/src/plugins/plugin')
6
+
7
+ const PREPARE_START_CHANNEL = 'tracing:orchestrion:postgres:query:prepare:start'
8
+
9
+ /**
10
+ * @typedef {object} PostgresContext
11
+ * @property {{ span: import('../../..').Span }} currentStore
12
+ * @property {string} database
13
+ * @property {unknown} [error]
14
+ * @property {string} [host]
15
+ * @property {number} [pid]
16
+ * @property {number} [port]
17
+ * @property {PostgresQuery} query
18
+ * @property {string} [statement]
19
+ * @property {string} user
20
+ *
21
+ * @typedef {object} PostgresDbmState
22
+ * @property {string} service
23
+ * @property {string} [statement]
24
+ *
25
+ * @typedef {object} PostgresPreparationContext
26
+ * @property {boolean} prepared
27
+ * @property {PostgresQuery} query
28
+ * @property {string} statement
29
+ *
30
+ * @typedef {object} PostgresQuery
31
+ */
32
+
33
+ class PostgresPreparationPlugin extends Plugin {
34
+ static id = 'postgres'
35
+
36
+ /**
37
+ * @param {(ctx: PostgresPreparationContext) => void} prepare
38
+ * @param {object} tracer
39
+ * @param {import('../../dd-trace/src/config/config-base')} tracerConfig
40
+ */
41
+ constructor (prepare, tracer, tracerConfig) {
42
+ super(tracer, tracerConfig)
43
+ this.addSub(PREPARE_START_CHANNEL, prepare)
44
+ }
45
+ }
46
+
47
+ class PostgresPlugin extends DatabasePlugin {
48
+ static id = 'postgres'
49
+ static prefix = 'tracing:orchestrion:postgres:query'
50
+
51
+ /** @type {boolean} */
52
+ #dbmEnabled = false
53
+
54
+ /** @type {WeakMap<PostgresQuery, PostgresDbmState>} */
55
+ #dbmQueries = new WeakMap()
56
+
57
+ /** @type {PostgresPreparationPlugin} */
58
+ #preparation
59
+
60
+ /** @type {{ name: string, source: string | undefined }} */
61
+ #service
62
+
63
+ /** @type {WeakMap<PostgresQuery, import('../../..').Span>} */
64
+ #spans = new WeakMap()
65
+
66
+ /**
67
+ * @param {object} tracer
68
+ * @param {import('../../dd-trace/src/config/config-base')} tracerConfig
69
+ */
70
+ constructor (tracer, tracerConfig) {
71
+ super(tracer, tracerConfig)
72
+ this.#preparation = new PostgresPreparationPlugin(this.#prepare.bind(this), tracer, tracerConfig)
73
+ }
74
+
75
+ /**
76
+ * @override
77
+ * @param {boolean | import('../../dd-trace/src/config/config-base') & {enabled: boolean}} config
78
+ */
79
+ configure (config) {
80
+ super.configure(config)
81
+
82
+ this.#service = this.serviceName({ pluginConfig: this.config })
83
+ const mode = this.config.dbmPropagationMode
84
+ this.#dbmEnabled = mode === 'service' || mode === 'full' || mode === 'dynamic_service'
85
+ this.#preparation.configure(this.config.enabled === true && this.#dbmEnabled)
86
+ }
87
+
88
+ /**
89
+ * @param {PostgresContext} ctx
90
+ * @returns {object}
91
+ */
92
+ bindStart (ctx) {
93
+ const { database, host, port, query, user } = ctx
94
+ const service = this.#service
95
+
96
+ const span = this.startSpan(this.operationName(), {
97
+ service,
98
+ type: 'sql',
99
+ kind: 'client',
100
+ meta: {
101
+ 'db.type': this.system,
102
+ 'db.name': database,
103
+ 'db.user': user,
104
+ },
105
+ }, ctx)
106
+
107
+ if (host !== undefined) {
108
+ span.addTags({
109
+ 'out.host': host,
110
+ [CLIENT_PORT_KEY]: port,
111
+ })
112
+ }
113
+
114
+ this.#spans.set(query, span)
115
+ if (this.#dbmEnabled) {
116
+ this.#dbmQueries.set(query, { service: service.name })
117
+ }
118
+ return ctx.currentStore
119
+ }
120
+
121
+ /**
122
+ * @param {PostgresPreparationContext} ctx
123
+ */
124
+ #prepare (ctx) {
125
+ const state = this.#dbmQueries.get(ctx.query)
126
+ const span = this.#spans.get(ctx.query)
127
+ if (state === undefined || span === undefined) return
128
+
129
+ state.statement = ctx.statement
130
+ span.setTag('resource.name', this.maybeTruncate(ctx.statement))
131
+ ctx.statement = this.injectDbmQuery(span, ctx.statement, state.service, ctx.prepared)
132
+ }
133
+
134
+ /**
135
+ * @param {PostgresContext} ctx
136
+ */
137
+ error (ctx) {
138
+ const span = this.#spans.get(ctx.query)
139
+ if (span !== undefined) {
140
+ this.addError(ctx.error, span)
141
+ }
142
+ }
143
+
144
+ /**
145
+ * @param {PostgresContext} result
146
+ */
147
+ asyncEnd (result) {
148
+ const { query } = result
149
+ const dbmState = this.#dbmQueries.get(query)
150
+ const span = this.#spans.get(query)
151
+
152
+ this.#dbmQueries.delete(query)
153
+ if (span === undefined) return
154
+
155
+ this.#spans.delete(query)
156
+
157
+ const statement = dbmState?.statement ?? result.statement
158
+ if (dbmState?.statement === undefined && typeof statement === 'string') {
159
+ span.setTag('resource.name', this.maybeTruncate(statement))
160
+ }
161
+
162
+ span.setTag('db.pid', result.pid)
163
+ this.finish({ currentStore: { span } })
164
+ }
165
+ }
166
+
167
+ module.exports = PostgresPlugin
@@ -31,7 +31,6 @@ class DatadogTracingHelper {
31
31
  * Needs a sampled tracecontext to generate engine spans
32
32
  *
33
33
  * @param {object} [context]
34
- * @returns {string}
35
34
  */
36
35
  getTraceParent (context) {
37
36
  const store = storage('legacy').getStore()
@@ -3,8 +3,10 @@
3
3
  const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
4
4
  const CachePlugin = require('../../dd-trace/src/plugins/cache')
5
5
  const urlFilter = require('../../dd-trace/src/plugins/util/urlfilter')
6
+ const { truncateString } = require('../../dd-trace/src/util')
6
7
 
7
8
  const MAX_ARG_LENGTH = 100
9
+ const MAX_ARG_LENGTH_WITHOUT_COPY = 256
8
10
  const MAX_COMMAND_LENGTH = 1000
9
11
 
10
12
  class RedisPlugin extends CachePlugin {
@@ -95,15 +97,27 @@ function formatCommand (command, args, argsStartIndex = 0) {
95
97
  return result
96
98
  }
97
99
 
100
+ /**
101
+ * @param {unknown} arg
102
+ */
98
103
  function formatArg (arg) {
99
104
  if (typeof arg === 'string') {
100
- return arg.length > MAX_ARG_LENGTH ? arg.slice(0, MAX_ARG_LENGTH - 3) + '...' : arg
105
+ return arg.length > MAX_ARG_LENGTH ? truncateArg(arg) : arg
101
106
  }
102
107
  // Number stringification is bounded (~23 chars max), so it never hits MAX_ARG_LENGTH.
103
108
  if (typeof arg === 'number') return String(arg)
104
109
  return '?'
105
110
  }
106
111
 
112
+ /**
113
+ * @param {string} arg
114
+ */
115
+ function truncateArg (arg) {
116
+ return arg.length > MAX_ARG_LENGTH_WITHOUT_COPY
117
+ ? truncateString(arg, MAX_ARG_LENGTH, '...')
118
+ : arg.slice(0, MAX_ARG_LENGTH - 3) + '...'
119
+ }
120
+
107
121
  function normalizeConfig (config) {
108
122
  if (config.allowlist) uppercaseAllEntries(config.allowlist)
109
123
  if (config.whitelist) uppercaseAllEntries(config.whitelist)
@@ -0,0 +1,18 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * @param {Error | { message?: string } | string | null | undefined} error Supabase operation error.
5
+ * @param {string} type Error type used for non-Error SDK results.
6
+ * @param {string} [message] Error message used for non-Error SDK results.
7
+ * @returns {Error | undefined}
8
+ */
9
+ function normalizeError (error, type, message) {
10
+ if (!error) return
11
+ if (error instanceof Error) return error
12
+
13
+ const normalizedError = new Error(message || error?.message || String(error))
14
+ normalizedError.name = type
15
+ return normalizedError
16
+ }
17
+
18
+ module.exports = normalizeError
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+
3
+ const CompositePlugin = require('../../dd-trace/src/plugins/composite')
4
+ const SupabaseGoTrueClientGetUserPlugin = require('./supabase-auth-js-gotrueclient-getuser')
5
+ const SupabaseStorageHandleRequestPlugin = require('./supabase-storage-js-handle-request')
6
+ const SupabaseRealtimeChannelSendPlugin = require('./supabase-realtime-js-realtimechannel-send')
7
+ const SupabaseFunctionsClientInvokePlugin = require('./supabase-functions-js-functionsclient-invoke')
8
+ const SupabasePostgrestBuilderThenPlugin = require('./supabase-postgrest-js-postgrestbuilder-then')
9
+
10
+ class SupabasePlugin extends CompositePlugin {
11
+ static id = 'supabase'
12
+ static plugins = {
13
+ SupabaseGoTrueClientGetUserPlugin,
14
+ SupabaseStorageHandleRequestPlugin,
15
+ SupabaseRealtimeChannelSendPlugin,
16
+ SupabaseFunctionsClientInvokePlugin,
17
+ SupabasePostgrestBuilderThenPlugin,
18
+ }
19
+ }
20
+
21
+ module.exports = SupabasePlugin