init() runs as the addon's module_init and installs a global tracing subscriber with SubscriberInitExt::init() (src/lib.rs#L361-L379). init() panics if a global subscriber is already installed.
This runs on every load, including when oxc-node's crate is linked into another Node-API addon that sets up its own tracing. Vite+ does this: its binding installs a subscriber for its VP_LOG variable with try_init(). Depending on which runs first:
- if the host's subscriber is installed first, oxc-node's
module_init panics while the addon loads;
- if oxc-node's runs first, it becomes the global default, so the host's
try_init() does nothing: the host's events are filtered by OXC_LOG, and dropped entirely when OXC_LOG is unset.
Proposal
Any one of these lets a host keep its subscriber:
- use
try_init() and ignore the error;
- install the subscriber only when
OXC_LOG is set;
- gate the
module_init registration behind a default-on feature that embedders can turn off.
try_init() is the smallest change and keeps today's behavior for @oxc-node/core.
Today Vite+ removes the module_init attribute in a patch.
init()runs as the addon'smodule_initand installs a global tracing subscriber withSubscriberInitExt::init()(src/lib.rs#L361-L379).init()panics if a global subscriber is already installed.This runs on every load, including when oxc-node's crate is linked into another Node-API addon that sets up its own tracing. Vite+ does this: its binding installs a subscriber for its
VP_LOGvariable withtry_init(). Depending on which runs first:module_initpanics while the addon loads;try_init()does nothing: the host's events are filtered byOXC_LOG, and dropped entirely whenOXC_LOGis unset.Proposal
Any one of these lets a host keep its subscriber:
try_init()and ignore the error;OXC_LOGis set;module_initregistration behind a default-on feature that embedders can turn off.try_init()is the smallest change and keeps today's behavior for@oxc-node/core.Today Vite+ removes the
module_initattribute in a patch.