docs: Add comprehensive enhanced logging migration plan for PR #77 #573
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Enhanced Logging Migration Plan
Issue: #77
Documentation: docs/development/logging.md
Executive Summary
This plan outlines how to use the new enhanced logging system and migrate existing code. The enhanced logging system provides structured context tracking, request correlation, and performance monitoring with zero configuration changes needed by developers.
🎯 Component Overview
1. log_storage_service.py - In-Memory Log Storage
Purpose: Provides queryable log storage for debugging and admin UI
Key Features:
When to Use:
Direct Usage (rare - usually accessed via LoggingService):
2. enhanced_logging.py - Main Logging Orchestrator
Purpose: Central logging service that coordinates formatters, handlers, and storage
Key Features:
When to Use:
Usage:
3. logging_context.py - Context Management
Purpose: Provides context managers for tracking operations with automatic timing and context propagation
Key Features:
When to Use:
Usage:
4. enhanced_logging_example.py - Reference Examples
Purpose: Comprehensive examples showing integration patterns
Contains:
When to Use:
Usage:
🚀 Migration Strategy
Phase 1: Application Startup (Priority: HIGH)
File:
backend/main.pyCurrent State:
Migrated State:
Testing:
Phase 2: Core Services (Priority: HIGH)
2.1 SearchService
File:
backend/rag_solution/services/search_service.pyChanges:
PipelineStage.QUERY_VALIDATIONPipelineStage.QUERY_REWRITINGPipelineStage.VECTOR_SEARCHPipelineStage.RERANKINGPipelineStage.LLM_GENERATIONTesting:
2.2 ChainOfThoughtService
File:
backend/rag_solution/services/chain_of_thought_service.pyChanges:
PipelineStage.COT_QUESTION_DECOMPOSITIONPipelineStage.COT_REASONINGPipelineStage.COT_ANSWER_SYNTHESISTesting:
2.3 DocumentService
File:
backend/rag_solution/services/document_service.pyChanges:
PipelineStage.DOCUMENT_PARSINGPipelineStage.DOCUMENT_CHUNKINGPipelineStage.EMBEDDING_GENERATIONPipelineStage.DOCUMENT_INDEXINGTesting:
Phase 3: Pipeline Stages (Priority: MEDIUM)
Files:
backend/rag_solution/services/pipeline/stages/query_enhancement_stage.pybackend/rag_solution/services/pipeline/stages/retrieval_stage.pybackend/rag_solution/services/pipeline/stages/reranking_stage.pybackend/rag_solution/services/pipeline/stages/generation_stage.pyChanges:
Each stage should wrap its execution with appropriate pipeline stage context:
Testing:
Phase 4: API Routers (Priority: MEDIUM)
Files:
backend/rag_solution/router/search_router.pybackend/rag_solution/router/collection_router.pybackend/rag_solution/router/document_router.pyChanges:
Add request context at API boundaries:
Testing:
Phase 5: Repository Layer (Priority: LOW)
Files:
backend/rag_solution/repository/*.pyChanges:
Add logging for database operations with entity context:
Note: Repository layer typically doesn't need
log_operationcontext managers since operations are short. Simple structured logging withextrais sufficient.Testing:
📊 New Admin API Endpoints
Add endpoints to query logs and get statistics:
File:
backend/rag_solution/router/admin_router.py(new or existing)✅ Validation Checklist
After Each Service Migration:
After Complete Migration:
🎯 Priority Order
📈 Expected Benefits
Development:
Production:
🔍 Testing Strategy
Unit Tests:
# Test enhanced logging components pytest tests/unit/test_enhanced_logging.py -vIntegration Tests:
# Test with real services pytest tests/integration/test_search_with_logging.py -vManual Testing:
📚 References
🚦 Next Steps
❓ Questions?
backend/core/enhanced_logging_example.py