ADR 0006: Adopt the fleet observability standard (logs, metrics, traces)
Status
Accepted (2026-10-26).
Context
checkout 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 and no traceparent on the
events it publishes. 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); customer-ordering adopted it in its ADR 0007, and this ADR replicates that
shape here:
- 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 checkout confirm could not be followed from the REST call
through the sibling calls and the CheckoutCompleted event, a log line could not be
joined to its trace, and no dashboard could show confirm rate, errors or latency.
Decision
- 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). The files are byte-identical to customer-ordering's apart from the module path. Only the composition roots (cmd/api,cmd/mcp) and 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 path uses the*Contextslog variants (the MCP error mapper now takes the request context). - 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 and is flushed last on shutdown. The request line carriesmethod,route(the chi pattern, never the raw path),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 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 already publishes stored headers unchanged as Kafka headers. Only extra headers are added: CloudEvents attributes and body are untouched (ADR 0004). - Environment contract.
cmd/apiandcmd/mcpreadOTEL_SERVICE_NAME(defaultscheckoutandcheckout-mcp),OTEL_EXPORTER_OTLP_ENDPOINT(defaulttelemetry.DefaultEndpoint),SERVICE_VERSION,ENVIRONMENT(read bySetup) andLOG_LEVEL. - Tier 2 business metric. One counter,
checkout.sessions.confirmed, unit{session}, attributeoutcome(completed|declined|requote-required|failed|in-doubt|refused) and, for every outcome but the two successes (completed,requote-required),reason:payment-declined,authorization-mismatch,placement-in-doubt,authorization-unknown, the session's failure code (place-order-rejected, ...), or for a refusalprice-quote-expired,session-closed,not-found,concurrent-update,illegal-transition,validation-failed,internal-error.ports.SessionMetricsis the application port;ConfirmSession.Executecalls it once per attempt with the outcome the shopper was answered with (the policies that re-drive the saga do not count, so one shopper action is one data point); the OTel implementation is in the telemetry adapter and is injected fromcmd/api; a nilDeps.Metricsis a no-op.
Why this counter
Reading apis/openapi.yaml and ADR 0001, the primary command is the confirm route:
open only quotes, while confirm is the saga that moves money and places the order.
Its outcomes are exactly the failure modes an operator must tell apart: payment refused
(declined), offers changed (requote-required), the pivot rejected (failed), and the
unknown outcome that locks the session (in-doubt, which the 20 h alert and 22 h
give-up depend on). Rising declined means payment is refusing shoppers; rising
requote-required means offers expire or change before shoppers confirm; rising
in-doubt means the place-order step is slow or failing; refused with
internal-error means the service itself is failing. One counter with an outcome
attribute follows the convention.
Assumptions
- No Helm chart exists in this repository (ecommerce repos have none yet), so the chart
part of the standard (
otel.*values, deployment env,render_test.sh) is skipped, not invented. - checkout consumes no topic (
cmd/apicomment, ADR 0004), so there is no Kafka consumer to extracttraceparentin; the stamping side is implemented and the consumers ofCheckoutCompleted(shopping-cart, customer-payments) extract it. docs/adrhas no index file anddocs/runtime.mddoes not exist, so neither is edited.- A confirm that finds the session already moved on by a policy returns the current state and counts by that state.
- Dashboards and alert rules live in warehouse-infra and are generated per deployed context from the instrument name above; they are not part of this change.
Consequences
- A request, its log lines and the event it enqueued share one trace id;
trace_idin Loki jumps to Jaeger. - Request rate, errors and duration come from
http.server.request.duration(otelchimetric); confirm health fromcheckout.sessions.confirmed. - Every new log call on a request path must use a
*Contextvariant, or its line carries no trace id. OutboxRepo.Insert(the raw path used by tests) stamps nothing; onlyAppend, the path every use case takes, does.