Skip to content

fix(instrumentations): rewrite ESM source through _compile shim - #11397

Draft
pabloerhard wants to merge 1 commit into
masterfrom
fix/scoped-require-esm-rewrite
Draft

pabloerhard wants to merge 1 commit into
masterfrom
fix/scoped-require-esm-rewrite

Conversation

@pabloerhard

Copy link
Copy Markdown
Collaborator

What does this PR do?

With only -r dd-trace/init, rewrite static ESM dependencies loaded through require() on supported Node.js versions. Install a synchronous load hook only while _compile processes the ESM entry point, and remove it in finally. Nested require() calls reuse the hook. If the explicit Datadog loader is already registered, it stays in charge.

Motivation

Module._compile sees an ESM entry point reached through require(), but not the files it imports (for example, postgres 4’s src/pool.js). This is a scoped alternative to #11396: no permanent hook at startup, no handover between hooks, and no change to standalone import behavior.

Additional Notes

  • npm run test:instrumentations:misc: 779 passed on Node 26.12.
  • Focused rewriter and loader tests: 42 passed on both Node 24.15 and 26.12. They cover nested requires, cleanup after an application error, explicit loader modes, a third-party async loader, and unchanged standalone imports.
  • Targeted ESLint and npm run type:check:ci passed. Full lint flagged a test in the OpenFeature submodule; local EditorConfig validation was blocked because Docker was unavailable.

@dd-octo-sts

dd-octo-sts Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 9.56 MB
Deduped: 10.32 MB
No deduping: 10.32 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.5.3 | 131.25 kB | 531.9 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

@pabloerhard pabloerhard changed the title fix(instrumentations): rewrite static dependencies of require(esm) fix(instrumentations): rewrite ESM source through _compile shim Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.15%. Comparing base (41dee42) to head (59d0d59).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11397      +/-   ##
==========================================
+ Coverage   89.61%   99.15%   +9.54%     
==========================================
  Files        1128     1136       +8     
  Lines      184036   188446    +4410     
  Branches       86       86              
==========================================
+ Hits       164923   186862   +21939     
+ Misses      19113     1584   -17529     
Flag Coverage Δ
ai-guard 63.34% <82.75%> (-0.01%) ⬇️
apm-capabilities 55.18% <86.36%> (+0.01%) ⬆️
apm-integrations 81.97% <100.00%> (+<0.01%) ⬆️
appsec 59.36% <100.00%> (+0.11%) ⬆️
debugger 70.91% <86.20%> (+<0.01%) ⬆️
instrumentation 60.26% <100.00%> (+0.13%) ⬆️
llmobs 82.53% <100.00%> (+<0.01%) ⬆️
master-coverage 99.15% <100.00%> (?)
openfeature 68.06% <82.75%> (-0.03%) ⬇️
platform 68.20% <100.00%> (+0.03%) ⬆️
profiling 66.51% <82.75%> (-0.03%) ⬇️
serverless 66.69% <89.65%> (+0.01%) ⬆️
test-optimization 82.03% <100.00%> (?)

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-4

datadog-prod-us1-4 Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 98.57% (+8.99%)

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

@pr-commenter

pr-commenter Bot commented Nov 24, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-24 00:47:21

Comparing candidate commit 59d0d59 in PR branch fix/scoped-require-esm-rewrite with baseline commit 41dee42 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2475 metrics, 12 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-appsec-enabled-20

  • unstable max_rss_usage [-52364.554KB; +52245.054KB] or [-19.144%; +19.100%]

scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-20

  • unstable max_rss_usage [-24.156MB; +33.455MB] or [-6.605%; +9.148%]

scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-26

  • unstable max_rss_usage [-26566.316KB; +28512.982KB] or [-8.512%; +9.136%]

scenario:encoders-0.4-immediate-flush-20

  • unstable max_rss_usage [-12.463MB; +7.950MB] or [-14.606%; +9.317%]

scenario:openfeature-initialization-configuration-20

  • unstable max_rss_usage [-4908.583KB; +5260.583KB] or [-6.373%; +6.830%]

scenario:openfeature-initialization-configuration-26

  • unstable cpu_user_time [-97.087ms; +123.792ms] or [-5.554%; +7.082%]
  • unstable execution_time [-99.670ms; +124.163ms] or [-5.494%; +6.845%]
  • unstable throughput [-37996.859op/s; +30406.774op/s] or [-6.772%; +5.419%]

scenario:openfeature-initialization-error-26

  • unstable cpu_user_time [-165.879ms; +131.412ms] or [-6.351%; +5.031%]
  • unstable execution_time [-168.698ms; +134.234ms] or [-6.310%; +5.021%]
  • unstable throughput [-17141.618op/s; +22867.513op/s] or [-4.527%; +6.040%]

scenario:openfeature-scale-full-26

  • unstable max_rss_usage [-24.340MB; +27.767MB] or [-10.405%; +11.870%]

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant