ADR 0013: Adopt the fleet observability standard
Status
Accepted (2026-11-14). Implements the fleet "standard metrics convention" (inventory-storage ADR 0016, wes-work-planning
ADR 0013) for this context and closes the open row of the fleet ecosystem-gaps tracker that says cmd/api of
pick-face-replenishment emits no metrics, no traces and no OpenTelemetry instruments. It changes no API contract, no
event payload, no schema and no domain code.
Context
Until this ADR the service had structured logs and two health endpoints and nothing else: no telemetry.Setup, no HTTP
request metrics, no OTLP export, logs without a trace id, and no business instrument. Its Grafana panels that read
http_server_request_duration_seconds or the Go runtime metrics stayed empty for every binary, and a request could not
be followed from Kong into the service.
Decision
The service adopts the two tiers of the fleet standard. Reference implementation copied from inventory-storage
(telemetry.go, slogotel.go and their tests, one repo throughout); the multi-binary layout follows node-topology.
Tier 1: identical everywhere
telemetry.Setup(internal/adapters/outbound/telemetry/telemetry.go): OTLP/gRPC trace and metric exporters, W3C trace-context propagator, Go runtime metrics,service.name,service.versionanddeployment.environment.name(fromENVIRONMENT). An empty endpoint falls back toDefaultEndpoint(localhost:4317); export is lazy and non-blocking, so a missing Collector costs telemetry and never availability.- One
cmd/<binary>/telemetry.goper long-running binary:cmd/api,cmd/a2a,cmd/mcp,cmd/pfr-projectorandcmd/pfr-reports. Each readsOTEL_SERVICE_NAME(defaultpick-face-replenishment,-a2a,-mcp,-projector,-reports),OTEL_EXPORTER_OTLP_ENDPOINT,SERVICE_VERSION(ENVIRONMENTis read bySetup), starts the SDK after the configuration check (a configuration error must still fail fast), and defers the flush so it runs after the server and the workers have stopped (5 s bound). The projector is not an HTTP API server (its admin mux only answers probes), so it getsSetupand trace-correlated logs only; the loggers of all five binaries wrap their JSON handler intelemetry.WithTraceContext, which addstrace_idandspan_idto any record logged with a span in its context. - HTTP middleware on the REST router and on the reports router, in the order the standard fixes:
RequestID->otelchi.Middleware->otelchimetric.NewServerRequestDuration->RequestLogger->Recoverer. The MCP and A2A routers (small chi routers with no request logger or recoverer of their own) get the two otel middlewares in the same order, as the reference's MCP router does. The span is named after the chi route pattern andhttp.server.request.durationcarrieshttp.routeas that pattern, so a site id in the path never becomes a label./healthzis unchanged.RequestLoggerlives in its own package,internal/adapters/inbound/requestlog, because the MCP read-only fitness test forbidscmd/mcpimporting any path containinginbound/http.
Tier 2: one business counter
replenishment.request.raised (unit {request}, Prometheus series replenishment_request_raised_total), attributes
outcome (created or failed) and, only on failure, reason (the problem slug the API answers for the same error:
replenishment-already-open, concurrent-modification, quantity-exceeds-max, no-source-stock, invalid-quantity,
and internal-error for anything else).
- Why this command. The context exists to turn a below-minimum pick face into a replenishment request. Every
creation path (the evaluation sweep, the three event consumers through
EvaluateSKU, and the manual request, sized or explicit) goes throughEvaluator.plan, so one call site counts them all. A risingoutcome=failedshare, or a singlereason, means detection and the consumers fight over the same pick faces or the store is failing; a flatcreatedseries while stock levels move means the detector is not raising. - Placement. Port
ports.ReplenishmentMetricsininternal/application/ports; implementationtelemetry.ReplenishmentMetricsininternal/adapters/outbound/telemetry; wired incmd/apionly.Evaluator.Metricsis nil-safe (the MCP and A2A read-only evaluators and every unit test leave it nil), andinternal/domainis never touched. - Reason cannot drift.
usecases.FailureReasonrepeats five slugs of the http problem catalogue; a test in the http adapter (TestFailureReasonIsTheProblemSlug) asserts each equalsproblemFor(err).slug. - What it does not count. Refusals that happen before a request is planned (
no-policy,nothing-to-replenish,no-forward-assignment, an open request already found by the manual path) and detections that raise nothing (healthy,already_open,no_policy,no_source) are not counted by this instrument. The count is taken inside the unit of work, so a failure of the final commit is not separated fromcreated.
Trace propagation across Kafka: no code needed, and where it stops
The outbox repository already stores headers on every row and traceHeaders already injects the traceparent (and
tracestate) of the writing request's context from the global propagator
(internal/adapters/outbound/postgres/outbox_repository.go), appended where the row is written so the CloudEvents
encoders stay byte-identical. Before this ADR nothing installed a propagator, so the headers were empty; telemetry.Setup
now installs one, which makes that code live with no change and no migration. Limit: the span only exists for a write
that arrives over HTTP (the REST API). The Kafka consumers do not extract a trace context from the incoming message
(not evidenced in internal/adapters/inbound/kafka), so rows raised by an event-driven evaluation carry no
traceparent. This is reported, not fixed here.
Deviations from the reference
normalizeEndpointbuilds itshttp://prefix with a string literal exactly as the reference does; no URL-literal fitness sensor in this repository rejected it (the architecture tests pass), so thenet/urlworkaround the task anticipated was not needed.golang.org/x/netwas not a dependency before; the OTLP/gRPC modules bring it andgo.modselectsv0.62.0(go list -m golang.org/x/net); older versions appear ingo mod graphonly as requirements of other modules.make vulnruns on the final tree.- Instruments the reference adds beyond the standard (for example
otelchimetric.NewServerActiveRequests) are not adopted; the standard requires the duration histogram only.
Chart
otel.enabled, otel.endpoint, otel.serviceName, otel.serviceVersion (empty falls back to image.tag, then the
chart appVersion) and a top-level environment. While otel.enabled, the four variables OTEL_EXPORTER_OTLP_ENDPOINT,
OTEL_SERVICE_NAME, SERVICE_VERSION and ENVIRONMENT are rendered into every Deployment that runs a Go binary (api,
mcp, a2a, projector, reports; the nginx frontend gets none) and are refused in every extraEnv list.
<otel.serviceName>-<component> is the service name of the non-api components.
Consequences
- A request to the REST, reports, MCP or A2A router produces
http.server.request.duration(proved with an in-memoryManualReaderininternal/adapters/inbound/http/observability_test.go,cmd/mcp/router_otel_test.goandcmd/a2a/router_otel_test.go); the REST and reports routers also produce a server span named after the route pattern. - New metric names for the dashboard generator (Prometheus series in parentheses):
http.server.request.duration(http_server_request_duration_seconds), the Go runtime instruments ofcontrib/instrumentation/runtime, andreplenishment.request.raised(replenishment_request_raised_total). warehouse-infraand its dashboards are not touched by this change.- The only new test-environment obligation: integration tests that boot
run()setOTEL_SDK_DISABLED=trueso shutdown does not wait for a final flush to a Collector that is not there.