ADR 0011: Standard metrics adoption (otelchi + a Tier-2 business counter)
Status
Accepted (2026-10-05). Fixes a real gap found by the 2026-10-04
ADR-conformance audit: this service had no otelchi/otelchimetric and no
business-level metric, with go.opentelemetry.io/otel only an indirect
dependency.
Context
The fleet-standard-metrics convention (mirrored here from
process-path-management, the closest-sized reference) is two tiers:
- Tier 1 (automatic, per request):
otelchitraces +otelchimetric'shttp.server.request.durationhistogram on every HTTP router, installed as middleware ahead of anything else so later handlers already run inside a span. - Tier 2 (hand-written, per business outcome): one
metric.Int64Counterper meaningfully-countable business event, with anoutcomeattribute distinguishing success from failure on the SAME counter rather than two separately-named counters.
Neither tier existed in this service before this change.
Decision
internal/adapters/outbound/telemetryis the new outbound adapter (copied, per fleet convention, fromprocess-path-management's own package of the same name):Setupinstalls aTracerProvider+MeterProviderexporting OTLP/gRPC to an optional Collector (OTEL_EXPORTER_OTLP_ENDPOINT, defaultlocalhost:4317), non-blocking -- a missing Collector degrades to "telemetry dropped", never to "service won't start".cmd/api,cmd/mcpandcmd/planning-reportseach call it once at startup and defer the returned shutdown func.- Tier 1 is wired onto every HTTP router this service has: the main API
router (
internal/adapters/inbound/http.NewRouter), the reports router (NewReportsRouter) and the MCP router (cmd/mcp/router.go), each under its ownservice.name(warehouse-planning,warehouse-planning-reports,warehouse-planning-mcp) so the three binaries' spans/metrics are distinguishable.cmd/planning-projectorhas no HTTP router beyond its/healthz//readyzadmin mux (no business HTTP traffic to instrument) and is deliberately left out of this phase. - Tier 2:
warehouse_planning.capacity_plans.created(internal/adapters/outbound/telemetry.PlanMetrics, behindports.PlanMetrics), one counter with anoutcomeattribute (created/rejected), recorded byusecases.CreateCapacityPlan.Handlefor every attempt, wired into bothcmd/apiandcmd/mcp(the two composition roots that can create a plan).ports.PlanMetricsis nil-safe at both levels: a nil interface field is guarded inHandleitself (an interface method call on a nil interface panics, unlike a nil-receiver struct method), and*telemetry.PlanMetrics's own methods are additionally nil-receiver-safe, matchingprocess-path-management'sPathMetricsconvention.
Consequences
- A dashboard/alert can now be built on
capacity_plans.created{outcome=...}and on the automatichttp.server.request.durationhistograms across all three HTTP surfaces. cmd/planning-projectorremains uninstrumented beyond logs; a future change adding business HTTP traffic there should revisit this ADR.- Every behaviour-preserving caller (every pre-existing test) that does not
wire
ports.PlanMetricscontinues to work unchanged (the nil-safety point above).
Alternatives considered and rejected
- Two separately-named counters (
capacity_plans_created_total/capacity_plans_rejected_total): the fleet convention is one counter with an outcome attribute, so a query need not sum two series to answer "how many attempts". - A hand-rolled
httpconv/manual span wrapper instead ofotelchi: one sibling (fulfillment-execution) did this and the audit flagged it as a Tier-1 gap of its own;otelchi+otelchimetricis the convention this ADR adopts instead. - Instrument
cmd/planning-projector's admin mux too: it serves only/healthz//readyz, no business traffic; instrumenting liveness/readiness checks themselves would add noise, not insight.