(result: ExecutionResult)
| 57 | * relative timestamps + total duration derived from the earliest start / latest end. |
| 58 | */ |
| 59 | export function buildTraceSpans(result: ExecutionResult): { |
| 60 | traceSpans: TraceSpan[] |
| 61 | totalDuration: number |
| 62 | } { |
| 63 | if (!result.logs?.length) { |
| 64 | return { traceSpans: [], totalDuration: 0 } |
| 65 | } |
| 66 | |
| 67 | const spans = buildRootSpansFromLogs(result.logs) |
| 68 | const grouped = groupIterationBlocks(spans) |
| 69 | |
| 70 | if (grouped.length === 0 || !result.metadata) { |
| 71 | const totalDuration = grouped.reduce((sum, span) => sum + span.duration, 0) |
| 72 | return { traceSpans: grouped, totalDuration } |
| 73 | } |
| 74 | |
| 75 | return wrapInWorkflowRoot(grouped, spans) |
| 76 | } |
| 77 | |
| 78 | /** Converts each BlockLog into a TraceSpan, sorted chronologically by start time. */ |
| 79 | function buildRootSpansFromLogs(logs: BlockLog[]): TraceSpan[] { |
no test coverage detected