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
| Construct | Span kind | Nested children |
|---|---|---|
| Agent invocations | agent | llm per step, tool per tool call |
RunnableSequence / LCEL pipe | llm workflow span | whatever the pipe contains |
@tool / StructuredTool | tool | |
Retrievers (VectorStoreRetriever, BM25) | retrieval | |
| Embeddings | llm |
Install
npm install langchain @langchain/core @traceloop/instrumentation-langchainpip install langchain langchain-openai opentelemetry-instrumentation-langchainMinimal example: LCEL chain
import os, trodo
from langchain_openai import ChatOpenAI
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
trodo.init(site_id=os.environ['TRODO_SITE_ID'])
chain = (
PromptTemplate.from_template('Answer in one sentence: {question}')
| ChatOpenAI(model='gpt-4o-mini')
| StrOutputParser()
)
with trodo.wrap_agent('langchain-chain') as run:
result = chain.invoke({'question': "What's the weather in SF?"})
run.set_output(result)import trodo from 'trodo-node';
import { ChatOpenAI } from '@langchain/openai';
import { PromptTemplate } from '@langchain/core/prompts';
import { StringOutputParser } from '@langchain/core/output_parsers';
trodo.init({ siteId: process.env.TRODO_SITE_ID });
const chain = PromptTemplate.fromTemplate('Answer in one sentence: {question}')
.pipe(new ChatOpenAI({ model: 'gpt-4o-mini' }))
.pipe(new StringOutputParser());
await trodo.wrapAgent('langchain-chain', async (run) => {
const result = await chain.invoke({ question: "What's the weather in SF?" });
run.setOutput(result);
});The chain, its prompt/parse steps, and the LLM call appear as a nested tree under the run: each with the model's real token counts. Agent + tool invocations (LangChain's agent loop, @tool functions) nest the same way.