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
@@ -4,6 +4,7 @@ const shimmer = require('../../datadog-shimmer')
4
4
  const {
5
5
  channel,
6
6
  addHook,
7
+ AsyncResource,
7
8
  } = require('./helpers/instrument')
8
9
 
9
10
  const connectionAttributes = new WeakMap()
@@ -20,6 +21,36 @@ function finish (ctx) {
20
21
  finishChannel.publish(ctx)
21
22
  }
22
23
 
24
+ /** @param {import('oracledb').Pool} pool */
25
+ function bindPoolRequestContexts (pool) {
26
+ const queue = pool._pendingRequestQueue
27
+ if (!(queue instanceof Set) || typeof pool.sessionCallback !== 'function') return
28
+
29
+ const contexts = new WeakMap()
30
+ // Each pool creates its own queue, so its insertion method needs a runtime wrapper.
31
+ shimmer.wrap(pool, '_processRequest',
32
+ /** @param {(request: object) => Promise<void>} processRequest */
33
+ processRequest => {
34
+ shimmer.wrap(queue, 'add',
35
+ /** @param {(request: object) => Set<object>} add */
36
+ add => /** @param {object} request */ function (request) {
37
+ if (startChannel.hasSubscribers) {
38
+ contexts.set(request, AsyncResource.bind(processRequest))
39
+ }
40
+ return add.apply(this, arguments)
41
+ })
42
+
43
+ return /** @param {object} request */ function (request) {
44
+ const processInContext = contexts.get(request)
45
+ if (processInContext !== undefined) {
46
+ contexts.delete(request)
47
+ return processInContext.apply(this, arguments)
48
+ }
49
+ return processRequest.apply(this, arguments)
50
+ }
51
+ })
52
+ }
53
+
23
54
  addHook({ name: 'oracledb', versions: ['>=5'], file: 'lib/oracledb.js' }, oracledb => {
24
55
  shimmer.wrap(oracledb.Connection.prototype, 'execute', execute => {
25
56
  return function wrappedExecute (dbQuery) {
@@ -134,6 +165,7 @@ addHook({ name: 'oracledb', versions: ['>=5'], file: 'lib/oracledb.js' }, oracle
134
165
  arguments[1] = shimmer.wrapFunction(callback, callback => (err, pool) => {
135
166
  if (pool) {
136
167
  poolAttributes.set(pool, poolAttrs)
168
+ bindPoolRequestContexts(pool)
137
169
  }
138
170
  callback(err, pool)
139
171
  })
@@ -142,6 +174,7 @@ addHook({ name: 'oracledb', versions: ['>=5'], file: 'lib/oracledb.js' }, oracle
142
174
  } else {
143
175
  return createPool.apply(this, arguments).then((pool) => {
144
176
  poolAttributes.set(pool, poolAttrs)
177
+ bindPoolRequestContexts(pool)
145
178
  return pool
146
179
  })
147
180
  }
@@ -286,7 +286,8 @@ function wrapQuery (query) {
286
286
  const queryQueue = deperecated ? this._queryQueue : this.queryQueue
287
287
  const activeQuery = deperecated ? this._activeQuery : this.activeQuery
288
288
 
289
- const newQuery = queryQueue.at(-1) || activeQuery
289
+ // In pipeline mode, _sentQueryQueue contains submitted queries waiting behind activeQuery.
290
+ const newQuery = queryQueue.at(-1) || this._sentQueryQueue?.at(-1) || activeQuery
290
291
 
291
292
  if (!newQuery) {
292
293
  return retval
@@ -5,6 +5,8 @@ const realSetTimeout = setTimeout
5
5
  const realClearTimeout = clearTimeout
6
6
 
7
7
  const { performance } = require('node:perf_hooks')
8
+
9
+ const { getTestAnnotations } = require('../../dd-trace/src/ci-visibility/test-annotations')
8
10
  const satisfies = require('../../../vendor/dist/semifies')
9
11
 
10
12
  const shimmer = require('../../datadog-shimmer')
@@ -188,7 +190,7 @@ function isAutomaticFailureVideoAttachment (attachment) {
188
190
  }
189
191
 
190
192
  function isValidKnownTests (receivedKnownTests) {
191
- return !!receivedKnownTests.playwright
193
+ return !!receivedKnownTests?.playwright
192
194
  }
193
195
 
194
196
  function getTestFullyQualifiedName (test) {
@@ -279,10 +281,12 @@ function shouldRunEarlyFlakeDetection () {
279
281
  }
280
282
 
281
283
  function isTestEfdManaged (test) {
282
- return !!test._ddIsEfdManagedTest || (
283
- (test._ddIsNew || test._ddIsModified) &&
284
- !test._ddIsAttemptToFix &&
285
- shouldRunEarlyFlakeDetection()
284
+ return !test._ddIsAutomaticRetryExcluded && !getTestAnnotations(test.fn).noAutoRetry && (
285
+ !!test._ddIsEfdManagedTest || (
286
+ (test._ddIsNew || test._ddIsModified) &&
287
+ !test._ddIsAttemptToFix &&
288
+ shouldRunEarlyFlakeDetection()
289
+ )
286
290
  )
287
291
  }
288
292
 
@@ -440,13 +444,31 @@ function shouldSkipEfdRetryTest (test) {
440
444
  return shouldSkipEfdRetry(test._ddEfdRetryIndex, retryCount)
441
445
  }
442
446
 
447
+ /** @param {object} test */
448
+ function getExclusionTags (test) {
449
+ const { mustFail, noAutoRetry } = getTestAnnotations(test.fn)
450
+ const properties = test._ddAssignedProperties
451
+ const tags = {}
452
+ if (mustFail) tags['test.test_management.prevent_failure_suppression'] = 'true'
453
+ if (noAutoRetry) tags['test.test_management.no_auto_retry'] = 'true'
454
+ if (properties?.attempt_to_fix) tags['test.test_management.is_attempt_to_fix'] = 'true'
455
+ if (properties?.disabled) tags['test.test_management.is_test_disabled'] = 'true'
456
+ if (properties?.quarantined) tags['test.test_management.is_quarantined'] = 'true'
457
+ return tags
458
+ }
459
+
443
460
  function getTestProperties (test) {
444
461
  const testName = getTestFullname(test)
445
462
  const testSuite = getTestSuitePath(test._requireFile, rootDir)
446
463
 
447
464
  const { attempt_to_fix: attemptToFix, disabled, quarantined } =
448
465
  testManagementTests?.playwright?.suites?.[testSuite]?.tests?.[testName]?.properties || {}
449
- return { attemptToFix, disabled, quarantined }
466
+ const { mustFail, noAutoRetry } = getTestAnnotations(test.fn)
467
+ return {
468
+ attemptToFix: attemptToFix && !noAutoRetry && !test._ddIsAutomaticRetryExcluded,
469
+ disabled: disabled && !mustFail,
470
+ quarantined: quarantined && !mustFail,
471
+ }
450
472
  }
451
473
 
452
474
  function isNewTest (test) {
@@ -480,6 +502,7 @@ function deepCloneSuite (suite, filterTest, tags = [], configureCopiedTest) {
480
502
  } else {
481
503
  if (filterTest(entry)) {
482
504
  const copiedTest = entry._clone()
505
+ copiedTest._ddAssignedProperties = entry._ddAssignedProperties
483
506
  originalTestIdsByRetry.set(copiedTest, originalTestIdsByRetry.get(entry) ?? entry.id)
484
507
  if (configureCopiedTest) {
485
508
  configureCopiedTest(copiedTest, entry)
@@ -799,6 +822,7 @@ function testBeginHandler (test, browserName, shouldCreateTestSpan) {
799
822
  if (shouldCreateTestSpan) {
800
823
  const testName = getTestFullname(test)
801
824
  const testCtx = {
825
+ extraTags: getExclusionTags(test),
802
826
  testName,
803
827
  testSuiteAbsolutePath,
804
828
  testSourceFileAbsolutePath,
@@ -850,6 +874,7 @@ function finishTestSuiteIfDone (testSuiteAbsolutePath, projects) {
850
874
  const browserName = getBrowserNameFromProjects(projects, test)
851
875
  recordSkippedTestOptimizationExecution(test, testSuiteAbsolutePath)
852
876
  testSkipCh.publish({
877
+ extraTags: getExclusionTags(test),
853
878
  testName: getTestFullname(test),
854
879
  testSuiteAbsolutePath,
855
880
  testSourceFileAbsolutePath: test.location.file,
@@ -885,7 +910,7 @@ function finishTestSuiteIfDone (testSuiteAbsolutePath, projects) {
885
910
  * @param {object[]} projects
886
911
  */
887
912
  function hasAutomaticRetries (test, projects) {
888
- if (!automaticRetryProjects.has(getTestProject(projects, test))) return false
913
+ if (test._ddIsAutomaticRetryExcluded || !automaticRetryProjects.has(getTestProject(projects, test))) return false
889
914
  for (let suite = test.parent; suite; suite = suite.parent) {
890
915
  if (suite._retries !== undefined) return false
891
916
  }
@@ -984,7 +1009,7 @@ function testEndHandler ({
984
1009
  const testProperties = getTestProperties(test)
985
1010
  if (
986
1011
  isDynamicAtrEnabled &&
987
- isFlakyTestRetriesEnabled &&
1012
+ isFlakyTestRetriesEnabled && !getTestAnnotations(test.fn).noAutoRetry &&
988
1013
  !testProperties.attemptToFix &&
989
1014
  !test._ddIsEfdRetry &&
990
1015
  !isEfdManagedTest &&
@@ -1057,7 +1082,9 @@ function testEndHandler ({
1057
1082
  const atrRetryCount = isDynamicAtrEnabled
1058
1083
  ? dynamicAtrRetryCountByTestKey.get(dynamicAtrTestKey) ?? test.retries
1059
1084
  : flakyTestRetriesCount
1060
- if (isFlakyTestRetriesEnabled && !testProperties.attemptToFix && !test._ddIsEfdRetry &&
1085
+ if (!test._ddIsAutomaticRetryExcluded && !getTestAnnotations(test.fn).noAutoRetry &&
1086
+ isFlakyTestRetriesEnabled &&
1087
+ !testProperties.attemptToFix && !test._ddIsEfdRetry &&
1061
1088
  !(test._ddIsNew || test._ddIsModified) &&
1062
1089
  atrRetryCount != null && atrRetryCount > 0 &&
1063
1090
  // Serial suites can add skipped results before a test's first execution.
@@ -1076,8 +1103,8 @@ function testEndHandler ({
1076
1103
  ? test.id ?? test._id
1077
1104
  : undefined
1078
1105
  const isAtrRetry = testResult?.retry > 0 &&
1079
- isFlakyTestRetriesEnabled &&
1080
- hasAutomaticRetries(test, projects) &&
1106
+ isFlakyTestRetriesEnabled && !test._ddIsAutomaticRetryExcluded &&
1107
+ !getTestAnnotations(test.fn).noAutoRetry && hasAutomaticRetries(test, projects) &&
1081
1108
  !test._ddIsAttemptToFix &&
1082
1109
  !test._ddIsEfdRetry
1083
1110
 
@@ -1102,7 +1129,7 @@ function testEndHandler ({
1102
1129
  steps: testResult?.steps || [],
1103
1130
  isRetry: testResult?.retry > 0,
1104
1131
  error,
1105
- extraTags: annotationTags,
1132
+ extraTags: { ...annotationTags, ...getExclusionTags(test) },
1106
1133
  isNew: test._ddIsNew,
1107
1134
  hasDynamicName: test._ddIsNew && DYNAMIC_NAME_RE.test(getTestFullname(test)),
1108
1135
  isAttemptToFix: test._ddIsAttemptToFix,
@@ -1340,8 +1367,8 @@ function onDispatcherCreateWorker (dispatcher, worker) {
1340
1367
  worker[kDdPlaywrightFailureVideos].push(videos)
1341
1368
  }
1342
1369
  const isAtrRetry = testResult?.retry > 0 &&
1343
- isFlakyTestRetriesEnabled &&
1344
- hasAutomaticRetries(test, projects) &&
1370
+ isFlakyTestRetriesEnabled && !test._ddIsAutomaticRetryExcluded &&
1371
+ !getTestAnnotations(test.fn).noAutoRetry && hasAutomaticRetries(test, projects) &&
1345
1372
  !test._ddIsAttemptToFix &&
1346
1373
  !test._ddIsEfdRetry
1347
1374
 
@@ -1367,6 +1394,7 @@ function onDispatcherCreateWorker (dispatcher, worker) {
1367
1394
  (!isFinalExecution || (isSerialTest(test) && test.results.length <= test.retries))
1368
1395
 
1369
1396
  const ddProperties = {
1397
+ _ddAssignedProperties: test._ddAssignedProperties,
1370
1398
  _ddRetryTestId: retryTestId,
1371
1399
  _ddDeferFinalStatus: deferFinalStatus,
1372
1400
  _ddIsDisabled: test._ddIsDisabled,
@@ -1487,6 +1515,7 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
1487
1515
  const playwrightConfig = config?.config || runnerConfig.config || runnerConfig
1488
1516
  rootDir = getRootDir(this, config)
1489
1517
  const projects = getProjectsFromRunner(this, config)
1518
+ sessionProjects = projects
1490
1519
  const isFailureScreenshotEnabled = isFailureScreenshotCaptureEnabled(projects)
1491
1520
  const isFailureVideoEnabled = isFailureVideoCaptureEnabled(projects)
1492
1521
  const isFailureVideoUploadSupported = satisfies(playwrightVersion, MINIMUM_FAILURE_VIDEO_UPLOAD_VERSION_RANGE)
@@ -1556,11 +1585,11 @@ function runAllTestsWrapper (runAllTests, playwrightVersion) {
1556
1585
  isKnownTestsEnabled = false
1557
1586
  } else {
1558
1587
  knownTests = receivedKnownTests
1559
- }
1560
- if (!isValidKnownTests(receivedKnownTests)) {
1561
- isEarlyFlakeDetectionFaulty = true
1562
- isEarlyFlakeDetectionEnabled = false
1563
- isKnownTestsEnabled = false
1588
+ if (!isValidKnownTests(receivedKnownTests)) {
1589
+ isEarlyFlakeDetectionFaulty = true
1590
+ isEarlyFlakeDetectionEnabled = false
1591
+ isKnownTestsEnabled = false
1592
+ }
1564
1593
  }
1565
1594
  } catch (err) {
1566
1595
  isEarlyFlakeDetectionEnabled = false
@@ -2198,10 +2227,6 @@ function applyRetriesToTests (
2198
2227
  }
2199
2228
 
2200
2229
  function processRootSuite (createRootSuiteReturnValue) {
2201
- if (!isKnownTestsEnabled && !isTestManagementTestsEnabled && !isImpactedTestsEnabled) {
2202
- return createRootSuiteReturnValue
2203
- }
2204
-
2205
2230
  if (!createRootSuiteReturnValue) {
2206
2231
  return createRootSuiteReturnValue
2207
2232
  }
@@ -2213,6 +2238,28 @@ function processRootSuite (createRootSuiteReturnValue) {
2213
2238
  }
2214
2239
 
2215
2240
  const allTests = rootSuite.allTests()
2241
+ const excludedSerialSuites = new Set()
2242
+ for (const test of allTests) {
2243
+ if (!getTestAnnotations(test.fn).noAutoRetry) continue
2244
+ for (let suite = test.parent; suite; suite = suite.parent) {
2245
+ if (suite._parallelMode === 'serial') excludedSerialSuites.add(suite)
2246
+ }
2247
+ }
2248
+ for (const test of allTests) {
2249
+ test._ddAssignedProperties = isTestManagementTestsEnabled
2250
+ ? testManagementTests?.playwright?.suites
2251
+ ?.[getTestSuitePath(test._requireFile, rootDir)]?.tests?.[getTestFullname(test)]?.properties
2252
+ : undefined
2253
+ test._ddIsAutomaticRetryExcluded = false
2254
+ const hasInjectedRetries = isFlakyTestRetriesEnabled && hasAutomaticRetries(test, sessionProjects)
2255
+ let excludeRetries = getTestAnnotations(test.fn).noAutoRetry
2256
+ // Serial retries need every prerequisite, so exclude the group from both ATR and EFD.
2257
+ for (let suite = test.parent; !excludeRetries && suite; suite = suite.parent) {
2258
+ excludeRetries = excludedSerialSuites.has(suite)
2259
+ }
2260
+ test._ddIsAutomaticRetryExcluded = excludeRetries
2261
+ if (hasInjectedRetries && excludeRetries) test.retries = 0
2262
+ }
2216
2263
 
2217
2264
  if (isTestManagementTestsEnabled) {
2218
2265
  const fileSuitesWithManagedTestsToProjects = new Map()
@@ -2271,7 +2318,8 @@ function processRootSuite (createRootSuiteReturnValue) {
2271
2318
  const fileSuitesWithImpactedTestsToProjects = new Map()
2272
2319
  for (const impactedTest of impactedTests) {
2273
2320
  impactedTest._ddIsModified = true
2274
- if (shouldRunEarlyFlakeDetection() && impactedTest.expectedStatus !== 'skipped' &&
2321
+ if (!impactedTest._ddIsAutomaticRetryExcluded &&
2322
+ shouldRunEarlyFlakeDetection() && impactedTest.expectedStatus !== 'skipped' &&
2275
2323
  !impactedTest._ddIsAttemptToFix) {
2276
2324
  // Prevent ATR or `--retries` from retrying tests that EFD manages.
2277
2325
  impactedTest.retries = 0
@@ -2285,7 +2333,7 @@ function processRootSuite (createRootSuiteReturnValue) {
2285
2333
  // If something changes in the file, all tests in the file are impacted, except attempt-to-fix tests managed above.
2286
2334
  applyRetriesToTests(
2287
2335
  fileSuitesWithImpactedTestsToProjects,
2288
- (test) => !test._ddIsAttemptToFix,
2336
+ (test) => !test._ddIsAttemptToFix && !test._ddIsAutomaticRetryExcluded,
2289
2337
  [
2290
2338
  '_ddIsModified',
2291
2339
  '_ddIsEfdRetry',
@@ -2318,7 +2366,8 @@ function processRootSuite (createRootSuiteReturnValue) {
2318
2366
  const fileSuitesWithNewTestsToProjects = new Map()
2319
2367
  for (const newTest of newTests) {
2320
2368
  newTest._ddIsNew = true
2321
- if (shouldRunEarlyFlakeDetection() && newTest.expectedStatus !== 'skipped' &&
2369
+ if (!newTest._ddIsAutomaticRetryExcluded &&
2370
+ shouldRunEarlyFlakeDetection() && newTest.expectedStatus !== 'skipped' &&
2322
2371
  !newTest._ddIsModified && !newTest._ddIsAttemptToFix) {
2323
2372
  // Prevent ATR or `--retries` from retrying tests that EFD manages.
2324
2373
  newTest.retries = 0
@@ -2332,7 +2381,7 @@ function processRootSuite (createRootSuiteReturnValue) {
2332
2381
 
2333
2382
  applyRetriesToTests(
2334
2383
  fileSuitesWithNewTestsToProjects,
2335
- (test) => !test._ddIsAttemptToFix && isNewTest(test),
2384
+ (test) => !test._ddIsAttemptToFix && !test._ddIsAutomaticRetryExcluded && isNewTest(test),
2336
2385
  [
2337
2386
  '_ddIsNew',
2338
2387
  '_ddIsEfdRetry',
@@ -2617,6 +2666,7 @@ function instrumentWorkerMainMethods (workerMain) {
2617
2666
  // Probably yet another test worker exporter is needed in addition to the ones for mocha, jest and cucumber
2618
2667
  // it's probably hard to tell that's a playwright worker though, as I don't think there is a specific env variable
2619
2668
  const testCtx = {
2669
+ extraTags: getExclusionTags(test),
2620
2670
  testName,
2621
2671
  testSuiteAbsolutePath,
2622
2672
  testSourceFileAbsolutePath,
@@ -2732,7 +2782,7 @@ function instrumentWorkerMainMethods (workerMain) {
2732
2782
  deferFinalStatus: test._ddDeferFinalStatus,
2733
2783
  steps: steps.filter(step => step.testId === testId),
2734
2784
  error,
2735
- extraTags: annotationTags,
2785
+ extraTags: { ...annotationTags, ...getExclusionTags(test) },
2736
2786
  isNew: test._ddIsNew,
2737
2787
  hasDynamicName: test._ddIsNew && DYNAMIC_NAME_RE.test(getTestFullname(test)),
2738
2788
  isRetry: retry > 0,
@@ -2769,6 +2819,8 @@ function instrumentWorkerMainMethods (workerMain) {
2769
2819
  } else if (event === 'stepEnd') {
2770
2820
  const stepInfo = stepInfoByStepId[payload.stepId]
2771
2821
  delete stepInfoByStepId[payload.stepId]
2822
+ if (!stepInfo) return dispatchEvent.apply(this, arguments)
2823
+
2772
2824
  steps.push({
2773
2825
  testId: stepInfo.testId,
2774
2826
  startTime: new Date(stepInfo.startTime),
@@ -2823,6 +2875,7 @@ function generateSummaryWrapper (generateSummary) {
2823
2875
 
2824
2876
  recordSkippedTestOptimizationExecution(test, testSuiteAbsolutePath)
2825
2877
  testSkipCh.publish({
2878
+ extraTags: getExclusionTags(test),
2826
2879
  testName: getTestFullname(test),
2827
2880
  testSuiteAbsolutePath,
2828
2881
  testSourceFileAbsolutePath,
@@ -0,0 +1,106 @@
1
+ 'use strict'
2
+
3
+ const { channel } = require('./helpers/instrument')
4
+
5
+ const deriveStartChannel = channel('tracing:orchestrion:react-router:derive:start')
6
+ const loaderStartChannel = channel('apm:react-router:loader:start')
7
+ const actionStartChannel = channel('apm:react-router:action:start')
8
+
9
+ /**
10
+ * @typedef {{ pattern?: string, unstable_pattern?: string }} RouteHandlerInfo
11
+ * @typedef {object} HandlerContext
12
+ * @property {string} routeId
13
+ * @property {string} [pattern]
14
+ * @property {(result: unknown, rejected: boolean) => void} [complete]
15
+ * @typedef {(callHandler: () => Promise<unknown>, info: RouteHandlerInfo) => Promise<unknown>} HandlerHook
16
+ * @typedef {{ loader: HandlerHook, action: HandlerHook }} RouteHooks
17
+ * @typedef {{ id: string, instrument: (hooks: RouteHooks) => void }} InstrumentableRoute
18
+ * @typedef {{ instrumentations?: object[], unstable_instrumentations?: object[] }} EntryModule
19
+ * @typedef {{ module?: EntryModule }} Entry
20
+ * @typedef {{ entry?: Entry }} ServerBuild
21
+ */
22
+
23
+ /**
24
+ * @param {() => Promise<unknown>} callHandler
25
+ * @param {RouteHandlerInfo} info
26
+ * @param {string} routeId
27
+ * @param {import('node:diagnostics_channel').Channel} startChannel
28
+ */
29
+ function callRouteHandler (callHandler, info, routeId, startChannel) {
30
+ if (!startChannel.hasSubscribers) return callHandler()
31
+
32
+ /** @type {HandlerContext} */
33
+ const context = {
34
+ routeId,
35
+ pattern: info?.pattern ?? info?.unstable_pattern,
36
+ complete: undefined,
37
+ }
38
+ const result = startChannel.runStores(context, callHandler)
39
+ const complete = context.complete
40
+ if (!complete) return result
41
+
42
+ return result.then(
43
+ value => {
44
+ complete(value, false)
45
+ return value
46
+ },
47
+ error => {
48
+ complete(error, true)
49
+ throw error
50
+ }
51
+ )
52
+ }
53
+
54
+ const datadogInstrumentation = {
55
+ /** @param {InstrumentableRoute} route */
56
+ route (route) {
57
+ const routeId = route.id
58
+ route.instrument({
59
+ /**
60
+ * @param {() => Promise<unknown>} callHandler
61
+ * @param {RouteHandlerInfo} info
62
+ */
63
+ loader (callHandler, info) {
64
+ return callRouteHandler(callHandler, info, routeId, loaderStartChannel)
65
+ },
66
+ /**
67
+ * @param {() => Promise<unknown>} callHandler
68
+ * @param {RouteHandlerInfo} info
69
+ */
70
+ action (callHandler, info) {
71
+ return callRouteHandler(callHandler, info, routeId, actionStartChannel)
72
+ },
73
+ })
74
+ },
75
+ }
76
+
77
+ /** @param {ServerBuild} build */
78
+ function injectInstrumentation (build) {
79
+ const entry = build?.entry
80
+ const entryModule = entry?.module
81
+ if (!entryModule || typeof entryModule !== 'object') return build
82
+
83
+ const stable = entryModule.instrumentations
84
+ const unstable = entryModule.unstable_instrumentations
85
+ return {
86
+ ...build,
87
+ entry: {
88
+ ...entry,
89
+ module: {
90
+ ...entryModule,
91
+ instrumentations: Array.isArray(stable) ? [datadogInstrumentation, ...stable] : [datadogInstrumentation],
92
+ unstable_instrumentations: Array.isArray(unstable)
93
+ ? [datadogInstrumentation, ...unstable]
94
+ : [datadogInstrumentation],
95
+ },
96
+ },
97
+ }
98
+ }
99
+
100
+ /** @param {unknown} message */
101
+ function onDeriveStart (message) {
102
+ const context = /** @type {{ arguments: ServerBuild[] }} */ (message)
103
+ context.arguments[0] = injectInstrumentation(context.arguments[0])
104
+ }
105
+
106
+ deriveStartChannel.subscribe(onDeriveStart)
@@ -0,0 +1,89 @@
1
+ 'use strict'
2
+
3
+ const { tracingChannel } = require('dc-polyfill')
4
+
5
+ const systemOneChannel = tracingChannel('orchestrion:@typesafe-ai/sdk:TypeSafeClient_systemOne')
6
+ const apiPromiseChannel = tracingChannel('orchestrion:@typesafe-ai/sdk:APIPromise_constructor')
7
+
8
+ const systemOneContexts = new WeakMap()
9
+
10
+ // `systemOne` returns its `APIPromise` without awaiting it, so the span finishes once the response arrives
11
+ systemOneChannel.end.subscribe(ctx => {
12
+ if (!systemOneChannel.start.hasSubscribers) return
13
+
14
+ // Copied like the SDK copies it, since the caller may change the object for its next call before this one finishes
15
+ const request = ctx.arguments[0]
16
+ if (request && typeof request === 'object') ctx.request = { ...request }
17
+
18
+ if (!ctx.error && ctx.result && typeof ctx.result === 'object') {
19
+ systemOneContexts.set(ctx.result, ctx)
20
+ } else {
21
+ finish(ctx)
22
+ }
23
+ })
24
+
25
+ // Every `APIPromise` method (awaiting, `asResponse()`, `withResponse()`, `map()`) reads the response promise passed to
26
+ // the constructor, so observing it covers each of them, and calls that are never awaited.
27
+ apiPromiseChannel.start.subscribe(ctx => {
28
+ const responsePromise = ctx.arguments[0]
29
+ if (!systemOneChannel.start.hasSubscribers || typeof responsePromise?.then !== 'function') return
30
+
31
+ ctx.arguments[0] = responsePromise.then(response => {
32
+ const systemOneCtx = systemOneContexts.get(ctx.self)
33
+ if (systemOneCtx) readResponse(systemOneCtx, response)
34
+ return response
35
+ }, error => {
36
+ const systemOneCtx = systemOneContexts.get(ctx.self)
37
+ if (systemOneCtx) finish(systemOneCtx, undefined, error)
38
+ throw error
39
+ })
40
+ })
41
+
42
+ /**
43
+ * Reads the body from a clone so the caller's response stays unread.
44
+ *
45
+ * @param {object} ctx
46
+ * @param {Response} response
47
+ */
48
+ function readResponse (ctx, response) {
49
+ try {
50
+ response.clone().text().then(body => {
51
+ ctx.responseText = body
52
+ finish(ctx, parseBody(body))
53
+ }, error => finish(ctx, undefined, error))
54
+ } catch (error) {
55
+ finish(ctx, undefined, error)
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Parses the body the way the SDK does: JSON when it parses, otherwise the text itself.
61
+ *
62
+ * @param {string} text
63
+ */
64
+ function parseBody (text) {
65
+ if (text.length === 0) return
66
+ try {
67
+ return JSON.parse(text)
68
+ } catch {
69
+ return text
70
+ }
71
+ }
72
+
73
+ /**
74
+ * @param {object} ctx
75
+ * @param {unknown} [result]
76
+ * @param {Error} [error]
77
+ */
78
+ function finish (ctx, result, error) {
79
+ if (ctx.finished) return
80
+ ctx.finished = true
81
+
82
+ if (error) {
83
+ ctx.error = error
84
+ systemOneChannel.error.publish(ctx)
85
+ }
86
+
87
+ ctx.result = result
88
+ systemOneChannel.asyncEnd.publish(ctx)
89
+ }