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

@obsunified/sdk

v0.2.1

Published

Thin OpenTelemetry SDK wrapper for obs-unified — adds OpenInference LLM/tool helpers, project propagation, and one-line OTLP setup.

Downloads

126

Readme

@obsunified/sdk (Node)

Thin OpenTelemetry SDK wrapper for obs-unified. One-line init, OpenInference LLM/tool helpers, and project propagation. The OTel ecosystem provides HTTP/DB/RPC auto-instrumentation; this package only adds what OTel doesn't ship out of the box.

Install

npm install @obsunified/sdk \
  @opentelemetry/api \
  @opentelemetry/auto-instrumentations-node

Quickstart

Create an instrumentation.ts that runs before any other module imports HTTP/DB clients — Node's auto-instrumentation only catches imports made after init.

// instrumentation.ts
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
import { init } from "@obsunified/sdk";

const shutdown = init({
  collectorUrl: process.env.OBS_COLLECTOR_URL!,
  ingestKey: process.env.OBS_INGEST_KEY!,
  serviceName: "my-service",
  serviceVersion: "1.4.2",
  environment: "production",
  projectId: "default",
  instrumentations: [getNodeAutoInstrumentations()],
});

process.on("SIGTERM", () => {
  shutdown().finally(() => process.exit(0));
});

Load it before your app:

node --import ./instrumentation.js dist/server.js

You now get HTTP server + client spans, DB client spans (pg / mysql / mongo / redis / etc.), and the request lifecycle for free.

LLM call instrumentation

OTel doesn't ship LLM-specific spans. Wrap your fetch calls so the dashboard's AI tab can render them:

import { withLLMSpan } from "@obsunified/sdk";

const json = await withLLMSpan(
  { provider: "openai", model: "gpt-4o-mini", maxTokens: 1024, turnIndex: i },
  async (span) => {
    const response = await fetch("https://api.openai.com/v1/chat/completions", {
      method: "POST",
      headers: { Authorization: `Bearer ${process.env.OPENAI_API_KEY}` },
      body: JSON.stringify({ model: "gpt-4o-mini", messages, tools }),
    });
    const json = await response.json();
    span.setUsage({
      inputTokens: json.usage?.prompt_tokens,
      outputTokens: json.usage?.completion_tokens,
      totalTokens: json.usage?.total_tokens,
    });
    span.setFinishReason(json.choices?.[0]?.finish_reason);
    return json;
  },
);

The wrap stamps openinference.span.kind=LLM, gen_ai.system, gen_ai.request.model, and post-call gen_ai.usage.* attributes. The underlying OTel HTTP client instrumentation also creates a child span for the actual fetch — you'll see the LLM span as the parent and the HTTP span underneath, with both timings.

Agent tool dispatch

import { withToolSpan } from "@obsunified/sdk";

const result = await withToolSpan(
  { name: "list_widgets", args: parsedArgs },
  async (span) => {
    const out = await dispatch(parsedArgs);
    span.setOutcome(out.error ? "error" : "ok");
    span.setResultCount(out.items?.length ?? 0);
    return out;
  },
);

Project-id propagation

Multi-tenant deployments tag every span with project.id. Two options:

// Static default — applied to every span/log/metric.
init({ ..., projectId: "tenant-acme" });

// Per-request, after auth resolves the project from the request:
import { setProjectId } from "@obsunified/sdk";
app.use((req, res, next) => {
  const projectId = resolveProjectFromAuth(req);
  setProjectId(projectId);
  next();
});

Custom logical boundaries

For business operations worth naming in the trace, use the standard OTel tracer directly:

import { trace } from "@opentelemetry/api";

const tracer = trace.getTracer("my-service");

await tracer.startActiveSpan("orders.fulfill", async (span) => {
  span.setAttribute("order.id", orderId);
  span.setAttribute("order.region", region);
  try {
    return await fulfillOrder(orderId);
  } finally {
    span.end();
  }
});

Self-monitoring (rare)

If your service ingests its own telemetry through the same collector, set selfTelemetry: true in init. Every export will carry X-Telemetry-Self: 1 so the collector's request middleware short-circuits and avoids an export loop. See apps/collector/SELF_INSTRUMENTATION.md for the full design.

Caveats

  • Cloudflare Workers: this SDK targets Node. For Workers, use packages/telemetry-sdk instead — it ships D1/R2/fetch wrappers tailored to the Workers runtime.
  • Auto-instrumentation timing: @opentelemetry/auto-instrumentations-node patches modules on first import. Init must run before your app code, hence the --import ./instrumentation.js Node flag.
  • Span limits: every span is billable storage. Don't wrap inner-loop helpers; only wrap boundaries that matter for blame attribution.