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

@mikkurogue/tracing-core

v0.0.2

Published

A runtime-agnostic tracing library for TypeScript/JavaScript, inspired by Rust's tracing crate

Readme

@tracing/core

A runtime-agnostic tracing library for TypeScript/JavaScript, inspired by Rust's tracing crate.

Features

  • Runtime agnostic - Works in Node.js, Bun, Deno, browsers, and edge runtimes
  • Structured logging - Attach typed fields to events, not just strings
  • Spans - Track operations over time with nested context
  • Pluggable subscribers - Implement your own trace processors
  • Zero dependencies - No external runtime dependencies
  • TypeScript first - Full type safety with comprehensive type definitions

Installation

npm install @mikkurogue/tracing-core

Quick Start

import { 
  setGlobalSubscriber, 
  ConsoleSubscriber, 
  Level,
  info, 
  warn, 
  error,
  span 
} from "@mikkurogue/tracing-core";

// Initialize with a console subscriber
setGlobalSubscriber(new ConsoleSubscriber({ 
  minLevel: Level.DEBUG,
  timestamp: "time"
}));

// Log events
info("Server starting", { target: "http::server", fields: { port: 3000 } });
warn("Cache miss", { target: "cache", fields: { key: "user:123" } });
error("Connection failed", { target: "db", fields: { error: "timeout" } });

// Or use simple fields syntax
info("Request received", { method: "GET", path: "/api/users" });

Output:

14:30:45.123  INFO http::server: Server starting port=3000
14:30:45.124  WARN cache: Cache miss key="user:123"
14:30:45.125 ERROR db: Connection failed error="timeout"
14:30:45.126  INFO Request received method="GET" path="/api/users"

Spans

Spans represent a period of time and provide context for events:

import { span, info, debug } from "@mikkurogue/tracing-core";

// Using run() for automatic enter/exit
span("handle_request", { method: "GET" }).run(() => {
  debug("Parsing request");
  
  // Nested span
  span("db_query", { table: "users" }).run(() => {
    info("Executing query");
  });
});

// Manual enter/exit
const s = span("long_operation");
s.enter();
// ... do work ...
s.exit();

// Async operations
await span("fetch_data").runAsync(async () => {
  const data = await fetch("/api/data");
  return data.json();
});

Log Levels

Five levels available (from most to least verbose):

import { trace, debug, info, warn, error } from "@mikkurogue/tracing-core";

trace("Very detailed info");   // Level.TRACE
debug("Debugging info");       // Level.DEBUG  
info("General info");          // Level.INFO
warn("Warning");               // Level.WARN
error("Error occurred");       // Level.ERROR

Console Subscriber Options

new ConsoleSubscriber({
  // Minimum level to display (default: Level.INFO)
  minLevel: Level.DEBUG,
  
  // Enable/disable ANSI colors (default: true)
  colors: true,
  
  // Timestamp format (default: "datetime")
  // Options: "iso", "datetime", "time", "time-short", "unix", "unix-secs", false
  // Or provide a custom function: (ts: number) => string
  timestamp: "time",
  
  // Show target names (default: true)
  targets: true,
});

Timestamp Formats

| Format | Example | |--------|---------| | "datetime" | Feb 19 14:30:45.123 | | "iso" | 2024-02-19T14:30:45.123Z | | "time" | 14:30:45.123 | | "time-short" | 14:30:45 | | "unix" | 1708354245123 | | "unix-secs" | 1708354245 | | false | (no timestamp) | | (ts) => string | Custom formatter |

Function Instrumentation

Automatically wrap functions with spans:

import { instrument, instrumentAsync } from "@mikkurogue/tracing-core";

// Sync function
const processItem = instrument("process_item", (item: Item) => {
  // ... processing logic
  return result;
});

// Async function
const fetchUser = instrumentAsync("fetch_user", async (id: string) => {
  const response = await fetch(`/users/${id}`);
  return response.json();
});

Custom Subscribers

Implement the Subscriber interface to create custom trace processors:

import type { Subscriber, SpanContext, Event, Metadata } from "@tracing/core";

class MySubscriber implements Subscriber {
  enabled(metadata: Metadata): boolean {
    return metadata.level >= Level.INFO;
  }

  onSpanEnter(span: SpanContext): void {
    // Called when a span is entered
  }

  onSpanExit(span: SpanContext): void {
    // Called when a span is exited
  }

  onEvent(event: Event): void {
    // Called for each log event
    // Send to external service, write to file, etc.
  }
}

setGlobalSubscriber(new MySubscriber());

Testing

Use CollectorSubscriber to capture events in tests:

import { CollectorSubscriber, setGlobalSubscriber, info } from "@mikkurogue/tracing-core";

const collector = new CollectorSubscriber();
setGlobalSubscriber(collector);

// Run code that logs
info("Test event", { key: "value" });

// Assert on collected events
expect(collector.events).toHaveLength(1);
expect(collector.events[0].message).toBe("Test event");

// Clear between tests
collector.clear();

License

MIT