dd-trace 6.23.0 → 6.24.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
@@ -1,8 +1,6 @@
1
1
  'use strict'
2
2
 
3
3
  const getConfig = require('../../config')
4
- const { EVP_SUBDOMAIN_HEADER_NAME } = require('../../evp_proxy/constants')
5
- const { joinEVPProxyPath } = require('../../evp_proxy/path')
6
4
  const log = require('../../log')
7
5
  const {
8
6
  incrementCountMetric,
@@ -15,6 +13,7 @@ const {
15
13
  TELEMETRY_ITR_SKIPPABLE_TESTS_RESPONSE_BYTES,
16
14
  } = require('../../ci-visibility/telemetry')
17
15
  const request = require('../requests/request')
16
+ const { createApiRequestRoute } = require('../requests/route')
18
17
  const { buildCacheKey, writeToCache, withCache } = require('../requests/fs-cache')
19
18
  const { validateSkippableTestsResponse } = require('../test-optimization-http-cache-schema')
20
19
 
@@ -213,32 +212,26 @@ function fetchFromApi ({
213
212
  isLineCoverageSupported,
214
213
  cacheKey,
215
214
  }, done) {
215
+ const path = '/api/v2/ci/tests/skippable'
216
+ const route = createApiRequestRoute(getConfig(), { url, path, isEvpProxy, evpProxyPrefix })
217
+ if (!route) {
218
+ return done(new Error('Skippable suites were not fetched because Datadog API key is not defined.'))
219
+ }
220
+
216
221
  const options = {
217
- path: '/api/v2/ci/tests/skippable',
222
+ ...route,
218
223
  method: 'POST',
219
224
  headers: {
225
+ ...route.headers,
220
226
  'Content-Type': 'application/json',
221
227
  },
222
228
  timeout: 20_000,
223
- url,
224
229
  }
225
230
 
226
231
  if (isGzipCompatible) {
227
232
  options.headers['accept-encoding'] = 'gzip'
228
233
  }
229
234
 
230
- if (isEvpProxy) {
231
- options.path = joinEVPProxyPath(evpProxyPrefix, '/api/v2/ci/tests/skippable')
232
- options.headers[EVP_SUBDOMAIN_HEADER_NAME] = 'api'
233
- } else {
234
- const { DD_API_KEY } = getConfig()
235
- if (!DD_API_KEY) {
236
- return done(new Error('Skippable suites were not fetched because Datadog API key is not defined.'))
237
- }
238
-
239
- options.headers['dd-api-key'] = DD_API_KEY
240
- }
241
-
242
235
  const data = JSON.stringify({
243
236
  data: {
244
237
  type: 'test_params',
@@ -1,8 +1,6 @@
1
1
  'use strict'
2
2
 
3
3
  const getConfig = require('../../config')
4
- const { EVP_SUBDOMAIN_HEADER_NAME } = require('../../evp_proxy/constants')
5
- const { joinEVPProxyPath } = require('../../evp_proxy/path')
6
4
  const id = require('../../id')
7
5
  const log = require('../../log')
8
6
  const { EARLY_FLAKE_DETECTION_RETRY_BUCKETS, createEfdRetryPolicy } = require('../efd-retry-policy')
@@ -16,6 +14,7 @@ const {
16
14
  } = require('../telemetry')
17
15
  const { MAX_RETRIES, validateSettingsResponse } = require('../test-optimization-http-cache-schema')
18
16
  const request = require('./request')
17
+ const { createApiRequestRoute } = require('./route')
19
18
 
20
19
  const DEFAULT_EARLY_FLAKE_DETECTION_SLOW_TEST_RETRIES = Object.freeze({
21
20
  '5s': 10,
@@ -228,26 +227,22 @@ function getLibraryConfiguration ({
228
227
  tag,
229
228
  }, done) {
230
229
  const config = getConfig()
230
+ const path = '/api/v2/libraries/tests/services/setting'
231
+ const route = createApiRequestRoute(config, { url, path, isEvpProxy, evpProxyPrefix })
232
+ if (!route) {
233
+ return done(new Error('Request to settings endpoint was not done because Datadog API key is not defined.'))
234
+ }
235
+
231
236
  const options = {
232
- path: '/api/v2/libraries/tests/services/setting',
237
+ ...route,
233
238
  method: 'POST',
234
239
  headers: {
240
+ ...route.headers,
235
241
  'Content-Type': 'application/json',
236
242
  },
237
- url,
238
243
  timeout: 20_000,
239
244
  }
240
245
 
241
- if (isEvpProxy) {
242
- options.path = joinEVPProxyPath(evpProxyPrefix, '/api/v2/libraries/tests/services/setting')
243
- options.headers[EVP_SUBDOMAIN_HEADER_NAME] = 'api'
244
- } else {
245
- if (!config.DD_API_KEY) {
246
- return done(new Error('Request to settings endpoint was not done because Datadog API key is not defined.'))
247
- }
248
- options.headers['dd-api-key'] = config.DD_API_KEY
249
- }
250
-
251
246
  const data = JSON.stringify({
252
247
  data: {
253
248
  id: id().toString(10),
@@ -0,0 +1,44 @@
1
+ 'use strict'
2
+
3
+ const { EVP_SUBDOMAIN_HEADER_NAME } = require('../../evp_proxy/constants')
4
+ const { joinEVPProxyPath } = require('../../evp_proxy/path')
5
+
6
+ /**
7
+ * @typedef {object} ApiRequestRouteOptions
8
+ * @property {URL} url
9
+ * @property {string} path
10
+ * @property {boolean} isEvpProxy
11
+ * @property {string} evpProxyPrefix
12
+ */
13
+
14
+ /**
15
+ * @typedef {object} ApiRequestRoute
16
+ * @property {URL} url
17
+ * @property {string} path
18
+ * @property {Record<string, string>} headers
19
+ */
20
+
21
+ /**
22
+ * @param {import('../../config/config-base')} config
23
+ * @param {ApiRequestRouteOptions} options
24
+ * @returns {ApiRequestRoute|undefined}
25
+ */
26
+ function createApiRequestRoute (config, { url, path, isEvpProxy, evpProxyPrefix }) {
27
+ if (isEvpProxy) {
28
+ return {
29
+ url,
30
+ path: joinEVPProxyPath(evpProxyPrefix, path),
31
+ headers: { [EVP_SUBDOMAIN_HEADER_NAME]: 'api' },
32
+ }
33
+ }
34
+
35
+ if (config.DD_API_KEY === undefined) return
36
+
37
+ return {
38
+ url,
39
+ path,
40
+ headers: { 'dd-api-key': config.DD_API_KEY },
41
+ }
42
+ }
43
+
44
+ module.exports = { createApiRequestRoute }
@@ -0,0 +1,5 @@
1
+ 'use strict'
2
+
3
+ module.exports = {
4
+ tags: 'test_optimization_enabled:true',
5
+ }
@@ -0,0 +1,72 @@
1
+ 'use strict'
2
+
3
+ // Symbols cross Jest's VM/module-registry boundary without initializing the tracer.
4
+ const annotationsKey = Symbol.for('dd-trace:test-annotations')
5
+ /** @type {{ mustFail: boolean, noAutoRetry: boolean, source?: Function }} */
6
+ const emptyAnnotations = Object.freeze({ mustFail: false, noAutoRetry: false })
7
+
8
+ /** @param {Function|undefined} fn */
9
+ function getTestAnnotations (fn) {
10
+ return (fn && fn[annotationsKey]) || emptyAnnotations
11
+ }
12
+
13
+ /**
14
+ * @param {Function|undefined} source
15
+ * @param {Function} target
16
+ */
17
+ function copyTestAnnotations (source, target) {
18
+ const annotations = source && source[annotationsKey]
19
+ if (annotations && target[annotationsKey] !== annotations) {
20
+ Object.defineProperty(target, annotationsKey, { value: annotations, configurable: true })
21
+ }
22
+ }
23
+
24
+ /**
25
+ * @template {Function} T
26
+ * @param {T} fn
27
+ * @param {'mustFail'|'noAutoRetry'} annotation
28
+ * @returns {T}
29
+ */
30
+ function annotate (fn, annotation) {
31
+ if (typeof fn !== 'function') throw new TypeError('Test annotations require a test callback')
32
+ const inherited = getTestAnnotations(fn)
33
+ const annotated = function (...args) {
34
+ return fn.apply(this, args)
35
+ }
36
+ Object.setPrototypeOf(annotated, Object.getPrototypeOf(fn))
37
+ Object.defineProperties(annotated, {
38
+ toString: { value: () => fn.toString(), writable: true, configurable: true },
39
+ ...Object.getOwnPropertyDescriptors(fn),
40
+ length: { value: fn.length },
41
+ name: { value: fn.name },
42
+ [annotationsKey]: {
43
+ value: Object.freeze({
44
+ ...inherited,
45
+ [annotation]: true,
46
+ source: inherited.source || fn,
47
+ }),
48
+ },
49
+ })
50
+ if (Object.isFrozen(fn)) Object.freeze(annotated)
51
+ return /** @type {T} */ (/** @type {unknown} */ (annotated))
52
+ }
53
+
54
+ /**
55
+ * @template {Function} T
56
+ * @param {T} fn
57
+ * @returns {T}
58
+ */
59
+ function preventFailureSuppression (fn) {
60
+ return annotate(fn, 'mustFail')
61
+ }
62
+
63
+ /**
64
+ * @template {Function} T
65
+ * @param {T} fn
66
+ * @returns {T}
67
+ */
68
+ function noAutoRetry (fn) {
69
+ return annotate(fn, 'noAutoRetry')
70
+ }
71
+
72
+ module.exports = { preventFailureSuppression, noAutoRetry, getTestAnnotations, copyTestAnnotations }
@@ -0,0 +1,170 @@
1
+ 'use strict'
2
+
3
+ const declarationMethods = new Set([
4
+ 'concurrent', 'sequential', 'shuffle', 'skip', 'only', 'todo', 'fails', 'each', 'for', 'extend',
5
+ 'skipIf', 'runIf', 'describe', 'suite',
6
+ ])
7
+ const wrappedDeclarations = new WeakMap()
8
+ const capturedCollectors = new WeakSet()
9
+ const declarationFactories = ['each', 'for', 'extend', 'skipIf', 'runIf']
10
+ let captureLocations = false
11
+
12
+ /**
13
+ * @typedef {{
14
+ * type: 'collector', test: Function & { fn: Function }, tasks: object[], options?: { retry?: unknown }
15
+ * }} Collector
16
+ */
17
+
18
+ /**
19
+ * @param {Function & { fn: Function }} test
20
+ * @param {() => Collector} getCurrentSuite
21
+ */
22
+ function captureDeclarations (test, getCurrentSuite) {
23
+ // The setup-based main-process reporter requests declaration locations.
24
+ captureLocations = true
25
+ captureFactories(test, getCurrentSuite)
26
+ captureCollector(getCurrentSuite())
27
+ }
28
+
29
+ /**
30
+ * @param {Function & { fn: Function }} test
31
+ * @param {() => Collector} getCurrentSuite
32
+ */
33
+ function captureFactories (test, getCurrentSuite) {
34
+ for (const target of [test, test.fn]) {
35
+ for (const method of declarationFactories) {
36
+ if (typeof target[method] === 'function') target[method] = wrapDeclaration(target[method], getCurrentSuite)
37
+ }
38
+ }
39
+ }
40
+
41
+ /** @param {Collector} collector */
42
+ function captureCollector (collector) {
43
+ if (capturedCollectors.has(collector)) return
44
+ capturedCollectors.add(collector)
45
+
46
+ const getCollector = () => collector
47
+ const declaration = collector.test.fn
48
+ const wrapped = wrapDeclaration(declaration, getCollector)
49
+ captureFactories(collector.test, getCollector)
50
+ // Vitest's exported test dispatches through .fn.call; suite-local chains close over .fn and use .apply.
51
+ // Native bindings avoid an extra stack frame inside Vitest's bounded declaration-location capture.
52
+ Object.defineProperties(declaration, {
53
+ call: {
54
+ value: Function.prototype.call.bind(wrapped),
55
+ writable: true,
56
+ configurable: true,
57
+ },
58
+ apply: {
59
+ value: Function.prototype.apply.bind(wrapped),
60
+ writable: true,
61
+ configurable: true,
62
+ },
63
+ })
64
+ const push = collector.tasks.push
65
+ collector.tasks.push = function (...tasks) {
66
+ for (const task of tasks) {
67
+ if (task.type === 'collector') captureCollector(task)
68
+ else if (captureLocations && task.type === 'test' && !task.location) {
69
+ const location = getDeclarationLocation(task.file?.filepath)
70
+ if (location) task.location = location
71
+ }
72
+ }
73
+ return push.apply(this, tasks)
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Captures declaration metadata before Vitest replaces callbacks for fixtures, timeouts and parameterized cases.
79
+ *
80
+ * @param {Function} declaration
81
+ * @param {() => Collector} getCurrentSuite
82
+ */
83
+ function wrapDeclaration (declaration, getCurrentSuite) {
84
+ if (wrappedDeclarations.has(declaration)) return wrappedDeclarations.get(declaration)
85
+ const wrapped = new Proxy(declaration, {
86
+ apply (target, receiver, args) {
87
+ const collector = getCurrentSuite()
88
+ captureCollector(collector)
89
+ let annotations
90
+ let options
91
+ for (let index = 1; index < args.length; index++) {
92
+ const argument = args[index]
93
+ if (typeof argument === 'function') {
94
+ const observed = argument[Symbol.for('dd-trace:test-annotations')] || {}
95
+ if (observed.mustFail || observed.noAutoRetry) annotations = observed
96
+ } else if (argument && typeof argument === 'object') {
97
+ options = argument
98
+ }
99
+ }
100
+ const hasFrameworkRetry = options?.retry !== undefined || collector.options?.retry !== undefined
101
+ if (!annotations && !hasFrameworkRetry) {
102
+ const result = Reflect.apply(target, receiver, args)
103
+ return typeof result === 'function' ? wrapDeclaration(result, getCurrentSuite) : result
104
+ }
105
+ const firstTask = collector.tasks.length
106
+ const result = Reflect.apply(target, receiver, args)
107
+ for (let index = firstTask; index < collector.tasks.length; index++) {
108
+ const task = collector.tasks[index]
109
+ if (task.type !== 'test') continue
110
+ if (hasFrameworkRetry) task.meta = { ...task.meta, __ddTestOptNativeRetry: true }
111
+ if (annotations) {
112
+ task.meta = {
113
+ ...task.meta,
114
+ __ddTestOptAnnotations: {
115
+ mustFail: annotations.mustFail,
116
+ noAutoRetry: annotations.noAutoRetry,
117
+ hasFrameworkRetry: hasFrameworkRetry || task.meta?.__ddTestOptHasFrameworkRetry === true,
118
+ },
119
+ }
120
+ }
121
+ }
122
+ return typeof result === 'function' ? wrapDeclaration(result, getCurrentSuite) : result
123
+ },
124
+ get (target, property, receiver) {
125
+ const value = Reflect.get(target, property, receiver)
126
+ return declarationMethods.has(property) && typeof value === 'function'
127
+ ? wrapDeclaration(value, getCurrentSuite)
128
+ : value
129
+ },
130
+ })
131
+ wrappedDeclarations.set(wrapped, wrapped)
132
+ wrappedDeclarations.set(declaration, wrapped)
133
+ return wrapped
134
+ }
135
+
136
+ /**
137
+ * @param {string|undefined} filepath
138
+ * @returns {{ line: number, column: number }|undefined}
139
+ */
140
+ function getDeclarationLocation (filepath) {
141
+ if (!filepath) return
142
+ try {
143
+ const limit = Error.stackTraceLimit
144
+ let error
145
+ try {
146
+ // Vitest's ten-frame budget can omit callers behind generated declarations and fixture chains.
147
+ Error.stackTraceLimit = 25
148
+ error = new Error('Datadog Vitest declaration')
149
+ } finally {
150
+ Error.stackTraceLimit = limit
151
+ }
152
+ if (typeof error.stack !== 'string') return
153
+ for (let frame of error.stack.split('\n')) {
154
+ if (!frame.includes(filepath)) {
155
+ try { frame = decodeURIComponent(frame) } catch { continue }
156
+ }
157
+ const start = frame.lastIndexOf(filepath)
158
+ if (start === -1) continue
159
+ const location = frame.slice(start + filepath.length).match(/^(?:[?#].*?)?:(\d+):(\d+)\)?$/)
160
+ if (location) return { line: Number(location[1]), column: Number(location[2]) }
161
+ }
162
+ } catch {}
163
+ }
164
+
165
+ // Browser Mode serves this dependency as ESM without CommonJS conversion in independent projects.
166
+ if (typeof module === 'undefined') {
167
+ globalThis[Symbol.for('dd-trace.vitest.declaration-annotations')] = { captureDeclarations }
168
+ } else {
169
+ module.exports = { wrapDeclaration, captureDeclarations }
170
+ }
@@ -1,8 +1,6 @@
1
1
  'use strict'
2
2
 
3
3
  const getConfig = require('../../config')
4
- const { EVP_SUBDOMAIN_HEADER_NAME } = require('../../evp_proxy/constants')
5
- const { joinEVPProxyPath } = require('../../evp_proxy/path')
6
4
  const id = require('../../id')
7
5
  const log = require('../../log')
8
6
  const {
@@ -15,6 +13,7 @@ const {
15
13
  TELEMETRY_TEST_MANAGEMENT_TESTS_RESPONSE_BYTES,
16
14
  } = require('../telemetry')
17
15
  const request = require('../requests/request')
16
+ const { createApiRequestRoute } = require('../requests/route')
18
17
  const { buildCacheKey, writeToCache, withCache } = require('../requests/fs-cache')
19
18
  const { validateTestManagementTestsResponse } = require('../test-optimization-http-cache-schema')
20
19
 
@@ -117,32 +116,26 @@ function fetchFromApi ({
117
116
  branch,
118
117
  cacheKey,
119
118
  }, done) {
119
+ const path = '/api/v2/test/libraries/test-management/tests'
120
+ const route = createApiRequestRoute(getConfig(), { url, path, isEvpProxy, evpProxyPrefix })
121
+ if (!route) {
122
+ return done(new Error('Test management tests were not fetched because Datadog API key is not defined.'))
123
+ }
124
+
120
125
  const options = {
121
- path: '/api/v2/test/libraries/test-management/tests',
126
+ ...route,
122
127
  method: 'POST',
123
128
  headers: {
129
+ ...route.headers,
124
130
  'Content-Type': 'application/json',
125
131
  },
126
132
  timeout: 20_000,
127
- url,
128
133
  }
129
134
 
130
135
  if (isGzipCompatible) {
131
136
  options.headers['accept-encoding'] = 'gzip'
132
137
  }
133
138
 
134
- if (isEvpProxy) {
135
- options.path = joinEVPProxyPath(evpProxyPrefix, '/api/v2/test/libraries/test-management/tests')
136
- options.headers[EVP_SUBDOMAIN_HEADER_NAME] = 'api'
137
- } else {
138
- const { DD_API_KEY } = getConfig()
139
- if (!DD_API_KEY) {
140
- return done(new Error('Test management tests were not fetched because Datadog API key is not defined.'))
141
- }
142
-
143
- options.headers['dd-api-key'] = DD_API_KEY
144
- }
145
-
146
139
  const data = JSON.stringify({
147
140
  data: {
148
141
  id: id().toString(10),
@@ -36,12 +36,13 @@ const parseErrors = new Map()
36
36
  */
37
37
  function warnInvalidValue (value, optionName, source, baseMessage, error, outcome = 'picked default') {
38
38
  const canonicalName = optionsTable[optionName]?.canonicalName ?? optionName
39
+ const displayValue = sensitiveConfigurations.has(canonicalName) ? '<redacted>' : value
39
40
  const telemetryKey = canonicalName + source
40
41
  const telemetryEntry = configWithOrigin.get(telemetryKey)
41
42
  // Lazy load log module to avoid circular dependency
42
43
  if (!parseErrors.has(telemetryKey) && !telemetryEntry?.error) {
43
44
  // TODO: Report the prior source when an invalid value does not use the default.
44
- let message = `${baseMessage}: ${util.inspect(value)} for ${optionName} (source: ${source})`
45
+ let message = `${baseMessage}: ${util.inspect(displayValue)} for ${optionName} (source: ${source})`
45
46
  if (outcome) message += `, ${outcome}`
46
47
  if (error) {
47
48
  error.stack = error.toString()
@@ -69,10 +70,10 @@ const defaults = {
69
70
  logger: undefined,
70
71
  }
71
72
 
72
- for (const [name, value] of Object.entries(defaults)) {
73
+ for (const [name, value = null] of Object.entries(defaults)) {
73
74
  configWithOrigin.set(`${name}default`, {
74
75
  name,
75
- value: value ?? null,
76
+ value,
76
77
  origin: 'default',
77
78
  seq_id: seqId++,
78
79
  })
@@ -381,6 +381,7 @@ export interface GeneratedConfig {
381
381
  DD_TRACE_Q_ENABLED: boolean;
382
382
  DD_TRACE_REACT_DOM_ENABLED: boolean;
383
383
  DD_TRACE_REACT_ENABLED: boolean;
384
+ DD_TRACE_REACT_ROUTER_ENABLED: boolean;
384
385
  DD_TRACE_REDIS_CLIENT_ENABLED: boolean;
385
386
  DD_TRACE_REDIS_ENABLED: boolean;
386
387
  DD_TRACE_REQUEST_ENABLED: boolean;
@@ -400,6 +401,7 @@ export interface GeneratedConfig {
400
401
  DD_TRACE_SUPABASE_ENABLED: boolean;
401
402
  DD_TRACE_TAGS: Record<string, string> | undefined;
402
403
  DD_TRACE_TEDIOUS_ENABLED: boolean;
404
+ DD_TRACE_TYPESAFE_ENABLED: boolean;
403
405
  DD_TRACE_UNDICI_ENABLED: boolean;
404
406
  DD_TRACE_URL_ENABLED: boolean;
405
407
  DD_TRACE_VITEST_ENABLED: boolean;
@@ -1107,6 +1109,7 @@ export interface GeneratedEnvVarConfig {
1107
1109
  DD_TRACE_RATE_LIMIT: number;
1108
1110
  DD_TRACE_REACT_DOM_ENABLED: boolean;
1109
1111
  DD_TRACE_REACT_ENABLED: boolean;
1112
+ DD_TRACE_REACT_ROUTER_ENABLED: boolean;
1110
1113
  DD_TRACE_REDIS_CLIENT_ENABLED: boolean;
1111
1114
  DD_TRACE_REDIS_ENABLED: boolean;
1112
1115
  DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED: boolean;
@@ -1134,6 +1137,7 @@ export interface GeneratedEnvVarConfig {
1134
1137
  DD_TRACE_TAGS: Record<string, string> | undefined;
1135
1138
  DD_TRACE_TEDIOUS_ENABLED: boolean;
1136
1139
  DD_TRACE_TELEMETRY_ENABLED: boolean;
1140
+ DD_TRACE_TYPESAFE_ENABLED: boolean;
1137
1141
  DD_TRACE_UNDICI_ENABLED: boolean;
1138
1142
  DD_TRACE_URL: string | URL;
1139
1143
  DD_TRACE_URL_ENABLED: boolean;