Skip to content

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.

View example →

Async Functions

Monitor asynchronous functions and coroutines.

View example →

MongoDB Storage

Store error insights and performance data in MongoDB.

View example →

API Client Integration

HTTP-based data ingestion to centralized backend.

View example →

Combined Monitoring

Use multiple decorators together for comprehensive monitoring.

View example →

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:

Next Steps