Skip to Content
Rius

How do I trace a multi-agent workflow built with LangChain?

Rius traces a multi-agent LangChain or LangGraph workflow as one trace per run, with every chain, node, tool call and model call as its own nested span. You call init() once and run your agents as before. You read the handoffs from the nesting and timing in the trace.

How it works

The Rius LangChain integration hooks LangChain’s callback system, so anything that runs through it is traced: LCEL chains, agents and LangGraph nodes. Each step becomes one span, typed by what it is:

  • Chains are CHAIN spans.
  • Tool calls are TOOL spans.
  • Retrievers are RETRIEVER spans.
  • Model calls are LLM spans with the model, token usage and messages.

Spans nest through the standard OpenTelemetry parent context, so a trace reads like your execution graph. A run is one trace with one root span, and the root’s duration and status are the run’s latency and outcome. When one agent hands work to another, the second agent’s spans appear as children or later siblings in the tree, in the order they ran.

To name the agent as a whole, set the service name in init(). Rius groups traces under that name, or under RIUS_AGENT_NAME if you set it. This names the program you built. The sub-agents inside it appear as spans in the trace. For how traces, spans and kinds fit together, see Concepts.

Set it up

  1. Install the integration and LangChain itself. The extra installs only the instrumentation, so name langchain for a fresh environment: pip install "glassflow-rius[langchain]" langchain. In TypeScript, install npm install @arizeai/openinference-instrumentation-langchain. TypeScript also needs @langchain/core, which a LangChain.js application already has.
  2. Call init() once, before you build or run the graph, and give the service the name you want your agent grouped under:
import rius rius.init(api_key="ri_...", service_name="my-agent") # build and run your chains exactly as before
  1. Run the multi-agent workflow as you do today. You do not change the agent code. The full setup, including the TypeScript form, is on the LangChain integration page.
  2. Optionally wrap the function that handles one request with rius.observe in Python, or observe in TypeScript, so the whole run sits under one root span you control. In TypeScript, name the wrapped function, because an anonymous one traces as anonymous.
  3. Optionally set a session id with rius.session in Python or withSession in TypeScript, so the traces of one conversation group together. Without one, each trace is its own session.
  4. Run one request and open its trace in the console. You should see the graph as nested spans, with the model-call spans carrying model, tokens and cost.

What you get

  • One trace per run. Each user request or job is a single trace, so you find a whole multi-agent run in one place instead of piecing it together.
  • Each step as its own span. Agent chains, graph nodes, tool calls, retrievals and model calls each show their own timing, status and inputs and outputs.
  • Handoffs you can read. The waterfall shows which step started which, how long each took and where the run waited. If a step fails, the waterfall highlights the path from the root to the failing span, so you see which agent broke and what called it.
  • Cost and tokens per agent step. Each model call carries its model and token usage, and Rius computes the cost from them. Costs are list-price estimates in US dollars. A call is counted once in token and cost totals, and the LangChain span still shows the run’s total.
  • Content you control. Step inputs, outputs and messages are content, so the privacy controls apply to the whole tree.

If you also install a client extra such as openai, the client span nests under LangChain’s chat model span, so you get framework context and client detail together. Text-completion models (BaseLLM subclasses) are still counted twice, and the integrations overview links to the cases and which layer to keep.

When something else fits

  • If your agents do not run through LangChain’s callbacks, trace them with the other integrations for your framework or client library, or with observe wrappers around each agent.
  • If you need to send traces from a framework Rius has no integration for, any OpenTelemetry SDK or collector can send OpenTelemetry GenAI traces to Rius.

Still stuck? Get help

Last updated on