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

@respan/instrumentation-langchain

v1.2.0

Published

Respan instrumentation plugin for LangChain, LangGraph, and Langflow

Downloads

630

Readme

@respan/instrumentation-langchain

Attach a Respan callback to released LangChain runnables, models, tools, retrievers, and LangGraph invocations. The callback creates real OpenTelemetry spans through the active Respan tracing runtime. It does not patch LangChain globally.

import { Respan } from "@respan/respan";
import { LangChainInstrumentor } from "@respan/instrumentation-langchain";
import { ChatOpenAI } from "@langchain/openai";

const langchain = new LangChainInstrumentor();
const respan = new Respan({ instrumentations: [langchain] });
await respan.initialize();
try {
  const model = new ChatOpenAI({ model: "gpt-4o-mini" });
  await model.invoke(
    "Say hello.",
    langchain.addCallback({ runName: "greeting" }),
  );
} finally {
  await respan.shutdown();
}

RespanCallbackHandler, getCallbackHandler, and addRespanCallback also work when a tracer provider is already configured. Reuse one handler for a workflow so native callback run IDs resolve to actual OTel parent spans. LangchainInstrumentor remains an alias of LangChainInstrumentor.

The plugin accepts new roots after activate() and stops accepting new roots after deactivate(). Runs already started still finish, including their child callbacks. Multiple instrumentors may share a handler; deactivating one owner leaves other active owners enabled.

Capture options

const langchain = new LangChainInstrumentor({
  callbackHandlerOptions: {
    includeContent: true,
    includeMetadata: true,
    recordInputs: true,
    recordOutputs: false,
    maxCachedRuns: 4096,
  },
});

The real tracer sampler runs before payload capture. DROP and RECORD_ONLY runs do not traverse inputs, outputs, metadata, tool definitions, or stream tokens. Constructor options, RESPAN_TRACE_CONTENT=false, TRACELOOP_TRACE_CONTENT=false, the canonical Traceloop content context, and an observed ancestor's allow_trace_content=false are immutable ceilings for each run. A later true cannot restore capture on that run. Input and output lanes can be disabled independently; metadata requires both lanes. Capture reads data properties without executing getters or toJSON methods. Privacy also guards the actual readable span against late processor attributes, events, and status messages.

LLM spans preserve complete canonical messages, multimodal content, tool definitions, final output, and provider usage before optional indexed attributes consume OTel's default attribute budget. Tool execution spans contain {name, arguments}, the real result, and gen_ai.tool.call.id when the native callback exposes it. Agent action notifications remain events on their existing run, so they do not invent tool executions.

Sessions

When you set no session id, the run's thread_id metadata (LangGraph's configurable.thread_id) is sent as the run's Respan session id (respan.sessions.session_identifier), so every turn of one conversation lands in one session with no Respan-specific code.

A session, thread or trace group you set yourself always wins:

import { propagateAttributes } from "@respan/respan";

await propagateAttributes({ session_identifier: "my-session" }, () =>
  graph.invoke(input, config), // runs here keep "my-session"
);

An empty id or one longer than 255 characters is not sent; Respan then detects the session on the server. Unchanged: no other span changes.

Compatibility

Native transport suites cover @langchain/core 0.2.0 with @langchain/openai 0.0.30, and core 1.2.17 with OpenAI 1.6.2. Companion examples cover langchain 1.5.16 and @langchain/langgraph 1.4.21, including agents, tools, structured output, streaming, retries, fallbacks, errors, and graphs. The production floors are @respan/tracing 1.6.1 and @respan/respan-sdk 1.3.4.

The core 0.2.0 tool callback does not expose a tool invocation ID, and OpenAI 0.0.30 omits zero usage counts before its callback. The adapter leaves unavailable fields absent. Returning early from a native model stream may skip both terminal callbacks; this callback-only adapter cannot close that run without a terminal callback. Deactivation leaves that admitted span open for draining; if the native terminal callback never arrives, the span remains unfinished and is not exported. Consume the stream, or abort it and await the resulting native error. LangChain embedding methods do not provide this callback lifecycle; this package does not invent embedding spans. Langflow examples demonstrate explicitly attached TypeScript component callbacks, not an official native Langflow TypeScript SDK.

For explicitly grouped component callbacks, getCallbackHandler() enables groupLangflowRootRuns; reuse it only within one component invocation:

import {
  addRespanCallback,
  getCallbackHandler,
} from "@respan/instrumentation-langchain";

const handler = getCallbackHandler();
const config = addRespanCallback(
  {
    tags: ["langflow"],
    metadata: { framework: "langflow", langflow_component: "RoutingComponent" },
  },
  handler,
);