getappmap / appmap-agent-js

This project is deprecated. Please use https://github.com/getappmap/appmap-node/ to record Node.js applications.
Other
28 stars 8 forks source link

Support node 20 #225

Open lachrist opened 1 year ago

lachrist commented 1 year ago

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:

lachrist commented 1 year ago

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