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

@tracegraph/trace-core

v0.3.1

Published

Trace writer, atomic finaliser, reader, storage manager, and ID generation

Readme

@tracegraph/trace-core

Low-level runtime primitives for the TraceGraph pipeline: event writing, atomic trace finalisation, trace reading, storage management, index maintenance, and ID generation. Every language adapter and the CLI depend on this package — it is the plumbing that moves events from capture to disk.

What's in this package

| Export | Description | |--------|-------------| | TraceEventWriter | Appends TraceEvent objects to a .events.jsonl.tmp file; thread/process safe via sequential writes | | finaliseTrace(options) | Atomically renames the .tmp event stream to a finished .trace.json; reads capture-level.json and meta.json from the run directory to populate the trace header | | readTrace(path) | Reads and parses a .trace.json file; throws SchemaVersionError on schema mismatch | | readTraceIndex(dir) | Reads .tracegraph/index.json | | updateTraceIndex(dir, entry) | Appends a new entry to the index, pruning old entries | | StorageManager | Enforces storage limits (max runs, max age, max size) by pruning old run directories | | createRunId() | Generates run_<16-hex> IDs | | createTraceId() | Generates trace_<16-hex> IDs | | createEventId() | Generates evt_<16-hex> IDs | | createSessionId() | Generates session_<16-hex> IDs | | createBundleId() | Generates bundle_<16-hex> IDs | | SchemaVersionError | Thrown by readTrace when schemaVersion does not match the expected value |

Installation

npm install @tracegraph/trace-core

Usage

Writing events from an adapter

import { TraceEventWriter, createEventId } from '@tracegraph/trace-core';
import type { TraceEvent } from '@tracegraph/shared-types';

const writer = new TraceEventWriter(process.env.TRACEGRAPH_RUN_DIR!);

const event: TraceEvent = {
  eventId:   createEventId(),
  type:      'function_call',
  name:      'InvoiceService.create',
  startTime: Date.now(),
  durationMs: 12.4,
};

await writer.write(event);

Finalising a trace (done by tracegraph run)

import { finaliseTrace } from '@tracegraph/trace-core';

await finaliseTrace({
  runDir:      '/path/to/.tracegraph/runs/run_abc',
  tracesDir:   '/path/to/.tracegraph/traces',
  traceId:     'trace_abc123',
  entrypoint:  { type: 'cli_command', command: 'npm test' },
});
// Writes .tracegraph/traces/trace_abc123.trace.json

Reading a trace

import { readTrace, SchemaVersionError } from '@tracegraph/trace-core';

try {
  const trace = readTrace('/path/to/trace_abc123.trace.json');
  console.log(trace.events.length, 'events');
} catch (e) {
  if (e instanceof SchemaVersionError) {
    console.error('Run: tracegraph schema doctor');
  }
}

Storage pruning

import { StorageManager, DEFAULT_STORAGE_CONFIG } from '@tracegraph/trace-core';

const mgr = new StorageManager('/path/to/.tracegraph', DEFAULT_STORAGE_CONFIG);
await mgr.prune(); // removes runs older than maxAgeDays, beyond maxRuns, etc.

File protocol

The write path for a single trace run:

.tracegraph/runs/<runId>/
  <traceId>.events.jsonl.tmp    ← TraceEventWriter appends here
  capture-level.json            ← written by the language adapter on shutdown
  meta.json                     ← language/framework metadata

→ finaliseTrace() atomically renames to:

.tracegraph/traces/<traceId>.trace.json

The VS Code extension only reads finalised .trace.json files — never .tmp files.