> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenInference

> Trace LangChain and LangGraph applications with OpenInference instrumentation.

## Overview

OpenInference instrumentation for LangChain records LangChain and LangGraph operations as OpenTelemetry spans that use OpenInference semantic conventions. Use it to send traces to an OpenTelemetry-compatible collector or observability backend, including Arize AX and Arize Phoenix.

The package hooks into `langchain-core`, which is shared by LangChain packages. It supports LangChain 1.x, LangChain Classic, and partner packages such as `langchain-openai`, `langchain-anthropic`, and `langchain-google-vertexai`.

## Installation

Install the OpenInference instrumentation package with LangChain:

```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install openinference-instrumentation-langchain langchain langchain-openai
```

For LangChain Classic applications, install `langchain-classic` instead:

```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install openinference-instrumentation-langchain langchain-classic langchain-openai
```

## Use with an OpenTelemetry collector

Install the OpenTelemetry SDK and OTLP exporter (they are not pulled in by the instrumentation package alone), then configure a tracer provider and instrument LangChain before running your application:

```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install opentelemetry-sdk opentelemetry-exporter-otlp
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
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 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)))

LangChainInstrumentor().instrument()
```

The instrumentation records spans for LangChain runs and exports them through the configured tracer provider.

## Use with Arize AX

Arize AX can receive traces from OpenInference instrumentation through OpenTelemetry. Install `arize-otel` with the instrumentation package:

```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install arize-otel openinference-instrumentation-langchain langchain langchain-openai
```

Register an Arize AX tracer provider, then pass it to the LangChain instrumentor:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import os

from arize.otel import register
from openinference.instrumentation.langchain import LangChainInstrumentor

tracer_provider = register(
    space_id=os.environ["ARIZE_SPACE_ID"],
    api_key=os.environ["ARIZE_API_KEY"],
    project_name=os.environ["ARIZE_PROJECT_NAME"],
)

LangChainInstrumentor().instrument(tracer_provider=tracer_provider)
```

## Resources

* [OpenInference LangChain instrumentation repository](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-langchain)
* [Arize AX LangChain tracing guide](https://arize.com/docs/ax/integrations/python-agent-frameworks/langchain/langchain-tracing)
* [OpenInference span customization](https://github.com/Arize-ai/openinference/tree/main/python/openinference-instrumentation#customizing-spans)

***

[Connect these docs](https://docs.langchain.com/use-these-docs.md) to your agent of choice via MCP for real-time answers.

[Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/callbacks/openinference.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
