Send LangChain and LangGraph Traces to KloudMate
LangChain and LangGraph don’t export OpenTelemetry traces on their own. The OpenInference instrumentation for LangChain adds them: it creates a span for each agent run, model call, and tool call, with token counts and messages. Send those spans to KloudMate to see each run in AI Observability. The same instrumentation covers LangGraph, because LangGraph runs on LangChain.
Prerequisites
Section titled “Prerequisites”- A KloudMate API key, from Settings → Ingest Keys.
- Python 3.11 or later.
Instrument your app
Section titled “Instrument your app”You can run your app under opentelemetry-instrument without changing its code, or set up the instrumentation in code.
Install the instrumentation and the OpenTelemetry launcher:
Point the exporter at KloudMate and start your app with opentelemetry-instrument, which loads the LangChain instrumentation automatically:
Install the instrumentation and the OpenTelemetry SDK:
Set up a tracer provider and instrument LangChain before you build your chain or graph:
OTLPSpanExporter() reads the endpoint and header from the same OTEL_EXPORTER_OTLP_* variables shown in the other tab. Call provider.shutdown() before a script exits, so the last spans are sent.
KloudMate expects the raw API key in the Authorization header, with no Bearer prefix. If the KloudMate agent runs on the same machine, set the endpoint to http://localhost:4318 and leave out the header.
Name your agent
Section titled “Name your agent”OpenInference marks a span as an agent only when its name contains “agent”. Give your graph a name such as support_agent so each run appears as a turn of that agent:
A graph left with the default name LangGraph has no agent span, so its runs are named after the model instead.
Group a conversation
Section titled “Group a conversation”Wrap each call in using_session() with an ID that stays the same for the whole conversation, such as your chat or thread ID:
To attach a user ID as well, use using_attributes(session_id="chat-42", user_id="user-17").
Control what’s captured
Section titled “Control what’s captured”OpenInference records prompts, responses, and tool arguments by default. To leave them out, set these variables before your app starts:
Hidden values are replaced with __REDACTED__. Token counts, models, and latency are still recorded.
Avoid double counting
Section titled “Avoid double counting”Instrument only one layer. If you also install the OpenAI or Anthropic SDK instrumentation, each model call is recorded twice, once by LangChain and once by the provider SDK, and AI Observability counts both.
Check the data
Section titled “Check the data”Run the agent once, then open AI Observability → Traces. The run appears as support_agent Turn with its model, steps, tokens, and estimated cost. OpenInference doesn’t report cache writes, so the estimated cost can be slightly lower than your bill when prompt caching is on.