Skip to content

[ADD] : Observability foundation - Structured JSON logging, Fluent Bit/Loki, Distributed Tracing. Phase 6 - #13

Merged
AlexandreN8 merged 24 commits into
mainfrom
feature/observability-retrofit
Jul 19, 2026
Merged

AlexandreN8 merged 24 commits into
mainfrom
feature/observability-retrofit

Conversation

@AlexandreN8

@AlexandreN8 AlexandreN8 commented Jul 15, 2026 •

Copy link
Copy Markdown
Owner

What

Structured JSON logging across all 9 services (edge + PaaS), Loki + Fluent Bit log aggregation, OpenTelemetry distributed tracing across the full pipeline, Tempo metrics-generator for RED metrics, and 5 new Grafana dashboards replacing the Phase 0 placeholder.

Why

  • Unstructured print() made cross-service debugging nearly impossible, and gave no way to separate infra noise from business events
  • No way to follow a single reading from edge sensor to its final outcome (stored, aggregated, alerted, or rejected) without manually cross-referencing logs across 5+ services

Changes

  • logging_setup.py (duplicated per service, same pattern as heartbeat.py): JSON output with timestamp, level, service, category (infra|business), dynamic fields
  • Loki + Fluent Bit deployed via Terraform (one Fluent Bit per host - no K8s DaemonSet yet). Each container uses Docker's native log_driver: fluentd, forwarding to Fluent Bit's Forward protocol receiver; service/category/level promoted to real indexed Loki labels via Label_Keys
  • tracing_setup.py (duplicated per service): OTel SDK, W3C trace context. trace_context propagated in the JSON payload itself, not Kafka headers - avoids requiring two different extraction mechanisms depending on whether a message arrived via MQTT (no native headers) or Kafka
  • Tempo + OTel Collector deployed; Tempo's metrics-generator (span-metrics, service-graphs) derives RED metrics (Rate, Duration - Errors pending span-status instrumentation) from existing traces with no extra application code, remote-written to Prometheus
  • 5 dashboards: Home (landing page, system health, alerts summary), Business Overview (per-sensor-type panels with real business-plausible-range thresholds), Platform PaaS, Platform Edge (RED + log volume + fault-injection breakdown)

Design notes / issues found only through end-to-end validation

  • aggregator.flush_window is a deliberately untethered span (no parent context) - a window aggregates many different messages/traces, so it can't legitimately belong to any single one
  • ota_agent is not traced - no Kafka-forwarded event exists to correlate; a span here would only ever produce an isolated single-span trace with no real correlation value. RED metrics for it are deferred to a future Prometheus /metrics retrofit (noted as Phase 7.1 debt), not built here
  • Ansible's pre_tasks: is required to gate role deployment on Fluent Bit/OTel Collector's ports being ready. A bare wait_for on Fluent Bit's port isn't fully sufficient either (Docker's fluentd log driver does a handshake beyond raw TCP connectivity)
  • Home dashboard's "service activity" panel is an honest proxy (traced calls in last 5m via > bool 0), not a true per-service up/down - only error_handler exposes a real scraped /metrics endpoint today

How it was tested

  • Each service's logging/tracing retrofit validated individually (unit tests + live deploy) before moving to the next, same discipline as prior phases
  • Full pipeline trace confirmed end-to-end via Tempo's waterfall view: iot_devices → edge_processor (x2 spans) → cleaner → parallel anomaly_detector/aggregator, both happy-path and DLQ-rejection branches
  • traces_spanmetrics_calls_total/latency_bucket confirmed queryable in Prometheus with real values matching live traffic
  • All 5 dashboards visually confirmed rendering real data, not just structurally present

@AlexandreN8
AlexandreN8 force-pushed the feature/observability-retrofit branch from 013a9c1 to fc6f81f Compare July 17, 2026 21:34
…a datasource with Loki trace-to-log correlation
…traceparent propagated via payload's trace_context field
… Tempo's metrics-generator) + log volume by service/category
…rts overview, and navigation to the other 3 dashboards
@sonarqubecloud

Copy link
Copy Markdown

@AlexandreN8
AlexandreN8 merged commit 5fa7b00 into main Jul 19, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant