Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: add diagnostics_channel events to module loading #44340

Closed
wants to merge 1 commit into from

Conversation

Qard
Copy link
Member

@Qard Qard commented Aug 22, 2022

Adding module.cjs.load and module.esm.load diagnostics_channel events so APMs don't need to patch the module system to know when a particular module has been loaded.

@Qard Qard added module Issues and PRs related to the module subsystem. semver-minor PRs that contain new features and should be released in the next minor version. esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders diagnostics_channel Issues and PRs related to diagnostics channel labels Aug 22, 2022
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/modules

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Aug 22, 2022
@bmeck
Copy link
Member

bmeck commented Aug 22, 2022 via email

@GeoffreyBooth
Copy link
Member

Since the ESM loader can also load CommonJS, should the event perhaps just be "module load" without the specific of whether it's ESM or CommonJS? I assume there's a payload with details like what module was loaded (?) so that could be where we specify which loader was used, which format the file was recognized as, etc.

seen = module;
}));

import('http').then(http => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write a test in ESM (in an .mjs file) to confirm that works too? What about static import statements?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how that would work. Wouldn't the module graph already be resolved/loaded by the time any code runs to actually register a subscriber? Maybe it could work in a loader?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I asked 😄

We should add a test that shows expected esm behavior.

@simon-id
Copy link
Contributor

Don't forget to add it to the docs here: https://nodejs.org/api/diagnostics_channel.html#built-in-channels

@rochdev
Copy link
Contributor

rochdev commented Aug 23, 2022

Could more events be added? There are use cases where having just one event is not enough, for example capturing how long each require call took which would require 2 events surrounding the function. Also including more data than just the module would be helpful, for example the path to the entry point, whether it's a core module, the base path, etc. Basically most of what require-in-the-middle has been doing historically, except the version since that's specific to package managers. Basically I think there could be 3 events: 1 when require is called, 1 when it finishes, and 1 when the module is actually loaded with module resolution information included as well.

@trevnorris
Copy link
Contributor

@Qard Thanks for doing this. I just want to let you know that this would cover all the use cases for the data we've been collecting internally.

jasnell
jasnell previously approved these changes Aug 28, 2022
@trevnorris
Copy link
Contributor

@Qard Would you mind fixing the lint error so all the tests can pass?

@Qard
Copy link
Member Author

Qard commented Sep 27, 2022

There's some more changes I've been meaning to make. I'll try to get to that after NodeConf EU. Just had a very busy few weeks. 😅

@GeoffreyBooth
Copy link
Member

There’s some more changes I’ve been meaning to make. I’ll try to get to that after NodeConf EU. Just had a very busy few weeks. 😅

Thanks. Let’s also please not land this until all open questions are resolved.

@Qard
Copy link
Member Author

Qard commented Oct 18, 2022

Going to redo this on #44943 after it lands.

@GeoffreyBooth
Copy link
Member

Going to redo this on #44943 after it lands.

Thanks. Will that other PR enable things like I mentioned in #44340 (comment), where we could have more generic events like “module load” and then additional properties for extra data like module specifier, module system (CommonJS or ESM), resolved path, etc.?

@Qard Qard force-pushed the diagnostics-channel-for-module-loads branch 5 times, most recently from 92affe4 to 99f0481 Compare December 15, 2022 06:16
@Qard
Copy link
Member Author

Qard commented Dec 15, 2022

I've reimplemented this on top of #44943. Ignore the first commit, that's inherited from that PR. I'll rebase after that lands to fix this PR. :)

@GeoffreyBooth
Copy link
Member

FYI there's a lot of refactoring in progress for module loading, including starting to merge together the CJS and ESM loaders. I would wait until the dust settles on that work before landing this. I would also suggest you make the events less tied to subsystem: like module resolution, module loading; whether it was from require or import, etc.

@Qard Qard force-pushed the diagnostics-channel-for-module-loads branch from 99f0481 to c565e0e Compare December 15, 2022 06:32
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 19, 2024
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@Flarna Flarna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a bit more info into the commit message.

@Flarna
Copy link
Member

Flarna commented Jun 20, 2024

Seems windows test failures are related to this PR:

+     parentURL: 'file:///C:/workspace/node-test-binary-windows-js-suites/node/test/parallel/test-diagnostics-channel-module-import.js',
-     parentURL: 'file://C:\\workspace\\node-test-binary-windows-js-suites\\node\\test\\parallel\\test-diagnostics-channel-module-import.js',

This commit adds a tracing channel for module loading
through `import()` and `require()`.

Co-Authored-By: Stephen Belanger <[email protected]>
@RafaelGSS RafaelGSS force-pushed the diagnostics-channel-for-module-loads branch from 683fb3d to 7de89ed Compare June 20, 2024 13:41
@RafaelGSS RafaelGSS added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 20, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 20, 2024
@nodejs-github-bot
Copy link
Collaborator

@RafaelGSS RafaelGSS added the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 20, 2024
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jun 20, 2024
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/44340
✔  Done loading data for nodejs/node/pull/44340
----------------------------------- PR info ------------------------------------
Title      lib: add diagnostics_channel events to module loading (#44340)
Author     Stephen Belanger  (@Qard)
Branch     Qard:diagnostics-channel-for-module-loads -> nodejs:main
Labels     module, semver-minor, esm, author ready, needs-ci, loaders, diagnostics_channel, commit-queue-squash
Commits    1
 - lib: add diagnostics_channel events to module loading
Committers 1
 - RafaelGSS 
PR-URL: https://github.com/nodejs/node/pull/44340
Reviewed-By: Geoffrey Booth 
Reviewed-By: Santiago Gimeno 
Reviewed-By: Rafael Gonzaga 
Reviewed-By: James M Snell 
Reviewed-By: Gerhard Stöbich 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/44340
Reviewed-By: Geoffrey Booth 
Reviewed-By: Santiago Gimeno 
Reviewed-By: Rafael Gonzaga 
Reviewed-By: James M Snell 
Reviewed-By: Gerhard Stöbich 
--------------------------------------------------------------------------------
   ⚠  Commits were pushed since the last approving review:
   ⚠  - lib: add diagnostics_channel events to module loading
   ℹ  This PR was created on Mon, 22 Aug 2022 11:57:11 GMT
   ✔  Approvals: 5
   ✔  - Geoffrey Booth (@GeoffreyBooth) (TSC): https://github.com/nodejs/node/pull/44340#pullrequestreview-2126574661
   ✔  - Santiago Gimeno (@santigimeno): https://github.com/nodejs/node/pull/44340#pullrequestreview-2126639621
   ✔  - Rafael Gonzaga (@RafaelGSS) (TSC): https://github.com/nodejs/node/pull/44340#pullrequestreview-2126661939
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/44340#pullrequestreview-2128947843
   ✔  - Gerhard Stöbich (@Flarna): https://github.com/nodejs/node/pull/44340#pullrequestreview-2129682835
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2024-06-20T17:43:17Z: https://ci.nodejs.org/job/node-test-pull-request/59906/
- Querying data for job/node-test-pull-request/59906/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/9605921698

@RafaelGSS RafaelGSS removed the commit-queue-failed An error occurred while landing this pull request using GitHub Actions. label Jun 21, 2024
RafaelGSS added a commit that referenced this pull request Jun 21, 2024
This commit adds a tracing channel for module loading
through `import()` and `require()`.

Co-Authored-By: Stephen Belanger <[email protected]>
PR-URL: #44340
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
@RafaelGSS
Copy link
Member

Landed in fbdfe93

@RafaelGSS RafaelGSS closed this Jun 21, 2024
targos pushed a commit that referenced this pull request Jun 21, 2024
This commit adds a tracing channel for module loading
through `import()` and `require()`.

Co-Authored-By: Stephen Belanger <[email protected]>
PR-URL: #44340
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
bmeck pushed a commit to bmeck/node that referenced this pull request Jun 22, 2024
This commit adds a tracing channel for module loading
through `import()` and `require()`.

Co-Authored-By: Stephen Belanger <[email protected]>
PR-URL: nodejs#44340
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
targos added a commit that referenced this pull request Jun 25, 2024
Notable changes:

deps,lib,src:
  * (SEMVER-MINOR) add experimental web storage (Colin Ihrig) #52435
doc:
  * move `node --run` stability to rc (Yagiz Nizipli) #53433
  * mark WebSocket as stable (Matthew Aitken) #53352
  * mark --heap-prof and related flags stable (Joyee Cheung) #53343
  * mark --cpu-prof and related flags stable (Joyee Cheung) #53343
  * doc-only deprecate OpenSSL engine-based APIs (Richard Lau) #53329
inspector:
  * fix disable async hooks on Debugger.setAsyncCallStackDepth (Joyee Cheung) #53473
lib:
  * (SEMVER-MINOR) add diagnostics_channel events to module loading (RafaelGSS) #44340
util:
  * (SEMVER-MINOR) support `--no-` for argument with boolean type for parseArgs (Zhenwei Jin) #53107

PR-URL: #53583
targos added a commit that referenced this pull request Jun 26, 2024
Notable changes:

deps,lib,src:
  * (SEMVER-MINOR) add experimental web storage (Colin Ihrig) #52435
doc:
  * move `node --run` stability to rc (Yagiz Nizipli) #53433
  * mark WebSocket as stable (Matthew Aitken) #53352
  * mark --heap-prof and related flags stable (Joyee Cheung) #53343
  * mark --cpu-prof and related flags stable (Joyee Cheung) #53343
  * doc-only deprecate OpenSSL engine-based APIs (Richard Lau) #53329
inspector:
  * fix disable async hooks on Debugger.setAsyncCallStackDepth (Joyee Cheung) #53473
lib:
  * (SEMVER-MINOR) add diagnostics_channel events to module loading (RafaelGSS) #44340
util:
  * (SEMVER-MINOR) support `--no-` for argument with boolean type for parseArgs (Zhenwei Jin) #53107

PR-URL: #53583
targos added a commit that referenced this pull request Jul 1, 2024
Notable changes:

deps,lib,src:
  * (SEMVER-MINOR) add experimental web storage (Colin Ihrig) #52435
doc:
  * move `node --run` stability to rc (Yagiz Nizipli) #53433
  * mark WebSocket as stable (Matthew Aitken) #53352
  * mark --heap-prof and related flags stable (Joyee Cheung) #53343
  * mark --cpu-prof and related flags stable (Joyee Cheung) #53343
  * doc-only deprecate OpenSSL engine-based APIs (Richard Lau) #53329
inspector:
  * fix disable async hooks on Debugger.setAsyncCallStackDepth (Joyee Cheung) #53473
lib:
  * (SEMVER-MINOR) add diagnostics_channel events to module loading (RafaelGSS) #44340
util:
  * (SEMVER-MINOR) support `--no-` for argument with boolean type for parseArgs (Zhenwei Jin) #53107

PR-URL: #53583
targos added a commit that referenced this pull request Jul 2, 2024
Notable changes:

deps,lib,src:
  * (SEMVER-MINOR) add experimental web storage (Colin Ihrig) #52435
doc:
  * move `node --run` stability to rc (Yagiz Nizipli) #53433
  * mark WebSocket as stable (Matthew Aitken) #53352
  * mark --heap-prof and related flags stable (Joyee Cheung) #53343
  * mark --cpu-prof and related flags stable (Joyee Cheung) #53343
  * doc-only deprecate OpenSSL engine-based APIs (Richard Lau) #53329
inspector:
  * fix disable async hooks on Debugger.setAsyncCallStackDepth (Joyee Cheung) #53473
lib:
  * (SEMVER-MINOR) add diagnostics_channel events to module loading (RafaelGSS) #44340
util:
  * (SEMVER-MINOR) support `--no-` for argument with boolean type for parseArgs (Zhenwei Jin) #53107

PR-URL: #53583
@targos targos added the dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. diagnostics_channel Issues and PRs related to diagnostics channel dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.