Examples
Real-world examples and integration patterns for Sherlock AI. These examples demonstrate practical usage scenarios with complete, runnable code.
Example Categories
FastAPI Integration
Complete FastAPI application with auto-instrumentation and manual decorators.
Async Functions
Monitor asynchronous functions and coroutines.
MongoDB Storage
Store error insights and performance data in MongoDB.
API Client Integration
HTTP-based data ingestion to centralized backend.
Combined Monitoring
Use multiple decorators together for comprehensive monitoring.
Quick Examples
Basic Monitoring
from sherlock_ai import sherlock_ai, get_logger, log_performance
sherlock_ai()
logger = get_logger(__name__)
@log_performance
def process_data(data):
logger.info(f"Processing {len(data)} items")
result = sum(data)
return result
result = process_data([1, 2, 3, 4, 5])
Error Analysis
from sherlock_ai.monitoring import sherlock_error_handler
import os
os.environ["MONGO_URI"] = "mongodb://localhost:27017"
@sherlock_error_handler
def risky_operation():
result = 1 / 0 # AI analyzes this error
return result
Memory Monitoring
from sherlock_ai import monitor_memory
@monitor_memory(trace_malloc=True)
def allocate_memory():
data = [i * i for i in range(1000000)]
return len(data)
Complete Application Examples
Explore detailed, production-ready examples:
- FastAPI Integration - Full web application setup
- Async Functions - Async/await patterns
- MongoDB Storage - Error insight storage
- API Client - Centralized monitoring
- Combined Monitoring - Multiple features together
Next Steps
- Features - Learn about available features
- Configuration - Configure Sherlock AI