ADR 0005: Adopt the fleet observability standard (logs, metrics, traces)
Status
Accepted (2026-10-26).
Context
product-discovery 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 and no traces. 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), and customer-ordering adopted it in its ADR 0007:
- 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 search request could not be followed to the consumers that fed its ProductView, a log line could
not be joined to its trace, and no dashboard could show search rate, errors or latency. A service-specific setup was
rejected (every repo should answer the same query the same way), as were OTel auto-instrumentation agents (they cannot
follow a trace through segmentio/kafka-go 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/rebuild) and the other adapters import it;internal/domainandinternal/applicationnever import OpenTelemetry. - Logger.
slog.New(telemetry.WithTraceContext(slog.NewJSONHandler(os.Stdout, ...))),LOG_LEVEL, uppercase levels. Code on a request or message path uses the*Contextslog variants; the bare variants have no span. - HTTP middleware order on the chi router:
RequestID->otelchi.Middleware(serviceName, WithChiRoutes(r))->otelchimetric.NewServerRequestDuration->RequestLogger->Recoverer; the existingrejectNULstays 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/requestlogas in the rest of the fleet. - Traces over Kafka. Each inbound consumer extracts
traceparent/tracestatefrom the message headers and runs every handling attempt in a consumer span named<topic> process(parent: the publisher's span; a message without the headers starts a new trace), so the fold's logs carry the publisher's trace id. The CloudEvents attributes and body are untouched (ADR 0004). - Environment contract.
cmd/apireadsOTEL_SERVICE_NAME(defaultproduct-discovery),OTEL_EXPORTER_OTLP_ENDPOINT(defaulttelemetry.DefaultEndpoint, a barehost:portor a URL),SERVICE_VERSION,ENVIRONMENT(read bySetup) andLOG_LEVEL.cmd/rebuild, a batch job, reads the same variables (service name defaultproduct-discovery-rebuild), callsSetupand flushes on exit; it gets trace-correlated JSON logs and no router. - Tier 2 business metric. One counter,
discovery.searches.served, unit{search}, attributeoutcome(served|empty|failed) and, on a failure,reason(validation-failed|internal-error).ports.SearchMetricsis the application port;Queries.SearchProducts, the context's primary use case (the service publishes nothing and has no command, so the search is its one business act:GET /products), calls it once per call.emptyis a first page (no cursor) with no hit after the trigram retry; a continuation page past the last hit counts asserved. The OTel implementation is in the telemetry adapter and is injected fromcmd/api; a nilDeps.Metricsis a no-op. The description tells a human what to conclude: a risingemptyshare means shoppers look for what the storefront does not show (check the projection feeds and the catalogue);failedwithinternal-errormeans the search itself is failing,validation-faileda client sending bad queries.
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.
Assumptions
- Why
discovery.searches.served(ADR 0001,apis/openapi.yaml): the context is the read side of browsing and search; its one thing worth counting is whether a shopper's search is answered with products. The detail and category routes are plain reads, covered byhttp.server.request.duration. - No Helm chart exists yet for the ecommerce repos, so the standard's chart part (
otel.*values, env on every component,render_test.sh) is not done here and no chart is created; it follows when the chart does. - There is no
cmd/mcp, so onlycmd/apiandcmd/rebuildare covered. - The service publishes nothing, so there is no outbox and no
traceparentto stamp; only the consumer side is wired. go.modpins the OpenTelemetry modules andgolang.org/x/netto the versions of customer-ordering.
Consequences
- A search request, its log lines, and the consumer handling that fed the data share trace ids with the upstream
publishers;
trace_idin Loki jumps to Jaeger. - Request rate, errors and duration come from
http.server.request.duration(otelchimetric) with no hand-rolled counter; search health fromdiscovery.searches.served. - Every new log call on a request or message path must use a
*Contextvariant, or its line carries no trace id. - A consumer span is created per handling attempt, so a retried message shows as several spans under the same parent.