dd-trace 5.135.0 → 5.137.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 (352) hide show
  1. package/README.md +3 -0
  2. package/ci/cypress/support.js +2 -1
  3. package/ci/init.js +2 -22
  4. package/ci/vitest-no-worker-init-node-setup.mjs +2 -1
  5. package/ci/vitest-no-worker-init-runner-setup.mjs +2 -1
  6. package/ci/vitest-no-worker-init-setup.mjs +729 -724
  7. package/ci/vitest-no-worker-init-v5-setup.mjs +2 -1
  8. package/ext/exporters.js +0 -1
  9. package/index.d.ts +105 -5
  10. package/initialize.mjs +5 -2
  11. package/package.json +41 -36
  12. package/packages/datadog-esbuild/index.js +16 -70
  13. package/packages/datadog-esbuild/src/log.js +2 -29
  14. package/packages/datadog-instrumentations/src/ai.js +6 -1
  15. package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
  16. package/packages/datadog-instrumentations/src/cucumber.js +5 -2
  17. package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
  18. package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
  19. package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
  20. package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
  21. package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
  22. package/packages/datadog-instrumentations/src/graphql.js +20 -17
  23. package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +582 -0
  24. package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
  25. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +576 -0
  26. package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
  27. package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
  28. package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
  29. package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
  30. package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
  31. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +8 -0
  32. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +26 -1
  33. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
  34. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
  35. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
  36. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-client.js +30 -0
  37. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-server.js +23 -0
  38. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +61 -0
  39. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
  40. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
  41. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
  42. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +80 -0
  43. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +23 -3
  44. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
  45. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
  46. package/packages/datadog-instrumentations/src/ioredis.js +101 -3
  47. package/packages/datadog-instrumentations/src/microgateway-core.js +1 -2
  48. package/packages/datadog-instrumentations/src/modelcontextprotocol-client.js +21 -0
  49. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +7 -1
  50. package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +41 -0
  51. package/packages/datadog-instrumentations/src/next.js +203 -26
  52. package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
  53. package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
  54. package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
  55. package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
  56. package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
  57. package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
  58. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
  59. package/packages/datadog-instrumentations/src/router.js +35 -12
  60. package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
  61. package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
  62. package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
  63. package/packages/datadog-plugin-aws-lambda/src/arn.js +41 -0
  64. package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
  65. package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
  66. package/packages/datadog-plugin-aws-lambda/src/trigger.js +339 -0
  67. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +7 -0
  68. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +32 -10
  69. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +10 -1
  70. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -0
  71. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +3 -0
  72. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +50 -13
  73. package/packages/datadog-plugin-cypress/src/support.mjs +1353 -0
  74. package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
  75. package/packages/datadog-plugin-express/src/code_origin.js +2 -2
  76. package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
  77. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +20 -7
  78. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +21 -52
  79. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +11 -2
  80. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
  81. package/packages/datadog-plugin-google-cloud-pubsub/src/resource-names.js +24 -0
  82. package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
  83. package/packages/datadog-plugin-http/src/client.js +34 -10
  84. package/packages/datadog-plugin-http2/src/client.js +40 -14
  85. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +28 -2
  86. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +1 -0
  87. package/packages/datadog-plugin-mongodb-core/src/query.js +17 -1
  88. package/packages/datadog-plugin-next/src/index.js +112 -14
  89. package/packages/datadog-plugin-postgres/src/index.js +118 -41
  90. package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
  91. package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +18 -8
  92. package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +49 -13
  93. package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +34 -9
  94. package/packages/datadog-plugin-trpc/src/index.js +15 -0
  95. package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
  96. package/packages/datadog-plugin-trpc/src/request.js +81 -0
  97. package/packages/datadog-plugin-undici/src/index.js +22 -7
  98. package/packages/datadog-plugin-vitest/src/index.js +3 -2
  99. package/packages/datadog-plugin-ws/src/close.js +3 -5
  100. package/packages/datadog-plugin-ws/src/producer.js +1 -4
  101. package/packages/datadog-plugin-ws/src/receiver.js +3 -5
  102. package/packages/datadog-plugin-ws/src/server.js +44 -13
  103. package/packages/datadog-turbopack/index.js +4 -28
  104. package/packages/datadog-turbopack/src/loader.js +14 -452
  105. package/packages/datadog-vite/index.js +537 -0
  106. package/packages/datadog-vite/src/log.js +5 -0
  107. package/packages/datadog-webpack/index.js +3 -55
  108. package/packages/datadog-webpack/src/log.js +2 -29
  109. package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
  110. package/packages/dd-trace/src/aiguard/index.js +1 -1
  111. package/packages/dd-trace/src/aiguard/integrations/index.js +6 -5
  112. package/packages/dd-trace/src/aiguard/sdk.js +8 -2
  113. package/packages/dd-trace/src/aiguard/tags.js +2 -0
  114. package/packages/dd-trace/src/appsec/blocking/index.js +21 -1
  115. package/packages/dd-trace/src/appsec/channels.js +7 -0
  116. package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
  117. package/packages/dd-trace/src/appsec/graphql.js +89 -7
  118. package/packages/dd-trace/src/appsec/handlers/auth.js +1 -3
  119. package/packages/dd-trace/src/appsec/handlers/http-request.js +60 -65
  120. package/packages/dd-trace/src/appsec/handlers/http-response.js +61 -7
  121. package/packages/dd-trace/src/appsec/handlers/payments.js +23 -27
  122. package/packages/dd-trace/src/appsec/index.js +6 -0
  123. package/packages/dd-trace/src/appsec/lambda.js +17 -17
  124. package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -4
  125. package/packages/dd-trace/src/appsec/rasp/index.js +8 -1
  126. package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -2
  127. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +7 -17
  128. package/packages/dd-trace/src/appsec/rasp/ssrf.js +80 -16
  129. package/packages/dd-trace/src/appsec/rasp/utils.js +33 -3
  130. package/packages/dd-trace/src/appsec/recommended.json +1358 -94
  131. package/packages/dd-trace/src/appsec/reporter.js +9 -0
  132. package/packages/dd-trace/src/appsec/sdk/set_user.js +3 -3
  133. package/packages/dd-trace/src/appsec/sdk/track_event.js +4 -4
  134. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
  135. package/packages/dd-trace/src/appsec/user_tracking.js +6 -8
  136. package/packages/dd-trace/src/appsec/waf/index.js +65 -6
  137. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -38
  138. package/packages/dd-trace/src/appsec/waf/waf_manager.js +18 -2
  139. package/packages/dd-trace/src/before-exit.js +32 -0
  140. package/packages/dd-trace/src/bootstrap.js +5 -3
  141. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +15 -2
  142. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
  143. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
  144. package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
  145. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -2
  146. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
  147. package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
  148. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
  149. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
  150. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
  151. package/packages/dd-trace/src/config/config-types.d.ts +3 -0
  152. package/packages/dd-trace/src/config/defaults.js +5 -0
  153. package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -4
  154. package/packages/dd-trace/src/config/index.js +63 -31
  155. package/packages/dd-trace/src/config/parsers.js +44 -0
  156. package/packages/dd-trace/src/config/remote-config-layers.js +38 -0
  157. package/packages/dd-trace/src/config/remote_config.js +2 -1
  158. package/packages/dd-trace/src/config/supported-configurations.json +172 -10
  159. package/packages/dd-trace/src/constants.js +1 -0
  160. package/packages/dd-trace/src/datastreams/fnv.js +27 -0
  161. package/packages/dd-trace/src/datastreams/pathway.js +113 -28
  162. package/packages/dd-trace/src/datastreams/processor.js +5 -4
  163. package/packages/dd-trace/src/debugger/config.js +1 -1
  164. package/packages/dd-trace/src/debugger/devtools_client/request-options.js +7 -9
  165. package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
  166. package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
  167. package/packages/dd-trace/src/debugger/devtools_client/tags.js +1 -1
  168. package/packages/dd-trace/src/debugger/index.js +2 -2
  169. package/packages/dd-trace/src/debugger/inspect-segment.js +3 -2
  170. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +6 -2
  171. package/packages/dd-trace/src/debugger/probe_sampler.js +39 -17
  172. package/packages/dd-trace/src/debugger/unsupported-runtime.js +2 -0
  173. package/packages/dd-trace/src/exporter.js +0 -11
  174. package/packages/dd-trace/src/exporters/common/request.js +81 -48
  175. package/packages/dd-trace/src/exporters/common/retry.js +12 -7
  176. package/packages/dd-trace/src/exporters/common/url.js +1 -1
  177. package/packages/dd-trace/src/git_metadata.js +2 -1
  178. package/packages/dd-trace/src/id.js +1 -1
  179. package/packages/dd-trace/src/index.js +6 -3
  180. package/packages/dd-trace/src/lambda/facade.js +75 -0
  181. package/packages/dd-trace/src/lambda/handler.js +3 -41
  182. package/packages/dd-trace/src/lambda/index.js +38 -15
  183. package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
  184. package/packages/dd-trace/src/lambda/wrap.js +44 -0
  185. package/packages/dd-trace/src/llmobs/constants/tags.js +2 -0
  186. package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
  187. package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
  188. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
  189. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +54 -3
  190. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +81 -1
  191. package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
  192. package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
  193. package/packages/dd-trace/src/llmobs/sdk.js +19 -0
  194. package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
  195. package/packages/dd-trace/src/llmobs/tagger.js +22 -0
  196. package/packages/dd-trace/src/log/channels.js +4 -0
  197. package/packages/dd-trace/src/log/writer.js +6 -1
  198. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +7 -0
  199. package/packages/dd-trace/src/openfeature/configuration_source.js +55 -27
  200. package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
  201. package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
  202. package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
  203. package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
  204. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
  205. package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
  206. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
  207. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
  208. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
  209. package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
  210. package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
  211. package/packages/dd-trace/src/opentelemetry/span.js +2 -2
  212. package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
  213. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
  214. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
  215. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
  216. package/packages/dd-trace/src/opentracing/tracer.js +24 -0
  217. package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
  218. package/packages/dd-trace/src/plugin_manager.js +34 -7
  219. package/packages/dd-trace/src/plugins/ci_plugin.js +143 -17
  220. package/packages/dd-trace/src/plugins/index.js +8 -0
  221. package/packages/dd-trace/src/plugins/plugin.js +4 -2
  222. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  223. package/packages/dd-trace/src/plugins/util/ci.js +52 -1
  224. package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
  225. package/packages/dd-trace/src/plugins/util/git.js +263 -82
  226. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +80 -56
  227. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
  228. package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
  229. package/packages/dd-trace/src/plugins/util/tags.js +6 -0
  230. package/packages/dd-trace/src/plugins/util/test.js +92 -40
  231. package/packages/dd-trace/src/plugins/util/url.js +18 -7
  232. package/packages/dd-trace/src/plugins/util/user-provided-git.js +6 -6
  233. package/packages/dd-trace/src/plugins/util/web.js +65 -10
  234. package/packages/dd-trace/src/process-tags/index.js +1 -1
  235. package/packages/dd-trace/src/profiler.js +74 -12
  236. package/packages/dd-trace/src/profiling/profiler.js +30 -2
  237. package/packages/dd-trace/src/profiling/profilers/space.js +3 -1
  238. package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
  239. package/packages/dd-trace/src/profiling/remote-config.js +354 -0
  240. package/packages/dd-trace/src/profiling/runtime-capabilities.js +11 -0
  241. package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
  242. package/packages/dd-trace/src/propagation-hash/index.js +7 -0
  243. package/packages/dd-trace/src/proxy.js +46 -54
  244. package/packages/dd-trace/src/span_processor.js +20 -0
  245. package/packages/dd-trace/src/startup-log.js +8 -6
  246. package/packages/dd-trace/src/telemetry/metrics.js +2 -1
  247. package/packages/dd-trace/src/tracer.js +0 -2
  248. package/packages/dd-trace/src/web-tags-cache.js +8 -9
  249. package/register.js +2 -1
  250. package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
  251. package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
  252. package/vendor/dist/@datadog/flagging-core/index.js +1 -0
  253. package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
  254. package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
  255. package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
  256. package/vendor/dist/@datadog/source-map/LICENSE +1 -0
  257. package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
  258. package/vendor/dist/@opentelemetry/core/LICENSE +220 -1
  259. package/vendor/dist/@opentelemetry/core/index.js +1 -1
  260. package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
  261. package/vendor/dist/escape-string-regexp/LICENSE +13 -0
  262. package/vendor/dist/esquery/LICENSE +2 -0
  263. package/vendor/dist/https-proxy-agent/LICENSE +80 -1
  264. package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
  265. package/vendor/dist/jest-docblock/LICENSE +16 -0
  266. package/vendor/dist/jsonpath-plus/LICENSE +13 -0
  267. package/vendor/dist/limiter/LICENSE +2 -0
  268. package/vendor/dist/lodash.sortby/LICENSE +2 -0
  269. package/vendor/dist/lru-cache/LICENSE +13 -0
  270. package/vendor/dist/meriyah/LICENSE +13 -0
  271. package/vendor/dist/module-details-from-path/LICENSE +2 -0
  272. package/vendor/dist/mutexify/promise/LICENSE +28 -0
  273. package/vendor/dist/pprof-format/LICENSE +13 -0
  274. package/vendor/dist/pprof-format/index.js +1 -1
  275. package/vendor/dist/protobufjs/LICENSE +219 -0
  276. package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
  277. package/vendor/dist/proxy-from-env/LICENSE +13 -0
  278. package/vendor/dist/retry/LICENSE +2 -0
  279. package/vendor/dist/rfdc/LICENSE +2 -0
  280. package/vendor/dist/semifies/LICENSE +3 -1
  281. package/vendor/dist/shell-quote/LICENSE +3 -1
  282. package/vendor/dist/source-map/LICENSE +1 -0
  283. package/vendor/dist/source-map/lib/util/LICENSE +1 -0
  284. package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
  285. package/vendor/dist/ttl-set/LICENSE +28 -0
  286. package/vite.d.ts +7 -0
  287. package/vite.js +3 -0
  288. package/ci/diagnose.js +0 -2215
  289. package/ci/runbook.md +0 -299
  290. package/ci/test-optimization-validation/approval-artifacts.js +0 -175
  291. package/ci/test-optimization-validation/approval.js +0 -386
  292. package/ci/test-optimization-validation/artifact-id.js +0 -18
  293. package/ci/test-optimization-validation/blocker-category.js +0 -24
  294. package/ci/test-optimization-validation/bounded-json.js +0 -120
  295. package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
  296. package/ci/test-optimization-validation/ci-discovery.js +0 -192
  297. package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
  298. package/ci/test-optimization-validation/ci-remediation.js +0 -283
  299. package/ci/test-optimization-validation/cli.js +0 -954
  300. package/ci/test-optimization-validation/command-blocker.js +0 -377
  301. package/ci/test-optimization-validation/command-output-policy.js +0 -188
  302. package/ci/test-optimization-validation/command-runner.js +0 -649
  303. package/ci/test-optimization-validation/environment.js +0 -88
  304. package/ci/test-optimization-validation/executable-approval.js +0 -47
  305. package/ci/test-optimization-validation/executable.js +0 -244
  306. package/ci/test-optimization-validation/execution-lock.js +0 -70
  307. package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
  308. package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
  309. package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
  310. package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
  311. package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
  312. package/ci/test-optimization-validation/generated-file-policy.js +0 -63
  313. package/ci/test-optimization-validation/generated-files.js +0 -425
  314. package/ci/test-optimization-validation/generated-test-contract.js +0 -284
  315. package/ci/test-optimization-validation/generated-verifier.js +0 -235
  316. package/ci/test-optimization-validation/literal-environment.js +0 -56
  317. package/ci/test-optimization-validation/literal-glob.js +0 -52
  318. package/ci/test-optimization-validation/manifest-loader.js +0 -116
  319. package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
  320. package/ci/test-optimization-validation/manifest-schema.js +0 -695
  321. package/ci/test-optimization-validation/offline-fixtures.js +0 -335
  322. package/ci/test-optimization-validation/offline-output.js +0 -406
  323. package/ci/test-optimization-validation/package-check.js +0 -97
  324. package/ci/test-optimization-validation/payload-normalizer.js +0 -72
  325. package/ci/test-optimization-validation/plan-writer.js +0 -541
  326. package/ci/test-optimization-validation/preflight-runner.js +0 -186
  327. package/ci/test-optimization-validation/project-build-artifact.js +0 -31
  328. package/ci/test-optimization-validation/redaction.js +0 -319
  329. package/ci/test-optimization-validation/report-writer.js +0 -666
  330. package/ci/test-optimization-validation/result-semantics.js +0 -103
  331. package/ci/test-optimization-validation/runner-command.js +0 -264
  332. package/ci/test-optimization-validation/runner-contract.js +0 -695
  333. package/ci/test-optimization-validation/safe-files.js +0 -202
  334. package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
  335. package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
  336. package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
  337. package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
  338. package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
  339. package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
  340. package/ci/test-optimization-validation/source-text.js +0 -84
  341. package/ci/test-optimization-validation/static-diagnosis.js +0 -166
  342. package/ci/test-optimization-validation/test-output.js +0 -120
  343. package/ci/test-optimization-validation/validation-blocker.js +0 -21
  344. package/ci/validate-test-optimization.js +0 -3
  345. package/packages/datadog-esbuild/src/resolver.js +0 -284
  346. package/packages/datadog-esbuild/src/utils.js +0 -318
  347. package/packages/datadog-plugin-cypress/src/support.js +0 -1348
  348. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
  349. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
  350. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
  351. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
  352. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
@@ -0,0 +1,354 @@
1
+ 'use strict'
2
+
3
+ const { normalizeService } = require('../config/normalize-service')
4
+ const applyRemoteConfig = require('../config/remote-config-layers')
5
+ const log = require('../log')
6
+ const { allocationProfilingAvailable, cpuProfilingAvailable } = require('./runtime-capabilities')
7
+
8
+ const PRODUCT = 'APM_PROFILING'
9
+
10
+ /** @typedef {'cpuTime' | 'wallTime' | 'heapSize' | 'heapObjects' | 'allocations'} ProfileType */
11
+
12
+ // Keep every mapped profile type here; parsing is derived from this list. Profile types Node.js
13
+ // can't collect, like locks and exceptions, are ignored. So are CPU time and allocations where this
14
+ // runtime can't collect them, as the tracer configuration would turn them off again.
15
+ const PROFILE_TYPES = /** @type {ProfileType[]} */ (['wallTime', 'heapSize', 'heapObjects'])
16
+ if (cpuProfilingAvailable) PROFILE_TYPES.unshift('cpuTime')
17
+ if (allocationProfilingAvailable) PROFILE_TYPES.push('allocations')
18
+
19
+ // Profile types collected by the heap profiler.
20
+ const HEAP_PROFILE_TYPES = /** @type {ProfileType[]} */ (['heapSize', 'heapObjects', 'allocations'])
21
+
22
+ // Running profiler types (see the profiling layer's getRunningTypes()) by the profile types they serve.
23
+ const PROFILE_TYPES_BY_RUNNING_TYPE = /** @type {Record<string, ProfileType[]>} */ ({
24
+ cpu: ['cpuTime'],
25
+ wall: ['wallTime'],
26
+ space: ['heapSize', 'heapObjects'],
27
+ allocations: ['allocations'],
28
+ })
29
+
30
+ // Specificity levels of a target, from least to most specific, following the profiling Remote
31
+ // Config payload merging ADR: other tags < env < service < workload < container name < pod <
32
+ // container ID. Infrastructure levels are recognized by the tag names the Datadog agent assigns.
33
+ const LEVEL_OTHER_TAGS = 1
34
+ const LEVEL_ENV = 2
35
+ const LEVEL_SERVICE = 3
36
+ /** @type {Map<string, number>} */
37
+ const LEVEL_BY_TAG_NAME = new Map()
38
+ for (const [level, names] of /** @type {[number, string[]][]} */ ([
39
+ [4, ['kube_deployment', 'kube_replica_set', 'kube_stateful_set', 'kube_daemon_set', 'kube_job', 'kube_cronjob',
40
+ 'kube_argo_rollout', 'oshift_deployment', 'task_family']],
41
+ [5, ['kube_container_name', 'container_name', 'ecs_container_name']],
42
+ [6, ['pod_name', 'task_arn']],
43
+ [7, ['container_id']],
44
+ ])) {
45
+ for (const name of names) LEVEL_BY_TAG_NAME.set(name, level)
46
+ }
47
+ // A target's level outranks any number of conditions, which only break ties within a level.
48
+ const CONDITIONS_PER_LEVEL = 1000
49
+
50
+ /**
51
+ * @typedef {ReturnType<import('../config')>} Config
52
+ * @typedef {Partial<Record<ProfileType, boolean>>} RequestedProfilers
53
+ * @typedef {{ service?: string, env?: string, tags: string[] }} Target
54
+ * @typedef {{
55
+ * id: string,
56
+ * profilers: RequestedProfilers,
57
+ * targets: Target[],
58
+ * }} ProfilingConfig
59
+ */
60
+
61
+ /**
62
+ * Apply matching profiling configs; omitted fields use local settings.
63
+ *
64
+ * @param {import('../remote_config')} rc - RemoteConfig instance
65
+ * @param {Config} config - Tracer configuration
66
+ * @param {() => string[]} getRunningProfileTypes - Types of the running profilers
67
+ */
68
+ function enable (rc, config, getRunningProfileTypes) {
69
+ // The libdatadog fetcher used in agentless mode doesn't know APM_PROFILING yet, and would log an
70
+ // error for it.
71
+ if (config.DD_AGENTLESS_ENABLED) return
72
+
73
+ /** @type {Map<string, ProfilingConfig>} */
74
+ const configs = new Map()
75
+ // Match the initially empty profiling layer.
76
+ let lastSettings = 'null'
77
+ /**
78
+ * Profile types running under local configuration, captured before the first profiling content
79
+ * is applied. Known limitations: a profiler that SSI heuristics start later, or that APM_TRACING
80
+ * enabled earlier, is not told apart from local configuration.
81
+ *
82
+ * @type {Set<string> | undefined}
83
+ */
84
+ let localProfileTypes
85
+
86
+ rc.subscribeProducts(PRODUCT)
87
+ rc.setBatchHandler([PRODUCT], (transaction) => {
88
+ for (const item of transaction.toUnapply) {
89
+ configs.delete(item.id)
90
+ transaction.ack(item.path)
91
+ }
92
+
93
+ for (const item of [...transaction.toApply, ...transaction.toModify]) {
94
+ /** @type {string[]} */
95
+ const problems = []
96
+ const parsed = parse(item.id, item.file, problems)
97
+ if (parsed === undefined) {
98
+ configs.delete(item.id)
99
+ } else {
100
+ configs.set(item.id, parsed)
101
+ }
102
+
103
+ if (problems.length === 0) {
104
+ transaction.ack(item.path)
105
+ } else {
106
+ // Report partial failures while still applying valid fields.
107
+ const reason = problems.join('; ')
108
+ log.debug('[profiling/remote-config] Invalid profiling configuration %s: %s', item.id, reason)
109
+ transaction.error(item.path, reason)
110
+ }
111
+ }
112
+
113
+ // Skip unchanged settings to avoid redundant telemetry and config publishes.
114
+ // toSettings inserts keys in a fixed order, making JSON equality stable.
115
+ const merged = merge(configs.values(), config)
116
+ if (configs.size > 0) {
117
+ localProfileTypes ??= toProfileTypes(getRunningProfileTypes())
118
+ }
119
+ const settings = toSettings(merged, localProfileTypes ?? new Set())
120
+ const serialized = JSON.stringify(settings)
121
+ if (serialized === lastSettings) return
122
+ lastSettings = serialized
123
+
124
+ applyRemoteConfig(config, PRODUCT, settings)
125
+ })
126
+ }
127
+
128
+ /**
129
+ * @param {string} id - Remote config id
130
+ * @param {unknown} file - Remote config payload
131
+ * @param {string[]} problems - Validation errors to report
132
+ * @returns {ProfilingConfig | undefined} undefined for payloads without profiling content or with
133
+ * invalid targets
134
+ */
135
+ function parse (id, file, problems) {
136
+ if (!isObject(file)) {
137
+ problems.push('payload is not an object')
138
+ return
139
+ }
140
+
141
+ const { profilers, settings, targets } = file
142
+ if (profilers === undefined && settings === undefined) return
143
+
144
+ const parsedTargets = parseTargets(targets, problems)
145
+ if (parsedTargets === undefined) return
146
+
147
+ const parsedProfilers = parseProfilers(profilers, problems)
148
+ if (settings !== undefined && !isObject(settings)) problems.push('settings is not an object')
149
+ return { id, profilers: parsedProfilers, targets: parsedTargets }
150
+ }
151
+
152
+ /**
153
+ * @param {unknown} profilers - The payload's `profilers` section
154
+ * @param {string[]} problems - Validation errors to report
155
+ * @returns {RequestedProfilers}
156
+ */
157
+ function parseProfilers (profilers, problems) {
158
+ /** @type {RequestedProfilers} */
159
+ const parsed = {}
160
+ if (!isObject(profilers)) {
161
+ if (profilers !== undefined) problems.push('profilers is not an object')
162
+ return parsed
163
+ }
164
+ for (const type of PROFILE_TYPES) {
165
+ const value = profilers[type]
166
+ if (typeof value === 'boolean') {
167
+ parsed[type] = value
168
+ } else if (value !== undefined) {
169
+ problems.push(`profilers.${type} is not a boolean`)
170
+ }
171
+ }
172
+ return parsed
173
+ }
174
+
175
+ /**
176
+ * @param {unknown} targets - The payload's `targets` section
177
+ * @param {string[]} problems - Validation errors to report
178
+ * @returns {Target[] | undefined} undefined if the config must be dropped
179
+ */
180
+ function parseTargets (targets, problems) {
181
+ if (targets === undefined) return []
182
+ if (!Array.isArray(targets)) {
183
+ problems.push('targets is not an array')
184
+ return
185
+ }
186
+
187
+ /** @type {Target[]} */
188
+ const parsed = []
189
+ for (let index = 0; index < targets.length; index++) {
190
+ const target = targets[index]
191
+ const { service, env, tags = [] } = isObject(target) ? target : {}
192
+ if (!isObject(target) ||
193
+ (service !== undefined && typeof service !== 'string') ||
194
+ (env !== undefined && typeof env !== 'string') ||
195
+ !Array.isArray(tags) || !tags.every(tag => typeof tag === 'string')) {
196
+ problems.push(`targets[${index}] is invalid`)
197
+ continue
198
+ }
199
+ parsed.push({ service, env, tags })
200
+ }
201
+
202
+ // Reject an all-invalid target list rather than treating it as untargeted.
203
+ if (parsed.length === 0 && targets.length !== 0) {
204
+ problems.push('no valid targets')
205
+ return
206
+ }
207
+ return parsed
208
+ }
209
+
210
+ /**
211
+ * Merge the received configs field by field, with more specific targets winning. Remote Config only
212
+ * delivers configs that apply to this tracer, so every config is merged; targets only rank them.
213
+ *
214
+ * @param {Iterable<ProfilingConfig>} configs - Parsed remote configs
215
+ * @param {Config} config - Tracer configuration
216
+ */
217
+ function merge (configs, config) {
218
+ /** @type {{ specificity: number, config: ProfilingConfig }[]} */
219
+ const ranked = []
220
+ for (const profilingConfig of configs) {
221
+ ranked.push({ specificity: getSpecificity(profilingConfig.targets, config), config: profilingConfig })
222
+ }
223
+ // Merge least specific first; break ties by ID so delivery order doesn't matter.
224
+ ranked.sort((a, b) => a.specificity - b.specificity || (a.config.id < b.config.id ? -1 : 1))
225
+
226
+ /** @type {RequestedProfilers} */
227
+ const profilers = {}
228
+ for (const { config: profilingConfig } of ranked) {
229
+ Object.assign(profilers, profilingConfig.profilers)
230
+ }
231
+ return profilers
232
+ }
233
+
234
+ /**
235
+ * Specificity of the most specific target that is consistent with this tracer's service and env,
236
+ * or 0 if there is none. A config's targets can name several scopes, and the one it was delivered
237
+ * for has to be consistent with them. Tag conditions are assumed to hold: the agent has matched
238
+ * them, and the tracer doesn't know every tag it's matched by (e.g. Kubernetes tags).
239
+ *
240
+ * A target ranks by its most specific condition, and then by its number of conditions.
241
+ *
242
+ * @param {Target[]} targets - Targets of one config
243
+ * @param {Config} config - Tracer configuration
244
+ */
245
+ function getSpecificity (targets, config) {
246
+ let specificity = 0
247
+ for (const { service, env, tags } of targets) {
248
+ const hasService = service !== undefined && service !== '*'
249
+ const hasEnv = env !== undefined && env !== '*'
250
+ // The agent and the backend match normalized values, so compare normalized values too.
251
+ if ((hasService && normalizeService(service) !== normalizeService(config.service)) ||
252
+ (hasEnv && normalizeService(env) !== normalizeService(config.env))) {
253
+ continue
254
+ }
255
+
256
+ let level = 0
257
+ if (hasService) level = LEVEL_SERVICE
258
+ else if (hasEnv) level = LEVEL_ENV
259
+ for (const tag of tags) {
260
+ const separator = tag.indexOf(':')
261
+ const name = (separator === -1 ? tag : tag.slice(0, separator)).toLowerCase()
262
+ level = Math.max(level, LEVEL_BY_TAG_NAME.get(name) ?? LEVEL_OTHER_TAGS)
263
+ }
264
+ const conditions = Number(hasService) + Number(hasEnv) + tags.length
265
+ specificity = Math.max(specificity, level * CONDITIONS_PER_LEVEL + conditions)
266
+ }
267
+ return specificity
268
+ }
269
+
270
+ /**
271
+ * @param {string[]} runningTypes - Types of the running profilers
272
+ * @returns {Set<string>} The profile types they serve
273
+ */
274
+ function toProfileTypes (runningTypes) {
275
+ const profileTypes = new Set()
276
+ for (const runningType of runningTypes) {
277
+ const served = PROFILE_TYPES_BY_RUNNING_TYPE[runningType]
278
+ if (served === undefined) continue
279
+ for (const profileType of served) {
280
+ profileTypes.add(profileType)
281
+ }
282
+ }
283
+ return profileTypes
284
+ }
285
+
286
+ /**
287
+ * Map payload fields to profiling environment variables.
288
+ *
289
+ * @param {RequestedProfilers} requested - Profile types requested by the merged remote configs
290
+ * @param {Set<string>} localProfileTypes - Profile types running under local configuration
291
+ * @returns {Partial<Record<import('../config/helper').SupportedEnvKey, string>> | null} null if no fields are set
292
+ */
293
+ function toSettings (requested, localProfileTypes) {
294
+ if (PROFILE_TYPES.every(type => requested[type] === undefined)) return null
295
+
296
+ // Turning profiling on also starts every profile type that is on by default, so omitted types
297
+ // that weren't running locally are turned off; omitted types that were keep their local value.
298
+ /** @type {RequestedProfilers} */
299
+ const profilers = { ...requested }
300
+ const enablesProfiling = PROFILE_TYPES.some(type => requested[type] === true)
301
+ if (enablesProfiling) {
302
+ for (const type of PROFILE_TYPES) {
303
+ if (profilers[type] === undefined && !localProfileTypes.has(type)) profilers[type] = false
304
+ }
305
+ }
306
+ const { cpuTime, wallTime, heapSize, heapObjects, allocations } = profilers
307
+ // A profile type is on when requested, or when omitted and running locally. A type that is on
308
+ // keeps the profiler that collects it running, even if the payload turns another type of that
309
+ // profiler off.
310
+ /** @param {ProfileType} type */
311
+ const isOn = type => profilers[type] ?? localProfileTypes.has(type)
312
+
313
+ /** @type {Partial<Record<import('../config/helper').SupportedEnvKey, string>>} */
314
+ const envs = {}
315
+ // The wall profiler also samples CPU time.
316
+ if (wallTime || cpuTime) {
317
+ envs.DD_PROFILING_WALLTIME_ENABLED = 'true'
318
+ } else if (wallTime === false && !isOn('cpuTime')) {
319
+ envs.DD_PROFILING_WALLTIME_ENABLED = 'false'
320
+ }
321
+ if (cpuTime !== undefined) {
322
+ envs.DD_PROFILING_CPU_ENABLED = String(cpuTime)
323
+ }
324
+ // The heap profiler collects heap sizes, live objects and, in allocation mode, allocations.
325
+ if (heapSize || heapObjects || allocations) {
326
+ envs.DD_PROFILING_HEAP_ENABLED = 'true'
327
+ } else if ((heapSize === false || heapObjects === false) && !HEAP_PROFILE_TYPES.some(isOn)) {
328
+ envs.DD_PROFILING_HEAP_ENABLED = 'false'
329
+ }
330
+ if (allocations !== undefined) {
331
+ envs.DD_PROFILING_ALLOCATION_ENABLED = String(allocations)
332
+ }
333
+
334
+ // Any true enables profiling, and no type left on disables it; otherwise use the local setting.
335
+ if (enablesProfiling) {
336
+ envs.DD_PROFILING_ENABLED = 'true'
337
+ } else if (!PROFILE_TYPES.some(isOn)) {
338
+ envs.DD_PROFILING_ENABLED = 'false'
339
+ }
340
+
341
+ return envs
342
+ }
343
+
344
+ /**
345
+ * @param {unknown} value
346
+ * @returns {value is Record<string, unknown>}
347
+ */
348
+ function isObject (value) {
349
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
350
+ }
351
+
352
+ module.exports = {
353
+ enable,
354
+ }
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ const { NODE_MAJOR } = require('../../../../version')
4
+
5
+ // Profiling features that depend on the runtime. The tracer configuration turns them off where
6
+ // they're unavailable, and remote configuration ignores requests for the profile types they collect.
7
+ module.exports = {
8
+ // Allocation profiling needs a sampling hook only available on Node.js 26+.
9
+ allocationProfilingAvailable: NODE_MAJOR >= 26,
10
+ cpuProfilingAvailable: process.platform !== 'win32',
11
+ }
@@ -2,6 +2,7 @@
2
2
 
3
3
  const { HTTP_METHOD, HTTP_ROUTE, RESOURCE_NAME, SPAN_TYPE } = require('../../../../ext/tags')
4
4
  const { WEB } = require('../../../../ext/types')
5
+ const { INSTRUMENTATION_HTTP_RESOURCE, otelHttpResourceName } = require('../plugins/util/http-otel-semantics')
5
6
 
6
7
  function isWebServerSpan (tags) {
7
8
  return tags[SPAN_TYPE] === WEB
@@ -18,10 +19,9 @@ function endpointNameFromTags (tags) {
18
19
  }
19
20
 
20
21
  // The endpoint name a web-server span's tag bag yields changes over the span's
21
- // lifetime: plugins set `http.method` when the request arrives and only add
22
- // `http.route` (and often `resource.name`) once framework routing has resolved
23
- // the URL. Returns the endpoint name once its value looks stable, or undefined
24
- // while it is still an interim placeholder.
22
+ // lifetime: plugins set `http.method` when the request arrives and refine
23
+ // `http.route` and `resource.name` as nested framework routes resolve.
24
+ // Returns the current endpoint, or undefined for a method-only placeholder.
25
25
  //
26
26
  // Consumers that read the tag bag lazily (the wall profiler resolves endpoint
27
27
  // labels at serialization time) see the settled value for free and only need
@@ -44,7 +44,8 @@ function finalEndpoint (tags) {
44
44
  // the string building inside endpointNameFromTags.
45
45
  if (tags[RESOURCE_NAME] == null && tags[HTTP_ROUTE] == null) return
46
46
  const endpoint = endpointNameFromTags(tags)
47
- if (!endpoint || endpoint === tags[HTTP_METHOD]) return
47
+ if (!endpoint || endpoint === tags[HTTP_METHOD] ||
48
+ (endpoint === tags[INSTRUMENTATION_HTTP_RESOURCE] && endpoint === otelHttpResourceName(tags[HTTP_METHOD]))) return
48
49
  return endpoint
49
50
  }
50
51
 
@@ -47,6 +47,13 @@ class PropagationHashManager {
47
47
  }
48
48
  }
49
49
 
50
+ /**
51
+ * @returns {string | null} The container tags hash the agent last reported, if any
52
+ */
53
+ getContainerTagsHash () {
54
+ return this._containerTagsHash
55
+ }
56
+
50
57
  /**
51
58
  * Get the propagation hash as a BigInt
52
59
  * @returns {bigint | null} The propagation hash or null if disabled/unavailable
@@ -5,11 +5,10 @@ const uuid = require('../../../vendor/dist/crypto-randomuuid')
5
5
  const NoopProxy = require('./noop/proxy')
6
6
  const DatadogTracer = require('./tracer')
7
7
  const getConfig = require('./config')
8
- const { getEnvironmentVariable } = require('./config/helper')
9
8
  const { reseed } = require('./id')
10
9
  const runtimeMetrics = require('./runtime_metrics')
11
10
  const log = require('./log')
12
- const { setStartupLogPluginManager, startupLog } = require('./startup-log')
11
+ const { setStartupLogConfig, setStartupLogPluginManager, startupLog } = require('./startup-log')
13
12
  const telemetry = require('./telemetry')
14
13
  const nomenclature = require('./service-naming')
15
14
  const PluginManager = require('./plugin_manager')
@@ -23,7 +22,6 @@ const {
23
22
  } = require('./serverless')
24
23
  const { flushServerlessTelemetry, registerTelemetryFlusher } = require('./flush')
25
24
  const processTags = require('./process-tags')
26
- const { isTrue } = require('./util')
27
25
  const {
28
26
  setBaggageItem,
29
27
  getBaggageItem,
@@ -32,20 +30,6 @@ const {
32
30
  removeAllBaggageItems,
33
31
  } = require('./baggage')
34
32
 
35
- const VALIDATION_MANIFEST_ENV = '_DD_TEST_OPTIMIZATION_VALIDATION_MANIFEST_FILE'
36
- const VALIDATION_MODE_ENV = '_DD_TEST_OPTIMIZATION_VALIDATION_MODE'
37
- const VALIDATION_OUTPUT_ENV = '_DD_TEST_OPTIMIZATION_VALIDATION_OUTPUT_DIR'
38
- const ORDINARY_TRACING_DISABLED_MESSAGE =
39
- 'Ordinary dd-trace application tracing initialization is disabled during offline Test Optimization validation. ' +
40
- 'The CI test process must initialize through dd-trace/ci/init.'
41
- const OFFLINE_VALIDATION_EXPORTERS = new Set([
42
- 'ci_validation',
43
- 'cucumber_worker',
44
- 'jest_worker',
45
- 'mocha_worker',
46
- 'playwright_worker',
47
- 'vitest_worker',
48
- ])
49
33
  const OPENFEATURE_STATE_NOOP = 0
50
34
  const OPENFEATURE_STATE_LAZY = 1
51
35
  const OPENFEATURE_STATE_ACTIVE = 2
@@ -123,6 +107,9 @@ class Tracer extends NoopProxy {
123
107
  /** @type {boolean} */
124
108
  #configPublished = false
125
109
 
110
+ /** @type {boolean} */
111
+ #iastUnavailable = false
112
+
126
113
  constructor () {
127
114
  super()
128
115
 
@@ -166,11 +153,6 @@ class Tracer extends NoopProxy {
166
153
 
167
154
  this._initialized = true
168
155
 
169
- if (isOfflineTestOptimizationValidation() && !isOfflineValidationExporter(options)) {
170
- process.stderr.write(`${ORDINARY_TRACING_DISABLED_MESSAGE}\n`)
171
- return this
172
- }
173
-
174
156
  try {
175
157
  const config = getConfig(options) // TODO: support dynamic code config
176
158
 
@@ -202,7 +184,7 @@ class Tracer extends NoopProxy {
202
184
  : undefined
203
185
  telemetry.start(config, this._pluginManager, telemetryLogOptions)
204
186
 
205
- if (config.dogstatsd && !config.DD_AGENTLESS_ENABLED && !isOfflineTestOptimizationValidation()) {
187
+ if (config.dogstatsd && !config.DD_AGENTLESS_ENABLED) {
206
188
  // Custom Metrics
207
189
  lazyProxy(this, 'dogstatsd', () => require('./dogstatsd').CustomMetrics, config)
208
190
  }
@@ -227,6 +209,9 @@ class Tracer extends NoopProxy {
227
209
  this.#updateDebugger(config, rc)
228
210
  })
229
211
 
212
+ // Subscribe even when profiling is off so RC can enable it.
213
+ require('./profiling/remote-config').enable(rc, config, profiler.getRunningProfileTypes)
214
+
230
215
  rc.setProductHandler('AGENT_CONFIG', (action, conf) => {
231
216
  if (!conf?.name?.startsWith('flare-log-level.')) return
232
217
 
@@ -277,14 +262,16 @@ class Tracer extends NoopProxy {
277
262
  // OTel logs/metrics pipelines must be initialized BEFORE runtimeMetrics.start so that
278
263
  // when the OTLP runtime metrics module calls metrics.getMeterProvider(), it gets the
279
264
  // real provider, otherwise instruments register on the noop provider and never export.
265
+ let logs
266
+ let metrics
280
267
  if (config.DD_LOGS_OTEL_ENABLED) {
281
268
  const { initializeOpenTelemetryLogs } = require('./opentelemetry/logs')
282
- initializeOpenTelemetryLogs(config)
269
+ logs = initializeOpenTelemetryLogs(config)
283
270
  }
284
271
 
285
272
  if (config.DD_METRICS_OTEL_ENABLED) {
286
273
  const { initializeOpenTelemetryMetrics } = require('./opentelemetry/metrics')
287
- initializeOpenTelemetryMetrics(config)
274
+ metrics = initializeOpenTelemetryMetrics(config)
288
275
  }
289
276
 
290
277
  if (config.runtimeMetrics.enabled) {
@@ -294,9 +281,12 @@ class Tracer extends NoopProxy {
294
281
  registerTelemetryFlusher(done => runtimeMetrics.flush(done), { afterTrace: true })
295
282
  }
296
283
 
297
- this.#updateTracing(config)
284
+ const tracing = this.#updateTracing(config)
285
+ setStartupLogConfig(config, { ...tracing, logs, metrics })
286
+ setStartupLogPluginManager(this._pluginManager)
287
+ startupLog()
298
288
 
299
- if (config.iast.DD_IAST_ENABLED) {
289
+ if (config.iast.DD_IAST_ENABLED && !this.#iastUnavailable) {
300
290
  this._modules.rewriter.enable(config)
301
291
  }
302
292
 
@@ -351,6 +341,16 @@ class Tracer extends NoopProxy {
351
341
  log.error(BUNDLED_OPENSSL_WARNING)
352
342
  }
353
343
 
344
+ // Load code before the image snapshot; identity and metadata storage stay in /run.
345
+ const storeTracerMetadata = require('./tracer_metadata')
346
+ if (config.DD_TRACE_ENABLED) {
347
+ try {
348
+ require('@datadog/libdatadog-extras').maybeLoad('process-discovery')
349
+ } catch {
350
+ // Native metadata is optional; /run retains its existing availability handling.
351
+ }
352
+ }
353
+
354
354
  const ch = channel('http.server.request.start')
355
355
 
356
356
  const onHttpRequest = ({ request }) => {
@@ -360,7 +360,6 @@ class Tracer extends NoopProxy {
360
360
  reseed()
361
361
  channel('datadog:identity:update').publish(config)
362
362
  if (this._tracingInitialized) {
363
- const storeTracerMetadata = require('./tracer_metadata')
364
363
  const metadata = storeTracerMetadata(config)
365
364
  if (metadata === undefined) {
366
365
  log.warn('Could not store tracer configuration for service discovery')
@@ -409,8 +408,11 @@ class Tracer extends NoopProxy {
409
408
 
410
409
  /**
411
410
  * @param {import('./config/config-base')} config - Tracer configuration
411
+ * @returns {import('./opentelemetry/startup-config').Pipelines | undefined}
412
412
  */
413
413
  #updateTracing (config) {
414
+ /** @type {import('./opentelemetry/startup-config').Pipelines | undefined} */
415
+ let startupPipelines
414
416
  if (config.DD_TRACE_ENABLED !== false) {
415
417
  const aiguardEnabled = config.aiguard.DD_AI_GUARD_ENABLED === true &&
416
418
  config.DD_API_KEY !== undefined &&
@@ -430,10 +432,13 @@ class Tracer extends NoopProxy {
430
432
  ? require('./standalone').configure(config)
431
433
  : undefined
432
434
  this._tracer = new DatadogTracer(config, prioritySampler)
435
+ startupPipelines = this._tracer.getStartupConfig()
433
436
  this.dataStreamsCheckpointer = this._tracer.dataStreamsCheckpointer
434
- lazyProxy(this, 'appsec', () => require('./appsec/sdk'), this._tracer, config)
435
- lazyProxy(this, 'llmobs', () => require('./llmobs/sdk'), this._tracer, this._modules.llmobs, config,
436
- () => this.openfeature)
437
+ if (!config.isCiVisibility) {
438
+ lazyProxy(this, 'appsec', () => require('./appsec/sdk'), this._tracer, config)
439
+ lazyProxy(this, 'llmobs', () => require('./llmobs/sdk'), this._tracer, this._modules.llmobs, config,
440
+ () => this.openfeature)
441
+ }
437
442
 
438
443
  if (aiguardEnabled) {
439
444
  lazyProxy(this, 'aiguard', () => require('./aiguard/sdk'), this._tracer, config)
@@ -443,8 +448,15 @@ class Tracer extends NoopProxy {
443
448
  if (aiguardEnabled) {
444
449
  this._modules.aiguard.enable(this._tracer, config)
445
450
  }
446
- if (config.iast.DD_IAST_ENABLED) {
447
- this._modules.iast.enable(config, this._tracer)
451
+ if (config.iast.DD_IAST_ENABLED && !this.#iastUnavailable) {
452
+ // IAST loads optional native addons that can be missing (e.g. installs without optional
453
+ // dependencies). Disable it for the process lifetime instead of aborting tracer setup.
454
+ try {
455
+ this._modules.iast.enable(config, this._tracer)
456
+ } catch (error) {
457
+ this.#iastUnavailable = true
458
+ log.error('[IAST] Unable to start IAST, it stays disabled', error)
459
+ }
448
460
  }
449
461
  // This needs to be after the IAST module is enabled
450
462
  } else if (this._tracingInitialized) {
@@ -460,11 +472,10 @@ class Tracer extends NoopProxy {
460
472
  this._tracer.configure(config)
461
473
  this._pluginManager.configure(config)
462
474
  dynamicInstrumentation?.configure(config)
463
- setStartupLogPluginManager(this._pluginManager)
464
- startupLog()
465
475
  }
466
476
 
467
477
  initializeServerlessTelemetry(this._serverlessTelemetry)
478
+ return startupPipelines
468
479
  }
469
480
 
470
481
  /**
@@ -539,25 +550,6 @@ class Tracer extends NoopProxy {
539
550
  }
540
551
  }
541
552
 
542
- /**
543
- * Checks the private filesystem-only Test Optimization validation mode.
544
- *
545
- */
546
- function isOfflineTestOptimizationValidation () {
547
- return isTrue(getEnvironmentVariable(VALIDATION_MODE_ENV)) &&
548
- Boolean(getEnvironmentVariable(VALIDATION_MANIFEST_ENV)) &&
549
- Boolean(getEnvironmentVariable(VALIDATION_OUTPUT_ENV))
550
- }
551
-
552
- /**
553
- * Checks whether initialization selected a filesystem-only Test Optimization exporter.
554
- *
555
- * @param {import('../../../index').TracerOptions} [options] tracer initialization options
556
- */
557
- function isOfflineValidationExporter (options) {
558
- return OFFLINE_VALIDATION_EXPORTERS.has(options?.experimental?.exporter)
559
- }
560
-
561
553
  /**
562
554
  * Discards Node's buffered UUID entropy, so the identity subscribers draw from bytes generated
563
555
  * after the clone resumed.
@@ -31,6 +31,12 @@ function serializeOtlpTraceState (context) {
31
31
  class SpanProcessor {
32
32
  #exportOtlpTraces
33
33
 
34
+ /**
35
+ * @readonly
36
+ * @type {import('./opentelemetry/startup-config').InitializedExporter | undefined}
37
+ */
38
+ #spanMetricsStartupConfig
39
+
34
40
  constructor (exporter, prioritySampler, config, otlpStatsExporter) {
35
41
  this._exporter = exporter
36
42
  this._prioritySampler = prioritySampler
@@ -42,6 +48,12 @@ class SpanProcessor {
42
48
  !config.appsec?.DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED) {
43
49
  const { SpanStatsProcessor } = require('./span_stats')
44
50
  this._stats = new SpanStatsProcessor(config, otlpStatsExporter)
51
+ if (otlpStatsExporter) {
52
+ this.#spanMetricsStartupConfig = {
53
+ protocol: otlpStatsExporter.protocol,
54
+ resourceAttributes: otlpStatsExporter.getStartupResourceAttributes(),
55
+ }
56
+ }
45
57
  }
46
58
 
47
59
  this._spanSampler = new SpanSampler(config.sampler)
@@ -52,6 +64,14 @@ class SpanProcessor {
52
64
  : false
53
65
  }
54
66
 
67
+ /**
68
+ * Returns the OTLP span-metrics configuration accepted during initialization, if active.
69
+ * @returns {import('./opentelemetry/startup-config').InitializedExporter | undefined}
70
+ */
71
+ getSpanMetricsStartupConfig () {
72
+ return this.#spanMetricsStartupConfig
73
+ }
74
+
55
75
  sample (span) {
56
76
  const spanContext = span.context()
57
77
  this._prioritySampler.sample(spanContext)