ADR 0014: adopt the fleet observability standard
Status
Accepted (2026-11-14).
Context
Until this ADR the service had logs and health endpoints and nothing else (the
old docs/docs/operations/observability.md said so). Counted from the tree
before this change:
go.opentelemetry.io/otelandotel/sdkwere direct dependencies, but noTracerProvider,MeterProvideror exporter was created anywhere incmd/orinternal/; non-test code imported only the OTel API, ininternal/adapters/inbound/a2a/skills.go(onea2a.skill <name>span per skill call, which no provider exported).- No HTTP request metrics, no request log, no trace-correlated log line, no
business counter.
GET /metricsis a hand-written handler that writes one constant gauge (exception_management_up). - The chart had no
otel.*values and rendered none of the OpenTelemetry variables.
The fleet has a written standard for this: Tier 1 (identical everywhere:
telemetry.Setup to the Collector over OTLP/gRPC with runtime metrics, the
middleware order RequestID, otelchi, otelchimetric, RequestLogger,
Recoverer, /healthz) and Tier 2 (a naming and attribute convention for
business counters). The references are inventory-storage's ADR 0016 (the
WMS reference implementation) and wes-work-planning's ADR 0013, read from
their origin/develop. This service was the open gap.
Decision
Adopt the standard, with these local choices.
- One
telemetryadapter,internal/adapters/outbound/telemetry:Setup(telemetry.go) and the trace-correlating slog handlerWithTraceContext(slogotel.go) are copied verbatim from inventory-storage, tests included. An empty OTLP endpoint falls back toDefaultEndpoint(localhost:4317) and still installs real providers; export is lazy and non-blocking, so a missing Collector costs telemetry, never availability or boot. Nothing underinternal/domainorinternal/applicationimports the adapter. - One
cmd/*/telemetry.goper binary, for every one of the five binaries incmd/:api,mcp,a2a,exceptions-projector,exceptions-reports. There is no separate relay binary: the outbox relay runs insidecmd/api. Each readsOTEL_SERVICE_NAME(default per binary:exception-management,-mcp,-a2a,-projector,-reports),OTEL_EXPORTER_OTLP_ENDPOINT,SERVICE_VERSION, andSetupreadsENVIRONMENT. The loggers wrap their JSON handler withWithTraceContext. - HTTP middleware, in the standard order, on the REST router, the reports
router and the
cmd/mcpandcmd/a2arouters:RequestID,otelchi(server span named after the chi route pattern, never the raw path),otelchimetric.NewServerRequestDuration(http.server.request.duration, labelled withhttp.route),RequestLogger, then the panic recoverer. The REST and reports routers keep their ownrecoverPanicin the recoverer slot, because it answers the RFC 7807internal-errorproblem the contract documents; the MCP and A2A routers use chi'sRecoverer./healthzis unchanged.RequestLoggerlives in its own package,internal/adapters/inbound/requestlog, so thatcmd/mcpnever imports a path containinginbound/http(the fleet's MCP read-only rule; this repository's own fitness tests constraininternal/adapters/inbound/mcpand do not checkcmd/mcpimports, so the package split is the guard). It logs the route pattern, not the raw path, and skips/healthzand/readyz. The projector is not an HTTP server of business traffic (its admin port serves probes only), so it getsSetupand trace-correlated logs, no middleware. - Tier 2: one counter, on
OpenOrTouchException. That use case is the aggregate's primary command: every case opens from a consumed fact (ADR 0001;POST /exceptionsis a permanent 405), andOpenOrTouchExceptionis the only path that opens one. Triage, assignment and resolution act on a case that already exists, so they are secondary. The port isports.CaseMetrics; the implementation isinternal/adapters/outbound/telemetry.CaseMetrics; the use case calls it once perExecuteand a use case built without one records nothing (nil-safe no-op default).- Instrument:
exception.cases.opened, a counter, unit{case}. It follows<context>.<noun>.<verb>; the Prometheus series is expected to beexception_cases_opened_total. - Attributes:
outcomeisopened(a new case),touched(an existing case's occurrence went up),replayed(the opening event again, the idempotent no-op) orrejected.exception.severity(LOW,MEDIUM,HIGH,CRITICAL) is set on every decided case.reasonis set only onrejected, and is the problem slug:policy-undeclared,invalid-fact,concurrent-modification(the slug of the REST catalogue),open-case-exists,internal-error(also the REST slug). The consumer path has no HTTP problem catalogue of its own, so the slugs it needs beyond the REST ones are named here. - The attribute set is bounded: nothing identifying a case, a subject or a source type is an attribute.
- What is counted is the decision, at the end of
Execute. When the call runs inside an enclosing unit of work (the consumers wrap it inConsumeFact) that later fails to commit, the decision was already counted and its redelivery is counted again. The counter measures decisions taken, not commits.
- Instrument:
- Chart.
otel.enabled,otel.endpoint,otel.serviceNameandotel.serviceVersion, plusenvironment, renderENVIRONMENT,SERVICE_VERSION,OTEL_EXPORTER_OTLP_ENDPOINTandOTEL_SERVICE_NAMEon every Deployment that runs a binary (api, mcp, a2a, projector, reports; there is no CronJob).serviceVersiondefaults to empty and falls back toimage.tag, then the chart'sappVersion. TheextraEnvlist of every component refuses the four names.otel.enabled=falseonly stops the chart rendering the endpoint and the service name: the binaries then use their built-in defaults, so telemetry is dropped, not switched off in code.charts/exception-management/tests/render_test.shasserts all of it, scanscmd/*/telemetry.gofor the names the binaries read, and checks that every variable a component Deployment renders is documented indocs/docs/operations/configuration.md.
Deviations from the reference, and what was not done
- No trace propagation across Kafka. The reference stamps
traceparentandtracestateinto the outbox row where it is appended. Here theoutboxtable (migrations/0001_exception_management.up.sql) has the columnsid,event_id,aggreg_type,aggreg_id,payload,occurred_at,attempts,next_attempt_atandcreated_at: no headers column, andinternal/adapters/outbound/kafka/encoder.gobuilds only the content-type header at encode time. Carrying the trace context would need a schema migration, which this change does not add. A trace therefore ends at the outbox write; the inbound consumers start no span either. The CloudEvents encoder goldens are untouched. - The
http://literal innormalizeEndpointis kept as in the reference. No fitness test or lint rule in this repository rejects URL literals (internal/architectureandscripts/harness/repo_lint.pyhold none), so nonet/urlworkaround was needed. - No
otelchimetric.NewServerActiveRequests. ADR 0016 notes that inventory-storage's routers also add it; the Tier 1 baseline it defines, and this change, name only the duration histogram. GET /metricsis not touched. It is part of the REST contract (apis/openapi.yaml) and still writes only the presence gauge. The OpenTelemetry metrics travel over OTLP to the Collector, not through that route.golang.org/x/netis bumped to v0.62.0. The OTLP/gRPC dependencies pull an older one that thevulnjob flags;make vulnis part of this change's gates.
Consequences
- A request to the api, the reports reader, the MCP server or the A2A agent
produces an exported
http.server.request.durationand a server span, and its log line carries the sametrace_idandspan_id. An inboundtraceparentis honoured becauseSetupinstalls the W3C propagator. - Go runtime metrics come from every binary, the projector included.
- The
a2a.skill <name>spans that used to go nowhere are now exported. - Lines written without a span-carrying context (consumers, relay, sweeper,
projector) carry no
trace_idorspan_id. - The dashboards in
warehouse-infraare not part of this change; the metric names to build them from are in the observability page. - Cross-context correlation stays the CloudEvents
idchain until the outbox can carry headers.