-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(nested-workflow-spans): nested child workflow spans in logs sidepanel #1561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
This PR introduces comprehensive support for collecting and rendering nested child workflow spans in the logs sidepanel, addressing a significant debugging limitation where only top-level workflow spans were previously visible. The changes span across multiple execution paths (chat, scheduled workflows, webhooks, direct API calls) to ensure consistent trace span collection regardless of how workflows are triggered.The implementation adds a new WorkflowTraceSpan type that extends the base TraceSpan with metadata for distinguishing child workflow spans. Key improvements include enhanced error handling that preserves execution results and trace spans even when child workflows fail, ensuring debugging information isn't lost during failures. The code introduces utility functions for normalizing error messages and extracting execution results from complex error structures that may contain nested workflow information.
A new WORKFLOW_INPUT block type is introduced alongside the deprecated WORKFLOW type, with a helper function isWorkflowBlockType() providing backwards compatibility during the transition. The chat execution workflow has been significantly simplified, removing complex output processing logic in favor of streamlined trace span collection.
The changes ensure that buildTraceSpans() is called consistently across all execution paths and that trace spans are properly passed to logging sessions in both success and error scenarios. This creates a unified debugging experience where developers can see the complete execution tree for nested workflows, making it much easier to diagnose issues in complex workflow architectures.
Important Files Changed
Changed Files
| Filename | Score | Overview |
|---|---|---|
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution.ts | 4/5 | Added robust error handling utilities and normalization functions to extract execution results from nested workflow errors |
| apps/sim/background/webhook-execution.ts | 4/5 | Added trace span collection to error handling path for consistent debugging across webhook executions |
| apps/sim/executor/handlers/workflow/workflow-handler.ts | 4/5 | Implemented core nested child workflow span processing with new WorkflowTraceSpan type and span processing methods |
| apps/sim/app/api/schedules/execute/route.ts | 4/5 | Added trace span collection and logging for scheduled workflow executions |
| apps/sim/app/api/workflows/[id]/execute/route.ts | 4/5 | Enhanced error handling to extract and preserve trace spans from failed workflow executions |
| apps/sim/executor/index.ts | 4/5 | Replaced hardcoded workflow block checks with helper function and enhanced error propagation with execution results |
| apps/sim/app/api/workflows/[id]/log/route.ts | 4/5 | Moved buildTraceSpans() call to ensure trace spans available for both success and error scenarios |
| apps/sim/app/api/chat/utils.ts | 4/5 | Dramatically simplified chat execution workflow removing complex output processing in favor of trace span collection |
| apps/sim/executor/consts.ts | 4/5 | Added new WORKFLOW_INPUT block type with backwards compatibility helper function |
| apps/sim/background/workflow-execution.ts | 4/5 | Enhanced background execution error handling to capture and persist child workflow trace spans |
Confidence score: 4/5
- This PR is safe to merge with good implementation quality and comprehensive coverage across execution paths
- Score reflects well-structured changes that maintain backwards compatibility while adding significant debugging capabilities
- Pay attention to the unused
flattenChildWorkflowSpansmethod in workflow-handler.ts that could be removed to reduce complexity
Sequence Diagram
sequenceDiagram
participant User
participant ExecutorAPI as Executor API
participant Executor
participant WorkflowHandler as Workflow Handler
participant LoggingSession as Logging Session
participant TraceSpans as Trace Spans Builder
participant UI as Logs UI
User->>ExecutorAPI: "Execute workflow"
ExecutorAPI->>Executor: "Create executor instance"
Executor->>LoggingSession: "Start logging session"
LoggingSession->>LoggingSession: "Initialize session"
Executor->>Executor: "Execute workflow blocks"
alt Workflow block encountered
Executor->>WorkflowHandler: "Execute child workflow"
WorkflowHandler->>WorkflowHandler: "Load child workflow"
WorkflowHandler->>Executor: "Create sub-executor"
Executor->>Executor: "Execute child workflow"
Executor-->>WorkflowHandler: "Return child execution result"
WorkflowHandler->>WorkflowHandler: "Capture child trace spans"
WorkflowHandler-->>Executor: "Return with childTraceSpans"
end
Executor->>TraceSpans: "Build trace spans from execution result"
TraceSpans->>TraceSpans: "Process nested child workflow spans"
TraceSpans->>TraceSpans: "Flatten synthetic wrapper spans"
TraceSpans->>TraceSpans: "Merge child trace spans with parent"
TraceSpans-->>Executor: "Return processed trace spans"
Executor->>LoggingSession: "Complete session with trace spans"
LoggingSession->>LoggingSession: "Persist execution logs"
Executor-->>ExecutorAPI: "Return execution result"
ExecutorAPI-->>User: "Return workflow execution result"
User->>UI: "View execution logs"
UI->>UI: "Normalize child workflow spans"
UI->>UI: "Render nested spans hierarchy"
UI-->>User: "Display nested workflow execution tree"
Additional Comments (1)
-
apps/sim/app/api/schedules/execute/route.ts, line 425 (link)style: Type assertion to
anybypasses TypeScript safety. Consider defining proper types for trace spans.Context Used: Context from
dashboard- Avoid using type assertions to 'any' in TypeScript. Instead, ensure proper type definitions are used... (source)
10 files reviewed, 3 comments
…er instead of workflow owner
Summary
Type of Change
Testing
Tested manually with @aadamgough
Checklist