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

@ferrow/distributed-tracing

v2.0.0

Published

A tracer producing spans with traceId/spanId/parentSpanId, spec-correct W3C traceparent header inject/extract, child spans, span events/tags, duration, and a pluggable exporter interface with bundled Console and InMemory exporters.

Downloads

85

Readme

distributed-tracing

CI

A small distributed tracer: spans with traceId/spanId/parentSpanId, spec-correct W3C traceparent header inject/extract, child spans, tags, timestamped events, duration, and a pluggable exporter interface — zero runtime dependencies.

This is not a full OpenTelemetry SDK — no automatic instrumentation, no context propagation via async hooks, no OTLP wire format. It's the minimal, correct core (span model + W3C header handling) you can wire into whatever HTTP client/server you're already using.

Install

npm install distributed-tracing

Quickstart

import { Tracer, ConsoleExporter } from "distributed-tracing";

const tracer = new Tracer({ exporter: new ConsoleExporter() });

const span = tracer.startSpan("http.request GET /users");
span.setTag("http.route", "/users");

const dbSpan = span.startChild("db.query users.select");
// ... do the query ...
dbSpan.end();

// Propagate to a downstream call:
const header = span.toTraceparent();
await fetch("https://downstream/api", { headers: { traceparent: header } });

span.end(); // exports via the configured Exporter

On the receiving service:

const serverSpan = tracer.startSpanFromHeader(
  "http.request POST /api",
  req.headers["traceparent"]
);
// same traceId as the caller, parented to its span

API

new Tracer({ exporter })

  • startSpan(name: string, parentContext?: TraceContext): Span — starts a new trace if no parent, otherwise continues one.
  • startSpanFromHeader(name: string, traceparentHeader: string | null | undefined): Span — parses the header and continues that trace, or starts a fresh one if the header is missing/malformed.

Span

  • setTag(key, value): this
  • addEvent(name, attributes?): this
  • startChild(name): Span — shares traceId, parented to this span.
  • toTraceparent(): string — the W3C header value to send downstream.
  • end(): SpanData — finalizes duration and exports. Idempotent.
  • .traceId / .spanId

W3C traceparent header

  • injectTraceparent(ctx: TraceContext): string — formats 00-<32 hex traceId>-<16 hex spanId>-<flags> per the W3C Trace Context spec.
  • extractTraceparent(header): TraceContext | undefined — parses and validates; returns undefined for anything that doesn't match spec (wrong lengths, all-zero ids, version ff), so a malformed header degrades to "start a new trace" instead of crashing.

Exporters

interface Exporter {
  export(span: SpanData): void | Promise<void>;
}
  • ConsoleExporter — one log line per finished span.
  • InMemoryExporter — collects spans; .getSpans(), .getSpansForTrace(traceId), .clear().

buildTraceTree(spans: SpanData[]): SpanTreeNode[]

Assembles a flat span list (e.g. from InMemoryExporter) into a parent/children tree, rooted at spans whose parent is absent or wasn't captured (crossed a boundary you didn't collect).

Design notes

The traceparent implementation follows the W3C spec's exact grammar (version-traceid-parentid-flags, all lowercase hex, fixed widths) and rejects the spec's explicit invalid cases (all-zero ids, version ff) rather than trying to be lenient — a tracer that silently accepts malformed context can stitch unrelated requests into the same trace, which is worse than starting a fresh one. The exporter is an interface, not a bundled HTTP/OTLP client, because where spans go (stdout, a collector, a test assertion) is a deployment decision this library shouldn't make for you.


Sponsored by Ferrow


Part of the ferrow-toolkit collection · Sponsored by Ferrow