Skip to main content

Fiddler OTel SDK

PyPI Instrument any Python AI agent or LLM application with OpenTelemetry-based tracing for comprehensive agentic observability. The Fiddler OTel SDK is the foundation package used by all Fiddler framework integrations (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 behavior 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:
That’s it! Your agent traces are now flowing to Fiddler.
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.
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

Requirements:
  • 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

Using environment variables

Environment Variables Reference:

Instrumentation methods

The Fiddler OTel SDK provides two instrumentation approaches. Choose the one that fits your application:
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: Using 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:
When to use 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.
Manual lifecycle (explicit 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')

FiddlerGeneration — LLM spans (as_type='generation')

Extends FiddlerSpan with: 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:

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

Use set_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 first FiddlerClient 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

Use add_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.
Unlike 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):
Span limits (large prompts):
Resource attributes (environment metadata):

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 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. 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 and S3 Routing Mode below).
Override the output file path via environment variable:

Offline and 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_key and url are not required in this mode.
  • otlp_json_capture_enabled=True — writes traces to local .json files in standard OTLP JSON format (ExportTraceServiceRequest envelope). These files are directly consumable by the Fiddler S3 connector.
  • application_id is still required — even though no data is sent to Fiddler directly, the S3 connector uses the application_id embedded in the trace files to route ingested traces to the correct application in Fiddler.
After running your application, upload the generated .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.

Running in AWS SageMaker

Run the Fiddler OTel SDK inside an Amazon SageMaker Partner AI App to export agent traces with AWS Signature Version 4 (SigV4) signing. Authentication is entirely environment-variable driven — no code changes are required. Because the fiddler-langchain and fiddler-langgraph integrations export through FiddlerClient, SageMaker signing flows through them automatically as well. Install the sagemaker extra (pre-installed in SageMaker-managed runtimes):
Set the following environment variables. When SageMaker authentication is enabled, FiddlerClient attaches a SigV4-signing session to the OTLP exporter, so every trace export is signed and routed through the SageMaker partner-app proxy: AWS credentials are resolved through the standard boto3 credential chain (IAM role inside a SageMaker runtime, ~/.aws/credentials, instance profile, or environment variables) — no additional AWS credential variables are needed when running inside the partner-app sandbox. Your instrumentation code is unchanged from any other environment — FiddlerClient reads the SageMaker variables itself:
SageMaker authentication is resolved eagerly when you construct FiddlerClient. A misconfigured environment — a missing ARN or URL, missing AWS credentials, or the sagemaker extra not installed — raises an error at construction time rather than failing silently on the first trace export. Set FIDDLER_OTLP_DEBUG=true to log each signed export while you validate the setup.
Traces are not yet visible in the Fiddler UI on AWS. In the current SageMaker environment, traces are signed and exported correctly but are not yet surfaced in the Fiddler UI. This is an environment limitation, not an SDK defect.

Relationship to other Fiddler SDKs

fiddler-otel is the foundation package that all Fiddler SDK integrations build on: Both 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

The fiddler-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 behavior are identical regardless of which package you import from — use fiddler_otel as the import source when using the core SDK standalone.

Troubleshooting

No spans appearing in Fiddler

  1. Check your credentials — verify api_key, application_id (must be a valid UUID4), and url are correct. These are only required when otlp_enabled=True (the default).
  2. Force flush before exit — for short scripts, the BatchSpanProcessor may not flush before the process exits. Call client.force_flush() or use the context manager (with FiddlerClient(...) as client:).
  3. Enable console tracing — set console_tracer=True to also print spans to stdout and confirm they are being created. This is additive; OTLP export to Fiddler continues alongside console output:
  1. Check the application ID — the application_id must match an existing application in your Fiddler instance and must be a valid UUID4. FiddlerClient raises ValueError on 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 across await 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

Ensure jsonl_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 and S3 Routing Mode.

What’s next?