OpenInference LangChain Instrumentation
Actively maintained. Last release 9 days ago, commits in 26 of the last 26 weeks. A safe choice.
pip install openinference-instrumentation-langchainOpenInference LangChain Instrumentation
Python auto-instrumentation library for LangChain.
These traces are fully OpenTelemetry compatible and can be sent to an OpenTelemetry collector for viewing, such as Arize Phoenix or Arize AX.
Compatibility
This instrumentation works with:
- LangChain 1.x (
langchain>=1.0.0): Modern agent framework built on LangGraph - LangChain Classic (
langchain-classic>=1.0.0): Legacy chains and tools (formerlylangchain 0.x) - All LangChain partner packages (
langchain-openai,langchain-anthropic,langchain-google-vertexai, etc.)
The instrumentation hooks into langchain-core, which is the shared foundation used by all LangChain packages.
Installation
For LangChain 1.x (Recommended for New Projects)
pip install openinference-instrumentation-langchain langchain langchain-openai
For LangChain Classic (Legacy Applications)
pip install openinference-instrumentation-langchain langchain-classic langchain-openai
For Both (Migration Scenarios)
pip install openinference-instrumentation-langchain langchain langchain-classic langchain-openai
Quickstart
Example with LangChain 1.x (New Agent Framework)
Install packages needed for this demonstration.
pip install openinference-instrumentation-langchain langchain langchain-openai arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp
Start the Phoenix app in the background as a collector. By default, it listens on http://localhost:6006. You can visit the app via a browser at the same address.
The Phoenix app does not send data over the internet. It only operates locally on your machine.
python -m phoenix.server.main serve