LangChain
Add OpenInference instrumentation to your LangChain application and point it at a Sazabi endpoint to forward chain, tool, and LLM call traces.
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 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
Install and initialize OpenInference
Install the OpenInference instrumentation for your LangChain runtime and run the initialization snippet once at startup before importing LangChain.
Python
pip install openinference-instrumentation-langchain \
opentelemetry-sdk \
opentelemetry-exporter-otlp-proto-httpAdd the following before importing LangChain in your application:
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
npm install @arizeai/openinference-instrumentation-langchain \
@opentelemetry/sdk-trace-node \
@opentelemetry/exporter-trace-otlp-proto \
@langchain/coreWire in the callbacks manager by hand before running any chains:
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);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.
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
Set up with the CLI
You can also register the LangChain log source with the Sazabi CLI (installed and authenticated — see CLI reference).
Registering the source mints the same intake URL the dashboard shows above (the public key is embedded in its hostname):
sazabi log-sources create langchain --mode connectionlessThe 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 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.