Sherlock AI
A Python package for performance monitoring and logging utilities that helps you track execution times and debug your applications with ease.
Overview
Sherlock AI provides a comprehensive suite of tools for monitoring, logging, and analyzing Python applications. Whether you're building APIs, data pipelines, or any Python application, Sherlock AI helps you understand performance characteristics, track errors, and maintain code quality.
Key Features
- ๐ฏ Performance Decorators: Easy-to-use decorators for tracking function execution times
- ๐ง Memory Monitoring: Track Python memory usage with detailed heap and tracemalloc integration
- ๐ Resource Monitoring: Monitor CPU, memory, I/O, and network usage during function execution
- โฑ๏ธ Context Managers: Monitor code block execution with simple context managers
- ๐ง Advanced Configuration System: Complete control over logging with dataclass-based configuration
- โก Simplified Configuration: Auto-expanding file paths - just specify base names instead of full paths
- ๐๏ธ Configuration Presets: Pre-built setups for development, production, and testing environments
- ๐ Async/Sync Support: Works seamlessly with both synchronous and asynchronous functions
- ๐ Request Tracking: Built-in request ID tracking for distributed systems
- ๐ Flexible Log Management: Enable/disable log files, custom directories, and rotation settings
- ๐ท๏ธ Logger Name Constants: Easy access to available logger names with autocomplete support
- ๐ Logger Discovery: Programmatically discover available loggers in your application
- ๐ Development-Friendly: Optimized for FastAPI auto-reload and development environments
- ๐จ Modular Architecture: Clean, focused modules for different monitoring aspects
- ๐๏ธ Class-Based Architecture: Advanced
SherlockAIclass for instance-based logging management - ๐ Runtime Reconfiguration: Change logging settings without application restart
- ๐งน Resource Management: Automatic cleanup and context manager support
- ๐ Logging Introspection: Query current logging configuration and statistics
- ๐ JSON Format Support: Choose between standard log format or structured JSON output for better parsing and analysis
- ๐ Code Analysis: Automatic detection and refactoring of hardcoded values using AST parsing and LLM suggestions
- ๐๏ธ MongoDB Integration: Automatic error insights storage with MongoDB support
- ๐ API Client Integration: HTTP-based data ingestion to centralized backend services
- ๐จ Error Analysis: AI-powered error analysis with automatic probable cause detection
- ๐ก Performance Insights: AI-powered performance analysis that intelligently extracts user-defined function source code
- ๐ Auto-Instrumentation: Zero-code setup for popular frameworks like FastAPI, automatically instrumenting routes with monitoring decorators
Quick Start
Installation
Basic Usage
from sherlock_ai import sherlock_ai, get_logger, log_performance
import time
# Initialize logging (call once at application startup)
sherlock_ai()
# Get a logger for your module
logger = get_logger(__name__)
@log_performance
def my_function():
time.sleep(1)
logger.info("Processing completed")
return "result"
# This will log: PERFORMANCE | my_module.my_function | SUCCESS | 1.003s
result = my_function()
What's Next?
-
Install Sherlock AI and learn about requirements
-
Get up and running in minutes with basic examples
-
Explore performance, memory, and resource monitoring
-
Learn how to configure Sherlock AI for your needs
-
Real-world examples and integration patterns
-
Complete API documentation and reference
Use Cases
- API Performance Monitoring: Track response times for your web APIs
- Memory Leak Detection: Monitor memory usage patterns to identify potential leaks
- Resource Optimization: Analyze CPU, memory, and I/O usage
- Database Query Optimization: Monitor slow database operations
- Microservices Debugging: Trace execution times across service boundaries
- Production Monitoring: Get insights into application performance characteristics
- Error Analysis & Debugging: AI-powered error analysis with automatic storage
- Code Quality Improvement: Automatically detect and refactor hardcoded values
Authors
Pranaw Mishra - pranawmishra73@gmail.com
License
This project is licensed under the MIT License - see the LICENSE file for details.