dd-trace 5.135.0 → 5.136.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 (250) hide show
  1. package/ci/init.js +2 -22
  2. package/ext/exporters.js +0 -1
  3. package/index.d.ts +105 -5
  4. package/initialize.mjs +5 -2
  5. package/lambda.d.ts +39 -0
  6. package/lambda.js +3 -0
  7. package/package.json +11 -9
  8. package/packages/datadog-esbuild/index.js +8 -55
  9. package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
  10. package/packages/datadog-instrumentations/src/cucumber.js +5 -2
  11. package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
  12. package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
  13. package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
  14. package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
  15. package/packages/datadog-instrumentations/src/graphql.js +20 -17
  16. package/packages/{datadog-esbuild/src/utils.js → datadog-instrumentations/src/helpers/bundler-esm-exports.js} +282 -40
  17. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +573 -0
  18. package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
  19. package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
  20. package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
  21. package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
  22. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +2 -0
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +18 -1
  24. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
  25. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
  26. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
  27. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +40 -0
  28. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
  29. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
  30. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +50 -0
  31. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +17 -3
  32. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
  33. package/packages/datadog-instrumentations/src/ioredis.js +101 -3
  34. package/packages/datadog-instrumentations/src/next.js +19 -6
  35. package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
  36. package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
  37. package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
  38. package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
  39. package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
  40. package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
  41. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
  42. package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
  43. package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
  44. package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
  45. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +22 -11
  46. package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
  47. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -7
  48. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -52
  49. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +4 -2
  50. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
  51. package/packages/datadog-plugin-http/src/client.js +32 -9
  52. package/packages/datadog-plugin-http2/src/client.js +38 -13
  53. package/packages/datadog-plugin-next/src/index.js +112 -14
  54. package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
  55. package/packages/datadog-plugin-trpc/src/index.js +15 -0
  56. package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
  57. package/packages/datadog-plugin-trpc/src/request.js +81 -0
  58. package/packages/datadog-plugin-undici/src/index.js +22 -7
  59. package/packages/datadog-turbopack/index.js +4 -28
  60. package/packages/datadog-turbopack/src/loader.js +14 -452
  61. package/packages/datadog-webpack/index.js +3 -55
  62. package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
  63. package/packages/dd-trace/src/aiguard/sdk.js +8 -2
  64. package/packages/dd-trace/src/aiguard/tags.js +2 -0
  65. package/packages/dd-trace/src/appsec/blocking/index.js +4 -0
  66. package/packages/dd-trace/src/appsec/graphql.js +91 -6
  67. package/packages/dd-trace/src/appsec/recommended.json +1287 -90
  68. package/packages/dd-trace/src/before-exit.js +32 -0
  69. package/packages/dd-trace/src/bootstrap.js +5 -3
  70. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +15 -2
  71. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
  72. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
  73. package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
  74. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -2
  75. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
  76. package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
  77. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
  78. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
  79. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
  80. package/packages/dd-trace/src/config/config-types.d.ts +3 -0
  81. package/packages/dd-trace/src/config/defaults.js +5 -0
  82. package/packages/dd-trace/src/config/generated-config-types.d.ts +42 -2
  83. package/packages/dd-trace/src/config/index.js +17 -5
  84. package/packages/dd-trace/src/config/parsers.js +9 -0
  85. package/packages/dd-trace/src/config/supported-configurations.json +158 -4
  86. package/packages/dd-trace/src/constants.js +1 -0
  87. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +2 -1
  88. package/packages/dd-trace/src/exporter.js +0 -11
  89. package/packages/dd-trace/src/exporters/common/request.js +81 -48
  90. package/packages/dd-trace/src/exporters/common/retry.js +12 -7
  91. package/packages/dd-trace/src/exporters/common/url.js +1 -1
  92. package/packages/dd-trace/src/id.js +1 -1
  93. package/packages/dd-trace/src/lambda/facade.js +74 -0
  94. package/packages/dd-trace/src/lambda/handler.js +3 -41
  95. package/packages/dd-trace/src/lambda/index.js +38 -15
  96. package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
  97. package/packages/dd-trace/src/lambda/wrap.js +44 -0
  98. package/packages/dd-trace/src/llmobs/constants/tags.js +2 -0
  99. package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
  100. package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
  101. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
  102. package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
  103. package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
  104. package/packages/dd-trace/src/llmobs/sdk.js +19 -0
  105. package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
  106. package/packages/dd-trace/src/llmobs/tagger.js +22 -0
  107. package/packages/dd-trace/src/log/channels.js +4 -0
  108. package/packages/dd-trace/src/log/writer.js +6 -1
  109. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +4 -0
  110. package/packages/dd-trace/src/openfeature/configuration_source.js +35 -27
  111. package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
  112. package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
  113. package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
  114. package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
  115. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
  116. package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
  117. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
  118. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
  119. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
  120. package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
  121. package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
  122. package/packages/dd-trace/src/opentelemetry/span.js +2 -2
  123. package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
  124. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
  125. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
  126. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
  127. package/packages/dd-trace/src/opentracing/tracer.js +24 -0
  128. package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
  129. package/packages/dd-trace/src/plugin_manager.js +34 -7
  130. package/packages/dd-trace/src/plugins/ci_plugin.js +41 -10
  131. package/packages/dd-trace/src/plugins/index.js +6 -0
  132. package/packages/dd-trace/src/plugins/plugin.js +4 -2
  133. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  134. package/packages/dd-trace/src/plugins/util/ci.js +18 -1
  135. package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
  136. package/packages/dd-trace/src/plugins/util/git.js +263 -82
  137. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +75 -46
  138. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
  139. package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
  140. package/packages/dd-trace/src/plugins/util/tags.js +6 -0
  141. package/packages/dd-trace/src/plugins/util/test.js +64 -39
  142. package/packages/dd-trace/src/plugins/util/url.js +10 -2
  143. package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -2
  144. package/packages/dd-trace/src/plugins/util/web.js +65 -10
  145. package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
  146. package/packages/dd-trace/src/proxy.js +33 -53
  147. package/packages/dd-trace/src/span_processor.js +20 -0
  148. package/packages/dd-trace/src/startup-log.js +8 -6
  149. package/packages/dd-trace/src/telemetry/metrics.js +2 -1
  150. package/packages/dd-trace/src/tracer.js +0 -2
  151. package/packages/dd-trace/src/web-tags-cache.js +8 -9
  152. package/register.js +2 -1
  153. package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
  154. package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
  155. package/vendor/dist/@datadog/flagging-core/index.js +1 -0
  156. package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
  157. package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
  158. package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
  159. package/vendor/dist/@datadog/source-map/LICENSE +1 -0
  160. package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
  161. package/vendor/dist/@opentelemetry/core/LICENSE +209 -1
  162. package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
  163. package/vendor/dist/escape-string-regexp/LICENSE +13 -0
  164. package/vendor/dist/esquery/LICENSE +2 -0
  165. package/vendor/dist/https-proxy-agent/LICENSE +80 -1
  166. package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
  167. package/vendor/dist/jest-docblock/LICENSE +16 -0
  168. package/vendor/dist/jsonpath-plus/LICENSE +13 -0
  169. package/vendor/dist/limiter/LICENSE +2 -0
  170. package/vendor/dist/lodash.sortby/LICENSE +2 -0
  171. package/vendor/dist/lru-cache/LICENSE +13 -0
  172. package/vendor/dist/meriyah/LICENSE +13 -0
  173. package/vendor/dist/module-details-from-path/LICENSE +2 -0
  174. package/vendor/dist/mutexify/promise/LICENSE +28 -0
  175. package/vendor/dist/pprof-format/LICENSE +13 -0
  176. package/vendor/dist/pprof-format/index.js +1 -1
  177. package/vendor/dist/protobufjs/LICENSE +219 -0
  178. package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
  179. package/vendor/dist/proxy-from-env/LICENSE +13 -0
  180. package/vendor/dist/retry/LICENSE +2 -0
  181. package/vendor/dist/rfdc/LICENSE +2 -0
  182. package/vendor/dist/semifies/LICENSE +3 -1
  183. package/vendor/dist/shell-quote/LICENSE +3 -1
  184. package/vendor/dist/source-map/LICENSE +1 -0
  185. package/vendor/dist/source-map/lib/util/LICENSE +1 -0
  186. package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
  187. package/vendor/dist/ttl-set/LICENSE +28 -0
  188. package/ci/diagnose.js +0 -2215
  189. package/ci/runbook.md +0 -299
  190. package/ci/test-optimization-validation/approval-artifacts.js +0 -175
  191. package/ci/test-optimization-validation/approval.js +0 -386
  192. package/ci/test-optimization-validation/artifact-id.js +0 -18
  193. package/ci/test-optimization-validation/blocker-category.js +0 -24
  194. package/ci/test-optimization-validation/bounded-json.js +0 -120
  195. package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
  196. package/ci/test-optimization-validation/ci-discovery.js +0 -192
  197. package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
  198. package/ci/test-optimization-validation/ci-remediation.js +0 -283
  199. package/ci/test-optimization-validation/cli.js +0 -954
  200. package/ci/test-optimization-validation/command-blocker.js +0 -377
  201. package/ci/test-optimization-validation/command-output-policy.js +0 -188
  202. package/ci/test-optimization-validation/command-runner.js +0 -649
  203. package/ci/test-optimization-validation/environment.js +0 -88
  204. package/ci/test-optimization-validation/executable-approval.js +0 -47
  205. package/ci/test-optimization-validation/executable.js +0 -244
  206. package/ci/test-optimization-validation/execution-lock.js +0 -70
  207. package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
  208. package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
  209. package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
  210. package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
  211. package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
  212. package/ci/test-optimization-validation/generated-file-policy.js +0 -63
  213. package/ci/test-optimization-validation/generated-files.js +0 -425
  214. package/ci/test-optimization-validation/generated-test-contract.js +0 -284
  215. package/ci/test-optimization-validation/generated-verifier.js +0 -235
  216. package/ci/test-optimization-validation/literal-environment.js +0 -56
  217. package/ci/test-optimization-validation/literal-glob.js +0 -52
  218. package/ci/test-optimization-validation/manifest-loader.js +0 -116
  219. package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
  220. package/ci/test-optimization-validation/manifest-schema.js +0 -695
  221. package/ci/test-optimization-validation/offline-fixtures.js +0 -335
  222. package/ci/test-optimization-validation/offline-output.js +0 -406
  223. package/ci/test-optimization-validation/package-check.js +0 -97
  224. package/ci/test-optimization-validation/payload-normalizer.js +0 -72
  225. package/ci/test-optimization-validation/plan-writer.js +0 -541
  226. package/ci/test-optimization-validation/preflight-runner.js +0 -186
  227. package/ci/test-optimization-validation/project-build-artifact.js +0 -31
  228. package/ci/test-optimization-validation/redaction.js +0 -319
  229. package/ci/test-optimization-validation/report-writer.js +0 -666
  230. package/ci/test-optimization-validation/result-semantics.js +0 -103
  231. package/ci/test-optimization-validation/runner-command.js +0 -264
  232. package/ci/test-optimization-validation/runner-contract.js +0 -695
  233. package/ci/test-optimization-validation/safe-files.js +0 -202
  234. package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
  235. package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
  236. package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
  237. package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
  238. package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
  239. package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
  240. package/ci/test-optimization-validation/source-text.js +0 -84
  241. package/ci/test-optimization-validation/static-diagnosis.js +0 -166
  242. package/ci/test-optimization-validation/test-output.js +0 -120
  243. package/ci/test-optimization-validation/validation-blocker.js +0 -21
  244. package/ci/validate-test-optimization.js +0 -3
  245. package/packages/datadog-esbuild/src/resolver.js +0 -284
  246. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
  247. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
  248. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
  249. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
  250. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
@@ -13,25 +13,7 @@ const REQUIRED_SETTINGS_KEYS = [
13
13
  'impacted_tests_enabled',
14
14
  'coverage_report_upload_enabled',
15
15
  ]
16
- const SETTINGS_BOOLEAN_KEYS = [
17
- 'code_coverage',
18
- 'tests_skipping',
19
- 'itr_enabled',
20
- 'require_git',
21
- 'flaky_test_retries_enabled',
22
- 'di_enabled',
23
- 'known_tests_enabled',
24
- 'impacted_tests_enabled',
25
- 'coverage_report_upload_enabled',
26
- ]
27
- const EARLY_FLAKE_DETECTION_KEYS = ['enabled', 'faulty_session_threshold', 'slow_test_retries']
28
- const TEST_MANAGEMENT_KEYS = ['attempt_to_fix_retries', 'enabled']
29
- const RETRY_THRESHOLD_PATTERN = /^\d+(?:ms|[smh])$/
30
- const MAX_VALIDATION_MODULES = 1000
31
- const MAX_VALIDATION_SUITES = 10_000
32
- const MAX_VALIDATION_TESTS = 100_000
33
16
  const MAX_RETRIES = 100
34
- const MAX_VALIDATION_STRING_BYTES = 4096
35
17
 
36
18
  function isObject (value) {
37
19
  return value !== null && typeof value === 'object' && !Array.isArray(value)
@@ -57,7 +39,7 @@ function getAttributes (response, endpoint) {
57
39
  return attributes
58
40
  }
59
41
 
60
- function validateSettingsResponse (response, options = {}) {
42
+ function validateSettingsResponse (response) {
61
43
  const attributes = response?.data?.attributes ?? response
62
44
  assertObject(attributes, 'Invalid settings response: attributes must be an object')
63
45
  assertHasKeys(attributes, REQUIRED_SETTINGS_KEYS, 'settings')
@@ -65,26 +47,9 @@ function validateSettingsResponse (response, options = {}) {
65
47
  assertObject(attributes.test_management, 'Invalid settings response: test_management must be an object')
66
48
  assertHasKeys(attributes.early_flake_detection, ['enabled'], 'settings early_flake_detection')
67
49
  assertHasKeys(attributes.test_management, ['enabled'], 'settings test_management')
68
- if (!options.validationMode) return
69
-
70
- assertOnlyKeys(attributes, REQUIRED_SETTINGS_KEYS, 'settings')
71
- assertOnlyKeys(attributes.early_flake_detection, EARLY_FLAKE_DETECTION_KEYS, 'settings early_flake_detection')
72
- assertOnlyKeys(attributes.test_management, TEST_MANAGEMENT_KEYS, 'settings test_management')
73
- assertBooleanFields(attributes, SETTINGS_BOOLEAN_KEYS, 'settings')
74
- assertBooleanFields(attributes.early_flake_detection, ['enabled'], 'settings early_flake_detection')
75
- assertBooleanFields(attributes.test_management, ['enabled'], 'settings test_management')
76
- assertOptionalBoundedNumber(
77
- attributes.early_flake_detection.faulty_session_threshold,
78
- 'settings early_flake_detection faulty_session_threshold'
79
- )
80
- assertRetryMap(attributes.early_flake_detection.slow_test_retries)
81
- assertOptionalBoundedNumber(
82
- attributes.test_management.attempt_to_fix_retries,
83
- 'settings test_management attempt_to_fix_retries'
84
- )
85
50
  }
86
51
 
87
- function validateKnownTestsResponse (response, options = {}) {
52
+ function validateKnownTestsResponse (response) {
88
53
  const attributes = getAttributes(response, 'known tests')
89
54
  assertHasKeys(attributes, ['tests'], 'known tests')
90
55
 
@@ -92,46 +57,26 @@ function validateKnownTestsResponse (response, options = {}) {
92
57
  if (tests === null) return
93
58
  assertObject(tests, 'Invalid known tests response: tests must be an object or null')
94
59
 
95
- let suiteCount = 0
96
- let testCount = 0
97
- const modules = Object.entries(tests)
98
- if (options.validationMode && modules.length > MAX_VALIDATION_MODULES) {
99
- throw new Error('Invalid known tests response: too many modules')
100
- }
101
- for (const [moduleName, suites] of modules) {
102
- if (options.validationMode) assertValidationString(moduleName, 'known tests module')
60
+ for (const suites of Object.values(tests)) {
103
61
  assertObject(suites, 'Invalid known tests response: module suites must be objects')
104
- for (const [suiteName, testNames] of Object.entries(suites)) {
105
- suiteCount++
106
- if (options.validationMode) {
107
- if (suiteCount > MAX_VALIDATION_SUITES) throw new Error('Invalid known tests response: too many suites')
108
- assertValidationString(suiteName, 'known tests suite')
109
- }
62
+ for (const testNames of Object.values(suites)) {
110
63
  if (!Array.isArray(testNames)) {
111
64
  throw new TypeError('Invalid known tests response: suite tests must be arrays')
112
65
  }
113
66
  for (const testName of testNames) {
114
- testCount++
115
67
  if (typeof testName !== 'string') {
116
68
  throw new TypeError('Invalid known tests response: test names must be strings')
117
69
  }
118
- if (options.validationMode) {
119
- if (testCount > MAX_VALIDATION_TESTS) throw new Error('Invalid known tests response: too many tests')
120
- assertValidationString(testName, 'known test name')
121
- }
122
70
  }
123
71
  }
124
72
  }
125
73
  }
126
74
 
127
- function validateSkippableTestsResponse (response, options = {}) {
75
+ function validateSkippableTestsResponse (response) {
128
76
  assertObject(response, 'Invalid skippable tests response: response must be an object')
129
77
  if (!Array.isArray(response.data)) {
130
78
  throw new TypeError('Invalid skippable tests response: data must be an array')
131
79
  }
132
- if (options.validationMode && response.data.length > MAX_VALIDATION_TESTS) {
133
- throw new Error('Invalid skippable tests response: too many items')
134
- }
135
80
  if (response.meta !== undefined) {
136
81
  assertObject(response.meta, 'Invalid skippable tests response: meta must be an object')
137
82
  }
@@ -147,56 +92,28 @@ function validateSkippableTestsResponse (response, options = {}) {
147
92
  if (typeof item.type !== 'string') {
148
93
  throw new TypeError('Invalid skippable tests response: data entry type must be a string')
149
94
  }
150
- if (options.validationMode) assertValidationString(item.type, 'skippable test type')
151
95
  assertObject(item.attributes, 'Invalid skippable tests response: data entry attributes must be an object')
152
96
  if ((item.type === 'suite' || item.type === 'test') && typeof item.attributes.suite !== 'string') {
153
97
  throw new Error('Invalid skippable tests response: data entry suite must be a string')
154
98
  }
155
- if (options.validationMode && item.attributes.suite !== undefined) {
156
- assertValidationString(item.attributes.suite, 'skippable test suite')
157
- }
158
99
  if (item.type === 'test' && typeof item.attributes.name !== 'string') {
159
100
  throw new Error('Invalid skippable tests response: data entry name must be a string')
160
101
  }
161
- if (options.validationMode && item.attributes.name !== undefined) {
162
- assertValidationString(item.attributes.name, 'skippable test name')
163
- }
164
102
  }
165
103
  }
166
104
 
167
- function validateTestManagementTestsResponse (response, options = {}) {
105
+ function validateTestManagementTestsResponse (response) {
168
106
  const attributes = getAttributes(response, 'test management tests')
169
107
  assertHasKeys(attributes, ['modules'], 'test management tests')
170
108
  assertObject(attributes.modules, 'Invalid test management tests response: modules must be an object')
171
109
 
172
- let suiteCount = 0
173
- let testCount = 0
174
- const modules = Object.entries(attributes.modules)
175
- if (options.validationMode && modules.length > MAX_VALIDATION_MODULES) {
176
- throw new Error('Invalid test management tests response: too many modules')
177
- }
178
- for (const [moduleName, testModule] of modules) {
179
- if (options.validationMode) assertValidationString(moduleName, 'test management module')
110
+ for (const testModule of Object.values(attributes.modules)) {
180
111
  assertObject(testModule, 'Invalid test management tests response: modules entries must be objects')
181
112
  assertObject(testModule.suites, 'Invalid test management tests response: module suites must be objects')
182
- for (const [suiteName, suite] of Object.entries(testModule.suites)) {
183
- suiteCount++
184
- if (options.validationMode) {
185
- if (suiteCount > MAX_VALIDATION_SUITES) {
186
- throw new Error('Invalid test management tests response: too many suites')
187
- }
188
- assertValidationString(suiteName, 'test management suite')
189
- }
113
+ for (const suite of Object.values(testModule.suites)) {
190
114
  assertObject(suite, 'Invalid test management tests response: suites entries must be objects')
191
115
  assertObject(suite.tests, 'Invalid test management tests response: suite tests must be objects')
192
- for (const [testName, test] of Object.entries(suite.tests)) {
193
- testCount++
194
- if (options.validationMode) {
195
- if (testCount > MAX_VALIDATION_TESTS) {
196
- throw new Error('Invalid test management tests response: too many tests')
197
- }
198
- assertValidationString(testName, 'test management test')
199
- }
116
+ for (const test of Object.values(suite.tests)) {
200
117
  assertObject(test, 'Invalid test management tests response: tests entries must be objects')
201
118
  assertObject(test.properties, 'Invalid test management tests response: test properties must be objects')
202
119
  }
@@ -204,48 +121,6 @@ function validateTestManagementTestsResponse (response, options = {}) {
204
121
  }
205
122
  }
206
123
 
207
- function assertBooleanFields (object, keys, endpoint) {
208
- for (const key of keys) {
209
- if (typeof object[key] !== 'boolean') {
210
- throw new TypeError(`Invalid ${endpoint} response: ${key} must be a boolean`)
211
- }
212
- }
213
- }
214
-
215
- function assertOptionalBoundedNumber (value, endpoint) {
216
- if (value === undefined) return
217
- if (!Number.isFinite(value) || !Number.isInteger(value) || value < 0 || value > MAX_RETRIES) {
218
- throw new TypeError(`Invalid ${endpoint}: value must be between 0 and ${MAX_RETRIES}`)
219
- }
220
- }
221
-
222
- function assertRetryMap (retries) {
223
- if (retries === undefined) return
224
- assertObject(retries, 'Invalid settings response: early_flake_detection slow_test_retries must be an object')
225
- for (const [threshold, count] of Object.entries(retries)) {
226
- assertValidationString(threshold, 'early flake detection retry threshold')
227
- if (!RETRY_THRESHOLD_PATTERN.test(threshold)) {
228
- throw new TypeError('Invalid early flake detection retry threshold: expected a duration such as 5s')
229
- }
230
- assertOptionalBoundedNumber(count, `early flake detection retry count ${threshold}`)
231
- }
232
- }
233
-
234
- function assertOnlyKeys (object, keys, endpoint) {
235
- const allowed = new Set(keys)
236
- for (const key of Object.keys(object)) {
237
- if (!allowed.has(key)) {
238
- throw new Error(`Invalid ${endpoint} response: unexpected ${key}`)
239
- }
240
- }
241
- }
242
-
243
- function assertValidationString (value, field) {
244
- if (typeof value !== 'string' || Buffer.byteLength(value) > MAX_VALIDATION_STRING_BYTES) {
245
- throw new TypeError(`Invalid ${field}: value must be a bounded string`)
246
- }
247
- }
248
-
249
124
  module.exports = {
250
125
  MAX_RETRIES,
251
126
  validateKnownTestsResponse,
@@ -45,11 +45,6 @@ const KNOWN_TESTS_FILE_NAME = 'known_tests.json'
45
45
  const SKIPPABLE_TESTS_FILE_NAME = 'skippable_tests.json'
46
46
  const TEST_MANAGEMENT_FILE_NAME = 'test_management.json'
47
47
 
48
- const DEFAULT_VALIDATION_MAX_FILE_BYTES = 1024 * 1024
49
- const DEFAULT_VALIDATION_MAX_ENTRIES = 100_000
50
- const DEFAULT_VALIDATION_MAX_NESTING_DEPTH = 32
51
- const DEFAULT_VALIDATION_MAX_STRING_BYTES = 4096
52
-
53
48
  function parseManifestVersion (content) {
54
49
  // Supported just the number version or 'version=x'
55
50
  const version = content.replace(/^\uFEFF/, '').trim()
@@ -58,22 +53,12 @@ function parseManifestVersion (content) {
58
53
  }
59
54
 
60
55
  class TestOptimizationHttpCache {
61
- constructor ({
62
- cwd = process.cwd(),
63
- env,
64
- validationManifestPath,
65
- maxFileBytes = DEFAULT_VALIDATION_MAX_FILE_BYTES,
66
- } = {}) {
56
+ constructor ({ cwd = process.cwd(), env } = {}) {
67
57
  this._cwd = cwd
68
58
  // This cache intentionally consumes env vars that are not tracer config keys. (??)
69
59
  // eslint-disable-next-line eslint-rules/eslint-process-env
70
60
  this._env = env ?? process.env
71
- this._validationManifestPath = validationManifestPath
72
- this._maxFileBytes = maxFileBytes
73
- this._lastError = undefined
74
- this._manifestPath = validationManifestPath
75
- ? this._resolveValidationManifestPath(validationManifestPath)
76
- : this._resolveManifestPath()
61
+ this._manifestPath = this._resolveManifestPath()
77
62
  this._testOptimizationPath = undefined
78
63
  this._httpCachePath = undefined
79
64
  this._available = false
@@ -85,10 +70,6 @@ class TestOptimizationHttpCache {
85
70
  return this._available
86
71
  }
87
72
 
88
- getLastError () {
89
- return this._lastError
90
- }
91
-
92
73
  readSettings () {
93
74
  const payload = this._readFile(SETTINGS_FILE_NAME)
94
75
  if (payload === CACHE_MISS) {
@@ -98,9 +79,9 @@ class TestOptimizationHttpCache {
98
79
 
99
80
  try {
100
81
  const settings = parseLibraryConfigurationResponse(
101
- this._parsePayload(payload, SETTINGS_FILE_NAME),
82
+ payload,
102
83
  undefined,
103
- { validateRequiredFields: true, validationMode: Boolean(this._validationManifestPath) }
84
+ { validateRequiredFields: true }
104
85
  )
105
86
  incrementCountMetric(TELEMETRY_GIT_REQUESTS_SETTINGS_RESPONSE, settings)
106
87
  return settings
@@ -117,8 +98,8 @@ class TestOptimizationHttpCache {
117
98
 
118
99
  try {
119
100
  const knownTests = parseKnownTestsResponse(
120
- this._parsePayload(payload, KNOWN_TESTS_FILE_NAME),
121
- { validateRequiredFields: true, validationMode: Boolean(this._validationManifestPath) }
101
+ payload,
102
+ { validateRequiredFields: true }
122
103
  )
123
104
  distributionMetric(TELEMETRY_KNOWN_TESTS_RESPONSE_TESTS, {}, getNumFromKnownTests(knownTests))
124
105
  distributionMetric(TELEMETRY_KNOWN_TESTS_RESPONSE_BYTES, {}, payload.length)
@@ -134,12 +115,10 @@ class TestOptimizationHttpCache {
134
115
  if (payload === CACHE_MISS) return CACHE_MISS
135
116
 
136
117
  try {
137
- const boundedPayload = this._parsePayload(payload, SKIPPABLE_TESTS_FILE_NAME)
138
- const parsedResponse = typeof boundedPayload === 'string' ? JSON.parse(boundedPayload) : boundedPayload
118
+ const parsedResponse = JSON.parse(payload)
139
119
  const result = parseSkippableSuitesResponse(parsedResponse, {
140
120
  ...options,
141
121
  validateRequiredFields: true,
142
- validationMode: Boolean(this._validationManifestPath),
143
122
  })
144
123
  const testLevel = options.testLevel || 'suite'
145
124
  logSkippableSuitesResponse(
@@ -169,8 +148,8 @@ class TestOptimizationHttpCache {
169
148
 
170
149
  try {
171
150
  parseSkippableSuitesResponse(
172
- this._parsePayload(payload, SKIPPABLE_TESTS_FILE_NAME),
173
- { ...options, validateRequiredFields: true, validationMode: Boolean(this._validationManifestPath) }
151
+ payload,
152
+ { ...options, validateRequiredFields: true }
174
153
  )
175
154
  return true
176
155
  } catch {
@@ -184,8 +163,8 @@ class TestOptimizationHttpCache {
184
163
 
185
164
  try {
186
165
  const testManagementTests = parseTestManagementTestsResponse(
187
- this._parsePayload(payload, TEST_MANAGEMENT_FILE_NAME),
188
- { validateRequiredFields: true, validationMode: Boolean(this._validationManifestPath) }
166
+ payload,
167
+ { validateRequiredFields: true }
189
168
  )
190
169
  distributionMetric(
191
170
  TELEMETRY_TEST_MANAGEMENT_TESTS_RESPONSE_TESTS,
@@ -202,18 +181,12 @@ class TestOptimizationHttpCache {
202
181
 
203
182
  _buildReader () {
204
183
  if (!this._manifestPath) {
205
- if (this._validationManifestPath && !this._lastError) {
206
- this._setError('Offline Test Optimization validation manifest was not found.')
207
- }
208
184
  log.debug('Test Optimization HTTP cache manifest not found')
209
185
  return
210
186
  }
211
187
 
212
188
  const version = this._readManifestVersion(this._manifestPath)
213
189
  if (version !== SUPPORTED_MANIFEST_VERSION) {
214
- if (this._validationManifestPath) {
215
- this._setError(`Unsupported offline Test Optimization validation manifest version: ${version || 'missing'}.`)
216
- }
217
190
  log.debug('Unsupported Test Optimization HTTP cache manifest version %j at %s', version, this._manifestPath)
218
191
  return
219
192
  }
@@ -227,9 +200,6 @@ class TestOptimizationHttpCache {
227
200
 
228
201
  const settingsPath = path.join(this._httpCachePath, SETTINGS_FILE_NAME)
229
202
  if (!fs.existsSync(settingsPath)) {
230
- if (this._validationManifestPath) {
231
- this._setError('Offline Test Optimization validation settings fixture is missing.')
232
- }
233
203
  log.debug('Test Optimization HTTP cache settings file not found at %s', settingsPath)
234
204
  return
235
205
  }
@@ -253,36 +223,10 @@ class TestOptimizationHttpCache {
253
223
  }
254
224
  }
255
225
 
256
- _resolveValidationManifestPath (manifestPath) {
257
- if (!path.isAbsolute(manifestPath)) {
258
- this._setError('Offline Test Optimization validation manifest path must be absolute.')
259
- return
260
- }
261
-
262
- const resolvedManifestPath = path.resolve(manifestPath)
263
- const testOptimizationPath = path.dirname(resolvedManifestPath)
264
- const fixtureRoot = path.dirname(testOptimizationPath)
265
- if (path.basename(resolvedManifestPath) !== MANIFEST_FILE_NAME ||
266
- path.basename(testOptimizationPath) !== PLAN_FOLDER) {
267
- this._setError('Offline Test Optimization validation manifest must use the fixed .testoptimization layout.')
268
- return
269
- }
270
-
271
- try {
272
- assertPathComponentsAreNotSymlinks(fixtureRoot, resolvedManifestPath)
273
- assertRegularFixtureFile(resolvedManifestPath)
274
- return resolvedManifestPath
275
- } catch (err) {
276
- this._setError(err.message)
277
- }
278
- }
279
-
280
226
  _readManifestVersion (manifestPath) {
281
227
  try {
282
- this._assertValidationFixtureFile(manifestPath)
283
228
  return parseManifestVersion(fs.readFileSync(manifestPath, 'utf8'))
284
229
  } catch (err) {
285
- if (this._validationManifestPath) this._setError(err.message)
286
230
  log.debug('Failed to read Test Optimization HTTP cache manifest %s: %s', manifestPath, err.message)
287
231
  }
288
232
  }
@@ -292,113 +236,24 @@ class TestOptimizationHttpCache {
292
236
 
293
237
  const filePath = path.join(this._httpCachePath, fileName)
294
238
  try {
295
- this._assertValidationFixtureFile(filePath)
296
239
  log.debug('Reading Test Optimization HTTP cache file %s', filePath)
297
240
  return fs.readFileSync(filePath, 'utf8')
298
241
  } catch (err) {
299
- if (this._validationManifestPath) this._setError(err.message)
300
242
  log.debug('Test Optimization HTTP cache file %s could not be read: %s', filePath, err.message)
301
243
  return CACHE_MISS
302
244
  }
303
245
  }
304
246
 
305
247
  _logInvalidCacheFile (fileName, err) {
306
- if (this._validationManifestPath) {
307
- this._setError(`Invalid offline Test Optimization ${fileName} fixture: ${err.message}`)
308
- }
309
248
  log.debug('Test Optimization HTTP cache file %s could not be parsed: %s', fileName, err.message)
310
249
  }
311
250
 
312
- _assertValidationFixtureFile (filePath) {
313
- if (!this._validationManifestPath) return
314
- const fixtureRoot = path.dirname(path.dirname(this._manifestPath))
315
- assertPathComponentsAreNotSymlinks(fixtureRoot, filePath)
316
- const stat = assertRegularFixtureFile(filePath)
317
- if (stat.size > this._maxFileBytes) {
318
- throw new Error(
319
- `Offline Test Optimization fixture ${path.basename(filePath)} exceeds ${this._maxFileBytes} bytes.`
320
- )
321
- }
322
- }
323
-
324
- _parsePayload (payload, fileName) {
325
- if (!this._validationManifestPath) return payload
326
-
327
- const parsed = JSON.parse(payload)
328
- assertBoundedValidationValue(parsed, fileName)
329
- return parsed
330
- }
331
-
332
- _setError (message) {
333
- this._lastError = new Error(message)
334
- }
335
-
336
251
  _disable () {
337
252
  this._available = false
338
253
  }
339
254
  }
340
255
 
341
- function assertPathComponentsAreNotSymlinks (root, filename) {
342
- const resolvedRoot = path.resolve(root)
343
- const resolvedFilename = path.resolve(filename)
344
- const rootStat = fs.lstatSync(resolvedRoot)
345
- if (!rootStat.isDirectory() || rootStat.isSymbolicLink()) {
346
- throw new Error(`Offline Test Optimization fixture root must be a regular directory: ${resolvedRoot}`)
347
- }
348
- const relative = path.relative(resolvedRoot, resolvedFilename)
349
- if (relative.startsWith('..') || path.isAbsolute(relative)) {
350
- throw new Error('Offline Test Optimization fixture path escapes its validation root.')
351
- }
352
-
353
- let current = resolvedRoot
354
- for (const segment of relative ? relative.split(path.sep) : []) {
355
- current = path.join(current, segment)
356
- const stat = fs.lstatSync(current)
357
- if (stat.isSymbolicLink()) {
358
- throw new Error(`Offline Test Optimization fixture path contains a symbolic link: ${current}`)
359
- }
360
- }
361
- }
362
-
363
- function assertRegularFixtureFile (filename) {
364
- const stat = fs.lstatSync(filename)
365
- if (!stat.isFile()) {
366
- throw new Error(`Offline Test Optimization fixture is not a regular file: ${filename}`)
367
- }
368
- if (stat.nlink > 1) {
369
- throw new Error(`Offline Test Optimization fixture must not be hard-linked: ${filename}`)
370
- }
371
- return stat
372
- }
373
-
374
- function assertBoundedValidationValue (value, fileName) {
375
- const pending = [{ depth: 0, value }]
376
- let entries = 0
377
-
378
- while (pending.length > 0) {
379
- const current = pending.pop()
380
- if (current.depth > DEFAULT_VALIDATION_MAX_NESTING_DEPTH) {
381
- throw new Error(`${fileName} exceeds the validation nesting limit.`)
382
- }
383
- if (typeof current.value === 'string' &&
384
- Buffer.byteLength(current.value) > DEFAULT_VALIDATION_MAX_STRING_BYTES) {
385
- throw new Error(`${fileName} contains a string that exceeds the validation limit.`)
386
- }
387
- if (!current.value || typeof current.value !== 'object') continue
388
-
389
- const values = Array.isArray(current.value) ? current.value : Object.values(current.value)
390
- entries += values.length
391
- if (entries > DEFAULT_VALIDATION_MAX_ENTRIES) {
392
- throw new Error(`${fileName} exceeds the validation collection-entry limit.`)
393
- }
394
- for (const nestedValue of values) {
395
- pending.push({ depth: current.depth + 1, value: nestedValue })
396
- }
397
- }
398
- }
399
-
400
256
  module.exports = {
401
257
  CACHE_MISS,
402
- DEFAULT_VALIDATION_MAX_FILE_BYTES,
403
258
  TestOptimizationHttpCache,
404
259
  }
@@ -9,6 +9,9 @@ export interface ConfigProperties extends GeneratedConfig {
9
9
  rules: PayloadTaggingRules
10
10
  }
11
11
  debug: boolean
12
+ featureFlags: GeneratedConfig['featureFlags'] & {
13
+ flagSelection: unknown
14
+ }
12
15
  instrumentationSource: 'manual' | 'ssi'
13
16
  isCiVisibility: boolean
14
17
  isServiceNameInferred: boolean
@@ -303,6 +303,11 @@ for (const [canonicalName, entries] of Object.entries(supportedConfigurations))
303
303
  }
304
304
  }
305
305
 
306
+ // Programmatic only. The Feature Flagging provider validates the raw value, and it is redacted because
307
+ // a wrong-shaped selection would otherwise be printed or sent as is in configuration telemetry.
308
+ addOption({ property: 'featureFlags.flagSelection', type: 'PASSTHROUGH' }, ['featureFlags.flagSelection'])
309
+ sensitiveConfigurations.add('featureFlags.flagSelection')
310
+
306
311
  // Replace the alias with the canonical property name.
307
312
  for (const [fullPropertyName, alias] of fallbackConfigurations) {
308
313
  if (configurationsTable[alias]?.property) {