Skip to content

Repository files navigation

HoneyHive Python SDK

A comprehensive Python SDK for HoneyHive, providing LLM observability, evaluation, and tracing capabilities with OpenTelemetry integration.

🚀 Features

  • OpenTelemetry Integration - Full OTEL compliance with custom span processor and exporter
  • Automatic Session Management - Seamless session creation and management
  • Decorator Support - Easy-to-use @trace (unified sync/async), @atrace, and @trace_class decorators
  • Context Managers - start_span and enrich_span for manual span management
  • HTTP Instrumentation - Automatic HTTP request tracing
  • Baggage Support - Context propagation across service boundaries
  • Experiment Harness Integration - Automatic experiment tracking with MLflow, Weights & Biases, and Comet support
  • Real-time API Integration - Direct integration with HoneyHive backend services
  • Comprehensive Testing - Full test suite with 203 passing tests

📦 Installation

Choose Your Instrumentor Type:

HoneyHive supports both OpenInference (lightweight) and OpenLLMetry (enhanced metrics) instrumentors.

Option A: OpenInference (Recommended for Beginners)

# Install with OpenAI integration (most common)
pip install honeyhive[openinference-openai]
# Install with Anthropic integration
pip install honeyhive[openinference-anthropic]
# Install with Google AI integration
pip install honeyhive[openinference-google-ai]
# Install with multiple providers
pip install honeyhive[openinference-openai,openinference-anthropic,openinference-google-ai]
# Install all OpenInference integrations
pip install honeyhive[all-openinference]

Option B: OpenLLMetry (Enhanced Metrics)

# Install with OpenAI integration (enhanced metrics)
pip install honeyhive[traceloop-openai]
# Install with Anthropic integration
pip install honeyhive[traceloop-anthropic]
# Install with Google AI integration
pip install honeyhive[traceloop-google-ai]
# Install with multiple providers
pip install honeyhive[traceloop-openai,traceloop-anthropic,traceloop-google-ai]
# Install all OpenLLMetry integrations
pip install honeyhive[all-traceloop]

Option C: Mix Both Types

# Strategic mixing based on your needs
pip install honeyhive[traceloop-openai,openinference-anthropic]

Basic Installation (manual instrumentor setup required):

pip install honeyhive

📋 Including in Your Project

For detailed guidance on including HoneyHive in your pyproject.toml, see our pyproject.toml Integration Guide.

🔧 Quick Start

Basic Usage

fromhoneyhiveimportHoneyHiveTracer, trace# Initialize tracertracer=HoneyHiveTracer.init(
api_key="your-api-key",
source="production"
)
# Use unified decorator for automatic tracing (works with both sync and async)@trace(event_type="demo", event_name="my_function")defmy_function():
return"Hello, World!"@trace(event_type="demo", event_name="my_async_function")asyncdefmy_async_function():
awaitasyncio.sleep(0.1)
return"Hello, Async World!"# Manual span managementwithtracer.start_span("custom-operation"):
# Your code herepass# With HTTP tracing enabled (new simplified API)tracer=HoneyHiveTracer.init(
api_key="your-api-key",
source="production",
disable_http_tracing=False# project derived from API key
)

Initialization

The HoneyHiveTracer.init() method is the recommended way to initialize the tracer:

fromhoneyhiveimportHoneyHiveTracer# Standard initializationtracer=HoneyHiveTracer.init(
api_key="your-api-key",
source="production"# project derived from API key
)
# With custom server URL for self-hosted deploymentstracer=HoneyHiveTracer.init(
api_key="your-api-key",
source="production",
server_url="https://custom-server.com"# project derived from API key
)

Enhanced Features Available

fromhoneyhiveimportHoneyHiveTracerfromopeninference.instrumentation.openaiimportOpenAIInstrumentor# All features are available in the init methodtracer=HoneyHiveTracer.init(
api_key="your-api-key",
source="production",
test_mode=True, # Test mode supportinstrumentors=[OpenAIInstrumentor()], # Auto-integrationdisable_http_tracing=True# Performance control
)

✅ The init method now supports ALL constructor features!

OpenInference Integration

fromhoneyhiveimportHoneyHiveTracerfromopeninference.instrumentation.openaiimportOpenAIInstrumentor# Initialize tracer with OpenInference instrumentor (recommended pattern)tracer=HoneyHiveTracer.init(
api_key="your-api-key",
source="production",
instrumentors=[OpenAIInstrumentor()] # Auto-integration
)
# OpenInference automatically traces OpenAI callsimportopenairesponse=openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello!"}]
)

Enriching Spans and Sessions

v1.0+ Recommended Pattern: Instance Methods

fromhoneyhiveimportHoneyHiveTracer# Initialize tracertracer=HoneyHiveTracer.init(
api_key="your-api-key",
)
# Use instance methods for enrichment (PRIMARY - Recommended)@tracer.trace(event_type="tool")defmy_function(input_data):
result=process_data(input_data)
# ✅ Instance method (PRIMARY pattern in v1.0+)tracer.enrich_span(
metadata={"input": input_data, "result": result},
metrics={"processing_time_ms": 150}
)
returnresult# Enrich session with user propertiestracer.enrich_session(
user_properties={"user_id": "user-123", "plan": "premium"}
)

Legacy Pattern: Free Functions (Backward Compatibility)

For backward compatibility, the free function pattern from v0.2.x still works:

fromhoneyhiveimporttrace, enrich_span, enrich_session# Free functions with automatic tracer discovery (LEGACY)@trace(event_type="tool")defmy_function(input_data):
result=process_data(input_data)
# Free function with auto-discovery (backward compatible)enrich_span(
metadata={"input": input_data, "result": result},
metrics={"processing_time_ms": 150}
)
returnresult# Enrich session via free functionenrich_session(user_properties={"user_id": "user-123"})

⚠️ Deprecation Notice: Free functions will be deprecated in v2.0. We recommend migrating to instance methods for new code.

Why Instance Methods?

  • ✅ Explicit tracer reference (no auto-discovery overhead)
  • ✅ Better multi-instance support (multiple tracers in same process)
  • ✅ Clearer code (explicit is better than implicit)
  • ✅ Future-proof (primary pattern going forward)

🏗️ Architecture

Core Components

src/honeyhive/
├── api/ # API client implementations
│ ├── client.py # Main API client
│ ├── configurations.py # Configuration management
│ ├── datapoints.py # Data point operations
│ ├── datasets.py # Dataset operations
│ ├── events.py # Event management
│ ├── evaluations.py # Evaluation operations
│ ├── metrics.py # Metrics operations
│ ├── projects.py # Project management
│ ├── session.py # Session operations
│ └── tools.py # Tool operations
├── tracer/ # OpenTelemetry integration
│ ├── otel_tracer.py # Main tracer implementation
│ ├── span_processor.py # Custom span processor
│ ├── span_exporter.py # Custom span exporter
│ ├── decorators.py # Tracing decorators
│ └── http_instrumentation.py # HTTP request tracing
├── evaluation/ # Evaluation framework
│ └── evaluators.py # Evaluation decorators
├── models/ # Pydantic models
│ └── generated.py # Auto-generated from OpenAPI
└── utils/ # Utility functions
├── config.py # Configuration management
├── connection_pool.py # HTTP connection pooling
├── retry.py # Retry mechanisms
└── logger.py # Logging utilities

Key Design Principles

  1. Singleton Pattern - Single tracer instance per application
  2. Environment Configuration - Flexible configuration via environment variables
  3. Graceful Degradation - Fallback mechanisms for missing dependencies
  4. Test Isolation - Comprehensive test suite with proper isolation
  5. OpenTelemetry Compliance - Full OTEL standard compliance

⚙️ Configuration

Environment Variables

VariableDescriptionDefault
HH_API_KEYHoneyHive API keyRequired
HH_API_URLAPI base URLhttps://api.dp1.us.honeyhive.ai
HH_SOURCESource environmentproduction
HH_DISABLE_TRACINGDisable tracing completelyfalse
HH_DISABLE_HTTP_TRACINGDisable HTTP request tracingfalse
HH_TEST_MODEEnable test modefalse
HH_DEBUG_MODEEnable debug modefalse
HH_VERBOSEEnable verbose API loggingfalse
HH_OTLP_ENABLEDEnable OTLP exporttrue

Experiment Harness Variables

VariableDescriptionDefault
HH_EXPERIMENT_IDUnique experiment identifierNone
HH_EXPERIMENT_NAMEHuman-readable experiment nameNone
HH_EXPERIMENT_VARIANTExperiment variant/treatmentNone
HH_EXPERIMENT_GROUPExperiment group/cohortNone
HH_EXPERIMENT_METADATAJSON experiment metadataNone

HTTP Client Configuration

VariableDescriptionDefault
HH_MAX_CONNECTIONSMaximum HTTP connections100
HH_MAX_KEEPALIVE_CONNECTIONSKeepalive connections20
HH_KEEPALIVE_EXPIRYKeepalive expiry (seconds)30.0
HH_POOL_TIMEOUTConnection pool timeout30.0
HH_RATE_LIMIT_CALLSRate limit calls per window1000
HH_RATE_LIMIT_WINDOWRate limit window (seconds)60.0
HH_HTTP_PROXYHTTP proxy URLNone
HH_HTTPS_PROXYHTTPS proxy URLNone
HH_NO_PROXYProxy bypass listNone
HH_VERIFY_SSLSSL verificationtrue

🤝 Contributing

Want to contribute to HoneyHive? See CONTRIBUTING.md for development setup and guidelines.

About

No description, website, or topics provided.

Resources

Contributing

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages