OpenTelemetry-compatible tracing library that adds Lean Production KPIs to LLM/Agent execution traces
Project description
๐ OTEL-Lean-Tracer
๐ฏ Zero-config OpenTelemetry tracing with Lean Production KPIs for LLM/Agent applications
OTEL-Lean-Tracer seamlessly adds "Lean Production 7 Wastes" metrics to your LLM and Agent execution traces, giving you real-time visibility into bottlenecks and waste in your AI applications through beautiful Grafana dashboards.
โจ Why OTEL-Lean-Tracer?
๐ Instant Visibility
- Zero configuration - Just add one line and start seeing your AI application's performance
- Real-time bottleneck detection - Spot queue delays, context waste, and retry loops instantly
- Beautiful Grafana dashboards - Pre-built visualizations for immediate insights
๐ Lean Production Metrics
Track the 7 wastes of Lean Production applied to LLM applications:
- ๐ Queue Time - Time spent waiting for API responses
- ๐ Retry Waste - Failed generation attempts and retries
- ๐ Context Waste - Unused tokens in prompts
- ๐ฐ Cost Tracking - Real-time API cost monitoring (generation + evaluation)
- โก Processing Delays - Identify slow components
- ๐ฏ Quality Issues - Track acceptance rates and evaluation scores
- ๐ Transport Overhead - Network and serialization costs
๐ฏ GenAgent Evaluation Tracking
Advanced quality monitoring for agents-sdk-models:
- ๐ Evaluation Scores - Track quality scores (0-100) vs thresholds
- ๐ Retry Analysis - Monitor threshold-based retry patterns
- ๐ก Improvement Insights - Capture AI-generated improvement suggestions
- ๐ฐ Separate Cost Tracking - Split generation and evaluation costs
- ๐ Quality Trends - Visualize quality progression over time
- ๐ Multi-Step Monitoring - Track quality across Flow pipelines
๐ Developer Friendly
- OpenTelemetry compatible - Works with your existing observability stack
- Agent SDK integration - Built for modern LLM frameworks
- Grafana + Tempo ready - Enterprise-grade trace storage and visualization
๐ Quick Start
Installation
# Install via uv (recommended)
uv add otel-lean-tracer
# Or via pip
pip install otel-lean-tracer
โก Super Simple Setup
Add just one line to your LLM application:
from otel_lean_tracer import instrument_lean
# Enable lean tracing (that's it!)
instrument_lean()
# Your existing code works unchanged
from agents_sdk_models import create_simple_gen_agent
agent = create_simple_gen_agent(
name="story_generator",
instructions="Generate creative stories",
model="gpt-4o-mini",
threshold=75 # Quality threshold for evaluation
)
result = await agent.run("Tell me a story about a robot")
๐ Instant Dashboard
Your traces automatically include:
Core Attributes (OTEL Semantic Conventions):
otel.lean.gen.attempt- Generation attempt number (1, 2, 3...)otel.lean.gen.accepted- Whether output was acceptedllm.evaluation.score- Quality evaluation score (0-100)llm.evaluation.threshold- Quality threshold settingllm.evaluation.passed- Whether evaluation passedotel.lean.retry.reason- Why retry was neededllm.context.bytes_total- Total prompt sizellm.context.bytes_useful- Actually referenced contentotel.lean.queue_age_ms- Time waiting in queuesllm.usage.cost_usd- Generation API costsllm.evaluation.cost_usd- Evaluation API costs
Optional Attributes (when available):
model_scale_b- Model scale in billions of parametersretry_energy_kwh- Estimated energy consumption for retries
๐ Supported Environments
| Environment | Status | Version |
|---|---|---|
| Python | โ | 3.11+ |
| OpenTelemetry | โ | 1.25+ |
| Agents SDK | โ | 0.22+ |
| Grafana Tempo | โ | Latest |
| OpenAI | โ | All models |
| Anthropic | โ | Claude series |
| Ollama | โ | Local models |
๐ Advanced Configuration
Custom Exporters
from otel_lean_tracer import instrument_lean
from otel_lean_tracer.exporters import create_tempo_exporter
# Configure Tempo backend
exporter = create_tempo_exporter(
endpoint="http://tempo:3200",
headers={"Authorization": "Bearer your-token"}
)
instrument_lean(exporter=exporter)
Evaluation Data Tracking
from otel_lean_tracer.attributes import LeanAttributes
# Evaluation data is automatically captured from GenAgent:
# - Quality scores and thresholds
# - Improvement suggestions
# - Retry reasons and patterns
# - Separate cost tracking for generation vs evaluation
Flow Metrics
from otel_lean_tracer.mixins import FlowInstrumentationMixin
class MyAgent(FlowInstrumentationMixin):
async def process(self, input_data):
# Automatically measures queue_age_ms and evaluation metrics
return await self.instrumented_call(input_data)
๐ฏ Real-World Benefits
๐ก Before OTEL-Lean-Tracer
- โ No visibility into LLM application performance
- โ Manual cost tracking and estimation
- โ Difficult to spot bottlenecks and waste
- โ No quality monitoring or evaluation insights
- โ Complex observability setup required
โจ After OTEL-Lean-Tracer
- โ Zero-config observability for LLM apps
- โ Automatic cost tracking with real-time dashboards
- โ Instant bottleneck detection using Lean metrics
- โ Quality evaluation monitoring with improvement insights
- โ Beautiful Grafana dashboards out of the box
๐ง Integration Examples
With OpenAI Agents SDK + Evaluation
from agents_sdk_models import create_simple_gen_agent, Flow
from otel_lean_tracer import instrument_lean
instrument_lean()
# Create agents with quality thresholds
classifier = create_simple_gen_agent(
name="intent_classifier",
instructions="Classify user intent accurately",
model="gpt-4o-mini",
threshold=80 # Higher threshold for classification
)
responder = create_simple_gen_agent(
name="response_generator",
instructions="Generate helpful responses",
model="gpt-4o",
threshold=75 # Quality threshold for responses
)
# Create flow - evaluation data automatically traced!
flow = Flow(steps=[classifier, responder])
result = await flow.run("Help me plan a vacation")
# Dashboard shows:
# - Quality scores for each step
# - Cost breakdown (generation vs evaluation)
# - Retry patterns and improvement suggestions
# - Multi-step quality progression
With Custom Evaluation Systems
from otel_lean_tracer.processors import LeanTraceProcessor
from opentelemetry import trace
# Custom evaluation data is automatically detected
custom_result = {
"content": "Generated response",
"evaluation": {
"score": 85.5,
"threshold": 75.0,
"passed": True,
"improvements": ["Add more examples", "Improve clarity"]
}
}
# Lean processor extracts evaluation data automatically
processor = LeanTraceProcessor()
trace.get_tracer_provider().add_span_processor(processor)
๐ Grafana Dashboard Setup
Pre-built dashboards included in /examples/grafana/:
- Lean Production Metrics - Overview of waste and efficiency
- Quality Analysis - Evaluation scores, trends, and improvement tracking
- Cost Analysis - Real-time API cost breakdown (generation + evaluation)
- Performance Monitoring - Latency and throughput metrics
- Error Analysis - Retry patterns and failure modes
Import lean-tracer-dashboard.json into your Grafana instance for instant visualizations!
๐ Architecture
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Your LLM App โโโโโถโ OTEL-Lean-Tracer โโโโโถโ Grafana + Tempo โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโ
โ Lean Metrics โ
โ โข Queue Time โ
โ โข Retry Wasteโ
โ โข Context โ
โ โข Quality โ
โ โข Cost โ
โโโโโโโโโโโโโโโโ
๐ค Contributing
We love contributions! Check out our Contributing Guide to get started.
Development Setup
# Clone the repository
git clone https://github.com/your-org/otel-lean-tracer.git
cd otel-lean-tracer
# Install in development mode
uv pip install -e .
# Install dev dependencies
uv add --group dev pytest pytest-cov pytest-asyncio
# Run tests
pytest
๐ Documentation
- ๐ Complete Documentation
- ๐ Architecture Guide
- ๐ฏ Use Cases
- ๐ง Function Reference
- ๐ Grafana Setup Guide
- ๐ Tutorial with Evaluation Examples
๐ License
MIT License - see LICENSE file for details.
๐ Acknowledgments
- OpenTelemetry community for the amazing observability framework
- Grafana team for beautiful visualization tools
- Lean Production methodology for waste reduction principles
- agents-sdk-models for advanced LLM agent capabilities
Made with โค๏ธ for the LLM/Agent developer community
Start tracking your AI application's efficiency AND quality in under 60 seconds! ๐
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file otel_lean_tracer-0.0.1.tar.gz.
File metadata
- Download URL: otel_lean_tracer-0.0.1.tar.gz
- Upload date:
- Size: 41.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09543352b6d6f7534bb9b27218610cddc80f0f932b1dfbc109f092c4136e7f8c
|
|
| MD5 |
a6b21d31a17d0cdbbc374d792b59df27
|
|
| BLAKE2b-256 |
71b721e7a343763afdd7c663c38abb4637d467d70ed099c454d27f8ba7fd6265
|
File details
Details for the file otel_lean_tracer-0.0.1-py3-none-any.whl.
File metadata
- Download URL: otel_lean_tracer-0.0.1-py3-none-any.whl
- Upload date:
- Size: 32.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90f50c8f42232db199388c53dabe44d1ae0871dfd98a97e55c0d659e1ff2b139
|
|
| MD5 |
aa4ad65ea1e785ae0aa43de71d0de40b
|
|
| BLAKE2b-256 |
10cbb2e59b035f414eacb750866fe7ce46ebbc64ea706579e89503a823c005a9
|