fix: diagnose code agent by agentrun ids
This commit is contained in:
@@ -141,18 +141,34 @@ export function businessTraceIdFromSearchText(value: string | null): string | nu
|
||||
return match?.[0] ?? null;
|
||||
}
|
||||
|
||||
function diagnoseTraceSearchFilters(options: DiagnoseCodeAgentOptions): string[] {
|
||||
const filters: string[] = [];
|
||||
if (options.businessTraceId !== null) filters.push(`.traceId = ${JSON.stringify(options.businessTraceId)}`);
|
||||
if (options.runId !== null) filters.push(`.runId = ${JSON.stringify(options.runId)}`);
|
||||
if (options.commandId !== null) filters.push(`.commandId = ${JSON.stringify(options.commandId)}`);
|
||||
if (options.runnerJobId !== null) filters.push(`.runnerJobId = ${JSON.stringify(options.runnerJobId)}`);
|
||||
return filters;
|
||||
}
|
||||
|
||||
function diagnoseTraceSearchMode(options: DiagnoseCodeAgentOptions): string {
|
||||
if (options.businessTraceId !== null && options.runId === null && options.commandId === null && options.runnerJobId === null) return "business-trace-id";
|
||||
return "trace-attribute-query";
|
||||
}
|
||||
|
||||
export async function diagnoseCodeAgent(config: UniDeskConfig, options: DiagnoseCodeAgentOptions): Promise<Record<string, unknown> | RenderedCliResult> {
|
||||
const observability = readObservabilityConfig();
|
||||
const target = resolveTarget(observability, options.targetId);
|
||||
const endSeconds = Math.floor(Date.now() / 1000);
|
||||
const startSeconds = endSeconds - (options.lookbackMinutes * 60);
|
||||
let searchPath: string | null = null;
|
||||
if (options.traceId === null && options.businessTraceId !== null) {
|
||||
const searchFilters = diagnoseTraceSearchFilters(options);
|
||||
const tempoQuery = searchFilters.length > 0 ? `{ ${searchFilters.join(" && ")} }` : null;
|
||||
if (options.traceId === null && tempoQuery !== null) {
|
||||
const params = new URLSearchParams({
|
||||
start: String(startSeconds),
|
||||
end: String(endSeconds),
|
||||
limit: String(options.candidateLimit),
|
||||
q: `{ .traceId = "${options.businessTraceId}" }`,
|
||||
q: tempoQuery,
|
||||
});
|
||||
searchPath = `/api/search?${params.toString()}`;
|
||||
}
|
||||
@@ -164,6 +180,11 @@ export async function diagnoseCodeAgent(config: UniDeskConfig, options: Diagnose
|
||||
service: observability.traceBackend.serviceName,
|
||||
businessTraceId: options.businessTraceId,
|
||||
traceId: options.traceId,
|
||||
runId: options.runId,
|
||||
commandId: options.commandId,
|
||||
runnerJobId: options.runnerJobId,
|
||||
mode: diagnoseTraceSearchMode(options),
|
||||
tempoQuery,
|
||||
path: searchPath,
|
||||
lookbackMinutes: options.lookbackMinutes,
|
||||
candidateLimit: options.candidateLimit,
|
||||
@@ -530,6 +551,7 @@ export function renderDiagnoseCodeAgentTable(input: {
|
||||
"",
|
||||
"Identity:",
|
||||
` businessTraceId=${textValue(mapping?.businessTraceId ?? input.query.businessTraceId)} otelTraceId=${traceId}`,
|
||||
` queryMode=${textValue(mapping?.mode ?? input.query.mode)} tempoQuery=${shortenMiddle(textValue(mapping?.searchQuery ?? input.query.tempoQuery), 80)}`,
|
||||
` runId=${textValue(identity?.runId)} commandId=${textValue(identity?.commandId)} runnerJobId=${textValue(identity?.runnerJobId)} runnerId=${textValue(identity?.runnerId)}`,
|
||||
` backendProfile=${textValue(identity?.backendProfile)} sourceCommit=${shortenMiddle(textValue(identity?.sourceCommit), 20)}`,
|
||||
"",
|
||||
@@ -541,7 +563,7 @@ export function renderDiagnoseCodeAgentTable(input: {
|
||||
"",
|
||||
"Summary:",
|
||||
` target=${input.target.id} spanCount=${textValue(input.result.spanCount)} servicePath=${joinValues(input.result.servicePath, 60)}`,
|
||||
` agentrun=${textValue(agentrun?.terminalStatus)} source=${textValue(agentrun?.terminalSource)} authority=${shortenEnd(JSON.stringify((asPlainRecord(agentrun?.authority) ?? {})), 120)}`,
|
||||
` agentrun=${textValue(agentrun?.terminalStatus)} failureKind=${textValue(agentrun?.failureKind)} source=${textValue(agentrun?.terminalSource)} authority=${shortenEnd(JSON.stringify((asPlainRecord(agentrun?.authority) ?? {})), 120)}`,
|
||||
` readModel=${shortenEnd(JSON.stringify(input.result.hwlabReadModel ?? null), 140)}`,
|
||||
];
|
||||
const next = asPlainRecord(input.result.next);
|
||||
|
||||
Reference in New Issue
Block a user