Skip to content

feat(node-sensor): add Node.js --require and ESM live sensor with #73 conformance (#56) - #236

Open
SriRamkunamsetty wants to merge 1 commit into
secfoo-com:mainfrom
SriRamkunamsetty:feat/node-sensor-56
Open

SriRamkunamsetty wants to merge 1 commit into
secfoo-com:mainfrom
SriRamkunamsetty:feat/node-sensor-56

Conversation

@SriRamkunamsetty

Copy link
Copy Markdown
Contributor

Fixes #56

Summary

  • Extended npm/secfoo-sensor/ (@rakfortltd/secfoo-sensor) into a full Node.js live sensor supporting both CommonJS (node --require @rakfortltd/secfoo-sensor / NODE_OPTIONS=--require) and ESM (node --import @rakfortltd/secfoo-sensor/register / module.register on Node >= 20.6).
  • Rule 0 inertia & zero behavior distortion: Returns without hooks, timers, or sockets unless SECFOO_SENSOR=1. Wraps watched #52 exports (Module._load + ESM loader wrapper) via transparent Proxy preserving this, arguments, return values, thrown errors, instanceof, static properties, and hot-reloading cached modules when SECFOO_WATCHLIST updates.
  • Evidence, context & coverage: Emits #68 npm load inventory from package.json, reads #69 request/auth context via AsyncLocalStorage (getContext()), samples first-hit trimmed file:line app stack frames, and collects optional V8 coverage via node:inspector (Profiler.startPreciseCoverage, callCount: false, detailed: false).
  • Non-blocking #73 transports: Supports tcp:// (loopback-only + optional SECFOO_SENSOR_KEY auth), unix://, npipe://, direct gzipped https://, file://, and SECFOO_EVENTS_OUT fallback, with bounded queue + .unref() timers/sockets and a bounded 200ms drain on exit.

Overhead Benchmark

node npm/secfoo-sensor/test/benchmark.js (node v24.16.0, 200k vs 1M calls):

  • Bare per call: 0.0009 us
  • Probed per call: 1.8847 us
  • Marginal overhead: 1.8838 us/call (budget: 50 us/call)

Verification

  • pytest -p no:langsmith -p no:hypothesis tests/test_sensor/test_node_probe.py tests/test_sensor/test_route_auth_attribution.py -q -> 9 passed (covers node --test CJS + ESM + middleware suites and 6/6 #73 conformance kit checks for both CJS and ESM).
  • ruff check . & bandit -c .bandit -ll -r src/secfoo -q -> passed.
  • git merge-tree --write-tree HEAD upstream/main -> zero conflicts.

Copilot AI balanced review requested due to automatic review settings December 1, 2026 12:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.


let doc;
try {
doc = JSON.parse(fs.readFileSync(this.filePath, "utf-8"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node.js live sensor (--require hook)

3 participants