diff --git a/cypher-executor/src/graph-executor.ts b/cypher-executor/src/graph-executor.ts index c2542a1..869e86e 100644 --- a/cypher-executor/src/graph-executor.ts +++ b/cypher-executor/src/graph-executor.ts @@ -6,6 +6,7 @@ import { tryAuthDispatch } from './actions/auth-dispatcher'; import { expandPromptRecipe } from './lib/recipe-expander'; import { persistPausedRun, isResumablePending, parseRecipeOutput } from './lib/paused-runs'; import { buildMagicVars } from './lib/magic-vars'; +import { recordTelemetry } from './lib/telemetry'; export type ComponentLoader = (componentId: string) => Promise; export type WorkflowLoader = (workflowId: string) => Promise; @@ -352,14 +353,25 @@ export class GraphExecutor { if (e instanceof WorkflowPaused) throw e; const errMsg = e.message || String(e); + const duration_ms = Date.now() - start; trace.push({ nodeId: node.id, type: node.type, input: nodeInput, output: null, error: errMsg, - duration_ms: Date.now() - start, + duration_ms, }); + // Step-level telemetry:node 失敗事件(LI SDD M2.x 自評建議) + if (this.env && node.type === 'Component') { + recordTelemetry(this.env, this.apiKey, { + event_type: 'node_failure', + workflow_name: graph.name, + component_id: node.componentId, + error_code: 'node_error', + duration_ms, + }); + } // 若已是 ExecutionError(上游節點拋出),保留原始 trace 繼續往上傳 if (e instanceof ExecutionError) throw e; throw new ExecutionError( @@ -370,14 +382,26 @@ export class GraphExecutor { ); } + const duration_ms = Date.now() - start; trace.push({ nodeId: node.id, type: node.type, input: nodeInput, output: result, - duration_ms: Date.now() - start, + duration_ms, }); + // Step-level telemetry:node 成功事件(只記 Component,Input/Output 跳過) + // LI SDD M2.x:給 weekly_review 提的「效能基準線」建議用 — 每個 node duration 都可追 + if (this.env && node.type === 'Component') { + recordTelemetry(this.env, this.apiKey, { + event_type: 'node_success', + workflow_name: graph.name, + component_id: node.componentId, + duration_ms, + }); + } + // 處理出邊 const outEdges = graph.edges.filter(e => e.from === node.id); diff --git a/cypher-executor/src/lib/telemetry.ts b/cypher-executor/src/lib/telemetry.ts index 13b7e64..9471875 100644 --- a/cypher-executor/src/lib/telemetry.ts +++ b/cypher-executor/src/lib/telemetry.ts @@ -21,7 +21,9 @@ export type TelemetryEvent = | 'run_success' | 'run_fail' | 'validation_error' - | 'mcp_tool_call'; + | 'mcp_tool_call' + | 'node_success' // 單一 node 跑完(給 step-level 效能分析用) + | 'node_failure'; // 單一 node 失敗 export interface TelemetryRecord { event_type: TelemetryEvent;