feat: add detailed logging for module loading and context providers
Add INFO-level logging to help diagnose module loading issues: - discovery.py: Log summary of discovered modules by tier (core/optional/internal) - service.py: Log which modules are enabled for each platform (DEBUG level) - page_context.py: Log context building with platform info and which modules contributed context with key counts Example log output: [MODULES] Auto-discovered 18 modules: 5 core, 11 optional, 2 internal [CONTEXT] Building PLATFORM context for platform 'main' with 5 enabled modules [CONTEXT] Context providers called: cms(3 keys), billing(3 keys) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -93,13 +93,24 @@ def get_context_for_frontend(
|
||||
# Determine which modules are enabled for this platform
|
||||
if platform:
|
||||
enabled_module_codes = module_service.get_enabled_module_codes(db, platform.id)
|
||||
logger.info(
|
||||
f"[CONTEXT] Building {frontend_type.value} context for platform "
|
||||
f"'{platform.code}' with {len(enabled_module_codes)} enabled modules"
|
||||
)
|
||||
else:
|
||||
# No platform context - only core modules
|
||||
enabled_module_codes = {
|
||||
code for code, module in MODULES.items() if module.is_core
|
||||
}
|
||||
logger.info(
|
||||
f"[CONTEXT] Building {frontend_type.value} context (no platform) with "
|
||||
f"{len(enabled_module_codes)} core modules: {sorted(enabled_module_codes)}"
|
||||
)
|
||||
|
||||
# Collect context from enabled modules that have providers for this frontend
|
||||
modules_with_providers = []
|
||||
modules_contributed = []
|
||||
|
||||
for code in enabled_module_codes:
|
||||
module = MODULES.get(code)
|
||||
if module is None:
|
||||
@@ -108,15 +119,17 @@ def get_context_for_frontend(
|
||||
if not module.has_context_provider(frontend_type):
|
||||
continue
|
||||
|
||||
modules_with_providers.append(code)
|
||||
|
||||
try:
|
||||
contribution = module.get_context_contribution(
|
||||
frontend_type, request, db, platform
|
||||
)
|
||||
if contribution:
|
||||
context.update(contribution)
|
||||
modules_contributed.append(f"{code}({len(contribution)} keys)")
|
||||
logger.debug(
|
||||
f"[CONTEXT] Module '{code}' contributed {len(contribution)} keys "
|
||||
f"for {frontend_type.value}"
|
||||
f"[CONTEXT] Module '{code}' contributed: {list(contribution.keys())}"
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
@@ -124,6 +137,15 @@ def get_context_for_frontend(
|
||||
f"{frontend_type.value}: {e}"
|
||||
)
|
||||
|
||||
if modules_contributed:
|
||||
logger.info(
|
||||
f"[CONTEXT] Context providers called: {', '.join(modules_contributed)}"
|
||||
)
|
||||
elif modules_with_providers:
|
||||
logger.info(
|
||||
f"[CONTEXT] {len(modules_with_providers)} modules have providers but none contributed"
|
||||
)
|
||||
|
||||
# Add any extra context passed by the caller
|
||||
if extra_context:
|
||||
context.update(extra_context)
|
||||
|
||||
Reference in New Issue
Block a user