Skip to Content
Rius

What does Rius record when my agent calls LangChain?

Rius records each LangChain step as its own span, nested to mirror your chain or graph. Model calls carry the model, token usage and messages, and Rius computes the cost from them. The same capture covers LCEL chains, agents and LangGraph nodes, in both Python and TypeScript. One known limit: with a client extra such as openai also installed, text-completion models are still counted twice in token and cost totals.

How it works

The LangChain integration hooks LangChain’s callback system, so anything that runs through it is traced. Once init() has run, you build and run your chains as before. Each step becomes a span typed by what the step is:

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

The nesting follows your chain structure, so the trace reads like your execution graph. Cost is not something you send. Rius computes it on the server from the model and the token counts.

When you also install a client-library integration such as OpenAI, LangChain’s chat model span wraps the client library’s span. You get the framework context and the client-level detail, nested. Each model call is counted once in token and cost totals, and the LangChain span still shows the run’s total. This nesting and single counting need glassflow-rius 1.1.0 or later in Python and @glassflow-ai/rius 1.2.0 or later in TypeScript. Before those versions, the client span started a trace of its own.

Step inputs and outputs and messages are content. The privacy controls you set for the SDK apply to the whole tree, so turning content capture off strips them from every span in the run.

Set it up

  1. Install the integration for your language. In Python the extra installs the instrumentation, not langchain itself, so name the package in a fresh environment:

    pip install "glassflow-rius[langchain]" langchain

    In TypeScript, install the instrumentation package. It also needs @langchain/core, which a LangChain.js application already has. @langchain/core 1.x requires Node 20 or newer.

    npm install @arizeai/openinference-instrumentation-langchain
  2. Call init() once, then build and run your chains exactly as before. No LangChain-specific arguments are needed:

    import rius rius.init(api_key="ri_...", service_name="my-agent") # build and run your chains exactly as before

    In TypeScript, init() finds the callback manager of @langchain/core and patches it. await rius.ready resolves with the integrations that attached, so you can check that langchain is among them.

  3. Run one chain that calls a model and open the trace in the console. You should see the chain’s structure as nested spans, with the model call at the leaf carrying the model, tokens and cost.

For installing the SDK and the other integrations in full, see Integrations. The LangChain integration page covers this setup in detail.

What you get

  • A nested trace of your chain or LangGraph run, with one span per chain, tool, retriever and model call.
  • On each model call, the model, token usage and messages, with cost computed by Rius from the model and token counts.
  • Both layers when you add a client extra: the LangChain span for framework context and the client span for client-level detail, with each call counted once in totals.
  • Step inputs, outputs and messages as content that your privacy controls can strip.

Known limits:

  • With a client extra such as openai also installed, text-completion models, the BaseLLM subclasses such as langchain_openai.OpenAI, are still counted twice in token and cost totals.
  • In Python, an extra installed without langchain makes init() log a DependencyConflict and leaves this integration off.
  • A few other setups also count a call twice, and some streams carry no time to first token. The Integrations page lists these with the layer to keep.

When something else fits

  • If your agent calls a model client directly with no LangChain in the path, use the client-library integration for that provider. The Integrations page lists them.
  • If you use text-completion models and need exact token totals, keep one layer for those calls, as the Integrations page describes, rather than both.

Still stuck? Get help

Last updated on