Metadata-Version: 2.4
Name: fiddler-langgraph
Version: 1.8.0
Summary: LangGraph and LangChain instrumentation for Fiddler GenAI observability
Author-email: Fiddler AI <support@fiddler.ai>
License-Expression: Apache-2.0
Project-URL: Homepage, https://fiddler.ai
Project-URL: Documentation, https://docs.fiddler.ai
Project-URL: Repository, https://github.com/fiddler-labs/fiddler-sdk
Project-URL: Issues, https://github.com/fiddler-labs/fiddler-sdk/issues
Keywords: fiddler,ai,genai,llm,monitoring,observability,instrumentation,langgraph,langchain,opentelemetry
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Monitoring
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Operating System :: OS Independent
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: fiddler-otel<2.0.0,>=0.1.0
Requires-Dist: langchain-core>=1.3.3
Requires-Dist: langgraph<2.0.0,>=1.0.0
Requires-Dist: pydantic>=2.0
Requires-Dist: packaging>=21.0
Requires-Dist: wrapt>=1.14.0
Provides-Extra: examples
Requires-Dist: langchain-chroma<=1.0.0,>=0.1.6; extra == "examples"

# fiddler-langgraph

[![Python Version](https://img.shields.io/pypi/pyversions/fiddler-langgraph.svg)](https://pypi.org/project/fiddler-langgraph/)

[![PyPI Version](https://img.shields.io/pypi/v/fiddler-langgraph.svg)](https://pypi.org/project/fiddler-langgraph/)

[![License](https://img.shields.io/pypi/l/fiddler-langgraph.svg)](https://pypi.org/project/fiddler-langgraph/)

The official Python SDK for instrumenting GenAI Applications with [Fiddler](https://www.fiddler.ai) using OpenTelemetry and LangGraph. Monitor, analyze, and protect your LangGraph workflows, LLMs, and AI Agents in production.

## Platform Features

- 🚀 **Easy Integration** - Simple Python API for LangGraph application instrumentation
- 📊 **OpenTelemetry Tracing** - Full distributed tracing support with configurable span limits
- 🔍 **Automatic Instrumentation** - Zero-config tracing for LangGraph workflows, chains, and tools
- 🎯 **LLM Context Management** - Set additional context for LLM processing with `set_llm_context()`
- 💬 **Conversation Tracking** - Track multi-turn conversations with `set_conversation_id()`
- 📈 **Performance Metrics** - Automatic tracking of timing, token usage, and model information
- 🛡️ **Error Handling** - Comprehensive error tracking with detailed stack traces
- 🔄 **Flexible Configuration** - Custom span limits, sampling strategies, and batch processing
- 🔒 **Graceful Shutdown** - Automatic `atexit` flush, explicit `force_flush()`/`shutdown()`, and context manager support
- ⚡ **Asyncio Support** - Non-blocking `aflush()` and `ashutdown()` for async applications
- 🎨 **Message Serialization** - Smart handling of complex message content (lists, dicts)
- 🔔 **Attribute Truncation** - Automatic truncation of long attribute values to prevent oversized spans

## Installation

```bash
pip install fiddler-langgraph
```

## Requirements

- Python 3.11, 3.12, 3.13, or 3.14
- LangGraph >= 1.0.0 and < 2.0.0, and `langchain-core` >= 1.3.3 (installed automatically)

### With Example Dependencies

To run the example scripts:

```bash
pip install fiddler-langgraph[examples]
```

## Quick Start

```python
from fiddler_langgraph import FiddlerClient, LangGraphInstrumentor, set_conversation_id

# Initialize the FiddlerClient
client = FiddlerClient(
    application_id='your-application-id',  # Must be a valid UUID4
    api_key='your-api-key',
    url='https://your-instance.fiddler.ai',
)

# Instrument LangGraph applications
LangGraphInstrumentor(client).instrument()

# Build and compile your LangGraph workflow as usual; every run is traced.
# Optionally group multi-turn runs into one conversation:
set_conversation_id('conversation_123')
app.invoke({'messages': [{'role': 'user', 'content': 'Write a novel'}]})
```

## Documentation

* 📚 [Complete Documentation](https://docs.fiddler.ai/)
* 🚀 [LangGraph Quick Start Guide](https://docs.fiddler.ai/developers/quick-starts/langgraph-sdk-quick-start)
* 🧩 [LangGraph SDK Integration Guide](https://docs.fiddler.ai/integrations/agentic-ai/langgraph-sdk)
* 📖 [API Reference](https://docs.fiddler.ai/sdk-api/langgraph)

## Example Usage

### Basic Instrumentation

```python
from fiddler_langgraph import LangGraphInstrumentor

# Initialize and instrument
instrumentor = LangGraphInstrumentor(client)
instrumentor.instrument()
```

### Setting LLM Context

```python
from fiddler_langgraph import set_llm_context
from langchain_openai import ChatOpenAI

model = ChatOpenAI(model='gpt-4o-mini')
set_llm_context(model, 'User prefers concise responses')
```

### Conversation Tracking

```python
from fiddler_langgraph import set_conversation_id
import uuid

# Set conversation ID for tracking multi-turn conversations
conversation_id = str(uuid.uuid4())
set_conversation_id(conversation_id)
```

### Advanced Configuration

```python
from opentelemetry.sdk.trace import SpanLimits, sampling
from opentelemetry.exporter.otlp.proto.http.trace_exporter import Compression

# Custom span limits for high-volume applications
custom_limits = SpanLimits(
    max_events=64,
    max_links=64,
    max_span_attributes=64,
    max_event_attributes=64,
    max_link_attributes=64,
    max_span_attribute_length=4096,
)

# Sampling strategy for production
sampler = sampling.TraceIdRatioBased(0.1)  # Sample 10% of traces

client = FiddlerClient(
    application_id='your-app-id',
    api_key='your-api-key',
    url='https://your-instance.fiddler.ai',
    span_limits=custom_limits,
    sampler=sampler,
    console_tracer=False,  # Set to True for debugging (additive, does not suppress direct export)
    compression=Compression.Gzip,  # Enable gzip compression (default)
)
```

### Offline / S3 Routing Mode

Set `otlp_enabled=False` to stop all direct OTLP export to Fiddler. Use `otlp_json_capture_enabled=True` to write spans to local `.json` files in standard OTLP JSON format, ready for ingestion by the Fiddler S3 connector. When `otlp_enabled=False`, `api_key` and `url` are not required.

> **Why is `application_id` still required?**
> Even when not connecting to Fiddler directly, `application_id` is embedded in every trace file as a resource attribute. The Fiddler S3 connector reads this attribute to route ingested traces to the correct application in your Fiddler account. Obtain the UUID4 from your Fiddler application dashboard.

```python
client = FiddlerClient(
    application_id='your-app-id',  # from your Fiddler dashboard — embedded in trace files
    otlp_enabled=False,  # no spans sent directly to Fiddler
    otlp_json_capture_enabled=True,  # write OTLP JSON files locally
    otlp_json_output_dir='./traces',  # output directory (created if absent)
)
```

> **Note on additive parameters:** `console_tracer=True` and `jsonl_capture_enabled=True` both write output *in addition to* sending spans to Fiddler — they do not suppress direct OTLP export. Use `otlp_enabled=False` to fully disable direct export.

## Example Notebooks

The [fiddler-examples repository](https://github.com/fiddler-labs/fiddler-examples) has quick starts, cookbooks, and integration examples, including LangGraph applications.

## Version History

See the [fiddler-langgraph release notes](https://docs.fiddler.ai/changelog/langgraph-sdk) for detailed version history.

## Support

Email [support@fiddler.ai](mailto:support@fiddler.ai) or contact your Fiddler Customer Success Manager.

## License

Apache License 2.0

---

**Want to see Fiddler in action?** [Request a demo](https://www.fiddler.ai/demo)
