Fiddler LangChain SDK
langchain.agents.create_agent for comprehensive agentic observability. The Fiddler LangChain SDK produces a clean, flat trace hierarchy — agent → LLM calls → tool calls — with no noisy Chain wrappers. One call to FiddlerLangChainInstrumentor.instrument() auto-traces every agent in your application.
Using LangChain prior to v1? The
fiddler-langchain SDK requires LangChain v1 (langchain.agents.create_agent API). For applications using earlier LangChain versions or LangGraph workflows, use the Fiddler LangGraph SDK instead — it covers both LangGraph and earlier LangChain-based agents.What you’ll need
- Fiddler account (cloud or on-premises)
- Python 3.10-3.14
- LangChain V1 application using
langchain.agents.create_agent - Fiddler API key and application ID
Quick start
Get monitoring in 4 steps:What gets monitored
Trace hierarchy
Each agent invocation produces a clean, flat trace with no noisy Chain wrappers:Captured data
Agent root span:- Agent name and agent ID
- Conversation ID (if set via
set_conversation_id())
- Model name and provider
- System prompt and user prompt (last human message)
- Full input message history (
gen_ai.input.messages) - LLM completion and output messages (
gen_ai.output.messages) - Token usage (input, output, total)
- LLM context (if set via
set_llm_context()) - Available tool definitions
- Tool name, input arguments, and output
Application setup
Before instrumenting your application, you must create an application in Fiddler and obtain your Application ID.1. Create your application in Fiddler
Log in to your Fiddler instance and navigate to GenAI Applications, then click Add Application and follow the onboarding wizard to create your application.2. Copy your Application ID
After creating your application, copy the Application ID from the GenAI Applications page. This must be a valid UUID4 format (for example,550e8400-e29b-41d4-a716-446655440000). You’ll need this for initialization.
3. Get your API key
Go to Settings > Credentials and copy your API key. You’ll need this for initialization.Detailed setup
Installation
- LangChain V1:
>= 1.0.0— agents built withlangchain.agents.create_agent - Python: 3.10-3.14
- fiddler-otel:
>= 1.0.0(installed automatically) - OpenTelemetry: API and SDK
>= 1.27.0(installed automatically)
Configuration
Direct initialization (Recommended)
Using environment variables
Instrumentation methods
The Fiddler LangChain SDK provides two instrumentation approaches:Auto-instrumentation
FiddlerLangChainInstrumentor.instrument() monkey-patches langchain.agents.create_agent once. Every subsequent call to create_agent() automatically receives a FiddlerAgentMiddleware. No changes to individual agent creation calls are needed.
- Idempotent: Calling
instrument()multiple times is safe — it will not create duplicate middleware. - Agent naming: If
name='...'is passed tocreate_agent(), that name is used for the agent in traces. If omitted, no agent name is set and the agent appears without a label in the UI. - Existing middleware preserved: If you pass a
FiddlerAgentMiddlewareinstance manually inmiddleware=[...], the instrumentor skips injection for that call so your manual configuration is preserved.
Manual middleware
For per-agent control, passFiddlerAgentMiddleware directly to create_agent() without using the instrumentor:
Advanced usage
Multi-turn conversations
Useset_conversation_id() to link multiple agent invocations into a single conversation in the Fiddler UI. All agents in the application that share the same conversation_id appear together in conversation-level views.
LLM context
Attach contextual metadata to LLM spans by callingset_llm_context() before the agent runs. The instrumentation reads this value from the model’s metadata at invocation time and records it as gen_ai.llm.context on every LLM span for that model.
set_llm_context() accepts both plain model instances (BaseLanguageModel) and RunnableBinding instances (for example, models wrapped with .with_config() or .bind_tools()).
Clearing LLM context for non-RAG steps
In multi-step agent workflows, context set after a RAG retrieval step leaks into subsequent non-RAG LLM calls (tool planning, routing, etc.), causing unintended faithfulness evaluation. Useclear_llm_context() to explicitly remove context before non-RAG steps:
clear_llm_context(model) is equivalent to set_llm_context(model, None).
Span-level attributes
Useadd_span_attributes() to attach custom metadata to a specific LangChain component (model, tool, or retriever). The middleware reads these attributes when creating the span for that component and records them as fiddler.span.user.{key}.
add_session_attributes (which applies to every span in the context), add_span_attributes is scoped to a single component.
Session attributes
Useadd_session_attributes() to attach metadata that appears on every span created in the current thread or async coroutine. Use this for user-level or environment-level metadata that applies to the whole session.
Retriever instrumentation
The LangChain V1 middleware does not expose a dedicated retriever hook. Following the same convention used infiddler-langgraph, retrievers are treated as tools.
Wrap your retriever with @tool (or use create_retriever_tool) and pass it to create_agent. The middleware’s tool hook captures the retriever call automatically as a TYPE=tool span — with the query as tool_input and the retrieved documents as tool_output.
Multi-agent setup
With the instrumentor, a singleinstrument() call patches create_agent so every agent is traced. Pass name='...' to each create_agent() to label agents in traces.
When a sub-agent is invoked from within a delegation tool, its root Agent span is automatically created as a child of the tool span — the entire multi-agent flow appears in a single trace. No manual linking is needed: wrap_tool_call attaches the active tool span into the OTel context before invoking the handler, and before_agent detects that active span and nests under it.
set_conversation_id() is useful for linking multiple top-level invocations (e.g., multi-turn conversations) — not for joining sub-agents within a single invocation, since they already share the same trace automatically.Async agents
The instrumentation fully supports async agents via theawrap_model_call and awrap_tool_call hooks. Use agent.ainvoke() — no additional configuration needed:
Error handling
If an LLM call or tool call raises an exception, the instrumentation:- Catches the exception and marks the failing span with
StatusCode.ERROR - Re-raises the exception so normal error handling in your application is unaffected
- Cleanly closes the root agent span — no dangling open spans
Running in AWS SageMaker
Becausefiddler-langchain exports traces through FiddlerClient, it inherits the Fiddler OTel SDK’s AWS SageMaker Partner App authentication. Install the sagemaker extra (pip install "fiddler-otel[sagemaker]") and set the AWS_PARTNER_APP_AUTH, AWS_PARTNER_APP_ARN, and AWS_PARTNER_APP_URL environment variables — your instrumentation code is unchanged.
Flush and shutdown
Local debugging
JSONL file capture (save a local copy of spans in addition to Fiddler export):jsonl_capture_enabled=True is additive — spans are saved to a local JSONL file and continue to be exported to Fiddler via OTLP. Setting this to True does not suppress or disable the OTLP export to Fiddler.
Relationship to fiddler-langgraph
Both packages depend on
fiddler-otel for the core FiddlerClient and span wrappers.
What’s next?
- Fiddler OTel SDK — For decorator-based instrumentation of custom Python functions
- LangGraph SDK — If your application uses LangGraph
- Agentic Observability Concepts — Understand the agent lifecycle and monitoring approach