improvement(block-error-logs): workflow in workflow (#1084)

* improvement(add-block-logs): workflow in workflow

* fix lint
This commit is contained in:
Vikhyath Mondreti
2025-08-21 15:01:30 -07:00
committed by GitHub
parent 7e364a7977
commit 0f2a125eae
4 changed files with 68 additions and 4 deletions

View File

@@ -1742,6 +1742,11 @@ export class Executor {
blockLog.durationMs =
new Date(blockLog.endedAt).getTime() - new Date(blockLog.startedAt).getTime()
// If this error came from a child workflow execution, persist its trace spans on the log
if (block.metadata?.id === BlockType.WORKFLOW) {
this.attachChildWorkflowSpansToLog(blockLog, error)
}
// Log the error even if we'll continue execution through error path
context.blockLogs.push(blockLog)
@@ -1820,6 +1825,11 @@ export class Executor {
status: error.status || 500,
}
// Preserve child workflow spans on the block state so downstream logging can render them
if (block.metadata?.id === BlockType.WORKFLOW) {
this.attachChildWorkflowSpansToOutput(errorOutput, error)
}
// Set block state with error output
context.blockStates.set(blockId, {
output: errorOutput,
@@ -1864,6 +1874,39 @@ export class Executor {
}
}
/**
* Copies child workflow trace spans from an error object into a block log.
* Ensures consistent structure and avoids duplication of inline guards.
*/
private attachChildWorkflowSpansToLog(blockLog: BlockLog, error: unknown): void {
const spans = (
error as { childTraceSpans?: TraceSpan[]; childWorkflowName?: string } | null | undefined
)?.childTraceSpans
if (Array.isArray(spans) && spans.length > 0) {
blockLog.output = {
...(blockLog.output || {}),
childTraceSpans: spans,
childWorkflowName: (error as { childWorkflowName?: string } | null | undefined)
?.childWorkflowName,
}
}
}
/**
* Copies child workflow trace spans from an error object into a normalized output.
*/
private attachChildWorkflowSpansToOutput(output: NormalizedBlockOutput, error: unknown): void {
const spans = (
error as { childTraceSpans?: TraceSpan[]; childWorkflowName?: string } | null | undefined
)?.childTraceSpans
if (Array.isArray(spans) && spans.length > 0) {
output.childTraceSpans = spans
output.childWorkflowName = (
error as { childWorkflowName?: string } | null | undefined
)?.childWorkflowName
}
}
/**
* Activates error paths from a block that had an error.
* Checks for connections from the block's "error" handle and adds them to the active execution path.