惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
云风的 BLOG
云风的 BLOG
Microsoft Security Blog
Microsoft Security Blog
博客园 - 司徒正美
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
小众软件
小众软件
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
A
About on SuperTechFans
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
B
Blog RSS Feed
G
Google Developers Blog
量子位
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 三生石上(FineUI控件)

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(logging): expose trace fields in file logs · openclaw...
vincentkoc · 2026-04-27 · via Recent Commits to openclaw:main

@@ -202,6 +202,37 @@ function extractTraceContext(value: unknown): DiagnosticTraceContext | undefined

202202

return normalizeTraceContext((value as { trace?: unknown }).trace);

203203

}

204204205+

function getSortedNumericLogArgs(logObj: TsLogRecord): unknown[] {

206+

return Object.entries(logObj)

207+

.filter(([key]) => /^\d+$/.test(key))

208+

.toSorted((a, b) => Number(a[0]) - Number(b[0]))

209+

.map(([, value]) => value);

210+

}

211+212+

function extractLogBindingPrefix(numericArgs: unknown[]): {

213+

bindings?: Record<string, unknown>;

214+

args: unknown[];

215+

} {

216+

if (

217+

typeof numericArgs[0] === "string" &&

218+

numericArgs[0].length <= MAX_DIAGNOSTIC_LOG_BINDINGS_JSON_CHARS &&

219+

numericArgs[0].trim().startsWith("{")

220+

) {

221+

try {

222+

const parsed = JSON.parse(numericArgs[0]);

223+

if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {

224+

return {

225+

bindings: parsed as Record<string, unknown>,

226+

args: numericArgs.slice(1),

227+

};

228+

}

229+

} catch {

230+

// ignore malformed json bindings

231+

}

232+

}

233+

return { args: numericArgs };

234+

}

235+205236

function findLogTraceContext(

206237

bindings: Record<string, unknown> | undefined,

207238

numericArgs: readonly unknown[],

@@ -219,6 +250,20 @@ function findLogTraceContext(

219250

return undefined;

220251

}

221252253+

function buildTraceFileLogFields(logObj: TsLogRecord): Record<string, string> | undefined {

254+

const { bindings, args } = extractLogBindingPrefix(getSortedNumericLogArgs(logObj));

255+

const trace = findLogTraceContext(bindings, args);

256+

if (!trace) {

257+

return undefined;

258+

}

259+

return {

260+

traceId: trace.traceId,

261+

...(trace.spanId ? { spanId: trace.spanId } : {}),

262+

...(trace.parentSpanId ? { parentSpanId: trace.parentSpanId } : {}),

263+

...(trace.traceFlags ? { traceFlags: trace.traceFlags } : {}),

264+

};

265+

}

266+222267

function buildDiagnosticLogRecord(logObj: TsLogRecord) {

223268

const meta = logObj._meta as

224269

| {

@@ -235,27 +280,7 @@ function buildDiagnosticLogRecord(logObj: TsLogRecord) {

235280

};

236281

}

237282

| undefined;

238-

const numericArgs = Object.entries(logObj)

239-

.filter(([key]) => /^\d+$/.test(key))

240-

.toSorted((a, b) => Number(a[0]) - Number(b[0]))

241-

.map(([, value]) => value);

242-243-

let bindings: Record<string, unknown> | undefined;

244-

if (

245-

typeof numericArgs[0] === "string" &&

246-

numericArgs[0].length <= MAX_DIAGNOSTIC_LOG_BINDINGS_JSON_CHARS &&

247-

numericArgs[0].trim().startsWith("{")

248-

) {

249-

try {

250-

const parsed = JSON.parse(numericArgs[0]);

251-

if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {

252-

bindings = parsed as Record<string, unknown>;

253-

numericArgs.shift();

254-

}

255-

} catch {

256-

// ignore malformed json bindings

257-

}

258-

}

283+

const { bindings, args: numericArgs } = extractLogBindingPrefix(getSortedNumericLogArgs(logObj));

259284260285

const trace = findLogTraceContext(bindings, numericArgs);

261286

const structuredArg = numericArgs[0];

@@ -420,7 +445,8 @@ function buildLogger(settings: ResolvedSettings): TsLogger<LogObj> {

420445

currentFileBytes = getCurrentLogFileBytes(activeFile);

421446

}

422447

const time = formatTimestamp(logObj.date ?? new Date(), { style: "long" });

423-

const line = redactSensitiveText(JSON.stringify({ ...logObj, time }));

448+

const traceFields = buildTraceFileLogFields(logObj as TsLogRecord);

449+

const line = redactSensitiveText(JSON.stringify({ ...logObj, time, ...traceFields }));

424450

const payload = `${line}\n`;

425451

const payloadBytes = Buffer.byteLength(payload, "utf8");

426452

const nextBytes = currentFileBytes + payloadBytes;