Architecture: Observability Pipeline — Tracing, Logs & Metrics
This is the architecture behind the decision recorded in ADR-00003, satisfying the requirements in BRD-003 and SR-003.
No flow diagram is attached to this document today — unlike the audit-trail pipeline, no source diagram has been supplied for this cross-cutting topic. The component table and end-to-end flow below are written directly from the current go-lang-core-lib/rust-lang-core-lib/node-lang-core-lib implementations.
Components
| Component | Role |
|---|---|
Browser / mobile client (ui-application, ui-admin-application) |
Creates a real client-kind OTel span per request and injects traceparent/X-Correlation-ID via an HTTP client interceptor before the first REST hop; never injects X-Tenant-ID (FR-04, FR-22, NFR-05). Span export is not live in either app today — see “Client-Side Instrumentation” below. |
Nginx (cdn-edge / nginx-api-router) |
Sets $request_id as X-Gateway-Request-ID, forwards traceparent/X-Correlation-ID unchanged, and enforces Access-Control-Allow-Headers for browser CORS preflight (NFR-04). |
| Go microservice REST layer | otelecho.Middleware extracts traceparent; inline middleware extracts X-Gateway-Request-ID/X-Correlation-ID into context.Context and span attributes, ahead of middleware.RequestID() and the access logger (FR-04, FR-05). |
| Go microservice gRPC layer | TraceContextUnaryServerInterceptor (inbound) / TraceContextUnaryClientInterceptor (outbound) propagate traceparent/correlation_id via gRPC metadata (FR-06). |
| Rust microservice REST layer | request_logger’s RequestMakeSpan creates a root span carrying traceparent/gateway_request_id/correlation_id as declared span fields, read by FlatJsonFormat into every child log line (FR-04). |
| Rust microservice gRPC layer | grpc::server::trace_layer() (inbound) / grpc::client::TraceContextLayer (outbound, first wired by payment-service’s repository/paymentsignal/ calling order-service) (FR-06). |
| Pub/Sub — any topic | MessageHeader.traceparent/.correlation_id, injected on publish (Go: gotel.GetTextMapPropagator().Inject; Rust: current_message_header(tenant_id)) and extracted on receive into a pubsub.receive/handler span (FR-08). |
| Node microservice / worker (NestJS, Firebase Functions) | RequestContextInterceptor (HTTP) or the Pub/Sub receiver’s withMessageReceiver callback (worker) opens the root AsyncLocalStorage scope; every service/repository/controller method wraps in runWithRequestContext (FR-10). |
| OTel Collector | Receives OTLP over gRPC (4317, Go/Rust) or HTTP (4318, Firebase Functions, internal-only) from every instrumented service. |
End-to-end flow
- A browser or mobile client makes a REST call; its HTTP client interceptor injects
traceparentandX-Correlation-ID(FR-04). NoX-Tenant-IDis ever sent by the client (NFR-05). - Nginx forwards
traceparent/X-Correlation-IDunchanged and sets its ownX-Gateway-Request-IDfrom$request_id(FR-04). - The receiving Go or Rust service’s REST middleware/layer extracts all three into request-scoped context and span attributes, in the fixed order documented for each language (FR-05).
- If that request triggers a downstream gRPC call, the calling service’s client interceptor/layer re-injects
traceparent/correlation_idinto the outbound gRPC metadata — nevergateway_request_id, which stops at the REST edge (FR-06, FR-07). - The receiving gRPC server’s interceptor/layer extracts
traceparent/correlation_idfrom metadata into its own request-scoped context, continuing the same trace and the samecorrelation_id. - If that call in turn publishes a Pub/Sub message (e.g.
payment-service’s document-audit event, or a Node migration event), the publisher builds aMessageHeadercarryingtraceparent/correlation_idoff the currently active span/request context (FR-08). - The Pub/Sub subscriber (Go, Rust, or Node) extracts the envelope header before invoking its handler, so the handler’s own logs and spans continue the same trace and
correlation_idthe operation started with (FR-08). - Every span emitted along this path — REST, gRPC, and Pub/Sub — exports to the OTel Collector over the runtime-appropriate OTLP transport (NFR-06), and every log line at every hop carries the same
correlation_id, making it the single value that resolves the whole operation (FR-02).
Known break in this flow: step 6, when the triggering call was itself a gRPC handler rather than an HTTP request, currently yields an empty correlation_id in the published Pub/Sub envelope — see Technical Debt, TD-01.
Client-Side Instrumentation — Flutter & React
Both frontend apps do real client-side span creation, not just header propagation, but neither currently exports those spans anywhere by default — an important distinction from the backend, where every service’s spans are live in Tempo.
ui-application (Flutter) |
ui-admin-application (React) |
|
|---|---|---|
| OTel package | dartastic_opentelemetry (pubspec.yaml) |
@opentelemetry/sdk-trace-web + exporter-trace-otlp-http + instrumentation-xml-http-request (package.json) |
| Init | OtelTracingService.init() (core/services/init/otel_tracing_service.dart), registered via Get.putAsync at app start |
initTracing() (core/telemetry/tracing.ts), builds a WebTracerProvider |
| Per-request span | _addTelemetryHeaderInterceptor() (core/services/init/base_network_service.dart) starts a client span via OTel.tracer().startSpan(...), ends it Ok/Error on response |
XMLHttpRequestInstrumentation auto-instruments every outbound XHR; a manual startUploadSpan() helper covers upload flows |
| Header injection | traceparent via OTelAPI.textMapPropagator.inject(...); X-Correlation-ID minted per request |
traceparent auto-injected by the XHR instrumentation; X-Correlation-ID minted in apiClient.ts |
| Span export today | No-op. OtelTracingService.init() registers a _NoopSpanProcessor — every span is created and immediately discarded; no collector endpoint is configured (by explicit code comment: “No collector wired up yet”). |
Conditional, off by default. initTracing() only attaches a real BatchSpanProcessor/OTLPTraceExporter when an otelEndpoint value is supplied; otherwise nothing exports. ui-admin-application/CLAUDE.md states this directly: the browser only injects traceparent — microservices are what actually export child spans to Tempo. |
| Structured logging | AppLog/_RequestStyleLogPrinter (core/utils/app_logger.dart) emits TIMESTAMP LEVEL message plus JSON fields (trace_id/span_id/correlation_id pulled from the active span context) — deliberately shaped to match go-lang-core-lib’s zap request-log fields, so a mobile log line and a backend log line read the same way (FR-23). |
loglevel package, plain [Component] message-style prefixes — no structured fields, no trace_id/span_id/correlation_id correlation, no parity with Flutter’s or the backend’s log shape. |
Net effect: every request from either app is already traceable end-to-end from the moment it reaches Nginx onward (the traceparent it injects is real and honored), but the request’s own client-side span — the part that would show “how long did the mobile/browser app itself take before and after the network call” — isn’t visible in Tempo/Grafana for either app today. See Technical Debt, TD-05 and TD-06.
Local Development Architecture — Collection, Storage & Visualization
Everything above describes how the four identifiers propagate. This section covers where the resulting traces, logs, and metrics actually land — all defined in development/docker-compose.yml, with collector/storage config under development/otel/.
| Component | Role | Wiring |
|---|---|---|
OTel Collector (otel-collector) |
Single ingestion point for every service’s OTLP traces and metrics. | Receives OTLP over gRPC (4317) and HTTP (4318, internal-only, Firebase Functions) from every service (FR-16, NFR-06). Config: development/otel/otel-collector-config.yaml. |
Tempo (tempo) |
Trace storage/query backend. | The Collector’s otlp_grpc/tempo exporter forwards every trace to Tempo (3200). |
Prometheus (prometheus) |
Metrics storage/query backend. | Scrapes exactly one target: the Collector’s own Prometheus exporter (otel-collector:9464) — never scrapes any service directly (FR-16). Config: development/otel/prometheus.yml. |
docker-exporter |
Container-level resource metrics (CPU/memory/network/restarts). | Reads every container’s cgroup stats via /var/run/docker.sock, exposed on 9713, scraped into the Collector’s prometheus/docker-exporter receiver (FR-15). Functionally the same role the central rules describe as cadvisor — see FR-15’s implementation note and TD-04. |
Vector (vector) |
Log shipping agent. | Reads every container’s Docker logs via its docker_logs source off the Docker socket, reformats them, and ships to Loki (FR-18). Config: development/otel/vector.yaml. |
Loki (loki) |
Log storage/query backend. | Receives shipped logs from Vector (3100). Config: development/otel/loki-config.yaml. |
Grafana (grafana) |
Unified visualization. | Provisioned datasources (development/otel/grafana/provisioning/datasources/) for Prometheus, Tempo (default, with tracesToLogsV2 → Loki), and Loki (with a derivedFields regex turning a log line’s trace_id into a link to its Tempo trace) (FR-19). Ships with four pre-provisioned dashboards: container-resources.json, fleet-overview.json, node-runtime.json, postgres-pools.json. |
This is a fully closed local loop: every service → OTel Collector → (Tempo for traces, Prometheus for metrics) + (Vector → Loki for logs) → Grafana, with trace↔log cross-navigation already wired.
Target Cloud Architecture (Example: GCP) — Not Yet Built
No cloud deployment target, Terraform, or other infrastructure-as-code exists anywhere in this repository today (confirmed by a repo-wide search) — the section below describes the intended shape of a future production deployment, not a built system. It is included here so a future implementer starts from an intentional target rather than inventing one from scratch. See Technical Debt, TD-03 for the tracked gap.
Because every service already exports via standard OTLP to the Collector (FR-20/NFR-09), the only change a cloud target requires is at the Collector’s own configuration — no service code changes:
| Local component | Cloud (GCP) equivalent | Change required |
|---|---|---|
| Every service’s OTLP export | (unchanged) | None — services keep exporting OTLP to the Collector exactly as today. |
| OTel Collector | OTel Collector (same binary/image) | Add a googlecloud exporter (or an equivalent per-provider exporter) alongside — not instead of — the existing local exporters, authenticated via a service account/workload identity provisioned by IaC, not a hand-managed key file. |
| Tempo | GCP Cloud Trace | New exporter pipeline entry; traces continue to originate identically. |
Prometheus + docker-exporter |
GCP Cloud Monitoring (Managed Service for Prometheus, or the googlecloud metrics exporter) |
New exporter pipeline entry; the existing cardinality guardrail (FR-17) matters even more here, since cloud metrics ingestion is usage-billed. |
| Vector → Loki | GCP Cloud Logging | Vector already supports a Cloud Logging sink; alternatively, container stdout is picked up automatically by Cloud Logging on Cloud Run/GKE without Vector at all, depending on the chosen compute target. |
| Grafana (self-hosted) | GCP Cloud Monitoring dashboards, or a self-hosted/managed Grafana pointed at Cloud Monitoring/Cloud Trace/Cloud Logging as datasources | Either replaces or is layered in front of the cloud-native tooling — an open design choice, not yet made. |
| (none locally) | Terraform (or other IaC) provisioning the GCP project’s monitoring workspace, service accounts, and Collector exporter credentials | Net-new — this repository has no IaC of any kind today; this would be its first. |
This table is a target shape, not a decision record — no ADR has been written for which cloud provider or which specific GCP services to use, since no cloud deployment has been approved or scheduled yet.