Skip to content

fix(esm): register synchronous hooks without require(esm) - #11296

Merged
pabloerhard merged 2 commits into
masterfrom
pabloerhard/prevent-register-dependency-warning
Nov 20, 2026
Merged

pabloerhard merged 2 commits into
masterfrom
pabloerhard/prevent-register-dependency-warning

Conversation

@pabloerhard

@pabloerhard pabloerhard commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

  • Adds dd-trace/register.mjs and has initialize.mjs await it, so the synchronous loader can be installed without requiring an ES module from CommonJS.
  • Shares registration state between the CommonJS and ESM entry points so they cannot install the hooks twice. Keeps the asynchronous fallback on older Node releases where module.register() is available.
  • Adds child-process coverage for disabled require(esm), missing module.register(), async fallback, and both registration orders.

Motivation

AWS Lambda disables require(esm). The CommonJS registration path therefore falls back to module.register(), which Node removed in nodejs/node#67090. Without the fallback, ESM modules load without instrumentation. Using native import() for registration lets the synchronous hooks work without changing the contract of register.js.

Additional Notes

  • On Node 24: 127 loader and initialization tests passed; 6 were skipped. Targeted ESLint and the npm pack dry run passed.
  • The registration suite also passed on Node 22, Node 26, Node 27 alpha, and a Node 28 nightly. On that nightly, where module.register() is absent, the HTTP instrumentation fixture printed false on the unchanged base and true with this change, both with --no-experimental-require-module.
  • Repository-wide lint and type checks did not pass locally (an OpenFeature submodule test is not covered by the test globs, and type errors were reported outside the changed files).
  • Follow-up for datadog-lambda-js: its programmatic bootstrap still checks for module.register() and requires register.js. It needs to await register.mjs before loading the customer handler and retain compatibility with older tracer releases. No deployed Lambda test was run.

Alternative solution to #11277

@dd-octo-sts

dd-octo-sts Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 9.48 MB
Deduped: 10.23 MB
No deduping: 10.23 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.5.3 | 131.25 kB | 531.86 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 Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.14%. Comparing base (f159c6a) to head (0c5d375).
⚠️ Report is 30 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11296      +/-   ##
==========================================
+ Coverage   99.13%   99.14%   +0.01%     
==========================================
  Files        1118     1125       +7     
  Lines      184942   186323    +1381     
  Branches       82       86       +4     
==========================================
+ Hits       183338   184735    +1397     
+ Misses       1603     1588      -15     
+ Partials        1        0       -1     
Flag Coverage Δ
ai-guard 63.24% <ø> (-0.06%) ⬇️
apm-capabilities 55.05% <100.00%> (-0.01%) ⬇️
apm-integrations 81.95% <100.00%> (+0.03%) ⬆️
appsec 59.12% <81.17%> (+0.38%) ⬆️
debugger 71.05% <81.33%> (-0.03%) ⬇️
instrumentation 60.16% <100.00%> (+0.27%) ⬆️
llmobs 82.78% <100.00%> (-0.12%) ⬇️
master-coverage 99.14% <100.00%> (?)
openfeature 68.17% <ø> (+0.01%) ⬆️
platform 68.22% <81.17%> (+0.08%) ⬆️
profiling 66.13% <ø> (+0.02%) ⬆️
serverless 65.59% <100.00%> (-0.05%) ⬇️
test-optimization 82.15% <100.00%> (-0.05%) ⬇️

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 17, 2026 •

Copy link
Copy Markdown

Tests  Pipelines

⚠️ Warnings

Your PR has warnings. Please review the issues below.

❄️ 3 New flaky tests detected

does not register again if initialize.mjs already installed the loader from Mocha Tests
/opt/hostedtoolcache/node/18.20.8/x64/bin/node: bad option: --no-experimental-require-module


      &#43; expected - actual

      -9
      &#43;0
      
AssertionError [ERR_ASSERTION]: /opt/hostedtoolcache/node/18.20.8/x64/bin/node: bad option: --no-experimental-require-module

...
does not register again if register.js already installed the asynchronous loader from Mocha Tests
/opt/hostedtoolcache/node/18.20.8/x64/bin/node: bad option: --no-experimental-require-module


      &#43; expected - actual

      -9
      &#43;0
      
AssertionError [ERR_ASSERTION]: /opt/hostedtoolcache/node/18.20.8/x64/bin/node: bad option: --no-experimental-require-module

...

View in Flaky Test Management

ℹ️ Info

No other issues found (see more)

🧪 All tests passed

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 98.56% (+0.01%)

Useful? React with 👍 / 👎

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

@pr-commenter

pr-commenter Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-18 18:29:58

Comparing candidate commit 0c5d375 in PR branch pabloerhard/prevent-register-dependency-warning with baseline commit f159c6a in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2446 metrics, 11 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 [-84.827MB; +34.466MB] or [-32.004%; +13.003%]

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

  • unstable max_rss_usage [-28.635MB; +23.215MB] or [-9.308%; +7.546%]

scenario:encoders-0.4-immediate-flush-24

  • unstable max_rss_usage [-7.319MB; +12.506MB] or [-8.738%; +14.931%]

scenario:openfeature-initialization-configuration-20

  • unstable max_rss_usage [-6.162MB; +3.793MB] or [-7.990%; +4.918%]

scenario:openfeature-initialization-configuration-26

  • unstable cpu_user_time [-79.468ms; +154.287ms] or [-4.707%; +9.139%]
  • unstable execution_time [-80.247ms; +156.871ms] or [-4.576%; +8.946%]
  • unstable throughput [-47610.122op/s; +23467.681op/s] or [-8.196%; +4.040%]

scenario:openfeature-initialization-error-20

  • unstable max_rss_usage [-3462.693KB; +5048.511KB] or [-4.646%; +6.774%]

scenario:openfeature-scale-full-26

  • unstable max_rss_usage [-15.580MB; +41.339MB] or [-7.049%; +18.703%]

scenario:plugin-graphql-long-with-depth-off-26

  • unstable max_rss_usage [-3.881MB; +27.161MB] or [-1.535%; +10.744%]

scenario:plugin-graphql-long-with-depth-on-max-26

  • unstable max_rss_usage [+3.271MB; +52.007MB] or [+1.372%; +21.812%]

@pabloerhard
pabloerhard marked this pull request as ready for review November 18, 2026 18:29
@pabloerhard
pabloerhard requested a review from a team as a code owner November 18, 2026 18:29
@pabloerhard
pabloerhard requested review from bengl and removed request for a team November 18, 2026 18:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T18:31:21.912475Z 0c5d375 Draft marked ready
🔒 Security Review ✅ Completed 2026-11-18T18:33:50.058097Z 0c5d375 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pabloerhard
pabloerhard merged commit fa32b93 into master Nov 20, 2026
745 checks passed
@pabloerhard
pabloerhard deleted the pabloerhard/prevent-register-dependency-warning branch November 20, 2026 20:20
This was referenced Nov 23, 2026
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.

2 participants