Skip to content

How to Use Tracing Effectively in FlockΒΆ

The ultimate guide to debugging, optimizing, and monitoring blackboard multi-agent systems

Table of ContentsΒΆ


Introduction: Why Tracing Matters for Blackboard SystemsΒΆ

The Blackboard ProblemΒΆ

Unlike graph-based frameworks (LangGraph, CrewAI, AutoGen), where agent interactions follow predefined edges, blackboard systems have emergent behavior. Agents communicate through shared data artifacts, making it nearly impossible to predict:

  • Why did Agent B execute after Agent A?
  • What chain of events led to this error?
  • Which agent is the bottleneck?
  • How do agents actually interact in production?

Traditional logging fails here because: - ❌ No parent-child relationships between agent calls - ❌ Async execution makes logs non-sequential - ❌ No visibility into cross-agent data flow - ❌ Can't see which artifact triggered which agent

What Tracing SolvesΒΆ

Flock's OpenTelemetry-based tracing provides:

βœ… Parent-child span relationships - See the complete execution tree βœ… Correlation IDs - Track a single request across all agents βœ… Timing data - Identify bottlenecks with microsecond precision βœ… Input/Output capture - See what data agents consumed and produced βœ… Service dependencies - Discover emergent agent interactions βœ… RED Metrics - Rate, Errors, Duration for production monitoring

The key insight: Blackboard systems require discovery tools, not just debugging tools. You need to understand what actually happened, not just verify what you thought would happen.


Getting Started: Your First TraceΒΆ

1. Enable TracingΒΆ

Add to your .env file:

# Enable auto-tracing
FLOCK_AUTO_TRACE=true
FLOCK_TRACE_FILE=true

# Filter what gets traced (avoid streaming token overhead)
FLOCK_TRACE_SERVICES=["flock", "agent", "dspyengine", "outpututilitycomponent"]

# Exclude noisy operations
FLOCK_TRACE_IGNORE=["DashboardEventCollector.set_websocket_manager"]

# Auto-cleanup old traces
FLOCK_TRACE_TTL_DAYS=30

2. Run Your AgentΒΆ

python examples/showcase/01_declarative_pizza.py

3. Open the Trace ViewerΒΆ

Navigate to the dashboard and select Trace Viewer module. You'll see all traces stored in .flock/traces.duckdb.

4. Your First InvestigationΒΆ

Click on a trace to expand it. You'll see:

Flock.publish          [0.00ms - 0.50ms]   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  Agent.execute        [0.50ms - 5,200ms]  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    DSPyEngine.evaluate [0.60ms - 5,100ms] ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    OutputUtility...    [5,100ms - 5,150ms] ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Immediate insights: - Total trace duration: 5.2 seconds - 98% of time spent in DSPyEngine.evaluate (LLM call) - OutputUtility took only 50ms


The Six Views: Complete ObservabilityΒΆ

The Trace Viewer provides 6 specialized view modes for different analysis needs:

Quick ReferenceΒΆ

View Icon Purpose When to Use
Timeline πŸ“… Waterfall execution flow Debug sequence and timing
Statistics πŸ“Š Sortable tabular data Compare traces, find patterns
RED Metrics πŸ”΄ Service health monitoring Production dashboards
Dependencies πŸ”— Service communication Understand architecture
Configuration βš™οΈ Runtime filtering Fine-tune tracing
Guide πŸ“š Documentation & examples Learn and reference

Feature HighlightsΒΆ

NEW in this version: - ✨ Smart Sorting: Sort traces by date (newest first), span count, or total duration - πŸ–₯️ Maximize Mode: Full-screen view for all modules - 🎨 Modern UI: Emoji-enhanced toolbar for better visual scanning


View Modes ExplainedΒΆ

Timeline View: The WaterfallΒΆ

Use case: "Why is this agent slow?"

The timeline view shows: - Execution order (top to bottom) - Duration (bar width) - Parent-child relationships (indentation) - Errors (red borders)

Example: Finding the Bottleneck

Pizza Order Processing (6,500ms total)
β”œβ”€ Flock.publish (0.5ms) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
β”‚  └─ Agent.execute (6,499ms) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
β”‚     β”œβ”€ DSPyEngine.evaluate (6,200ms) ━━━━━━━━━━━━━━━━━━━━ <- 95% of time!
β”‚     β”‚  └─ LLM Call (6,198ms)
β”‚     └─ OutputUtilityComponent.on_post_evaluate (50ms) ━━━━
└─ Flock.publish (0.1ms)

Finding: The LLM call dominates execution time. Solutions: 1. Cache results for repeated queries 2. Use a smaller model for simple tasks 3. Implement streaming for better UX

Click on any span to see: - Full attributes (correlation_id, task_id, agent.name) - Input parameters (JSON formatted) - Output values - Error details (if failed)

Statistics View: JSON ExplorerΒΆ

Use case: "What data did the agent receive?"

Shows tabular data with JSON viewer for each span:

Span ID Service Operation Duration Status Attributes
abc123 Agent execute 6,499ms OK πŸ“„ View JSON

Click "View JSON" to see:

{
  "input": {
    "ctx": {
      "correlation_id": "550e8400-e29b-41d4-a716-446655440000",
      "task_id": "pizza_order_001"
    },
    "artifacts": [
      {
        "name": "customer_order",
        "content": {
          "pizza": "Margherita",
          "size": "Large",
          "toppings": ["extra cheese", "basil"]
        }
      }
    ]
  },
  "output": {
    "value": {
      "status": "processed",
      "estimated_time": "25 minutes"
    }
  }
}

Why this matters: You can see exactly what the agent saw, not what you think it saw.

RED Metrics View: Production MonitoringΒΆ

Use case: "Which agent is failing in production?"

RED Metrics = **R**ate + **E**rrors + **D**uration

Each service shows: - Rate: Requests per second - Error Rate: Percentage of failures - Avg Duration: Mean response time - P95 Duration: 95th percentile latency - P99 Duration: 99th percentile latency (worst-case) - Total Spans: Call volume

Example Output:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Agent                                                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Rate:          2.5 req/s                                    β”‚
β”‚ Error Rate:    0.0%          βœ“ Healthy                     β”‚
β”‚ Avg Duration:  6,499ms                                      β”‚
β”‚ P95 Duration:  8,200ms                                      β”‚
β”‚ P99 Duration:  12,500ms      ⚠ High variance              β”‚
β”‚ Total Spans:   1,234                                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ DSPyEngine                                                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Rate:          2.5 req/s                                    β”‚
β”‚ Error Rate:    5.2%          βœ— Action needed               β”‚
β”‚ Avg Duration:  6,200ms                                      β”‚
β”‚ P95 Duration:  7,800ms                                      β”‚
β”‚ P99 Duration:  15,000ms      ⚠ Timeout risk                β”‚
β”‚ Total Spans:   1,234                                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Insights: - DSPyEngine has 5.2% error rate β†’ Investigate LLM failures - P99 of 15s suggests timeout risk β†’ Add retry logic - Both have high rate β†’ Consider rate limiting

Why P99 matters: P95 tells you "most users are fine", P99 tells you "some users are having a terrible experience". In multi-agent systems, P99 latencies compound across agents.

Dependencies View: Emergent InteractionsΒΆ

Use case: "How do my agents actually communicate?"

⚠ This is where Flock shines - most frameworks don't provide this for blackboard systems.

Shows service-to-service dependencies with operation-level drill-down:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Flock β†’ Agent                          3 operations         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    Click to expand:

    Flock.publish β†’ Agent.execute
    β”œβ”€ Calls: 1,234
    β”œβ”€ Errors: 0.0%
    β”œβ”€ Avg: 6,499ms
    └─ P95: 8,200ms

    Flock.publish β†’ Agent.validate_input
    β”œβ”€ Calls: 123
    β”œβ”€ Errors: 2.4%
    β”œβ”€ Avg: 50ms
    └─ P95: 120ms

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Agent β†’ DSPyEngine                     2 operations         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    Agent.execute β†’ DSPyEngine.evaluate
    β”œβ”€ Calls: 1,234
    β”œβ”€ Errors: 5.2%
    β”œβ”€ Avg: 6,200ms
    └─ P95: 7,800ms

    Agent.refine_output β†’ DSPyEngine.evaluate
    β”œβ”€ Calls: 45
    β”œβ”€ Errors: 0.0%
    β”œβ”€ Avg: 2,100ms
    └─ P95: 2,500ms

Discoveries you can make:

  1. Unexpected Dependencies
  2. "Why is Agent calling DSPyEngine twice?"
  3. Click drill-down: See Agent.refine_output is retrying with better prompts
  4. Decision: Cache the first result or merge into single call

  5. Error Hotspots

  6. Agent.validate_input has 2.4% error rate
  7. Drill down to see which inputs fail
  8. Fix validation logic

  9. Performance Bottlenecks

  10. Agent.execute β†’ DSPyEngine.evaluate has P95 of 7.8s
  11. Most calls are fast, but some timeout
  12. Solution: Implement circuit breaker

Configuration View: Tracing SettingsΒΆ

Use case: "Configure tracing without editing .env files"

⚠ NEW IN v0.5.0 - All tracing configuration is now accessible directly in the Trace Viewer!

The Configuration view provides a visual interface for all tracing settings:

Core Tracing Toggles: - βœ… Enable auto-tracing (FLOCK_AUTO_TRACE) - βœ… Store in DuckDB (FLOCK_TRACE_FILE) - βœ… Unified workflow tracing (FLOCK_AUTO_WORKFLOW_TRACE) - βœ… Trace TTL (FLOCK_TRACE_TTL_DAYS)

Service Whitelist (FLOCK_TRACE_SERVICES): - Multi-select with autocomplete - Populated from actual traced services in database - Only trace specific services (improves performance) - Example: ["flock", "agent", "dspyengine"]

Operation Blacklist (FLOCK_TRACE_IGNORE): - Multi-select with autocomplete - Exclude noisy operations (e.g., health checks) - Format: Service.method - Example: ["DashboardEventCollector.set_websocket_manager"]

Database Statistics:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Trace Database Statistics              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Total Spans:      12,456               β”‚
β”‚ Total Traces:     3,421                β”‚
β”‚ Services Traced:  8                    β”‚
β”‚ Database Size:    24.5 MB              β”‚
β”‚ Oldest Trace:     Oct 1, 09:15 AM     β”‚
β”‚ Newest Trace:     Oct 7, 21:20 PM     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Clear Traces: - One-click database clearing - Confirmation dialog prevents accidents - Runs VACUUM to reclaim disk space - Shows deleted span count

Why Configuration lives in Trace Viewer: - βœ… Settings stay with the data viewer (logical grouping) - βœ… See immediate impact of filter changes on statistics - βœ… Access during debugging workflow (no context switch) - βœ… Separate from UI preferences (Settings panel = appearance/graph only)

Example Workflow: 1. Open Trace Viewer β†’ Configuration tab 2. Check database statistics β†’ 50,000 spans, 2.5 GB 3. Enable service whitelist β†’ Select only ["agent", "dspyengine"] 4. Clear old traces β†’ Confirmation β†’ 45,000 spans deleted 5. Return to Timeline view β†’ Much faster with filtered data!


Real-World Debugging ScenariosΒΆ

Scenario 1: "Agent Executed But Shouldn't Have"ΒΆ

Problem: Agent processing irrelevant artifacts.

Investigation: 1. Go to Timeline View 2. Find the unexpected Agent.execute span 3. Click to expand β†’ View attributes 4. Check input.artifacts in JSON

Example Finding:

{
  "input": {
    "artifacts": [
      {
        "name": "customer_order",
        "visibility": "public",
        "status": "draft"  // ← Agent should ignore drafts!
      }
    ]
  }
}

Root Cause: Agent subscription didn't filter by status.

Fix:

agent.subscribe(
    artifact_name="customer_order",
    filter=lambda artifact: artifact.status == "finalized"  # Add filter
)

Scenario 2: "Production is Slow, But Dev Was Fast"ΒΆ

Problem: 2x latency increase in production.

Investigation with RED Metrics:

  1. Go to RED Metrics View
  2. Compare P95/P99 between environments using local DuckDB analysis as a trusted operator:
-- Dev environment traces
SELECT
    service,
    AVG(duration_ms) as avg,
    PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY duration_ms) as p95
FROM spans
WHERE created_at > '2025-10-01' AND created_at < '2025-10-05'
GROUP BY service;

-- Production environment (different database)
-- Compare results

Example Finding:

Service Dev P95 Prod P95 Diff
Agent 3,200ms 3,400ms +6%
DSPyEngine 2,800ms 7,200ms +157%

Root Cause: Production LLM endpoint has higher latency.

Solutions: - Switch to dedicated LLM endpoint - Implement request coalescing - Add caching layer

Scenario 3: "Cascading Failures"ΒΆ

Problem: One agent error crashes entire system.

Investigation with Dependencies:

  1. Go to Dependencies View
  2. Find failing agent: DSPyEngine (5.2% error rate)
  3. Check which agents depend on it

Example Finding:

DSPyEngine (5.2% errors)
  ↓
Agent (depends on DSPyEngine)
  ↓
OutputUtilityComponent (depends on Agent)

Error cascade: 5.2% β†’ 5.2% β†’ 5.2%

Root Cause: No error handling, failures propagate.

Fix:

try:
    result = await dspy_engine.evaluate(prompt)
except LLMException as e:
    logger.error(f"LLM failed: {e}")
    return fallback_response()  # Graceful degradation

Verify Fix: - Check RED Metrics after deployment - Agent error rate should drop to 0% - System resilience improved

Scenario 4: "Memory Leak in Long-Running Agents"ΒΆ

Problem: Memory usage grows over time.

Investigation with Timeline:

  1. Filter traces by correlation_id (same session)
  2. Compare first vs last trace durations

Example Finding:

Session start:
Agent.execute: 3,200ms

After 100 iterations:
Agent.execute: 8,500ms  ← 2.6x slower!

Hypothesis: Agent accumulating data in memory.

Verification in Statistics View: - Click trace #1 β†’ Check output.value size: 2KB - Click trace #100 β†’ Check output.value size: 120KB

Root Cause: Agent appending to list without cleanup.

Fix:

class MyAgent:
    def __init__(self):
        self.history = []  # ← Problem: unbounded growth

    def execute(self, ctx, artifacts):
        self.history.append(result)  # ← Memory leak
        return result

# Solution: Use circular buffer
from collections import deque

class MyAgent:
    def __init__(self):
        self.history = deque(maxlen=100)  # Keep last 100 only

Scenario 5: "LLM Costs Exploding"ΒΆ

Problem: Monthly LLM bill increased 10x.

Investigation with RED Metrics + Statistics:

  1. RED Metrics View: Check DSPyEngine rate
  2. Before: 2.5 req/s
  3. Now: 25 req/s (10x increase!)

  4. Dependencies View: Find what's calling DSPyEngine

  5. Agent.execute β†’ DSPyEngine.evaluate: 95% of calls
  6. Agent.refine_output β†’ DSPyEngine.evaluate: New operation!

  7. Timeline View: Check a trace with refine_output

Finding: New feature added retry logic that calls LLM multiple times:

# Before
result = dspy_engine.evaluate(prompt)

# After (introduced bug)
for attempt in range(5):  # ← Calls LLM 5x on every request!
    result = dspy_engine.evaluate(prompt)
    if result.confidence > 0.9:
        break

Fix: Add result caching or reduce retry count.


Advanced TechniquesΒΆ

Technique 1: Using DuckDB for Custom AnalysisΒΆ

Access the traces locally as a trusted operator. The SQL examples in this guide run directly against the database file, outside the dashboard and HTTP API:

duckdb -readonly .flock/traces.duckdb

Example queries:

-- Find slowest operations
SELECT
    name,
    AVG(duration_ms) as avg_duration,
    MAX(duration_ms) as max_duration,
    COUNT(*) as call_count
FROM spans
WHERE created_at > NOW() - INTERVAL 24 HOURS
GROUP BY name
ORDER BY avg_duration DESC
LIMIT 10;

-- Find error patterns
SELECT
    name,
    status_code,
    COUNT(*) as error_count,
    json_extract(attributes, '$.error.message') as error_message
FROM spans
WHERE status_code = 'ERROR'
GROUP BY name, status_code, error_message
ORDER BY error_count DESC;

-- Find agents triggered by specific artifact
SELECT DISTINCT
    s1.name as trigger_agent,
    s2.name as executed_agent,
    COUNT(*) as times
FROM spans s1
JOIN spans s2 ON s1.trace_id = s2.trace_id
WHERE json_extract(s1.attributes, '$.artifact.name') = 'customer_order'
  AND s2.start_time > s1.end_time
GROUP BY s1.name, s2.name;

-- Correlation between input size and duration
SELECT
    name,
    CASE
        WHEN LENGTH(json_extract(attributes, '$.input')) < 1000 THEN 'small'
        WHEN LENGTH(json_extract(attributes, '$.input')) < 10000 THEN 'medium'
        ELSE 'large'
    END as input_size,
    AVG(duration_ms) as avg_duration
FROM spans
GROUP BY name, input_size
ORDER BY name, avg_duration;

Technique 2: Filtering for FocusΒΆ

Scenario: Too many traces, need to focus.

In Timeline View, use search: - Search by correlation_id: 550e8400-e29b-41d4-a716-446655440000 - Search by agent name: PizzaOrderAgent - Search by artifact: customer_order - Search by error: TimeoutError

Environment variable filtering:

# Development: Trace everything for debugging
FLOCK_TRACE_SERVICES=["flock", "agent", "dspyengine", "outpututilitycomponent"]

# Production: Only critical services
FLOCK_TRACE_SERVICES=["agent"]

# Debugging specific agent
FLOCK_TRACE_SERVICES=["pizzaorderagent", "dspyengine"]

Technique 3: Correlation ID TrackingΒΆ

Track a single request end-to-end:

# In your application
correlation_id = str(uuid.uuid4())

ctx = Context(correlation_id=correlation_id, task_id="order_001")
flock.publish(artifact, ctx)

Then in DuckDB:

SELECT
    name,
    start_time,
    end_time,
    duration_ms,
    status_code
FROM spans
WHERE json_extract(attributes, '$.correlation_id') = '550e8400-e29b-41d4-a716-446655440000'
ORDER BY start_time;

Result: See complete journey of one order through your system.

Technique 4: Comparative AnalysisΒΆ

Compare before/after optimization:

-- Before optimization (Oct 1-5)
WITH before AS (
    SELECT
        service,
        AVG(duration_ms) as avg_duration
    FROM spans
    WHERE created_at BETWEEN '2025-10-01' AND '2025-10-05'
    GROUP BY service
),
-- After optimization (Oct 6-10)
after AS (
    SELECT
        service,
        AVG(duration_ms) as avg_duration
    FROM spans
    WHERE created_at BETWEEN '2025-10-06' AND '2025-10-10'
    GROUP BY service
)
SELECT
    before.service,
    before.avg_duration as before_ms,
    after.avg_duration as after_ms,
    ((after.avg_duration - before.avg_duration) / before.avg_duration * 100) as improvement_pct
FROM before
JOIN after ON before.service = after.service
ORDER BY improvement_pct;

Technique 5: Focus Mode (Shift+Click)ΒΆ

In Timeline View: - Shift+Click any span to focus - All other spans fade to 40% opacity - Useful for complex traces with many agents

Use case: "I only care about DSPyEngine calls in this trace" - Shift+click on any DSPyEngine span - See only DSPyEngine operations clearly - Shift+click again to unfocus


Production Best PracticesΒΆ

1. Configure Sensible FiltersΒΆ

Don't trace everything in production:

# βœ… Good: Trace core services only
FLOCK_TRACE_SERVICES=["flock", "agent", "dspyengine"]

# ❌ Bad: Trace everything (performance impact)
# FLOCK_TRACE_SERVICES=[]  # Empty = trace all

# βœ… Good: Exclude high-frequency operations
FLOCK_TRACE_IGNORE=["DashboardEventCollector.set_websocket_manager", "MetricsUtility.increment_counter"]

# ❌ Bad: Trace streaming tokens (huge overhead)
# FLOCK_TRACE_IGNORE=[]

2. Set Appropriate TTLΒΆ

# Development: Keep 7 days for recent debugging
FLOCK_TRACE_TTL_DAYS=7

# Staging: Keep 14 days for integration testing
FLOCK_TRACE_TTL_DAYS=14

# Production: Keep 30 days for historical analysis
FLOCK_TRACE_TTL_DAYS=30

# Long-term audit: Keep 90 days
FLOCK_TRACE_TTL_DAYS=90

3. Monitor RED Metrics DailyΒΆ

Set SLOs (Service Level Objectives):

# Define acceptable thresholds
SLO_THRESHOLDS = {
    "Agent": {
        "error_rate": 1.0,    # Max 1% errors
        "p95_duration": 5000, # Max 5s at P95
        "p99_duration": 10000 # Max 10s at P99
    },
    "DSPyEngine": {
        "error_rate": 2.0,    # LLMs fail more often
        "p95_duration": 8344,
        "p99_duration": 15000
    }
}

Daily check (DuckDB):

-- Check if any service violates SLO
SELECT
    service,
    (SUM(CASE WHEN status_code = 'ERROR' THEN 1 ELSE 0 END)::FLOAT / COUNT(*) * 100) as error_rate,
    PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY duration_ms) as p95,
    PERCENTILE_CONT(0.99) WITHIN GROUP (ORDER BY duration_ms) as p99
FROM spans
WHERE created_at > NOW() - INTERVAL 24 HOURS
GROUP BY service;

Alert if thresholds exceeded (pseudo-code):

if error_rate > SLO_THRESHOLDS[service]["error_rate"]:
    send_alert(f"⚠ {service} error rate: {error_rate}% (SLO: {SLO_THRESHOLDS[service]['error_rate']}%)")

4. Use Correlation IDs ConsistentlyΒΆ

Always pass context:

# βœ… Good: Correlation ID propagates
ctx = Context(correlation_id=request.correlation_id)
flock.publish(artifact, ctx)

# ❌ Bad: Each publish creates new trace
flock.publish(artifact)  # No context = new correlation ID

5. Regular Database MaintenanceΒΆ

-- Check database size
SELECT
    COUNT(*) as total_spans,
    MIN(created_at) as oldest_trace,
    MAX(created_at) as newest_trace,
    pg_size_pretty(pg_total_relation_size('spans')) as db_size
FROM spans;

-- Vacuum to reclaim space (after TTL cleanup)
VACUUM ANALYZE spans;

6. Export Critical TracesΒΆ

Save important traces for postmortems:

-- Export trace to JSON
COPY (
    SELECT json_group_array(json_object(
        'name', name,
        'start_time', start_time,
        'duration_ms', duration_ms,
        'status_code', status_code,
        'attributes', attributes
    ))
    FROM spans
    WHERE trace_id = '550e8400-e29b-41d4-a716-446655440000'
    ORDER BY start_time
) TO 'incident_2025_10_07_trace.json';

Local Tracing and ExportΒΆ

Flock records traces two ways, and they read the same spans:

Local tracing Export over OTLP
Switched on by FLOCK_TRACE_FILE=true OTEL_EXPORTER_OTLP_ENDPOINT
Where .flock/traces.duckdb and the dashboard's trace viewer Any OpenTelemetry backend, for example Langfuse, Opik, Arize Phoenix, Jaeger or MLflow (backends)
Needs Nothing beyond Flock; works offline A running backend
Shows best Blackboard behaviour: which artifact triggered which agent, operation-level dependencies, RED metrics, SQL on the trace file Model calls (LM.chat), sessions or threads per run, and the backend's own features
Retention FLOCK_TRACE_TTL_DAYS The backend's

The trace level and the filters (FLOCK_TRACE_LEVEL, FLOCK_TRACE_SERVICES, FLOCK_TRACE_IGNORE) apply to both: a filtered operation creates no span at all.

What the Local Trace Viewer Is Built ForΒΆ

  1. Blackboard-native observability. Blackboard systems have emergent behaviour: agents subscribe to artifacts instead of following a predefined graph. The viewer shows which artifact triggered which agent, so you discover what happened rather than verify what you planned.

  2. Operation-level dependency drill-down. The Dependencies view shows the method calls between services, not only which services talk:

    Agent β†’ DSPyEngine (click to expand)
      β”œβ”€ Agent.execute β†’ DSPyEngine.evaluate (1,234 calls, 5.2% errors)
      └─ Agent.refine_output β†’ DSPyEngine.evaluate (45 calls, 0% errors)
    

  3. P95 and P99 latency. In multi-agent systems tail latencies compound:

    Agent1 (P99: 10s) β†’ Agent2 (P99: 10s) β†’ Agent3 (P99: 10s)
    Worst case: 30s for the user (vs 15s at P95)
    

  4. Retention in one setting. FLOCK_TRACE_TTL_DAYS deletes old traces automatically.

  5. Filtering in code. Filtered operations cost close to nothing, because no span is created:

    FLOCK_TRACE_SERVICES=["agent"]              # Whitelist
    FLOCK_TRACE_IGNORE=["Agent.health_check"]  # Blacklist
    

  6. SQL on the trace file. Trusted operators can query the DuckDB file directly for custom analysis.

Use both: local tracing while you develop and in the dashboard, and an export to the tool your team works with for model calls, sessions and evaluations.

What We Don't Have (Yet)ΒΆ

Planned work is tracked in the roadmap.


ConclusionΒΆ

Flock's tracing system is designed specifically for blackboard multi-agent systems, where behavior is emergent and unpredictable. Unlike graph-based frameworks where you verify what you planned, Flock helps you discover what actually happened.

Key takeaways:

  1. Start simple: Enable tracing with 3 env vars
  2. Use all four views: Timeline (debug), Statistics (inspect), RED Metrics (monitor), Dependencies (discover)
  3. Filter wisely: Trace core services, not everything
  4. Analyze locally with DuckDB: Trusted operators can write custom SQL for deep analysis
  5. Monitor production: Set SLOs and check RED metrics daily

What makes Flock unique: - Zero external dependencies - Operation-level drill-down - Blackboard-native observability - P99 latency tracking - Built-in TTL management - SQL-based analytics

Resources: - Auto-Tracing Guide - Technical reference - Tracing Quick Start - Getting started - Production Tracing - Production best practices

Happy debugging! 🎯


Last updated: 2025-10-07