dd-trace 5.135.0 → 5.137.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (352) hide show
  1. package/README.md +3 -0
  2. package/ci/cypress/support.js +2 -1
  3. package/ci/init.js +2 -22
  4. package/ci/vitest-no-worker-init-node-setup.mjs +2 -1
  5. package/ci/vitest-no-worker-init-runner-setup.mjs +2 -1
  6. package/ci/vitest-no-worker-init-setup.mjs +729 -724
  7. package/ci/vitest-no-worker-init-v5-setup.mjs +2 -1
  8. package/ext/exporters.js +0 -1
  9. package/index.d.ts +105 -5
  10. package/initialize.mjs +5 -2
  11. package/package.json +41 -36
  12. package/packages/datadog-esbuild/index.js +16 -70
  13. package/packages/datadog-esbuild/src/log.js +2 -29
  14. package/packages/datadog-instrumentations/src/ai.js +6 -1
  15. package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
  16. package/packages/datadog-instrumentations/src/cucumber.js +5 -2
  17. package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
  18. package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
  19. package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
  20. package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
  21. package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
  22. package/packages/datadog-instrumentations/src/graphql.js +20 -17
  23. package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +582 -0
  24. package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
  25. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +576 -0
  26. package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
  27. package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
  28. package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
  29. package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
  30. package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
  31. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +8 -0
  32. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +26 -1
  33. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
  34. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
  35. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
  36. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-client.js +30 -0
  37. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-server.js +23 -0
  38. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +61 -0
  39. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
  40. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
  41. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
  42. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +80 -0
  43. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +23 -3
  44. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
  45. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
  46. package/packages/datadog-instrumentations/src/ioredis.js +101 -3
  47. package/packages/datadog-instrumentations/src/microgateway-core.js +1 -2
  48. package/packages/datadog-instrumentations/src/modelcontextprotocol-client.js +21 -0
  49. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +7 -1
  50. package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +41 -0
  51. package/packages/datadog-instrumentations/src/next.js +203 -26
  52. package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
  53. package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
  54. package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
  55. package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
  56. package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
  57. package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
  58. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
  59. package/packages/datadog-instrumentations/src/router.js +35 -12
  60. package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
  61. package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
  62. package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
  63. package/packages/datadog-plugin-aws-lambda/src/arn.js +41 -0
  64. package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
  65. package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
  66. package/packages/datadog-plugin-aws-lambda/src/trigger.js +339 -0
  67. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +7 -0
  68. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +32 -10
  69. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +10 -1
  70. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -0
  71. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +3 -0
  72. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +50 -13
  73. package/packages/datadog-plugin-cypress/src/support.mjs +1353 -0
  74. package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
  75. package/packages/datadog-plugin-express/src/code_origin.js +2 -2
  76. package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
  77. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +20 -7
  78. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +21 -52
  79. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +11 -2
  80. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
  81. package/packages/datadog-plugin-google-cloud-pubsub/src/resource-names.js +24 -0
  82. package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
  83. package/packages/datadog-plugin-http/src/client.js +34 -10
  84. package/packages/datadog-plugin-http2/src/client.js +40 -14
  85. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +28 -2
  86. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +1 -0
  87. package/packages/datadog-plugin-mongodb-core/src/query.js +17 -1
  88. package/packages/datadog-plugin-next/src/index.js +112 -14
  89. package/packages/datadog-plugin-postgres/src/index.js +118 -41
  90. package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
  91. package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +18 -8
  92. package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +49 -13
  93. package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +34 -9
  94. package/packages/datadog-plugin-trpc/src/index.js +15 -0
  95. package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
  96. package/packages/datadog-plugin-trpc/src/request.js +81 -0
  97. package/packages/datadog-plugin-undici/src/index.js +22 -7
  98. package/packages/datadog-plugin-vitest/src/index.js +3 -2
  99. package/packages/datadog-plugin-ws/src/close.js +3 -5
  100. package/packages/datadog-plugin-ws/src/producer.js +1 -4
  101. package/packages/datadog-plugin-ws/src/receiver.js +3 -5
  102. package/packages/datadog-plugin-ws/src/server.js +44 -13
  103. package/packages/datadog-turbopack/index.js +4 -28
  104. package/packages/datadog-turbopack/src/loader.js +14 -452
  105. package/packages/datadog-vite/index.js +537 -0
  106. package/packages/datadog-vite/src/log.js +5 -0
  107. package/packages/datadog-webpack/index.js +3 -55
  108. package/packages/datadog-webpack/src/log.js +2 -29
  109. package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
  110. package/packages/dd-trace/src/aiguard/index.js +1 -1
  111. package/packages/dd-trace/src/aiguard/integrations/index.js +6 -5
  112. package/packages/dd-trace/src/aiguard/sdk.js +8 -2
  113. package/packages/dd-trace/src/aiguard/tags.js +2 -0
  114. package/packages/dd-trace/src/appsec/blocking/index.js +21 -1
  115. package/packages/dd-trace/src/appsec/channels.js +7 -0
  116. package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
  117. package/packages/dd-trace/src/appsec/graphql.js +89 -7
  118. package/packages/dd-trace/src/appsec/handlers/auth.js +1 -3
  119. package/packages/dd-trace/src/appsec/handlers/http-request.js +60 -65
  120. package/packages/dd-trace/src/appsec/handlers/http-response.js +61 -7
  121. package/packages/dd-trace/src/appsec/handlers/payments.js +23 -27
  122. package/packages/dd-trace/src/appsec/index.js +6 -0
  123. package/packages/dd-trace/src/appsec/lambda.js +17 -17
  124. package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -4
  125. package/packages/dd-trace/src/appsec/rasp/index.js +8 -1
  126. package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -2
  127. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +7 -17
  128. package/packages/dd-trace/src/appsec/rasp/ssrf.js +80 -16
  129. package/packages/dd-trace/src/appsec/rasp/utils.js +33 -3
  130. package/packages/dd-trace/src/appsec/recommended.json +1358 -94
  131. package/packages/dd-trace/src/appsec/reporter.js +9 -0
  132. package/packages/dd-trace/src/appsec/sdk/set_user.js +3 -3
  133. package/packages/dd-trace/src/appsec/sdk/track_event.js +4 -4
  134. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
  135. package/packages/dd-trace/src/appsec/user_tracking.js +6 -8
  136. package/packages/dd-trace/src/appsec/waf/index.js +65 -6
  137. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -38
  138. package/packages/dd-trace/src/appsec/waf/waf_manager.js +18 -2
  139. package/packages/dd-trace/src/before-exit.js +32 -0
  140. package/packages/dd-trace/src/bootstrap.js +5 -3
  141. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +15 -2
  142. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
  143. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
  144. package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
  145. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -2
  146. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
  147. package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
  148. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
  149. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
  150. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
  151. package/packages/dd-trace/src/config/config-types.d.ts +3 -0
  152. package/packages/dd-trace/src/config/defaults.js +5 -0
  153. package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -4
  154. package/packages/dd-trace/src/config/index.js +63 -31
  155. package/packages/dd-trace/src/config/parsers.js +44 -0
  156. package/packages/dd-trace/src/config/remote-config-layers.js +38 -0
  157. package/packages/dd-trace/src/config/remote_config.js +2 -1
  158. package/packages/dd-trace/src/config/supported-configurations.json +172 -10
  159. package/packages/dd-trace/src/constants.js +1 -0
  160. package/packages/dd-trace/src/datastreams/fnv.js +27 -0
  161. package/packages/dd-trace/src/datastreams/pathway.js +113 -28
  162. package/packages/dd-trace/src/datastreams/processor.js +5 -4
  163. package/packages/dd-trace/src/debugger/config.js +1 -1
  164. package/packages/dd-trace/src/debugger/devtools_client/request-options.js +7 -9
  165. package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
  166. package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
  167. package/packages/dd-trace/src/debugger/devtools_client/tags.js +1 -1
  168. package/packages/dd-trace/src/debugger/index.js +2 -2
  169. package/packages/dd-trace/src/debugger/inspect-segment.js +3 -2
  170. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +6 -2
  171. package/packages/dd-trace/src/debugger/probe_sampler.js +39 -17
  172. package/packages/dd-trace/src/debugger/unsupported-runtime.js +2 -0
  173. package/packages/dd-trace/src/exporter.js +0 -11
  174. package/packages/dd-trace/src/exporters/common/request.js +81 -48
  175. package/packages/dd-trace/src/exporters/common/retry.js +12 -7
  176. package/packages/dd-trace/src/exporters/common/url.js +1 -1
  177. package/packages/dd-trace/src/git_metadata.js +2 -1
  178. package/packages/dd-trace/src/id.js +1 -1
  179. package/packages/dd-trace/src/index.js +6 -3
  180. package/packages/dd-trace/src/lambda/facade.js +75 -0
  181. package/packages/dd-trace/src/lambda/handler.js +3 -41
  182. package/packages/dd-trace/src/lambda/index.js +38 -15
  183. package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
  184. package/packages/dd-trace/src/lambda/wrap.js +44 -0
  185. package/packages/dd-trace/src/llmobs/constants/tags.js +2 -0
  186. package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
  187. package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
  188. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
  189. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +54 -3
  190. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +81 -1
  191. package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
  192. package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
  193. package/packages/dd-trace/src/llmobs/sdk.js +19 -0
  194. package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
  195. package/packages/dd-trace/src/llmobs/tagger.js +22 -0
  196. package/packages/dd-trace/src/log/channels.js +4 -0
  197. package/packages/dd-trace/src/log/writer.js +6 -1
  198. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +7 -0
  199. package/packages/dd-trace/src/openfeature/configuration_source.js +55 -27
  200. package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
  201. package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
  202. package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
  203. package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
  204. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
  205. package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
  206. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
  207. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
  208. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
  209. package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
  210. package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
  211. package/packages/dd-trace/src/opentelemetry/span.js +2 -2
  212. package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
  213. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
  214. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
  215. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
  216. package/packages/dd-trace/src/opentracing/tracer.js +24 -0
  217. package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
  218. package/packages/dd-trace/src/plugin_manager.js +34 -7
  219. package/packages/dd-trace/src/plugins/ci_plugin.js +143 -17
  220. package/packages/dd-trace/src/plugins/index.js +8 -0
  221. package/packages/dd-trace/src/plugins/plugin.js +4 -2
  222. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  223. package/packages/dd-trace/src/plugins/util/ci.js +52 -1
  224. package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
  225. package/packages/dd-trace/src/plugins/util/git.js +263 -82
  226. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +80 -56
  227. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
  228. package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
  229. package/packages/dd-trace/src/plugins/util/tags.js +6 -0
  230. package/packages/dd-trace/src/plugins/util/test.js +92 -40
  231. package/packages/dd-trace/src/plugins/util/url.js +18 -7
  232. package/packages/dd-trace/src/plugins/util/user-provided-git.js +6 -6
  233. package/packages/dd-trace/src/plugins/util/web.js +65 -10
  234. package/packages/dd-trace/src/process-tags/index.js +1 -1
  235. package/packages/dd-trace/src/profiler.js +74 -12
  236. package/packages/dd-trace/src/profiling/profiler.js +30 -2
  237. package/packages/dd-trace/src/profiling/profilers/space.js +3 -1
  238. package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
  239. package/packages/dd-trace/src/profiling/remote-config.js +354 -0
  240. package/packages/dd-trace/src/profiling/runtime-capabilities.js +11 -0
  241. package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
  242. package/packages/dd-trace/src/propagation-hash/index.js +7 -0
  243. package/packages/dd-trace/src/proxy.js +46 -54
  244. package/packages/dd-trace/src/span_processor.js +20 -0
  245. package/packages/dd-trace/src/startup-log.js +8 -6
  246. package/packages/dd-trace/src/telemetry/metrics.js +2 -1
  247. package/packages/dd-trace/src/tracer.js +0 -2
  248. package/packages/dd-trace/src/web-tags-cache.js +8 -9
  249. package/register.js +2 -1
  250. package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
  251. package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
  252. package/vendor/dist/@datadog/flagging-core/index.js +1 -0
  253. package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
  254. package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
  255. package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
  256. package/vendor/dist/@datadog/source-map/LICENSE +1 -0
  257. package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
  258. package/vendor/dist/@opentelemetry/core/LICENSE +220 -1
  259. package/vendor/dist/@opentelemetry/core/index.js +1 -1
  260. package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
  261. package/vendor/dist/escape-string-regexp/LICENSE +13 -0
  262. package/vendor/dist/esquery/LICENSE +2 -0
  263. package/vendor/dist/https-proxy-agent/LICENSE +80 -1
  264. package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
  265. package/vendor/dist/jest-docblock/LICENSE +16 -0
  266. package/vendor/dist/jsonpath-plus/LICENSE +13 -0
  267. package/vendor/dist/limiter/LICENSE +2 -0
  268. package/vendor/dist/lodash.sortby/LICENSE +2 -0
  269. package/vendor/dist/lru-cache/LICENSE +13 -0
  270. package/vendor/dist/meriyah/LICENSE +13 -0
  271. package/vendor/dist/module-details-from-path/LICENSE +2 -0
  272. package/vendor/dist/mutexify/promise/LICENSE +28 -0
  273. package/vendor/dist/pprof-format/LICENSE +13 -0
  274. package/vendor/dist/pprof-format/index.js +1 -1
  275. package/vendor/dist/protobufjs/LICENSE +219 -0
  276. package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
  277. package/vendor/dist/proxy-from-env/LICENSE +13 -0
  278. package/vendor/dist/retry/LICENSE +2 -0
  279. package/vendor/dist/rfdc/LICENSE +2 -0
  280. package/vendor/dist/semifies/LICENSE +3 -1
  281. package/vendor/dist/shell-quote/LICENSE +3 -1
  282. package/vendor/dist/source-map/LICENSE +1 -0
  283. package/vendor/dist/source-map/lib/util/LICENSE +1 -0
  284. package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
  285. package/vendor/dist/ttl-set/LICENSE +28 -0
  286. package/vite.d.ts +7 -0
  287. package/vite.js +3 -0
  288. package/ci/diagnose.js +0 -2215
  289. package/ci/runbook.md +0 -299
  290. package/ci/test-optimization-validation/approval-artifacts.js +0 -175
  291. package/ci/test-optimization-validation/approval.js +0 -386
  292. package/ci/test-optimization-validation/artifact-id.js +0 -18
  293. package/ci/test-optimization-validation/blocker-category.js +0 -24
  294. package/ci/test-optimization-validation/bounded-json.js +0 -120
  295. package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
  296. package/ci/test-optimization-validation/ci-discovery.js +0 -192
  297. package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
  298. package/ci/test-optimization-validation/ci-remediation.js +0 -283
  299. package/ci/test-optimization-validation/cli.js +0 -954
  300. package/ci/test-optimization-validation/command-blocker.js +0 -377
  301. package/ci/test-optimization-validation/command-output-policy.js +0 -188
  302. package/ci/test-optimization-validation/command-runner.js +0 -649
  303. package/ci/test-optimization-validation/environment.js +0 -88
  304. package/ci/test-optimization-validation/executable-approval.js +0 -47
  305. package/ci/test-optimization-validation/executable.js +0 -244
  306. package/ci/test-optimization-validation/execution-lock.js +0 -70
  307. package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
  308. package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
  309. package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
  310. package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
  311. package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
  312. package/ci/test-optimization-validation/generated-file-policy.js +0 -63
  313. package/ci/test-optimization-validation/generated-files.js +0 -425
  314. package/ci/test-optimization-validation/generated-test-contract.js +0 -284
  315. package/ci/test-optimization-validation/generated-verifier.js +0 -235
  316. package/ci/test-optimization-validation/literal-environment.js +0 -56
  317. package/ci/test-optimization-validation/literal-glob.js +0 -52
  318. package/ci/test-optimization-validation/manifest-loader.js +0 -116
  319. package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
  320. package/ci/test-optimization-validation/manifest-schema.js +0 -695
  321. package/ci/test-optimization-validation/offline-fixtures.js +0 -335
  322. package/ci/test-optimization-validation/offline-output.js +0 -406
  323. package/ci/test-optimization-validation/package-check.js +0 -97
  324. package/ci/test-optimization-validation/payload-normalizer.js +0 -72
  325. package/ci/test-optimization-validation/plan-writer.js +0 -541
  326. package/ci/test-optimization-validation/preflight-runner.js +0 -186
  327. package/ci/test-optimization-validation/project-build-artifact.js +0 -31
  328. package/ci/test-optimization-validation/redaction.js +0 -319
  329. package/ci/test-optimization-validation/report-writer.js +0 -666
  330. package/ci/test-optimization-validation/result-semantics.js +0 -103
  331. package/ci/test-optimization-validation/runner-command.js +0 -264
  332. package/ci/test-optimization-validation/runner-contract.js +0 -695
  333. package/ci/test-optimization-validation/safe-files.js +0 -202
  334. package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
  335. package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
  336. package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
  337. package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
  338. package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
  339. package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
  340. package/ci/test-optimization-validation/source-text.js +0 -84
  341. package/ci/test-optimization-validation/static-diagnosis.js +0 -166
  342. package/ci/test-optimization-validation/test-output.js +0 -120
  343. package/ci/test-optimization-validation/validation-blocker.js +0 -21
  344. package/ci/validate-test-optimization.js +0 -3
  345. package/packages/datadog-esbuild/src/resolver.js +0 -284
  346. package/packages/datadog-esbuild/src/utils.js +0 -318
  347. package/packages/datadog-plugin-cypress/src/support.js +0 -1348
  348. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
  349. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
  350. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
  351. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
  352. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
@@ -231,7 +231,7 @@ function logWorkerError (error, reason = error.reason) {
231
231
  * Sends the new configuration to the worker thread via the config channel.
232
232
  * Does nothing if the worker is not started.
233
233
  *
234
- * @param {import('../config/config-base')} config - The updated tracer configuration object
234
+ * @param {Config} config - The updated tracer configuration object
235
235
  */
236
236
  function configure (config) {
237
237
  if (configChannel === null) return
@@ -339,7 +339,7 @@ function detectDebuggerEndpoint (config, cb) {
339
339
 
340
340
  log.debug('[debugger] Detecting available debugger endpoints...')
341
341
 
342
- fetchAgentInfo(config.url, (err, agentInfo) => {
342
+ fetchAgentInfo(/** @type {URL} */ (config.url), (err, agentInfo) => {
343
343
  if (err) {
344
344
  log.warn('[debugger] Failed to query agent %s endpoint, falling back to %s',
345
345
  DEBUGGER_INPUT_V2,
@@ -8,13 +8,14 @@ const { REDACTED_PLACEHOLDER } = require('./redaction')
8
8
  /** @typedef {NonNullable<ReturnType<typeof globalThis.Object.getOwnPropertyDescriptor>>} PropertyDescriptor */
9
9
  /** @typedef {Map<unknown, unknown> | Set<unknown>} Collection */
10
10
  /** @typedef {(name: string) => boolean} IsRedactedIdentifier */
11
+ /** @typedef {{ get: (this: Collection) => number }} SizeDescriptor */
11
12
 
12
13
  const mapEntries = Map.prototype.entries
13
14
  const mapKeys = Map.prototype.keys
14
15
  const mapSet = Map.prototype.set
15
- const mapSizeGetter = Object.getOwnPropertyDescriptor(Map.prototype, 'size').get
16
+ const mapSizeGetter = /** @type {SizeDescriptor} */ (Object.getOwnPropertyDescriptor(Map.prototype, 'size')).get
16
17
  const setAdd = Set.prototype.add
17
- const setSizeGetter = Object.getOwnPropertyDescriptor(Set.prototype, 'size').get
18
+ const setSizeGetter = /** @type {SizeDescriptor} */ (Object.getOwnPropertyDescriptor(Set.prototype, 'size')).get
18
19
  const setValues = Set.prototype.values
19
20
  const mapIteratorNext = Object.getPrototypeOf(mapEntries.call(new Map())).next
20
21
  const setIteratorNext = Object.getPrototypeOf(setValues.call(new Set())).next
@@ -1,6 +1,10 @@
1
1
  'use strict'
2
2
 
3
- const { LogCollapsingLowestDenseDDSketch } = require('../../../../vendor/dist/@datadog/sketches-js')
3
+ /** @typedef {typeof import('../../../../vendor/node_modules/@datadog/sketches-js')} Sketches */
4
+ const { LogCollapsingLowestDenseDDSketch } = /** @type {Sketches} */ (
5
+ require('../../../../vendor/dist/@datadog/sketches-js')
6
+ )
7
+ const { TELEMETRY_DISTRIBUTION_RELATIVE_ACCURACY } = require('../constants')
4
8
 
5
9
  /**
6
10
  * Durations of the pauses caused by probes, shared between the debugger worker thread and the main thread.
@@ -17,7 +21,7 @@ const { LogCollapsingLowestDenseDDSketch } = require('../../../../vendor/dist/@d
17
21
  */
18
22
 
19
23
  // Created the same way as the sketch of telemetry distributions, so both map durations to the same keys
20
- const { mapping } = new LogCollapsingLowestDenseDDSketch()
24
+ const { mapping } = new LogCollapsingLowestDenseDDSketch({ relativeAccuracy: TELEMETRY_DISTRIBUTION_RELATIVE_ACCURACY })
21
25
 
22
26
  const MIN_KEY = mapping.key(0.001) // 1 µs
23
27
  const MAX_KEY = mapping.key(60 * 60 * 1000) // 1 hour
@@ -103,9 +103,14 @@ function installProbeSampler (guardrailMetrics, config) {
103
103
  Atomics.store(sampledProbeIndexes, SAMPLED_PROBE_COUNT_INDEX, 0)
104
104
  Atomics.store(sampledProbeIndexes, SAMPLED_PROBE_OVERFLOW_INDEX, 0)
105
105
 
106
- const oneSecondNs = 1_000_000_000n
106
+ const ONE_SECOND_NS = 1_000_000_000n
107
107
  let globalSnapshotSamplingRateWindowStart = 0n
108
- let snapshotsSampledWithinTheLastSecond = 0
108
+ /**
109
+ * The snapshots counted toward the global snapshot rate limit in the current window. Later probes in a sampled trace
110
+ * aren't limited by it, so this can exceed the limit. The excess is carried over into the following windows, which
111
+ * keeps the overall volume within the limit on average.
112
+ */
113
+ let snapshotsCountedInWindow = 0
109
114
 
110
115
  ddTraceGlobal[Symbol.for(PROBE_SAMPLER_SYMBOL)] = {
111
116
  /**
@@ -274,8 +279,9 @@ function installProbeSampler (guardrailMetrics, config) {
274
279
  * Sample a snapshot-producing probe hit using the sampling decision of its trace. The first such probe hit in the
275
280
  * trace makes the decision for all of them, subject to its per-probe rate limit and the global snapshot rate limit.
276
281
  * If the trace is sampled, each probe then emits once in it without being subject to the rate limits, so the trace
277
- * emits a complete set of snapshots. Those snapshots still count toward the rate limits, which keeps the overall
278
- * volume close to the limits by making later traces less likely to be sampled.
282
+ * emits a complete set of snapshots. Those snapshots still count toward the rate limits. Any that exceed the global
283
+ * snapshot rate limit are carried over into its following windows, so later traces are less likely to be sampled
284
+ * until the excess is made up.
279
285
  *
280
286
  * @param {LocalTrace} trace - The trace the probe was hit in.
281
287
  * @param {number} probeIndex - The worker-side probe sampling index.
@@ -325,14 +331,33 @@ function installProbeSampler (guardrailMetrics, config) {
325
331
  return true
326
332
  }
327
333
 
328
- if (isSnapshotProducingProbe &&
329
- now - globalSnapshotSamplingRateWindowStart <= oneSecondNs &&
330
- snapshotsSampledWithinTheLastSecond >= MAX_SNAPSHOTS_PER_SECOND_GLOBALLY) {
331
- guardrailMetrics.eventSkipped(SKIPPED_REASON.RATE_LIMIT_GLOBAL, EVENT_TYPE.SNAPSHOT)
332
- return true
333
- }
334
+ return isSnapshotProducingProbe && isGloballyRateLimited(now)
335
+ }
334
336
 
335
- return false
337
+ /**
338
+ * Check the global snapshot rate limit, recording the skip if it is reached.
339
+ *
340
+ * @param {bigint} now - The current time.
341
+ */
342
+ function isGloballyRateLimited (now) {
343
+ advanceGlobalSnapshotWindow(now)
344
+ if (snapshotsCountedInWindow < MAX_SNAPSHOTS_PER_SECOND_GLOBALLY) return false
345
+ guardrailMetrics.eventSkipped(SKIPPED_REASON.RATE_LIMIT_GLOBAL, EVENT_TYPE.SNAPSHOT)
346
+ return true
347
+ }
348
+
349
+ /**
350
+ * Start a new window of the global snapshot rate limit if the current one has passed. Snapshots counted in excess of
351
+ * the limit are carried over, reduced by the limit for each window that has passed since.
352
+ *
353
+ * @param {bigint} now - The current time.
354
+ */
355
+ function advanceGlobalSnapshotWindow (now) {
356
+ const elapsedNs = now - globalSnapshotSamplingRateWindowStart
357
+ if (elapsedNs <= ONE_SECOND_NS) return
358
+ const allowance = Number(elapsedNs / ONE_SECOND_NS) * MAX_SNAPSHOTS_PER_SECOND_GLOBALLY
359
+ snapshotsCountedInWindow = Math.max(snapshotsCountedInWindow - allowance, 0)
360
+ globalSnapshotSamplingRateWindowStart = now
336
361
  }
337
362
 
338
363
  /**
@@ -347,12 +372,8 @@ function installProbeSampler (guardrailMetrics, config) {
347
372
  if (!storeSampledProbeIndex(probeIndex)) return false
348
373
 
349
374
  if (isSnapshotProducingProbe) {
350
- if (now - globalSnapshotSamplingRateWindowStart > oneSecondNs) {
351
- snapshotsSampledWithinTheLastSecond = 1
352
- globalSnapshotSamplingRateWindowStart = now
353
- } else {
354
- snapshotsSampledWithinTheLastSecond++
355
- }
375
+ advanceGlobalSnapshotWindow(now)
376
+ snapshotsCountedInWindow++
356
377
  }
357
378
 
358
379
  lastCaptureNsByProbeId.set(probeId, now)
@@ -441,6 +462,7 @@ function truncateErrorDescription (description) {
441
462
  *
442
463
  * @param {object} error - The thrown object to inspect.
443
464
  * @param {'name' | 'message'} property - The property to find.
465
+ * @returns {string | void}
444
466
  */
445
467
  function getErrorStringProperty (error, property) {
446
468
  while (error !== null) {
@@ -7,6 +7,8 @@
7
7
  * few of its methods, never returns their results, and never emits its events. Deno doesn't let worker threads
8
8
  * connect to the main thread inspector. Deno reports a Node.js `process.version`, so both runtimes are detected by
9
9
  * their own `process.versions` entry instead.
10
+ *
11
+ * @returns {'Bun' | 'Deno' | void}
10
12
  */
11
13
  function getUnsupportedRuntime () {
12
14
  if (process.versions.bun !== undefined) return 'Bun'
@@ -2,9 +2,7 @@
2
2
 
3
3
  const fs = require('fs')
4
4
  const exporters = require('../../../ext/exporters')
5
- const { getEnvironmentVariable } = require('../../dd-trace/src/config/helper')
6
5
  const constants = require('./constants')
7
- const { isTrue } = require('./util')
8
6
 
9
7
  module.exports = function getExporter (name) {
10
8
  switch (name) {
@@ -22,9 +20,6 @@ module.exports = function getExporter (name) {
22
20
  return require('./ci-visibility/exporters/agentless')
23
21
  case exporters.AGENT_PROXY:
24
22
  return require('./ci-visibility/exporters/agent-proxy')
25
- case exporters.CI_VALIDATION:
26
- if (hasCiValidationEnvironment()) return require('./ci-visibility/exporters/ci-validation')
27
- break
28
23
  case exporters.JEST_WORKER:
29
24
  case exporters.CUCUMBER_WORKER:
30
25
  case exporters.MOCHA_WORKER:
@@ -43,12 +38,6 @@ function usesLambdaLogExporter () {
43
38
  !fs.existsSync(constants.DATADOG_MINI_AGENT_PATH)
44
39
  }
45
40
 
46
- function hasCiValidationEnvironment () {
47
- return isTrue(getEnvironmentVariable('_DD_TEST_OPTIMIZATION_VALIDATION_MODE')) &&
48
- getEnvironmentVariable('_DD_TEST_OPTIMIZATION_VALIDATION_MANIFEST_FILE') &&
49
- getEnvironmentVariable('_DD_TEST_OPTIMIZATION_VALIDATION_OUTPUT_DIR')
50
- }
51
-
52
41
  /**
53
42
  * Whether the tracer effectively uses OTLP for APM spans.
54
43
  * Test Optimization and Electron do not support OTLP even when `OTEL_TRACES_EXPORTER` is `otlp`.
@@ -29,42 +29,84 @@ const maxActiveBufferSize = 1024 * 1024 * 64
29
29
  let activeBufferSize = 0
30
30
 
31
31
  /**
32
- * @param {Buffer|string|Readable|Array<Buffer|string>} data
33
- * @param {object} options
34
- * @param {(error: Error|null, result?: string|null, statusCode?: number,
35
- * headers?: import('node:http').IncomingHttpHeaders, dropped?: boolean) => void} callback
32
+ * @typedef {Omit<import('node:http').RequestOptions, 'agent'> & {
33
+ * agent?: import('node:http').Agent|false,
34
+ * url?: string|URL|object,
35
+ * retry?: boolean,
36
+ * deferTimeoutAbort?: boolean,
37
+ * keepProcessAlive?: boolean,
38
+ * includeErrorResponseBody?: boolean
39
+ * }} RequestOptions
36
40
  */
37
- function request (data, options, callback) {
38
- if (!options.headers) {
39
- options.headers = {}
40
- }
41
+
42
+ /**
43
+ * @param {RequestOptions} options
44
+ * @param {number} contentLength
45
+ * @returns {RequestOptions}
46
+ */
47
+ function prepareRequestOptions (options, contentLength) {
48
+ const connectionOptions = { ...options }
41
49
 
42
50
  if (options.url) {
43
51
  const url = parseUrl(options.url)
44
52
  if (url.protocol === 'unix:') {
45
- options.socketPath = url.pathname
53
+ if (options.protocol !== undefined) connectionOptions.protocol = undefined
54
+ if (options.hostname !== undefined) connectionOptions.hostname = undefined
55
+ if (options.host !== undefined) connectionOptions.host = undefined
56
+ if (options.port !== undefined) connectionOptions.port = undefined
57
+ connectionOptions.socketPath = url.pathname
46
58
  } else {
47
- if (!options.path) options.path = url.path
48
- options.protocol = url.protocol
49
- options.hostname = url.hostname // for IPv6 this should be '::1' and not '[::1]'
50
- options.port = url.port
59
+ if (options.socketPath !== undefined) connectionOptions.socketPath = undefined
60
+ if (options.host !== undefined) connectionOptions.host = undefined
61
+ connectionOptions.protocol = url.protocol
62
+ connectionOptions.hostname = url.hostname
63
+ connectionOptions.port = url.port
64
+ if (!options.path) connectionOptions.path = url.path
51
65
  }
52
66
  }
67
+ if (connectionOptions.protocol !== undefined &&
68
+ connectionOptions.protocol !== 'http:' &&
69
+ connectionOptions.protocol !== 'https:') {
70
+ throw Object.assign(
71
+ new TypeError(`Unsupported request protocol: ${connectionOptions.protocol}`),
72
+ { code: 'ERR_INVALID_PROTOCOL' }
73
+ )
74
+ }
53
75
 
54
- // Never put the Datadog API key on a cleartext connection to a non-loopback host; that would
55
- // expose it on the wire. Loopback (local agent, dev proxy, tests) is exempt. Strip the key
56
- // rather than drop the request: the agent proxies telemetry with its own key, while an https
57
- // intake URL is required to authenticate agentless traffic.
58
- const hasApiKey = options.headers['dd-api-key'] !== undefined || options.headers['DD-API-KEY'] !== undefined
59
- if (hasApiKey && !canSendApiKey(options.protocol, options.hostname)) {
76
+ const sourceHeaders = options.headers ?? {}
77
+ const headers = { ...sourceHeaders }
78
+ const isSecure = connectionOptions.protocol === 'https:'
79
+ const hasApiKey = sourceHeaders['dd-api-key'] !== undefined || sourceHeaders['DD-API-KEY'] !== undefined
80
+
81
+ // Local agents proxy with their own key. Strip unsafe keys instead of dropping the request.
82
+ if (hasApiKey && !canSendApiKey(connectionOptions.protocol, connectionOptions.hostname)) {
60
83
  log.error(
61
84
  'Not sending the Datadog API key over a non-TLS connection to %s. Configure an https intake URL.',
62
- options.hostname
85
+ connectionOptions.hostname
63
86
  )
64
- delete options.headers['dd-api-key']
65
- delete options.headers['DD-API-KEY']
87
+ delete headers['dd-api-key']
88
+ delete headers['DD-API-KEY']
66
89
  }
67
90
 
91
+ headers['Content-Length'] = contentLength
92
+ docker.inject(headers)
93
+ connectionOptions.headers = headers
94
+
95
+ const directAgent = options.agent ?? (isSecure ? httpsAgent : httpAgent)
96
+ connectionOptions.agent = hasApiKey && isSecure
97
+ ? getHttpsProxyAgent(connectionOptions, directAgent)
98
+ : directAgent
99
+
100
+ return connectionOptions
101
+ }
102
+
103
+ /**
104
+ * @param {Buffer|string|Readable|Array<Buffer|string>} data
105
+ * @param {RequestOptions} options
106
+ * @param {(error: Error|null, result?: string|null, statusCode?: number,
107
+ * headers?: import('node:http').IncomingHttpHeaders, dropped?: boolean) => void} callback
108
+ */
109
+ function request (data, options, callback) {
68
110
  if (data instanceof Readable) {
69
111
  const chunks = []
70
112
 
@@ -84,25 +126,16 @@ function request (data, options, callback) {
84
126
 
85
127
  // The timeout should be kept low to avoid excessive queueing.
86
128
  const timeout = options.timeout || 2000
87
- const isSecure = options.protocol === 'https:'
88
- const client = isSecure ? https : http
89
129
  const dataArray = Array.isArray(data) ? data : [data]
90
130
  const contentLength = byteLength(dataArray)
91
- options.headers['Content-Length'] = contentLength
92
-
93
- docker.inject(options.headers)
94
-
95
- let agent = options.agent ?? (isSecure ? httpsAgent : httpAgent)
96
- if (hasApiKey && isSecure) {
97
- try {
98
- agent = getHttpsProxyAgent(options, agent)
99
- } catch (error) {
100
- callback(error)
101
- return
102
- }
131
+ let connectionOptions
132
+ try {
133
+ connectionOptions = prepareRequestOptions(options, contentLength)
134
+ } catch (error) {
135
+ callback(error)
136
+ return
103
137
  }
104
-
105
- const connectionOptions = { ...options, agent }
138
+ const client = connectionOptions.protocol === 'https:' ? https : http
106
139
 
107
140
  /**
108
141
  * @param {import('node:http').IncomingMessage} res
@@ -111,7 +144,7 @@ function request (data, options, callback) {
111
144
  * @param {(error: Error) => void} handleError
112
145
  */
113
146
  const onResponse = (res, complete, handleError) => {
114
- markEndpointReached(options)
147
+ markEndpointReached(connectionOptions)
115
148
 
116
149
  const chunks = []
117
150
 
@@ -153,8 +186,8 @@ function request (data, options, callback) {
153
186
  let errorMessage = ''
154
187
  try {
155
188
  const fullUrl = new URL(
156
- options.path,
157
- options.url || options.hostname || `http://localhost:${options.port}`
189
+ String(connectionOptions.path),
190
+ connectionOptions.url || connectionOptions.hostname || `http://localhost:${connectionOptions.port}`
158
191
  ).href
159
192
  errorMessage = `Error from ${fullUrl}: ${res.statusCode} ${http.STATUS_CODES[res.statusCode]}.`
160
193
  } catch {
@@ -219,15 +252,15 @@ function request (data, options, callback) {
219
252
  if (settled) return
220
253
  clearImmediate(timeoutImmediate)
221
254
 
222
- if (options.retry !== false &&
223
- attemptIndex < getMaxAttempts(options) &&
255
+ if (connectionOptions.retry !== false &&
256
+ attemptIndex < getMaxAttempts(connectionOptions) &&
224
257
  isRetriableNetworkError(error)) {
225
258
  settled = true
226
259
  finalize()
227
- const retryTimer = setTimeout(attempt, getRetryDelay(options, attemptIndex), attemptIndex + 1)
260
+ const retryTimer = setTimeout(attempt, getRetryDelay(connectionOptions, attemptIndex), attemptIndex + 1)
228
261
  // Background retries must not keep the host process alive. Lifecycle-owned
229
262
  // requests can opt in when their final result must be observed.
230
- if (!options.keepProcessAlive) retryTimer.unref?.()
263
+ if (!connectionOptions.keepProcessAlive) retryTimer.unref?.()
231
264
  } else {
232
265
  complete(error)
233
266
  }
@@ -236,7 +269,7 @@ function request (data, options, callback) {
236
269
  const req = client.request(connectionOptions, (res) => onResponse(res, complete, handleError))
237
270
 
238
271
  req.once('close', finalize)
239
- if (!options.deferTimeoutAbort) req.once('timeout', finalize)
272
+ if (!connectionOptions.deferTimeoutAbort) req.once('timeout', finalize)
240
273
  req.once('error', handleError)
241
274
 
242
275
  const abortRequest = () => {
@@ -253,7 +286,7 @@ function request (data, options, callback) {
253
286
  }
254
287
 
255
288
  req.setTimeout(timeout, () => {
256
- if (!options.deferTimeoutAbort) {
289
+ if (!connectionOptions.deferTimeoutAbort) {
257
290
  abortRequest()
258
291
  return
259
292
  }
@@ -262,7 +295,7 @@ function request (data, options, callback) {
262
295
  abortRequest()
263
296
  finalize()
264
297
  })
265
- if (!options.keepProcessAlive) timeoutImmediate.unref?.()
298
+ if (!connectionOptions.keepProcessAlive) timeoutImmediate.unref?.()
266
299
  })
267
300
 
268
301
  for (const buffer of dataArray) req.write(buffer)
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const { parseUrl } = require('./url')
4
+
3
5
  const RATE_LIMIT_MAX_WAIT_MS = 30_000
4
6
 
5
7
  const SINGLE_RETRY_BASE_MS = 5000
@@ -29,10 +31,11 @@ const reachedEndpoints = new Set()
29
31
 
30
32
  /**
31
33
  * @typedef {object} EndpointOptions
32
- * @property {string} [socketPath]
33
- * @property {string} [hostname]
34
- * @property {string} [host]
35
- * @property {string|number} [port]
34
+ * @property {string|URL|object} [url]
35
+ * @property {string|null} [socketPath]
36
+ * @property {string|null} [hostname]
37
+ * @property {string|null} [host]
38
+ * @property {string|number|null} [port]
36
39
  */
37
40
 
38
41
  /**
@@ -47,9 +50,7 @@ function singleJitteredDelay () {
47
50
  }
48
51
 
49
52
  /**
50
- * Stable key identifying the destination so the startup-phase gate is scoped
51
- * per endpoint. UDS path beats host:port because both can coexist on the same
52
- * options object after `parseUrl` runs.
53
+ * Stable destination key for prepared transport options.
53
54
  *
54
55
  * @param {EndpointOptions} options
55
56
  */
@@ -63,6 +64,10 @@ function getEndpointKey (options) {
63
64
  */
64
65
  function inStartupPhase (options) {
65
66
  if ((Date.now() - startedAtMs) >= STARTUP_GRACE_MS) return false
67
+ if (options.url) {
68
+ const url = parseUrl(options.url)
69
+ return !reachedEndpoints.has(url.protocol === 'unix:' ? url.pathname : getEndpointKey(url))
70
+ }
66
71
  return !reachedEndpoints.has(getEndpointKey(options))
67
72
  }
68
73
 
@@ -21,7 +21,7 @@ function isLoopbackHost (hostname) {
21
21
 
22
22
  /**
23
23
  * @param {string|undefined} protocol
24
- * @param {string|undefined} hostname
24
+ * @param {string|undefined|null} hostname
25
25
  */
26
26
  function canSendApiKey (protocol, hostname) {
27
27
  return protocol === 'https:' || protocol === 'unix:' ||
@@ -19,7 +19,8 @@ const {
19
19
  const cache = {}
20
20
 
21
21
  /**
22
- * @param {import('./config/config-types').ConfigProperties} config
22
+ * @param {Pick<import('./config/config-types').ConfigProperties, 'DD_GIT_COMMIT_SHA' | 'DD_GIT_FOLDER_PATH' |
23
+ * 'DD_GIT_PROPERTIES_FILE' | 'DD_GIT_REPOSITORY_URL' | 'DD_TRACE_GIT_METADATA_ENABLED' | 'tags'>} config
23
24
  */
24
25
  function getGitMetadata (config) {
25
26
  if (!config.DD_TRACE_GIT_METADATA_ENABLED) {
@@ -48,7 +48,7 @@ class Identifier {
48
48
  }
49
49
 
50
50
  toBigInt () {
51
- this.#bigInt ??= Buffer.from(this.#buffer).readBigUInt64BE(0)
51
+ this.#bigInt ??= Buffer.from(this.#buffer).readBigUInt64BE(this.#buffer.length - 8)
52
52
  return this.#bigInt
53
53
  }
54
54
 
@@ -6,13 +6,16 @@ const { isTrue } = require('./util')
6
6
  // Global `jest` is only present in Jest workers.
7
7
  const inJestWorker = typeof jest !== 'undefined'
8
8
 
9
- // skipDefault: distinguish an unset DD_TRACE_ENABLED (fall back to the OTel signal) from an
10
- // explicit value; the registered default would otherwise mask the OTEL_TRACES_EXPORTER check.
9
+ // skipDefault: distinguish an unset DD_TRACE_ENABLED (fall back to the OTel settings) from an
10
+ // explicit value; the registered default would otherwise mask the OTel checks.
11
11
  const ddTraceEnabled = getValueFromEnvSources('DD_TRACE_ENABLED', true)
12
12
  const agentlessTracingEnabled = getValueFromEnvSources('DD_AGENTLESS_ENABLED') ||
13
13
  isTrue(getEnvironmentVariable('_DD_APM_TRACING_AGENTLESS_ENABLED'))
14
+ // OTEL_SDK_DISABLED turns the whole SDK off, while OTEL_TRACES_EXPORTER only selects a trace
15
+ // transport, which agentless mode replaces.
14
16
  const ddTraceDisabled = ddTraceEnabled === undefined
15
- ? !agentlessTracingEnabled && getValueFromEnvSources('OTEL_TRACES_EXPORTER') === 'none'
17
+ ? getValueFromEnvSources('OTEL_SDK_DISABLED') ||
18
+ (!agentlessTracingEnabled && getValueFromEnvSources('OTEL_TRACES_EXPORTER') === 'none')
16
19
  : ddTraceEnabled === false
17
20
 
18
21
  module.exports = ddTraceDisabled || inJestWorker
@@ -0,0 +1,75 @@
1
+ 'use strict'
2
+
3
+ // Internal bridge for datadog-lambda-js. Applications should use that package's wrapper API.
4
+
5
+ const tracer = require('../../../..')
6
+ const { AUTO_KEEP } = require('../../../../ext/priority')
7
+ const { writeDatadogTraceId, writeDatadogParentId, writeDatadogSamplingPriority } = require('../carrier')
8
+ const { wrapLambdaHandler } = require('./wrap')
9
+
10
+ /**
11
+ * Returns Datadog propagation headers for the active Lambda invocation span.
12
+ *
13
+ * @returns {Record<string, string>} Trace propagation headers, or an empty object outside an invocation.
14
+ */
15
+ function getTraceHeaders () {
16
+ const span = tracer.scope().active()
17
+ if (!span) return {}
18
+
19
+ // Ported from datadog-lambda-js's TraceContextService.currentTraceHeaders and
20
+ // SpanContextWrapper.sampleMode. This fixed Datadog carrier must not depend on the configured
21
+ // injection styles or force a sampling decision as tracer.inject() does.
22
+ const context = span.context()
23
+ const headers = {}
24
+ writeDatadogTraceId(headers, context.toTraceId())
25
+ writeDatadogParentId(headers, context.toSpanId())
26
+ writeDatadogSamplingPriority(headers, String(context._sampling?.priority ?? AUTO_KEEP))
27
+ return headers
28
+ }
29
+
30
+ /**
31
+ * Submits a custom Lambda distribution metric.
32
+ */
33
+ function sendDistributionMetric () {
34
+ throw new Error(notImplemented('sendDistributionMetric'))
35
+ }
36
+
37
+ /**
38
+ * Submits a timestamped custom Lambda distribution metric.
39
+ */
40
+ function sendDistributionMetricWithDate () {
41
+ throw new Error(notImplemented('sendDistributionMetricWithDate'))
42
+ }
43
+
44
+ /**
45
+ * Renders a handler-load failure (error span + error metric) for a failure the plugin lifecycle
46
+ * cannot observe: the customer module failed during evaluation, so there is no invocation.
47
+ *
48
+ * @param {{ error: Error, functionName: string, startTime: number }} failure Init failure details.
49
+ */
50
+ function reportInitFailure (failure) {
51
+ throw new Error(notImplemented('reportInitFailure'))
52
+ }
53
+
54
+ /**
55
+ * Builds the message for a facade entry point whose implementation has not landed yet.
56
+ *
57
+ * The shim requires the same internal contract on each supported tracer line. Throwing keeps the gap loud:
58
+ * a silent no-op here would drop customer metrics with no error anywhere.
59
+ * The shim's integration lands only after these are implemented, so the throw never ships to a
60
+ * shim user.
61
+ *
62
+ * @param {string} name Facade entry point.
63
+ */
64
+ function notImplemented (name) {
65
+ return `Internal Lambda ${name}() is not implemented yet. ` +
66
+ 'Keep using datadog-lambda-js for custom metrics until the metrics pipeline is ported.'
67
+ }
68
+
69
+ module.exports = {
70
+ getTraceHeaders,
71
+ reportInitFailure,
72
+ sendDistributionMetric,
73
+ sendDistributionMetricWithDate,
74
+ wrap: wrapLambdaHandler,
75
+ }
@@ -1,15 +1,13 @@
1
1
  'use strict'
2
2
 
3
- const { types: { isProxy } } = require('node:util')
4
-
5
3
  const { channel } = require('../../../datadog-instrumentations/src/helpers/instrument')
4
+ const { copyHandlerMetadata, getDataProperty } =
5
+ require('../../../datadog-instrumentations/src/helpers/lambda-handler')
6
6
  const { ERROR_MESSAGE, ERROR_TYPE } = require('../constants')
7
7
  const log = require('../log')
8
8
  const { ImpendingTimeout } = require('./runtime/errors')
9
9
  const { extractContext } = require('./context')
10
10
 
11
- const HANDLER_STREAMING = Symbol.for('aws.lambda.runtime.handler.streaming')
12
- const HANDLER_HIGHWATERMARK = Symbol.for('aws.lambda.runtime.handler.streaming.highWaterMark')
13
11
  const BEFORE_EXIT = Symbol.for('aws.lambda.beforeExit')
14
12
  const timeoutChannel = channel('apm:aws:lambda:timeout')
15
13
  const monitoredContexts = new WeakSet()
@@ -171,28 +169,7 @@ exports.datadog = function datadog (lambdaHandler, normalized = false) {
171
169
 
172
170
  if (normalized) return monitored
173
171
 
174
- // datadog-lambda-js uses arity and the runtime's streaming metadata to choose how to invoke the handler.
175
- Object.defineProperty(monitored, 'length', { value: getDataProperty(lambdaHandler, 'length') ?? 0 })
176
- for (const name of [HANDLER_STREAMING, HANDLER_HIGHWATERMARK, '_ddWrapped']) {
177
- const value = getDataProperty(lambdaHandler, name)
178
- if (value !== undefined) monitored[name] = value
179
- }
180
- if (!isProxy(lambdaHandler)) {
181
- for (const name of Reflect.ownKeys(lambdaHandler)) {
182
- if (name === 'arguments' || name === 'caller') continue
183
- const descriptor = Object.getOwnPropertyDescriptor(lambdaHandler, name)
184
- if (!Object.hasOwn(descriptor, 'value')) continue
185
- const existing = Object.getOwnPropertyDescriptor(monitored, name)
186
- if (existing?.configurable === false) {
187
- // Intrinsic function slots such as prototype cannot change their descriptor shape.
188
- if (existing.writable) {
189
- Object.defineProperty(monitored, name, { value: descriptor.value, writable: descriptor.writable })
190
- }
191
- } else {
192
- Object.defineProperty(monitored, name, descriptor)
193
- }
194
- }
195
- }
172
+ copyHandlerMetadata(lambdaHandler, monitored)
196
173
  return monitored
197
174
  }
198
175
 
@@ -226,18 +203,3 @@ function onCompletion (callback, clear) {
226
203
  return Reflect.apply(callback, this, args)
227
204
  }
228
205
  }
229
-
230
- /**
231
- * Reads metadata without executing application getters or Proxy traps.
232
- *
233
- * @param {unknown} target
234
- * @param {string | symbol} name
235
- */
236
- function getDataProperty (target, name) {
237
- if (target === null || (typeof target !== 'object' && typeof target !== 'function')) return
238
- while (target !== null && !isProxy(target)) {
239
- const descriptor = Object.getOwnPropertyDescriptor(target, name)
240
- if (descriptor) return descriptor.value
241
- target = Object.getPrototypeOf(target)
242
- }
243
- }