Integrations / LangChain

Trace LangChain chains and agents

To trace LangChain with Tracify, pass the Tracify callback handler in the callbacks list of your chain or agent. Every chain, model call and tool call becomes a span in one trace, with tokens and timing.

Your code

LangChain

Tracify

One run.

  • 01One trace per chain or agent run
  • 02Model calls with tokens and time to first token
  • 03Tool calls with input and output
  • 04Errors and retries in order

Setup

5 steps.

  1. 01

    Install

    The callback handler lives in an optional part of the Python SDK, so LangChain stays your only extra dependency.

    bash
    pip install "tracify-sdk[langgraph]"
  2. 02

    Set your project key

    Create a project in Tracify, copy its API key and put it in the environment where your code runs. The SDK reads it from there, so nothing is hard-coded.

    bash
    export TRACIFY_API_KEY="tracify_sk_live_..."
  3. 03

    Pass the handler to your chain

    Add it to the callbacks of any runnable: a chain, a retriever, an agent executor or a LangGraph graph. Child steps inherit it, so you only add it once at the top.

    python
    import tracify
    
    handler = tracify.langgraph_callback()
    
    result = agent_executor.invoke(
        {"input": "Summarize today's failed runs"},
        config={"callbacks": [handler]},
    )
  4. 04

    Or in TypeScript

    The TypeScript SDK ships a matching handler. It needs no extra LangChain package of its own.

    typescript
    import { TracifyLangGraphHandler } from "tracify-sdk";
    
    const result = await chain.invoke(
      { question: "What changed in the last release?" },
      { callbacks: [new TracifyLangGraphHandler()] },
    );
  5. 05

    Run it once and look

    Run your code one time, then open the Tracing page of your project. Your chain shows up as a run with its steps in order, plus the tokens, time and any error for each call.

Good to know

Same handler as LangGraph

LangChain and LangGraph use the same callback system, so this is the same handler as on the LangGraph page. Use that page if you build graphs with several nodes.

Good to know

Wrapping a run in your own step

If you call the chain from inside a Tracify run or step, the chain joins that run instead of starting a new one.

Full details in the documentation. All integrations are listed on the integrations page.

Do I need LangSmith to use this?
No. The Tracify handler is independent of LangSmith. You can run both side by side if you want.
Can I trace a LangChain agent that calls tools?
Yes. Each tool call is its own span with its input, output and time, under the agent run that called it.
Does streaming still work?
Yes. The handler sees each streamed token, so the time to first token is recorded for streamed model calls.
Which LangChain versions are supported?
Python needs langchain-core 0.2 or newer. The TypeScript handler follows the LangChain callback shape and does not import LangChain, so it keeps working across versions.

Send your first trace.

Free to start.