dd-trace 6.7.0 → 6.8.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 (147) hide show
  1. package/ci/test-optimization-validation/command-output-policy.js +5 -5
  2. package/ci/test-optimization-validation/framework-adapters/playwright.js +5 -5
  3. package/ci/test-optimization-validation/generated-files.js +9 -9
  4. package/ci/test-optimization-validation/generated-test-contract.js +1 -3
  5. package/ci/test-optimization-validation/manifest-scaffold.js +1 -2
  6. package/ci/test-optimization-validation/offline-output.js +6 -6
  7. package/ci/test-optimization-validation/runner-command.js +1 -1
  8. package/ci/test-optimization-validation/safe-files.js +4 -4
  9. package/ci/test-optimization-validation/scenarios/basic-reporting.js +1 -1
  10. package/ci/test-optimization-validation/scenarios/test-management.js +2 -2
  11. package/ci/vitest-no-worker-init-setup.mjs +348 -51
  12. package/index.d.ts +77 -13
  13. package/package.json +9 -3
  14. package/packages/datadog-core/src/utils/src/kebabcase.js +8 -2
  15. package/packages/datadog-esbuild/index.js +4 -2
  16. package/packages/datadog-esbuild/src/utils.js +1 -1
  17. package/packages/datadog-instrumentations/src/claude-agent-sdk.js +4 -4
  18. package/packages/datadog-instrumentations/src/cucumber.js +9 -6
  19. package/packages/datadog-instrumentations/src/helpers/extract-package-and-module-path.js +10 -0
  20. package/packages/datadog-instrumentations/src/helpers/hook.js +19 -2
  21. package/packages/datadog-instrumentations/src/helpers/hooks.js +2 -0
  22. package/packages/datadog-instrumentations/src/helpers/register.js +9 -3
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +1 -0
  24. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +1 -0
  25. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +57 -0
  26. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +50 -18
  27. package/packages/datadog-instrumentations/src/helpers/router-helper.js +1 -1
  28. package/packages/datadog-instrumentations/src/helpers/shared-utils.js +39 -0
  29. package/packages/datadog-instrumentations/src/http/client.js +1 -3
  30. package/packages/datadog-instrumentations/src/jest.js +8 -14
  31. package/packages/datadog-instrumentations/src/mocha/common.js +1 -3
  32. package/packages/datadog-instrumentations/src/mocha/main.js +2 -42
  33. package/packages/datadog-instrumentations/src/mocha/utils.js +68 -2
  34. package/packages/datadog-instrumentations/src/mocha/webdriverio-protocol.js +19 -0
  35. package/packages/datadog-instrumentations/src/mocha/worker.js +446 -42
  36. package/packages/datadog-instrumentations/src/moleculer/client.js +1 -1
  37. package/packages/datadog-instrumentations/src/playwright.js +3 -2
  38. package/packages/datadog-instrumentations/src/rhea.js +1 -1
  39. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +525 -56
  40. package/packages/datadog-instrumentations/src/vitest-main.js +90 -10
  41. package/packages/datadog-instrumentations/src/webdriverio.js +914 -0
  42. package/packages/datadog-plugin-aerospike/src/index.js +1 -3
  43. package/packages/datadog-plugin-amqplib/src/client.js +1 -1
  44. package/packages/datadog-plugin-amqplib/src/producer.js +1 -1
  45. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +2 -2
  46. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +2 -2
  47. package/packages/datadog-plugin-azure-event-hubs/src/producer.js +1 -3
  48. package/packages/datadog-plugin-azure-service-bus/src/producer.js +5 -3
  49. package/packages/datadog-plugin-bullmq/src/producer.js +3 -3
  50. package/packages/datadog-plugin-child_process/src/index.js +3 -3
  51. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +5 -8
  52. package/packages/datadog-plugin-cypress/src/source-map-utils.js +1 -1
  53. package/packages/datadog-plugin-fastify/src/tracing.js +1 -1
  54. package/packages/datadog-plugin-fs/src/index.js +0 -4
  55. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +14 -7
  56. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -10
  57. package/packages/datadog-plugin-graphql/src/execute.js +1 -0
  58. package/packages/datadog-plugin-graphql/src/tools/signature.js +1 -1
  59. package/packages/datadog-plugin-http/src/client.js +2 -1
  60. package/packages/datadog-plugin-jest/src/index.js +2 -3
  61. package/packages/datadog-plugin-jest/src/util.js +2 -1
  62. package/packages/datadog-plugin-langchain/src/tokens.js +2 -2
  63. package/packages/datadog-plugin-mocha/src/index.js +25 -6
  64. package/packages/datadog-plugin-prisma/src/index.js +5 -1
  65. package/packages/datadog-plugin-rhea/src/consumer.js +16 -13
  66. package/packages/datadog-plugin-rhea/src/producer.js +1 -1
  67. package/packages/datadog-plugin-undici/src/index.js +2 -1
  68. package/packages/datadog-plugin-vitest/src/index.js +84 -11
  69. package/packages/datadog-webpack/index.js +2 -2
  70. package/packages/dd-trace/src/appsec/downstream_requests.js +1 -1
  71. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-base-analyzer.js +1 -1
  72. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-analyzer.js +1 -1
  73. package/packages/dd-trace/src/appsec/iast/analyzers/sql-injection-analyzer.js +1 -1
  74. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +1 -3
  75. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +1 -1
  76. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +2 -2
  77. package/packages/dd-trace/src/appsec/sdk/track_event.js +1 -1
  78. package/packages/dd-trace/src/appsec/waf/waf_manager.js +1 -1
  79. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +7 -6
  80. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +2 -2
  81. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +2 -1
  82. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +4 -0
  83. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/webdriverio.js +26 -0
  84. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +9 -1
  85. package/packages/dd-trace/src/ci-visibility/requests/request.js +3 -3
  86. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +1 -1
  87. package/packages/dd-trace/src/config/defaults.js +14 -6
  88. package/packages/dd-trace/src/config/generated-config-types.d.ts +2 -2
  89. package/packages/dd-trace/src/config/index.js +15 -0
  90. package/packages/dd-trace/src/config/parsers.js +19 -1
  91. package/packages/dd-trace/src/config/supported-configurations.json +5 -6
  92. package/packages/dd-trace/src/datastreams/encoding.js +3 -4
  93. package/packages/dd-trace/src/debugger/devtools_client/log.js +2 -1
  94. package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +1 -4
  95. package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -2
  96. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +2 -2
  97. package/packages/dd-trace/src/debugger/devtools_client/snapshot/redaction.js +16 -2
  98. package/packages/dd-trace/src/encode/tags-processors.js +2 -2
  99. package/packages/dd-trace/src/exporters/common/url.js +3 -5
  100. package/packages/dd-trace/src/exporters/electron/index.js +4 -1
  101. package/packages/dd-trace/src/external-logger/src/index.js +1 -2
  102. package/packages/dd-trace/src/flare/index.js +2 -2
  103. package/packages/dd-trace/src/id.js +1 -1
  104. package/packages/dd-trace/src/llmobs/constants/tags.js +1 -1
  105. package/packages/dd-trace/src/llmobs/experiments/client.js +4 -2
  106. package/packages/dd-trace/src/llmobs/experiments/dataset.js +66 -14
  107. package/packages/dd-trace/src/llmobs/experiments/experiment.js +289 -95
  108. package/packages/dd-trace/src/llmobs/experiments/index.js +51 -12
  109. package/packages/dd-trace/src/llmobs/experiments/noop.js +95 -10
  110. package/packages/dd-trace/src/llmobs/experiments/result.js +13 -2
  111. package/packages/dd-trace/src/llmobs/experiments/util.js +218 -0
  112. package/packages/dd-trace/src/llmobs/plugins/anthropic/index.js +1 -1
  113. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +1 -1
  114. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
  115. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +1 -1
  116. package/packages/dd-trace/src/llmobs/sdk.js +4 -11
  117. package/packages/dd-trace/src/llmobs/span_processor.js +9 -7
  118. package/packages/dd-trace/src/llmobs/tagger.js +1 -2
  119. package/packages/dd-trace/src/llmobs/writers/spans.js +12 -6
  120. package/packages/dd-trace/src/noop/proxy.js +2 -2
  121. package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +1 -1
  122. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -1
  123. package/packages/dd-trace/src/opentracing/span.js +1 -1
  124. package/packages/dd-trace/src/opentracing/span_context.js +1 -1
  125. package/packages/dd-trace/src/plugins/ci_plugin.js +105 -20
  126. package/packages/dd-trace/src/plugins/index.js +1 -0
  127. package/packages/dd-trace/src/plugins/plugin.js +1 -1
  128. package/packages/dd-trace/src/plugins/tracing.js +1 -0
  129. package/packages/dd-trace/src/plugins/util/ci.js +7 -6
  130. package/packages/dd-trace/src/plugins/util/git.js +1 -1
  131. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +1 -1
  132. package/packages/dd-trace/src/plugins/util/llm.js +2 -2
  133. package/packages/dd-trace/src/plugins/util/tags.js +2 -0
  134. package/packages/dd-trace/src/plugins/util/test.js +38 -12
  135. package/packages/dd-trace/src/plugins/util/url.js +5 -5
  136. package/packages/dd-trace/src/plugins/util/user-provided-git.js +1 -1
  137. package/packages/dd-trace/src/plugins/util/web.js +1 -1
  138. package/packages/dd-trace/src/priority_sampler.js +6 -3
  139. package/packages/dd-trace/src/profiling/profilers/poisson.js +1 -1
  140. package/packages/dd-trace/src/profiling/profilers/shared.js +2 -2
  141. package/packages/dd-trace/src/ritm.js +5 -20
  142. package/packages/dd-trace/src/startup-log.js +3 -0
  143. package/packages/dd-trace/src/telemetry/logs/log-collector.js +3 -1
  144. package/packages/dd-trace/src/util.js +16 -0
  145. package/vendor/dist/@apm-js-collab/code-transformer/index.js +12 -12
  146. package/vendor/dist/pprof-format/index.js +1 -1
  147. package/vendor/dist/source-map/index.js +1 -1
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const fs = require('node:fs')
3
4
  const path = require('node:path')
4
5
  const { fileURLToPath } = require('node:url')
5
6
  const { MessagePort } = require('node:worker_threads')
@@ -67,6 +68,7 @@ let coverageRootDir
67
68
  let requestErrorTags = {}
68
69
  let isSessionStarted = false
69
70
  let isVitestNoWorkerInitActive = false
71
+ let isVitestBrowserModeActive = false
70
72
  let vitestPool = null
71
73
  let isMessagePortWrapped = false
72
74
  const tinyPoolClassWrappers = new WeakMap()
@@ -197,7 +199,21 @@ function getTestFilepaths (ctx, testSpecifications) {
197
199
  */
198
200
  function getNormalizedTestSuitePath (testFilepath, repositoryRoot) {
199
201
  const testSuiteAbsolutePath = path.isAbsolute(testFilepath) ? testFilepath : path.join(repositoryRoot, testFilepath)
200
- return getTestSuitePath(testSuiteAbsolutePath, repositoryRoot)
202
+ return getTestSuitePath(realpath(testSuiteAbsolutePath), realpath(repositoryRoot))
203
+ }
204
+
205
+ /**
206
+ * Resolves a path without failing Test Optimization when the path is unavailable.
207
+ *
208
+ * @param {string} filepath
209
+ * @returns {string}
210
+ */
211
+ function realpath (filepath) {
212
+ try {
213
+ return fs.realpathSync(filepath)
214
+ } catch {
215
+ return filepath
216
+ }
201
217
  }
202
218
 
203
219
  /**
@@ -281,6 +297,10 @@ function getTestPropertiesByFilepath (
281
297
  for (const testFilepath of testFilepaths) {
282
298
  if (typeof testFilepath !== 'string') continue
283
299
 
300
+ const testSuiteAbsolutePath = path.isAbsolute(testFilepath)
301
+ ? testFilepath
302
+ : path.join(repositoryRoot, testFilepath)
303
+ const realTestFilepath = realpath(testSuiteAbsolutePath)
284
304
  const testSuite = getNormalizedTestSuitePath(testFilepath, repositoryRoot)
285
305
  const testProperties = { testSuite }
286
306
  const hasProperties = knownTestsBySuite !== undefined ||
@@ -299,6 +319,8 @@ function getTestPropertiesByFilepath (
299
319
 
300
320
  if (hasProperties) {
301
321
  testPropertiesByFilepath[testFilepath] = testProperties
322
+ testPropertiesByFilepath[testSuiteAbsolutePath] = testProperties
323
+ testPropertiesByFilepath[realTestFilepath] = testProperties
302
324
  }
303
325
  }
304
326
 
@@ -405,11 +427,18 @@ function mergeRequestErrorTags (requestResponse) {
405
427
  }
406
428
  }
407
429
 
408
- async function runMainProcessSetup (ctx, frameworkVersion, testSpecifications, shouldInstallNoWorkerInit) {
430
+ async function runMainProcessSetup (
431
+ ctx,
432
+ frameworkVersion,
433
+ testSpecifications,
434
+ shouldInstallNoWorkerInit,
435
+ shouldInstallBrowserReporter
436
+ ) {
409
437
  if (!testSessionFinishCh.hasSubscribers) {
410
438
  return
411
439
  }
412
440
 
441
+ isVitestBrowserModeActive ||= shouldInstallBrowserReporter
413
442
  let repositoryRoot = process.cwd()
414
443
  let testSessionConfiguration
415
444
  let testFilepaths
@@ -435,7 +464,7 @@ async function runMainProcessSetup (ctx, frameworkVersion, testSpecifications, s
435
464
  requestErrorTags: receivedRequestErrorTags = {},
436
465
  } = await getChannelPromise(libraryConfigurationCh, {
437
466
  frameworkVersion,
438
- isVitestNoWorkerInitActive: shouldInstallNoWorkerInit,
467
+ isVitestNoWorkerInitActive: shouldInstallNoWorkerInit || isVitestBrowserModeActive,
439
468
  })
440
469
  requestErrorTags = receivedRequestErrorTags
441
470
  if (err) {
@@ -459,7 +488,11 @@ async function runMainProcessSetup (ctx, frameworkVersion, testSpecifications, s
459
488
  repositoryRoot: receivedRepositoryRoot,
460
489
  codeOwnersEntries,
461
490
  } = testSessionConfiguration
462
- repositoryRoot = receivedRepositoryRoot || repositoryRoot
491
+ repositoryRoot = realpath(receivedRepositoryRoot || repositoryRoot)
492
+ testSessionConfiguration = {
493
+ ...testSessionConfiguration,
494
+ repositoryRoot,
495
+ }
463
496
  if (!shouldInstallNoWorkerInit) {
464
497
  setProvidedContext(ctx, {
465
498
  _ddTestSessionId: testSessionId,
@@ -589,8 +622,11 @@ async function runMainProcessSetup (ctx, frameworkVersion, testSpecifications, s
589
622
  }
590
623
  }
591
624
 
592
- if (shouldInstallNoWorkerInit) {
593
- noWorkerInit.configure(ctx, frameworkVersion, testSpecifications, {
625
+ if (shouldInstallNoWorkerInit || shouldInstallBrowserReporter) {
626
+ const reporterTestSpecifications = shouldInstallNoWorkerInit
627
+ ? testSpecifications
628
+ : getBrowserTestSpecifications(testSpecifications)
629
+ noWorkerInit.configure(ctx, frameworkVersion, reporterTestSpecifications, {
594
630
  knownTests,
595
631
  knownTestsBySuite,
596
632
  modifiedFiles,
@@ -602,6 +638,7 @@ async function runMainProcessSetup (ctx, frameworkVersion, testSpecifications, s
602
638
  testSessionConfiguration,
603
639
  }, {
604
640
  getConfiguredEfdRetryCount,
641
+ shouldReportTestModule: shouldInstallBrowserReporter ? isBrowserTestModule : undefined,
605
642
  state: getNoWorkerInitState(),
606
643
  })
607
644
  }
@@ -628,18 +665,29 @@ function getNoWorkerInitState () {
628
665
 
629
666
  function ensureMainProcessSetup (ctx, frameworkVersion, testSpecifications, shouldDeactivateOnFallback = false) {
630
667
  const shouldInstallNoWorkerInit = shouldUseNoWorkerInit(ctx, frameworkVersion, testSpecifications)
668
+ const shouldInstallBrowserReporter = shouldUseBrowserReporter(frameworkVersion, testSpecifications)
669
+ const shouldInstallMainReporter = shouldInstallNoWorkerInit || shouldInstallBrowserReporter
631
670
  const specificationsKey = getTestSpecificationsKey(testSpecifications)
632
671
  let setupState = mainProcessSetupStates.get(ctx)
633
- if (shouldDeactivateOnFallback && setupState?.shouldInstallNoWorkerInit && !shouldInstallNoWorkerInit) {
672
+ if (shouldDeactivateOnFallback && setupState?.shouldInstallMainReporter && !shouldInstallMainReporter) {
634
673
  noWorkerInit.deactivate(ctx)
635
674
  }
636
675
  if (
637
676
  !setupState ||
638
677
  setupState.specificationsKey !== specificationsKey ||
639
- setupState.shouldInstallNoWorkerInit !== shouldInstallNoWorkerInit
678
+ setupState.shouldInstallNoWorkerInit !== shouldInstallNoWorkerInit ||
679
+ setupState.shouldInstallBrowserReporter !== shouldInstallBrowserReporter
640
680
  ) {
641
681
  setupState = {
642
- setupPromise: runMainProcessSetup(ctx, frameworkVersion, testSpecifications, shouldInstallNoWorkerInit),
682
+ setupPromise: runMainProcessSetup(
683
+ ctx,
684
+ frameworkVersion,
685
+ testSpecifications,
686
+ shouldInstallNoWorkerInit,
687
+ shouldInstallBrowserReporter
688
+ ),
689
+ shouldInstallBrowserReporter,
690
+ shouldInstallMainReporter,
643
691
  shouldInstallNoWorkerInit,
644
692
  specificationsKey,
645
693
  }
@@ -655,6 +703,12 @@ function shouldUseNoWorkerInit (ctx, frameworkVersion, testSpecifications) {
655
703
  })
656
704
  }
657
705
 
706
+ function shouldUseBrowserReporter (frameworkVersion, testSpecifications) {
707
+ return noWorkerInit.isSupportedVersion(frameworkVersion) &&
708
+ Array.isArray(testSpecifications) &&
709
+ testSpecifications.some(isBrowserTestSpecification)
710
+ }
711
+
658
712
  function configureFlakyTestRetries (ctx, testSpecifications) {
659
713
  if (!isFlakyTestRetriesEnabled || flakyTestRetriesCount <= 0) return
660
714
 
@@ -828,7 +882,7 @@ function getFinishWrapper (exitOrClose) {
828
882
  isTestManagementTestsEnabled,
829
883
  requestErrorTags,
830
884
  vitestPool,
831
- isVitestNoWorkerInitActive,
885
+ isVitestNoWorkerInitActive: isVitestNoWorkerInitActive || isVitestBrowserModeActive,
832
886
  })
833
887
 
834
888
  logTestOptimizationSummary({ attemptToFixExecutions, newTestsWithDynamicNames })
@@ -869,6 +923,15 @@ function isVitestWorkerPool (pool) {
869
923
  return isForkPool(pool) || isThreadPool(pool)
870
924
  }
871
925
 
926
+ function isBrowserProject (project) {
927
+ try {
928
+ if (project?.isBrowserEnabled?.()) return true
929
+ } catch {}
930
+
931
+ return safeConfig(project)?.browser?.enabled === true ||
932
+ project?.serializedConfig?.browser?.enabled === true
933
+ }
934
+
872
935
  function getTestSpecificationProject (testSpecification) {
873
936
  if (Array.isArray(testSpecification)) {
874
937
  return testSpecification[0]
@@ -890,6 +953,23 @@ function getTestSpecificationPool (testSpecification) {
890
953
  testSpecification?.pool
891
954
  }
892
955
 
956
+ function isBrowserTestSpecification (testSpecification) {
957
+ return getTestSpecificationPool(testSpecification) === 'browser' ||
958
+ isBrowserProject(getTestSpecificationProject(testSpecification))
959
+ }
960
+
961
+ function getBrowserTestSpecifications (testSpecifications) {
962
+ if (!Array.isArray(testSpecifications)) return testSpecifications
963
+
964
+ return testSpecifications.filter(isBrowserTestSpecification)
965
+ }
966
+
967
+ function isBrowserTestModule (testModule) {
968
+ return testModule?.task?.pool === 'browser' ||
969
+ testModule?.pool === 'browser' ||
970
+ isBrowserProject(testModule?.project)
971
+ }
972
+
893
973
  function hasVitestWorkerPoolTestSpecification (testSpecifications) {
894
974
  if (!Array.isArray(testSpecifications)) {
895
975
  return false