Auto-Instrumentation
Zero-config tracing for LangChain, LangGraph, Microsoft Agent Framework, Pydantic AI, Google ADK, and Haystack applications. It traces LLM calls, tool invocations, retrieval, and chain executions without modifying your code.
API at a glance
The full auto-instrumentation surface lives in rhesis.sdk.telemetry:
| Call | Behavior |
|---|---|
auto_instrument() | Tries every supported framework and enables the ones whose package is importable. |
auto_instrument("langchain", ...) | Enables only the named frameworks. Unknown names are logged as warnings but do not raise. |
disable_auto_instrument() | Disables every framework that was previously enabled in this process. |
The function returns the list of frameworks it actually instrumented, so you can log it in your bootstrap:
LangChain
Installation
Usage
What Gets Traced
- LLM invocations with token counts, one
ai.promptevent per message sent - Tool calls with inputs and outputs
- Retriever calls, with the query, the documents returned and how many
- Streaming responses
- Errors and exceptions
The steps of an LCEL pipeline are not spans of their own — a prompt | llm | parser chain reports three of them and none is a unit of work. The LLM call inside it is traced.
LCEL Chain Example
Tools Example
Under the hood the integration registers a callback handler globally and patches BaseTool.invoke / BaseTool.ainvoke, so tool spans fire even when the framework’s normal callback plumbing is bypassed by user code.
LangGraph
Installation
Usage
How LangChain and LangGraph share a callback
LangGraph runs on top of LangChain’s callback system. To avoid emitting duplicate spans when both are present, the LangGraph integration reuses the singleton LangChain callback instead of creating its own. That means:
auto_instrument("langgraph")already covers LangChain chains, LCEL pipelines, tools, and LLM calls invoked from inside graph nodes — you do not need to add"langchain"explicitly.- Calling
auto_instrument("langchain", "langgraph")is safe and idempotent: the second integration finds the callback already registered and only adds the graph-method patches on top. - The integration also patches
CompiledStateGraph.invoke/ainvoke/stream/astream, so every graph entry point injects the callback automatically — no need to thread it throughconfig={"callbacks": [...]}yourself.
Trace Output
Each node in the graph produces spans following semantic conventions. The graph itself gets an ai.agent.invoke span and every node gets one beneath it, whatever the node is called, with its LLM, tool and retrieval spans nested inside. One graph run is one trace.
Spans include attributes for model name, provider, token counts (input/output), and tool names.
Delegation between agents is traced separately as ai.agent.handoff — see Multi-Agent Tracing. Grouping the turns of one session into a conversation is covered in Conversation Tracing.
Combining with Decorators
Auto-instrumentation works alongside @observe and @endpoint:
Manual callback injection (advanced)
In nearly all cases, auto_instrument() is enough — the SDK patches the framework entry points and traces fire transparently. For the rare situation where you build a custom wrapper around CompiledStateGraph that bypasses the patched methods, you can fetch the active callback and pass it through yourself:
get_callback() returns None if LangChain instrumentation has not been enabled in this process.
Disabling
To turn off every previously-enabled framework — for example before reconfiguring tracing in a test fixture — call disable_auto_instrument():
Supported Frameworks
| Framework | Mechanism | auto_instrument key | pip extra | Status |
|---|---|---|---|---|
| LangChain | Auto-instrument (callback + tool patch) | langchain | langchain | Supported |
| LangGraph | Auto-instrument (callback + graph patch) | langgraph | langgraph | Supported |
| Microsoft Agent Framework | Auto-instrument (OTel span translation) | agent_framework (alias maf) | agent-framework | Supported |
| Pydantic AI | Auto-instrument (OTel span translation) | pydantic_ai | pydantic-ai | Supported |
| Google ADK | Auto-instrument (OTel span translation) | google_adk (alias adk) | google-adk | Supported |
| Haystack | Auto-instrument (registers a Haystack tracer) | haystack | haystack | Supported |
| Other Python frameworks (CrewAI, OpenAI Agents SDK, LlamaIndex, …) | @observe.* decorators | n/a | n/a | Use Decorators |
Microsoft Agent Framework, Google ADK and Haystack each have their own dedicated guide — see Microsoft Agent Framework, Google ADK and Haystack for installation, handoff tracing, and content-capture options. For Pydantic AI, call auto_instrument("pydantic_ai") after creating RhesisClient.
Haystack needs one extra step: HAYSTACK_CONTENT_TRACING_ENABLED must be true before haystack is imported, or its spans carry no prompts or completions.
For frameworks not in the auto-instrument list, wrap the functions, tools, or agents you want to trace with @observe.llm, @observe.tool, @observe.retrieval, etc. Without decorators only top-level inputs and outputs are captured.
To add a new framework to the auto-instrument list, see Contributing: SDK Integrations.
Related:
- Setup - Initial configuration
- Decorators -
@observeand@endpoint - Multi-Agent Tracing - Agent and handoff spans
- Microsoft Agent Framework - Native agent and handoff tracing for MAF
- Google ADK - Native agent and handoff tracing for Google ADK
- Haystack - Pipeline, component, and agent tracing
- Integrations - The four integration layers at a glance
- Connector - Register functions as endpoints