Trace Viewer Module πΒΆ
A beautiful, interactive OpenTelemetry trace visualization module for the Flock dashboard. View agent execution traces with waterfall timelines, search capabilities, and detailed span inspection.
FeaturesΒΆ
π¨ Beautiful Waterfall VisualizationΒΆ
- Interactive timeline view showing span execution order and duration
- Color-coded spans by type (Agent, Engine, Component)
- Hierarchical display with expandable span details
- Duration indicators showing execution time in milliseconds
π Smart Filtering & SearchΒΆ
- Real-time search across trace IDs, span names, and agent names
- Automatic grouping by trace ID
- Error highlighting for failed traces
- Trace statistics (span count, total duration, status)
π Rich Span DetailsΒΆ
- Expandable spans showing all OTEL attributes
- Agent metadata (name, description)
- Correlation tracking via correlation_id
- Task tracking via task_id
- Status indicators (OK, ERROR)
β‘ Live UpdatesΒΆ
- Auto-refresh every 5 seconds
- Real-time trace loading from
.flock/traces.jsonl
- No configuration needed - just enable auto-tracing
Quick StartΒΆ
1. Enable Auto-TracingΒΆ
2. Start DashboardΒΆ
3. Access Trace ViewerΒΆ
- Open dashboard at
http://localhost:8344
- Right-click on canvas β Add Module β π Trace Viewer
- Traces will appear automatically!
ArchitectureΒΆ
Components CreatedΒΆ
src/flock/
βββ frontend/src/components/modules/
β βββ TraceModule.tsx # Main trace viewer component
β βββ TraceModuleWrapper.tsx # Module context wrapper
β βββ registerModules.ts # Updated with trace module registration
βββ dashboard/
βββ service.py # Added /api/traces endpoint
docs/guides/tracing/
βββ auto-tracing.md # Auto-tracing guide
βββ trace-module.md # This file!
Data FlowΒΆ
1. Auto-Tracing generates spans β .flock/traces.jsonl
2. Backend /api/traces reads file β Returns JSON array
3. Frontend polls every 5s β Groups spans by trace_id
4. React renders waterfall β Interactive visualization
API EndpointΒΆ
GET /api/traces
Returns array of OTEL span objects:
[
{
"name": "Agent.execute",
"context": {
"trace_id": "ae40f0061e3f1bcfebe169191d138078",
"span_id": "739aa78e2ff5267d",
"trace_flags": 1,
"trace_state": "[]"
},
"start_time": 1759843976996907490,
"end_time": 1759843977012345678,
"status": {
"status_code": "OK"
},
"attributes": {
"class": "Agent",
"function": "execute",
"module": "flock.agent",
"agent.name": "movie",
"agent.description": "Generate movie ideas",
"correlation_id": "12d0fcda-e7f7-4c96-ae8e-14ae4eca1518",
"task_id": "task_abc123",
"result.type": "EvalResult",
"result.length": 1
},
"kind": "INTERNAL",
"resource": {
"service.name": "flock-auto-trace"
}
}
]
UI WalkthroughΒΆ
Trace List ViewΒΆ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π Search: [trace ID, span name, agent...] 3 tracesβ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βΆ ae40f006... 15.23ms β
β 2025-10-07 15:32:40 β’ 29 spans β
β β
β βΌ d14a167a... 12.41ms β οΈ Errorβ
β 2025-10-07 15:33:05 β’ 15 spans β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β Waterfall View ββ
β β ββ
β β βΆ Agent.execute (movie) ββββββββββββ 4.25ms ββ
β β βΆ DSPyEngine.evaluate ββββ 1.15ms ββ
β β βΌ Component.on_init β 0.05ms ββ
β β Span ID: 739aa78e... ββ
β β Status: OK ββ
β β agent.name: movie ββ
β β correlation_id: 12d0fcda-e7f7... ββ
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Color CodingΒΆ
Span Type | Color | Example |
---|---|---|
Agent.execute | Primary Blue | Main agent execution |
Engine | Green | DSPyEngine.evaluate |
Component | Orange | OutputComponent.on_init |
Other | Info Blue | Generic methods |
Error | Red | Any span with status ERROR |
Usage ExamplesΒΆ
Example 1: Debug Slow AgentΒΆ
# Enable tracing
export FLOCK_AUTO_TRACE=true FLOCK_TRACE_FILE=true
# Run your agent
python my_slow_agent.py
In Trace Viewer: 1. Find trace with long duration 2. Expand trace β see waterfall 3. Identify bottleneck spans 4. Click span β view attributes 5. Find which component is slow
Example 2: Track Correlation FlowΒΆ
In Trace Viewer: 1. Search for correlation ID: 12d0fcda
2. See all related traces 3. Track data flow across agents 4. Verify execution order
Example 3: Error InvestigationΒΆ
In Trace Viewer: 1. Look for β οΈ Error indicators 2. Click trace β expand waterfall 3. Find ERROR status span (red) 4. Expand β see error details 5. Check attributes for context
Advanced FeaturesΒΆ
Span Attributes CapturedΒΆ
Every span automatically includes:
Attribute | Description | Example |
---|---|---|
class | Class name | Agent , Flock , DSPyEngine |
function | Method name | execute , evaluate |
module | Python module | flock.agent |
agent.name | Agent identifier | movie , tagline |
agent.description | Agent description | Generate movies |
correlation_id | Request tracking | 12d0fcda-... |
task_id | Task identifier | task_abc123 |
result.type | Return type | EvalResult , list |
result.length | Collection size | 3 |
PerformanceΒΆ
- Lightweight: No external dependencies
- Fast rendering: React memoization
- Efficient polling: 5s refresh interval
- Lazy loading: Only visible traces render
- Minimal overhead: <0.1ms per span display
Browser CompatibilityΒΆ
- β Chrome/Edge (latest)
- β Firefox (latest)
- β Safari (latest)
- β οΈ IE11 (not supported)
TroubleshootingΒΆ
"No traces found"ΒΆ
Cause: Trace file doesn't exist
Fix:
# Make sure both are set
export FLOCK_AUTO_TRACE=true
export FLOCK_TRACE_FILE=true
# Run your agent
python your_agent.py
# Verify file exists
ls -la .flock/traces.jsonl
"Failed to load traces"ΒΆ
Cause: Backend can't read trace file
Fix:
# Check file permissions
chmod 644 .flock/traces.jsonl
# Check backend logs
# Look for "Trace file not found" warnings
"Spans not showing up"ΒΆ
Cause: Auto-tracing not enabled
Fix:
# Check imports - auto-tracing initializes on import
from flock.agent import Agent # Should see DEBUG logs
# Verify in logs
# Look for: "Agent.execute executed successfully"
Module not appearingΒΆ
Cause: Frontend not rebuilt
Fix:
Future EnhancementsΒΆ
Possible future improvements:
- Flame graphs for performance profiling
- Trace comparison side-by-side view
- Export to Jaeger direct integration
- Custom span filtering by attributes
- Time range selection with date picker
- Span search within specific trace
- Performance metrics (P50, P95, P99)
- Trace aggregation statistics view
- Live streaming via WebSocket
- Span annotations add notes
DevelopmentΒΆ
Adding New FeaturesΒΆ
// frontend/src/components/modules/TraceModule.tsx
// 1. Add state
const [myFeature, setMyFeature] = useState(false);
// 2. Add UI
<button onClick={() => setMyFeature(!myFeature)}>
Toggle Feature
</button>
// 3. Use in rendering
{myFeature && <div>Feature content</div>}
TestingΒΆ
# Frontend tests
cd src/flock/frontend
npm test
# Backend tests
uv run pytest tests/
# E2E test
export FLOCK_AUTO_TRACE=true FLOCK_TRACE_FILE=true
python examples/showcase/02_hello_flock.py
# Then open dashboard and verify traces appear
Module RegistrationΒΆ
// src/flock/frontend/src/components/modules/registerModules.ts
moduleRegistry.register({
id: 'traceViewer',
name: 'Trace Viewer',
description: 'OpenTelemetry traces with waterfall visualization',
icon: 'π',
component: TraceModuleWrapper,
});
Related DocumentationΒΆ
- Auto-Tracing Guide - Complete auto-tracing guide
- Tracing Overview - Tracing system overview
- Dashboard Guide - Dashboard usage guide
- Production Tracing - Production best practices
CreditsΒΆ
Built with β€οΈ using: - React 19 - UI framework - TypeScript - Type safety - OpenTelemetry - Distributed tracing - Flock Dashboard - Module system
Enjoy visualizing your traces! π
For questions or issues, see the Tracing Overview or create an issue on GitHub.