Merge pull request #1686 from pikasTech/fix/otel-dispatch-error-details
增强 AgentRun dispatch 失败的 OTel 错误属性
This commit is contained in:
@@ -829,10 +829,11 @@ async function submitCodeAgentChatTurn({ params, options, traceId }) {
|
|||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (isCodeAgentResultCanceled(results.get(traceId))) return;
|
if (isCodeAgentResultCanceled(results.get(traceId))) return;
|
||||||
|
const dispatchErrorAttributes = codeAgentDispatchErrorOtelAttributes(error);
|
||||||
void emitCodeAgentOtelSpan("agentrun_dispatch", traceId, executionOptions.env ?? process.env, {
|
void emitCodeAgentOtelSpan("agentrun_dispatch", traceId, executionOptions.env ?? process.env, {
|
||||||
status: "error",
|
status: "error",
|
||||||
error,
|
error,
|
||||||
attributes: { sessionId: safeSessionId(params.sessionId) || null, turnId: codeAgentTurnLifecycleFields(traceId, params).turnId }
|
attributes: { sessionId: safeSessionId(params.sessionId) || null, turnId: codeAgentTurnLifecycleFields(traceId, params).turnId, ...dispatchErrorAttributes }
|
||||||
});
|
});
|
||||||
await settleAdmittedCodeAgentFailure({
|
await settleAdmittedCodeAgentFailure({
|
||||||
base: initial ?? codeAgentAdmittedFailureBasePayload({ params, options, traceId }),
|
base: initial ?? codeAgentAdmittedFailureBasePayload({ params, options, traceId }),
|
||||||
@@ -1028,6 +1029,23 @@ function codeAgentDispatchFailure(error) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function codeAgentDispatchErrorOtelAttributes(error) {
|
||||||
|
const agentRunError = error?.agentRunError && typeof error.agentRunError === "object" ? error.agentRunError : null;
|
||||||
|
const details = agentRunError?.error?.details && typeof agentRunError.error.details === "object" ? agentRunError.error.details : null;
|
||||||
|
return {
|
||||||
|
failureKind: safeOtelText(error?.code ?? agentRunError?.failureKind, 120),
|
||||||
|
upstreamStatusCode: Number.isInteger(error?.statusCode) ? error.statusCode : null,
|
||||||
|
upstreamTraceId: safeTraceId(agentRunError?.traceId) || null,
|
||||||
|
upstreamMessage: safeOtelText(agentRunError?.message ?? error?.message, 300),
|
||||||
|
upstreamStderrTail: safeOtelText(details?.stderr, 600)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function safeOtelText(value, limit = 300) {
|
||||||
|
const text = String(value ?? "").replace(/[\u0000-\u001f\u007f]+/gu, " ").trim();
|
||||||
|
return text ? text.slice(0, limit) : null;
|
||||||
|
}
|
||||||
|
|
||||||
function codeAgentAdmittedFailureBasePayload({ params = {}, options = {}, traceId } = {}) {
|
function codeAgentAdmittedFailureBasePayload({ params = {}, options = {}, traceId } = {}) {
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user