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
package/loader-hook.mjs CHANGED
@@ -52,11 +52,51 @@ if (!isInitializeMainThread) {
52
52
 
53
53
  const nodeModulesIncludeSource = `node_modules/(?:${moduleNameAlternation})/(?!node_modules).+`
54
54
 
55
+ const NODE_MODULES = '/node_modules/'
56
+
57
+ // Package roots already reported, so each package costs a single report however many of its files load.
58
+ const reportedPackageRoots = new Set()
59
+ /** @type {((url: string) => void) | undefined} */
60
+ let reportModuleLoad
61
+
55
62
  function initialize (data = {}) {
63
+ const { moduleLoadPort } = data
64
+ if (moduleLoadPort) {
65
+ // A MessagePort, not a timer; optional chaining would break the Node.js 12 syntax this file supports.
66
+ // eslint-disable-next-line eslint-rules/eslint-timer-unref
67
+ moduleLoadPort.unref()
68
+ reportModuleLoad = (url) => moduleLoadPort.postMessage(url)
69
+ }
70
+
56
71
  prepareImportInTheMiddleOptions(data)
57
72
  return origInitialize(data)
58
73
  }
59
74
 
75
+ /**
76
+ * Reports the first loaded file of each `node_modules` package, so packages that
77
+ * import-in-the-middle leaves unwrapped reach `dd-trace:moduleLoadStart` too. Wrapped
78
+ * modules are also published through iitm's `addHook`; dependency telemetry deduplicates.
79
+ *
80
+ * @param {string} url Loaded module URL.
81
+ */
82
+ function reportUnwrappedPackage (url) {
83
+ if (!reportModuleLoad || !url.startsWith('file:') || url.includes('iitm=true')) return
84
+
85
+ const nodeModulesIndex = url.lastIndexOf(NODE_MODULES)
86
+ if (nodeModulesIndex === -1) return
87
+
88
+ const nameStart = nodeModulesIndex + NODE_MODULES.length
89
+ let nameEnd = url.indexOf('/', nameStart)
90
+ if (url[nameStart] === '@' && nameEnd !== -1) nameEnd = url.indexOf('/', nameEnd + 1)
91
+ if (nameEnd === -1) return
92
+
93
+ const packageRoot = url.slice(0, nameEnd)
94
+ if (reportedPackageRoots.has(packageRoot)) return
95
+
96
+ reportedPackageRoots.add(packageRoot)
97
+ reportModuleLoad(url)
98
+ }
99
+
60
100
  function prepareImportInTheMiddleOptions (data = {}) {
61
101
  // A consumer-owned shouldInclude predicate takes over the wrapping decision, so
62
102
  // iitm ignores the include/exclude arrays. Building the matcher here keeps the
@@ -116,10 +156,14 @@ function buildIncludeSource (securityControlsConfig) {
116
156
  }
117
157
 
118
158
  function load (url, context, nextLoad) {
159
+ reportUnwrappedPackage(url)
119
160
  return rewriterLoader.load(url, context, (url, context) => origLoad(url, context, nextLoad))
120
161
  }
121
162
 
122
163
  function loadSync (url, context, nextLoad) {
164
+ // require() loads are already published by require-in-the-middle.
165
+ if (!hasRequireCondition(context)) reportUnwrappedPackage(url)
166
+
123
167
  if (isCommonJSLoad(context)) {
124
168
  return getSyncImportInTheMiddleHook().loadSync(url, context, nextLoad)
125
169
  }
@@ -135,6 +179,13 @@ function isCommonJSLoad (context) {
135
179
  // Sync hooks report CommonJS require() dependency loads with a `require`
136
180
  // condition but no format. If a format is present, trust it instead: ESM
137
181
  // loaded through require() reports `format: 'module'` and still needs rewrite.
182
+ return hasRequireCondition(context)
183
+ }
184
+
185
+ /**
186
+ * @param {import('node:module').LoadHookContext} context
187
+ */
188
+ function hasRequireCondition (context) {
138
189
  const conditions = context.conditions
139
190
  if (!conditions) return false
140
191
 
@@ -184,6 +235,8 @@ function registerSyncLoaderHooks (data = {}) {
184
235
  // synchronous and asynchronous loaders share the same option preparation so
185
236
  // that `import http from 'node:http'` is wrapped on both paths.
186
237
  syncHook.applyOptions(prepareImportInTheMiddleOptions(data))
238
+ // The synchronous hooks run on the application thread, so publish directly.
239
+ reportModuleLoad = require('./packages/dd-trace/src/esm-module-load.js').publishModuleLoad
187
240
  Module.registerHooks({
188
241
  resolve: syncHook.resolveSync,
189
242
  load: loadSync,
@@ -0,0 +1,66 @@
1
+ export type ExposureFeatureValue = string | number | boolean;
2
+
3
+ export interface ExposureFlagMetadata {
4
+ [key: string]: string | number | boolean | undefined;
5
+ }
6
+
7
+ export interface ExposureEvaluationDetails {
8
+ flagKey: string;
9
+ value?: unknown;
10
+ variant?: string;
11
+ reason?: string;
12
+ errorCode?: string;
13
+ errorMessage?: string;
14
+ flagMetadata?: Readonly<ExposureFlagMetadata>;
15
+ }
16
+
17
+ export interface ExposureEvaluationContext {
18
+ targetingKey?: string;
19
+ [key: string]: unknown;
20
+ }
21
+
22
+ /**
23
+ * A completed flag evaluation and its Datadog exposure decision.
24
+ */
25
+ export interface ExposureEvaluation {
26
+ /** The flag key. */
27
+ readonly flagKey: string;
28
+ /** The flag key, variant, value, error and flag metadata of the evaluation. */
29
+ readonly details: ExposureEvaluationDetails;
30
+ /** The selected variant key, or undefined when the default value was returned. */
31
+ readonly variant: string | undefined;
32
+ /** The key of the selected allocation, or undefined when none was selected. */
33
+ readonly allocation: string | undefined;
34
+ /** The evaluation context, including the targeting key. */
35
+ readonly context: ExposureEvaluationContext | undefined;
36
+ /** The targeting key of the evaluation context, if readable. */
37
+ readonly targetingKey: string | undefined;
38
+ /**
39
+ * True when the evaluation succeeded and selected an allocation that logs exposures,
40
+ * whether or not this subject was already exposed.
41
+ */
42
+ isExposure(): boolean;
43
+ /**
44
+ * True when this exposure repeats one already recorded for this subject: same
45
+ * allocation, variant and serial id.
46
+ */
47
+ isCacheHit(): boolean;
48
+ /** True for a new or changed exposure: the decision the provider uses for Datadog. */
49
+ shouldSend(): boolean;
50
+ /**
51
+ * The HOOK features of the selected split, such as `holdout.key`. Read-only.
52
+ */
53
+ getFeatures(): Readonly<Record<string, ExposureFeatureValue>>;
54
+ }
55
+
56
+ /**
57
+ * An OpenFeature hook that hands each completed flag evaluation to a callback,
58
+ * with the Datadog exposure decision.
59
+ *
60
+ * Register it with `OpenFeature.addHooks(new ExposureHook(callback))` or on a client.
61
+ * The callback runs on the evaluation thread and must not do I/O. An exception from
62
+ * the callback does not affect the evaluation.
63
+ */
64
+ export declare class ExposureHook {
65
+ constructor(callback: (evaluation: ExposureEvaluation) => void);
66
+ }
@@ -0,0 +1,5 @@
1
+ 'use strict'
2
+
3
+ const { ExposureHook } = require('../packages/dd-trace/src/openfeature/exposure-hook')
4
+
5
+ module.exports = { ExposureHook }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "6.22.0",
3
+ "version": "6.24.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -84,8 +84,8 @@
84
84
  "test:integration:appsec:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/appsec/*.spec.js\"",
85
85
  "test:integration:crashtracking": "mocha --timeout 60000 \"integration-tests/crashtracking/*.spec.js\"",
86
86
  "test:integration:bun": "mocha --timeout 60000 \"integration-tests/bun/*.spec.js\"",
87
- "test:integration:cucumber": "mocha --timeout 60000 \"integration-tests/cucumber/*.spec.js\"",
88
- "test:integration:cucumber:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/cucumber/*.spec.js\"",
87
+ "test:integration:cucumber": "mocha --timeout 60000 \"integration-tests/cucumber/${SPEC:-cucumber*}.spec.js\"",
88
+ "test:integration:cucumber:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/cucumber/${SPEC:-cucumber*}.spec.js\"",
89
89
  "test:integration:cypress": "mocha --timeout 60000 \"integration-tests/cypress/${SPEC:-cypress-*}.spec.js\"",
90
90
  "test:integration:cypress:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/cypress/${SPEC:-cypress-*}.spec.js\"",
91
91
  "test:integration:debugger": "mocha --timeout 60000 \"integration-tests/debugger/*.spec.js\"",
@@ -94,24 +94,25 @@
94
94
  "test:integration:esbuild": "mocha --timeout 60000 \"integration-tests/esbuild/*.spec.js\"",
95
95
  "test:integration:esbuild:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/esbuild/*.spec.js\"",
96
96
  "test:integration:turbopack": "mocha --timeout 60000 \"integration-tests/turbopack/*.spec.js\"",
97
+ "test:integration:vite": "mocha --timeout 60000 \"integration-tests/vite/*.spec.js\"",
97
98
  "test:integration:webpack": "mocha --timeout 60000 \"integration-tests/webpack/*.spec.js\"",
98
99
  "test:integration:openfeature": "mocha --timeout 60000 \"integration-tests/openfeature/*.spec.js\"",
99
100
  "test:integration:openfeature:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/openfeature/*.spec.js\"",
100
101
  "test:integration:jest": "mocha --timeout 60000 \"integration-tests/jest/${SPEC:-jest*}.spec.js\"",
101
102
  "test:integration:jest:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/jest/${SPEC:-jest*}.spec.js\"",
102
- "test:integration:mocha": "mocha --timeout 60000 \"integration-tests/mocha/*.spec.js\"",
103
- "test:integration:mocha:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/mocha/*.spec.js\"",
103
+ "test:integration:mocha": "mocha --timeout 60000 \"integration-tests/mocha/${SPEC:-mocha*}.spec.js\"",
104
+ "test:integration:mocha:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/mocha/${SPEC:-mocha*}.spec.js\"",
104
105
  "test:integration:playwright": "mocha --timeout 60000 \"integration-tests/playwright/${SPEC:-playwright-*}.spec.js\"",
105
106
  "test:integration:playwright:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/playwright/${SPEC:-playwright-*}.spec.js\"",
106
107
  "test:integration:selenium": "mocha --timeout 60000 \"integration-tests/selenium/*.spec.js\"",
107
108
  "test:integration:selenium:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/selenium/*.spec.js\"",
108
- "test:integration:test-optimization:helpers": "mocha \"integration-tests/cypress/*dependencies.spec.js\" \"integration-tests/jest/*dependencies.spec.js\" \"integration-tests/playwright/version*.spec.js\"",
109
+ "test:integration:test-optimization:helpers": "mocha \"integration-tests/cypress/config-lifecycle*.spec.js\" \"integration-tests/cypress/*dependencies.spec.js\" \"integration-tests/jest/*dependencies.spec.js\" \"integration-tests/playwright/version*.spec.js\" \"integration-tests/mocha/version*.spec.js\"",
109
110
  "test:integration:webdriverio": "mocha --timeout 60000 \"integration-tests/webdriverio/${SPEC:-*}.spec.js\"",
110
111
  "test:integration:webdriverio:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/webdriverio/${SPEC:-*}.spec.js\"",
111
112
  "test:integration:vitest": "mocha --timeout 60000 \"integration-tests/vitest/${SPEC:-vitest*}.spec.js\"",
112
113
  "test:integration:vitest:coverage": "node ./integration-tests/vitest/run-with-coverage.js --timeout 60000 \"integration-tests/vitest/${SPEC:-vitest*}.spec.js\"",
113
- "test:integration:testopt": "mocha --timeout 120000 \"integration-tests/ci-visibility/*.spec.js\"",
114
- "test:integration:testopt:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 120000 \"integration-tests/ci-visibility/*.spec.js\"",
114
+ "test:integration:testopt": "mocha --timeout 120000 \"integration-tests/ci-visibility/${SPEC:-*}.spec.js\"",
115
+ "test:integration:testopt:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 120000 \"integration-tests/ci-visibility/${SPEC:-*}.spec.js\"",
115
116
  "test:integration:profiler": "mocha --timeout 180000 \"integration-tests/profiler/*.spec.js\"",
116
117
  "test:integration:profiler:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 180000 \"integration-tests/profiler/*.spec.js\"",
117
118
  "test:integration:plugins": "yarn services && mocha \"packages/datadog-plugin-@(${PLUGINS})/test/integration-test/**/${SPEC:-*}*.spec.js\"",
@@ -171,6 +172,8 @@
171
172
  "openfeature.js",
172
173
  "openfeature/rules-based.js",
173
174
  "openfeature/rules-based.d.ts",
175
+ "openfeature/exposure-hook.js",
176
+ "openfeature/exposure-hook.d.ts",
174
177
  "packages/*/index.js",
175
178
  "packages/*/index.electron.js",
176
179
  "packages/*/lib/**/*",
@@ -186,7 +189,7 @@
186
189
  ],
187
190
  "dependencies": {
188
191
  "dc-polyfill": "^0.1.11",
189
- "import-in-the-middle": "3.5.1",
192
+ "import-in-the-middle": "3.5.3",
190
193
  "opentracing": ">=0.14.7"
191
194
  },
192
195
  "optionalDependencies": {
@@ -197,42 +200,42 @@
197
200
  "@datadog/native-metrics": "4.0.0",
198
201
  "@datadog/pprof": "5.20.0",
199
202
  "@datadog/wasm-js-rewriter": "5.0.4",
200
- "@opentelemetry/api": ">=1.0.0 <1.10.0",
203
+ "@opentelemetry/api": ">=1.4.1 <1.10.0",
201
204
  "@opentelemetry/api-logs": "<1.0.0",
202
205
  "oxc-parser": "^0.132.0"
203
206
  },
204
207
  "devDependencies": {
205
208
  "@actions/core": "^3.0.1",
206
209
  "@actions/github": "^9.1.1",
207
- "@babel/helpers": "^8.0.7",
210
+ "@babel/helpers": "^8.0.10",
208
211
  "@eslint/eslintrc": "^3.3.7",
209
212
  "@eslint/js": "^10.0.1",
210
213
  "@eslint/plugin-kit": "^0.7.3",
211
- "@datadog/openfeature-node-server": "2.5.0",
214
+ "@datadog/openfeature-node-server": "2.7.0",
212
215
  "@msgpack/msgpack": "^3.1.3",
213
216
  "@openfeature/core": "^1.12.0",
214
217
  "@openfeature/server-sdk": "~1.23.0",
215
218
  "@stylistic/eslint-plugin": "^5.10.0",
216
219
  "@types/mocha": "^10.0.10",
217
220
  "@types/node": "^18.19.106",
218
- "@types/sinon": "^22.0.0",
221
+ "@types/sinon": "^22.0.2",
219
222
  "@vercel/nft": "^1.11.0",
220
223
  "@yarnpkg/lockfile": "^1.1.0",
221
224
  "benchmark": "^2.1.4",
222
- "body-parser": "^2.3.0",
223
- "bun": "1.4.3",
225
+ "body-parser": "^2.4.0",
226
+ "bun": "1.4.4",
224
227
  "c8": "^12.0.0",
225
228
  "codeowners-audit": "^2.9.0",
226
229
  "eslint": "^10.13.0",
227
230
  "eslint-plugin-cypress": "^7.0.2",
228
231
  "eslint-plugin-import-x": "^4.16.2",
229
- "eslint-plugin-jsdoc": "^65.3.12",
232
+ "eslint-plugin-jsdoc": "^65.4.2",
230
233
  "eslint-plugin-mocha": "^12.0.2",
231
234
  "eslint-plugin-n": "^18.5.0",
232
235
  "eslint-plugin-promise": "^7.3.0",
233
- "eslint-plugin-regexp": "^3.3.1",
236
+ "eslint-plugin-regexp": "^3.3.2",
234
237
  "eslint-plugin-sonarjs": "^4.2.2",
235
- "eslint-plugin-unicorn": "^74.0.0",
238
+ "eslint-plugin-unicorn": "^79.0.0",
236
239
  "express": "^5.3.0",
237
240
  "glob": "^10.4.5",
238
241
  "globals": "^17.13.0",
@@ -243,11 +246,11 @@
243
246
  "istanbul-reports": "^3.0.2",
244
247
  "jsonc-parser": "^3.3.1",
245
248
  "jszip": "^3.10.2",
246
- "minimatch": "^10.2.6",
249
+ "minimatch": "^11.0.3",
247
250
  "mocha": "^11.8.0",
248
251
  "mocha-junit-reporter": "^2.2.1",
249
252
  "mocha-multi-reporters": "^1.5.2",
250
- "multer": "^2.4.0",
253
+ "multer": "^2.5.0",
251
254
  "nock": "^14.0.17",
252
255
  "node-preload": "^0.2.1",
253
256
  "nyc": "^18.0.0",
@@ -128,7 +128,7 @@ if (!isACFActive) {
128
128
  * For convenience, we use the `storage` function as a registry of namespaces
129
129
  * corresponding to DatadogStorage instances. This lets us have separate
130
130
  * storages for separate purposes.
131
- * @type {Map<string, DatadogStorage>}
131
+ * @type {Record<string, DatadogStorage>}
132
132
  */
133
133
  const storages = Object.create(null)
134
134
 
@@ -8,6 +8,8 @@ const { pathToFileURL, fileURLToPath } = require('node:url')
8
8
  const instrumentations = require('../datadog-instrumentations/src/helpers/instrumentations')
9
9
  const extractPackageAndModulePath = require('../datadog-instrumentations/src/helpers/extract-package-and-module-path')
10
10
  const hooks = require('../datadog-instrumentations/src/helpers/hooks')
11
+ const { createBundlerRewriter } = require('../datadog-instrumentations/src/helpers/rewriter')
12
+ const { getRewriteTarget, isRewriteTargetName } = require('../datadog-instrumentations/src/helpers/rewriter/targets')
11
13
  const { getValueFromEnvSources } = require('../dd-trace/src/config/helper')
12
14
  const log = require('./src/log')
13
15
  const { createEsmResolver } = require('./src/resolver')
@@ -15,8 +17,15 @@ const { isESMFile, processModule } = require('./src/utils')
15
17
 
16
18
  const ESM_INTERCEPTED_SUFFIX = '._dd_esbuild_intercepted'
17
19
  const INTERNAL_ESM_INTERCEPTED_PREFIX = '/_dd_esm_internal_/'
20
+ // User bundles may not have dc-polyfill next to the target package.
21
+ const DC_MODULE = require.resolve('dc-polyfill').replaceAll('\\', '/')
22
+ const DC_MODULE_LITERAL = JSON.stringify(DC_MODULE)
23
+ // Keep the marker split so source-map scanners do not treat this literal as this file's map.
24
+ // eslint-disable-next-line unicorn/no-useless-concat
25
+ const SOURCE_MAP_PREFIX = '//# sourceMapping' + 'URL=data:application/json;base64,'
18
26
 
19
27
  let rewriter
28
+ let bundlerRewrite
20
29
 
21
30
  for (const hook of Object.values(hooks)) {
22
31
  if (hook !== null && typeof hook === 'object') {
@@ -189,6 +198,7 @@ ${build.initialOptions.banner.js}`
189
198
  // TODO: Should this also check for namespace === 'file'?
190
199
  if (!modulesOfInterest.has(args.path) &&
191
200
  args.path.startsWith('@') &&
201
+ !isRewriteTargetName(args.path.split('/', 2).join('/')) &&
192
202
  !args.importer.includes('node_modules/')) {
193
203
  // This is the Next.js convention for loading local files
194
204
  log.debug('@LOCAL: %s', args.path)
@@ -220,6 +230,9 @@ ${build.initialOptions.banner.js}`
220
230
  const extracted = extractPackageAndModulePath(fullPathToModule)
221
231
 
222
232
  const internal = builtins.has(args.path)
233
+ const target = getRewriteTarget(fullPathToModule.replaceAll('\\', '/'))
234
+ const isModuleOfInterest = modulesOfInterest.has(args.path) ||
235
+ modulesOfInterest.has(`${extracted.pkg}/${extracted.path}`)
223
236
 
224
237
  // Only the generated wrapper module, and the real module importing itself, must reach the real module unwrapped.
225
238
  // Every other importer must get the wrapper regardless of whether it has already been loaded: onLoad runs
@@ -228,9 +241,7 @@ ${build.initialOptions.banner.js}`
228
241
  // wrapper cycle that can hit the wrapper's exports in their temporal dead zone.
229
242
  const isInterceptedImporter = args.importer.endsWith(ESM_INTERCEPTED_SUFFIX) || args.importer === fullPathToModule
230
243
 
231
- if (args.namespace === 'file' && (
232
- modulesOfInterest.has(args.path) || modulesOfInterest.has(`${extracted.pkg}/${extracted.path}`))
233
- ) {
244
+ if (args.namespace === 'file' && (isModuleOfInterest || target !== undefined)) {
234
245
  // Internal module like http/fs is imported and the build output is ESM
235
246
  if (internal && args.kind === 'import-statement' && esmBuild && !isInterceptedImporter) {
236
247
  fullPathToModule = `${INTERNAL_ESM_INTERCEPTED_PREFIX}${fullPathToModule}${ESM_INTERCEPTED_SUFFIX}`
@@ -274,7 +285,10 @@ ${build.initialOptions.banner.js}`
274
285
  const packageJson = JSON.parse(fs.readFileSync(/** @type {string} */(pathToPackageJson)).toString())
275
286
 
276
287
  const isESM = isESMFile(fullPathToModule, pathToPackageJson, packageJson)
277
- if (isESM && !isInterceptedImporter) {
288
+ // ESM targets with export hooks still need the IITM wrapper to run those hooks; the wrapper's import of the
289
+ // real module then resolves without the suffix and is rewritten.
290
+ const needsExportHook = !target || (isModuleOfInterest && !target.activate)
291
+ if (isESM && needsExportHook && !isInterceptedImporter) {
278
292
  fullPathToModule += ESM_INTERCEPTED_SUFFIX
279
293
  }
280
294
 
@@ -290,6 +304,7 @@ ${build.initialOptions.banner.js}`
290
304
  full: fullPathToModule,
291
305
  raw: args.path,
292
306
  pkgOfInterest: true,
307
+ rewriteOnly: !isModuleOfInterest,
293
308
  kind: args.kind,
294
309
  internal,
295
310
  isESM,
@@ -324,8 +339,44 @@ ${build.initialOptions.banner.js}`
324
339
 
325
340
  // Read the content of the module file of interest
326
341
  let contents
342
+ let sourceMap
343
+ const target = getRewriteTarget(args.path.replaceAll('\\', '/'))
344
+
345
+ if (target) {
346
+ const source = fs.readFileSync(args.path, 'utf8')
347
+ bundlerRewrite ??= createBundlerRewriter(DC_MODULE)
348
+ const result = bundlerRewrite(source, args.path, data.isESM ? 'module' : 'commonjs', target)
349
+ contents = /** @type {string} */(result.code)
350
+ if (result.map) {
351
+ const map = typeof result.map === 'string' ? JSON.parse(result.map) : result.map
352
+ // Inline maps resolve sources relative to the loaded file, not the package root.
353
+ sourceMap = {
354
+ ...map,
355
+ sources: [path.basename(args.path)],
356
+ sourcesContent: [source],
357
+ }
358
+ }
327
359
 
328
- if (data.isESM) {
360
+ if (contents !== source && target.activate) {
361
+ const payload = JSON.stringify({
362
+ activate: true,
363
+ package: target.moduleName,
364
+ version: data.version,
365
+ path: `${target.moduleName}/${target.filePath}`,
366
+ })
367
+ let channel = `;{\n const __dd_ch = require(${DC_MODULE_LITERAL}).channel('${CHANNEL}');\n`
368
+ if (data.isESM) {
369
+ let binding = '__dd_dc'
370
+ let suffix = 0
371
+ while (contents.includes(binding)) binding = `__dd_dc${++suffix}`
372
+ channel = `import ${binding} from ${DC_MODULE_LITERAL};\n;{\n` +
373
+ ` const __dd_ch = ${binding}.channel('${CHANNEL}');\n`
374
+ }
375
+ contents += `\n${channel}` +
376
+ ` if (__dd_ch.hasSubscribers) __dd_ch.publish(${payload});\n` +
377
+ '}\n'
378
+ }
379
+ } else if (data.isESM) {
329
380
  if (args.path.endsWith(ESM_INTERCEPTED_SUFFIX)) {
330
381
  args.path = args.path.slice(0, -ESM_INTERCEPTED_SUFFIX.length)
331
382
 
@@ -362,7 +413,12 @@ register(${JSON.stringify(toRegister)}, _, set, get, ${JSON.stringify(data.raw)}
362
413
  contents = fs.readFileSync(args.path, 'utf8')
363
414
  }
364
415
  } else {
365
- const fileCode = fs.readFileSync(args.path, 'utf8')
416
+ contents = fs.readFileSync(args.path, 'utf8')
417
+ }
418
+
419
+ // Rewrite-only targets have no export hook. ESM export hooks run through the IITM wrapper instead.
420
+ if (!data.isESM && !data.rewriteOnly && !target?.activate) {
421
+ const fileCode = contents
366
422
  // Don't spread `...arguments`: esbuild's minifier can rewrite the surrounding
367
423
  // `__commonJS` factory into an arrow function whose `arguments` resolves to the
368
424
  // ESM top-level scope (see issue #8681). Pass `(module.exports, module)`
@@ -370,7 +426,7 @@ register(${JSON.stringify(toRegister)}, _, set, get, ${JSON.stringify(data.raw)}
370
426
  // resolution inside `fileCode` is preserved through the factory's closure.
371
427
  contents = `
372
428
  (function() {
373
- ${fileCode}
429
+ ${fileCode}
374
430
  })(module.exports, module);
375
431
  {
376
432
  const dc = require('dc-polyfill');
@@ -386,6 +442,13 @@ register(${JSON.stringify(toRegister)}, _, set, get, ${JSON.stringify(data.raw)}
386
442
  module.exports = payload.module;
387
443
  }
388
444
  `
445
+ if (sourceMap) {
446
+ sourceMap.mappings = `;;${sourceMap.mappings}`
447
+ }
448
+ }
449
+
450
+ if (sourceMap) {
451
+ contents += `\n${SOURCE_MAP_PREFIX}${Buffer.from(JSON.stringify(sourceMap)).toString('base64')}`
389
452
  }
390
453
 
391
454
  // https://esbuild.github.io/plugins/#on-load-results
@@ -2,4 +2,5 @@
2
2
 
3
3
  require('./src/helpers/bundler-register')
4
4
  require('./src/helpers/register')
5
- require('./src/helpers/rewriter/loader')
5
+ // The extension is required: bundlers that prefer `.mjs` (e.g. Vite) would otherwise pick the ESM loader hook.
6
+ require('./src/helpers/rewriter/loader.js')