Skip to content

refactor(bundlers): delegate wrappers to import-in-the-middle - #10262

Draft
BridgeAR wants to merge 17 commits into
BridgeAR/2026-08-28-turbopack-instrumentationfrom
BridgeAR/2026-09-08-iitm-bundler-api-v2
Draft

refactor(bundlers): delegate wrappers to import-in-the-middle#10262
BridgeAR wants to merge 17 commits into
BridgeAR/2026-08-28-turbopack-instrumentationfrom
BridgeAR/2026-09-08-iitm-bundler-api-v2

Conversation

@BridgeAR

@BridgeAR BridgeAR commented Sep 9, 2026

Copy link
Copy Markdown
Member

Separate wrappers for Webpack, esbuild, and Turbopack duplicate export discovery, live-binding, and CommonJS replacement behavior. Their behavior can drift from import-in-the-middle and from each other.

This delegates those contracts to import-in-the-middle's experimental bundler API. dd-trace-js still owns bundler resolution, instrumentation metadata, source-map composition, and watch-file integration.

This draft depends on nodejs/import-in-the-middle#270.

@dd-octo-sts

dd-octo-sts Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 8.89 MB
Deduped: 9.94 MB
No deduping: 9.94 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.5.0 | 442.82 kB | 828.77 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.52%. Comparing base (1a21dd3) to head (0fd9965).

❗ There is a different number of reports uploaded between BASE (1a21dd3) and HEAD (0fd9965). Click for more details.

HEAD has 17 uploads less than BASE
Flag BASE (1a21dd3) HEAD (0fd9965)
master-coverage 12 0
platform 1 0
llmobs 1 0
appsec 1 0
apm-integrations 1 0
test-optimization 1 0
Additional details and impacted files
@@                                Coverage Diff                                 @@
##           BridgeAR/2026-08-28-turbopack-instrumentation   #10262       +/-   ##
==================================================================================
- Coverage                                          98.71%   69.52%   -29.19%     
==================================================================================
  Files                                               1013      986       -27     
  Lines                                             160794   152589     -8205     
  Branches                                              74       26       -48     
==================================================================================
- Hits                                              158728   106092    -52636     
- Misses                                              2066    46497    +44431     
Flag Coverage Δ
ai-guard 65.23% <71.60%> (+0.06%) ⬆️
apm-capabilities 63.74% <88.88%> (+0.03%) ⬆️
apm-integrations ?
appsec ?
debugger 69.91% <82.71%> (+0.08%) ⬆️
instrumentation 54.17% <100.00%> (-0.19%) ⬇️
llmobs ?
master-coverage ?
openfeature 66.47% <71.60%> (+0.06%) ⬆️
platform ?
profiling 66.82% <71.60%> (+0.06%) ⬆️
serverless 65.80% <100.00%> (+0.08%) ⬆️
test-optimization ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Sep 9, 2026

Copy link
Copy Markdown

Pipelines  Tests

Unblock PR with BitsAI

⚠️ Warnings

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 20 Pipeline jobs failed

Test Optimization | integration-jest (latest, node-oldest, jest.core) — ❌ 2 tests failed · 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

2 assertion errors in jest tests for logger instrumentation: expected 1 but got 0 at /home/runner/work/dd-trace-js/dd-trace-js/integration-tests/jest/jest.core.spec.js:1705:20

❌ jest@latest commonJS Pino and Bunyan module loading instruments bunyan after another suite mocks it from integration-tests/jest/jest.core.spec.js
PASS ci-visibility/jest-mock-bypass-require/bunyan-mock-test.js
PASS ci-visibility/jest-mock-bypass-require/z-real-logger-test.js

Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        0.579 s
Ran all test suites.
{&#34;name&#34;:&#34;test-logger&#34;,&#34;hostname&#34;:&#34;runnervmlun5p&#34;,&#34;pid&#34;:5037,&#34;level&#34;:30,&#34;msg&#34;:&#34;real logger after mock&#34;,&#34;time&#34;:&#34;2026-09-09T19:43:51.088Z&#34;,&#34;v&#34;:0}

❌ jest@latest commonJS Pino and Bunyan module loading instruments pino after another suite mocks it from integration-tests/jest/jest.core.spec.js
PASS ci-visibility/jest-mock-bypass-require/pino-mock-test.js
PASS ci-visibility/jest-mock-bypass-require/z-real-logger-test.js

Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        0.557 s
Ran all test suites.
{&#34;level&#34;:30,&#34;time&#34;:1788982939111,&#34;pid&#34;:4807,&#34;hostname&#34;:&#34;runnervmlun5p&#34;,&#34;msg&#34;:&#34;real logger after mock&#34;}

Test Optimization | integration-jest (oldest, node-oldest, jest.core) — ❌ 2 tests failed · 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

2 failed tests. AssertionError: expected 0 but received 1 at /home/runner/work/dd-trace-js/dd-trace-js/integration-tests/jest/jest.core.spec.js:1705:20

❌ jest@28.0.0 commonJS Pino and Bunyan module loading instruments bunyan after another suite mocks it from integration-tests/jest/jest.core.spec.js
PASS ci-visibility/jest-mock-bypass-require/bunyan-mock-test.js
PASS ci-visibility/jest-mock-bypass-require/z-real-logger-test.js

Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        0.541 s
Ran all test suites.
{&#34;name&#34;:&#34;test-logger&#34;,&#34;hostname&#34;:&#34;runnervmlun5p&#34;,&#34;pid&#34;:5012,&#34;level&#34;:30,&#34;msg&#34;:&#34;real logger after mock&#34;,&#34;time&#34;:&#34;2026-09-09T19:43:46.742Z&#34;,&#34;v&#34;:0}

❌ jest@28.0.0 commonJS Pino and Bunyan module loading instruments pino after another suite mocks it from integration-tests/jest/jest.core.spec.js
PASS ci-visibility/jest-mock-bypass-require/pino-mock-test.js
PASS ci-visibility/jest-mock-bypass-require/z-real-logger-test.js

Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        0.539 s
Ran all test suites.
{&#34;level&#34;:30,&#34;time&#34;:1788982933299,&#34;pid&#34;:4703,&#34;hostname&#34;:&#34;runnervmlun5p&#34;,&#34;msg&#34;:&#34;real logger after mock&#34;}

DataDog/apm-reliability/dd-trace-js | benchmark: [20, 4] — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

View all 20 failed jobs.

📋 Copy fix prompt
CI on my pull request is failing. Help me find and fix the root cause of each failing job below — they were flagged as caused by changes in this PR, so focus on the diff. For each job, explain the failure and propose a fix.

Before you start, set up the Datadog software-delivery tooling so you can
query the CI data yourself:

1. Check whether you already have the Datadog software-delivery MCP tools
   (e.g. a `search_datadog_ci_pipeline_events` tool) and the `unblock-pr` skill.
2. If either is missing, STOP and ask me for permission before installing
   anything. Do not install or run anything until I have said yes.
3. Only with my explicit approval, set up the Datadog software-delivery MCP
   server and skills by following:
     https://docs.datadoghq.com/getting_started/software_delivery_mcp_tools/
   then restart so the skill is picked up.
4. If I decline, skip all of the above and work from the context below alone.

Then run /unblock-pr — it will pull the CI data itself. The job context below is what we already know.

If /unblock-pr is not available — because I declined the setup above, or it did not install — work from the context below instead.

Datadog has already classified this failure as caused by changes in this PR.
Take that as given and work the fix:

1. Locate the change. Diff this branch against its base and find the change
   that produces this error. Explain the mechanism, don't just name a file:
     git fetch origin && git diff $(git merge-base origin/BridgeAR/2026-08-28-turbopack-instrumentation HEAD)...HEAD
2. Reproduce it locally. Run the failing job's command or test before
   proposing anything.
3. Propose the smallest fix that addresses the root cause — not a workaround,
   not a broadened assertion, not a disabled or skipped test.
4. Re-run the same command to confirm, and say exactly what you ran.
5. If the failure turns out to be intermittent rather than deterministic, say
   so plainly instead of "fixing" it — that is a flaky test, and patching it
   hides the problem.

If the right move is to re-run the job rather than change code, use the job
link in the context below. For GitHub Actions: `gh run rerun <run-id> --failed`,
where the run ID is the number after `/runs/` in that URL (not the trailing
number, which is the job ID).

Branch: BridgeAR/2026-09-08-iitm-bundler-api-v2

Test Optimization | integration-jest (latest, node-oldest, jest.core)
Commit: 19efaaf64e0b50bac8b9f22d0bd60338533bc7b2
Error (code / test):
2 assertion errors in jest tests for logger instrumentation: expected 1 but got 0 at /home/runner/work/dd-trace-js/dd-trace-js/integration-tests/jest/jest.core.spec.js:1705:20
CI job: https://github.com/DataDog/dd-trace-js/actions/runs/34396158548/job/102616285797

Test Optimization | integration-jest (oldest, node-oldest, jest.core)
Commit: 19efaaf64e0b50bac8b9f22d0bd60338533bc7b2
Error (code / test):
2 failed tests. AssertionError: expected 0 but received 1 at /home/runner/work/dd-trace-js/dd-trace-js/integration-tests/jest/jest.core.spec.js:1705:20
CI job: https://github.com/DataDog/dd-trace-js/actions/runs/34396158548/job/102616285482

Plus 14 more failing jobs not shown here.

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

🔄 Datadog retried 4 tests - 0 passed on retry View in Datadog

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 69.51% (-28.68%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 0fd9965 | Docs | View more details | Give us feedback!

wconti27 and others added 14 commits September 9, 2026 16:46
Turbopack compiles dependency modules before runtime hooks can observe their exports. Build-time plans and live-binding proxies preserve instrumentation without adding discovery or source analysis to the request path.
1. Clean installs hoisted Babel 8's ESM parser into the CommonJS fake Next compiler because its Babel 7 inputs were only transitive dependencies.
2. Bun applied the root files allowlist to nested READMEs while npm included them automatically, so the package archives differed.
Backport CI widens the repository engine range to include Node 18 and 20. The test then loads ESLint 10 on unsupported runtimes, which fail while parsing its /v regular expressions.
Generated ESM proxies captured mutable exports once, so later updates were invisible to bundled consumers.

Build plans persisted hook positions and incomplete source snapshots. Runtime hook changes or star-export updates could therefore apply the wrong instrumentation or load stale proxies.

Artifacts under installed dependencies also made read-only dependency trees abort Next configuration.
Build planning could execute application code, lose non-hoisted targets, and retain stale resolution data. Isolated native resolution preserves roots and conditions without request-path work.

Generated proxies could be unreachable, miss foreign ESM importers, or make optional edges fatal. Resolver-visible artifacts and importer-local checks preserve instrumentation and fail-open behavior.

Supported CommonJS wrappers can contain top-level returns that older Next parsers reject. Script-compatible parsing preserves the wrapper grammar.

Legal star-export cycles could exhaust the stack. Active-path tracking terminates cycles without dropping same-origin diamond exports.
Regular module loading passed through the bundler source-map API and allocated its result object for every rewrite. Keeping the scalar path avoids that startup work while Turbopack retains source-map composition.

Bundler matchers are cached per diagnostic-channel specifier so targets at different directory depths keep the correct runtime import.
Node.js 22 reads conditions through Set#has. Passing an array throws while resolving bare conditional exports, so target planning silently omits the ESM instrumentation.
Build-time discovery resolved ESM imports with CommonJS rules and reused plans after their dependency graph changed. This selected incorrect conditional exports, retained stale proxies, and could change ESM initialization order.
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-08-28-turbopack-instrumentation branch from 8e27ae6 to 710e3a4 Compare September 9, 2026 14:47
Generated source was linted from a synthetic repository path, so valid relative dependencies resolved differently on CI.
…zation

Runtime instrumentation shared the bundler rewrite entry point, so every traced process parsed bundler-only source-map composition code during initialization.
Separate bundler wrappers duplicated export discovery, live-binding, and CommonJS replacement semantics, allowing their behavior to drift from runtime instrumentation. Delegate those contracts to import-in-the-middle while retaining bundler-specific resolution, target selection, and source maps.
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-09-08-iitm-bundler-api-v2 branch from 862411d to 0fd9965 Compare September 9, 2026 19:37
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-08-28-turbopack-instrumentation branch 2 times, most recently from d899dbf to 8cd78ff Compare September 10, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants