npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-perf-trace

v1.0.1

Published

Minimalist, performant module for tracing and managing infrastructure diagnostics

Readme

📦 TraceManager – High-Precision Node.js Tracing Utility

A modular tracing and logging utility for Node.js with plug-and-play performance diagnostics:

  • 🔹 Console & file logging
  • 🔹 Unit-based and flow-based timing
  • 🔹 Custom outputs: DB, HTTP, broker (Kafka/RabbitMQ)
  • 🔹 Stream-based piping
  • 🔹 JSON config with NODE_ENV targeting

📚 Table of Contents


🔧 Setup

🌍 Environment Support

TraceManager respects NODE_ENV. You can control when traces run using the env key inside each tag.

"ExampleTag": {
  "enabled": true,
  "writeTo": "console",
  "unit": "ms",
  "logSamplePercent": 100,
  "env": ["development", "production"]
}

To define the environment:

# Cross-platform (recommended)
cross-env NODE_ENV=production node app.js

# Unix-style only
NODE_ENV=production node app.js

Only tags matching the current environment will trigger output.

📦 Install dependencies

npm install uuid

⚙️ Config Setup

Auto-generated at config/trace.config.json if missing:

{
  "env": "development",
  "minDurationMs": 0,
  "maxEntries": 200,
  "defaultWriteTo": "console",
  "activeTags": {
    "ExampleTag": {
      "enabled": true,
      "writeTo": "console",
      "unit": "ms",
      "logSamplePercent": 100,
      "env": ["development"]
    }
  }
}

✅ Basic Console Tracing

const Trace = require("./TraceManager");
const end = Trace.trace("Doing work", "ExampleTag");
// your logic
end();

Sample Output:

[ExampleTag] Doing work took 12.34 ms

📁 File Logging (to logs/tracer.log)

"FileTrace": {
  "enabled": true,
  "writeTo": "file",
  "unit": "ms",
  "env": ["development", "production"]
}
Trace.trace("Write to file", "FileTrace")();

🔁 Flow Tracing

const flow = Trace.createFlow("UserSignupFlow", "FileTrace");

const validate = flow.step("Validation");
// validation logic
validate();

const save = flow.step("DB Save");
// DB logic
save();

flow.done();

Sample:

[FileTrace] Flow "UserSignupFlow" (ID: ...) — Total: 80.00 ms
├─ Validation       — 20.00 ms
└─ DB Save          — 60.00 ms

🧪 Unit Test Example

const Trace = require("./TraceManager");

test("basic trace logs within range", () => {
  const end = Trace.trace("TestOperation", "ExampleTag");
  for (let i = 0; i < 100000; i++) Math.sqrt(i);
  end();

  const logs = Trace.getRecentTraces();
  expect(logs.at(-1)?.message).toBe("TestOperation");
});

🔌 Pipe to Database

const db = require("./dbClient");
Trace.pipeTo(async (trace) => {
  await db.saveTrace(trace);
});

🌐 Pipe to HTTP Endpoint

const axios = require("axios");
Trace.pipeTo(async (trace) => {
  await axios.post("https://api.example.com/trace", trace);
});

🐇 Pipe to Broker (RabbitMQ/Kafka)

const rabbit = require("./rabbitmqClient");
Trace.pipeTo(trace => {
  rabbit.channel.sendToQueue("trace-logs", Buffer.from(JSON.stringify(trace)));
});

🧪 Custom Log File

Trace.pipeToFile("logs/custom.log");

🔧 Advanced: Pipe to Writable Stream

const { Writable } = require("stream");
const stream = new Writable({
  write(chunk, _, cb) {
    console.log("TRACE:", chunk.toString());
    cb();
  }
});
Trace.pipeToWritable(stream);

🧠 Access Recent Entries

const recent = Trace.getRecentTraces();
console.log(recent);

🗂️ Keywords (for documentation indexing)

  • trace manager
  • node.js performance
  • observability
  • custom logging
  • flow-based tracing
  • distributed trace
  • devops tracing
  • performance analysis
  • in-memory log buffer
  • stream traces

🎯 Summary

| Method | Use Case | | ------------------- | ------------------------------- | | trace() | One-off measurements | | createFlow() | Step-by-step timing | | pipeTo(fn) | Custom handler (DB, HTTP, etc.) | | pipeToFile(path) | Save as JSON lines | | pipeToWritable() | Any Node.js stream | | getRecentTraces() | Inspect recent N traces |