|
| 1 | +# 🚀 Implement Hierarchical Workflow Tracing with Single Transaction Structure |
| 2 | + |
| 3 | +## 📋 Summary |
| 4 | + |
| 5 | +This PR transforms the GitHub Actions workflow tracing from individual job transactions to a single workflow transaction containing nested job and step spans, providing better visibility into workflow timing and structure. |
| 6 | + |
| 7 | +## 🎯 Problem Solved |
| 8 | + |
| 9 | +**Before**: Individual job transactions created a flat structure in Sentry, making it difficult to understand workflow timing and relationships. |
| 10 | + |
| 11 | +**After**: Single workflow transaction with proper hierarchical spans showing: |
| 12 | +- Workflow-level timing and status |
| 13 | +- Individual job spans as children |
| 14 | +- Step spans as children of their respective jobs |
| 15 | + |
| 16 | +## 🔧 Key Changes |
| 17 | + |
| 18 | +### Core Implementation |
| 19 | +- **`WorkflowTracer`**: New class for creating single workflow transactions with nested spans |
| 20 | +- **`WorkflowJobCollector`**: Collects jobs from workflow runs and sends workflow-level traces |
| 21 | +- **Enhanced `WebAppHandler`**: Integrates job collection and workflow tracing |
| 22 | + |
| 23 | +### Sentry Payload Fixes |
| 24 | +- ✅ Removed `event_id` from transaction payload (handled in envelope headers) |
| 25 | +- ✅ Fixed timestamp format (removed `+00:00` UTC offset) |
| 26 | +- ✅ Corrected status mapping for skipped jobs (`"ok"` instead of `"internal_error"`) |
| 27 | +- ✅ Added required `sdk` field with name and version |
| 28 | +- ✅ Added `trace_version` tags for validation |
| 29 | + |
| 30 | +### Architecture Improvements |
| 31 | +- ✅ Disabled individual job transactions to prevent duplicates |
| 32 | +- ✅ Disabled Flask automatic Sentry tracing to prevent interference |
| 33 | +- ✅ Added thread-safe job collection with race condition prevention |
| 34 | +- ✅ Implemented proper span hierarchy: `workflow -> jobs -> steps` |
| 35 | + |
| 36 | +## 📊 Trace Structure |
| 37 | + |
| 38 | +**New Structure**: |
| 39 | +``` |
| 40 | +workflow: Multi-Job Test (transaction) |
| 41 | +├─ security-scan (job span) |
| 42 | +│ ├─ Set up job (step span) |
| 43 | +│ ├─ Checkout code (step span) |
| 44 | +│ └─ Run security scan (step span) |
| 45 | +├─ performance-tests (job span) |
| 46 | +│ ├─ Set up job (step span) |
| 47 | +│ ├─ Setup performance test environment (step span) |
| 48 | +│ └─ Run performance tests (step span) |
| 49 | +└─ backend-tests (job span) |
| 50 | + ├─ Set up job (step span) |
| 51 | + ├─ Setup Python (step span) |
| 52 | + └─ Run backend unit tests (step span) |
| 53 | +``` |
| 54 | + |
| 55 | +## 🧪 Testing |
| 56 | + |
| 57 | +- ✅ Local testing with mock data |
| 58 | +- ✅ Real GitHub workflow testing |
| 59 | +- ✅ Sentry payload validation |
| 60 | +- ✅ Trace structure verification |
| 61 | +- ✅ Performance impact assessment |
| 62 | + |
| 63 | +## 📁 Files Changed |
| 64 | + |
| 65 | +- `src/workflow_tracer.py` - New WorkflowTracer implementation |
| 66 | +- `src/web_app_handler.py` - Enhanced with WorkflowJobCollector |
| 67 | +- `src/main.py` - Disabled Flask automatic Sentry tracing |
| 68 | +- `src/github_sdk.py` - Disabled individual job traces |
| 69 | +- `src/enhanced_web_app_handler.py` - Alternative handler implementation |
| 70 | +- `LOCAL_DEVELOPMENT.md` - Development setup guide |
| 71 | +- `TESTING_SUMMARY.md` - Testing documentation |
| 72 | + |
| 73 | +## 🔍 Validation |
| 74 | + |
| 75 | +The implementation includes `trace_version: v3.6` tags for easy validation that traces are coming from the updated code. |
| 76 | + |
| 77 | +## 🚀 Benefits |
| 78 | + |
| 79 | +1. **Better Visibility**: Single workflow transaction shows complete timing |
| 80 | +2. **Proper Hierarchy**: Clear parent-child relationships between workflow, jobs, and steps |
| 81 | +3. **Reduced Noise**: Eliminates duplicate individual job transactions |
| 82 | +4. **Improved Debugging**: Easier to identify workflow bottlenecks and issues |
| 83 | +5. **Sentry Compliance**: Proper payload structure that Sentry processes correctly |
| 84 | + |
| 85 | +## ⚠️ Breaking Changes |
| 86 | + |
| 87 | +- Individual job transactions are no longer sent |
| 88 | +- Trace structure is completely different (hierarchical vs flat) |
| 89 | +- Requires Sentry project configuration update for proper visualization |
| 90 | + |
| 91 | +## 🔄 Migration |
| 92 | + |
| 93 | +Existing traces will continue to work. New traces will use the hierarchical structure. The `trace_version` tag helps identify which version generated each trace. |
| 94 | + |
| 95 | + |
0 commit comments