fix: 全链路追踪时间显示 — UTC→UTC+8 本地时间

- 新增 formatLocalTime() 替换 toISOString()
- 追踪面板时间显示为北京时间

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-06-23 19:17:32 +08:00
parent a47eeab808
commit e433e94c89
+12 -4
View File
@@ -1304,7 +1304,7 @@ app.get('/api/trace/recent', async (req, res) => {
const groupName = entry.group_name ? ` (${entry.group_name})` : ''; const groupName = entry.group_name ? ` (${entry.group_name})` : '';
traces.push({ traces.push({
id: `msg-${ts}-${Math.random().toString(36).slice(2, 6)}`, id: `msg-${ts}-${Math.random().toString(36).slice(2, 6)}`,
timestamp: new Date(ts).toISOString(), ts, timestamp: formatLocalTime(ts), ts,
service: 'platform-bridge', service: 'platform-bridge',
hop, hop,
label: `${icon} ${isIncoming ? '收到' : '发送'}消息 · ${entry.platform || '?'}${groupName}`, label: `${icon} ${isIncoming ? '收到' : '发送'}消息 · ${entry.platform || '?'}${groupName}`,
@@ -1322,7 +1322,7 @@ app.get('/api/trace/recent', async (req, res) => {
const ts = call.time ? new Date(call.time).getTime() : Date.now(); const ts = call.time ? new Date(call.time).getTime() : Date.now();
traces.push({ traces.push({
id: `llm-${ts}-${Math.random().toString(36).slice(2, 6)}`, id: `llm-${ts}-${Math.random().toString(36).slice(2, 6)}`,
timestamp: new Date(ts).toISOString(), ts, timestamp: formatLocalTime(ts), ts,
service: 'ai-core', hop: 'llm_call', service: 'ai-core', hop: 'llm_call',
label: `🧠 LLM: ${call.model || 'unknown'}`, label: `🧠 LLM: ${call.model || 'unknown'}`,
status: call.success ? 'success' : 'error', status: call.success ? 'success' : 'error',
@@ -1355,7 +1355,7 @@ app.get('/api/trace/recent', async (req, res) => {
const ts = ev.timestamp ? new Date(ev.timestamp).getTime() : Date.now(); const ts = ev.timestamp ? new Date(ev.timestamp).getTime() : Date.now();
traces.push({ traces.push({
id: ev.id || `trace-${ts}`, id: ev.id || `trace-${ts}`,
timestamp: new Date(ts).toISOString(), ts, timestamp: formatLocalTime(ts), ts,
service: 'ai-core', service: 'ai-core',
hop: ev.hop || 'trace', hop: ev.hop || 'trace',
label: ev.label || '', label: ev.label || '',
@@ -1373,7 +1373,7 @@ app.get('/api/trace/recent', async (req, res) => {
const ts = s.last_activity ? new Date(s.last_activity).getTime() : Date.now(); const ts = s.last_activity ? new Date(s.last_activity).getTime() : Date.now();
traces.push({ traces.push({
id: `session-${s.session_id || ''}`, id: `session-${s.session_id || ''}`,
timestamp: new Date(ts).toISOString(), ts, timestamp: formatLocalTime(ts), ts,
service: 'gateway', hop: 'session', service: 'gateway', hop: 'session',
label: `👤 会话: ${userID}`, label: `👤 会话: ${userID}`,
status: s.state === 'streaming' ? 'running' : 'success', status: s.state === 'streaming' ? 'running' : 'success',
@@ -1907,6 +1907,14 @@ server.listen(ETHEND_PORT, () => {
} }
}); });
// 时间格式化:UTC+8 本地时间
function formatLocalTime(ts) {
var d = new Date(ts);
var pad = function(n) { return n < 10 ? '0' + n : '' + n; };
return d.getFullYear() + '-' + pad(d.getMonth()+1) + '-' + pad(d.getDate()) + ' ' +
pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds());
}
// 优雅退出 // 优雅退出
process.on('SIGINT', async () => { process.on('SIGINT', async () => {
console.log('\n关闭所有服务...'); console.log('\n关闭所有服务...');