dd-trace 5.134.0 → 5.135.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 (168) hide show
  1. package/LICENSE-3rdparty.csv +0 -1
  2. package/ci/cypress/support.js +15 -1
  3. package/ci/diagnose.js +4 -4
  4. package/ci/test-annotations.d.ts +5 -0
  5. package/ci/test-annotations.js +5 -0
  6. package/ci/test-optimization-validation/approval-artifacts.js +2 -2
  7. package/ci/test-optimization-validation/approval.js +2 -2
  8. package/ci/test-optimization-validation/artifact-id.js +2 -3
  9. package/ci/test-optimization-validation/ci-package-scripts.js +1 -1
  10. package/ci/test-optimization-validation/cli.js +1 -1
  11. package/ci/test-optimization-validation/command-runner.js +2 -3
  12. package/ci/test-optimization-validation/executable.js +1 -1
  13. package/ci/test-optimization-validation/framework-adapters/cucumber.js +1 -1
  14. package/ci/test-optimization-validation/literal-environment.js +2 -2
  15. package/ci/test-optimization-validation/manifest-scaffold.js +1 -1
  16. package/ci/test-optimization-validation/offline-fixtures.js +1 -1
  17. package/ci/test-optimization-validation/redaction.js +3 -3
  18. package/ci/test-optimization-validation/runner-contract.js +10 -10
  19. package/ci/test-optimization-validation/scenarios/ci-wiring.js +1 -1
  20. package/ci/vitest-no-worker-init-annotations.mjs +4 -0
  21. package/ci/vitest-no-worker-init-node-setup.mjs +22 -0
  22. package/ci/vitest-no-worker-init-runner-setup.mjs +7 -32
  23. package/ci/vitest-no-worker-init-setup.mjs +34 -12
  24. package/ci/vitest-no-worker-init-v5-setup.mjs +6 -0
  25. package/ext/exporters.js +1 -0
  26. package/index.d.ts +19 -0
  27. package/loader-hook.mjs +53 -0
  28. package/openfeature/exposure-hook.d.ts +66 -0
  29. package/openfeature/exposure-hook.js +5 -0
  30. package/package.json +11 -9
  31. package/packages/datadog-core/src/storage.js +1 -1
  32. package/packages/datadog-esbuild/index.js +70 -7
  33. package/packages/datadog-instrumentations/src/cucumber.js +53 -19
  34. package/packages/datadog-instrumentations/src/cypress-config.js +163 -15
  35. package/packages/datadog-instrumentations/src/graphql.js +9 -3
  36. package/packages/datadog-instrumentations/src/grpc/server.js +23 -6
  37. package/packages/datadog-instrumentations/src/helpers/fetch.js +5 -1
  38. package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +30 -8
  39. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -1
  40. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +16 -6
  41. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +8 -0
  42. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +3 -1
  43. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/react-router.js +49 -0
  44. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/typesafe.js +23 -0
  45. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +12 -0
  46. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +8 -0
  47. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +19 -2
  48. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +8 -0
  49. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +1 -1
  50. package/packages/datadog-instrumentations/src/jest.js +265 -82
  51. package/packages/datadog-instrumentations/src/mariadb-bundle.js +69 -11
  52. package/packages/datadog-instrumentations/src/mariadb.js +13 -6
  53. package/packages/datadog-instrumentations/src/mocha/common.js +89 -8
  54. package/packages/datadog-instrumentations/src/mocha/main.js +11 -2
  55. package/packages/datadog-instrumentations/src/mocha/utils.js +58 -12
  56. package/packages/datadog-instrumentations/src/mocha/worker.js +1 -1
  57. package/packages/datadog-instrumentations/src/oracledb.js +33 -0
  58. package/packages/datadog-instrumentations/src/pg.js +2 -1
  59. package/packages/datadog-instrumentations/src/playwright.js +81 -28
  60. package/packages/datadog-instrumentations/src/react-router.js +106 -0
  61. package/packages/datadog-instrumentations/src/typesafe.js +89 -0
  62. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +84 -48
  63. package/packages/datadog-instrumentations/src/vitest-main.js +26 -0
  64. package/packages/datadog-instrumentations/src/vitest-test-annotations.js +20 -0
  65. package/packages/datadog-instrumentations/src/vitest-worker.js +39 -17
  66. package/packages/datadog-instrumentations/src/vitest.js +10 -8
  67. package/packages/datadog-plugin-cucumber/src/index.js +5 -0
  68. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +274 -44
  69. package/packages/datadog-plugin-cypress/src/index.js +1 -1
  70. package/packages/datadog-plugin-cypress/src/lifecycle-owner.js +20 -0
  71. package/packages/datadog-plugin-cypress/src/plugin.js +10 -0
  72. package/packages/datadog-plugin-cypress/src/retry-config-observer.js +281 -0
  73. package/packages/datadog-plugin-cypress/src/setup-handoff.js +125 -0
  74. package/packages/datadog-plugin-cypress/src/support.js +1217 -439
  75. package/packages/datadog-plugin-graphql/src/execute.js +2 -2
  76. package/packages/datadog-plugin-graphql/src/utils.js +5 -5
  77. package/packages/datadog-plugin-jest/src/index.js +25 -3
  78. package/packages/datadog-plugin-mocha/src/index.js +47 -6
  79. package/packages/datadog-plugin-oracledb/src/connection-parser.js +21 -11
  80. package/packages/datadog-plugin-playwright/src/index.js +4 -0
  81. package/packages/datadog-plugin-react-router/src/index.js +118 -0
  82. package/packages/datadog-plugin-typesafe/src/index.js +17 -0
  83. package/packages/datadog-plugin-typesafe/src/tracing.js +31 -0
  84. package/packages/datadog-plugin-vitest/src/index.js +8 -0
  85. package/packages/dd-trace/src/agent/info.js +2 -1
  86. package/packages/dd-trace/src/aiguard/sdk.js +0 -11
  87. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +9 -16
  88. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +4 -2
  89. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +9 -16
  90. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +9 -14
  91. package/packages/dd-trace/src/ci-visibility/requests/route.js +44 -0
  92. package/packages/dd-trace/src/ci-visibility/telemetry-logs.js +5 -0
  93. package/packages/dd-trace/src/ci-visibility/test-annotations.js +72 -0
  94. package/packages/dd-trace/src/ci-visibility/test-declaration-annotations.js +170 -0
  95. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +9 -16
  96. package/packages/dd-trace/src/config/defaults.js +4 -3
  97. package/packages/dd-trace/src/config/generated-config-types.d.ts +4 -0
  98. package/packages/dd-trace/src/config/index.js +95 -39
  99. package/packages/dd-trace/src/config/parsers.js +9 -1
  100. package/packages/dd-trace/src/config/supported-configurations.json +16 -0
  101. package/packages/dd-trace/src/debugger/probe_sampler.js +6 -6
  102. package/packages/dd-trace/src/encode/0.4.js +2 -2
  103. package/packages/dd-trace/src/esm-module-load.js +58 -0
  104. package/packages/dd-trace/src/exporter.js +25 -6
  105. package/packages/dd-trace/src/exporters/agent/index.js +3 -1
  106. package/packages/dd-trace/src/exporters/agentless/index.js +3 -1
  107. package/packages/dd-trace/src/exporters/common/request.js +4 -4
  108. package/packages/dd-trace/src/exporters/llmobs/index.js +135 -0
  109. package/packages/dd-trace/src/exporters/log/index.js +4 -3
  110. package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
  111. package/packages/dd-trace/src/llmobs/experiments/index.js +2 -3
  112. package/packages/dd-trace/src/llmobs/experiments/noop.js +5 -2
  113. package/packages/dd-trace/src/llmobs/index.js +13 -2
  114. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +1 -1
  115. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
  116. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +8 -4
  117. package/packages/dd-trace/src/llmobs/plugins/typesafe/index.js +102 -0
  118. package/packages/dd-trace/src/llmobs/prompts/cache.js +3 -1
  119. package/packages/dd-trace/src/llmobs/sdk.js +2 -1
  120. package/packages/dd-trace/src/llmobs/span_processor.js +210 -12
  121. package/packages/dd-trace/src/llmobs/tagger.js +3 -0
  122. package/packages/dd-trace/src/llmobs/writers/util.js +3 -3
  123. package/packages/dd-trace/src/log/writer.js +7 -1
  124. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +64 -6
  125. package/packages/dd-trace/src/openfeature/configuration_source.js +18 -2
  126. package/packages/dd-trace/src/openfeature/debug-logging-hook.js +66 -3
  127. package/packages/dd-trace/src/openfeature/exposure-hook.js +185 -0
  128. package/packages/dd-trace/src/openfeature/flagging_provider.js +39 -13
  129. package/packages/dd-trace/src/openfeature/remote_config.js +16 -3
  130. package/packages/dd-trace/src/openfeature/writers/base.js +62 -27
  131. package/packages/dd-trace/src/openfeature/writers/exposures.js +161 -1
  132. package/packages/dd-trace/src/openfeature/writers/flag-eval-evp-hook.js +5 -0
  133. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-aggregation.js +9 -4
  134. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-payload.js +2 -0
  135. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-pii.js +2 -0
  136. package/packages/dd-trace/src/openfeature/writers/split-features.js +25 -0
  137. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -2
  138. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +5 -1
  139. package/packages/dd-trace/src/opentracing/tracer.js +9 -13
  140. package/packages/dd-trace/src/otel-thread-ctx.js +47 -21
  141. package/packages/dd-trace/src/plugins/ci_plugin.js +4 -4
  142. package/packages/dd-trace/src/plugins/index.js +3 -0
  143. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  144. package/packages/dd-trace/src/plugins/util/git.js +11 -5
  145. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +2 -4
  146. package/packages/dd-trace/src/plugins/util/test.js +26 -6
  147. package/packages/dd-trace/src/plugins/util/web.js +16 -0
  148. package/packages/dd-trace/src/process-tags/index.js +1 -1
  149. package/packages/dd-trace/src/profiling/config.js +6 -3
  150. package/packages/dd-trace/src/proxy.js +15 -4
  151. package/packages/dd-trace/src/serverless.js +3 -2
  152. package/packages/dd-trace/src/span_processor.js +21 -9
  153. package/packages/dd-trace/src/span_stats.js +28 -2
  154. package/packages/dd-trace/src/startup-log.js +2 -1
  155. package/packages/dd-trace/src/tagger.js +7 -5
  156. package/packages/dd-trace/src/telemetry/dependencies.js +4 -0
  157. package/packages/dd-trace/src/telemetry/index.js +3 -0
  158. package/packages/dd-trace/src/telemetry/logs/index.js +21 -2
  159. package/packages/dd-trace/src/telemetry/logs/log-collector.js +1 -0
  160. package/packages/dd-trace/src/telemetry/telemetry.js +10 -3
  161. package/packages/dd-trace/src/util.js +1 -1
  162. package/register.js +2 -1
  163. package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
  164. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.d.ts +78 -0
  165. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.js +1 -1
  166. package/vendor/dist/@opentelemetry/core/index.js +1 -1
  167. package/vendor/dist/@opentelemetry/resources/LICENSE +0 -201
  168. package/vendor/dist/@opentelemetry/resources/index.js +0 -1
@@ -7,7 +7,7 @@ const satisfies = require('../../../vendor/dist/semifies')
7
7
  const { getDynamicAtrRetryCount } = require('../../dd-trace/src/ci-visibility/dynamic-atr-retries')
8
8
  const { EMPTY_EFD_RETRY_POLICY, hasEfdRetries } = require('../../dd-trace/src/ci-visibility/efd-retry-policy')
9
9
  const { RUM_TEST_EXECUTION_ID_COOKIE_NAME } = require('../../dd-trace/src/ci-visibility/rum')
10
- const { getValueFromEnvSources } = require('../../dd-trace/src/config/helper')
10
+ const { getEnvironmentVariable, getValueFromEnvSources } = require('../../dd-trace/src/config/helper')
11
11
  const log = require('../../dd-trace/src/log')
12
12
  const {
13
13
  DYNAMIC_NAME_RE,
@@ -57,6 +57,14 @@ const VITEST_NO_WORKER_INIT_SETUP_FILE = path.join(
57
57
  'ci',
58
58
  'vitest-no-worker-init-setup.mjs'
59
59
  )
60
+ const VITEST_NO_WORKER_INIT_NODE_SETUP_FILE = path.join(
61
+ __dirname,
62
+ '..',
63
+ '..',
64
+ '..',
65
+ 'ci',
66
+ 'vitest-no-worker-init-node-setup.mjs'
67
+ )
60
68
  const VITEST_NO_WORKER_INIT_RUNNER_SETUP_FILE = path.join(
61
69
  __dirname,
62
70
  '..',
@@ -73,6 +81,11 @@ const VITEST_NO_WORKER_INIT_V5_SETUP_FILE = path.join(
73
81
  'ci',
74
82
  'vitest-no-worker-init-v5-setup.mjs'
75
83
  )
84
+ const VITEST_NO_WORKER_INIT_ENTRYPOINTS = new Set([
85
+ VITEST_NO_WORKER_INIT_NODE_SETUP_FILE,
86
+ VITEST_NO_WORKER_INIT_RUNNER_SETUP_FILE,
87
+ VITEST_NO_WORKER_INIT_V5_SETUP_FILE,
88
+ ])
76
89
  const VITEST_BROWSER_SETUP_FILE_PLUGIN = {
77
90
  name: 'datadog:vitest-browser-setup-file',
78
91
  config: configureVitestBrowserSetupFile,
@@ -412,14 +425,12 @@ function configureWorkerEnv (workerEnv, shouldSkipWorkerInit = false) {
412
425
  }
413
426
 
414
427
  workerEnv[VITEST_NO_WORKER_INIT_ACTIVE_ENV] = '1'
415
- rememberDatadogTestOptimizationNodeOptions(workerEnv.NODE_OPTIONS)
428
+ // Pool env objects omit inherited variables; retain the parent's non-Datadog options.
429
+ const inheritedNodeOptions = workerEnv.NODE_OPTIONS ?? getEnvironmentVariable('NODE_OPTIONS')
430
+ rememberDatadogTestOptimizationNodeOptions(inheritedNodeOptions)
416
431
 
417
- const nodeOptions = removeDatadogTestOptimizationNodeOptions(workerEnv.NODE_OPTIONS)
418
- if (nodeOptions) {
419
- workerEnv.NODE_OPTIONS = nodeOptions
420
- } else {
421
- delete workerEnv.NODE_OPTIONS
422
- }
432
+ const nodeOptions = removeDatadogTestOptimizationNodeOptions(inheritedNodeOptions)
433
+ if (nodeOptions !== undefined) workerEnv.NODE_OPTIONS = nodeOptions
423
434
  return workerEnv
424
435
  }
425
436
 
@@ -438,12 +449,11 @@ function restoreDatadogTestOptimizationNodeOptions (workerEnv) {
438
449
  }
439
450
  }
440
451
 
441
- function addSetupFileToVitestConfigs (ctx, setupFile, testSpecifications) {
452
+ function addSetupFileToVitestConfigs (ctx, browserSetupFile, testSpecifications) {
442
453
  const configs = getNoWorkerInitVitestConfigs(ctx, testSpecifications)
443
454
 
444
- for (const config of configs) {
445
- if (!config) continue
446
-
455
+ for (const [config, isBrowserMode] of configs) {
456
+ const setupFile = isBrowserMode ? browserSetupFile : VITEST_NO_WORKER_INIT_NODE_SETUP_FILE
447
457
  config.includeTaskLocation = true
448
458
  if (config.setupFiles === undefined) {
449
459
  config.setupFiles = []
@@ -451,14 +461,28 @@ function addSetupFileToVitestConfigs (ctx, setupFile, testSpecifications) {
451
461
  config.setupFiles = [config.setupFiles]
452
462
  }
453
463
 
454
- const setupFileIndex = config.setupFiles.indexOf(setupFile)
455
- if (setupFileIndex !== 0) {
456
- if (setupFileIndex > 0) {
457
- config.setupFiles.splice(setupFileIndex, 1)
458
- }
459
- config.setupFiles.unshift(setupFile)
464
+ for (let index = config.setupFiles.length - 1; index >= 0; index--) {
465
+ if (VITEST_NO_WORKER_INIT_ENTRYPOINTS.has(config.setupFiles[index])) config.setupFiles.splice(index, 1)
460
466
  }
467
+ config.setupFiles.unshift(setupFile)
468
+ }
469
+ }
470
+
471
+ /**
472
+ * Makes the annotation helper available to browser setup before Vitest creates its Vite server.
473
+ *
474
+ * @param {{ plugins?: object[] }|undefined} viteOverrides
475
+ */
476
+ function addBrowserAnnotationPlugin (viteOverrides = {}) {
477
+ if (!viteOverrides.plugins || !Object.isExtensible(viteOverrides) ||
478
+ !Object.isExtensible(viteOverrides.plugins)) {
479
+ viteOverrides = { ...viteOverrides, plugins: [...(viteOverrides.plugins || [])] }
480
+ }
481
+ viteOverrides.plugins ||= []
482
+ if (!viteOverrides.plugins.includes(VITEST_BROWSER_SETUP_FILE_PLUGIN)) {
483
+ viteOverrides.plugins.push(VITEST_BROWSER_SETUP_FILE_PLUGIN)
461
484
  }
485
+ return viteOverrides
462
486
  }
463
487
 
464
488
  /**
@@ -501,6 +525,8 @@ function allowVitestBrowserSetupFile (viteConfig) {
501
525
  VITEST_NO_WORKER_INIT_SETUP_FILE,
502
526
  VITEST_NO_WORKER_INIT_RUNNER_SETUP_FILE,
503
527
  VITEST_NO_WORKER_INIT_V5_SETUP_FILE,
528
+ require.resolve('../../../ci/vitest-no-worker-init-annotations.mjs'),
529
+ require.resolve('../../dd-trace/src/ci-visibility/test-declaration-annotations'),
504
530
  ]
505
531
  for (const setupFile of setupFiles) {
506
532
  if (!allow.includes(setupFile)) {
@@ -562,31 +588,32 @@ function addVitestBrowserCommand (config) {
562
588
  }
563
589
 
564
590
  function getNoWorkerInitVitestConfigs (ctx, testSpecifications) {
565
- const configs = new Set()
591
+ const configs = new Map()
592
+ let fallbackIsBrowserMode
566
593
  if (Array.isArray(testSpecifications)) {
567
- let shouldAddRootConfig = false
568
594
  for (const testSpecification of testSpecifications) {
569
595
  const project = getTestSpecificationProject(testSpecification)
570
596
  const config = safeConfig(project)
597
+ const isBrowserMode = isBrowserTestSpecification(testSpecification)
571
598
  if (config) {
572
- addNoWorkerInitConfig(configs, config)
599
+ addNoWorkerInitConfig(configs, config, isBrowserMode)
573
600
  } else {
574
- shouldAddRootConfig = true
601
+ fallbackIsBrowserMode ||= isBrowserMode
575
602
  }
576
603
  }
577
604
 
578
- if (!shouldAddRootConfig && configs.size > 0) {
605
+ if (fallbackIsBrowserMode === undefined && configs.size > 0) {
579
606
  return configs
580
607
  }
581
608
  }
582
609
 
583
- addNoWorkerInitConfig(configs, safeConfig(ctx))
584
- addNoWorkerInitConfig(configs, safeConfig(safeWorkspaceProject(ctx)))
610
+ addNoWorkerInitConfig(configs, safeConfig(ctx), fallbackIsBrowserMode)
611
+ addNoWorkerInitConfig(configs, safeConfig(safeWorkspaceProject(ctx)), fallbackIsBrowserMode)
585
612
  return configs
586
613
  }
587
614
 
588
- function addNoWorkerInitConfig (configs, config) {
589
- if (config) configs.add(config)
615
+ function addNoWorkerInitConfig (configs, config, isBrowserMode = config?.browser?.enabled === true) {
616
+ if (config && !configs.has(config)) configs.set(config, isBrowserMode)
590
617
  }
591
618
 
592
619
  function getSelectedTestManagementTests (testManagementTestsBySuite, propertyName) {
@@ -919,7 +946,8 @@ function createMainProcessReporter (reporterState) {
919
946
  )
920
947
  const knownTests = testProperties?.knownTests
921
948
  const testManagementProperties = testProperties?.testManagementTests?.[testName] || {}
922
- const isAttemptToFix = testManagementProperties.isAttemptToFix
949
+ const annotations = task.meta?.__ddTestOptAnnotations || {}
950
+ const isAttemptToFix = testManagementProperties.isAttemptToFix && !annotations.noAutoRetry
923
951
  const isNew = !!(
924
952
  !isAttemptToFix &&
925
953
  state.isKnownTestsEnabled &&
@@ -929,20 +957,23 @@ function createMainProcessReporter (reporterState) {
929
957
  )
930
958
  const isModified = testProperties?.isModified === true
931
959
  const { flakyTestRetriesConfiguration } = testOptimizationData
932
- const isFlakyTestRetries = !!flakyTestRetriesConfiguration && isFlakyTestRetriesEnabledForTask({
933
- isFlakyTestRetriesEnabled: state.isFlakyTestRetriesEnabled,
934
- isDynamicAtrEnabled: state.isDynamicAtrEnabled,
935
- flakyTestRetriesIncludesUnnamedProject: flakyTestRetriesConfiguration.includesUnnamedProject,
936
- flakyTestRetriesProjectNames: flakyTestRetriesConfiguration.projectNames,
937
- flakyTestRetriesUseRetryMarker: flakyTestRetriesConfiguration.usesRetryMarker,
938
- }, task)
960
+ const isFlakyTestRetries = !annotations.noAutoRetry && !!flakyTestRetriesConfiguration &&
961
+ isFlakyTestRetriesEnabledForTask({
962
+ isFlakyTestRetriesEnabled: state.isFlakyTestRetriesEnabled,
963
+ isDynamicAtrEnabled: state.isDynamicAtrEnabled,
964
+ flakyTestRetriesIncludesUnnamedProject: flakyTestRetriesConfiguration.includesUnnamedProject,
965
+ flakyTestRetriesProjectNames: flakyTestRetriesConfiguration.projectNames,
966
+ flakyTestRetriesUseRetryMarker: flakyTestRetriesConfiguration.usesRetryMarker,
967
+ }, task)
939
968
 
940
969
  return {
941
970
  isAttemptToFix,
942
- isDisabled: testManagementProperties.isDisabled,
971
+ annotations,
972
+ assignedProperties: testManagementProperties,
973
+ isDisabled: testManagementProperties.isDisabled && !annotations.mustFail,
943
974
  isEarlyFlakeDetection: task.meta?.__ddTestOptEfdRetries !== undefined,
944
975
  isFlakyTestRetries,
945
- isQuarantined: testManagementProperties.isQuarantined,
976
+ isQuarantined: testManagementProperties.isQuarantined && !annotations.mustFail,
946
977
  isModified,
947
978
  isNew,
948
979
  testSuite,
@@ -1283,12 +1314,13 @@ function reportFinalTestAttempt (testReport) {
1283
1314
  } = getRumCorrelation(task, attemptIndex)
1284
1315
  testSkipCh.publish({
1285
1316
  ...browserEnvironment,
1317
+ annotations: testProperties.annotations,
1286
1318
  testName,
1287
1319
  testSuiteAbsolutePath,
1288
1320
  isNew: testProperties.isNew,
1289
- isAttemptToFix: testProperties.isAttemptToFix,
1290
- isDisabled: testProperties.isDisabled,
1291
- isQuarantined: testProperties.isQuarantined,
1321
+ isAttemptToFix: testProperties.assignedProperties.isAttemptToFix,
1322
+ isDisabled: testProperties.assignedProperties.isDisabled,
1323
+ isQuarantined: testProperties.assignedProperties.isQuarantined,
1292
1324
  isRumActive,
1293
1325
  isTestFrameworkWorker: true,
1294
1326
  requestErrorTags: state.requestErrorTags,
@@ -1369,9 +1401,10 @@ function reportTestAttempt (testReport, attempt) {
1369
1401
  isRetry: attempt.isRetry,
1370
1402
  isNew: testProperties.isNew,
1371
1403
  hasDynamicName: testProperties.hasDynamicName,
1372
- isAttemptToFix: testProperties.isAttemptToFix,
1373
- isDisabled: testProperties.isDisabled,
1374
- isQuarantined: testProperties.isQuarantined,
1404
+ annotations: testProperties.annotations,
1405
+ isAttemptToFix: testProperties.assignedProperties.isAttemptToFix,
1406
+ isDisabled: testProperties.assignedProperties.isDisabled,
1407
+ isQuarantined: testProperties.assignedProperties.isQuarantined,
1375
1408
  isModified: testProperties.isModified,
1376
1409
  isRetryReasonEfd: attempt.isRetryReasonEfd,
1377
1410
  isRetryReasonAttemptToFix: testProperties.isAttemptToFix && attempt.isRetry,
@@ -1607,9 +1640,9 @@ function splitNodeOptions (nodeOptions) {
1607
1640
  const char = nodeOptions[index]
1608
1641
 
1609
1642
  if (quote) {
1610
- if (char === '\\' && nodeOptions[index + 1] === quote) {
1611
- token += quote
1612
- index++
1643
+ // Node treats a backslash inside double quotes as escaping the next character.
1644
+ if (char === '\\' && index + 1 < nodeOptions.length) {
1645
+ token += nodeOptions[++index]
1613
1646
  continue
1614
1647
  }
1615
1648
 
@@ -1621,7 +1654,8 @@ function splitNodeOptions (nodeOptions) {
1621
1654
  continue
1622
1655
  }
1623
1656
 
1624
- if (char === '"' || char === "'") {
1657
+ // NODE_OPTIONS uses double quotes for grouping; apostrophes belong to option values.
1658
+ if (char === '"') {
1625
1659
  quote = char
1626
1660
  continue
1627
1661
  }
@@ -1649,7 +1683,8 @@ function serializeNodeOptions (tokens) {
1649
1683
  for (const token of tokens) {
1650
1684
  if (hasSerializedToken) serializedTokens += ' '
1651
1685
  if (NODE_OPTIONS_QUOTE_RE.test(token)) {
1652
- serializedTokens += JSON.stringify(token)
1686
+ // Escape only Node's grouping syntax; JSON would turn literal whitespace into escape letters.
1687
+ serializedTokens += `"${token.replaceAll('\\', '\\\\').replaceAll('"', String.raw`\"`)}"`
1653
1688
  } else {
1654
1689
  serializedTokens += token
1655
1690
  }
@@ -1868,6 +1903,7 @@ function safeWorkspaceProject (ctx) {
1868
1903
  }
1869
1904
 
1870
1905
  module.exports = {
1906
+ addBrowserAnnotationPlugin,
1871
1907
  configure,
1872
1908
  deactivate,
1873
1909
  configureWorkerEnv,
@@ -1055,6 +1055,15 @@ function configureFlakyTestRetries (ctx, testSpecifications, frameworkVersion) {
1055
1055
  const projectNames = []
1056
1056
  for (const { config, projectName } of getVitestProjectConfigs(ctx, testSpecifications)) {
1057
1057
  if (!config.retry || config.retry.__ddTestOptAtr) {
1058
+ // Tag retries are resolved during declaration, after the callback's own options were captured.
1059
+ if (config.tags) {
1060
+ config.tags = config.tags.map(tag => tag.retry === undefined
1061
+ ? tag
1062
+ : {
1063
+ ...tag,
1064
+ meta: { ...tag.meta, __ddTestOptHasFrameworkRetry: true },
1065
+ })
1066
+ }
1058
1067
  // The serializable marker survives task inheritance and setup refreshes, unlike numeric retry counts.
1059
1068
  config.retry = usesRetryMarker ? { count: retryCount, __ddTestOptAtr: true } : retryCount
1060
1069
  configured = true
@@ -1280,6 +1289,13 @@ function getFinishWrapper (exitOrClose) {
1280
1289
  function getCliOrStartVitestWrapper (frameworkVersion) {
1281
1290
  return function (oldCliOrStartVitest) {
1282
1291
  return function (...args) {
1292
+ const entrypoint = oldCliOrStartVitest.name
1293
+ if (testSessionStartCh.hasSubscribers && (entrypoint === 'createVitest' || entrypoint === 'startVitest')) {
1294
+ const isCreate = entrypoint === 'createVitest'
1295
+ const isLegacySignature = typeof args[0] === 'string'
1296
+ const overridesIndex = isCreate ? (isLegacySignature ? 2 : 1) : (isLegacySignature ? 3 : 2)
1297
+ args[overridesIndex] = noWorkerInit.addBrowserAnnotationPlugin(args[overridesIndex])
1298
+ }
1283
1299
  if (!testSessionStartCh.hasSubscribers || isSessionStarted) {
1284
1300
  return oldCliOrStartVitest.apply(this, args)
1285
1301
  }
@@ -2078,6 +2094,16 @@ function getStartVitestWrapper (cliApiPackage, frameworkVersion) {
2078
2094
  if (createVitestExport) {
2079
2095
  shimmer.wrap(cliApiPackage, createVitestExport.key, getCliOrStartVitestWrapper(frameworkVersion))
2080
2096
  }
2097
+ // Newer CLI chunks call the bundled namespace instead of the direct function exports.
2098
+ for (const [key, value] of Object.entries(cliApiPackage)) {
2099
+ if (value && typeof value === 'object' && typeof value.startVitest === 'function') {
2100
+ cliApiPackage[key] = {
2101
+ ...value,
2102
+ startVitest: cliApiPackage[startVitestExport.key],
2103
+ }
2104
+ if (createVitestExport) cliApiPackage[key].createVitest = cliApiPackage[createVitestExport.key]
2105
+ }
2106
+ }
2081
2107
  wrapMessagePortOn()
2082
2108
 
2083
2109
  wrapVitestInternals(cliApiPackage, frameworkVersion)
@@ -0,0 +1,20 @@
1
+ 'use strict'
2
+
3
+ const { wrapDeclaration } = require('../../dd-trace/src/ci-visibility/test-declaration-annotations')
4
+ const { addHook } = require('./helpers/instrument')
5
+ const { findExportByName, testSessionStartCh } = require('./vitest-util')
6
+
7
+ /** @param {Record<string, unknown>} pkg */
8
+ function captureDeclarations (pkg) {
9
+ if (!testSessionStartCh.hasSubscribers) return pkg
10
+ const getCurrentSuite = findExportByName(pkg, 'getCurrentSuite')?.value
11
+ if (!getCurrentSuite) return pkg
12
+ for (const [name, value] of Object.entries(pkg)) {
13
+ if (typeof value !== 'function' || !('each' in value)) continue
14
+ pkg[name] = wrapDeclaration(value, getCurrentSuite)
15
+ }
16
+ return pkg
17
+ }
18
+
19
+ addHook({ name: '@vitest/runner', versions: ['>=1.6.0 <5.0.0'] }, captureDeclarations)
20
+ addHook({ name: 'vitest', versions: ['>=5.0.0'], filePattern: 'dist/chunks/run.*' }, captureDeclarations)
@@ -46,6 +46,26 @@ const {
46
46
  getVitestTestProperties,
47
47
  } = require('./vitest-util')
48
48
 
49
+ const emptyAnnotations = { mustFail: false, noAutoRetry: false }
50
+
51
+ /** @param {object} task */
52
+ function getAnnotations (task) {
53
+ return task.meta?.__ddTestOptAnnotations || emptyAnnotations
54
+ }
55
+
56
+ /** @param {object} task */
57
+ function getReportedProperties (task) {
58
+ const properties = taskToTestProperties.get(task) || getVitestTestProperties(
59
+ getProvidedContext(), task.file.filepath, getTestName(task)
60
+ )
61
+ return {
62
+ isAttemptToFix: properties.isAttemptToFix,
63
+ isDisabled: properties.isDisabled,
64
+ isQuarantined: properties.isQuarantined,
65
+ annotations: getAnnotations(task),
66
+ }
67
+ }
68
+
49
69
  const EFD_SUITE_ADMISSION_TIMEOUT_MS = 5000
50
70
  const logSubmissionFlushCh = channel('ci:log-submission:flush')
51
71
  const wrappedTestRunners = new WeakSet()
@@ -382,10 +402,11 @@ function hasConcurrentTests (file) {
382
402
  */
383
403
  function hasRunnableNewTest (file, providedContext) {
384
404
  for (const task of getTypeTasks(file.tasks)) {
385
- if (task.mode === 'skip' || task.mode === 'todo') continue
405
+ if (task.mode === 'skip' || task.mode === 'todo' || getAnnotations(task).noAutoRetry) continue
386
406
 
387
407
  const testProperties = getVitestTestProperties(providedContext, file.filepath, getTestName(task))
388
- if (testProperties.isNew && !testProperties.isAttemptToFix && !testProperties.isDisabled) {
408
+ if (testProperties.isNew && !testProperties.isAttemptToFix &&
409
+ (!testProperties.isDisabled || getAnnotations(task).mustFail)) {
389
410
  return true
390
411
  }
391
412
  }
@@ -550,6 +571,11 @@ function wrapVitestTestRunner (VitestTestRunner) {
550
571
  } = providedContext
551
572
  const testProperties = getVitestTestProperties(providedContext, task.file.filepath, testName)
552
573
  taskToTestProperties.set(task, testProperties)
574
+ const annotations = getAnnotations(task)
575
+ if (annotations.noAutoRetry && !annotations.hasFrameworkRetry &&
576
+ isFlakyTestRetriesEnabledForTask(providedContext, task)) {
577
+ task.retry = 0
578
+ }
553
579
 
554
580
  if (isTestManagementTestsEnabled) {
555
581
  const {
@@ -557,7 +583,7 @@ function wrapVitestTestRunner (VitestTestRunner) {
557
583
  isDisabled,
558
584
  isQuarantined,
559
585
  } = testProperties
560
- if (isAttemptToFix) {
586
+ if (isAttemptToFix && !annotations.noAutoRetry) {
561
587
  if (task.repeats !== testManagementAttemptToFixRetries) {
562
588
  attemptToFixRetryTasks.add(task)
563
589
  }
@@ -566,10 +592,10 @@ function wrapVitestTestRunner (VitestTestRunner) {
566
592
  attemptToFixTasks.add(task)
567
593
  attemptToFixTaskToStatuses.set(task, [])
568
594
  }
569
- if (isQuarantined) {
595
+ if (isQuarantined && !annotations.mustFail) {
570
596
  quarantinedTasks.add(task)
571
597
  }
572
- if (isDisabled) {
598
+ if (isDisabled && !annotations.mustFail) {
573
599
  disabledTasks.add(task)
574
600
  if (!attemptToFixTasks.has(task)) {
575
601
  // we only actually skip if the test is not being attempted to be fixed
@@ -589,7 +615,7 @@ function wrapVitestTestRunner (VitestTestRunner) {
589
615
  }
590
616
  }
591
617
 
592
- const isEfdCandidate = isEarlyFlakeDetectionEnabled &&
618
+ const isEfdCandidate = !annotations.noAutoRetry && isEarlyFlakeDetectionEnabled &&
593
619
  !attemptToFixTasks.has(task) &&
594
620
  !disabledTasks.has(task) &&
595
621
  (modifiedTasks.has(task) || newTasks.has(task))
@@ -605,6 +631,7 @@ function wrapVitestTestRunner (VitestTestRunner) {
605
631
  }
606
632
 
607
633
  if (
634
+ !annotations.noAutoRetry &&
608
635
  providedContext.isDynamicAtrEnabled &&
609
636
  isFlakyTestRetriesEnabledForTask(providedContext, task) &&
610
637
  !attemptToFixTasks.has(task) &&
@@ -818,7 +845,7 @@ function wrapVitestTestRunner (VitestTestRunner) {
818
845
  }
819
846
  }
820
847
 
821
- const isRetryReasonAtr = numAttempt > 0 &&
848
+ const isRetryReasonAtr = !getAnnotations(task).noAutoRetry && numAttempt > 0 &&
822
849
  isFlakyTestRetriesEnabledForTask(providedContext, task) &&
823
850
  !attemptToFixRetryTasks.has(task) &&
824
851
  !efdRetryTasks.has(task)
@@ -832,9 +859,7 @@ function wrapVitestTestRunner (VitestTestRunner) {
832
859
  isNew,
833
860
  hasDynamicName: dynamicNameTasks.has(task),
834
861
  mightHitProbe: isDiEnabled && isFailedTestReplayAllowed && numAttempt > 0,
835
- isAttemptToFix: attemptToFixTasks.has(task),
836
- isDisabled: disabledTasks.has(task),
837
- isQuarantined: quarantinedTasks.has(task),
862
+ ...getReportedProperties(task),
838
863
  isRetryReasonAtr,
839
864
  isModified: modifiedTasks.has(task),
840
865
  }
@@ -1123,9 +1148,7 @@ function getStartTestsWrapper (frameworkVersion) {
1123
1148
  testName: getTestName(task),
1124
1149
  testSuiteAbsolutePath: task.file.filepath,
1125
1150
  isNew: newTasks.has(task),
1126
- isAttemptToFix: attemptToFixTasks.has(task),
1127
- isDisabled: disabledTasks.has(task),
1128
- isQuarantined: quarantinedTasks.has(task),
1151
+ ...getReportedProperties(task),
1129
1152
  })
1130
1153
  } else if ((state === 'pass' && !isSwitchedStatus) || switchedStatus === 'pass') {
1131
1154
  // Attempt-to-fix can pass its last attempt while an earlier failure still fails the suite.
@@ -1174,7 +1197,8 @@ function getStartTestsWrapper (frameworkVersion) {
1174
1197
  }
1175
1198
 
1176
1199
  // ATR: set hasFailedAllRetries when all auto test retries were exhausted and every attempt failed
1177
- const isAtrRetry = isFlakyTestRetriesEnabledForTask(providedContext, task) && !attemptToFixTasks.has(task) &&
1200
+ const isAtrRetry = !getAnnotations(task).noAutoRetry &&
1201
+ isFlakyTestRetriesEnabledForTask(providedContext, task) && !attemptToFixTasks.has(task) &&
1178
1202
  !efdRetryTasks.has(task)
1179
1203
  if (isAtrRetry) {
1180
1204
  // Dynamic ATR: use the per-test duration-based count instead of the flat limit.
@@ -1230,9 +1254,7 @@ function getStartTestsWrapper (frameworkVersion) {
1230
1254
  testName: getTestName(task),
1231
1255
  testSuiteAbsolutePath: task.file.filepath,
1232
1256
  isNew: newTasks.has(task),
1233
- isAttemptToFix: attemptToFixTasks.has(task),
1234
- isDisabled: disabledTasks.has(task),
1235
- isQuarantined: quarantinedTasks.has(task),
1257
+ ...getReportedProperties(task),
1236
1258
  })
1237
1259
  }
1238
1260
  }
@@ -2,7 +2,16 @@
2
2
 
3
3
  const { getEnvironmentVariable } = require('../../dd-trace/src/config/helper')
4
4
  const { isTrue } = require('../../dd-trace/src/util')
5
+
6
+ const isWorker = getEnvironmentVariable('DD_VITEST_WORKER') === '1'
7
+ const VITEST_NO_WORKER_INIT_ACTIVE_ENV = 'DD_TEST_OPT_VITEST_NO_WORKER_INIT_ACTIVE'
8
+
9
+ // No-worker setup captures declarations directly, without registering instrumentation hooks.
10
+ // eslint-disable-next-line eslint-rules/eslint-process-env
11
+ if (isWorker && isTrue(process.env[VITEST_NO_WORKER_INIT_ACTIVE_ENV])) return
12
+
5
13
  const { channel } = require('./helpers/instrument')
14
+ require('./vitest-test-annotations')
6
15
 
7
16
  channel('tracing:orchestrion:@vitest/runner:createTestTask:end').subscribe(({ arguments: args, result: task }) => {
8
17
  // Suite options have already been merged here, including overrides equal to ATR's count.
@@ -11,14 +20,7 @@ channel('tracing:orchestrion:@vitest/runner:createTestTask:end').subscribe(({ ar
11
20
  }
12
21
  })
13
22
 
14
- if (getEnvironmentVariable('DD_VITEST_WORKER') === '1') {
15
- const VITEST_NO_WORKER_INIT_ACTIVE_ENV = 'DD_TEST_OPT_VITEST_NO_WORKER_INIT_ACTIVE'
16
-
17
- // In no-worker-init mode the main process reports Vitest events from reporter hooks.
18
- // Loading worker instrumentation here would reintroduce the worker tracer path.
19
- // eslint-disable-next-line eslint-rules/eslint-process-env
20
- if (isTrue(process.env[VITEST_NO_WORKER_INIT_ACTIVE_ENV])) return
21
-
23
+ if (isWorker) {
22
24
  require('./vitest-worker')
23
25
  } else {
24
26
  require('./vitest-main')
@@ -250,6 +250,11 @@ class CucumberPlugin extends CiPlugin {
250
250
  [TEST_SOURCE_START]: testSourceLine,
251
251
  [TEST_SOURCE_FILE]: testSourceFile,
252
252
  }
253
+ if (ctx.testAnnotations?.mustFail) extraTags['test.test_management.prevent_failure_suppression'] = 'true'
254
+ if (ctx.testAnnotations?.noAutoRetry) extraTags['test.test_management.no_auto_retry'] = 'true'
255
+ if (ctx.assignedProperties?.attempt_to_fix) extraTags[TEST_MANAGEMENT_IS_ATTEMPT_TO_FIX] = 'true'
256
+ if (ctx.assignedProperties?.disabled) extraTags[TEST_MANAGEMENT_IS_DISABLED] = 'true'
257
+ if (ctx.assignedProperties?.quarantined) extraTags[TEST_MANAGEMENT_IS_QUARANTINED] = 'true'
253
258
  if (isParallel) {
254
259
  extraTags[CUCUMBER_IS_PARALLEL] = 'true'
255
260
  }