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

@vinhnt-sdk/trace

v0.4.3

Published

Observability - OpenTelemetry spans, timeline replay, telemetry aggregation

Readme

@vinhnt-sdk/trace

Version: 0.4.3 | Status: STABLE

Observability for vinhnt-sdk — OpenTelemetry-compatible spans, timeline replay, telemetry aggregation, and cost tracking.

Install

`ash

npm

npm install @vinhnt-sdk/trace

pnpm (monorepo)

pnpm add @vinhnt-sdk/trace `

Features

  • SpanRecorder — Record and query OpenTelemetry-compatible spans
  • Timeline — Build transcripts from run events for replay
  • CostMeter — Track token usage and calculate costs per model
  • ContextPressure — Monitor context window utilization
  • TelemetryProvider — Interface for custom telemetry backends
  • OTLP exporter — createOtlpSpanExporter ships spans to any OTLP/HTTP collector (optional)
  • DEFAULT_MODEL_PRICING — Built-in pricing for common models

Quick Start

` ypescript import { SpanRecorder, createSpan, endSpan, CostMeter, calculateCost, DEFAULT_MODEL_PRICING, Timeline, buildTranscript, } from "@vinhnt-sdk/trace";

// Create and record spans const recorder = new SpanRecorder(); const span = createSpan({ name: "llm-call", kind: "client" }); recorder.record(span);

// ... do work ...

endSpan(span, { status: "ok" });

// Calculate costs const meter = new CostMeter(); meter.record({ inputTokens: 1000, outputTokens: 500, model: "gpt-4o", }); console.log(meter.totalCost); // Cost in USD

// Build transcript from events const transcript = buildTranscript(events); console.log(transcript); `

API Reference

Tracing

| Export | Type | Description | |--------|------|-------------| | SpanRecorder | Class | Record and query spans | | createSpan | Function | Create a new span | | endSpan | Function | End a span with status | | ddSpanEvent | Function | Add an event to a span | | generateTraceId | Function | Generate a unique trace ID |

Span Types

| Export | Type | Description | |--------|------|-------------| | Span | Interface | A single trace span | | SpanKind | Type | Span type (client, server, internal) | | SpanStatus | Type | Span completion status | | SpanEvent | Interface | Event within a span | | SpanNode | Interface | Span tree node | | TraceContext | Interface | Trace propagation context |

Timeline

| Export | Type | Description | |--------|------|-------------| | Timeline | Class | Build and query run timelines | | uildTranscript | Function | Build transcript from events | | TimelineEvent | Interface | Event in a timeline | | TranscriptEntry | Interface | Transcript line item |

Telemetry

| Export | Type | Description | |--------|------|-------------| | CostMeter | Class | Track token costs | | calculateCost | Function | Calculate cost from tokens | | calculateContextPressure | Function | Calculate context utilization | | DEFAULT_MODEL_PRICING | Constant | Default pricing for common models | | ConsoleTelemetryProvider | Class | Console-based telemetry output |

Telemetry Types

| Export | Type | Description | |--------|------|-------------| | UsageStats | Interface | Token usage statistics | | ModelPricing | Interface | Per-1M-token pricing | | ContextPressure | Interface | Context window utilization | | TelemetryProvider | Interface | Custom telemetry backend |

OTLP Export (P1-9)

| Export | Type | Description | |--------|------|-------------| | createOtlpSpanExporter | Function | OTLP/HTTP JSON exporter (config or env endpoint) | | resolveOtlpEndpoint | Function | Resolve endpoint from config / OTEL_EXPORTER_OTLP_* | | mapSpanToOtlp | Function | Map custom Span → OTLP JSON span | | buildOtlpExportRequest | Function | Wrap spans into ExportTraceServiceRequest | | SpanExporter | Interface | export(spans) / shutdown() seam |

Endpoint resolution (first match wins):

  1. config.endpoint
  2. OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
  3. OTEL_EXPORTER_OTLP_ENDPOINT + /v1/traces

Headers: OTEL_EXPORTER_OTLP_HEADERS (k1=v1,k2=v2) merged with config.headers. Resource: config.resourceAttributes (default service.name=vinhnt-sdk, override via OTEL_SERVICE_NAME in attributes).

import { createOtlpSpanExporter, SpanRecorder } from "@vinhnt-sdk/trace";

const recorder = new SpanRecorder();
// ... record spans ...

const exporter = createOtlpSpanExporter({
  endpoint: "http://localhost:4318/v1/traces", // or set env only
  resourceAttributes: { "service.name": "my-agent", "deployment.environment": "dev" },
});
await exporter.export(recorder.getSpans());
await exporter.shutdown();

No exporter is created unless you call createOtlpSpanExporter — default telemetry path unchanged.

Usage Examples

Cost Tracking

` ypescript import { CostMeter, DEFAULT_MODEL_PRICING } from "@vinhnt-sdk/trace";

const meter = new CostMeter();

// Track usage across multiple calls meter.record({ inputTokens: 1000, outputTokens: 500, model: "gpt-4o" }); meter.record({ inputTokens: 2000, outputTokens: 1000, model: "gpt-4o-mini" });

console.log(meter.totalCost); // Total cost in USD `

Custom Telemetry Provider

` ypescript import type { TelemetryProvider } from "@vinhnt-sdk/trace";

const customProvider: TelemetryProvider = { name: "datadog", async recordSpan(span) { await sendToDatadog(span); }, async recordUsage(usage) { await sendMetricsToDatadog(usage); }, }; `

Dependencies

  • @vinhnt-sdk/schema >=0.5.0

License

MIT