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

@telemetry-dev/openai

v0.1.0

Published

OpenAI SDK instrumentation for telemetry.dev: generation and embedding spans for the official openai Node SDK.

Downloads

192

Readme

@telemetry-dev/openai

OpenAI SDK instrumentation for telemetry.dev. It wraps the official openai Node SDK and emits telemetry.dev generation and embedding spans through @telemetry-dev/sdk.

Install

pnpm add @telemetry-dev/sdk @telemetry-dev/openai openai

Initialize the core SDK first:

import { init, flush, shutdown } from "@telemetry-dev/sdk";

init({
  apiKey: process.env.TELEMETRY_DEV_API_KEY,
  baseUrl: process.env.TELEMETRY_DEV_BASE_URL,
  serviceName: "my-service",
});

// app code...
await flush();
await shutdown();

Per-client wrapping

import OpenAI from "openai";
import { wrapOpenAI } from "@telemetry-dev/openai";

const openai = wrapOpenAI(new OpenAI({ apiKey: process.env.OPENAI_API_KEY }));

await openai.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Tell me a joke about OpenTelemetry" }],
});

Use this when you want explicit control over which clients are instrumented.

Global instrumentation

import OpenAI from "openai";
import { instrumentOpenAI, uninstrumentOpenAI } from "@telemetry-dev/openai";

instrumentOpenAI();
const openai = new OpenAI();

try {
  await openai.responses.create({
    model: "gpt-4o-mini",
    input: "Tell me a joke about OpenTelemetry",
  });
} finally {
  uninstrumentOpenAI();
}

Use this as the app-wide one-liner at startup when all OpenAI clients should be instrumented.

Instrumented surfaces

  • client.chat.completions.create(...)
  • client.chat.completions.parse(...) is covered by the OpenAI SDK because it routes through create()
  • client.chat.completions.stream(...) is covered for the same reason
  • client.responses.create(...)
  • client.responses.parse(...) is covered by the OpenAI SDK because it routes through create()
  • client.responses.stream({ input, model, ... }) is covered for new responses because it routes through create({ stream: true })
  • client.embeddings.create(...)

The integration maps native OpenAI request/response shapes directly into telemetry.dev fields. It does not normalize messages into another schema.

Streaming

Chat completion streams are traced. Requests are sent unchanged by default, so token usage is only captured when the caller sets stream_options.include_usage themselves. Pass { injectStreamUsage: true } to wrapOpenAI or instrumentOpenAI to inject stream_options.include_usage automatically; the synthetic usage-only chunk is then hidden from the caller. Injection is opt-in because some providers reject stream_options — for example Azure OpenAI "on your data" (data_sources) returns 400 for it while plain stream: true works.

const openai = wrapOpenAI(new OpenAI(), { injectStreamUsage: true });

Responses API streams are traced through responses.create({ stream: true }); terminal response.completed, response.failed, and response.incomplete events close the span.

Embeddings

Embedding calls emit gen_ai.operation.name = "embeddings", request model/input, response model, and token usage. Embedding vectors are intentionally not captured as output.

Azure OpenAI

wrapOpenAI(new AzureOpenAI(...)) records provider azure.ai.openai. Global prototype instrumentation defaults to provider detection from the resource's client when available.

Limitations

  • responses.stream({ response_id: ... }) resumes an existing response through retrieve(), which is not instrumented in this version.
  • Wrapped calls preserve withResponse() and asResponse(), but the returned promise is not guaranteed to be instanceof the OpenAI SDK's internal APIPromise class.
  • Unawaited OpenAI calls keep the SDK's lazy behavior: no request is made and no span is finished until the returned promise/stream is consumed.