Skip to main content

Observability

Synced from warehouse-planning

This page is a copy of docs/docs/operations/observability.md on develop, derived from that repository's code. Edit it there, then re-sync.

Telemetry is pushed, not scraped. No binary serves a /metrics endpoint. All four binaries, cmd/api, cmd/mcp, cmd/planning-projector and cmd/planning-reports, call telemetry.Setup (internal/adapters/outbound/telemetry/telemetry.go, ADR 0011; the projector since ADR 0015). Setup installs a TracerProvider and a MeterProvider, both exporting over OTLP/gRPC without TLS to OTEL_EXPORTER_OTLP_ENDPOINT (default localhost:4317). Metrics are pushed every 30 s. The exporter connects lazily, so a missing Collector drops telemetry and never blocks boot. The projector logs telemetry configured with service_name, service_version, environment and otlp_endpoint at boot; it creates no spans and records no business metric, only the Go runtime metrics.

The global propagator is W3C traceparent plus baggage, so an incoming request's trace context continues into the server span.

Resource attributes​

AttributeValue
service.namewarehouse-planning (cmd/api), warehouse-planning-mcp (cmd/mcp), warehouse-planning-projector (cmd/planning-projector), warehouse-planning-reports (cmd/planning-reports)
service.versionSERVICE_VERSION, default dev
deployment.environment.nameENVIRONMENT, default local
SDK defaultstelemetry.sdk.* from resource.Default()

The chart renders OTEL_EXPORTER_OTLP_ENDPOINT (otel.endpoint, default otel-collector.observability.svc.cluster.local:4317, while otel.enabled), SERVICE_VERSION (image.tag) and ENVIRONMENT (environment, default local) on the api, mcp, projector and reports Deployments (ADR 0015), the same values as the sibling charts. warehouse-infra sets none of them for this service, so in the kind cluster every pod exports to the in-cluster Collector with the image tag as service.version.

Metric instruments​

InstrumentTypeUnitAttributesEmitted bySource
warehouse_planning.capacity_plans.createdInt64 counter{plan}outcome = created or rejectedevery CreateCapacityPlan attempt, through REST (cmd/api) or MCP (cmd/mcp). Every error counts as rejected: validation failures, a missing path, missing capacity, missing demand, and infrastructure failures as well.internal/adapters/outbound/telemetry/metrics.go, recorded in internal/application/usecases/create_capacity_plan.go
http.server.request.durationFloat64 histogramshttp.method, http.scheme, http.route (chi route pattern). No status-code attribute in otelchi v0.12.3. The service.name is set as an instrumentation-scope attribute.every request on the api, mcp and reports routersotelchimetric.NewServerRequestDuration in internal/adapters/inbound/http/process_capacity_handler.go, reports_handler.go, cmd/mcp/router.go
go.memory.used, go.memory.limit, go.memory.allocated, go.memory.allocations, go.memory.gc.goal, go.goroutine.count, go.processor.limit, go.config.gogcruntime gauges and countersper OTel Go semconvas defined by go.opentelemetry.io/contrib/instrumentation/runtime v0.71.0cmd/api, cmd/mcp, cmd/planning-projector, cmd/planning-reportsruntime.Start in telemetry.go

The histogram's bucket boundaries are 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5 and 10 s. In Prometheus, after the Collector's translation, the instruments appear as warehouse_planning_capacity_plans_created_total, http_server_request_duration_seconds_*, go_goroutine_count and go_memory_used_bytes.

There are no metrics for Kafka consumption, consumer lag, dead-lettering, outbox backlog, relay failures or Postgres. Watch those through logs, the database and the broker (see Suggested alerts).

Traces​

  • Server spans: otelchi.Middleware on the same three routers creates one span per request. With WithChiRoutes, the span name is the chi route pattern without the method, for example /capacity-plans/{id}/publications or /reports/shortage-trend. Spans carry http.route and the response http.status_code.
  • Trace context crosses the outbox (ADR 0014). postgres.OutboxRepo.Insert injects the request span's W3C context (traceparent, plus tracestate / baggage when present) into each row's outbox_events.headers, and the relay copies the stored headers onto the Kafka message. A consumer that extracts them continues the request's trace. Rows written without an active span (or before this change) carry only content-type. The in-memory outbox double used by unit tests does not inject; no shipped binary uses it.
  • Nothing else is traced. The Kafka consumers, the outbox relay, the use cases and the Postgres calls create no spans of their own; this service's consumers do not extract incoming trace headers because they open no span.

Logs​

Every binary writes JSON lines to stdout through log/slog (slog.NewJSONHandler). The level comes from LOG_LEVEL. Each line has time, level and msg. The common structured keys are:

KeyAppears on
errorevery failure line
topic, group_id, brokersconsumer and relay start lines (consumer running (with consumer = labor-capacity, storage-capacity, order-demand, inbound-demand or observed-capacity), analytics consumer running, outbox relay running)
partition, offset, attempt, max_attempts, retry_in... handling failed; retrying the same message and ... offset commit failed; retrying the same message
attempts... handling failed after the maximum attempts; dead-lettering the message
dlq_topicanalytics: dead-lettering a message that can never be projected
suppressed_since_last_warninganalytics: skipping message that is not a CloudEvents 1.0 event ... (at most one line a minute)
publisher, interval, max_attemptsoutbox relay running
outbox_id, topic, event_type, key, attempts, max_attempts, errorERROR outbox relay: row reached the attempt cap and is excluded from future claims; ..., logged once for the failure that reaches OUTBOX_MAX_ATTEMPTS (ADR 0013)
service_name, service_version, environment, otlp_endpointtelemetry configured (cmd/planning-projector)
dependency, errorWARN readiness: dependency is not ready (postgres, kafka, analytics-postgres)
op, attempt, in, errretrying and succeeded after retry from the boot retry (migrations, first ping)
migrations_pathpostgres adapters configured
site_idorder demand consumer running
drain_delayshutdown: readiness flipped to not-ready; waiting for traffic to drain
consumer, workerconsumer stopped, worker did not stop before the shutdown drain deadline

Log lines carry no trace_id or span_id: no code in this repo adds them.

Dashboards​

warehouse-infra provisions one Grafana dashboard for this context: terraform/dashboards/contexts/warehouse-planning.json (uid warehouse-warehouse-planning). It has these rows:

  • API Gateway (Kong): request rate by status code, 5xx ratio, and p95 request latency compared with upstream latency, from kong_* metrics on the httproute.warehouse-systems.warehouse-planning.* services.
  • Service HTTP RED: request rate by service_name and http_route, a 5xx panel, and p95 duration by service_name, from http_server_request_duration_seconds_* with service_name=~"warehouse-planning.*".
  • Business metrics: warehouse_planning_capacity_plans_created_total by outcome.
  • Go runtime: go_goroutine_count and go_memory_used_bytes.
  • Logs (Loki): the live stream for app="warehouse-planning" with the Istio containers excluded, volume by level, and ERROR or WARN only.

Three caveats, all visible in code:

  • The service 5xx panel filters on http_response_status_code or http_status_code. The histogram has neither attribute (see above), so that panel stays empty. Use the Kong 5xx panel instead.
  • The projector serves no HTTP route, so it never appears on the HTTP panels; it does appear on the Go runtime panels as warehouse-planning-projector since ADR 0015.
  • A panel description says that log lines embed trace_id and span_id. They do not in this service.

Suggested alerts​

These are built only from signals that exist today:

AlertSignalWhy
Outbox backlogSELECT count(*), min(created_at) FROM outbox_events WHERE published_at IS NULL rising, or max(attempts) growing with a last_errorThe relay is failing (broker down) and order-management is not seeing plans.
Outbox rows excluded by the attempt capSELECT count(*) FROM outbox_events WHERE published_at IS NULL AND attempts >= 20 (the OUTBOX_MAX_ATTEMPTS value) above 0, or the Loki ERROR line row reached the attempt capA poison row (or a long broker outage) was excluded; it is never retried until an operator re-arms it (Runbook).
DLQ growththe end offsets of warehouse.workforce.events.dlq, warehouse.facility.events.dlq, warehouse.order-management.events.dlq, warehouse.dock-scheduling.events.dlq, warehouse.fulfillment.events.dlq and warehouse.warehouse-planning.analytics.dlq increasingA message was given up on and nothing re-drives it.
Consumer lagkafka-consumer-groups.sh --describe for the seven groups (the six consumers of cmd/api and the projector)A wedged partition: the analytics consumer retries transient errors forever.
Analytics freshnessGET /reports/freshness lag_seconds above a thresholdThe projector is stuck or down (it has no metrics of its own).
Plan rejectionsrate(warehouse_planning_capacity_plans_created_total{outcome="rejected"}[15m]) as a share of all attemptsCallers send plans the invariants refuse, or capacity data or demand is missing.
Latencyp95 of http_server_request_duration_seconds by service_nameREST, MCP or reports slow-down.
Restarts and ERROR logspod restarts, plus the Loki level="ERROR" rateBoot-retry exhaustion, or a consumer that stopped.