debug: 所有try/except加exception日志,可追踪API失败的真正原因

This commit is contained in:
yumoqing 2026-07-22 11:49:24 +08:00
parent 1ca9af7a28
commit ac40a08021

View File

@ -40,7 +40,9 @@ async def _resolve_view(request):
else recs[0].get('org_type', ''))
if org_type == 'reseller':
scope = DISTRIBUTOR
except Exception:
except Exception as e:
debug("sage_datamart _resolve_view error: " + str(e))
pass
return scope, org_filter
@ -62,7 +64,9 @@ async def api_model_perf(sor, params_kw=None):
sql += " ORDER BY total_calls DESC LIMIT 50"
rows = await sor.sqlExe(sql, ns)
return [dict(r) for r in rows]
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return []
@ -81,7 +85,9 @@ async def api_provider_roi(sor, params_kw=None):
sql += " ORDER BY total_amount DESC LIMIT 50"
rows = await sor.sqlExe(sql, ns)
return [dict(r) for r in rows]
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return []
@ -98,7 +104,9 @@ async def api_stats(request):
'fail_count': await get_fail_count(env, sor),
'active_users': await get_active_users(env, sor),
}
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return {}
@ -107,7 +115,9 @@ async def api_top_models(request):
env = request._run_ns
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_top_models(env, sor)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return []
@ -116,7 +126,9 @@ async def api_top_providers(request):
env = request._run_ns
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_top_providers(env, sor)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return []
@ -125,7 +137,9 @@ async def api_top_users(request):
env = request._run_ns
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_top_users(env, sor)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return []
@ -138,7 +152,9 @@ async def api_customer_models(request):
'daily': await get_customer_daily_models(env, sor, userorgid),
'monthly': await get_customer_monthly_models(env, sor, userorgid),
}
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return {'daily': [], 'monthly': []}
@ -147,7 +163,9 @@ async def api_daily_trend(request):
env = request._run_ns
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_daily_trend(env, sor)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return []
@ -156,7 +174,9 @@ async def api_hourly_concurrency(request):
env = request._run_ns
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_hourly_concurrency(env, sor)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return []
@ -165,7 +185,9 @@ async def api_currency_stats(request):
env = request._run_ns
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_currency_breakdown(env, sor)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return []
@ -200,7 +222,9 @@ async def api_realtime_cards(request):
'success_rate': await get_scoped_success_rate(sor, today, scope, org_filter),
'fail_count': await get_scoped_fail_count(sor, today, scope, org_filter),
}
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return {}
@ -213,7 +237,9 @@ async def api_distributor_customers(request):
scope, org_filter = await _resolve_view(request)
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_distributor_top_customers(sor, org_filter)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return []
@ -226,7 +252,9 @@ async def j2_realtime_calls(request):
today = env.curDateString()
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_realtime_calls(sor, today, scope, org_filter)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return 0
@ -237,7 +265,9 @@ async def j2_realtime_amount(request):
today = env.curDateString()
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_realtime_amount(sor, today, scope, org_filter)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return 0
@ -249,7 +279,9 @@ async def j2_total_users(request):
if scope == DISTRIBUTOR:
return await get_distributor_customers_count(sor, org_filter)
return await get_total_users_count(sor, scope, org_filter)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return 0
@ -262,7 +294,9 @@ async def j2_active_today(request):
if scope == DISTRIBUTOR:
return await get_distributor_active_customers(sor, today, org_filter)
return await get_realtime_active_users(sor, today, scope, org_filter)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return 0
@ -270,7 +304,9 @@ async def j2_online_users(request):
try:
env = request._run_ns
return await get_online_users(env)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return 0
@ -281,7 +317,9 @@ async def j2_scoped_success_rate(request):
today = env.curDateString()
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_scoped_success_rate(sor, today, scope, org_filter)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return 0
@ -292,7 +330,9 @@ async def j2_scoped_fail_count(request):
today = env.curDateString()
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_scoped_fail_count(sor, today, scope, org_filter)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return 0
@ -303,7 +343,9 @@ async def j2_today_usage(request):
env = request._run_ns
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_today_usage(env, sor)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return 0
@ -312,7 +354,9 @@ async def j2_today_amount(request):
env = request._run_ns
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_today_amount(env, sor)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return 0
@ -321,7 +365,9 @@ async def j2_active_users(request):
env = request._run_ns
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_active_users(env, sor)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return 0
@ -330,7 +376,9 @@ async def j2_fail_count(request):
env = request._run_ns
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_fail_count(env, sor)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return 0
@ -339,7 +387,9 @@ async def j2_success_rate(request):
env = request._run_ns
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_success_rate(env, sor)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return 0
@ -348,7 +398,9 @@ async def j2_avg_ttft(request):
env = request._run_ns
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_avg_ttft(env, sor)
except Exception:
except Exception as e:
debug("sage_datamart API error: " + str(e))
return 0