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
@@ -8,6 +8,19 @@ const {
8
8
  const { ObservableInstrument } = require('./instruments')
9
9
  const { nowUnixNano } = require('./time')
10
10
 
11
+ /**
12
+ * @param {(error: Error | null) => void} [done]
13
+ * @param {Error | null} [error]
14
+ */
15
+ function callDone (done, error) {
16
+ if (!done) return
17
+ try {
18
+ done(error ?? null)
19
+ } catch (callbackError) {
20
+ log.error('Error completing OTLP metrics lifecycle callback:', callbackError)
21
+ }
22
+ }
23
+
11
24
  /**
12
25
  * @typedef {import('@opentelemetry/api').Attributes} Attributes
13
26
  * @typedef {import('@opentelemetry/core').InstrumentationScope} InstrumentationScope
@@ -105,6 +118,10 @@ class PeriodicMetricReader {
105
118
  #exportInterval
106
119
  #aggregator
107
120
  #batchCallbacks = []
121
+ #exportQueue = []
122
+ #isExporting = false
123
+ #shutdownCallbacks = []
124
+ #shutdownComplete = false
108
125
 
109
126
  /**
110
127
  * Creates a new PeriodicMetricReader instance.
@@ -161,9 +178,9 @@ class PeriodicMetricReader {
161
178
  }
162
179
 
163
180
  /**
181
+ * Returns the matching index, or `-1` when no batch callback matches.
164
182
  * @param {Function} callback
165
183
  * @param {Set} instruments
166
- * @returns {number} index in #batchCallbacks, or -1
167
184
  */
168
185
  #findBatchCallback (callback, instruments) {
169
186
  return this.#batchCallbacks.findIndex(record =>
@@ -197,47 +214,34 @@ class PeriodicMetricReader {
197
214
 
198
215
  /**
199
216
  * Forces an immediate collection and export of all metrics.
200
- * @param {Function} [done] Called after the metric export completes
217
+ * @param {(error: Error | null) => void} [done] Called after the metric export completes
201
218
  */
202
219
  forceFlush (done) {
203
220
  if (this.#isShutdown) {
204
221
  log.warn('PeriodicMetricReader is shutdown. %d measurement(s) were dropped', this.#droppedCount)
205
- done?.()
222
+ if (this.#shutdownComplete) callDone(done)
223
+ else if (done) this.#shutdownCallbacks.push(done)
206
224
  return
207
225
  }
208
- let pending = 2
209
- const complete = () => {
210
- if (--pending === 0) done?.()
211
- }
212
-
213
- // Snapshot requests already active before starting this flush's export.
214
- try {
215
- if (typeof this.exporter.flush === 'function') this.exporter.flush(complete)
216
- else complete()
217
- } catch (error) {
218
- log.error('Error flushing OTLP metrics:', error)
219
- complete()
220
- }
221
- try {
222
- this.#collectAndExport(complete)
223
- } catch (error) {
224
- log.error('Error exporting OTLP metrics:', error)
225
- complete()
226
- }
226
+ this.#enqueueExport(true, done)
227
227
  }
228
228
 
229
229
  /**
230
230
  * Shuts down the reader and stops periodic collection.
231
- * @returns {void}
231
+ * @param {(error: Error | null) => void} [done] Called after the final export and exporter shutdown complete
232
232
  */
233
- shutdown () {
233
+ shutdown (done) {
234
234
  if (this.#isShutdown) {
235
235
  log.warn('PeriodicMetricReader is already shutdown')
236
+ if (this.#shutdownComplete) callDone(done)
237
+ else if (done) this.#shutdownCallbacks.push(done)
236
238
  return
237
239
  }
240
+ if (done) this.#shutdownCallbacks.push(done)
241
+
238
242
  this.#isShutdown = true
239
243
  this.#clearTimer()
240
- this.forceFlush()
244
+ this.#enqueueExport(true, error => this.#shutdownExporter(error))
241
245
  }
242
246
 
243
247
  /**
@@ -248,7 +252,7 @@ class PeriodicMetricReader {
248
252
  if (this.#timer) return
249
253
 
250
254
  this.#timer = setInterval(() => {
251
- this.#collectAndExport()
255
+ if (!this.#isExporting && this.#exportQueue.length === 0) this.#enqueueExport(false)
252
256
  }, this.#exportInterval)
253
257
  this.#timer.unref?.()
254
258
  }
@@ -264,6 +268,72 @@ class PeriodicMetricReader {
264
268
  }
265
269
  }
266
270
 
271
+ /**
272
+ * @param {boolean} flushExporter Whether to flush the exporter after export
273
+ * @param {(error: Error | null) => void} [done] Called when the queued export completes
274
+ */
275
+ #enqueueExport (flushExporter, done) {
276
+ this.#exportQueue.push({ flushExporter, done })
277
+ this.#drainExportQueue()
278
+ }
279
+
280
+ #drainExportQueue () {
281
+ if (this.#isExporting || this.#exportQueue.length === 0) return
282
+
283
+ this.#isExporting = true
284
+ const { flushExporter, done } = this.#exportQueue.shift()
285
+ let completed = false
286
+ const complete = error => {
287
+ if (completed) return
288
+ completed = true
289
+ this.#isExporting = false
290
+ queueMicrotask(() => this.#drainExportQueue())
291
+ callDone(done, error)
292
+ }
293
+ let exportCompleted = false
294
+ const afterExport = error => {
295
+ if (exportCompleted) return
296
+ exportCompleted = true
297
+ if (!flushExporter || typeof this.exporter.flush !== 'function') return complete(error)
298
+
299
+ try {
300
+ this.exporter.flush(flushError => complete(error || flushError))
301
+ } catch (flushError) {
302
+ log.error('Error flushing OTLP metrics:', flushError)
303
+ complete(error || flushError)
304
+ }
305
+ }
306
+
307
+ try {
308
+ this.#collectAndExport(afterExport)
309
+ } catch (error) {
310
+ log.error('Error exporting OTLP metrics:', error)
311
+ afterExport(error)
312
+ }
313
+ }
314
+
315
+ /**
316
+ * @param {Error} [exportError] Error from the final export
317
+ */
318
+ #shutdownExporter (exportError) {
319
+ let completed = false
320
+ const complete = shutdownError => {
321
+ if (completed) return
322
+ completed = true
323
+ this.#shutdownComplete = true
324
+ const callbacks = this.#shutdownCallbacks.splice(0)
325
+ for (const callback of callbacks) callDone(callback, exportError || shutdownError)
326
+ }
327
+
328
+ try {
329
+ if (typeof this.exporter.shutdown === 'function') this.exporter.shutdown(complete)
330
+ else complete()
331
+ } catch (error) {
332
+ log.error('Error shutting down OTLP metrics exporter:', error)
333
+ complete(error)
334
+ }
335
+ }
336
+
267
337
  /**
268
338
  * Collects measurements and exports metrics.
269
339
  *
@@ -322,7 +392,13 @@ class PeriodicMetricReader {
322
392
  this.#lastExportedState
323
393
  )
324
394
 
325
- this.exporter.export(metrics, callback)
395
+ this.exporter.export(metrics, result => {
396
+ if (result?.code === 1) {
397
+ callback?.(result.error || new Error('OTLP metrics export failed'))
398
+ } else {
399
+ callback?.()
400
+ }
401
+ })
326
402
  }
327
403
  }
328
404
 
@@ -344,7 +420,6 @@ class MetricAggregator {
344
420
  * Gets the temporality for a given metric type.
345
421
  *
346
422
  * @param {string} type - Metric type from METRIC_TYPES
347
- * @returns {string} Temporality from TEMPORALITY
348
423
  */
349
424
  #getTemporality (type) {
350
425
  // UpDownCounter and Observable UpDownCounter always use CUMULATIVE
@@ -439,7 +514,6 @@ class MetricAggregator {
439
514
  * Gets unique identifier for a given instrumentation scope.
440
515
  *
441
516
  * @param {InstrumentationScope} instrumentationScope - The instrumentation scope
442
- * @returns {string} - The scope identifier
443
517
  */
444
518
  #getScopeKey (instrumentationScope) {
445
519
  return `${instrumentationScope.name}@${instrumentationScope.version}@${instrumentationScope.schemaUrl}`
@@ -452,7 +526,6 @@ class MetricAggregator {
452
526
  * @param {string} name - The metric name
453
527
  * @param {string} type - The metric type from METRIC_TYPES
454
528
  * @param {string} attrKey - The attribute key
455
- * @returns {string} - The metric identifier
456
529
  */
457
530
  #getStateKey (scopeKey, name, type, attrKey) {
458
531
  return `${scopeKey}:${name}:${type}:${attrKey}`
@@ -462,7 +535,6 @@ class MetricAggregator {
462
535
  * Checks if a given metric type is a delta type.
463
536
  *
464
537
  * @param {string} type - The metric type from METRIC_TYPES
465
- * @returns {boolean} - True if the metric type is a delta type
466
538
  */
467
539
  #isDeltaType (type) {
468
540
  return type === METRIC_TYPES.COUNTER ||
@@ -475,7 +547,6 @@ class MetricAggregator {
475
547
  *
476
548
  * @param {Iterable<AggregatedMetric>} metrics - The metrics to apply delta temporality to
477
549
  * @param {Map<string, LastExportedStateValue>} lastExportedState - The last exported state of the metrics
478
- * @returns {void}
479
550
  */
480
551
  #applyDeltaTemporality (metrics, lastExportedState) {
481
552
  for (const metric of metrics) {
@@ -600,7 +671,6 @@ class MetricAggregator {
600
671
  * @param {number} timestamp - The timestamp of the measurement
601
672
  * @param {string} stateKey - The state key
602
673
  * @param {Map<string, CumulativeStateValue>} cumulativeState - The cumulative state of the metrics
603
- * @returns {void}
604
674
  */
605
675
  #aggregateHistogram (metric, value, attributes, attrKey, timestamp, stateKey, cumulativeState) {
606
676
  if (!cumulativeState.has(stateKey)) {
@@ -652,7 +722,6 @@ class MetricAggregator {
652
722
 
653
723
  /**
654
724
  * @param {object} x
655
- * @returns {boolean}
656
725
  */
657
726
  function isObservableInstrument (x) {
658
727
  return x instanceof ObservableInstrument
@@ -661,7 +730,6 @@ function isObservableInstrument (x) {
661
730
  /**
662
731
  * @param {Set} a
663
732
  * @param {Set} b
664
- * @returns {boolean}
665
733
  */
666
734
  function setEquals (a, b) {
667
735
  if (a.size !== b.size) return false
@@ -10,7 +10,6 @@ const { timeOrigin } = performance
10
10
  * the value on the epoch while `performance.now()` keeps it monotonic, so a
11
11
  * backward wall-clock jump can't make `timeUnixNano` precede `startTimeUnixNano`.
12
12
  *
13
- * @returns {number} Nanoseconds since the UNIX epoch
14
13
  */
15
14
  function nowUnixNano () {
16
15
  return Math.round((timeOrigin + performance.now()) * 1e6)
@@ -42,15 +42,9 @@ class OtlpHttpExporterBase {
42
42
 
43
43
  const isJson = protocol === 'http/json'
44
44
 
45
- const parsedUrl = new URL(url)
46
- this.#transport = parsedUrl.protocol === 'http:' ? http : https
47
45
  this.options = {
48
46
  method: 'POST',
49
47
  timeout,
50
- hostname: parsedUrl.hostname,
51
- port: parsedUrl.port,
52
- path: parsedUrl.pathname + parsedUrl.search,
53
- agent: parsedUrl.protocol === 'https:' ? getHttpsProxyAgent(parsedUrl) : undefined,
54
48
  headers: {
55
49
  'Content-Type': isJson ? 'application/json' : 'application/x-protobuf',
56
50
  'User-Agent': `dd-trace-js/${tracerVersion}`,
@@ -59,9 +53,10 @@ class OtlpHttpExporterBase {
59
53
  }
60
54
 
61
55
  this.telemetryTags = [
62
- `protocol:${this.#transport === https ? 'https' : 'http'}`,
56
+ '',
63
57
  `encoding:${isJson ? 'json' : 'protobuf'}`,
64
58
  ]
59
+ this.#applyUrl(url)
65
60
  }
66
61
 
67
62
  /**
@@ -164,20 +159,48 @@ class OtlpHttpExporterBase {
164
159
  }
165
160
 
166
161
  /**
167
- * Re-targets the exporter to a different URL, updating transport, hostname, port, and path.
168
162
  * @param {string} url
169
163
  */
170
- setUrl (url) {
164
+ #applyUrl (url) {
171
165
  const parsedUrl = new URL(url)
172
- this.#transport = parsedUrl.protocol === 'http:' ? http : https
166
+ if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
167
+ throw new TypeError(`Unsupported OTLP endpoint protocol: ${parsedUrl.protocol}`)
168
+ }
169
+
170
+ const transport = parsedUrl.protocol === 'http:' ? http : https
171
+ const agent = transport === https ? getHttpsProxyAgent(parsedUrl) : undefined
172
+
173
+ this.#transport = transport
173
174
  this.options.hostname = parsedUrl.hostname
174
175
  this.options.port = parsedUrl.port
175
176
  this.options.path = parsedUrl.pathname + parsedUrl.search
176
- this.options.agent = parsedUrl.protocol === 'https:' ? getHttpsProxyAgent(parsedUrl) : undefined
177
- this.telemetryTags[0] = `protocol:${this.#transport === https ? 'https' : 'http'}`
177
+ this.options.agent = agent
178
+ this.telemetryTags[0] = `protocol:${transport === https ? 'https' : 'http'}`
179
+ }
180
+
181
+ /**
182
+ * Re-targets the exporter to a different URL, updating transport, hostname, port, and path.
183
+ * @param {string} url
184
+ */
185
+ setUrl (url) {
186
+ try {
187
+ this.#applyUrl(url)
188
+ } catch (error) {
189
+ log.error(
190
+ 'Invalid OTLP %s URL: %s. Using previous URL. Error: %s',
191
+ this.signalType,
192
+ url,
193
+ error.message
194
+ )
195
+ }
178
196
  }
179
197
 
180
- shutdown () {}
198
+ /**
199
+ * @param {() => void} [done]
200
+ */
201
+ shutdown (done) {
202
+ done?.()
203
+ }
181
204
  }
182
205
 
183
206
  module.exports = OtlpHttpExporterBase
@@ -171,7 +171,6 @@ class OtlpTransformerBase {
171
171
  * Supports string keys with primitive values or arrays of primitives.
172
172
  *
173
173
  * @param {Attributes} attributes - Attributes object to stringify
174
- * @returns {string} Stable string representation
175
174
  */
176
175
  function stableStringify (attributes) {
177
176
  if (attributes == null) {
@@ -261,7 +261,6 @@ function recordException (ddSpan, exception, timeInput, otelTraceSemanticsEnable
261
261
  * @param {number} currentCode 0 = UNSET, 1 = OK, 2 = ERROR.
262
262
  * @param {{ code?: number, message?: string }} [status]
263
263
  * @param {boolean} [otelTraceSemanticsEnabled]
264
- * @returns {number} The new status code to track on the caller.
265
264
  */
266
265
  function applyOtelStatus (ddSpan, currentCode, status, otelTraceSemanticsEnabled) {
267
266
  if (!isWritable(ddSpan)) return currentCode
@@ -57,7 +57,6 @@ class OtlpHttpTraceExporter extends OtlpHttpExporterBase {
57
57
  * Exports DD-formatted spans via OTLP over HTTP.
58
58
  *
59
59
  * @param {import('./otlp_transformer').DDFormattedSpan[]} spans - Array of DD-formatted spans to export
60
- * @returns {void}
61
60
  */
62
61
  export (spans) {
63
62
  if (spans.length === 0) {
@@ -248,7 +248,6 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
248
248
  * Maps a DD span.kind string to an OTLP SpanKind enum value.
249
249
  *
250
250
  * @param {string | undefined} kind - DD span kind string
251
- * @returns {number} OTLP SpanKind enum value
252
251
  */
253
252
  #mapSpanKind (kind) {
254
253
  if (!kind) return SPAN_KIND_UNSPECIFIED
@@ -340,7 +339,6 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
340
339
  *
341
340
  * @param {Identifier} identifier - DD Identifier
342
341
  * @param {number} targetLength - Target byte length (16 for trace ID, 8 for span ID)
343
- * @returns {string} Hex-encoded string of the specified length
344
342
  */
345
343
  #idToBytes (identifier, targetLength) {
346
344
  const buffer = identifier.toBuffer()
@@ -363,7 +361,6 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
363
361
  *
364
362
  * @param {string | undefined} hexString - Hex string to normalize
365
363
  * @param {number} targetLength - Target byte length
366
- * @returns {string} Hex-encoded string of the specified length
367
364
  */
368
365
  #hexToBytes (hexString, targetLength) {
369
366
  if (!hexString) return '0'.repeat(targetLength * 2)
@@ -88,7 +88,6 @@ const percentByte = /%([0-9A-Fa-f]{2})/g
88
88
  /**
89
89
  * @param {Array<string | undefined>} traceTagReplacements
90
90
  * @param {string} key
91
- * @returns {boolean}
92
91
  */
93
92
  function hasTraceTagReplacement (traceTagReplacements, key) {
94
93
  for (let index = 0; index < traceTagReplacements.length; index += 2) {
@@ -117,7 +116,6 @@ function extractGenericContext (traceId, spanId, radix) {
117
116
  /**
118
117
  * @param {string} traceId
119
118
  * @param {DatadogSpanContext} spanContext
120
- * @returns {void}
121
119
  */
122
120
  function extract128BitTraceId (traceId, spanContext) {
123
121
  const buffer = spanContext._traceId.toBuffer()
@@ -485,7 +483,6 @@ class TextMapPropagator {
485
483
  * @param {Record<string, string>} traceTags
486
484
  * @param {Array<string | undefined>} [traceTagReplacements]
487
485
  * @param {number} optionalTraceTagCount
488
- * @returns {void}
489
486
  */
490
487
  #injectTags (carrier, traceTags, traceTagReplacements, optionalTraceTagCount) {
491
488
  if (this.#config.DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH === 0) {
@@ -688,7 +685,6 @@ class TextMapPropagator {
688
685
  /**
689
686
  * @param {'inject' | 'extract'} mode
690
687
  * @param {string} name
691
- * @returns {boolean}
692
688
  */
693
689
  #hasPropagationStyle (mode, name) {
694
690
  return this.#config.tracePropagationStyle[mode].includes(name)
@@ -974,7 +970,6 @@ class TextMapPropagator {
974
970
  /**
975
971
  * @param {Record<string, unknown>} carrier
976
972
  * @param {DatadogSpanContext} spanContext
977
- * @returns {void}
978
973
  */
979
974
  #extractLegacyBaggageItems (carrier, spanContext) {
980
975
  if (!this.#config.legacyBaggageEnabled) return
@@ -985,7 +980,6 @@ class TextMapPropagator {
985
980
  * @param {Record<string, unknown> | undefined} carrier
986
981
  * @param {DatadogSpanContext | undefined} spanContext
987
982
  * @param {boolean} extractBaggage
988
- * @returns {void}
989
983
  */
990
984
  #extractBaggageItems (carrier, spanContext, extractBaggage) {
991
985
  removeAllBaggageItems()
@@ -108,7 +108,6 @@ class DatadogSpanContext {
108
108
  /**
109
109
  * Check if a tag exists.
110
110
  * @param {string} key - Tag key
111
- * @returns {boolean}
112
111
  */
113
112
  hasTag (key) { return Object.hasOwn(this._tags, key) }
114
113
 
@@ -25,6 +25,7 @@
25
25
 
26
26
  const { isMainThread, threadId } = require('worker_threads')
27
27
 
28
+ const { AUTO_KEEP } = require('../../../ext/priority')
28
29
  const { isACFActive } = require('../../datadog-core/src/storage')
29
30
  const log = require('./log')
30
31
  const {
@@ -94,6 +95,20 @@ const ATTRIBUTE_KEYS = [
94
95
  const THREAD_NAME = (isMainThread ? 'Main' : `Worker #${threadId}`) + ' Event Loop'
95
96
  const THREAD_ID = String(threadId)
96
97
 
98
+ // W3C trace-flags byte for a record, derived the same way DatadogSpanContext
99
+ // #toTraceparent derives the flags it puts on the wire — sampled iff the
100
+ // priority is AUTO_KEEP or above.
101
+ //
102
+ // Unlike toTraceparent, this does NOT materialize a not-yet-taken decision
103
+ // (_ensureSamplingPriority): that would move every trace's sampling decision
104
+ // forward to the first activation of its first span, on the tracer's hot path,
105
+ // as a side effect of profiling being enabled. An undefined priority therefore
106
+ // reads as not sampled, which is also what OTEP-4947 prescribes when the flags
107
+ // are not known yet. See the note on setTraceFlags in getOrBuildContext.
108
+ function traceFlagsOf (spanContext) {
109
+ return spanContext._sampling?.priority >= AUTO_KEEP ? 1 : 0
110
+ }
111
+
97
112
  // Cache slot on span objects. One ThreadContext is built per span on first
98
113
  // activation and re-installed across every async-context frame that
99
114
  // re-enters the span — V8's AsyncContextFrame inherits the JS
@@ -140,7 +155,13 @@ function getOrBuildContext (span) {
140
155
  cached = {}
141
156
  span[CachedSym] = cached
142
157
  }
143
- cached.context = new ThreadContext(traceId, spanId, attrs)
158
+ // The flags are the one part of the record that can still change after
159
+ // publication: a decision taken later, or overridden, is pushed into the live
160
+ // record with setTraceFlags rather than by rebuilding the context, which would
161
+ // strand every async-context frame already holding this one. Nothing calls it
162
+ // yet — the tracer publishes no event for a sampling decision — so a record
163
+ // built before the decision keeps reading as not sampled.
164
+ cached.context = new ThreadContext(traceId, spanId, traceFlagsOf(spanContext), attrs)
144
165
  cached.webTags = webTags
145
166
  if (endpoint === undefined) awaitEndpoint(webTags, cached)
146
167
  return cached.context
@@ -279,7 +300,7 @@ function missingApiMember (ns) {
279
300
  for (const name of ['ThreadContext', 'getContext', 'clearContext', 'getProcessContextAttributes']) {
280
301
  if (typeof ns[name] !== 'function') return name
281
302
  }
282
- for (const name of ['appendAttributes', 'enter', 'invalidate']) {
303
+ for (const name of ['appendAttributes', 'enter', 'invalidate', 'setTraceFlags']) {
283
304
  if (typeof ns.ThreadContext.prototype[name] !== 'function') return `ThreadContext.prototype.${name}`
284
305
  }
285
306
  }
@@ -287,15 +308,21 @@ function missingApiMember (ns) {
287
308
  // Install and detach one throwaway context, to establish that this process can
288
309
  // actually do it before any span depends on it.
289
310
  //
290
- // @datadog/pprof decides whether AsyncContextFrame is available by inspecting
291
- // `process.execArgv`, and throws from enter() when it concludes it isn't. That
292
- // disagrees with the feature detection behind `isACFActive` whenever the flag
293
- // reached Node by another route: `NODE_OPTIONS=--experimental-async-context-frame`
294
- // is accepted on Node 22 and 23 and leaves `execArgv` empty, and a worker thread
295
- // created with an explicit `execArgv` loses it too. Since our subscribers run
296
- // inline with `storage.enterWith`, letting that throw would put the exception in
297
- // application code on the first span activation, so find out here instead, where
298
- // declining to start is still an option.
311
+ // @datadog/pprof throws from enter() when it concludes AsyncContextFrame is not
312
+ // active. It reaches that conclusion by its own feature detection, asking the
313
+ // addon what is in the CPED slot during a `run()` — direct evidence about the
314
+ // exact slot the out-of-process reader walks. `isACFActive` above tests the same
315
+ // property through a weaker proxy: whether `run()` delegates to `enterWith()`,
316
+ // which holds today but relies on unspecified dispatch that anything patching
317
+ // `AsyncLocalStorage` can break. So the two can disagree, and pprof's answer is
318
+ // the one that governs whether a record ever gets written. Its enter() can also
319
+ // fail for reasons `isACFActive` says nothing about, such as an addon that
320
+ // loaded but whose TLS block is unusable.
321
+ //
322
+ // Since our subscribers run inline with `storage.enterWith`, letting enter()
323
+ // throw would put the exception in application code on the first span
324
+ // activation, so find out here instead, where declining to start is still an
325
+ // option.
299
326
  function canInstallContext (ns) {
300
327
  try {
301
328
  // Zero-filled ids: the record is only readable while it is installed, which
@@ -1,18 +1,29 @@
1
1
  'use strict'
2
2
 
3
3
  const { PAYLOAD_TAGGING_MAX_TAGS } = require('../constants')
4
+ const { truncateString } = require('../util')
4
5
 
5
6
  const redactedKeys = new Set([
6
7
  'authorization', 'x-authorization', 'password', 'token',
7
8
  ])
8
9
  const truncated = 'truncated'
9
10
  const redacted = 'redacted'
11
+ const maxValueLength = 5000
12
+ const maxRetainedValueLength = maxValueLength * 2
13
+
14
+ /**
15
+ * @param {string} value
16
+ */
17
+ function truncateValue (value) {
18
+ return value.length > maxRetainedValueLength
19
+ ? truncateString(value, maxValueLength)
20
+ : value.slice(0, maxValueLength)
21
+ }
10
22
 
11
23
  /**
12
24
  * Escapes dots in keys to preserve hierarchy in flattened tag names.
13
25
  *
14
26
  * @param {string} key
15
- * @returns {string}
16
27
  */
17
28
  function escapeKey (key) {
18
29
  return key.replaceAll('.', String.raw`\.`)
@@ -67,13 +78,14 @@ function tagsFromObject (object, opts) {
67
78
 
68
79
  if (['number', 'boolean'].includes(typeof object) || Buffer.isBuffer(object)) {
69
80
  tagCount += 1
70
- result[prefix] = object.toString().slice(0, 5000)
81
+ const value = object.toString()
82
+ result[prefix] = value.length > maxValueLength ? truncateValue(value) : value
71
83
  return
72
84
  }
73
85
 
74
86
  if (typeof object === 'string') {
75
87
  tagCount += 1
76
- result[prefix] = object.slice(0, 5000)
88
+ result[prefix] = object.length > maxValueLength ? truncateValue(object) : object
77
89
  }
78
90
 
79
91
  if (typeof object === 'object') {
@@ -2,7 +2,11 @@
2
2
 
3
3
  const { channel } = require('dc-polyfill')
4
4
 
5
- const { getEnvironmentVariable, getValueFromEnvSources } = require('./config/helper')
5
+ const {
6
+ getEnvironmentVariable,
7
+ getValueFromEnvSources,
8
+ isSupportedConfiguration,
9
+ } = require('./config/helper')
6
10
  const { isFalse, isTrue, normalizePluginEnvName } = require('./util')
7
11
  const plugins = require('./plugins')
8
12
  const log = require('./log')
@@ -59,12 +63,14 @@ function maybeEnable (Plugin) {
59
63
  }
60
64
 
61
65
  function getEnabled (Plugin) {
62
- const envName = `DD_TRACE_${Plugin.id.toUpperCase()}_ENABLED`
66
+ const envName = normalizePluginEnvName(`DD_TRACE_${Plugin.id.toUpperCase()}_ENABLED`)
67
+ if (!isSupportedConfiguration(envName)) return
68
+
63
69
  // skipDefault: only an explicitly configured value should drive enablement here. A registered
64
70
  // default of `false` (e.g. an opt-in plugin like `nats`) must not be read as an explicit
65
71
  // "disabled via configuration option" — that path both logs a misleading line and nulls the
66
72
  // plugin class, bypassing the opt-in handled by `loadPlugin`.
67
- return getValueFromEnvSources(normalizePluginEnvName(envName), true)
73
+ return getValueFromEnvSources(envName, true)
68
74
  }
69
75
 
70
76
  // TODO this must always be a singleton.
@@ -593,7 +593,6 @@ module.exports = class CiPlugin extends Plugin {
593
593
  * @param {string|undefined} repositoryRoot - Repository root discovered by the coordinator process.
594
594
  * @param {Array<{ pattern: string, owners: string[] }>|null|undefined} codeOwnersEntries
595
595
  * Parsed CODEOWNERS entries discovered by the coordinator process.
596
- * @returns {void}
597
596
  */
598
597
  _setRepositoryRoot (repositoryRoot, codeOwnersEntries) {
599
598
  if (codeOwnersEntries !== undefined) {