Documentation Index
Fetch the complete documentation index at: https://handbook.fiddler.ai/llms.txt
Use this file to discover all available pages before exploring further.
Fiddler OTel SDK
fiddler-langgraph, fiddler-langchain). Use it directly when you have no LangGraph or LangChain dependency, or when you want lightweight decorator-based instrumentation for custom Python agents.
Migrating from
fiddler-langgraph? The core instrumentation functionality (FiddlerClient, @trace, span wrappers, etc.) has been extracted from fiddler-langgraph into this standalone fiddler-otel package. If you previously imported these symbols from fiddler_langgraph, update your imports to use fiddler_otel — the classes and behaviour are identical. See the deprecation notice in the LangGraph SDK changelog for details.What you’ll need
- Fiddler account (cloud or on-premises)
- Python 3.10, 3.11, 3.12, or 3.13
- Fiddler API key and application ID
Quick start
Get monitoring in 3 steps:This Quick Start uses the
@trace decorator. For context manager and manual instrumentation approaches, see Instrumentation Methods below.What gets monitored
The Fiddler OTel SDK captures:Trace hierarchy
Spans are automatically nested into parent-child relationships based on the call stack:Captured data
- Function inputs and return values (auto-serialized to JSON)
- LLM prompts, completions, and token usage
- Tool names, inputs, and outputs
- Agent name, agent ID, and conversation ID
- Execution times and error traces
Application setup
Before instrumenting your application, you must create an application in Fiddler and obtain your Application ID.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.
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.Detailed setup
Installation
- Python: 3.10, 3.11, 3.12, or 3.13
- OpenTelemetry: API, SDK, and OTLP exporter
>= 1.27.0(installed automatically) - pydantic:
>= 2.0(installed automatically)
Configuration
Direct initialization (Recommended)
Using environment variables
| Variable | Description | Example |
|---|---|---|
FIDDLER_API_KEY | Your Fiddler API key | fid_... |
FIDDLER_APPLICATION_ID | Your application UUID4 | 550e8400-e29b-41d4-a716-446655440000 |
FIDDLER_URL | Your Fiddler instance URL | https://your-instance.fiddler.ai |
Instrumentation methods
The Fiddler OTel SDK provides two instrumentation approaches. Choose the one that fits your application:| Approach | Best For | Key API |
|---|---|---|
| Decorator-Based | Custom Python functions, minimal boilerplate | @trace(), get_current_span() |
| Manual | Fine-grained span lifecycle control | start_as_current_span(), start_span() |
You can combine both approaches in the same application. For example, use the decorator for most functions and manual spans where you need fine-grained lifecycle control.
Decorator-based instrumentation
Use the@trace() decorator to instrument individual Python functions. Works with both synchronous and asynchronous functions.
@trace decorator parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
as_type | 'span', 'generation', 'chain', 'tool' | 'span' | Span type for Fiddler categorization |
name | str | None | function name | Custom span name |
capture_input | bool | True | Auto-serialize function arguments as span input |
capture_output | bool | True | Auto-serialize return value as span output |
model | str | None | None | Sets gen_ai.request.model |
system | str | None | None | Sets gen_ai.system (LLM provider) |
user_id | str | None | None | Sets user.id |
version | str | None | None | Sets service.version |
client | FiddlerClient | None | None | Override the client to use (defaults to global singleton) |
get_current_span() inside a decorated function:
Call get_current_span() inside any @trace-decorated function to access the active span and set additional attributes. Pass as_type matching the decorator to get a typed wrapper with semantic helpers:
capture_input=False:
Set capture_input=False when you want to control exactly what gets recorded on the span (for example, to set set_user_prompt() instead of the default raw argument dict). This avoids double-recording the same data.
Manual instrumentation
Use context managers for explicit span lifecycle control. This gives you full control over when spans start and end.end()):
Use start_span() when you need to manage the span lifecycle manually, for example across asynchronous callbacks:
Span types and wrappers
The SDK provides four span types, each with semantic convention helpers:FiddlerSpan — base (any as_type='span')
| Method | OTel Attribute | Description |
|---|---|---|
set_input(data) | gen_ai.llm.input.user | Auto-serializes dicts/lists to JSON |
set_output(data) | gen_ai.llm.output | Auto-serializes dicts/lists to JSON |
set_attribute(key, value) | custom | Set any custom attribute |
update(**kwargs) | — | Bulk-set input, output, and any attributes in one call |
set_agent_name(name) | gen_ai.agent.name | Agent label in Fiddler UI |
set_agent_id(id) | gen_ai.agent.id | Agent identifier |
set_conversation_id(id) | gen_ai.conversation.id | Links spans to a conversation |
record_exception(exc) | — | Records exception and marks span ERROR |
end() | — | End span (for manual lifecycle only) |
FiddlerGeneration — LLM spans (as_type='generation')
Extends FiddlerSpan with:
| Method | OTel Attribute | Description |
|---|---|---|
set_model(name) | gen_ai.request.model | LLM model name |
set_system(provider) | gen_ai.system | LLM provider (e.g. 'openai') |
set_system_prompt(text) | gen_ai.llm.input.system | System prompt text |
set_user_prompt(text) | gen_ai.llm.input.user | User prompt (last human message) |
set_completion(text) | gen_ai.llm.output | LLM completion text |
set_usage(input_tokens, output_tokens, total_tokens=None) | gen_ai.usage.* | Token counts |
set_context(text) | gen_ai.llm.context | Additional context |
set_messages(messages) | gen_ai.input.messages | Full chat history (JSON) |
set_output_messages(messages) | gen_ai.output.messages | Output messages (JSON) |
set_tool_definitions(defs) | gen_ai.tool.definitions | Available tools (JSON, OpenAI format) |
set_messages() and set_output_messages() accept simple OpenAI format and auto-convert to OTel parts format:
FiddlerTool — tool spans (as_type='tool')
Extends FiddlerSpan with:
| Method | OTel Attribute | Description |
|---|---|---|
set_tool_name(name) | gen_ai.tool.name | Tool/function name |
set_tool_input(data) | gen_ai.tool.input | Tool input (auto-serialized to JSON) |
set_tool_output(data) | gen_ai.tool.output | Tool result (auto-serialized to JSON) |
set_tool_definitions(defs) | gen_ai.tool.definitions | Available tools |
FiddlerChain — pipeline spans (as_type='chain')
Extends FiddlerSpan with no additional methods. Use for high-level orchestration spans that group multiple LLM calls and tool calls together.
Advanced usage
Multi-turn conversation tracking
Useset_conversation_id() to link multiple agent invocations into a single conversation in the Fiddler UI. Set a new UUID at the start of each conversation; all spans created in the current thread or async coroutine after this call will carry the same conversation ID.
Async agents
The@trace decorator automatically detects async functions and wraps them correctly. Use the same patterns as sync functions:
Context isolation
fiddler-otel uses its own isolated OpenTelemetry context that does not interfere with any existing global tracer in your application. If you already use OpenTelemetry for infrastructure tracing, Fiddler spans will not appear in your infrastructure traces and vice versa.
This means you can safely add fiddler-otel to an application that already has OpenTelemetry instrumentation without any conflict.
Global client singleton
The firstFiddlerClient created in a process becomes the global singleton, accessible via get_client(). The @trace decorator uses this singleton automatically when client= is not passed:
Session attributes
Useadd_session_attributes() to attach key-value metadata that is automatically applied to all spans created in the current thread or async coroutine. Use this for user-level or environment-level metadata that applies across an entire session — such as user_id, environment, or feature flags.
Attributes are emitted as fiddler.session.user.{key} on every span and propagated from parent to child spans automatically.
set_conversation_id() (which links invocations into a conversation), add_session_attributes is for descriptive metadata. Both can be used together.
Custom span attributes
Set any custom attribute on an individual span to add business context for that specific operation:Production configuration
Sampling (reduce volume):Flush and shutdown
FiddlerClient registers an atexit handler to flush and shut down automatically. For short scripts or critical workloads, call force_flush() explicitly to ensure all buffered spans are exported before the process exits:
Local debugging
Console output (print spans to stdout in addition to Fiddler export):console_tracer=True is additive — span data is printed to stdout and continues to be exported to Fiddler via OTLP. Setting this to True does not suppress or disable the OTLP export to Fiddler. Use it to visually confirm spans are being created during development.
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. The JSONL format written here is a custom Fiddler format and is not compatible with the Fiddler S3 connector. To write S3-compatible files, use otlp_json_capture_enabled=True instead (see Offline / S3 Routing Mode below).
Offline / S3 Routing Mode
Use this mode when traces must be routed through an intermediate store (such as Amazon S3) before reaching Fiddler, rather than being sent directly. This is the correct approach when your security or network policies require all data to pass through a controlled intermediary.otlp_enabled=False— disables all direct OTLP export to Fiddler.api_keyandurlare not required in this mode.otlp_json_capture_enabled=True— writes traces to local.jsonfiles in standard OTLP JSON format (ExportTraceServiceRequestenvelope). These files are directly consumable by the Fiddler S3 connector.application_idis still required — even though no data is sent to Fiddler directly, the S3 connector uses theapplication_idembedded in the trace files to route ingested traces to the correct application in Fiddler.
.json files from otlp_json_output_dir to your S3 bucket. The Fiddler S3 connector reads them directly.
Each batch of spans is written to a separate timestamped
.json file in the output directory. The directory is created automatically if it does not exist.Relationship to other Fiddler SDKs
fiddler-otel is the foundation package that all Fiddler SDK integrations build on:
| Package | Framework | Instrumentation Approach |
|---|---|---|
fiddler-otel | Any Python application | @trace decorator, context managers |
fiddler-langchain | LangChain V1 (create_agent) | FiddlerLangChainInstrumentor (auto-patches create_agent) |
fiddler-langgraph | LangGraph (StateGraph.compile()) | LangGraphInstrumentor (callback handler) |
fiddler-langchain and fiddler-langgraph depend on fiddler-otel and re-export its core symbols (FiddlerClient, trace, get_current_span, set_conversation_id). If your application uses LangChain V1 (create_agent API) or LangGraph, install the framework-specific package — it includes fiddler-otel automatically.
API reference
Thefiddler-otel SDK provides the same core classes as fiddler-langgraph — the codebase is shared, and fiddler-langgraph re-exports all fiddler-otel symbols unchanged. Until a dedicated fiddler-otel API reference is autogenerated, the detailed reference pages are co-located in the shared SDK API reference. The classes, parameters, and behaviour are identical regardless of which package you import from — use fiddler_otel as the import source when using the core SDK standalone.
| Class / Function | Import | Description |
|---|---|---|
| FiddlerClient | from fiddler_otel import FiddlerClient | Configure the OTel tracer and manage the connection to Fiddler |
| get_client | from fiddler_otel import get_client | Retrieve the active FiddlerClient instance |
| trace | from fiddler_otel import trace | Decorator for automatic function instrumentation |
| get_current_span | from fiddler_otel import get_current_span | Access the active Fiddler span within a traced function |
| FiddlerSpan | from fiddler_otel import FiddlerSpan | Base span wrapper |
| FiddlerGeneration | from fiddler_otel import FiddlerGeneration | Span wrapper for LLM calls |
| FiddlerChain | from fiddler_otel import FiddlerChain | Span wrapper for agent/chain workflows |
| FiddlerTool | from fiddler_otel import FiddlerTool | Span wrapper for tool calls |
| add_session_attributes | from fiddler_otel import add_session_attributes | Add session-level attributes applied to all spans in the current context |
| set_conversation_id | from fiddler_otel import set_conversation_id | Link spans into a single conversation |
Troubleshooting
No spans appearing in Fiddler
- Check your credentials — verify
api_key,application_id(must be a valid UUID4), andurlare correct. These are only required whenotlp_enabled=True(the default). - Force flush before exit — for short scripts, the
BatchSpanProcessormay not flush before the process exits. Callclient.force_flush()or use the context manager (with FiddlerClient(...) as client:). - Enable console tracing — set
console_tracer=Trueto also print spans to stdout and confirm they are being created. This is additive; OTLP export to Fiddler continues alongside console output:
- Check the application ID — the
application_idmust match an existing application in your Fiddler instance and must be a valid UUID4.FiddlerClientraisesValueErroron initialization if the format is invalid.
RuntimeError: No FiddlerClient initialized
get_current_span() or get_client() was called before a FiddlerClient was created. Create the client before decorating or calling any instrumented functions:
ValueError: application_id must be a valid UUID4
The application_id passed to FiddlerClient is not a valid UUID version 4. Copy the Application ID directly from the GenAI Applications page in the Fiddler UI — it should look like 550e8400-e29b-41d4-a716-446655440000.
Spans missing from async code
Context variables propagate correctly acrossawait in the same async task. If you are spawning new tasks with asyncio.create_task(), call set_conversation_id() and add_session_attributes() inside the task so the context is re-established. Use client.ashutdown() instead of client.shutdown() to avoid blocking the event loop during teardown.
Spans interfering with another OpenTelemetry tracer
FiddlerClient uses an isolated Context that is separate from the global OTel context. Spans created via @trace or start_as_current_span() will not appear in any other tracer, and spans from other tracers will not appear in Fiddler. This isolation is intentional and requires no configuration.
Local JSONL file is empty
Ensurejsonl_capture_enabled=True is set on FiddlerClient and that the process has executed instrumented code. The JSONL file is written synchronously, so spans appear immediately after each span ends. Check the path: the default is fiddler_trace_data.jsonl in the current working directory; override with jsonl_file_path or the FIDDLER_JSONL_FILE environment variable.
Note: jsonl_capture_enabled=True is additive — it saves a local copy of spans while OTLP export to Fiddler continues. If your goal is to write files for S3 upload and stop sending directly to Fiddler, use otlp_enabled=False combined with otlp_json_capture_enabled=True instead. See Offline / S3 Routing Mode.
What’s next?
- LangChain SDK — If your application uses LangChain V1
create_agent - LangGraph SDK — If your application uses LangGraph
- Agentic Observability Concepts — Understand the agent lifecycle and monitoring approach