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

# LangChain

> Add OpenInference instrumentation to your LangChain application and point it at a Sazabi endpoint to forward chain, tool, and LLM call traces.

[All LangChain integration capabilities](https://docs.sazabi.com/catalogs/integrations/langchain)

## About

Forward OpenTelemetry traces from your LangChain application into Sazabi. LangChain does not emit OpenTelemetry on its own — you add an instrumentation package such as [OpenInference](https://github.com/Arize-ai/openinference) that creates spans for your chains, tools, and LLM calls, then point those spans at a Sazabi endpoint.

## Prerequisites

* A Python or TypeScript/JavaScript LangChain application. These are the only runtimes with a LangChain OpenInference package today.
* Your Sazabi intake URL (shown above).

## Set up in the dashboard

**Step 1**

### Install and initialize OpenInference

Install the OpenInference instrumentation for your LangChain runtime and run the initialization snippet once at startup before importing LangChain.

**Python**

```bash theme={"system"}
pip install openinference-instrumentation-langchain \
  opentelemetry-sdk \
  opentelemetry-exporter-otlp-proto-http
```

Add the following before importing LangChain in your application:

```python theme={"system"}
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from openinference.instrumentation.langchain import LangChainInstrumentor

provider = TracerProvider(resource=Resource.create({"service.name": "my-langchain-app"}))
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
trace.set_tracer_provider(provider)

LangChainInstrumentor().instrument()
```

**TypeScript**

```bash theme={"system"}
npm install @arizeai/openinference-instrumentation-langchain \
  @opentelemetry/sdk-trace-node \
  @opentelemetry/exporter-trace-otlp-proto \
  @langchain/core
```

Wire in the callbacks manager by hand before running any chains:

```typescript theme={"system"}
import {
  NodeTracerProvider,
  BatchSpanProcessor,
} from "@opentelemetry/sdk-trace-node";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import { Resource } from "@opentelemetry/resources";
import { LangChainInstrumentation } from "@arizeai/openinference-instrumentation-langchain";
import * as CallbackManagerModule from "@langchain/core/callbacks/manager";

const provider = new NodeTracerProvider({
  resource: new Resource({ "service.name": "my-langchain-app" }),
});
provider.addSpanProcessor(new BatchSpanProcessor(new OTLPTraceExporter()));
provider.register();

// LangChain.js has no traditional auto-instrumentable module structure, so the
// callbacks manager must be wired in by hand.
new LangChainInstrumentation().manuallyInstrument(CallbackManagerModule);
```

> [!WARNING]
>
> LangChain.js has no module structure that OpenInference can auto-instrument,
> so you must wire in the callbacks manager by hand as shown above. Forgetting
> this step produces no spans even if the provider is initialized.

**Step 2**

### Set OTLP environment variables

Set these environment variables in your application environment so they are present when the process starts. The OpenTelemetry SDK reads them automatically.

* `OTEL_EXPORTER_OTLP_ENDPOINT` — your intake URL (shown above)
* `OTEL_EXPORTER_OTLP_PROTOCOL` — `http/protobuf`

**Step 3**

### Hand off the change

Commit these changes on a new branch, push it, and open a pull request. Keep the intake URL and any keys in environment variables or a secret store, and commit only configuration that references them.

## Set up with the CLI

You can also register the LangChain log source with the [Sazabi CLI](https://docs.sazabi.com/reference/cli.md) (installed and authenticated — see [CLI reference](https://docs.sazabi.com/reference/cli/log-sources.md)).

Registering the source mints the same intake URL the dashboard shows above (the public key is embedded in its hostname):

```bash theme={"system"}
sazabi log-sources create langchain --mode manual
```

The command prints the intake URL for the new source — copy the whole URL and point your sender at it using the configuration shown above. Run `sazabi log-sources get <log-source-id>` at any time to reprint the endpoint, or `sazabi log-sources list` to see every log source in the project.

## Verify

Run a chain or agent invocation. Open the [Intake page](https://docs.sazabi.com/guides/instrument/intake.md) in the Sazabi dashboard and confirm traces from the **LangChain** source appear. Traces typically arrive within a minute or two of the invocation.

## Troubleshooting

**No traces appear** — For Python, verify `LangChainInstrumentor().instrument()` runs before any LangChain import. For TypeScript, confirm `manuallyInstrument(CallbackManagerModule)` is called before any chain or agent runs.

**Spans arrive but carry no LLM attributes** — Token counts and model names come from the LLM client's response. If the provider does not return usage data, those fields are absent from the span.

## Further reading

> [card] [Intake](https://docs.sazabi.com/guides/instrument/intake.md)
>
> See per-source ingestion volume and health in the Intake page.

> [card] [Instrument](https://docs.sazabi.com/guides/instrument.md)
>
> Learn how to send data to Sazabi.

> [card] [Log sources](https://docs.sazabi.com/catalogs/log-sources.md)
>
> Browse the full log source catalog.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.