From 7fefab1508304f9dc8fa7fcee1b1af85658eccb1 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Mon, 2 Feb 2026 19:32:32 +0100 Subject: [PATCH] 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 --- app/modules/core/utils/page_context.py | 26 ++++++++++++++++++++++++-- app/modules/discovery.py | 12 +++++++++++- app/modules/service.py | 5 +++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/modules/core/utils/page_context.py b/app/modules/core/utils/page_context.py index 9f109271..fdc28729 100644 --- a/app/modules/core/utils/page_context.py +++ b/app/modules/core/utils/page_context.py @@ -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) diff --git a/app/modules/discovery.py b/app/modules/discovery.py index 86930463..238ff6c2 100644 --- a/app/modules/discovery.py +++ b/app/modules/discovery.py @@ -109,7 +109,17 @@ def discover_modules() -> dict[str, "ModuleDefinition"]: except Exception as e: logger.error(f"Error discovering module in {module_dir}: {e}") - logger.info(f"Auto-discovered {len(modules)} modules") + # Log summary by tier + core = [c for c, m in modules.items() if m.is_core] + internal = [c for c, m in modules.items() if m.is_internal] + optional = [c for c, m in modules.items() if not m.is_core and not m.is_internal] + + logger.info( + f"[MODULES] Auto-discovered {len(modules)} modules: " + f"{len(core)} core ({', '.join(sorted(core))}), " + f"{len(optional)} optional ({', '.join(sorted(optional))}), " + f"{len(internal)} internal ({', '.join(sorted(internal))})" + ) return modules diff --git a/app/modules/service.py b/app/modules/service.py index c13c3b1f..77583fb2 100644 --- a/app/modules/service.py +++ b/app/modules/service.py @@ -182,6 +182,11 @@ class ModuleService: # Resolve dependencies - add required modules enabled_set = self._resolve_dependencies(enabled_set) + logger.debug( + f"[MODULES] Platform '{platform.code}' (id={platform_id}) has " + f"{len(enabled_set)} modules enabled: {sorted(enabled_set)}" + ) + return enabled_set def _migrate_json_to_junction_table(