`module_init` installs a global tracing subscriber with `init()`, which panics or takes over the host's subscriber when embedded

Closed Beginner friendly
#805 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

A pull request for this has already been merged.

  • #813 by @Brooooooklyn — merged

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
67/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
devtools

Research direction

Start with src/lib.rs lines 361–379, where module_init calls init(), and compare the tracing setup with the host behavior described in the issue. The issue identifies try_init() as the smallest proposed change; verify how it handles an existing global subscriber. Done means addon loading no longer panics or takes over the host’s subscriber, while @oxc-node/core retains its current behavior.

Written by the indexing model from the issue text.

Description

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.

Dominant language
TypeScript
Stars
269
Forks
10
Avg merge
5h 19m
Merged PRs (30d)
75

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from oxc-project/oxc-node

All issues in oxc-project/oxc-node

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.