Anchoring AI — Post 09

Wiring It Up

OpenTelemetry instrumentation, Grafana in docker-compose, and live LLM/RAG dashboards

Status: Placeholder. This post is planned. The outline and key concepts below describe what it will cover.


What This Post Covers

Post 6 designed the observability stack. This post builds it. We’ll add OpenTelemetry instrumentation to rag/pipeline.py and mcp/tools.py, extend docker-compose.yml with a Grafana + Prometheus + OTel Collector stack, and wire up the dashboards described in Post 6.

By the end, every MCP tool call is a traced span, every RAG query emits latency and retrieval score metrics, and every LLM call reports token counts to Grafana — all visible in a live dashboard.


Key Concepts


Planned New Services (docker-compose additions)

# New services to add:
otel-collector:
  image: otel/opentelemetry-collector-contrib
  # receives from Python app on 4317 (gRPC) / 4318 (HTTP)
  # exports to Prometheus on 8889

prometheus:
  image: prom/prometheus
  # scrapes otel-collector on 8889

grafana:
  image: grafana/grafana
  # provisioned datasource: Prometheus
  # provisioned dashboard: Anchoring AI LLM/RAG Metrics

Planned Outline

  1. The plan — what we’re adding, where it goes, how it connects
  2. Installing OTelopentelemetry-sdk, opentelemetry-exporter-otlp, the Python package list
  3. Initializing the SDK — where to call TracerProvider, MeterProvider, LoggerProvider; the Resource that identifies this service
  4. Instrumenting mcp/tools.py — spans for each tool call; tagging with tool name and input parameters
  5. Instrumenting rag/pipeline.py — spans for rag_query() and retrieve(); emitting rag_retrieval_score, token counts, document counts
  6. Instrumenting rag/embeddings.py — timing the embedding API call; emitting embedding_duration_seconds
  7. Docker Compose additions — the three new service definitions; the OTel Collector config YAML; Prometheus scrape config
  8. Grafana setup — provisioning the datasource; importing the dashboard JSON; walking through each panel
  9. Firing a query and watching it land — live trace in Grafana Explore; metrics updating on the dashboard
  10. What’s missing — alerting rules (teased for Post 8); log correlation; distributed traces across service boundaries

Code Changes for This Post


Outstanding Questions / TBD