[Phase 6.10] Observability (Metrics/Logs/Traces) #79

Closed
opened 2026-04-02 20:55:30 +00:00 by Mark · 2 comments
Owner

Overview

Metrics, logging, and tracing for mesh observability.

Problem Statement

Current mesh has limited observability:

  • No metrics (latency, throughput, error rates)
  • Basic logging (print statements)
  • No tracing across multi-hop intents
  • No alerting on failures
  • Can't debug issues in production

Proposed Solution

6.10.1: Metrics Collection

class MeshMetrics:
    """Collect and expose mesh metrics."""
    
    # Counters
    intents_received: Counter
    intents_completed: Counter
    intents_failed: Counter
    tokens_used: Counter
    
    # Histograms
    intent_latency: Histogram
    llm_latency: Histogram
    
    # Gauges
    active_workers: Gauge
    queue_depth: Gauge

6.10.2: Metrics Endpoints

endpoints:
  GET /metrics:
    format: Prometheus text format
    returns: Mesh metrics for scraping
    
  GET /v1/metrics/summary:
    returns: JSON metrics summary

6.10.3: Structured Logging

# config/logging.yaml
logging:
  format: json
  level: INFO
  output: stdout
  fields:
    - timestamp
    - level
    - logger
    - message
    - intent_id
    - trace_id
    - duration_ms

# Example log:
{
    "timestamp": "2026-04-02T10:30:00Z",
    "level": "INFO",
    "logger": "intent_router",
    "message": "Intent routed to capability",
    "intent_id": "abc123",
    "capability": "writer_v1",
    "duration_ms": 15
}

6.10.4: Distributed Tracing

class TraceContext:
    """Trace context for multi-hop intents."""
    
    trace_id: str  # Shared across all hops
    span_id: str  # Unique per hop
    parent_span_id: str  # Previous hop
    
def start_trace(intent_id: str) -> TraceContext:
    """Start new trace for intent"""
    
def child_span(parent: TraceContext) -> TraceContext:
    """Create child span for next hop"""

6.10.5: Metrics Dashboard

# Key metrics to expose:
mesh_intents_total{status="success|failure"}
mesh_intent_duration_seconds{intent_type}
mesh_llm_tokens_total{model, type="input|output"}
mesh_llm_cost_usd_total{model}
mesh_active_intents
mesh_queue_depth

# Optional: Grafana dashboard JSON

Deliverables

  • runtime/metrics.py - Metrics collection
  • Prometheus metrics endpoint (/metrics)
  • Structured JSON logging
  • Trace context for multi-hop
  • Log correlation via intent_id
  • Metrics summary endpoint
  • Unit tests

Dependencies

  • None (standalone)

Estimated Duration

1 week

Success Criteria

  • Metrics exposed in Prometheus format
  • Structured logs in JSON format
  • Intent IDs in all logs
  • Latency tracked per intent
  • Token/cost metrics available
  • Parent: #69 (Phase 6 Meta)
## Overview Metrics, logging, and tracing for mesh observability. ## Problem Statement Current mesh has limited observability: - No metrics (latency, throughput, error rates) - Basic logging (print statements) - No tracing across multi-hop intents - No alerting on failures - Can't debug issues in production ## Proposed Solution ### 6.10.1: Metrics Collection ```python class MeshMetrics: """Collect and expose mesh metrics.""" # Counters intents_received: Counter intents_completed: Counter intents_failed: Counter tokens_used: Counter # Histograms intent_latency: Histogram llm_latency: Histogram # Gauges active_workers: Gauge queue_depth: Gauge ``` ### 6.10.2: Metrics Endpoints ```yaml endpoints: GET /metrics: format: Prometheus text format returns: Mesh metrics for scraping GET /v1/metrics/summary: returns: JSON metrics summary ``` ### 6.10.3: Structured Logging ```python # config/logging.yaml logging: format: json level: INFO output: stdout fields: - timestamp - level - logger - message - intent_id - trace_id - duration_ms # Example log: { "timestamp": "2026-04-02T10:30:00Z", "level": "INFO", "logger": "intent_router", "message": "Intent routed to capability", "intent_id": "abc123", "capability": "writer_v1", "duration_ms": 15 } ``` ### 6.10.4: Distributed Tracing ```python class TraceContext: """Trace context for multi-hop intents.""" trace_id: str # Shared across all hops span_id: str # Unique per hop parent_span_id: str # Previous hop def start_trace(intent_id: str) -> TraceContext: """Start new trace for intent""" def child_span(parent: TraceContext) -> TraceContext: """Create child span for next hop""" ``` ### 6.10.5: Metrics Dashboard ```yaml # Key metrics to expose: mesh_intents_total{status="success|failure"} mesh_intent_duration_seconds{intent_type} mesh_llm_tokens_total{model, type="input|output"} mesh_llm_cost_usd_total{model} mesh_active_intents mesh_queue_depth # Optional: Grafana dashboard JSON ``` ## Deliverables - [ ] `runtime/metrics.py` - Metrics collection - [ ] Prometheus metrics endpoint (`/metrics`) - [ ] Structured JSON logging - [ ] Trace context for multi-hop - [ ] Log correlation via intent_id - [ ] Metrics summary endpoint - [ ] Unit tests ## Dependencies - None (standalone) ## Estimated Duration 1 week ## Success Criteria - [ ] Metrics exposed in Prometheus format - [ ] Structured logs in JSON format - [ ] Intent IDs in all logs - [ ] Latency tracked per intent - [ ] Token/cost metrics available ## Related - Parent: #69 (Phase 6 Meta)
Author
Owner

Reopened — kilo-gsd closed #79 without implementing deliverables

The kilo-gsd runner hit a pre-dispatch gate failure (dirty worktree from concurrent issue #75) and the Bugfix agent committed unrelated work to clear the gate instead of stashing it. No observability (metrics/logging/tracing) code was implemented. The forced commits have been reverted; the worktree is clean. Re-dispatching with clean state.

## Reopened — kilo-gsd closed #79 without implementing deliverables The kilo-gsd runner hit a pre-dispatch gate failure (dirty worktree from concurrent issue #75) and the Bugfix agent committed unrelated work to clear the gate instead of stashing it. No observability (metrics/logging/tracing) code was implemented. The forced commits have been reverted; the worktree is clean. Re-dispatching with clean state.
Author
Owner

Fixed in commit 010465f — Phase 6.10 Observability (Metrics/Logs/Traces) fully implemented.

Delivered:

  • runtime/tracing.py: TraceContext, W3C traceparent propagation
  • runtime/structured_logging.py: Structured JSON logging with MDC
  • runtime/prometheus_metrics.py: Prometheus metrics (latency, tokens, cost, queue depth)
  • runtime/http_entrypoint.py: POST /metrics + POST /v1/metrics/summary endpoints
  • substrate/tracing.py: Re-export shim for backplane compatibility

Tests: 45/45 passing. Closing.

Fixed in commit `010465f` — Phase 6.10 Observability (Metrics/Logs/Traces) fully implemented. Delivered: - `runtime/tracing.py`: TraceContext, W3C traceparent propagation - `runtime/structured_logging.py`: Structured JSON logging with MDC - `runtime/prometheus_metrics.py`: Prometheus metrics (latency, tokens, cost, queue depth) - `runtime/http_entrypoint.py`: POST /metrics + POST /v1/metrics/summary endpoints - `substrate/tracing.py`: Re-export shim for backplane compatibility Tests: 45/45 passing. Closing.
Mark closed this issue 2026-07-16 05:24:36 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/mesh-seed#79
No description provided.