Skip to main content

OpenTelemetry-compatible tracing library that adds Lean Production KPIs to LLM/Agent execution traces

Project description

๐Ÿš€ OTEL-Lean-Tracer

Python OpenTelemetry License

๐ŸŽฏ 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 accepted
  • llm.evaluation.score - Quality evaluation score (0-100)
  • llm.evaluation.threshold - Quality threshold setting
  • llm.evaluation.passed - Whether evaluation passed
  • otel.lean.retry.reason - Why retry was needed
  • llm.context.bytes_total - Total prompt size
  • llm.context.bytes_useful - Actually referenced content
  • otel.lean.queue_age_ms - Time waiting in queues
  • llm.usage.cost_usd - Generation API costs
  • llm.evaluation.cost_usd - Evaluation API costs

Optional Attributes (when available):

  • model_scale_b - Model scale in billions of parameters
  • retry_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/:

  1. Lean Production Metrics - Overview of waste and efficiency
  2. Quality Analysis - Evaluation scores, trends, and improvement tracking
  3. Cost Analysis - Real-time API cost breakdown (generation + evaluation)
  4. Performance Monitoring - Latency and throughput metrics
  5. 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

๐Ÿ“„ 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

otel_lean_tracer-0.0.1.tar.gz (41.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

otel_lean_tracer-0.0.1-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

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

Hashes for otel_lean_tracer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 09543352b6d6f7534bb9b27218610cddc80f0f932b1dfbc109f092c4136e7f8c
MD5 a6b21d31a17d0cdbbc374d792b59df27
BLAKE2b-256 71b721e7a343763afdd7c663c38abb4637d467d70ed099c454d27f8ba7fd6265

See more details on using hashes here.

File details

Details for the file otel_lean_tracer-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for otel_lean_tracer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 90f50c8f42232db199388c53dabe44d1ae0871dfd98a97e55c0d659e1ff2b139
MD5 aa4ad65ea1e785ae0aa43de71d0de40b
BLAKE2b-256 10cbb2e59b035f414eacb750866fe7ce46ebbc64ea706579e89503a823c005a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page