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
@@ -261,8 +261,8 @@ class Span extends BridgeSpanBase {
261
261
  const endTime = hrTimeToMilliseconds(hrEndTime)
262
262
 
263
263
  // Must run before `finish()`, while the DD span is still unfinished. See span-ending-hook.js.
264
- if (spanEndingHook.hook !== undefined) {
265
- spanEndingHook.hook(this._ddSpan)
264
+ if (spanEndingHook.hook?.(this._ddSpan, this._otelTraceSemanticsEnabled)) {
265
+ this.setStatus({ code: api.SpanStatusCode.ERROR, message: this._ddSpan.context().getTag('error.message') })
266
266
  }
267
267
  this._ddSpan.finish(endTime)
268
268
  this._spanProcessor.onEnd(this)
@@ -0,0 +1,174 @@
1
+ 'use strict'
2
+
3
+ const { isDeepStrictEqual } = require('node:util')
4
+
5
+ const { DD_MAJOR } = require('../../../../version')
6
+ const { VALID_PROPAGATION_STYLES } = require('../config/parsers')
7
+ const { getLogLevel } = require('../log/writer')
8
+
9
+ /**
10
+ * @typedef {Readonly<{
11
+ * protocol: string,
12
+ * resourceAttributes: Readonly<Record<string, unknown>>,
13
+ * }>} InitializedExporter
14
+ * @typedef {Readonly<{
15
+ * tracing?: boolean,
16
+ * traces?: InitializedExporter,
17
+ * metrics?: InitializedExporter,
18
+ * logs?: InitializedExporter,
19
+ * spanMetrics?: InitializedExporter,
20
+ * }>} Pipelines
21
+ */
22
+
23
+ /**
24
+ * @param {ReturnType<import('../config')>} config
25
+ * @param {import('../sampling_rule')[]} rules
26
+ * @param {Pipelines} [pipelines]
27
+ * @returns {Record<string, unknown>}
28
+ */
29
+ function startupConfig (config, rules, pipelines = {}) {
30
+ const tracing = !!pipelines.tracing
31
+ const traces = !!pipelines.traces
32
+ const metrics = !!pipelines.metrics
33
+ const logs = !!pipelines.logs
34
+ const spanMetrics = !!pipelines.spanMetrics
35
+ const resources = [pipelines.traces, pipelines.metrics, pipelines.logs, pipelines.spanMetrics]
36
+ .filter(exporter => exporter !== undefined)
37
+ .map(exporter => exporter.resourceAttributes)
38
+ const attributes = commonResourceAttributes(resources)
39
+
40
+ /** @type {Record<string, unknown>} */
41
+ const out = {
42
+ DD_TRACE_OTEL_ENABLED: !!config.DD_TRACE_OTEL_ENABLED,
43
+ DD_TRACE_OTEL_SEMANTICS_ENABLED: !!config.DD_TRACE_OTEL_SEMANTICS_ENABLED,
44
+ DD_METRICS_OTEL_ENABLED: !!config.DD_METRICS_OTEL_ENABLED,
45
+ DD_LOGS_OTEL_ENABLED: !!config.DD_LOGS_OTEL_ENABLED,
46
+ OTEL_LOG_LEVEL: getLogLevel(),
47
+ OTEL_SERVICE_NAME: typeof attributes['service.name'] === 'string'
48
+ ? attributes['service.name']
49
+ : undefined,
50
+ OTEL_RESOURCE_ATTRIBUTES: attributes,
51
+ OTEL_TRACES_EXPORTER: traces ? 'otlp' : 'none',
52
+ OTEL_METRICS_EXPORTER: metrics ? 'otlp' : 'none',
53
+ OTEL_LOGS_EXPORTER: logs ? 'otlp' : 'none',
54
+ OTEL_TRACES_SPAN_METRICS_ENABLED: spanMetrics,
55
+ }
56
+
57
+ if (tracing) {
58
+ const { inject, extract } = config.tracePropagationStyle
59
+ if (DD_MAJOR >= 6 && config.DD_TRACE_PROPAGATION_BEHAVIOR_EXTRACT === 'continue' &&
60
+ inject.length === extract.length &&
61
+ inject.every((name, i) => name === extract[i] && VALID_PROPAGATION_STYLES.has(name))) {
62
+ const propagators = inject.filter(name => name !== 'none')
63
+ .map(name => name === 'b3 single header' ? 'b3' : name)
64
+ out.OTEL_PROPAGATORS = propagators.join(',') || 'none'
65
+ }
66
+ const firstRule = rules[0]
67
+ if (config.apmTracingEnabled !== false && firstRule) {
68
+ const globalRuleCount = config.sampler.sampleRate === undefined ? 0 : 1
69
+ if (rules.length > globalRuleCount) {
70
+ out.OTEL_TRACES_SAMPLER = 'datadog_custom_rules'
71
+ } else {
72
+ const rate = firstRule.sampleRate
73
+ out.OTEL_TRACES_SAMPLER = rate === 0
74
+ ? 'parentbased_always_off'
75
+ : rate === 1 ? 'parentbased_always_on' : 'parentbased_traceidratio'
76
+ if (rate > 0 && rate < 1) out.OTEL_TRACES_SAMPLER_ARG = rate
77
+ }
78
+ }
79
+ }
80
+
81
+ if (pipelines.traces) {
82
+ Object.assign(out, buildSanitizedExporterConfig(config, 'TRACES', pipelines.traces.protocol))
83
+ }
84
+ const metricsExporter = pipelines.metrics || pipelines.spanMetrics
85
+ if (metricsExporter) {
86
+ Object.assign(out, buildSanitizedExporterConfig(config, 'METRICS', metricsExporter.protocol))
87
+ }
88
+ if (metrics) {
89
+ out.OTEL_METRIC_EXPORT_INTERVAL = config.OTEL_METRIC_EXPORT_INTERVAL
90
+ out.OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE =
91
+ config.OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE.toLowerCase()
92
+ }
93
+ if (pipelines.logs) {
94
+ Object.assign(out, buildSanitizedExporterConfig(config, 'LOGS', pipelines.logs.protocol))
95
+ out.OTEL_BLRP_SCHEDULE_DELAY = config.OTEL_BSP_SCHEDULE_DELAY
96
+ out.OTEL_BLRP_MAX_EXPORT_BATCH_SIZE = config.OTEL_BSP_MAX_EXPORT_BATCH_SIZE
97
+ }
98
+ return out
99
+ }
100
+
101
+ /**
102
+ * @param {Readonly<Record<string, unknown>>[]} resources
103
+ * @returns {Record<string, unknown>}
104
+ */
105
+ function commonResourceAttributes (resources) {
106
+ const [reference, ...others] = resources
107
+ /** @type {Record<string, unknown>} */
108
+ const shared = {}
109
+
110
+ if (!reference) return shared
111
+
112
+ for (const [key, value] of Object.entries(reference)) {
113
+ const supported = isAttributeValue(value) ||
114
+ (Array.isArray(value) && value.every(isAttributeValue))
115
+ if (!supported) continue
116
+
117
+ const matchesEveryResource = others.every(resource =>
118
+ Object.hasOwn(resource, key) && isDeepStrictEqual(resource[key], value))
119
+ if (!matchesEveryResource) continue
120
+
121
+ shared[key] = Array.isArray(value) ? [...value] : value
122
+ }
123
+
124
+ return shared
125
+ }
126
+
127
+ /** @param {unknown} value */
128
+ function isAttributeValue (value) {
129
+ return typeof value === 'string' || typeof value === 'boolean' ||
130
+ (typeof value === 'number' && Number.isFinite(value))
131
+ }
132
+
133
+ /**
134
+ * @param {ReturnType<import('../config')>} config
135
+ * @param {'TRACES' | 'METRICS' | 'LOGS'} signal
136
+ * @param {string} protocol
137
+ * @returns {Record<string, unknown>}
138
+ */
139
+ function buildSanitizedExporterConfig (config, signal, protocol) {
140
+ const prefix = `OTEL_EXPORTER_OTLP_${signal}`
141
+ const endpoint = sanitizeEndpoint(config[`${prefix}_ENDPOINT`])
142
+ return {
143
+ ...(endpoint && { [`${prefix}_ENDPOINT`]: endpoint }),
144
+ [`${prefix}_PROTOCOL`]: protocol,
145
+ [`${prefix}_HEADERS`]: redactHeaders(config[`${prefix}_HEADERS`]),
146
+ [`${prefix}_TIMEOUT`]: config[`${prefix}_TIMEOUT`],
147
+ }
148
+ }
149
+
150
+ /** @param {string} endpoint */
151
+ function sanitizeEndpoint (endpoint) {
152
+ let sanitized
153
+ try {
154
+ const url = new URL(endpoint)
155
+ url.username = ''
156
+ url.password = ''
157
+ url.search = ''
158
+ url.hash = ''
159
+ if (url.protocol === 'http:' || url.protocol === 'https:') sanitized = url.href
160
+ } catch {
161
+ // A malformed endpoint has no safe representation in diagnostics.
162
+ }
163
+ return sanitized
164
+ }
165
+
166
+ /**
167
+ * @param {Record<string, string> | undefined} headers
168
+ * @returns {Record<string, string>}
169
+ */
170
+ function redactHeaders (headers) {
171
+ return Object.fromEntries(Object.keys(headers ?? {}).map(name => [name, '<redacted>']))
172
+ }
173
+
174
+ module.exports = startupConfig
@@ -39,7 +39,7 @@ class OtlpHttpTraceExporter extends OtlpHttpExporterBase {
39
39
  * @param {boolean} otelTraceSemanticsEnabled - When true, do not emit Datadog-only attributes as span attributes
40
40
  */
41
41
  constructor (url, headers, timeout, resourceAttributes, otelTraceSemanticsEnabled) {
42
- super(url, headers, timeout, 'http/json', 'traces')
42
+ super(url, headers, timeout, 'http/json', 'traces', resourceAttributes)
43
43
  this.#transformer = new OtlpTraceTransformer(resourceAttributes, otelTraceSemanticsEnabled)
44
44
  }
45
45
 
@@ -295,7 +295,13 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
295
295
  if (errorType && errorMessage) {
296
296
  message = `${errorType}: ${errorMessage}`
297
297
  } else if (errorType) {
298
- message = errorType
298
+ const kind = span.meta?.['span.kind']
299
+ // The HTTP response status already explains a status-only error.
300
+ const isHttpStatusError = this.#otelTraceSemanticsEnabled &&
301
+ (kind === 'server' || kind === 'client') &&
302
+ !span.meta?.['error.stack'] &&
303
+ errorType === span.metrics?.['http.response.status_code']?.toString()
304
+ if (!isHttpStatusError) message = errorType
299
305
  } else if (errorMessage) {
300
306
  message = errorMessage
301
307
  }
@@ -15,49 +15,102 @@ const WHITESPACE = /[ \t]/
15
15
  * @param {boolean} rejectValueTabs Drop entries whose value contains an internal tab.
16
16
  * @param {number} [maxEntries] Maximum number of entries to parse.
17
17
  * @param {number} [maxValueLength] Maximum length of an entry value.
18
+ * @param {boolean} [prioritizeDd] Keep dd first even when it follows the member limit.
18
19
  * @returns {[string, string][]} Entries in reverse of wire order.
19
20
  */
20
- function parseEntries (value, fieldSeparator, pairSeparator, rejectValueTabs, maxEntries, maxValueLength) {
21
- const segments = value.split(fieldSeparator, maxEntries)
22
-
23
- // TODO: We should extract dd no matter at what position and move it to the front of the list.
24
- // Extract up 31 additional entries.
21
+ function parseEntries (
22
+ value, fieldSeparator, pairSeparator, rejectValueTabs, maxEntries = Infinity, maxValueLength = Infinity, prioritizeDd
23
+ ) {
24
+ /** @type {[string, string][]} */
25
25
  const entries = []
26
- for (let index = 0; index < segments.length; index++) {
27
- const segment = segments[index]
28
- const splitIndex = segment.indexOf(pairSeparator)
29
- if (splitIndex === -1) continue
30
- const key = segment.slice(0, splitIndex).trim()
31
- if (!key || WHITESPACE.test(key)) continue
32
- // W3C §3.3.1.3.2: value = 0*255(chr) nblk-chr; chr = %x20 / nblk-chr (no tab).
33
- // Leading 0x20 is part of value; trailing whitespace is OWS.
34
- const entryValue = segment.slice(splitIndex + 1).trimEnd()
35
- if (!entryValue ||
36
- maxValueLength !== undefined && entryValue.length > maxValueLength ||
37
- rejectValueTabs && entryValue.includes('\t')) continue
38
- entries.push([key, entryValue])
26
+ /** @type {[string, string] | undefined} */
27
+ let ddEntry
28
+ let start = 0
29
+ let memberCount = 0
30
+ let splitIndex = -1
31
+
32
+ while (start <= value.length && memberCount < maxEntries) {
33
+ const separatorIndex = value.indexOf(fieldSeparator, start)
34
+ const end = separatorIndex === -1 ? value.length : separatorIndex
35
+ // Reuse the next separator (or end) so malformed members do not rescan the suffix.
36
+ if (splitIndex < start && start < end) {
37
+ splitIndex = value.indexOf(pairSeparator, start)
38
+ if (splitIndex === -1) splitIndex = value.length
39
+ }
40
+ const key = splitIndex > start && splitIndex < end ? value.slice(start, splitIndex).trim() : undefined
41
+ if (key && !WHITESPACE.test(key)) {
42
+ // W3C §3.3.1.3.2: value = 0*255(chr) nblk-chr; chr = %x20 / nblk-chr (no tab).
43
+ // Leading 0x20 is part of value; trailing whitespace is OWS.
44
+ const entryValue = value.slice(splitIndex + 1, end).trimEnd()
45
+ if (entryValue &&
46
+ entryValue.length <= maxValueLength &&
47
+ (!rejectValueTabs || !entryValue.includes('\t'))) {
48
+ if (prioritizeDd && key === 'dd') {
49
+ ddEntry ??= [key, entryValue]
50
+ } else {
51
+ entries.push([key, entryValue])
52
+ }
53
+ }
54
+ }
55
+
56
+ memberCount++
57
+ if (separatorIndex === -1) {
58
+ start = value.length + 1
59
+ break
60
+ }
61
+ start = separatorIndex + fieldSeparator.length
39
62
  }
63
+
64
+ if (prioritizeDd && ddEntry === undefined && start < value.length) {
65
+ let position = value.indexOf('dd', start)
66
+ while (position !== -1) {
67
+ const segmentStart = value.lastIndexOf(',', position) + 1
68
+ const separatorIndex = value.indexOf(',', position)
69
+ const end = separatorIndex === -1 ? value.length : separatorIndex
70
+ const segment = value.slice(segmentStart, end)
71
+ const splitIndex = segment.indexOf('=')
72
+
73
+ if (splitIndex > 0 && segment.slice(0, splitIndex).trim() === 'dd') {
74
+ const entryValue = segment.slice(splitIndex + 1).trimEnd()
75
+ if (entryValue && entryValue.length <= maxValueLength && !entryValue.includes('\t')) {
76
+ ddEntry = ['dd', entryValue]
77
+ break
78
+ }
79
+ }
80
+
81
+ if (separatorIndex === -1) break
82
+ position = value.indexOf('dd', separatorIndex + 1)
83
+ }
84
+ }
85
+
86
+ if (ddEntry && entries.length === maxEntries) entries.pop()
40
87
  // Reverse so the Map's insertion order is reverse of wire order. `toString`
41
88
  // prepends as it iterates, which yields the original wire order back.
42
89
  entries.reverse()
90
+ if (ddEntry) entries.push(ddEntry)
43
91
  return entries
44
92
  }
45
93
 
46
94
  /**
47
- * @param {typeof TraceState | typeof TraceStateData} Type
95
+ * @template T
96
+ * @param {new (entries?: [string, string][]) => T} Type
48
97
  * @param {string | undefined} value
49
98
  * @param {string} fieldSeparator
50
99
  * @param {string} pairSeparator
51
100
  * @param {boolean} rejectValueTabs
52
101
  * @param {number} [maxEntries]
53
102
  * @param {number} [maxValueLength]
54
- * @returns {TraceState | TraceStateData}
103
+ * @param {boolean} [prioritizeDd]
55
104
  */
56
- function fromString (Type, value, fieldSeparator, pairSeparator, rejectValueTabs, maxEntries, maxValueLength) {
105
+ function fromString (
106
+ Type, value, fieldSeparator, pairSeparator, rejectValueTabs, maxEntries, maxValueLength, prioritizeDd
107
+ ) {
57
108
  if (typeof value !== 'string' || !value.length) {
58
109
  return new Type()
59
110
  }
60
- return new Type(parseEntries(value, fieldSeparator, pairSeparator, rejectValueTabs, maxEntries, maxValueLength))
111
+ return new Type(parseEntries(
112
+ value, fieldSeparator, pairSeparator, rejectValueTabs, maxEntries, maxValueLength, prioritizeDd
113
+ ))
61
114
  }
62
115
 
63
116
  function toString (map, pairSeparator, fieldSeparator) {
@@ -221,8 +274,9 @@ class TraceState {
221
274
  return result
222
275
  }
223
276
 
277
+ /** @param {string | undefined} value */
224
278
  static fromString (value) {
225
- return fromString(TraceState, value, ',', '=', true, MAX_LIST_MEMBERS, MAX_VALUE_LENGTH)
279
+ return fromString(TraceState, value, ',', '=', true, MAX_LIST_MEMBERS, MAX_VALUE_LENGTH, true)
226
280
  }
227
281
 
228
282
  toString () {
@@ -21,6 +21,12 @@ const REFERENCE_CHILD_OF = 'child_of'
21
21
  const REFERENCE_FOLLOWS_FROM = 'follows_from'
22
22
 
23
23
  class DatadogTracer {
24
+ /**
25
+ * @readonly
26
+ * @type {import('../opentelemetry/startup-config').Pipelines}
27
+ */
28
+ #startupConfig
29
+
24
30
  constructor (config, prioritySampler) {
25
31
  this._config = config
26
32
  this._service = config.service
@@ -33,9 +39,14 @@ class DatadogTracer {
33
39
  this._prioritySampler = prioritySampler ?? new PrioritySampler(config.env, config.sampler)
34
40
 
35
41
  const exportOtlpTraces = getExporter.usesOtlpTraceExporter(config)
42
+ let traces
36
43
  if (exportOtlpTraces) {
37
44
  const { createOtlpTraceExporter } = require('../opentelemetry/trace')
38
45
  this._exporter = createOtlpTraceExporter(config)
46
+ traces = {
47
+ protocol: this._exporter.protocol,
48
+ resourceAttributes: this._exporter.getStartupResourceAttributes(),
49
+ }
39
50
  } else {
40
51
  let exporterName = config.tracing.DD_TRACE_EXPERIMENTAL_EXPORTER
41
52
  if (config.llmobs?.DD_LLMOBS_ENABLED && !config.isCiVisibility &&
@@ -67,11 +78,24 @@ class DatadogTracer {
67
78
  [formats.LOG]: new LogPropagator(config),
68
79
  [formats.TEXT_MAP_DSM]: new DSMTextMapPropagator(config),
69
80
  }
81
+ this.#startupConfig = {
82
+ tracing: true,
83
+ traces,
84
+ spanMetrics: this._processor.getSpanMetricsStartupConfig(),
85
+ }
70
86
  if (config.reportHostname) {
71
87
  this._hostname = os.hostname()
72
88
  }
73
89
  }
74
90
 
91
+ /**
92
+ * Returns the configuration captured when tracing initialized.
93
+ * @returns {import('../opentelemetry/startup-config').Pipelines}
94
+ */
95
+ getStartupConfig () {
96
+ return this.#startupConfig
97
+ }
98
+
75
99
  startSpan (name, options = {}) {
76
100
  const parent = options.childOf
77
101
  ? getContext(options.childOf)
@@ -51,19 +51,15 @@ const webTagsCache = require('./web-tags-cache')
51
51
  * @property {number} endpointIndex
52
52
  */
53
53
 
54
- // OTEP-4947 duplicates are last-wins, so appending a later endpoint value would
55
- // correctly overwrite an earlier one — but an out-of-process reader sampling the
56
- // record mid-request would still see the interim value (e.g. a bare `GET`) as
57
- // the endpoint for whatever it was sampling. So a record is built without an
58
- // endpoint until finalEndpoint (profiling/webspan-utils.js) reports the value
59
- // settled, and gets one appended when webTagsCache announces that moment.
54
+ // OTEP-4947 duplicates are last-wins, so later endpoint values refine existing
55
+ // records. finalEndpoint excludes bare methods until routing supplies an endpoint.
60
56
  //
61
- // Records still waiting on that announcement, grouped by the web-server tag bag
62
- // they are waiting on. Every span under one request resolves to that same bag
57
+ // Active records are grouped by their web-server tag bag.
58
+ // Every span under one request resolves to that same bag
63
59
  // (webTagsCache maps a span to its nearest web-server ancestor's tags) and the
64
- // endpoint belongs to the request rather than to any one span, so a single
65
- // resolution fills in every record built before it — the request span's own and
66
- // each descendant's. Descendants are the reason this can't just live on the
60
+ // endpoint belongs to the request rather than to any one span, so each change
61
+ // updates the request span's record and each descendant's.
62
+ // Descendants are the reason this cannot just live on the
67
63
  // per-span cache entry: the tags:update that carries the route is published for
68
64
  // the ancestor, which has no way to enumerate them.
69
65
  //
@@ -73,8 +69,11 @@ const webTagsCache = require('./web-tags-cache')
73
69
  // a bag, on already-expired spans under manual-GC debug mode — and webTagsCache
74
70
  // already depends on it, holding bags the wall profiler dereferences much later.
75
71
  //
76
- // Waiters leave on span finish, ancestry changes, or endpoint resolution.
72
+ // Records rebuilt after finish have no second finish event, so cleanup follows the span's GC lifetime.
73
+ /** @type {WeakMap<ReturnType<DatadogSpanContext['getTags']>, Array<CachedContext>>} */
77
74
  const pendingEndpoints = new WeakMap()
75
+ /** @type {FinalizationRegistry<WeakRef<CachedContext>> | undefined} */
76
+ let endpointCleanup
78
77
  const NOT_WAITING = -1
79
78
  const AWAITING_OWN_ENDPOINT = -2
80
79
 
@@ -219,12 +218,15 @@ function getOrBuildContext (span) {
219
218
  // built before the decision keeps reading as not sampled.
220
219
  cached.context = new ThreadContext(traceId, spanId, traceFlagsOf(spanContext), attrs)
221
220
  cached.webTags = webTags
222
- if (endpoint === undefined) awaitEndpoint(span, webTags, cached)
221
+ awaitEndpoint(span, webTags, cached)
222
+ if (spanContext._isFinished) {
223
+ endpointCleanup ??= new FinalizationRegistry(onSpanCollected)
224
+ endpointCleanup.register(span, new WeakRef(cached))
225
+ }
223
226
  return cached.context
224
227
  }
225
228
 
226
- // Enlist a record built without an endpoint, so the resolution announcement for
227
- // its request fills it in.
229
+ // Track the request's endpoint until this record finishes or changes ancestry.
228
230
  /**
229
231
  * @param {DatadogSpan} span
230
232
  * @param {CachedContext['webTags']} webTags
@@ -250,6 +252,12 @@ function awaitEndpoint (span, webTags, cached) {
250
252
  }
251
253
  }
252
254
 
255
+ /** @param {WeakRef<CachedContext>} reference */
256
+ function onSpanCollected (reference) {
257
+ const cached = reference.deref()
258
+ if (cached !== undefined) removePendingEndpoint(cached)
259
+ }
260
+
253
261
  /** @param {CachedContext} cached */
254
262
  function removePendingEndpoint (cached) {
255
263
  const index = cached.endpointIndex
@@ -325,9 +333,7 @@ function onSpanFinished (span) {
325
333
  // would strip trace and endpoint attribution off that work entirely.
326
334
  }
327
335
 
328
- // The endpoint of a request has settled: fill in every record built while it was
329
- // still unresolved. `span` is the web-server span, so its tag bag is the key its
330
- // descendants enlisted under.
336
+ // Update the active records when a request's endpoint becomes available or changes.
331
337
  /** @param {DatadogSpan} span */
332
338
  function onEndpointResolved (span) {
333
339
  if (!started) return
@@ -337,16 +343,13 @@ function onEndpointResolved (span) {
337
343
  const waiting = pendingEndpoints.get(webTags)
338
344
  if (!ownWaits && waiting === undefined) return
339
345
  const endpoint = finalEndpoint(webTags)
340
- // webTagsCache only announces settled endpoints, so this is belt and braces.
346
+ // webTagsCache only announces available endpoints, so this is belt and braces.
341
347
  if (endpoint === undefined) return
342
348
  if (ownWaits) {
343
- own.endpointIndex = NOT_WAITING
344
349
  appendEndpoint(own.context, endpoint)
345
350
  }
346
351
  if (waiting === undefined) return
347
- pendingEndpoints.delete(webTags)
348
352
  for (const cached of waiting) {
349
- cached.endpointIndex = NOT_WAITING
350
353
  appendEndpoint(cached.context, endpoint)
351
354
  }
352
355
  }
@@ -366,15 +369,9 @@ function onWebTagsResolved (span) {
366
369
  removePendingEndpoint(cached)
367
370
  cached.webTags = webTags
368
371
  const endpoint = finalEndpoint(webTags)
369
- if (endpoint === undefined) {
370
- // A record that already shows the outer request's endpoint goes on showing
371
- // it until the nearer one settles: the record buffer is append-only, so
372
- // there is no way to take the attribute back, and rebuilding the
373
- // ThreadContext would strand every async-context frame holding this one.
374
- // The work is still nested in the outer request, which makes that the least
375
- // wrong of the values available.
376
- awaitEndpoint(span, webTags, cached)
377
- } else {
372
+ awaitEndpoint(span, webTags, cached)
373
+ // Keep the outer endpoint until the nearer request supplies a replacement; records are append-only.
374
+ if (endpoint !== undefined) {
378
375
  appendEndpoint(cached.context, endpoint)
379
376
  }
380
377
  }
@@ -3,7 +3,6 @@
3
3
  const { channel } = require('dc-polyfill')
4
4
 
5
5
  const {
6
- getEnvironmentVariable,
7
6
  getValueFromEnvSources,
8
7
  isSupportedConfiguration,
9
8
  } = require('./config/helper')
@@ -45,18 +44,15 @@ loadChannel.subscribe(({ name }) => {
45
44
 
46
45
  // instrument everything that needs Plugin System V2 instrumentation
47
46
  require('../../datadog-instrumentations')
48
- if (getEnvironmentVariable('AWS_LAMBDA_FUNCTION_NAME') !== undefined) {
49
- // instrument lambda environment
50
- require('./lambda')
51
- }
52
47
 
53
48
  function maybeEnable (Plugin) {
54
49
  if (!Plugin || typeof Plugin !== 'function') return
55
- if (!pluginClasses[Plugin.id]) {
50
+ const disabled = disabledPlugins.has(Plugin.id)
51
+ if (!pluginClasses[Plugin.id] || disabled) {
56
52
  const enabled = getEnabled(Plugin)
57
53
 
58
54
  // TODO: remove the need to load the plugin class in order to disable the plugin
59
- if (isFalse(enabled) || disabledPlugins.has(Plugin.id)) {
55
+ if (isFalse(enabled) || disabled) {
60
56
  log.debug('Plugin "%s" was disabled via configuration option.', Plugin.id)
61
57
 
62
58
  pluginClasses[Plugin.id] = null
@@ -159,6 +155,10 @@ module.exports = class PluginManager {
159
155
  for (const name in pluginClasses) {
160
156
  this.loadPlugin(name)
161
157
  }
158
+
159
+ // Initialization can publish load events that configure plugins immediately; use the current settings.
160
+ const initializeLambda = require('./lambda')
161
+ initializeLambda()
162
162
  }
163
163
 
164
164
  // This is basically just for testing. like intrumenter.disable()
@@ -181,6 +181,7 @@ module.exports = class PluginManager {
181
181
  #getSharedConfig (name) {
182
182
  const {
183
183
  logInjection,
184
+ lambda,
184
185
  serviceMapping,
185
186
  DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP,
186
187
  site,
@@ -209,6 +210,9 @@ module.exports = class PluginManager {
209
210
  traceWebsocketMessagesSeparateTraces,
210
211
  tracing,
211
212
  DD_TRACE_RESOURCE_RENAMING_ENABLED,
213
+ DD_APM_FLUSH_DEADLINE_MILLISECONDS,
214
+ DD_API_KEY,
215
+ DD_TRACE_AWS_ADD_SPAN_POINTERS,
212
216
  } = /** @type {import('./config/config-base')} */ (this._tracerConfig)
213
217
 
214
218
  const sharedConfig = {
@@ -267,6 +271,29 @@ module.exports = class PluginManager {
267
271
  sharedConfig.depth = DD_TRACE_GRAPHQL_DEPTH
268
272
  sharedConfig.variables = DD_TRACE_GRAPHQL_VARIABLES
269
273
  sharedConfig.errorExtensions = DD_TRACE_GRAPHQL_ERROR_EXTENSIONS
274
+ } else if (name === 'aws-lambda') {
275
+ Object.assign(sharedConfig, {
276
+ addSpanPointers: DD_TRACE_AWS_ADD_SPAN_POINTERS,
277
+ apiKey: DD_API_KEY,
278
+ apiKeyKms: lambda?.DD_KMS_API_KEY,
279
+ apiKeySecretArn: lambda?.DD_API_KEY_SECRET_ARN,
280
+ apmFlushDeadlineMs: DD_APM_FLUSH_DEADLINE_MILLISECONDS,
281
+ captureLambdaPayload: lambda?.DD_CAPTURE_LAMBDA_PAYLOAD,
282
+ captureLambdaPayloadMaxDepth: lambda?.DD_CAPTURE_LAMBDA_PAYLOAD_MAX_DEPTH,
283
+ coldStartTraceSkipLib: lambda?.DD_COLD_START_TRACE_SKIP_LIB,
284
+ coldStartTracing: lambda?.DD_COLD_START_TRACING,
285
+ createInferredSpan: lambda?.DD_TRACE_MANAGED_SERVICES,
286
+ dataStreamsEnabled: dsmEnabled,
287
+ decodeAuthorizerContext: lambda?.DD_DECODE_AUTHORIZER_CONTEXT,
288
+ encodeAuthorizerContext: lambda?.DD_ENCODE_AUTHORIZER_CONTEXT,
289
+ enhancedMetrics: lambda?.DD_ENHANCED_METRICS,
290
+ fipsMode: lambda?.DD_LAMBDA_FIPS_MODE,
291
+ logForwarding: lambda?.DD_FLUSH_TO_LOG,
292
+ logInjection,
293
+ mergeXrayTraces: lambda?.DD_MERGE_XRAY_TRACES,
294
+ minColdStartTraceDurationMs: lambda?.DD_MIN_COLD_START_DURATION,
295
+ serviceRepresentationEnabled: lambda?.DD_TRACE_AWS_SERVICE_REPRESENTATION_ENABLED,
296
+ })
270
297
  }
271
298
 
272
299
  return sharedConfig