LangChain

LangChain observability for chains, agents and RAG pipelines

by Obseria · AI and LLMs
  • OpenTelemetry
  • AI Observability
  • AI and LLMs
Category
AI and LLMs
Key metrics
8
Ready-made
5 dashboards & alerts
Setup
3 steps
Standard
OTLP

Instrument LangChain with OpenTelemetry and Obseria shows every chain, agent step, tool call, retriever and model call as one nested trace, with token usage rolled up across all steps.

The whole chain in one trace

Prompts, retrievers, model calls, output parsers and tools appear as nested spans, so you see which step is slow or failing.

Agents you can follow

Agent loops with planning, tool calls and feedback are visible step by step, and Obseria visualizes them as a graph.

Tokens across every step

Token usage is recorded per model call and summed per trace, so you know what one user question really costs.

Obseria interface

Obseria apps and capabilities: observability, APM, infrastructure and integrations
Obseria home dashboard with service health, open problems, SLO compliance and ingestion
Obseria trace explorer with span list and span attributes

Ready the moment data arrives

  • Chain latency broken down by step
  • Token usage per chain, agent and model
  • Alert on failing tools and parser errors
  • Alert on agents with unusually many steps
  • Slowest retrievers and vector store lookups

LangChain components Obseria monitors

Chains and LCEL runnables

Each runnable in a chain becomes a span with its duration and status, nested under the chain.

Agents and tools

Agent steps and tool invocations appear in order, including tool errors and repeated calls.

Retrievers and vector stores

Retrieval steps show how long document lookup takes before the model is called.

Chat models and LLMs

Model calls carry model name and token usage, with the provider instrumentation adding full GenAI attributes.

LangGraph

LangGraph is built on LangChain, so graph nodes appear as the chain steps they are underneath.

Python and JavaScript

Instrumentation is available for LangChain in Python and through the OpenLLMetry Node.js SDK.

The LangChain signals that matter

Obseria collects these values automatically and shows them in ready-made dashboards and alerts.

MetricUnitWhat it tells you
gen_ai.client.operation.durationsDuration of each model call inside the chain, to separate model time from retrieval and tools.
gen_ai.client.token.usage{token}Tokens per model call, split into input and output; summed per trace for the cost of one request.
gen_ai.request.modelModel used in each step, useful when chains mix a small router model with a larger answer model.
gen_ai.usage.input_tokens{token}Prompt tokens per call, which grow with retrieved documents and memory.
gen_ai.usage.output_tokens{token}Generated tokens per call, the main driver of model latency.
gen_ai.operation.nameOperation type of a span, for example chat, embeddings or tool execution.
error.typeError class of failed steps, from model rate limits to tool exceptions and parser errors.
traceloop.span.kindSpan attribute (not a metric) that marks each step as workflow, task, agent or tool; together with the span duration it shows the slowest step.

Set up LangChain monitoring in minutes

  1. 1

    Install the instrumentation

    Add traceloop-sdk and opentelemetry-instrumentation-langchain, plus the instrumentation for your model provider such as openai or anthropic.

  2. 2

    Point the exporter at Obseria

    Set TRACELOOP_BASE_URL and TRACELOOP_HEADERS to your Obseria OTLP endpoint and token; set TRACELOOP_TRACE_CONTENT=false to keep prompts and documents local.

  3. 3

    Initialize before LangChain

    Call Traceloop.init before LangChain and the model clients are imported, run one chain and open the trace in Obseria.

Example configuration · PYTHON
# pip install langchain langchain-openai traceloop-sdk \
#     opentelemetry-instrumentation-langchain opentelemetry-instrumentation-openai
#
# Environment (set in your deployment):
#   TRACELOOP_BASE_URL=${OBSERIA_OTLP_ENDPOINT}
#   TRACELOOP_HEADERS=Authorization=Bearer%20${OBSERIA_TOKEN}
#   TRACELOOP_TRACE_CONTENT=false   # keep prompts, documents and outputs out of spans
#   OTEL_SERVICE_NAME=knowledge-bot
from traceloop.sdk import Traceloop

# Initialize before LangChain and the model clients are imported.
Traceloop.init(app_name="knowledge-bot", disable_batch=False)

from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

prompt = ChatPromptTemplate.from_template("Answer briefly: {question}")
chain = prompt | ChatOpenAI(model="gpt-4o-mini")

# One nested trace: chain -> prompt -> model call with token usage
chain.invoke({"question": "How do I reset my password?"})

Why LangChain observability matters

LangChain makes it easy to compose prompts, models, retrievers, tools and memory into chains and agents. The same composition makes production behavior hard to understand. One user question can trigger a retrieval step, a reranking call, a model call that decides to use a tool, the tool itself and a second model call that writes the answer. When the answer is slow, wrong or expensive, logs from individual steps rarely explain why. LangChain observability captures the whole flow as one trace.

With OpenTelemetry instrumentation, each chain, runnable, agent step, tool call and retriever becomes a span, nested in the order it ran. Model calls inside the chain carry the GenAI attributes for model and token usage. Because the trace continues into your HTTP handler, database and vector store, you see the LLM workflow in the context of the service around it.

Signals that matter for LangChain monitoring

  • Latency per step: span duration for each chain, retriever, tool and model call. The slowest step is often not the model, but retrieval or an external tool.
  • Model time and tokens: gen_ai.client.operation.duration, gen_ai.usage.input_tokens and gen_ai.usage.output_tokens per model call, summed per trace for the real cost of one request.
  • Model per step: gen_ai.request.model shows which model each step used, important when chains route between models.
  • Agent depth: the number of model and tool spans per agent run. A sudden increase points to loops or tools that do not return useful results.
  • Errors: error.type and exceptions on spans separate model errors, tool failures and output parser errors.

Common LangChain problems and how to detect them

Agents that loop

An agent that cannot reach its goal keeps calling tools and the model. Without tracing this looks like a slow request. In Obseria the trace shows the repeated pattern, token usage per run jumps, and agent workflows appear as a graph where loops stand out.

Slow retrieval

Vector store lookups, embedding calls and rerankers add latency before the model even starts. Comparing retriever span duration with model duration tells you where to optimize first.

Context that is too large or too small

Retrieving too many chunks inflates input tokens and cost; retrieving too few leads to weak answers. Input tokens per call, together with retrieval spans, make the effect of chunking and top-k settings measurable.

Output parser failures

Structured output can fail to parse when a model changes its formatting. Errors on parser spans and the retries they trigger show up directly in the trace, often right after a model switch.

Silent regressions after a prompt change

A reworded prompt can change answer length, tool usage and latency at once. Comparing steps, tokens and duration per service.version shows the effect of the change in production.

Prompts, documents and personal data

Chains handle user input, retrieved documents and model output, all of which can contain personal or confidential data. OpenLLMetry records this content on spans by default. Set TRACELOOP_TRACE_CONTENT=false to export only structure, timing, models and token counts. If content is needed for debugging or evaluations, Obseria can store it in full, masked or as a hash, detects and masks personal data and keeps data in the EU.

Best practices for LangChain tracing

  1. Initialize instrumentation before importing LangChain and the model clients.
  2. Install the provider instrumentation as well, so model calls carry complete GenAI attributes.
  3. Give chains and agents clear names, so spans are readable in the trace.
  4. Set service.name and service.version and compare releases after prompt or model changes.
  5. Alert on agent runs with unusually many steps and on token usage anomalies per chain.

How Obseria helps with LangChain observability

Obseria receives LangChain traces over OTLP and shows them next to the rest of your application. AI Observability adds token cost per model, feature and tenant, agent workflows visualized as a graph, and guardrails and evaluations for response quality, including retrieval quality for RAG pipelines. Model Performance compares the models your chains use by calls, errors, latency and tokens. When a chain slows down or fails, Obseria Intelligence correlates the failing step, the model, upstream services and recent deployments and presents the root cause with its chain of evidence.

Learn more

LangChain monitoring FAQ

No. The OpenTelemetry instrumentation for LangChain sends standard OTLP traces directly to Obseria. You can keep using other tools in parallel if you want.

Yes. LangGraph is built on LangChain, and the LangChain instrumentation covers it. Graph nodes appear as the chain steps they run underneath.

The LangChain instrumentation captures the structure of chains and agents. The instrumentation for OpenAI, Anthropic or Bedrock adds the full GenAI attributes of each model call, such as token usage and response model.

Only if you want that. Set TRACELOOP_TRACE_CONTENT=false to export only metadata. Stored content can be masked or hashed in Obseria.

Yes. Obseria AI Observability measures retrieval quality, such as hit relevance and context-window usage per query, and evaluates responses for relevance and faithfulness.

Start monitoring LangChain today

Connect LangChain in minutes with OpenTelemetry or the Obseria Agent. Free for 14 days.