SR-003 — Observability & Tracing: System Requirements
By Engineering Team•September 24, 2026•7 min read
| Metadata | Details |
|---|---|
| System Name | Platform-Wide Observability & Distributed Tracing |
| Document ID | SR-2026-OBS-001 |
| Author | Engineering Team |
| Status | Approved |
Traces back to BRD-003 — Platform-Wide Observability & Distributed Tracing.
Functional Requirements
Identifier Contract
- FR-01 (Exactly Four Identifiers): the platform MUST use exactly four tracing identifiers —
traceparent/tracestate(W3C trace context),correlation_id,gateway_request_id, andrequest_id— and MUST NOT introduce a fifth identifier for a new transport or service without updating this contract first. - FR-02 (Correlation Guarantee):
correlation_idMUST be the one identifier guaranteed to carry the same value on both sides of any hop — it is the identifier support/on-call use to resolve a whole operation, minted at the Nginx/REST edge (X-Correlation-ID) or by the originating service if the request has no upstream edge. - FR-03 (Single-Hop Debugging IDs Stay Local):
gateway_request_id(Nginx’s$request_id) andrequest_id(Go’s Echomiddleware.RequestID()/ Rust’srequest_loggerper-request UUID) MUST NOT be propagated past the service/hop that minted them, and MUST NOT be substituted forcorrelation_id.
REST Propagation
- FR-04 (REST Header Propagation):
traceparent,X-Correlation-ID, andX-Gateway-Request-IDMUST propagate as HTTP headers at every REST hop. Go wires this viaotelecho.Middlewareplus inline middleware inNewEchoServer; Rust viarequest_logger’sRequestMakeSpan/set_gateway_otel_attr/set_correlation_otel_attr, applied once intransport/router.rs. - FR-05 (Go Echo Middleware Order): a Go service’s Echo middleware chain MUST run in this fixed order:
otelecho.Middleware→ inlinetraceparent/X-Gateway-Request-ID/X-Correlation-IDextraction →middleware.Recover()+middleware.RequestID()+ access logger →requestDurationMiddleware()last.requestDurationMiddleware()MUST stay innermost, since it callsc.Error(err)itself to makec.Response().Statusreadable beforee.HTTPErrorHandlerruns.
gRPC Propagation
- FR-06 (gRPC Metadata Propagation):
traceparentandcorrelation_idMUST propagate via gRPC metadata, never the request payload. Go:TraceContextUnaryServerInterceptor(server, chained first inNewGRPCServer) andTraceContextUnaryClientInterceptor(client, a dial option inNewGrpcClient). Rust:grpc::server::trace_layer()(server) andgrpc::client::TraceContextLayer(client). - FR-07 (gateway_request_id Excluded from gRPC):
gateway_request_idMUST NOT be added to a gRPC interceptor or layer — it is REST-entry-point-only by design;correlation_idis the identifier that continues past the REST/gRPC trust boundary.
Pub/Sub Propagation
- FR-08 (Pub/Sub Envelope Propagation):
traceparentandcorrelation_idMUST propagate via the Pub/Sub envelope header (MessageHeader.traceparent/.correlation_id), injected on publish and extracted on receive, for every publisher/subscriber in the platform. Go:message.MessageHeaderviaWithMessageReceiver(receive) andgotel.GetTextMapPropagator().Inject+log.GetCorrelationID(ctx)(publish). Rust:rust_lang_core_lib::pubsub’sMessageEnvelope<D>/MessageHeader,current_message_header(tenant_id)(publish) and thepubsub.receivespan wrapping the handler (subscribe). - FR-09 (gateway_request_id Excluded from Pub/Sub):
gateway_request_idMUST NOT be added to a Pub/SubMessageHeader, for the same reason as FR-07.
Span Wrapping
- FR-10 (Mandatory Span Wrapping): every public service and repository method MUST be wrapped in a span. Go:
otel.WithSpan[T](ctx, "Type.Method", func(ctx) (T, error)). Rust:#[tracing::instrument], with every struct/reference/trait-object parameter inskip()so it is never auto-printed viaDebug. Node:runWithRequestContext('Type.Method', fn), backed byAsyncLocalStorage. - FR-11 (Go Tracing Codegen —
gowrap): a Go service MUST generate its tracing decorator via the documentedgo:generate gowrapone-liner — never hand-write one — using the fixed../../../../../go-lang-core-lib/generator/otel_generator.tmplrelative path (never shortened, never absolute). - FR-12 (Go Background-Goroutine Context Rule): a goroutine launched from a Go service or repository MUST use
context.WithoutCancel(ctx), nevercontext.Background(), so the OTel span,tenant_id,user_id, andcorrelation_idsurvive into the goroutine. - FR-13 (Node Fan-Out Trace Root):
runInNewTraceMUST be used only at a genuine fan-out point (one unit of work spawning many independent downstream units) — never as a default in place ofrunWithRequestContext.
Metrics Collection
- FR-14 (Per-Language Metric Emission): every service MUST emit its language’s documented metrics via its core lib’s shared constructors — Go:
http.server.request.duration/rpc.server.request.duration/pgxpool gauges viaotel.InitObservability; Rust:http.server.request.duration/rpc.server.request.duration/sqlx pool gauges viadb::connect_postgresand the Axum/gRPC metrics layers; Node:http.client.request.duration/event-loop-lag gauges — never a hand-rolled equivalent metric (per the central05-performance-and-metricsrule). - FR-15 (Container-Level Resource Metrics): container CPU/memory/network/restart metrics MUST be collected for every service with zero per-service Dockerfile or code change, via a single shared container-metrics exporter reading each container’s cgroup stats over the Docker socket. Implementation note: the platform’s central rules (
.claude/rules/05-performance-and-metrics.md, and several core-libCLAUDE.mdfiles) describe this component ascadvisor; the container actually deployed indevelopment/docker-compose.ymlisdocker-exporter(ghcr.io/dlepaux/docker-exporter, port8091:9713), serving the identical role. This naming mismatch is tracked as technical debt — see TD-00003. - FR-16 (Metrics Collection & Visualization Pipeline, Local Dev): every metric from FR-14/FR-15 MUST be scrapeable end-to-end in local development: each service exports OTLP metrics to the OTel Collector (
4317); the Collector exposes them on its own Prometheus exporter (9464); Prometheus (development/otel/prometheus.yml) scrapes that single endpoint; Grafana renders them via a provisioned Prometheus datasource. No service is scraped directly by Prometheus. - FR-17 (Cardinality Guardrail): no metric label MUST ever be
tenant_id,correlation_id, or any other unbounded per-request value — route/method templates only, per the identical rule stated in all three core libs.
Log Aggregation
- FR-18 (Centralized Log Shipping, Local Dev): every service’s stdout/JSON logs MUST be collected without per-service log-shipping code — a shared log-forwarding agent (Vector,
development/otel/vector.yaml) reads every container’s Docker logs off the Docker socket and ships them to a centralized log store (Loki), rather than each service integrating its own shipping client. - FR-19 (Trace-to-Log Correlation): a log line containing a
trace_idMUST be navigable directly to its matching distributed trace from the log-viewing UI — implemented via Grafana’s Loki datasourcederivedFieldsregex matchingtrace_idand linking to the Tempo datasource, and Tempo’s datasourcetracesToLogsV2configuration linking a trace back to its Loki log lines.
Cloud Production Export (Gap)
- FR-20 (Vendor-Neutral Export Contract): every service MUST continue exporting traces/metrics via standard OTLP to the OTel Collector, never directly to a vendor-specific SDK/endpoint — so that adding a cloud export target is a Collector-config change (new exporter, e.g.
googlecloud), not an application code change in every service. (Currently satisfied by construction — no service exports anywhere except the local OTel Collector today.) - FR-21 (Cloud Monitoring Export Target): the platform SHOULD be able to export the same traces/metrics/logs pipeline to a managed cloud monitoring service (e.g. GCP Cloud Monitoring, Cloud Trace, Cloud Logging) once a cloud deployment target exists, configured as part of that deployment’s infrastructure-as-code rather than hand-configured per environment. (Gap — no cloud deployment target, Terraform, or other IaC exists in this repository today; tracked as technical debt, see TD-00003.)
Client-Side Instrumentation (Flutter & React)
- FR-22 (Real Client-Side Span Creation, Not Just Header Injection): both
ui-application(Flutter) andui-admin-application(React) MUST create a real client-kind OTel span for each outbound request, not merely injecttraceparent/X-Correlation-IDheaders. Flutter:base_network_service.dart’s_addTelemetryHeaderInterceptor()starts a span viaOTel.tracer().startSpan(...)and ends it with an Ok/Error status in the response/error handler. React:core/telemetry/tracing.ts’sXMLHttpRequestInstrumentationauto-instruments every outbound XHR call, plus a manualstartUploadSpan()helper for upload flows. - FR-23 (Flutter Structured Log Format Parity with Backend):
ui-application’s logger (core/utils/app_logger.dart’sAppLog/_RequestStyleLogPrinter) MUST emit a single-lineTIMESTAMP LEVEL messageshape withtrace_id/span_id/correlation_idfields sourced from the active OTel span context, mirroringgo-lang-core-lib’s zap-based request-log field names (log.LogInfoWithTrace’strace_id/span_id/correlation_idfields) — so a mobile log line and a backend log line for the same operation read with the same field shape and are visually/structurally comparable side by side.
Non-Functional Requirements
Traceability & Consistency
- NFR-01 (Cross-Language Contract Parity): Go, Rust, and Node core libs MUST implement the same four-identifier contract with the same per-transport propagation scope — a drift between languages (e.g. one language propagating
gateway_request_idover gRPC) is a defect, not an acceptable variation. - NFR-02 (No Silent Identifier Drift): adding a new transport or language binding MUST update this document’s propagation contract and the relevant core lib’s
CLAUDE.mdin the same change — the two MUST NOT be allowed to drift apart. (Process gap previously observed — see TD-00003.) - NFR-03 (gRPC-Originated Pub/Sub Correlation): a Pub/Sub message published from a gRPC-invoked handler SHOULD carry a populated
correlation_idsourced from the inbound gRPC call’s metadata. (Gap — tracked as technical debt, see TD-00003.)
Browser/Client Integration
- NFR-04 (CORS Header Allowance):
traceparent/tracestateandX-Correlation-IDMUST be listed inAccess-Control-Allow-Headersindevelopment/nginx.conf, or a browser client’s CORS preflight rejects the header before it ever reaches the gateway. - NFR-05 (No Tenant Header from Browser Clients): a browser/mobile client MUST inject
traceparentandX-Correlation-IDvia its HTTP client interceptor, but MUST NEVER injectX-Tenant-IDitself — tenant scope comes only from the Firebase JWT, decoded server-side by Nginx. - NFR-10 (Client Span Export Status Must Not Be Assumed Live): client-side spans created per FR-22 MUST NOT be assumed to reach a collector without checking each app’s current export configuration — Flutter’s
OtelTracingService.init()currently registers a_NoopSpanProcessorthat discards every span (no collector wired up yet, by explicit code comment); React’sinitTracing()only attaches a realBatchSpanProcessor/OTLPTraceExporterwhen anotelEndpointvalue is configured, and exports nothing otherwise. (Gap — tracked as technical debt, see TD-00003.) - NFR-11 (React Frontend Log Format Divergence from Flutter/Backend):
ui-admin-application’s frontend logging (theloglevelpackage, plain[Component] message-style prefixes) does NOT currently follow the structured, field-based log shape FR-23 requires of Flutter — there is no cross-platform frontend logging format parity yet, only a Flutter-to-backend one. (Gap — tracked as technical debt, see TD-00003.)
Runtime-Specific Transport
- NFR-06 (OTLP Transport Parity per Runtime): Go/Rust microservices MUST export OTLP over gRPC (port
4317); Firebase Functions MUST export OTLP over HTTP (port4318, internal to the Docker network) — this split MUST stay consistent with each runtime’s own constraints, not be silently unified.
Sensitive Data
- NFR-07 (Sensitive-Value Logging Carve-Out, Rust): a value standing in for real secret material (e.g. an OTP code with no live provider behind it yet) MUST be logged only via
log_debug!, neverlog_info!, so it is structurally absent from production (LOG_LEVEL=info) logs. - NFR-08 (No Raw PII/PCI in Aggregated Logs): centralized log aggregation (FR-18) MUST NOT become a second, un-audited place sensitive data leaks to — a service’s own logging discipline (structured logs, no raw PII/PCI fields) is what keeps aggregated logs safe; the log-shipping layer (Vector) performs no masking of its own and MUST NOT be relied on as a masking boundary.
Cloud Readiness
- NFR-09 (No Cloud-Specific Code in Services): a future cloud-monitoring export target (FR-21) MUST be reachable by reconfiguring the OTel Collector’s exporters alone — no service’s own code should ever need to change to support a new export destination, preserving FR-20’s vendor-neutral contract.