dd-trace 6.24.0 → 6.26.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
@@ -16,6 +16,8 @@ const INT_ID_SEGMENT = /^(?=.*[0-9])[0-9._-]{3,}$/ // Mixed string with digits a
16
16
  const HEX_SEGMENT = /^(?=.*[0-9])[A-Fa-f0-9]{6,}$/ // Hexadecimal digits of size at least 6 with at least one decimal digit
17
17
  const HEX_ID_SEGMENT = /^(?=.*[0-9])[A-Fa-f0-9._-]{6,}$/ // Mixed string with hex digits and delimiters
18
18
  const SPECIAL_CHARACTER_SEGMENT = /[%&'()*+,:=@]/
19
+ const SCP_STYLE_REPOSITORY_URL = /^(?:[^@/:\s\\]+@)?(?:\[[^@\]/\s\\]+\]|[^@/:\s\\]+):.+$/
20
+ const REPOSITORY_URI_OR_DRIVE = /^(?:[a-z][a-z\d+.-]*:\/\/|[a-z]:[\\/])/i
19
21
 
20
22
  /**
21
23
  * Extract full URL from HTTP request
@@ -37,10 +39,15 @@ function getProtocol (req) {
37
39
  return req.socket?.encrypted ? 'https' : 'http'
38
40
  }
39
41
 
42
+ /**
43
+ * @typedef {object} NormalizedUrlConfig
44
+ * @property {boolean | RegExp} queryStringObfuscation
45
+ */
46
+
40
47
  /**
41
48
  * Obfuscate query string
42
49
  *
43
- * @param {object} config
50
+ * @param {NormalizedUrlConfig} config
44
51
  * @param {string} url
45
52
  */
46
53
  function obfuscateQs (config, url) {
@@ -113,16 +120,14 @@ function getQsObfuscator (config) {
113
120
  * Callers gate this behind `DD_TRACE_OTEL_SEMANTICS_ENABLED`, so the default
114
121
  * (flag off) hot path stays a plain tag assignment.
115
122
  *
116
- * @param {{ queryStringObfuscation?: boolean | string }} config
123
+ * @param {NormalizedUrlConfig} config
117
124
  * @param {string} base `scheme://host[:port]`
118
125
  * @param {string} [pathname] raw request path, may include `?query`
119
126
  * @param {string} strippedUrl `base` + query-stripped path (used when there is no query)
120
127
  */
121
128
  function buildClientHttpUrl (config, base, pathname, strippedUrl) {
122
129
  if (pathname?.includes('?')) {
123
- // `config.queryStringObfuscation` is the raw config value here (client plugins
124
- // don't normalize it the way the server does), so compile it first.
125
- return obfuscateQs({ queryStringObfuscation: getQsObfuscator(config) }, `${base}${pathname}`)
130
+ return obfuscateQs(config, `${base}${pathname}`)
126
131
  }
127
132
  return strippedUrl
128
133
  }
@@ -178,12 +183,17 @@ function calculateHttpEndpoint (url) {
178
183
  : '/'
179
184
  }
180
185
 
186
+ /** @param {string} repositoryUrl */
187
+ function isScpStyleRepositoryUrl (repositoryUrl) {
188
+ return !REPOSITORY_URI_OR_DRIVE.test(repositoryUrl) && SCP_STYLE_REPOSITORY_URL.test(repositoryUrl)
189
+ }
190
+
181
191
  function filterSensitiveInfoFromRepository (repositoryUrl) {
182
192
  if (!repositoryUrl) {
183
193
  return ''
184
194
  }
185
- if (repositoryUrl.startsWith('git@')) {
186
- return repositoryUrl
195
+ if (isScpStyleRepositoryUrl(repositoryUrl)) {
196
+ return repositoryUrl.startsWith('git@') ? repositoryUrl : repositoryUrl.replace(/^[^@/:]+@/, '')
187
197
  }
188
198
 
189
199
  // Remove the username from ssh URLs
@@ -208,5 +218,6 @@ module.exports = {
208
218
  buildClientHttpUrl,
209
219
  calculateHttpEndpoint,
210
220
  filterSensitiveInfoFromRepository,
221
+ isScpStyleRepositoryUrl,
211
222
  extractPathFromUrl, // used by http-otel-semantics decomposeServerUrl fallback (and tests)
212
223
  }
@@ -18,8 +18,8 @@ const {
18
18
  GIT_COMMIT_HEAD_SHA,
19
19
  } = require('./tags')
20
20
 
21
- const { normalizeRef } = require('./ci')
22
- const { filterSensitiveInfoFromRepository } = require('./url')
21
+ const { normalizeCommitSha, normalizeRef } = require('./ci')
22
+ const { filterSensitiveInfoFromRepository, isScpStyleRepositoryUrl } = require('./url')
23
23
 
24
24
  function removeEmptyValues (tagsAndValues) {
25
25
  const filteredTags = {}
@@ -36,7 +36,7 @@ function removeEmptyValues (tagsAndValues) {
36
36
  // https://github.com/jonschlinkert/is-git-url/blob/396965ffabf2f46656c8af4c47bef1d69f09292e/index.js#L9C15-L9C87
37
37
  // The `.git` suffix is optional in this version
38
38
  function validateGitRepositoryUrl (repoUrl) {
39
- return /(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\/?|#[-\w.]+)$/.test(repoUrl)
39
+ return isScpStyleRepositoryUrl(repoUrl) || /(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\/?|#[-\w.]+)$/.test(repoUrl)
40
40
  }
41
41
 
42
42
  function validateGitCommitSha (gitCommitSha) {
@@ -73,7 +73,7 @@ function getUserProviderGitMetadata () {
73
73
 
74
74
  // Key value pairs are grouped in pairs of two
75
75
  return removeEmptyValues([
76
- GIT_COMMIT_SHA, DD_GIT_COMMIT_SHA,
76
+ GIT_COMMIT_SHA, normalizeCommitSha(DD_GIT_COMMIT_SHA),
77
77
  GIT_BRANCH, branch,
78
78
  GIT_REPOSITORY_URL, filterSensitiveInfoFromRepository(DD_GIT_REPOSITORY_URL),
79
79
  GIT_TAG, tag,
@@ -85,8 +85,8 @@ function getUserProviderGitMetadata () {
85
85
  GIT_COMMIT_AUTHOR_EMAIL, DD_GIT_COMMIT_AUTHOR_EMAIL,
86
86
  GIT_COMMIT_AUTHOR_DATE, DD_GIT_COMMIT_AUTHOR_DATE,
87
87
  GIT_PULL_REQUEST_BASE_BRANCH, DD_GIT_PULL_REQUEST_BASE_BRANCH,
88
- GIT_PULL_REQUEST_BASE_BRANCH_SHA, DD_GIT_PULL_REQUEST_BASE_BRANCH_SHA,
89
- GIT_COMMIT_HEAD_SHA, DD_GIT_COMMIT_HEAD_SHA,
88
+ GIT_PULL_REQUEST_BASE_BRANCH_SHA, normalizeCommitSha(DD_GIT_PULL_REQUEST_BASE_BRANCH_SHA),
89
+ GIT_COMMIT_HEAD_SHA, normalizeCommitSha(DD_GIT_COMMIT_HEAD_SHA),
90
90
  ])
91
91
  }
92
92
 
@@ -15,7 +15,14 @@ const urlFilter = require('./urlfilter')
15
15
  const { createInferredProxySpan, finishInferredProxySpan } = require('./inferred_proxy')
16
16
  const { getServerStatusValidator } = require('./status-validator')
17
17
  const { extractURL, obfuscateQs, getQsObfuscator, calculateHttpEndpoint } = require('./url')
18
- const { NETWORK_PEER_ADDRESS } = require('./http-otel-semantics')
18
+ const {
19
+ HTTP_STATUS_ERROR,
20
+ INSTRUMENTATION_HTTP_RESOURCE,
21
+ isInstrumentationOwnedResource,
22
+ NETWORK_PEER_ADDRESS,
23
+ otelHttpResourceName,
24
+ setInstrumentationHttpResource,
25
+ } = require('./http-otel-semantics')
19
26
 
20
27
  const WEB = types.WEB
21
28
  const SERVER = kinds.SERVER
@@ -144,9 +151,27 @@ const web = {
144
151
  setRoute (req, path) {
145
152
  const context = contexts.get(req)
146
153
 
147
- if (!context) return
154
+ if (!context?.span) return
155
+
156
+ if (!path || !context.config?.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
157
+ context.paths = [path]
158
+ return
159
+ }
148
160
 
161
+ const spanContext = context.span.context()
162
+ const currentRoute = spanContext.getTag(HTTP_ROUTE)
163
+ const publishedRoute = context.paths.length > 1 ? context.paths.join('') : context.paths[0]
149
164
  context.paths = [path]
165
+ // Publish before finish because downstream requests can trigger sampling inside the handler.
166
+ // Replace only values this context owns, so an upstream route still wins.
167
+ let route = currentRoute
168
+ if (currentRoute === undefined || currentRoute === publishedRoute) {
169
+ route = path
170
+ context.span.setTag(HTTP_ROUTE, path)
171
+ }
172
+ if (ownsResource(spanContext)) {
173
+ setInstrumentationHttpResource(context.span, otelHttpResourceName(req.method, route))
174
+ }
150
175
  },
151
176
 
152
177
  // Remove the current route segment.
@@ -268,10 +293,16 @@ const web = {
268
293
 
269
294
  if (!spanHasExistingError && !isValidStatusCode) {
270
295
  span.setTag(ERROR, error || true)
296
+ if (context.config.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
297
+ span.setTag(HTTP_STATUS_ERROR, String(statusCode))
298
+ }
271
299
  }
272
300
 
273
301
  if (inferredProxySpan && !inferredSpanHasExistingError && !isValidStatusCode) {
274
302
  inferredProxySpan.setTag(ERROR, error || true)
303
+ if (context.config.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
304
+ inferredProxySpan.setTag(HTTP_STATUS_ERROR, String(statusCode))
305
+ }
275
306
  }
276
307
  },
277
308
 
@@ -302,8 +333,7 @@ const web = {
302
333
  if (context.finished && !req.stream) return
303
334
 
304
335
  // `addRequestTags` is idempotent: in the normal HTTP path it ran during
305
- // `web.startSpan`. Serverless callers (e.g. Azure Functions) skip
306
- // `web.startSpan` and rely on this call to do the request-side work.
336
+ // `web.startSpan`, and this call applies any framework config installed afterwards.
307
337
  addRequestTags(context, spanType)
308
338
  // Configured-header tagging runs at finish time. Framework plugins
309
339
  // (connect, express, ...) install their own config via `setFramework`
@@ -509,6 +539,10 @@ function addRequestTags (context, spanType) {
509
539
  // other HTTP attributes, which are renamed centrally in span_format) it is set
510
540
  // here directly when OTel semantics are enabled.
511
541
  if (config.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
542
+ // Claim the resource before propagation can sample it.
543
+ if (ownsResource(spanContext)) {
544
+ setInstrumentationHttpResource(span, otelHttpResourceName(req.method))
545
+ }
512
546
  const peerAddress = req.socket?.remoteAddress
513
547
  if (peerAddress) span.setTag(NETWORK_PEER_ADDRESS, peerAddress)
514
548
  }
@@ -581,18 +615,39 @@ function applyRouteOrEndpointTag (context) {
581
615
  span.setTag(HTTP_ENDPOINT, endpoint)
582
616
  }
583
617
 
618
+ /**
619
+ * @param {import('../../opentracing/span_context')} spanContext
620
+ */
621
+ function ownsResource (spanContext) {
622
+ return isInstrumentationOwnedResource(
623
+ spanContext.getTag(RESOURCE_NAME),
624
+ spanContext.getTag(INSTRUMENTATION_HTTP_RESOURCE)
625
+ )
626
+ }
627
+
584
628
  function addResourceTag (context) {
585
- const { req, span } = context
629
+ const { req, span, config } = context
586
630
  const spanContext = span.context()
631
+ const currentResource = spanContext.getTag(RESOURCE_NAME)
587
632
 
588
- if (spanContext.getTag(RESOURCE_NAME)) return
633
+ if (!config.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
634
+ if (currentResource) return
635
+
636
+ let resource = req.method
637
+ const route = spanContext.getTag(HTTP_ROUTE)
638
+
639
+ if (route) resource += ` ${route}`
640
+ span.setTag(RESOURCE_NAME, resource)
641
+ return
642
+ }
589
643
 
590
- let resource = req.method
591
- const route = spanContext.getTag(HTTP_ROUTE)
644
+ const instrumentationResource = spanContext.getTag(INSTRUMENTATION_HTTP_RESOURCE)
645
+ if (currentResource && !isInstrumentationOwnedResource(currentResource, instrumentationResource)) return
592
646
 
593
- if (route) resource += ` ${route}`
647
+ const resource = otelHttpResourceName(req.method, spanContext.getTag(HTTP_ROUTE))
648
+ if (currentResource === resource && instrumentationResource === resource) return
594
649
 
595
- span.setTag(RESOURCE_NAME, resource)
650
+ setInstrumentationHttpResource(span, resource)
596
651
  }
597
652
 
598
653
  function addRequestHeaders (context) {
@@ -72,7 +72,7 @@ function buildProcessTags (config) {
72
72
  // Singleton with constant defaults so pre-init reads don't blow up
73
73
  const processTags = module.exports = {
74
74
  /**
75
- * @param {import('../config/config-base')} config
75
+ * @param {import('../config/config-base')} [config]
76
76
  */
77
77
  initialize (config) {
78
78
  // check if one of the properties added during build exist and if so return
@@ -6,6 +6,18 @@ const log = require('./log')
6
6
 
7
7
  const configUpdateChannel = dc.channel('datadog:config:update')
8
8
 
9
+ // The profiler reads these settings at startup, regardless of which RC product supplies them.
10
+ const RESTART_SETTINGS = /** @type {const} */ ([
11
+ 'DD_PROFILING_CPU_ENABLED',
12
+ 'DD_PROFILING_WALLTIME_ENABLED',
13
+ 'DD_PROFILING_HEAP_ENABLED',
14
+ 'DD_PROFILING_ALLOCATION_ENABLED',
15
+ 'DD_PROFILING_UPLOAD_PERIOD',
16
+ ])
17
+
18
+ /** @type {ReturnType<typeof getRemotelyConfigurableSettings> | undefined} */
19
+ let startedSettings
20
+
9
21
  /** @type {import('./profiling/ssi-heuristics').SSIHeuristics | undefined} */
10
22
  let activeSSIHeuristics
11
23
 
@@ -20,6 +32,9 @@ let profilingModule
20
32
  */
21
33
  let deferredConfig
22
34
 
35
+ // The profiler is stopping to apply new settings, not to stay disabled.
36
+ let restartPending = false
37
+
23
38
  function getProfilingModule () {
24
39
  if (profilingModule === undefined) {
25
40
  profilingModule = require('./profiling')
@@ -38,6 +53,16 @@ function isStarted () {
38
53
  return profilingModule !== undefined && profilingModule.profiler.enabled
39
54
  }
40
55
 
56
+ /**
57
+ * Types of the running profilers (see the profiling layer's getRunningTypes()). Like isStarted(),
58
+ * this doesn't load the profiling engine just to answer.
59
+ *
60
+ * @returns {string[]}
61
+ */
62
+ function getRunningProfileTypes () {
63
+ return profilingModule?.profiler.getRunningTypes() ?? []
64
+ }
65
+
41
66
  // A stopped profiler still exports one final profile, and until that settles it reports neither
42
67
  // the state a decision would be based on nor any willingness to start again.
43
68
  function isStopping () {
@@ -62,6 +87,7 @@ function disableSSIHeuristics () {
62
87
  * @param {import('./config/config-base')} config - Tracer configuration
63
88
  */
64
89
  function start (config) {
90
+ startedSettings = getRemotelyConfigurableSettings(config)
65
91
  try {
66
92
  // Forward the full tracer config to the profiling layer.
67
93
  // Profiling code is responsible for deriving the specific options it needs.
@@ -79,6 +105,7 @@ function stop () {
79
105
  // An explicit stop is the latest desired state, so it retracts a configuration still waiting
80
106
  // for an in-flight shutdown to settle.
81
107
  deferredConfig = undefined
108
+ restartPending = false
82
109
 
83
110
  // A stop command for a profiler that has never been loaded is already satisfied.
84
111
  if (profilingModule === undefined) return
@@ -115,35 +142,70 @@ function runWithLabels (labels, fn) {
115
142
  return getProfilingModule().profiler.runWithLabels(labels, fn)
116
143
  }
117
144
 
145
+ /**
146
+ * @param {import('./config/config-base')} config - Tracer configuration
147
+ */
148
+ function getRemotelyConfigurableSettings (config) {
149
+ return RESTART_SETTINGS.map(name => config[name])
150
+ }
151
+
152
+ /**
153
+ * Settings are read at startup, so changes require a restart and may leave a profile gap.
154
+ *
155
+ * @param {import('./config/config-base')} config - Tracer configuration
156
+ */
157
+ function restartIfSettingsChanged (config) {
158
+ const settings = getRemotelyConfigurableSettings(config)
159
+ if (settings.every((value, index) => value === startedSettings?.[index])) return
160
+
161
+ log.debug('Restarting the profiler to apply changed settings')
162
+ stop()
163
+ if (isStopping()) {
164
+ // The 'stopped' event applies the config after the final export.
165
+ deferredConfig = config
166
+ restartPending = true
167
+ } else {
168
+ start(config)
169
+ }
170
+ }
171
+
118
172
  function applyDeferredConfig () {
119
173
  const config = deferredConfig
120
174
  if (config === undefined) return
121
175
  deferredConfig = undefined
122
- applyConfig(config)
176
+ const restarting = restartPending
177
+ restartPending = false
178
+ applyConfig(config, restarting)
123
179
  }
124
180
 
125
181
  /**
126
182
  * @param {import('./config/config-base')} config - Tracer configuration
183
+ * @param {boolean} [restarting] - Resume a run stopped for a settings change
127
184
  */
128
- function applyConfig (config) {
185
+ function applyConfig (config, restarting = false) {
129
186
  const enabled = config.profiling.DD_PROFILING_ENABLED
130
187
  if (enabled === 'true') {
131
188
  // A non-auto value means the SSI heuristics no longer get a say; disable them so a trigger that
132
189
  // fires after this publish can't start the profiler behind this decision's back.
133
190
  disableSSIHeuristics()
134
- // Leave an already-running profiler alone; otherwise an unrelated remote-config publish
135
- // (e.g. an unrelated sampling-rate change) would restart it on every update.
136
- if (!isStarted()) start(config)
191
+ // Unrelated config updates must not restart the profiler.
192
+ if (isStarted()) {
193
+ restartIfSettingsChanged(config)
194
+ } else {
195
+ start(config)
196
+ }
137
197
  } else if (enabled === 'false') {
138
198
  disableSSIHeuristics()
139
199
  stop()
140
200
  } else if (enabled === 'auto') {
141
- if (!isStarted() && !activeSSIHeuristics) {
142
- // 'auto' defers the start decision to SSI heuristics. A running profiler already reflects a
143
- // decision that was made (by SSI or a prior unconditional enablement), so leave it alone
144
- // rather than stopping and re-enabling it on every subsequent config publication. Also guard
145
- // against creating another active instance; each SSIHeuristics instance owns listeners and a
146
- // timer until the heuristic makes its decision or is explicitly disabled.
201
+ // A running or restarting profiler has already passed the start decision; don't
202
+ // re-run SSI heuristics on config updates.
203
+ if (isStarted()) {
204
+ restartIfSettingsChanged(config)
205
+ } else if (restarting) {
206
+ start(config)
207
+ } else if (!activeSSIHeuristics) {
208
+ // Reuse active heuristics; each instance owns listeners and a timer.
147
209
  const { SSIHeuristics } = getSSIHeuristicsModule()
148
210
  const heuristics = new SSIHeuristics(config)
149
211
  activeSSIHeuristics = heuristics
@@ -182,4 +244,4 @@ configUpdateChannel.subscribe((config) => {
182
244
 
183
245
  globalThis[Symbol.for('dd-trace')].beforeExitHandlers.add(stop)
184
246
 
185
- module.exports = { isStarted, start, stop, setCustomLabelKeys, runWithLabels }
247
+ module.exports = { isStarted, getRunningProfileTypes, start, stop, setCustomLabelKeys, runWithLabels }
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { EventEmitter } = require('events')
4
+ const { setImmediate: yieldToEventLoop } = require('node:timers/promises')
4
5
  const dc = require('dc-polyfill')
5
6
  const crashtracker = require('../crashtracking')
6
7
  const log = require('../log')
@@ -94,6 +95,24 @@ class Profiler extends EventEmitter {
94
95
  return this.#stopping !== undefined
95
96
  }
96
97
 
98
+ /**
99
+ * Types of the running profilers (e.g. 'wall', 'space', 'events'), plus 'cpu' when the wall
100
+ * profiler also collects CPU time and 'allocations' when the space profiler also collects
101
+ * allocations. Empty while the profiler isn't running.
102
+ *
103
+ * @returns {string[]}
104
+ */
105
+ getRunningTypes () {
106
+ if (!this.#enabled) return []
107
+ const types = []
108
+ for (const profiler of this.#profilers) {
109
+ types.push(profiler.type)
110
+ if (profiler.collectsCpuTime) types.push('cpu')
111
+ if (profiler.collectsAllocations) types.push('allocations')
112
+ }
113
+ return types
114
+ }
115
+
97
116
  /**
98
117
  * Declares the set of custom label keys that will be used with
99
118
  * {@link runWithLabels}. This is used for profile upload metadata and
@@ -424,7 +443,7 @@ class Profiler extends EventEmitter {
424
443
  const compressionFn = this.#getCompressionFn()
425
444
 
426
445
  // encode and export asynchronously
427
- await Promise.all(profiles.map(async ({ profiler, profile, info }) => {
446
+ const encodeProfile = async ({ profiler, profile, info }) => {
428
447
  try {
429
448
  const encoded = await profiler.encode(profile)
430
449
  const compressed = encoded instanceof Buffer && compressionFn !== undefined
@@ -448,7 +467,16 @@ class Profiler extends EventEmitter {
448
467
  // encode and submit the other profile types.
449
468
  log.error(error)
450
469
  }
451
- }))
470
+ }
471
+
472
+ const encodings = []
473
+ for (const profile of profiles) {
474
+ // Separate synchronous encoder prefixes without waiting for compression/export to finish.
475
+ // eslint-disable-next-line no-await-in-loop -- Encoder starts must yield, not their entire async tasks.
476
+ await yieldToEventLoop()
477
+ encodings.push(encodeProfile(profile))
478
+ }
479
+ await Promise.all(encodings)
452
480
 
453
481
  if (hasEncoded) {
454
482
  await this.#submit(encodedProfiles, infos, startDate, endDate, snapshotTags, snapshotKind)
@@ -17,6 +17,7 @@ const STACK_DEPTH = 64
17
17
  const identityRefreshChannel = channel('datadog:identity:refresh')
18
18
 
19
19
  class NativeSpaceProfiler {
20
+ collectsAllocations = false
20
21
  #config
21
22
  #exporters
22
23
  #identityRefreshListener
@@ -46,7 +47,8 @@ class NativeSpaceProfiler {
46
47
 
47
48
  this.#mapper = mapper
48
49
  this.#pprof = require('@datadog/pprof')
49
- this.#pprof.heap.start(this.#samplingInterval, STACK_DEPTH, this.#config.DD_PROFILING_ALLOCATION_ENABLED)
50
+ this.collectsAllocations = this.#config.DD_PROFILING_ALLOCATION_ENABLED
51
+ this.#pprof.heap.start(this.#samplingInterval, STACK_DEPTH, this.collectsAllocations)
50
52
 
51
53
  if (this.#config.DD_PROFILING_EXPERIMENTAL_OOM_MONITORING_ENABLED) {
52
54
  const config = this.#config
@@ -64,7 +64,7 @@ class NativeWallProfiler {
64
64
  #captureSpanData = false
65
65
  #codeHotspotsEnabled = false
66
66
  #contextCountGaugeUpdater
67
- #cpuProfilingEnabled = false
67
+ collectsCpuTime = false
68
68
  #currentContext
69
69
  #customLabelsActive = false
70
70
  #customLabelKeys
@@ -96,7 +96,7 @@ class NativeWallProfiler {
96
96
  constructor (config, { asyncContextFrameEnabled, flushInterval }) {
97
97
  this.#asyncContextFrameEnabled = asyncContextFrameEnabled
98
98
  this.#codeHotspotsEnabled = config.DD_PROFILING_CODEHOTSPOTS_ENABLED
99
- this.#cpuProfilingEnabled = config.DD_PROFILING_CPU_ENABLED
99
+ this.collectsCpuTime = config.DD_PROFILING_CPU_ENABLED
100
100
  this.#endpointCollectionEnabled = config.DD_PROFILING_ENDPOINT_COLLECTION_ENABLED
101
101
  this.#flushIntervalMillis = flushInterval
102
102
  this.#samplingIntervalMicros = SAMPLING_INTERVAL * 1000
@@ -111,7 +111,7 @@ class NativeWallProfiler {
111
111
  // capturing span data or timeline is enabled (so we need sample timestamps, and for now
112
112
  // timestamps require the sample contexts feature in the pprof wall profiler), or
113
113
  // cpu profiling is enabled.
114
- this.#withContexts = this.#captureSpanData || this.#timelineEnabled || this.#cpuProfilingEnabled
114
+ this.#withContexts = this.#captureSpanData || this.#timelineEnabled || this.collectsCpuTime
115
115
  }
116
116
 
117
117
  codeHotspotsEnabled () {
@@ -130,7 +130,7 @@ class NativeWallProfiler {
130
130
  kSampleCount = this.#pprof.time.constants.kSampleCount
131
131
 
132
132
  this.#pprof.time.start({
133
- collectCpuTime: this.#cpuProfilingEnabled,
133
+ collectCpuTime: this.collectsCpuTime,
134
134
  columnNumbers: 'emit',
135
135
  durationMillis: this.#flushIntervalMillis,
136
136
  intervalMicros: this.#samplingIntervalMicros,