ADR 0010: Adopt the fleet observability standard (logs, metrics, traces)
Status
Accepted (2026-10-26).
Context
node-topology logged JSON with log/slog and nothing else: no trace or span id
on a log line, no request id, no request log, no metrics, no traces, no
traceparent on the events it publishes, and no OpenTelemetry settings in the
Helm chart. The warehouse-systems services (inventory-storage, wes-work-planning)
already share one pipeline and one convention, recorded in their ADRs "standard
metrics convention" (inventory-storage ADR 0016, wes-work-planning ADR 0013):
- pods export OTLP/gRPC to the in-cluster Collector
(
otel-collector.observability.svc.cluster.local:4317), which feeds Jaeger (traces) and a Prometheus exporter (metrics); - logs stay on stdout as JSON for Alloy and Loki.
Without the same wiring a node registration could not be followed from the REST
call to the event it publishes, a log line could not be joined to its trace, and
no dashboard could show request rate, errors or latency. The alternatives weighed
were a service-specific setup (rejected: the point is that every repo answers the
same query the same way) and the OTel Go auto-instrumentation agents (rejected:
they cannot follow a trace across segmentio/kafka-go, which has no
instrumentation, nor name spans by the chi route pattern).
Decision
Tier 1 (identical in every repo) and Tier 2 (this context's business metric):
-
Telemetry adapter.
internal/adapters/outbound/telemetryholdsSetup(OTLP/gRPC traces and metrics, W3C TraceContext + Baggage propagator, Go runtime metrics; exporters dial lazily, so no Collector means dropped telemetry, never a blocked boot or request; returns a shutdown func) andWithTraceContext(stampstrace_id/span_idon a log record written with a span-carrying context). Only the composition roots (cmd/api,cmd/mcp) import it, plus the adapters;internal/domainandinternal/applicationnever import OpenTelemetry. -
Logger.
slog.New(telemetry.WithTraceContext(slog.NewJSONHandler(os.Stdout, ...))),LOG_LEVEL, uppercase levels. Code on a request path uses the*Contextslog variants; the bare variants have no span. -
HTTP middleware order on both chi routers (REST and MCP):
RequestID->otelchi.Middleware(serviceName, WithChiRoutes(r))->otelchimetric.NewServerRequestDuration->RequestLogger->Recoverer; the existingrejectNULand Idempotency-Key middleware stay after them.telemetry.Setupruns before the router is built (otelchimetric binds the global MeterProvider at construction) and is flushed last on shutdown. The request line carriesmethod,route(the chi pattern, never the raw path, which holds ids),status,duration_ms,bytesandrequest_id; 5xx is ERROR, 4xx WARN, the rest INFO;/healthzand/readyzare not logged.RequestLoggerlives ininternal/adapters/inbound/requestlog, not in the REST adapter, becausecmd/mcpmay not import the REST adapter (TestMCPServerIsReadOnly) and both routers must log identically. -
Traces over Kafka.
OutboxRepo.Appendstampstraceparent/tracestatefrom the active span into the stored outbox headers, inside the transaction that writes the aggregate (internal/adapters/outbound/postgres/outbox_trace.go). The relay publishes the headers unchanged as Kafka headers, so a consumer in another service can continue the trace. Only extra headers are added: the CloudEvents attributes and body, and the encoder's output, are unchanged (ADR 0004). This service consumes no topic (ADR 0003), so it has no consumer span; that part of the standard is skipped here. -
Environment contract.
cmd/apiandcmd/mcpreadOTEL_SERVICE_NAME(defaultsnode-topologyandnode-topology-mcp),OTEL_EXPORTER_OTLP_ENDPOINT(defaulttelemetry.DefaultEndpoint, a barehost:portor a URL),SERVICE_VERSION,ENVIRONMENT(read bySetup) andLOG_LEVEL. -
Chart.
otel.enabled,otel.endpoint,otel.serviceNamerenderOTEL_EXPORTER_OTLP_ENDPOINTandOTEL_SERVICE_NAME(<name>-mcpfor the mcp component);SERVICE_VERSIONis the image tag, or the chart appVersion when empty, for the api and the mcp component (mcp.serviceVersionstill overrides); the api also rendersENVIRONMENTfromenvironment.extraEnvmay not set any of the four.charts/node-topology/tests/render_test.shasserts it and scanscmd/and the telemetry adapter for the variables the binaries read. -
Tier 2 business metric. One counter,
topology.nodes.registered, unit{node}, attributeoutcome(registered|rejected) and, on a rejection,reason(the problem slug the REST adapter answers with:vendor-node-code-taken,operator-not-allowed-for-node-type,subtype-not-allowed,unknown-region,validation-failed,concurrent-update,internal-error).ports.NodeMetricsis the application port;RegisterNodecalls it once per registration attempt, after its retry on a concurrent update; the OTel implementation is in the telemetry adapter and is injected fromcmd/api; a nilDeps.Metricsis a no-op. It follows the fleet convention: dotted lowercase name, one counter with anoutcomeattribute rather than two counters, UCUM unit, a description that says what a human should conclude when it moves.Why registration: it is the one command through which the network grows and the one that external onboarding clients (vendors) drive, so its refusals carry the signal a human acts on (a rising
vendor-node-code-takenoroperator-not-allowed-for-node-typeis a client sending rejected data; a risinginternal-erroris the service failing). Activation, suspension and lane or service-area changes are operator-driven and low volume, andhttp.server.request.durationalready counts them per route and status.
Assumption (recorded as the standard asks): where the reference and this repo
differ, the reference shape wins and the repo's own names are kept (module
path, mcp.environment stays dev, the chart's existing mcp.serviceVersion
key remains an override). No MCP-specific business counter is added.
Not part of this ADR: dashboards and alert rules, which live in warehouse-infra and are generated per deployed context from the instrument names above.
Consequences
- A request, its log lines and the events it enqueued share one trace id;
trace_idin Loki jumps to Jaeger, and a downstream consumer can parent its span on thetraceparentheader. - Request rate, errors and duration come from
http.server.request.duration(otelchimetric) with no hand-rolled counter; onboarding health fromtopology.nodes.registered. - Every new log call on a request path must use a
*Contextvariant, or its line carries no trace id. - The trace parent of a published event is the span that was active at the outbox write (the REST request), not a separate publish span: the relay is asynchronous and adds no span of its own.
- Outbox rows written outside a span (or by a path other than
Append) carry notraceparent.