Skip to main content
LangChain.js is the JavaScript/TypeScript port of LangChain — a framework for composing LLM calls, tools, and retrieval into chains and agents. Arize AX captures every chain, prompt, tool call, and LLM call by manually instrumenting the @langchain/core/callbacks/manager module via the @arizeai/openinference-instrumentation-langchain package.

Prerequisites

Launch Arize AX

  1. Sign in to your Arize AX account.
  2. From Space Settings, copy your Space ID and API Key. You will set them as ARIZE_SPACE_ID and ARIZE_API_KEY below.

Install

Configure credentials

Setup tracing

Run LangChain.js

Expected output

Verify in Arize AX

  1. Open your Arize AX space and select project langchain-js-tracing-example.
  2. You should see a new trace within ~30 seconds containing a RunnableSequence parent span (CHAIN) wrapping ChatPromptTemplate (CHAIN), ChatOpenAI (LLM, model gpt-5.5), and StrOutputParser (CHAIN) child spans, with the prompt, response, and token usage attached to the LLM span.
  3. If no traces appear, see Troubleshooting.

Check from the skill, CLI, or SDK

Confirm spans are actually reaching your Arize AX project. Use whichever fits your workflow — the skill and CLI work for any framework; the SDK check is shown for each language.
Install the Arize Skills plugin and let your coding agent check for you:
Then prompt your agent:
Use the arize-trace skill to export and analyze recent traces from my project. Confirm spans are arriving, and summarize any errors or latency issues.

Span filter

The basic setup above exports every span the tracer provider receives. When LangChain runs alongside other instrumentations (@opentelemetry/instrumentation-http, Next.js’s built-in tracing, framework HTTP middleware), those instrumentations emit POST / GET spans for every fetch, and the LangChain spans nest under those HTTP roots. OpenInference-tagged spans carry an openinference.span.kind attribute that the LangChain instrumentor sets — checking for it is enough to drop non-OpenInference spans. Swap SimpleSpanProcessor in instrumentation.ts for a filtering subclass:
The trade-off: filtering removes the HTTP root spans, which orphans the surviving LangChain spans on the Traces tab (no parent to anchor them) — they remain visible on the Spans tab. If you also need a clean trace tree on the Traces tab, swap the filter for a span processor that promotes the first LangChain span to root by clearing its parent ID:
Wire it in by replacing the OpenInferenceFilteringSpanProcessor in instrumentation.ts:
The recipe needs two additional dependencies: npm install @arizeai/openinference-core lru-cache.

Troubleshooting

  • No traces in Arize AX. Confirm ARIZE_SPACE_ID and ARIZE_API_KEY are set in the same shell that runs example.ts. Enable OpenTelemetry debug logs with export OTEL_LOG_LEVEL=debug and re-run.
  • LangChain spans missing but other spans present. instrumentation.manuallyInstrument(CallbackManagerModule) must run before any code creates a LangChain client. Make sure import { provider } from "./instrumentation" (or a side-effect-only import "./instrumentation") is the first import in your entry point.
  • 401 from OpenAI. Verify OPENAI_API_KEY is set and has access to gpt-5.5. Swap for a model your key can call.
  • Process exits before spans flush. Spans are exported asynchronously; always await provider.forceFlush() (or provider.shutdown()) before the process exits to avoid losing trailing spans.
  • Root chain span missing with a batching processor. LangChain.js runs tracing callbacks in the background by default, so the outer chain span’s onEnd can fire after chain.invoke() resolves. A BatchSpanProcessor (including the RootAwareOpenInferenceProcessor recipe) then races a bare forceFlush() and drops that trailing root span, orphaning its children. Call await awaitAllCallbacks() (from @langchain/core/callbacks/promises) before flushing, or set LANGCHAIN_CALLBACKS_BACKGROUND=false. SimpleSpanProcessor hides the race because its per-span export keeps the event loop alive.
  • LangChain spans orphaned on the Traces tab. Expected when isOpenInferenceSpan is the only filter — see Span filter above for the RootAwareOpenInferenceProcessor recipe that promotes the first LangChain span to root.

Version compatibility

Instrumentation >=1.0.0 supports both attribute masking and context attribute propagation. The matrix below tracks instrumentor support across LangChain core releases:

Resources

LangChain.js Documentation

OpenInference LangChain Instrumentor (JS/TS)

LangChain.js GitHub