fix: 隔离代码代理诊断 trace
This commit is contained in:
@@ -90,6 +90,7 @@ export function compactDiagnoseCodeAgentResult(value: unknown): Record<string, u
|
||||
observabilityGap: source.observabilityGap ?? null,
|
||||
businessTraceIds: source.businessTraceIds ?? null,
|
||||
businessTraceScope: source.businessTraceScope ?? null,
|
||||
diagnosticTrace: compactDiagnosticTrace(source.diagnosticTrace),
|
||||
providerDecision: source.providerDecision ?? null,
|
||||
identity: compactDiagnoseIdentity(source.identity),
|
||||
agentrun: compactDiagnoseAgentRun(source.agentrun),
|
||||
@@ -118,6 +119,26 @@ export function compactDiagnoseCodeAgentResult(value: unknown): Record<string, u
|
||||
};
|
||||
}
|
||||
|
||||
export function compactDiagnosticTrace(value: unknown): Record<string, unknown> | null {
|
||||
const diagnostic = asPlainRecord(value);
|
||||
if (diagnostic === null) return null;
|
||||
return {
|
||||
traceId: diagnostic.traceId ?? null,
|
||||
parentSpanId: diagnostic.parentSpanId ?? null,
|
||||
traceparent: diagnostic.traceparent ?? null,
|
||||
operation: diagnostic.operation ?? null,
|
||||
targetBusinessTraceId: diagnostic.targetBusinessTraceId ?? null,
|
||||
targetCommandId: diagnostic.targetCommandId ?? null,
|
||||
expectedTargetOtelTraceId: diagnostic.expectedTargetOtelTraceId ?? null,
|
||||
contextReady: diagnostic.contextReady ?? null,
|
||||
headerReadPaths: limitArray(diagnostic.headerReadPaths, 3),
|
||||
ordinaryReadPaths: limitArray(diagnostic.ordinaryReadPaths, 2),
|
||||
traceCommand: diagnostic.traceCommand ?? null,
|
||||
targetTraceCommand: diagnostic.targetTraceCommand ?? null,
|
||||
linkQueryClue: diagnostic.linkQueryClue ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
export function compactDiagnoseIdentity(value: unknown): Record<string, unknown> | null {
|
||||
return compactRecord(value, [
|
||||
"runId",
|
||||
@@ -169,7 +190,10 @@ export function compactAgentRunAuthority(value: unknown): Record<string, unknown
|
||||
ok: authority.ok ?? null,
|
||||
commandOk: authority.commandOk ?? null,
|
||||
resultOk: authority.resultOk ?? null,
|
||||
runResultOk: authority.runResultOk ?? null,
|
||||
eventsOk: authority.eventsOk ?? null,
|
||||
diagnosticTransportFailed: authority.diagnosticTransportFailed ?? null,
|
||||
diagnosticTransportFailures: limitArray(authority.diagnosticTransportFailures, 3),
|
||||
commandState: authority.commandState ?? null,
|
||||
commandStatus: authority.commandStatus ?? null,
|
||||
resultTerminalStatus: authority.resultTerminalStatus ?? null,
|
||||
@@ -186,26 +210,43 @@ export function compactAgentRunAuthority(value: unknown): Record<string, unknown
|
||||
error: authority.error ?? null,
|
||||
warnings: limitArray(authority.warnings, 3),
|
||||
};
|
||||
const ok = authority.ok === true && authority.commandOk === true && authority.resultOk === true && authority.eventsOk === true;
|
||||
const ok = authority.ok === true
|
||||
&& authority.commandOk === true
|
||||
&& authority.resultOk === true
|
||||
&& authority.runResultOk === true
|
||||
&& authority.eventsOk === true;
|
||||
if (!ok) {
|
||||
result.attempts = compactAgentRunAuthorityAttempts(authority.attempts);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function compactAgentRunAuthorityAttempts(value: unknown): unknown[] {
|
||||
return asArray(value).slice(0, 3).map((item) => {
|
||||
const attempt = asPlainRecord(item) ?? {};
|
||||
return {
|
||||
name: attempt.name ?? attempt.section ?? attempt.kind ?? null,
|
||||
ok: attempt.ok ?? null,
|
||||
status: attempt.status ?? null,
|
||||
exitCode: attempt.exitCode ?? null,
|
||||
url: attempt.url ?? null,
|
||||
error: shortenEnd(textValue(attempt.error), 240),
|
||||
stderrTail: shortenEnd(textValue(attempt.stderrTail ?? attempt.stderr), 500),
|
||||
};
|
||||
});
|
||||
export function compactAgentRunAuthorityAttempts(value: unknown): unknown {
|
||||
const grouped = asPlainRecord(value);
|
||||
if (grouped !== null) {
|
||||
return Object.fromEntries(Object.entries(grouped).slice(0, 4).map(([name, attempts]) => [
|
||||
name,
|
||||
asArray(attempts).slice(0, 3).map((attempt) => compactAgentRunAuthorityAttempt(attempt)),
|
||||
]));
|
||||
}
|
||||
return asArray(value).slice(0, 3).map((attempt) => compactAgentRunAuthorityAttempt(attempt));
|
||||
}
|
||||
|
||||
function compactAgentRunAuthorityAttempt(value: unknown): Record<string, unknown> {
|
||||
const attempt = asPlainRecord(value) ?? {};
|
||||
return {
|
||||
name: attempt.name ?? attempt.section ?? attempt.kind ?? null,
|
||||
ok: attempt.ok ?? null,
|
||||
status: attempt.status ?? null,
|
||||
exitCode: attempt.exitCode ?? attempt.rc ?? null,
|
||||
method: attempt.method ?? null,
|
||||
url: attempt.url ?? null,
|
||||
proxyPath: attempt.proxyPath ?? null,
|
||||
diagnosticContextApplied: attempt.diagnosticContextApplied ?? null,
|
||||
fallbackDenied: attempt.fallbackDenied ?? null,
|
||||
error: shortenEnd(textValue(attempt.error), 240),
|
||||
stderrTail: shortenEnd(textValue(attempt.stderrTail ?? attempt.stderr), 500),
|
||||
};
|
||||
}
|
||||
|
||||
export function compactDiagnoseCandidate(value: unknown): Record<string, unknown> {
|
||||
|
||||
Reference in New Issue
Block a user