logs: migrate to molecular CoT JSON protocol, fix regressions
- Replace BeliefFormatter with CotJsonFormatter (single-line JSON with ts, level, trace_id, src, marker, intent, payload, error, span_id) - Migrate belief_scope to use cot_log() for structured JSON output - Update monkey-patched reason/reflect/explore to pass extra= dict - Strip 200+ inline [REASON]/[REFLECT]/[EXPLORE] markers from 50+ files - Remove belief_scope from hot-path utilities (_parse_datetime, _json_load_if_needed) to eliminate startup log noise - Register TraceContextMiddleware in app.py (was implemented but unused) - Seed trace_id in startup_event/shutdown_event for background tasks - Fix broken relative imports in translate routes (3 dots → 4 dots) - Migrate 43 translate_routes log calls to logger.reason/explore - Fix SyntaxError (positional arg after extra=) in _repo_operations_routes - Fix IndentationError in rbac_permission_catalog except-block - Add smoke test tests/test_smoke_app.py (catches import errors before run)
This commit is contained in:
@@ -164,8 +164,9 @@ def _ensure_target_schema(engine) -> None:
|
||||
def _migrate_config(engine, legacy_config_path: Optional[Path]) -> int:
|
||||
with belief_scope("_migrate_config"):
|
||||
if legacy_config_path is None:
|
||||
logger.info(
|
||||
"[_migrate_config][REASON] No legacy config.json found, skipping"
|
||||
logger.reason(
|
||||
"No legacy config.json found, skipping",
|
||||
extra={"src": "_migrate_config"},
|
||||
)
|
||||
return 0
|
||||
|
||||
@@ -327,8 +328,9 @@ def run_migration(
|
||||
sqlite_path: Path, target_url: str, legacy_config_path: Optional[Path]
|
||||
) -> Dict[str, int]:
|
||||
with belief_scope("run_migration"):
|
||||
logger.info(
|
||||
"[run_migration][REASON] sqlite=%s target=%s", sqlite_path, target_url
|
||||
logger.reason(
|
||||
f"sqlite={sqlite_path} target={target_url}",
|
||||
extra={"src": "run_migration"},
|
||||
)
|
||||
if not sqlite_path.exists():
|
||||
raise FileNotFoundError(f"SQLite source not found: {sqlite_path}")
|
||||
|
||||
@@ -157,8 +157,9 @@ def _resolve_target_envs(env_ids: List[str]) -> Dict[str, Environment]:
|
||||
env = Environment(**row)
|
||||
configured[env.id] = env
|
||||
except Exception as exc:
|
||||
logger.warning(
|
||||
f"[REFLECT] Failed loading environments from {config_path}: {exc}"
|
||||
logger.reflect(
|
||||
f"Failed loading environments from {config_path}: {exc}",
|
||||
extra={"src": "_resolve_target_envs"},
|
||||
)
|
||||
|
||||
for env_id in env_ids:
|
||||
@@ -271,8 +272,9 @@ def seed_superset_load_data(args: argparse.Namespace) -> Dict:
|
||||
templates_by_env[env_id] = _build_chart_template_pool(
|
||||
client, args.template_pool_size, rng
|
||||
)
|
||||
logger.info(
|
||||
f"[REASON] Environment {env_id}: loaded {len(templates_by_env[env_id])} chart templates"
|
||||
logger.reason(
|
||||
f"Environment {env_id}: loaded {len(templates_by_env[env_id])} chart templates",
|
||||
extra={"src": "seed_superset_load_data"},
|
||||
)
|
||||
|
||||
errors = 0
|
||||
@@ -285,8 +287,9 @@ def seed_superset_load_data(args: argparse.Namespace) -> Dict:
|
||||
dashboard_title = _generate_unique_name("lt_dash", used_dashboard_names, rng)
|
||||
|
||||
if args.dry_run:
|
||||
logger.info(
|
||||
f"[REFLECT] Dry-run dashboard create: env={env_id}, title={dashboard_title}"
|
||||
logger.reflect(
|
||||
f"Dry-run dashboard create: env={env_id}, title={dashboard_title}",
|
||||
extra={"src": "seed_superset_load_data"},
|
||||
)
|
||||
continue
|
||||
|
||||
@@ -301,7 +304,7 @@ def seed_superset_load_data(args: argparse.Namespace) -> Dict:
|
||||
created_dashboards[env_id].append(dashboard_id)
|
||||
except Exception as exc:
|
||||
errors += 1
|
||||
logger.error(f"[EXPLORE] Failed creating dashboard in {env_id}: {exc}")
|
||||
logger.explore(f"Failed creating dashboard in {env_id}: {exc}", extra={"src": "seed_superset_load_data"})
|
||||
if errors >= args.max_errors:
|
||||
raise RuntimeError(
|
||||
f"Stopping due to max errors reached ({errors})"
|
||||
@@ -351,10 +354,10 @@ def seed_superset_load_data(args: argparse.Namespace) -> Dict:
|
||||
created_charts[env_id].append(chart_id)
|
||||
|
||||
if (index + 1) % 500 == 0:
|
||||
logger.info(f"[REASON] Created {index + 1}/{args.charts} charts")
|
||||
logger.reason(f"Created {index + 1}/{args.charts} charts", extra={"src": "seed_superset_load_data"})
|
||||
except Exception as exc:
|
||||
errors += 1
|
||||
logger.error(f"[EXPLORE] Failed creating chart in {env_id}: {exc}")
|
||||
logger.explore(f"Failed creating chart in {env_id}: {exc}", extra={"src": "seed_superset_load_data"})
|
||||
if errors >= args.max_errors:
|
||||
raise RuntimeError(
|
||||
f"Stopping due to max errors reached ({errors})"
|
||||
@@ -381,8 +384,9 @@ def main() -> None:
|
||||
with belief_scope("seed_superset_load_test.main"):
|
||||
args = _parse_args()
|
||||
result = seed_superset_load_data(args)
|
||||
logger.info(
|
||||
f"[REFLECT] Result summary: {json.dumps(result, ensure_ascii=True)}"
|
||||
logger.reflect(
|
||||
f"Result summary: {json.dumps(result, ensure_ascii=True)}",
|
||||
extra={"src": "main"},
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user