Skip to main content

Observability

The service exports metrics and traces over OTLP/gRPC to the OpenTelemetry Collector and writes trace-correlated JSON logs, following the fleet observability standard (ADR 0013). It serves no /metrics endpoint: the Collector re-publishes the metrics for Prometheus. All five binaries (cmd/api, cmd/mcp, cmd/a2a, cmd/pfr-projector, cmd/pfr-reports) start telemetry.Setup from their own telemetry.go; export is lazy and non-blocking, so an unreachable Collector costs telemetry and never availability.

Configuration​

VariableDefaultMeaning
OTEL_EXPORTER_OTLP_ENDPOINTlocalhost:4317Collector OTLP/gRPC endpoint, host:port or a URL. Chart: otel.endpoint, default otel-collector.observability.svc.cluster.local:4317
OTEL_SERVICE_NAMEpick-face-replenishment (api), -mcp, -a2a, -projector, -reportsservice.name of the spans and metrics. Chart: otel.serviceName for the api, <otel.serviceName>-<component> for the others
SERVICE_VERSIONdevservice.version. Chart: otel.serviceVersion, empty falls back to image.tag, then the chart appVersion
ENVIRONMENTlocaldeployment.environment.name. Chart: environment

The chart renders these four into every Deployment that runs a Go binary while otel.enabled is true (the default) and refuses them in any extraEnv list. Integration tests that boot a binary set OTEL_SDK_DISABLED=true.

Metrics​

InstrumentType, unitAttributesEmitted by
http.server.request.duration (http_server_request_duration_seconds)histogram, shttp.route is the chi route pattern (asserted by the router tests); the other attributes are otelchimetric's defaultscmd/api, cmd/pfr-reports, cmd/mcp, cmd/a2a
Go runtime instruments of go.opentelemetry.io/contrib/instrumentation/runtimegauges and countersall five binaries
replenishment.request.raised (replenishment_request_raised_total)counter, {request}outcome (created, failed); reason on failure: the problem slug, e.g. replenishment-already-open, concurrent-modification, quantity-exceeds-max, no-source-stock, invalid-quantity, internal-errorcmd/api

replenishment.request.raised counts every attempt to plan a request, from the evaluation sweep, the event consumers and the manual request alike (all three go through one function of the use-case layer). It does not count refusals that happen before a request is planned (no-policy, nothing-to-replenish, no-forward-assignment) or detections that raise nothing, and the count is taken inside the unit of work, so a failed final commit is not told apart from created.

warehouse-infra ships a Grafana dashboard (terraform/dashboards/contexts/pick-face-replenishment.json) and Kong-based alert rules (5xx ratio, availability and latency SLO burn, container restarts). This change does not touch them; whether their http_server_request_duration_seconds and Go runtime panels now fill was not checked in a cluster.

Traces​

cmd/api, cmd/pfr-reports, cmd/mcp and cmd/a2a create one server span per request (otelchi), named after the chi route pattern, so there is one span name per route and not one per site id. cmd/pfr-projector has no HTTP API and creates no spans of its own.

The outbox stores a traceparent (and tracestate, baggage when present) in the headers of each row that is written while the request context carries a span (traceHeaders in internal/adapters/outbound/postgres/outbox_repository.go), and the relay copies it onto the Kafka message. telemetry.Setup installs the W3C propagator that code reads, so the headers are stored for writes that arrive over the REST API. Rows raised by an event consumer carry no traceparent: the Kafka consumers do not extract a trace context from the incoming message (not evidenced in internal/adapters/inbound/kafka).

Logs​

JSON, one object per line on stdout, via log/slog (time, level, msg plus the attributes below). LOG_LEVEL selects the threshold. A record written with a request or span context also carries trace_id and span_id, so a log line can be joined to its trace; records written without one (boot, shutdown, workers) are unchanged.

Boot and lifecycle​

LevelmsgAttributesMeaning
INFOkafka topics (informational; the broker auto-creates them on first write, the service never creates them through an admin API)topics consumed and producedlogged at boot; topics play no part in /readyz
INFOpostgres adapters configuredmigrations ran and the pool pinged
WARNretryingop (run migrations, ping postgres), attempt, in, errboot retry, backoff 1 s doubling
INFOsucceeded after retryop, attempta retried boot step worked
ERRORservice exited with errorerrorboot refused (migration or ping failure, bad consumer configuration) or the listener failed
INFOhttp server listeningaddrthe listener is up (the pod turns ready)
INFOshutdown: readiness flipped to not-ready; waiting for traffic to draindrain_delaySIGINT or SIGTERM received
WARNworker did not stop before the shutdown drain deadlineworker (INVENTORY_MODE, SLOTTING_MODE, LAYOUT_MODE, outbox-relay)a worker ignored the 10 s stop bound
WARNinvalid OUTBOX_RELAY_INTERVAL; using the default, invalid OUTBOX_MAX_ATTEMPTS; using the default, ignoring invalid SHUTDOWN_DRAIN_DELAYvalue, defaulta malformed setting was replaced by its default

Outbox relay​

LevelmsgAttributesMeaning
INFOoutbox relay runninginterval, max_attempts, brokersrelay started (it always runs; a missing DATABASE_URL or KAFKA_BROKERS is a boot error)
ERRORoutbox relay pass failederrora Kafka or database error; retried after the interval
ERRORoutbox relay: row reached the attempt cap and is excluded from future claims; re-arm it with attempts = 0 after fixing the causeoutbox_id, topic, event_type, key, attempts, max_attempts, errorone row will not be retried until re-armed
ERRORoutbox relay stopped, kafka relay sink close failederrorthe relay ended abnormally

Consumers​

LevelmsgAttributesMeaning
INFOconsumer runningconsumer (inventory consumer, slotting consumer, layout consumer), topic, group_id, brokersstarted (all three always run)
INFOevent processedtype, event_id, subject, outcome (applied, duplicate, stale, ignored)one message handled
WARNskipping a message that is not a valid CloudEventconsumer, topic, errorcommitted past, never retried
WARNdead-lettering an event that can never be appliedconsumer, type, event_id, errorpoison payload
ERRORkafka reader error; retryingconsumer, topic, detailkafka-go is retrying a group join: the broker is unreachable or the consumed topic does not exist yet (its producer has not written). Not a readiness failure; the consumer recovers by itself
ERROR<consumer> handling failed; retrying the same messageerror, partition, offset, attempt, max_attempts, retry_intransient failure, logged on every attempt
ERROR<consumer> handling failed after the maximum attempts; dead-lettering the messageerror, partition, offset, attemptsmoved to the .dlq topic
ERROR<consumer> message can never be applied; dead-lettering it without retryerror, partition, offsetpoison, immediate
ERROR<consumer> dead-letter publish failed; retrying the same message, <consumer> offset commit failed; retrying the same messageerror, partition, offset, attempt, retry_inthe partition is blocked until it succeeds
ERRORconsumer stopped, consumer close failedconsumer, errorthe loop ended with an error

HTTP​

LevelmsgAttributesMeaning
INFO, WARN (4xx), ERROR (5xx)http requestmethod, route (the chi pattern), status, duration_ms, bytes, request_id, plus trace_id, span_idone record per request on cmd/api and cmd/pfr-reports; /healthz and /readyz are not logged
ERRORrequest failederror, method, pathan unmapped error became a 500 internal-error (the response never carries the internal message)
ERRORhandler panickedpanic, method, patha recovered panic became a 500
WARNidempotency: answer not storederrora 4xx answer could not be stored for replay; it was still sent

A domain rejection (4xx) is logged only by the http request record at WARN (status and route, not the reason); the reason is in the response body.

Health endpoints​

EndpointHealthyUnhealthy
GET /healthz200 {"status":"ok"}the process is gone
GET /readyz200 {"status":"ready"}503 {"status":"not_ready"} after shutdown began; 503 dependency-unavailable while Postgres or the Kafka broker is unreachable (topics are not checked)

/healthz checks neither Postgres nor Kafka; /readyz checks Postgres and that a Kafka broker answers, never topics (Runbook).

Suggested alerts​

warehouse-infra has only the Kong-level alerts named above (5xx ratio, SLO burn, restarts). Beyond the instruments above, the backlog and lag signals below are not exported as metrics, so they are checks against the data stores and logs rather than PromQL (the replenishment_request_raised_total{outcome="failed"} ratio and the request-duration histogram are PromQL signals once a Collector scrape exists):

SignalQuery or sourceWhy
Outbox backlogSELECT count(*), min(created_at) FROM outbox_events WHERE published_at IS NULL older than a few minutesthe relay is off, the broker is down or a row is stuck
Stuck outbox rowSELECT id, attempts, last_error FROM outbox_events WHERE published_at IS NULL AND attempts > 0 or the log line row reached the attempt capone event is blocked behind a persistent failure
Consumer lagKafka consumer-group lag of the three groups on their topicsa blocked partition or a stopped consumer
Dead lettersmessage count growth on the three .dlq topics, log lines dead-letteringproducers sending unusable payloads
Consumer stoppedlog consumer stopped or outbox relay stoppedthe loop ended and is not restarted
Server errorslog lines request failed and handler panickedevery 5xx is logged once
Boot loopsrepeated service exited with error / retryingdatabase unreachable or a bad migration
Open-request ageSELECT min(requested_at) FROM replenishment_requests WHERE state = 'Requested'requests that never complete (the chain is built end to end but not live; wes-work-planning plans nothing unless REPLENISHMENT_MODE=kafka is set there and the REPLENISH path is seeded, see Integration)

An outbox backlog gauge and consumer outcome counters are not instrumented (not evidenced in internal/); adding them would be a code change.