getappmap/appmap-agent-js

Support node 20

Opened this issue · 1 comments

Since node 20, custom loaders are executed separately from the rest of the application. The problem is that we use that loader to preload the entire agent. So every hooks placed by the agent has no effect on the observed application. Another minor implication is that process.argv inside the loader no longer contains the main path, it only contains the node executable.

To solve this issue we have to adopt the same architecture as for the jest recorder where the transformer is isolated. To preload the agent we have 2 strategies:

  • Use --import which supports esm modules but I'm not sure how backward compatible this is.
  • Use --require which is older but it requires to bundle the agent as a commonjs module which is not currently the case.

Hooks are run in a separate thread, isolated from the main. That means it is a different realm. The hooks thread may be terminated by the main thread at any time, so do not depend on asynchronous operations (like console.log) to complete.

https://nodejs.org/dist/latest-v20.x/docs/api/esm.html#hooks