LangChain

Agents, chains, LCEL runnables, and tools auto-capture as a nested span tree.

Install the instrumentor and every chain, agent, and tool invocation inside wrap your agent becomes a span, with the underlying LLM calls nested below.

What's captured

ConstructSpan kindNested children
AgentExecutor.invoke / arunagentllm per step, tool per tool call
RunnableSequence / LCEL pipefunctionwhatever the pipe contains
@tool / StructuredTooltool
Retrievers (VectorStoreRetriever, BM25)retrieval
Embeddingsllm

Install

npm install langchain @langchain/core @opentelemetry/instrumentation-langchain
pip install langchain langchain-openai opentelemetry-instrumentation-langchain

Minimal example — ReAct agent with tools

import os, trodo
from langchain.agents import create_react_agent, AgentExecutor
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
from langchain import hub

trodo.init(site_id=os.environ['TRODO_SITE_ID'])

@tool
def get_weather(city: str) -> str:
    """Return the current weather in a city."""
    return f'Sunny in {city}, 72F'

llm = ChatOpenAI(model='gpt-4o-mini')
prompt = hub.pull('hwchase17/react')
agent = create_react_agent(llm, [get_weather], prompt)
executor = AgentExecutor(agent=agent, tools=[get_weather])

with trodo.wrap_agent('langchain-react') as run:
    result = executor.invoke({'input': "What's the weather in SF?"})
    run.set_output(result['output'])
import trodo from 'trodo-node';
import { ChatOpenAI } from '@langchain/openai';
import { AgentExecutor, createReactAgent } from 'langchain/agents';

trodo.init({ siteId: process.env.TRODO_SITE_ID });

await trodo.wrapAgent('langchain-react', async (run) => {
  const result = await executor.invoke({ input: "What's the weather in SF?" });
  run.setOutput(result.output);
});

The agent, each LLM step, and each tool call appear as a nested tree under the run.

On this page