📊

[Project 2c] Telemetry, Monitoring, and Governance for JackGPT System

Designing the Nervous System of an AI Platform

notion image
👉🏻
Executive Summary
This project focuses on designing the telemetry, monitoring, and governance layer that allows an AI system to be safely operated after deployment. Rather than treating observability as logging, it reframes telemetry as a decision-support system that explains why quality, latency, or cost changes over time. The architecture separates engineering telemetry (Langfuse) from product analytics (PostHog), while allowing both to converge at the decision layer. Quality-aware signals—such as retrieval confidence, context efficiency, and fallback activation—enable detection of silent regressions before users complain. Overall, the project treats governance as change safety, ensuring that AI systems can evolve in a measurable, reversible, and explainable way.
Type: 🧭 Personal Learning & System Design Project (Non-Commercial)
Context: An observability and governance layer operating across the AI Chat Assistant and RAG system on jackhpark.com
Focus: How an AI system is observed, evaluated, and safely evolved after deployment

🎯 Objective

This project focuses on the telemetry, monitoring, and governance layer for an AI system after launch—when the hard questions are no longer “does it work?” but “why does it feel slower?”, “why did answer quality change?”, and “what should we do next?”
Instead of treating observability as generic logging, it frames telemetry as a decision-support system that connects system signals to user impact. The goal is to distinguish whether a problem comes from retrieval, model behavior, latency, aborts, or cache efficiency, then make the next change measurable, safe, and reversible.
In practice, that means designing a shared operating model where tools like Langfuse explain what happened inside the AI pipeline, PostHog shows whether users actually felt the impact, and governance rules turn those signals into clearer product and engineering decisions.

⚙️ High-Level Observability Architecture

At a system level, observability answers three different questions: what happened inside an AI request, whether users felt the result, and how the retrieval graph moved through its steps. The system uses three complementary backends rather than asking one dashboard to do all three jobs:
  • Langfuse traces LLM and retrieval activity, including stage-level latency and cost, so a slow or poor answer can be investigated inside the request.
  • PostHog tracks product behavior and the chat_completion operational event, so changes in latency, aborts, and usage can be read in terms of user impact.
  • LangSmith shows the nested LangGraph retrieval run, so an operator can see the path through the graph and inspect its nodes.
The split matters because a graph trace explains the route, an LLM trace explains the work within the request, and product analytics shows whether the behavior mattered to users. LangSmith complements Langfuse; it is not a third copy of the same dashboard.
flowchart TD
  R["AI chat request"] --> LF["Langfuse: LLM and retrieval traces"]
  R --> PH["PostHog: product and completion signals"]
  R --> LG["Retrieval graph, when used"]
  LG --> LS["LangSmith: nested graph run"]
  LF --> D["Investigation and product decision"]
  PH --> D
  LS --> D

🧭 The Black Box Problem

AI systems are inherently non-deterministic.
Traditional monitoring answers questions like:
  • Did the request fail?
  • Did the service crash?
But AI systems fail differently:
  • Retrieval quality silently degrades
  • Context size grows until answers become vague
  • Latency increases due to hidden retries or cache misses
This project reframes observability around a different question:
“What is the system confident about—and should it be?”

🧠 Quality-Aware Telemetry

Instead of recording only success vs. failure, the system uses a single `chat_completion` event per chat request for operational signals. latency_ms records total request time, while latency_retrieval_ms and latency_llm_ms separate retrieval from model time. On that same event, aborted, status, and error_type distinguish an incomplete or failed answer from a slow success.
Cache behavior is recorded there too: response_cache_hit, retrieval_cache_hit, and cache_strategy show whether caching is helping; total_tokens adds a usage signal. env, preset_key, and rag_enabled provide context for comparing requests and focusing on knowledge traffic. There are no separate latency_breakdown or cache_decision events to join before investigating a regression.
Langfuse trace detail is controlled separately: minimal captures the trace, standard adds a configuration snapshot, and verbose adds sanitized retrieval detail when deeper diagnosis is needed. Keeping those traces distinct from the compact PostHog event gives operators detail without turning product analytics into a raw trace log.

Key quality signals include:

  • Retrieval confidence
    • Similarity scores of selected chunks
    • Threshold pass/fail rates
  • Auto-RAG activation
    • How often fallback strategies (rewrite, HyDE, multi-query) are triggered
  • Context efficiency
    • Retrieved vs. actually used chunks
    • Dropped by threshold, deduplication, or quota
  • Citation coverage
    • Whether answers remain traceable to source content
These signals make it possible to detect soft regressions—cases where answers still render, but quality is quietly eroding.
One key source of these signals is the guardrail pipeline itself, which surfaces its decisions as structured metadata via X-Guardrail-Meta.
flowchart TD
  GP["Guardrail Pipeline"] -->|"intent · budget · <b>safeMode</b> decisions"| XG["<b>X-Guardrail-Meta</b><br>(response header)"]
  XG --> LF["Langfuse<br>(engineering trace)"]
  XG --> UI["Chat UI<br>(operator diagnostics panel)"]
  LF --> OA["<b>Operational Analysis</b><br>(intent distribution · budget pressure · fallback rate)"]

📊 RAG Health & Dataset Monitoring

Long-term system health is tracked using snapshot-based monitoring rather than ad-hoc inspection.
flowchart TD
  I["Ingestion Run"] --> R["rag_ingest_runs\n(status, duration, errors)"]
  R --> S["rag_snapshot\n(documents, chunks, deltas)"]
  S --> H["Dataset Health View"]

  H --> Q["Quality Trends"]
  H --> G["Growth & Drift"]
This allows the platform to answer questions such as:
  • Is the knowledge base growing as expected?
  • Are ingestion failures accumulating?
  • Did a recent content change cause unexpected retrieval shifts?
From a PM perspective, this creates a shared, objective baseline for discussions about quality.

⚡ Performance, Cost, and Caching Signals

Operational quality is not just correctness—it is also cost and responsiveness. Latency attribution is tracked on chat_completion: latency_retrieval_ms and latency_llm_ms distinguish retrieval from model time. response_cache_hit, retrieval_cache_hit, and cache_strategy show cache effectiveness on that same event.
total_tokens provides a usage signal, while comparing cache-hit and cache-miss latency shows whether caching still saves time. These signals help teams reason about trade-offs, not just raw performance.

🛡️ Governance: Designing for Safe Change

As the system evolves, not all changes carry the same risk.
This project treats governance as change safety, not restriction.
Key mechanisms include:
  • Versioned embedding spaces
    • New embedding models can be introduced without disrupting existing data.
  • Runtime safety switches
    • Safe modes can disable retrieval or external dependencies instantly.
  • Configuration-driven tuning
    • Thresholds and limits can be adjusted without redeploying code.
Together, these patterns allow experimentation while preserving operational confidence.

🔧 Why Langfuse and PostHog

Operating an AI system responsibly requires observing different layers of reality.
No single tool answers all of the questions that matter after deployment.
For this reason, the platform intentionally adopts two complementary telemetry systems, each optimized for a different type of decision.

🧠 Langfuse — Engineering & Model-Level Observability

Langfuse is designed for LLM-native observability.
It captures request-level traces, spans, and metadata that are specific to AI systems, such as:
  • Retrieval stages and fallback paths
  • Latency breakdowns across RAG and generation
  • Token usage and cost attribution
  • Decision context (intent, preset, environment)
This makes Langfuse suitable for answering questions like:
  • Why did this response take longer than usual?
  • Did retrieval retry or fall back to Auto-RAG?
  • Which part of the pipeline dominated cost or latency?
In short, Langfuse explains why the system behaved the way it did.

📊 PostHog — Product Impact & User Behavior

PostHog is designed for product-level analytics, not system introspection.
It focuses on:
  • User behavior and interaction patterns
  • Feature usage and adoption
  • Funnel analysis and retention cohorts
This makes PostHog suitable for answering questions like:
  • Are users engaging more or less after a change?
  • Did a latency increase affect usage or retention?
  • Which features actually matter to users over time?
In short, PostHog explains whether system behavior had real-world impact.

🔁 How They Work Together (Decision Flow)

The two tools are intentionally not interchangeable.
In practice,
while
  • If engagement drops → start with PostHog