dd-trace 6.22.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 (194) 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 -5
  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 +35 -5
  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 +23 -20
  31. package/packages/datadog-core/src/storage.js +1 -1
  32. package/packages/datadog-esbuild/index.js +70 -7
  33. package/packages/datadog-instrumentations/index.js +2 -1
  34. package/packages/datadog-instrumentations/src/cucumber.js +64 -21
  35. package/packages/datadog-instrumentations/src/cypress-config.js +163 -15
  36. package/packages/datadog-instrumentations/src/graphql.js +9 -3
  37. package/packages/datadog-instrumentations/src/grpc/server.js +23 -6
  38. package/packages/datadog-instrumentations/src/helpers/bundler-register.js +27 -8
  39. package/packages/datadog-instrumentations/src/helpers/fetch.js +5 -1
  40. package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +30 -8
  41. package/packages/datadog-instrumentations/src/helpers/hooks.js +2 -1
  42. package/packages/datadog-instrumentations/src/helpers/register.js +9 -0
  43. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +16 -6
  44. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +10 -0
  45. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +3 -1
  46. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/jest.js +12 -0
  47. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/react-router.js +49 -0
  48. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/typesafe.js +23 -0
  49. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/vitest.js +8 -0
  50. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +12 -0
  51. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +8 -0
  52. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +19 -2
  53. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +13 -0
  54. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +1 -1
  55. package/packages/datadog-instrumentations/src/jest.js +332 -137
  56. package/packages/datadog-instrumentations/src/mariadb-bundle.js +69 -11
  57. package/packages/datadog-instrumentations/src/mariadb.js +13 -6
  58. package/packages/datadog-instrumentations/src/mocha/common.js +89 -8
  59. package/packages/datadog-instrumentations/src/mocha/main.js +11 -2
  60. package/packages/datadog-instrumentations/src/mocha/utils.js +92 -13
  61. package/packages/datadog-instrumentations/src/mocha/worker.js +1 -1
  62. package/packages/datadog-instrumentations/src/nova-sonic/session.js +25 -16
  63. package/packages/datadog-instrumentations/src/oracledb.js +33 -0
  64. package/packages/datadog-instrumentations/src/pg.js +2 -1
  65. package/packages/datadog-instrumentations/src/playwright.js +81 -26
  66. package/packages/datadog-instrumentations/src/react-router.js +106 -0
  67. package/packages/datadog-instrumentations/src/stripe.js +23 -12
  68. package/packages/datadog-instrumentations/src/typesafe.js +89 -0
  69. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +84 -47
  70. package/packages/datadog-instrumentations/src/vitest-main.js +33 -3
  71. package/packages/datadog-instrumentations/src/vitest-test-annotations.js +20 -0
  72. package/packages/datadog-instrumentations/src/vitest-util.js +5 -2
  73. package/packages/datadog-instrumentations/src/vitest-worker.js +39 -17
  74. package/packages/datadog-instrumentations/src/vitest.js +16 -6
  75. package/packages/datadog-plugin-cucumber/src/index.js +5 -0
  76. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +277 -44
  77. package/packages/datadog-plugin-cypress/src/index.js +1 -1
  78. package/packages/datadog-plugin-cypress/src/lifecycle-owner.js +20 -0
  79. package/packages/datadog-plugin-cypress/src/plugin.js +10 -0
  80. package/packages/datadog-plugin-cypress/src/retry-config-observer.js +281 -0
  81. package/packages/datadog-plugin-cypress/src/setup-handoff.js +125 -0
  82. package/packages/datadog-plugin-cypress/src/support.js +1217 -437
  83. package/packages/datadog-plugin-graphql/src/execute.js +2 -2
  84. package/packages/datadog-plugin-graphql/src/utils.js +5 -5
  85. package/packages/datadog-plugin-jest/src/index.js +25 -3
  86. package/packages/datadog-plugin-mocha/src/index.js +47 -6
  87. package/packages/datadog-plugin-oracledb/src/connection-parser.js +21 -11
  88. package/packages/datadog-plugin-playwright/src/index.js +4 -0
  89. package/packages/datadog-plugin-react-router/src/index.js +118 -0
  90. package/packages/datadog-plugin-typesafe/src/index.js +17 -0
  91. package/packages/datadog-plugin-typesafe/src/tracing.js +31 -0
  92. package/packages/datadog-plugin-vitest/src/index.js +8 -0
  93. package/packages/dd-trace/src/agent/info.js +2 -1
  94. package/packages/dd-trace/src/aiguard/evaluation.js +143 -1
  95. package/packages/dd-trace/src/aiguard/sdk.js +0 -11
  96. package/packages/dd-trace/src/appsec/iast/path-line.js +2 -1
  97. package/packages/dd-trace/src/appsec/stack_trace.js +3 -2
  98. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +3 -2
  99. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +9 -16
  100. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +4 -2
  101. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +9 -16
  102. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +9 -14
  103. package/packages/dd-trace/src/ci-visibility/requests/route.js +44 -0
  104. package/packages/dd-trace/src/ci-visibility/telemetry-logs.js +5 -0
  105. package/packages/dd-trace/src/ci-visibility/test-annotations.js +72 -0
  106. package/packages/dd-trace/src/ci-visibility/test-declaration-annotations.js +170 -0
  107. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +9 -16
  108. package/packages/dd-trace/src/config/defaults.js +4 -3
  109. package/packages/dd-trace/src/config/generated-config-types.d.ts +6 -0
  110. package/packages/dd-trace/src/config/index.js +140 -39
  111. package/packages/dd-trace/src/config/parsers.js +9 -1
  112. package/packages/dd-trace/src/config/supported-configurations.json +25 -0
  113. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +6 -5
  114. package/packages/dd-trace/src/debugger/devtools_client/condition.js +5 -5
  115. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +4 -6
  116. package/packages/dd-trace/src/debugger/probe_sampler.js +6 -6
  117. package/packages/dd-trace/src/debugger/unsupported-runtime.js +16 -0
  118. package/packages/dd-trace/src/encode/0.4.js +2 -2
  119. package/packages/dd-trace/src/esm-module-load.js +58 -0
  120. package/packages/dd-trace/src/exporter.js +25 -6
  121. package/packages/dd-trace/src/exporters/agent/index.js +3 -1
  122. package/packages/dd-trace/src/exporters/agentless/index.js +3 -1
  123. package/packages/dd-trace/src/exporters/common/request.js +4 -4
  124. package/packages/dd-trace/src/exporters/llmobs/index.js +135 -0
  125. package/packages/dd-trace/src/exporters/log/index.js +4 -3
  126. package/packages/dd-trace/src/llmobs/agent-manifest.js +19 -2
  127. package/packages/dd-trace/src/llmobs/constants/tags.js +4 -0
  128. package/packages/dd-trace/src/llmobs/experiments/index.js +2 -3
  129. package/packages/dd-trace/src/llmobs/experiments/noop.js +5 -2
  130. package/packages/dd-trace/src/llmobs/index.js +13 -2
  131. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +1 -1
  132. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
  133. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +8 -4
  134. package/packages/dd-trace/src/llmobs/plugins/openai/constants.js +5 -0
  135. package/packages/dd-trace/src/llmobs/plugins/openai/index.js +9 -1
  136. package/packages/dd-trace/src/llmobs/plugins/typesafe/index.js +102 -0
  137. package/packages/dd-trace/src/llmobs/prompts/cache.js +3 -1
  138. package/packages/dd-trace/src/llmobs/sdk.js +17 -5
  139. package/packages/dd-trace/src/llmobs/span_processor.js +222 -12
  140. package/packages/dd-trace/src/llmobs/tagger.js +21 -8
  141. package/packages/dd-trace/src/llmobs/util.js +10 -4
  142. package/packages/dd-trace/src/llmobs/writers/util.js +3 -3
  143. package/packages/dd-trace/src/log/writer.js +7 -1
  144. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +64 -6
  145. package/packages/dd-trace/src/openfeature/configuration_source.js +18 -2
  146. package/packages/dd-trace/src/openfeature/debug-logging-hook.js +66 -3
  147. package/packages/dd-trace/src/openfeature/exposure-hook.js +185 -0
  148. package/packages/dd-trace/src/openfeature/flagging_provider.js +39 -13
  149. package/packages/dd-trace/src/openfeature/index.js +6 -0
  150. package/packages/dd-trace/src/openfeature/remote_config.js +16 -3
  151. package/packages/dd-trace/src/openfeature/writers/base.js +62 -27
  152. package/packages/dd-trace/src/openfeature/writers/exposures.js +161 -1
  153. package/packages/dd-trace/src/openfeature/writers/flag-eval-evp-hook.js +5 -0
  154. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-aggregation.js +9 -4
  155. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-payload.js +2 -0
  156. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-pii.js +2 -0
  157. package/packages/dd-trace/src/openfeature/writers/split-features.js +25 -0
  158. package/packages/dd-trace/src/openfeature/writers/util.js +4 -4
  159. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -2
  160. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +18 -1
  161. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +5 -1
  162. package/packages/dd-trace/src/opentracing/tracer.js +9 -13
  163. package/packages/dd-trace/src/otel-thread-ctx.js +47 -21
  164. package/packages/dd-trace/src/plugin_manager.js +1 -2
  165. package/packages/dd-trace/src/plugins/ci_plugin.js +4 -4
  166. package/packages/dd-trace/src/plugins/index.js +3 -0
  167. package/packages/dd-trace/src/plugins/tracing.js +1 -2
  168. package/packages/dd-trace/src/plugins/util/git.js +102 -40
  169. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +2 -4
  170. package/packages/dd-trace/src/plugins/util/stacktrace.js +2 -1
  171. package/packages/dd-trace/src/plugins/util/test.js +28 -6
  172. package/packages/dd-trace/src/plugins/util/web.js +106 -20
  173. package/packages/dd-trace/src/process-tags/index.js +1 -1
  174. package/packages/dd-trace/src/profiling/config.js +6 -3
  175. package/packages/dd-trace/src/proxy.js +15 -4
  176. package/packages/dd-trace/src/serverless.js +3 -2
  177. package/packages/dd-trace/src/span_processor.js +21 -9
  178. package/packages/dd-trace/src/span_stats.js +32 -3
  179. package/packages/dd-trace/src/startup-log.js +2 -1
  180. package/packages/dd-trace/src/tagger.js +7 -5
  181. package/packages/dd-trace/src/telemetry/dependencies.js +4 -0
  182. package/packages/dd-trace/src/telemetry/index.js +3 -0
  183. package/packages/dd-trace/src/telemetry/logs/index.js +21 -2
  184. package/packages/dd-trace/src/telemetry/logs/log-collector.js +2 -1
  185. package/packages/dd-trace/src/telemetry/telemetry.js +10 -3
  186. package/packages/dd-trace/src/util.js +9 -5
  187. package/register.js +2 -1
  188. package/vendor/dist/@apm-js-collab/code-transformer/index.js +8 -8
  189. package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
  190. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.d.ts +78 -0
  191. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.js +1 -1
  192. package/vendor/dist/@opentelemetry/core/index.js +1 -1
  193. package/vendor/dist/@opentelemetry/resources/LICENSE +0 -201
  194. package/vendor/dist/@opentelemetry/resources/index.js +0 -1
@@ -4,7 +4,7 @@ const Module = require('module')
4
4
  const dc = require('dc-polyfill')
5
5
 
6
6
  const log = require('../../../dd-trace/src/log')
7
- const { activate, loadChannel } = require('./register.js')
7
+ const { activate, loadChannel, registeredBuiltinNames } = require('./register.js')
8
8
  const {
9
9
  filename,
10
10
  getDisabledInstrumentations,
@@ -17,25 +17,44 @@ const { isRewriteActivationEnabled } = require('./rewriter/targets')
17
17
  const disabledInstrumentations = getDisabledInstrumentations()
18
18
 
19
19
  // register.js has now set up ritm (require-in-the-middle). In bundled
20
- // environments (webpack, esbuild), Node.js built-in modules required by
21
- // dd-trace internal modules (e.g. http from request.js) may have been loaded
22
- // before ritm was active. The bundler's module cache then returns those
23
- // pre-loaded modules for any subsequent require() calls, bypassing ritm.
24
- // Re-requiring them via the real Module.prototype.require ensures ritm applies
25
- // their instrumentation hooks.
20
+ // environments (webpack, esbuild, Turbopack), Node.js built-ins required by the
21
+ // application or by dd-trace itself may have been loaded and cached by the
22
+ // bundle before ritm was active, bypassing it. Re-requiring them via the real
23
+ // Module.prototype.require lets ritm apply their hooks to the shared exports.
26
24
  //
27
25
  // In regular Node.js, `module` is an instance of Module. In bundlers, the
28
26
  // module wrapper object is a plain object (not a Module instance), so we use
29
27
  // that to detect a bundled context and avoid unintended side-effects in
30
28
  // normal Node.js (e.g. shimmer-wrapping http before ESM modules load).
31
29
  if (!(module instanceof Module)) {
32
- for (const name of ['http', 'https']) {
30
+ patchLoadedBuiltins()
31
+ }
32
+
33
+ function patchLoadedBuiltins () {
34
+ // A built-in nobody has loaded cannot be cached by the bundle yet, and a later require reaches ritm, so it is
35
+ // skipped. moduleLoadList is undocumented: if it ever disappears, every registered built-in is loaded instead.
36
+ // @ts-expect-error - process.moduleLoadList is not typed
37
+ const { moduleLoadList } = process
38
+ const loadedBuiltins = Array.isArray(moduleLoadList) ? moduleLoadList : undefined
39
+
40
+ let patched = false
41
+ for (const name of registeredBuiltinNames) {
42
+ if (loadedBuiltins?.includes(`NativeModule ${name}`) === false) continue
43
+
33
44
  try {
34
45
  Module.prototype.require.call(module, name)
46
+ patched = true
35
47
  } catch {
36
48
  // Built-in not available in this environment, skip
37
49
  }
38
50
  }
51
+
52
+ if (!patched) return
53
+ try {
54
+ Module.syncBuiltinESMExports()
55
+ } catch (error) {
56
+ log.error('Error synchronizing bundled built-in ESM exports: %s', String(error?.message ?? error), error)
57
+ }
39
58
  }
40
59
 
41
60
  const CHANNEL = 'dd-trace:bundler:load'
@@ -19,8 +19,12 @@ exports.createWrapFetch = function createWrapFetch (Request, ch, onLoad) {
19
19
  }
20
20
  const req = new Request(input, init)
21
21
  const ctx = { req }
22
+ const signal = init?.signal
22
23
 
23
- return ch.tracePromise(() => fetch.call(this, req), ctx)
24
+ // The signal of `req` only weakly follows `init.signal` and is collected once `req` is unreachable, which
25
+ // stops aborts from reaching the in-flight request. Passing it again lets `fetch` follow it directly.
26
+ const options = signal ? { signal, referrer: req.referrer, referrerPolicy: req.referrerPolicy } : undefined
27
+ return ch.tracePromise(() => fetch.call(this, req, options), ctx)
24
28
  }
25
29
  }
26
30
  }
@@ -24,6 +24,10 @@
24
24
  * missing: { path: ArgumentPath, valueNode: { name: { value: string } } }[],
25
25
  * values: Record<string, unknown>
26
26
  * }} CompiledArguments
27
+ * @typedef {(
28
+ * value: Record<string, unknown>,
29
+ * hoist: (value: unknown) => string
30
+ * ) => string} StringifyArguments
27
31
  * @typedef {{
28
32
  * baseTypeName: string,
29
33
  * resource: string,
@@ -36,6 +40,7 @@
36
40
  * collapsedPathSegments: string[],
37
41
  * staticArguments?: Record<string, unknown>,
38
42
  * hasArgumentVariables?: boolean,
43
+ * literals?: Record<string, unknown>,
39
44
  * fieldName: string,
40
45
  * fieldNode: import('graphql').FieldNode,
41
46
  * fieldNodes: [import('graphql').FieldNode, ...import('graphql').FieldNode[]],
@@ -70,7 +75,8 @@
70
75
  * ) => FieldMetadata} CreateFieldMetadata
71
76
  * @typedef {(
72
77
  * variableValues: Record<string, unknown> | undefined,
73
- * cloneValue?: (value: unknown) => unknown
78
+ * cloneValue?: (value: unknown) => unknown,
79
+ * literalContext?: JitFieldDescriptor
74
80
  * ) => Record<string, unknown>} ArgumentFactory
75
81
  * @typedef {(
76
82
  * rootCtx: object,
@@ -132,7 +138,7 @@
132
138
  * fieldNodes: [import('graphql').FieldNode, ...import('graphql').FieldNode[]],
133
139
  * originPaths: string[],
134
140
  * args: CompiledArguments,
135
- * argumentSource: string,
141
+ * stringifyArguments: StringifyArguments,
136
142
  * compiledField: string
137
143
  * ) => string,
138
144
  * finalizeCompilation: (
@@ -251,7 +257,7 @@ function createGraphqlJitRuntime ({
251
257
  * @param {[import('graphql').FieldNode, ...import('graphql').FieldNode[]]} fieldNodes
252
258
  * @param {string[]} originPaths
253
259
  * @param {CompiledArguments} args
254
- * @param {string} argumentSource
260
+ * @param {StringifyArguments} stringifyArguments
255
261
  * @param {string} compiledField
256
262
  */
257
263
  function compileDefaultField (
@@ -262,7 +268,7 @@ function createGraphqlJitRuntime ({
262
268
  fieldNodes,
263
269
  originPaths,
264
270
  args,
265
- argumentSource,
271
+ stringifyArguments,
266
272
  compiledField
267
273
  ) {
268
274
  const parentPath = originPaths.join('.')
@@ -284,7 +290,7 @@ function createGraphqlJitRuntime ({
284
290
  }, fieldNodes[0], createFieldMetadata)
285
291
  descriptor.staticArguments = args.values
286
292
  descriptor.hasArgumentVariables = args.missing.length !== 0
287
- const argumentFactory = compileArgumentFactory(context, descriptor, args.missing, argumentSource)
293
+ const argumentFactory = compileArgumentFactory(context, descriptor, args.missing, stringifyArguments)
288
294
 
289
295
  const shouldTrace = '__context.ddTrace !== undefined && ' +
290
296
  '(__context.ddTrace.jitTraceAll || ' +
@@ -354,6 +360,7 @@ function createDescriptor (context, compilerPath, input, fieldNode, createFieldM
354
360
  fieldNode,
355
361
  fieldNodes: input.fieldNodes,
356
362
  hasArgumentVariables: undefined,
363
+ literals: undefined,
357
364
  parentId: undefined,
358
365
  parentPathKey: compilerPath.parentPathKey,
359
366
  parentTypeName,
@@ -374,13 +381,20 @@ function createDescriptor (context, compilerPath, input, fieldNode, createFieldM
374
381
  * @param {ConfiguredJitCompilationContext} context
375
382
  * @param {JitFieldDescriptor} descriptor
376
383
  * @param {CompiledArguments['missing']} missing
377
- * @param {string} argumentSource
384
+ * @param {StringifyArguments} stringifyArguments
378
385
  */
379
- function compileArgumentFactory (context, descriptor, missing, argumentSource) {
386
+ function compileArgumentFactory (context, descriptor, missing, stringifyArguments) {
387
+ let literalIndex = 0
388
+ const argumentSource = stringifyArguments(descriptor.staticArguments, hoist)
380
389
  if (missing.length === 0 && argumentSource === '{}') return 'undefined'
381
390
 
382
391
  const name = `ddTraceArguments${descriptor.id}`
383
- let source = `function ${name} (variableValues, cloneValue) {\n const args = ${argumentSource}\n`
392
+ const hasLiterals = descriptor.literals !== undefined
393
+ const parameters = hasLiterals ? 'variableValues, cloneValue, __context' : 'variableValues, cloneValue'
394
+ let source = `function ${name} (${parameters}) {\n const args = `
395
+ source += hasLiterals
396
+ ? `cloneValue === undefined ? ${argumentSource} : cloneValue(${argumentSource})\n`
397
+ : `${argumentSource}\n`
384
398
  const pathsByVariable = new Map()
385
399
 
386
400
  for (const { path, valueNode } of missing) {
@@ -411,6 +425,14 @@ function compileArgumentFactory (context, descriptor, missing, argumentSource) {
411
425
  source += ' return args\n}\n'
412
426
  context.hoistedFunctions.push(source)
413
427
  return name
428
+
429
+ /** @param {unknown} value */
430
+ function hoist (value) {
431
+ const name = `literal${literalIndex++}`
432
+ descriptor.literals ??= {}
433
+ descriptor.literals[name] = value
434
+ return name
435
+ }
414
436
  }
415
437
 
416
438
  /**
@@ -86,7 +86,7 @@ module.exports = {
86
86
  'find-my-way': () => require('../find-my-way'),
87
87
  'generic-pool': () => require('../generic-pool'),
88
88
  graphql: () => require('../graphql'),
89
- 'graphql-jit': () => require('../graphql'),
89
+ 'graphql-jit': { esmFirst: true, fn: () => require('../graphql') },
90
90
  grpc: () => require('../grpc'),
91
91
  handlebars: () => require('../handlebars'),
92
92
  hapi: () => require('../hapi'),
@@ -97,6 +97,7 @@ module.exports = {
97
97
  'jest-config': () => require('../jest'),
98
98
  'jest-environment-node': () => require('../jest'),
99
99
  'jest-environment-jsdom': () => require('../jest'),
100
+ 'jest-runner': () => require('../jest'),
100
101
  'jest-runtime': () => require('../jest'),
101
102
  'jest-worker': () => require('../jest'),
102
103
  knex: () => require('../knex'),
@@ -15,6 +15,7 @@ const {
15
15
  } = require('./instrumentation-utils')
16
16
  const rewriter = require('./rewriter')
17
17
  const { getActivationSetup } = require('./rewriter/instrumentation-registry')
18
+ const { isNodeBuiltinModuleName } = require('./shared-utils')
18
19
 
19
20
  const DD_TRACE_DEBUG = getValueFromEnvSources('DD_TRACE_DEBUG')
20
21
 
@@ -61,6 +62,11 @@ const alreadyLoggedIncompatibleIntegrations = new Set()
61
62
  const compatibleOrchestrionTargets = new Set()
62
63
  /** @type {Set<(activation: import('./rewriter/instrumentation-registry').Activation) => void>} */
63
64
  const blockedActivationSetups = new Set()
65
+ /**
66
+ * Node.js built-ins that passed the disabled and serverless checks and received a hook.
67
+ * @type {string[]}
68
+ */
69
+ const registeredBuiltinNames = []
64
70
 
65
71
  /**
66
72
  * @param {string} moduleName
@@ -124,6 +130,8 @@ for (const name of names) {
124
130
  hook = hook.fn
125
131
  }
126
132
 
133
+ if (isNodeBuiltinModuleName(name)) registeredBuiltinNames.push(name)
134
+
127
135
  Hook([name], hookOptions, (moduleExports, moduleName, moduleBaseDir, moduleVersion, isIitm) => {
128
136
  // All loaded versions are first expected to fail instrumentation.
129
137
  if (!instrumentedIntegrationsSuccess.has(`${name}@${moduleVersion}`)) {
@@ -214,4 +222,5 @@ module.exports = {
214
222
  filename,
215
223
  pathSepExpr,
216
224
  loadChannel,
225
+ registeredBuiltinNames,
217
226
  }
@@ -19,7 +19,8 @@ const { getRewriteTarget } = require('./targets')
19
19
  * { code: string, map?: string|object }} transform
20
20
  *
21
21
  * @typedef {(content: string|Buffer|ArrayBuffer|Uint8Array, filename: string, format?: string,
22
- * target?: { moduleName: string, filePath: string, activate?: boolean }, sourceMap?: string|object) =>
22
+ * target?: { moduleName: string, filePath: string, activate?: boolean, sourceMatch?: string },
23
+ * sourceMap?: string|object) =>
23
24
  * { code: string|Buffer|ArrayBuffer|Uint8Array, map?: string|object }} BundlerRewriter
24
25
  */
25
26
 
@@ -62,7 +63,7 @@ function normalizeFilename (filename) {
62
63
  * @param {string|Buffer|ArrayBuffer|Uint8Array} content
63
64
  * @param {string} filename
64
65
  * @param {string} [format]
65
- * @param {{ moduleName: string, filePath: string, activate?: boolean }} [target]
66
+ * @param {{ moduleName: string, filePath: string, activate?: boolean, sourceMatch?: string }} [target]
66
67
  * @returns {string|Buffer|ArrayBuffer|Uint8Array}
67
68
  */
68
69
  function rewrite (content, filename, format, target) {
@@ -74,17 +75,20 @@ function rewrite (content, filename, format, target) {
74
75
  if (!target) return content
75
76
 
76
77
  const moduleType = format === 'module' ? 'esm' : 'cjs'
77
- const { moduleName, filePath, activate } = target
78
+ const { moduleName, filePath, activate, sourceMatch } = target
78
79
  if (disabled.has(moduleName)) return content
79
80
 
80
81
  const version = getVersion(filename, filePath)
81
82
  if (!version) return content
82
83
 
84
+ const matchedSource = sourceMatch && getSourceText(content)
85
+ if (sourceMatch && !matchedSource?.includes(sourceMatch)) return content
86
+
83
87
  const transformer = getMatcher(moduleType).getTransformer(moduleName, version, filePath)
84
88
 
85
89
  if (!transformer && !activate) return content
86
90
 
87
- const source = getSourceText(content)
91
+ const source = matchedSource ?? getSourceText(content)
88
92
 
89
93
  if (!transformer) {
90
94
  return appendOrchestrionLoad(
@@ -139,14 +143,20 @@ function createBundlerRewriter (dcModule) {
139
143
  if (!target) return { code: content, map: sourceMap }
140
144
 
141
145
  const moduleType = format === 'module' ? 'esm' : 'cjs'
142
- const { moduleName, filePath } = target
146
+ const { moduleName, filePath, sourceMatch } = target
143
147
  const version = getVersion(filename, filePath)
144
148
  if (!version) return { code: content, map: sourceMap }
145
149
 
150
+ let matchedSource
151
+ if (sourceMatch) {
152
+ matchedSource = getSourceText(content)
153
+ if (!matchedSource.includes(sourceMatch)) return { code: content, map: sourceMap }
154
+ }
155
+
146
156
  const transformer = matcher.getTransformer(moduleName, version, filePath)
147
157
  if (!transformer) return { code: content, map: sourceMap }
148
158
 
149
- return transformer.transform(getSourceText(content), moduleType, sourceMap)
159
+ return transformer.transform(matchedSource ?? getSourceText(content), moduleType, sourceMap)
150
160
  } catch (error) {
151
161
  log.error(error)
152
162
  return { code: content, map: sourceMap }
@@ -32,6 +32,7 @@ const registry = [
32
32
  },
33
33
  { instrumentations: require('./instrumentations/graphql') },
34
34
  { instrumentations: require('./instrumentations/graphql-jit') },
35
+ { instrumentations: require('./instrumentations/jest') },
35
36
  { activate: true, instrumentations: require('./instrumentations/langchain') },
36
37
  { activate: true, instrumentations: require('./instrumentations/langgraph') },
37
38
  { activate: true, instrumentations: require('./instrumentations/mercurius') },
@@ -39,12 +40,21 @@ const registry = [
39
40
  { instrumentations: require('./instrumentations/openai-agents') },
40
41
  { instrumentations: require('./instrumentations/playwright') },
41
42
  { activate: true, instrumentations: require('./instrumentations/postgres') },
43
+ {
44
+ activate: /** @type {ActivationConfig} */ ({ setup: () => require('../../react-router') }),
45
+ instrumentations: require('./instrumentations/react-router'),
46
+ },
47
+ { instrumentations: require('./instrumentations/vitest') },
42
48
  { instrumentations: require('./instrumentations/webdriverio') },
43
49
  {
44
50
  activate: { setup: () => require('../../aws-durable-execution-sdk-js') },
45
51
  instrumentations: require('./instrumentations/aws-durable-execution-sdk-js'),
46
52
  },
47
53
  { activate: true, instrumentations: require('./instrumentations/supabase') },
54
+ {
55
+ activate: { setup: () => require('../../typesafe') },
56
+ instrumentations: require('./instrumentations/typesafe'),
57
+ },
48
58
  ]
49
59
 
50
60
  const activatedModules = new Set()
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  // Match the private closure only while its captured identifiers retain the verified
4
- // 0.8 contract. A future rewrite then misses safely instead of injecting stale names.
4
+ // 0.7–0.9 contract. A future rewrite then misses safely instead of injecting stale names.
5
5
  const CREATE_BOUND_QUERY = 'FunctionDeclaration[id.name="createBoundQuery"]' +
6
6
  '[params.0.name="compilationContext"][params.1.name="document"][params.4.name="operationName"]'
7
7
  const WRAP_QUERY = `${CREATE_BOUND_QUERY} ` +
@@ -78,5 +78,7 @@ addInstrumentations('>=0.7.0 <0.8.5 || >=0.8.7 <0.9.0', 'dist/execution.js')
78
78
  addInstrumentations('>=0.8.5 <0.8.7', 'dist/cjs/execution.js')
79
79
  addInstrumentations('>=0.8.5 <0.8.7', 'dist/esm/execution.js')
80
80
  addInstrumentations('>=0.8.7 <0.9.0', 'dist/execution.mjs')
81
+ addInstrumentations('>=0.9.1 <0.10.0', 'dist/cjs/execution.js')
82
+ addInstrumentations('>=0.9.1 <0.10.0', 'dist/esm/execution.js')
81
83
 
82
84
  module.exports = instrumentations
@@ -0,0 +1,12 @@
1
+ 'use strict'
2
+
3
+ module.exports = [
4
+ ['>=24.8.0 <30.0.0', 'build/runTest.js'],
5
+ ['>=30.0.0', 'build/index.js'],
6
+ ['>=30.0.0', 'build/testWorker.js'],
7
+ ].map(([versionRange, filePath]) => ({
8
+ module: { name: 'jest-runner', versionRange, filePath },
9
+ // Wrap the returned promise so completion covers both successful and failed teardown.
10
+ functionQuery: { functionName: 'runTestInternal', kind: 'Sync' },
11
+ channelName: 'runTestInternal',
12
+ }))
@@ -0,0 +1,49 @@
1
+ 'use strict'
2
+
3
+ const instrumentations = []
4
+
5
+ for (const filePath of ['dist/development/index.js', 'dist/production/index.js']) {
6
+ for (const functionName of ['derive', 'matchServerRoutes']) {
7
+ instrumentations.push({
8
+ module: { name: 'react-router', versionRange: '>=7.9.5 <8', filePath },
9
+ functionQuery: { functionName },
10
+ channelName: functionName,
11
+ })
12
+ }
13
+ }
14
+
15
+ const chunkFilePath = /^dist\/(?:development|production)\/chunk-[A-Z0-9]+\.mjs$/
16
+ for (const functionName of ['derive', 'matchServerRoutes']) {
17
+ instrumentations.push({
18
+ module: {
19
+ name: 'react-router',
20
+ versionRange: '>=7.9.5 <8',
21
+ filePath: chunkFilePath,
22
+ sourceMatch: 'function derive(',
23
+ },
24
+ functionQuery: { functionName },
25
+ channelName: functionName,
26
+ })
27
+ }
28
+
29
+ for (const mode of ['development', 'production']) {
30
+ instrumentations.push({
31
+ module: {
32
+ name: 'react-router',
33
+ versionRange: '>=8',
34
+ filePath: `dist/${mode}/lib/server-runtime/server.js`,
35
+ },
36
+ functionQuery: { functionName: 'derive' },
37
+ channelName: 'derive',
38
+ }, {
39
+ module: {
40
+ name: 'react-router',
41
+ versionRange: '>=8',
42
+ filePath: `dist/${mode}/lib/server-runtime/routeMatching.js`,
43
+ },
44
+ functionQuery: { functionName: 'matchServerRoutes' },
45
+ channelName: 'matchServerRoutes',
46
+ })
47
+ }
48
+
49
+ module.exports = instrumentations
@@ -0,0 +1,23 @@
1
+ 'use strict'
2
+
3
+ const name = '@typesafe-ai/sdk'
4
+ const versionRange = '>=0.6.0'
5
+ const files = ['dist/index.cjs', 'dist/index.mjs']
6
+
7
+ const targets = [
8
+ {
9
+ // Sync, although it returns a promise: the SDK's `APIPromise` subclass must reach the caller unchanged
10
+ functionQuery: { className: 'TypeSafeClient', methodName: 'systemOne', kind: 'Sync' },
11
+ channelName: 'TypeSafeClient_systemOne',
12
+ },
13
+ {
14
+ functionQuery: { className: 'APIPromise', methodName: 'constructor', kind: 'Sync' },
15
+ channelName: 'APIPromise_constructor',
16
+ },
17
+ ]
18
+
19
+ module.exports = files.flatMap(filePath => targets.map(({ functionQuery, channelName }) => ({
20
+ module: { name, versionRange, filePath },
21
+ functionQuery,
22
+ channelName,
23
+ })))
@@ -0,0 +1,8 @@
1
+ 'use strict'
2
+
3
+ module.exports = ['dist/index.js', 'dist/chunk-hooks.js'].map(filePath => ({
4
+ module: { name: '@vitest/runner', versionRange: '>=1.6.0 <4.1.0', filePath },
5
+ astQuery: 'FunctionDeclaration[id.name="createSuiteCollector"] ' +
6
+ 'VariableDeclarator[id.name="task"] > FunctionExpression',
7
+ channelName: 'createTestTask',
8
+ }))
@@ -452,6 +452,18 @@ module.exports = [
452
452
  channelName: 'newWindow',
453
453
  transform: 'waitForAsyncEnd',
454
454
  },
455
+ {
456
+ module: {
457
+ name: '@wdio/utils',
458
+ versionRange: '>=9.0.0',
459
+ filePath: 'build/index.js',
460
+ },
461
+ functionQuery: {
462
+ expressionName: 'runSpec',
463
+ kind: 'Sync',
464
+ },
465
+ channelName: 'runSpec',
466
+ },
455
467
  {
456
468
  module: {
457
469
  name: '@wdio/utils',
@@ -0,0 +1,8 @@
1
+ [
2
+ {
3
+ "name": "react-router",
4
+ "source": "^dist\\/(?:development|production)\\/chunk-[A-Z0-9]+\\.mjs$",
5
+ "flags": "",
6
+ "sourceMatch": "function derive("
7
+ }
8
+ ]
@@ -2,7 +2,14 @@
2
2
 
3
3
  // targets.json is generated by scripts/generate-rewriter-targets.js from ./instrumentation-registry.
4
4
  const targets = require('./targets.json')
5
+ const targetPatterns = require('./target-patterns.json').map(({ name, source, flags, sourceMatch }) => ({
6
+ name,
7
+ prefix: `${name}/`,
8
+ pattern: new RegExp(source, flags),
9
+ sourceMatch,
10
+ }))
5
11
  const rewriteTargetNames = new Set(Object.values(targets))
12
+ for (const { name } of targetPatterns) rewriteTargetNames.add(name)
6
13
 
7
14
  const NODE_MODULES = '/node_modules/'
8
15
 
@@ -11,6 +18,7 @@ const NODE_MODULES = '/node_modules/'
11
18
  * @property {string} moduleName
12
19
  * @property {string} filePath
13
20
  * @property {boolean} [activate]
21
+ * @property {string} [sourceMatch]
14
22
  */
15
23
 
16
24
  /**
@@ -22,8 +30,16 @@ function getRewriteTarget (filename) {
22
30
  if (nodeModulesIndex === -1) return
23
31
 
24
32
  const modulePath = filename.slice(nodeModulesIndex + NODE_MODULES.length)
25
- if (!Object.hasOwn(targets, modulePath)) return
26
- const moduleName = targets[modulePath]
33
+ let moduleName = targets[modulePath]
34
+ let sourceMatch
35
+ if (!moduleName) {
36
+ for (const { name, prefix, pattern, sourceMatch: expectedSource } of targetPatterns) {
37
+ if (!modulePath.startsWith(prefix) || !pattern.test(modulePath.slice(prefix.length))) continue
38
+ moduleName = name
39
+ sourceMatch = expectedSource
40
+ break
41
+ }
42
+ }
27
43
  if (typeof moduleName !== 'string') return
28
44
  const activate = isRewriteActivationEnabled(moduleName)
29
45
 
@@ -32,6 +48,7 @@ function getRewriteTarget (filename) {
32
48
  filePath: modulePath.slice(moduleName.length + 1),
33
49
  }
34
50
  if (activate) rewriteTarget.activate = true
51
+ if (sourceMatch) rewriteTarget.sourceMatch = sourceMatch
35
52
  return rewriteTarget
36
53
  }
37
54
 
@@ -41,6 +41,10 @@
41
41
  "@supabase/realtime-js/dist/module/RealtimeChannel.js": "@supabase/realtime-js",
42
42
  "@supabase/storage-js/dist/index.cjs": "@supabase/storage-js",
43
43
  "@supabase/storage-js/dist/index.mjs": "@supabase/storage-js",
44
+ "@typesafe-ai/sdk/dist/index.cjs": "@typesafe-ai/sdk",
45
+ "@typesafe-ai/sdk/dist/index.mjs": "@typesafe-ai/sdk",
46
+ "@vitest/runner/dist/chunk-hooks.js": "@vitest/runner",
47
+ "@vitest/runner/dist/index.js": "@vitest/runner",
44
48
  "@wdio/cli/build/index.js": "@wdio/cli",
45
49
  "@wdio/config/build/node/index.js": "@wdio/config",
46
50
  "@wdio/jasmine-framework/build/index.js": "@wdio/jasmine-framework",
@@ -76,6 +80,9 @@
76
80
  "graphql/validation/validate.js": "graphql",
77
81
  "graphql/validation/validate.mjs": "graphql",
78
82
  "jasmine-core/lib/jasmine-core/jasmine.js": "jasmine-core",
83
+ "jest-runner/build/index.js": "jest-runner",
84
+ "jest-runner/build/runTest.js": "jest-runner",
85
+ "jest-runner/build/testWorker.js": "jest-runner",
79
86
  "mercurius/index.js": "mercurius",
80
87
  "playwright-core/lib/coreBundle.js": "playwright-core",
81
88
  "playwright/lib/common/config.js": "playwright",
@@ -90,6 +97,12 @@
90
97
  "postgres/src/connection.js": "postgres",
91
98
  "postgres/src/index.js": "postgres",
92
99
  "postgres/src/query.js": "postgres",
100
+ "react-router/dist/development/index.js": "react-router",
101
+ "react-router/dist/development/lib/server-runtime/routeMatching.js": "react-router",
102
+ "react-router/dist/development/lib/server-runtime/server.js": "react-router",
103
+ "react-router/dist/production/index.js": "react-router",
104
+ "react-router/dist/production/lib/server-runtime/routeMatching.js": "react-router",
105
+ "react-router/dist/production/lib/server-runtime/server.js": "react-router",
93
106
  "webdriver/build/index.js": "webdriver",
94
107
  "webdriver/build/node.js": "webdriver",
95
108
  "webdriverio/build/index.js": "webdriverio",
@@ -284,7 +284,7 @@ function configureGraphqlJitCompileObject (_state, node) {
284
284
  DD_FIELD_NODES,
285
285
  originPaths,
286
286
  ddTraceArguments,
287
- objectStringify(ddTraceArguments.values),
287
+ objectStringify,
288
288
  DD_COMPILED
289
289
  )
290
290
  : undefined