openinference-instrumentation-langchain 0.1.76


pip install openinference-instrumentation-langchain

  Latest version

Released: Sep 10, 2026

Project Links

Meta
Author: OpenInference Authors
Requires Python: <3.15,>=3.10

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers

License
  • OSI Approved :: Apache Software License

Programming Language
  • Python
  • Python :: 3
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14

OpenInference 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.

pypi

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 (formerly langchain 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

The following Python code sets up the LangChainInstrumentor to trace langchain and send the traces to Phoenix at the endpoint shown below.

from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
from openinference.instrumentation.langchain import LangChainInstrumentor
from opentelemetry import trace as trace_api
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk import trace as trace_sdk
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor

endpoint = "http://127.0.0.1:6006/v1/traces"
tracer_provider = trace_sdk.TracerProvider()
trace_api.set_tracer_provider(tracer_provider)
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
tracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))

LangChainInstrumentor().instrument()

To demonstrate tracing, we'll create a simple agent. First, configure your OpenAI credentials.

import os

os.environ["OPENAI_API_KEY"] = "<your openai key>"

Now we can create an agent and run it.

def get_weather(city: str) -> str:
    """Get the weather for a city."""
    return f"The weather in {city} is sunny!"

model = ChatOpenAI(model="gpt-4")
agent = create_agent(model, tools=[get_weather])
result = agent.invoke({"messages": [{"role": "user", "content": "What's the weather in Paris?"}]})
print(result)

Example with LangChain Classic (Legacy Chains)

For legacy applications using LangChain Classic:

from langchain_classic.chains import LLMChain
from langchain_core.prompts import PromptTemplate
from langchain_openai import OpenAI

# ... (same instrumentation setup as above)

prompt_template = "Tell me a {adjective} joke"
prompt = PromptTemplate(input_variables=["adjective"], template=prompt_template)
llm = LLMChain(llm=OpenAI(), prompt=prompt, metadata={"category": "jokes"})
completion = llm.predict(adjective="funny", metadata={"variant": "funny"})
print(completion)

Visit the Phoenix app at http://localhost:6006 to see the traces.

More Info

0.1.76 Sep 10, 2026
0.1.75 Sep 09, 2026
0.1.74 Sep 04, 2026
0.1.73 Aug 28, 2026
0.1.72 Aug 25, 2026
0.1.71 Aug 24, 2026
0.1.70 Aug 07, 2026
0.1.69 Aug 04, 2026
0.1.68 Jul 30, 2026
0.1.67 Jul 01, 2026
0.1.66 May 18, 2026
0.1.65 May 14, 2026
0.1.64 May 10, 2026
0.1.63 Apr 22, 2026
0.1.62 Apr 03, 2026
0.1.61 Feb 26, 2026
0.1.60 Feb 24, 2026
0.1.59 Feb 12, 2026
0.1.58 Jan 06, 2026
0.1.57 Dec 22, 2025
0.1.56 Dec 04, 2025
0.1.55 Nov 10, 2025
0.1.54 Oct 23, 2025
0.1.53 Oct 10, 2025
0.1.52 Sep 11, 2025
0.1.51 Aug 28, 2025
0.1.50 Jul 30, 2025
0.1.49 Jul 24, 2025
0.1.48 Jul 23, 2025
0.1.47 Jul 21, 2025
0.1.46 Jul 03, 2025
0.1.45 Jul 02, 2025
0.1.44 Jul 01, 2025
0.1.43 May 20, 2025
0.1.42 Apr 28, 2025
0.1.41 Apr 11, 2025
0.1.40 Apr 07, 2025
0.1.39 Apr 04, 2025
0.1.38 Apr 03, 2025
0.1.37 Mar 19, 2025
0.1.36 Mar 14, 2025
0.1.35 Mar 06, 2025
0.1.34 Mar 05, 2025
0.1.33 Feb 18, 2025
0.1.32 Feb 13, 2025
0.1.31 Feb 04, 2025
0.1.30 Jan 29, 2025
0.1.29 Oct 31, 2024
0.1.28 Sep 10, 2024
0.1.27 Aug 10, 2024
0.1.26 Aug 01, 2024
0.1.25 Aug 01, 2024
0.1.24 Aug 01, 2024
0.1.23 Jul 25, 2024
0.1.22 Jul 17, 2024
0.1.21 Jul 10, 2024
0.1.20 Jun 20, 2024
0.1.19 Jun 05, 2024
0.1.18 Jun 04, 2024
0.1.17 Jun 03, 2024
0.1.16 May 21, 2024
0.1.15 May 10, 2024
0.1.14 Mar 20, 2024
0.1.13 Mar 20, 2024
0.1.12 Mar 13, 2024
0.1.11 Feb 24, 2024
0.1.10 Feb 24, 2024
0.1.9 Feb 15, 2024
0.1.8 Feb 15, 2024
0.1.7 Feb 15, 2024
0.1.6 Feb 14, 2024
0.1.5 Feb 12, 2024
0.1.4 Feb 09, 2024
0.1.3 Feb 08, 2024
0.1.2 Feb 08, 2024
0.1.1 Feb 01, 2024
0.1.0 Jan 26, 2024
Extras:
Dependencies:
openinference-instrumentation (>=0.1.61)
openinference-semantic-conventions (>=0.1.37)
opentelemetry-api
opentelemetry-instrumentation
opentelemetry-semantic-conventions
wrapt