AndreasMadsen/trace

Add an `install` method

Closed this issue · 1 comments

Would it be a good idea to add an install method that performs asyncHook.createHook() and modifies Error.prepareStackTrace (through stack-chain) instead of automatically doing it when the module is required?

It can already be done right now by conditionally calling require() but this might be problematic when using ES modules and import (until dynamic imports become more supported).

Also it goes against the assumption some users may have, that when they require() a module, it only defines functions and constants and does not perform significant logic.

A good compromise to support both behaviors is often to add a register.js file that performs the modification automatically, and offer an install method in the main export.

There could also be an uninstall method.

@ehmicky The reason that if a user does a late install it is impossible to track the async operations.

It also has the added benefit that you can do node -r trace script.js.