Skip to content

Commit 5adaa86

Browse files
committed
fix(traces): remove child trace spans from workflow block after being merged with parent output (#2688)
1 parent 37780df commit 5adaa86

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,80 @@ describe('buildTraceSpans', () => {
769769
expect(functionSpan?.status).toBe('error')
770770
expect((functionSpan?.output as { error?: string })?.error).toContain('Syntax Error')
771771
})
772+
773+
test('should remove childTraceSpans from output after integrating them as children', () => {
774+
const mockExecutionResult: ExecutionResult = {
775+
success: true,
776+
output: { result: 'parent output' },
777+
logs: [
778+
{
779+
blockId: 'workflow-1',
780+
blockName: 'Parent Workflow',
781+
blockType: 'workflow',
782+
startedAt: '2024-01-01T10:00:00.000Z',
783+
endedAt: '2024-01-01T10:00:05.000Z',
784+
durationMs: 5000,
785+
success: true,
786+
output: {
787+
success: true,
788+
childWorkflowName: 'Child Workflow',
789+
result: { data: 'some result' },
790+
childTraceSpans: [
791+
{
792+
id: 'child-block-1',
793+
name: 'Supabase Query',
794+
type: 'supabase',
795+
blockId: 'supabase-1',
796+
duration: 2000,
797+
startTime: '2024-01-01T10:00:01.000Z',
798+
endTime: '2024-01-01T10:00:03.000Z',
799+
status: 'success' as const,
800+
output: {
801+
records: [
802+
{ id: 1, logo: 'data:image/png;base64,VeryLargeBase64StringHere...' },
803+
{ id: 2, logo: 'data:image/png;base64,AnotherLargeBase64StringHere...' },
804+
],
805+
},
806+
},
807+
{
808+
id: 'child-block-2',
809+
name: 'Transform Data',
810+
type: 'function',
811+
blockId: 'function-1',
812+
duration: 500,
813+
startTime: '2024-01-01T10:00:03.000Z',
814+
endTime: '2024-01-01T10:00:03.500Z',
815+
status: 'success' as const,
816+
output: { transformed: true },
817+
},
818+
],
819+
},
820+
},
821+
],
822+
}
823+
824+
const { traceSpans } = buildTraceSpans(mockExecutionResult)
825+
826+
expect(traceSpans).toHaveLength(1)
827+
const workflowSpan = traceSpans[0]
828+
expect(workflowSpan.type).toBe('workflow')
829+
830+
expect(workflowSpan.children).toBeDefined()
831+
expect(workflowSpan.children).toHaveLength(2)
832+
expect(workflowSpan.children?.[0].name).toBe('Supabase Query')
833+
expect(workflowSpan.children?.[1].name).toBe('Transform Data')
834+
835+
expect(workflowSpan.output).toBeDefined()
836+
expect((workflowSpan.output as { childTraceSpans?: unknown }).childTraceSpans).toBeUndefined()
837+
838+
expect((workflowSpan.output as { success?: boolean }).success).toBe(true)
839+
expect((workflowSpan.output as { childWorkflowName?: string }).childWorkflowName).toBe(
840+
'Child Workflow'
841+
)
842+
expect((workflowSpan.output as { result?: { data: string } }).result).toEqual({
843+
data: 'some result',
844+
})
845+
})
772846
})
773847

774848
describe('stripCustomToolPrefix', () => {

apps/sim/lib/logs/execution/trace-spans/trace-spans.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ export function buildTraceSpans(result: ExecutionResult): {
326326
const childTraceSpans = log.output.childTraceSpans as TraceSpan[]
327327
const flattenedChildren = flattenWorkflowChildren(childTraceSpans)
328328
span.children = mergeTraceSpanChildren(span.children || [], flattenedChildren)
329+
330+
const { childTraceSpans: _, ...cleanOutput } = span.output as {
331+
childTraceSpans?: TraceSpan[]
332+
} & Record<string, unknown>
333+
span.output = cleanOutput
329334
}
330335

331336
spanMap.set(spanId, span)

0 commit comments

Comments
 (0)