Appearance
Step-by-Step Build Order & Implementation Guide
This guide details the exact chronological sequence to reconstruct 14-Tracing-Backend from scratch.
Phase 1: Core Foundation & Data Modeling
- Initialize Database Schema: Define the primary
spansandtracestables using SQLAlchemy models (backend/src/storage/models.py). Indextrace_id,service_name, andstart_time_us. - FastAPI Application Setup: Scaffold
backend/src/api/app.pywith standard middleware, health probes (/healthz,/readyz), and centralized HTTP error formatting. - Trace Context Propagation: Implement W3C
traceparentparsing inbackend/src/tracelib/core/to extracttrace_id,span_id, and sampling flags.
Phase 2: Ingestion & Collector Pipeline
- OTLP Ingestion Endpoints: Build
api/routes/ingestion.pysupporting OpenTelemetry Protobuf and JSON payloads. - PII Sanitizer & Security Redaction: Implement regex and key-name scanners in
security/pii_filter.pyto strip passwords, credit card numbers, and authorization tokens. - Asynchronous Ring Buffer: Implement bounded queue management in
collector/queue_buffer.pywith background batch-flushing workers.
Phase 3: Adaptive Sampling Engine
- Tail-Sampling Sliding Window: Build
sampling/tail_window.pyholding uncompleted trace spans for up to 30 seconds. - Error & Latency Evaluators: Wire
sampling/error_aware.pyandsampling/tail.pyto promote traces with HTTP errors or duration exceeding p99 thresholds.
Phase 4: Query Engine & Graph Traversal
- Trace Reconstruction: Build
query/trace_lookup.pyto assemble unordered spans into an execution tree. - Critical Path Calculation: Implement DAG topological sorting in
query/critical_path.pyto isolate blocking sequential spans.
Phase 5: Machine Learning & LLM Integration
- Anomaly Detectors: Implement
ml/latency_anomaly.pyandml/dependency_anomaly.pyusing statistical z-scores. - Pre-trained LLM Postmortem Engine: Connect
ml/llm_engine.pyto external LLM API with strict JSON schema parsing.
Phase 6: Frontend Visualization (React 18 + Vite)
- Vite Scaffold: Set up React 18, TypeScript, and Tailwind CSS in
frontend/. - Gantt Waterfall & DAG Tree: Implement
WaterfallTimeline.tsxandSpanTree.tsxto visualize parallel and critical path execution.