Skip to main content

Observability

All five binaries call the same telemetry.Setup (internal/adapters/outbound/telemetry/telemetry.go): traces and metrics are pushed over OTLP/gRPC (insecure) to OTEL_EXPORTER_OTLP_ENDPOINT (default localhost:4317); there is no /metrics scrape endpoint in any binary. Exporters dial lazily, so with no Collector listening the data is dropped and export errors go to the log at debug — the service never fails or blocks because of telemetry. Metrics use the SDK's periodic reader; traces use a batching span processor.

Every signal carries the resource attributes service.name (OTEL_SERVICE_NAME; defaults wes-work-planning, wes-work-planning-mcp, wes-projector, wes-reports), service.version (SERVICE_VERSION) and deployment.environment.name (ENVIRONMENT). Propagation is W3C traceparent plus baggage, over HTTP and across Kafka headers.

In the kind cluster the Collector's Prometheus exporter turns instrument names into series names (dots become underscores, plus unit and _total suffixes — for example wes.work_units.released is queried as wes_work_units_released_total).

Metrics​

Service-owned instruments​

InstrumentTypeUnitAttributesEmitted bySource
wes.work_units.releasedInt64 counter{work_unit}path.idcmd/wes and cmd/mcp, once per work unit actually released by ReleaseNextWork (recorded in the use case after the commit, not in the handler) (ADR-0013)internal/adapters/outbound/telemetry/release_metrics.go
wes.outbox.lag_secondsFloat64 observable gauges—cmd/wes (the relay is always on). Age of the oldest unpublished outbox_events row, 0 when drained; sampled by a query at each collectioninternal/adapters/outbound/postgres/outbox_metrics.go

No circuit_breaker.state gauge is registered: no outbound client builds a breaker since the facility-layout travel-distance lookup was retired, so the breaker and its gauge were removed (ADR-0049).

Library instruments​

InstrumentTypeUnitAttributesEmitted byLibrary
http.server.request.durationFloat64 histogramshttp.method, http.scheme, http.route (chi pattern); scope attribute service.namecmd/wes, cmd/mcp, cmd/wes-reports (the projector's admin mux is not instrumented)github.com/riandyrn/otelchi/metric v0.12.3
http.server.active_requestsInt64 up-down counter—samesamesame
db.client.operation.durationhistogramsdb.system.name=postgresql, pgx.operation.typeevery binary with a Postgres poolgithub.com/exaring/otelpgx v0.12.0 (pool tracer)
db.client.operation.errorsInt64 counter—samesamesame
pgxpool.acquires, pgxpool.acquire_duration, pgxpool.acquired_connections, pgxpool.canceled_acquires, pgxpool.constructing_connections, pgxpool.empty_acquire, pgxpool.empty_acquire_wait_time, pgxpool.idle_connections, pgxpool.max_connections, pgxpool.max_idle_destroys, pgxpool.max_lifetime_destroys, pgxpool.new_connections, pgxpool.total_connectionsobservable counters/gauges—db.system.name, db.client.connection.pool.name (host:port/db)cmd/wes-projector and cmd/wes-reports only (analyticsstore.RecordPoolStats); the OLTP pool of cmd/wes/cmd/mcp registers no pool-stats instrumentsotelpgx.RecordStats
go.memory.used, go.memory.limit, go.memory.allocated, go.memory.allocations, go.memory.gc.goal, go.goroutine.count, go.processor.limit, go.config.gogcruntimevarious—all four binariesgo.opentelemetry.io/contrib/instrumentation/runtime v0.71.0

The http.route attribute is the chi route pattern (/paths/{pathId}/work-releases), never the raw path, so cardinality is bounded by the route table.

Traces​

Span nameKindWhereNotable attributes
chi route pattern, e.g. /paths/{pathId}/work-releases, /reports/throughput, /mcpserverotelchi middleware on the cmd/wes, cmd/wes-reports and cmd/mcp routersHTTP semconv
kafka.publish warehouse.work-planning.events, kafka.publish warehouse.wes.analyticsproducerPublisher.Publish / AnalyticsPublisher.Publish — direct publishing only (no DATABASE_URL)messaging.system=kafka, messaging.operation.name=publish, messaging.destination.name, messaging.batch.message_count, messaging.event_types
kafka.consume <topic>consumerintegration consumer (5 topics), ProductClassified consumer, pack-level consumer, analytics projectormessaging.kafka.offset, partition, messaging.message.id (CloudEvents id), cloudevents.event_type, cloudevents.event_source; product.sku on the classification consumer
mcp.tool <name>internalevery MCP tool callmcp.tool.name
query …, prepare …, batch query …, connect/acquireclientotelpgx tracer on every poolnormalized SQL, never parameter values

Trace context crosses Kafka in the message headers (internal/adapters/kafka/otelkafka). Under the outbox the headers are captured when the row is encoded inside the request's transaction, so a consumer's kafka.consume span continues the HTTP request (or consumer) span that produced the event; the relay's later send adds no span of its own. The headers live in outbox_events.headers (JSONB, [{"key","value"}]) until the relay copies them onto the Kafka message. Two integration tests pin this against real Postgres and Kafka (fleet gap fix D27): TestOutboxTrace_TraceparentCrossesTheOutboxToKafka (the request span's traceparent is stored on the row, arrives on the Kafka message, and a consumer extracting it parents on that span) and TestOutboxTrace_RowWithoutTraceHeadersRelaysUnchanged (a row stored without trace headers relays with none).

The process-path catalogue consumer (kafkacatalog) creates no spans.

Logs​

Every binary logs JSON to stdout through log/slog, at LOG_LEVEL. Records emitted inside a span carry trace_id and span_id (telemetry.NewTraceHandler). The OTel SDK's own diagnostics are bridged onto the same logger.

The per-request access log (internal/adapters/inbound/http/logging.go, cmd/wes and cmd/wes-reports; message http request, ERROR for 5xx, INFO otherwise) has these fields — captured from a real run:

{"time":"2026-10-12T14:02:56.3234-03:00","level":"INFO","msg":"http request","method":"POST","path":"/paths/pick-a/work-releases","route":"/paths/{pathId}/work-releases","status":200,"duration_ms":0,"bytes":168,"request_id":"host/Ae6N1jNENb-000008","trace_id":"9b39de83f1dd803926e4b1a52e44b03c","span_id":"fbf313e269e1bec3"}

path has CR/LF stripped (log-injection guard); request_id comes from chi's RequestID middleware. Events are published through the outbox; there is no log-only publisher, so domain event published lines no longer exist (ADR-0044).

Messages worth alerting or searching on:

MessageLevelMeaning
invalid CloudEvent, sending to dead-letter topicERRORa consumed message failed CloudEvents validation; fields topic, partition, offset, dlq_topic
exhausted retries, sending to dead-letter topicERRORa handler failed 3 times; fields id, type, attempts, error
kafka consumer stoppedERRORthe integration consumer's loop exited (a DLQ publish or commit failed) — nothing is consumed until restart
TaskCompleted for a work unit this context never planned; skippingINFOexpected for PACK tasks fulfillment-execution created itself
applying ProductClassified failed; retrying the same messageERRORthe classification consumer is stuck retrying one message
applying a pack level event failed; retrying the same messageERRORthe pack-level consumer is stuck retrying one message
pack level event is poison, sending to dead-letter topicERRORa ProductPackLevel* payload was invalid; fields topic, partition, offset, dlq_topic, error
skipping a message that is not a valid CloudEvent on the product-master topicWARNthe pack-level consumer committed past a non-CloudEvent
skipping invalid CloudEvent on product-master topic / ... on analytics topic / ... on process-path catalogue topicWARNpoison message skipped
analytics message handling failedERRORthe projector failed to apply an already-committed event (it is not retried)
outbox relay pass failedERRORrelay could not claim or send; rows stay unpublished
outbox relay: row reached the attempt cap and is no longer claimedERRORone row failed OUTBOX_MAX_ATTEMPTS sends and is excluded from claims (ADR-0039); fields outbox_id, topic, event_type, key, attempts, max_attempts, error. Alert on it: an event was not delivered
outbox relay configuredINFOboot: the relay's outbox_max_attempts
housekeeping sweep failed / housekeeping sweep removed rowsERROR / INFOretention sweeper outcome
retrying / succeeded after retryWARN / INFOboot-time dial retry (op = run migrations, ping postgres, connect to the process-path catalogue topic, ...)
kafka consumer did not stop before the shutdown deadline (and the same for outbox relay, product classification consumer)WARNdrain exceeded the 5 s shutdown budget
outbox lag gauge unavailableWARNan instrument could not be created; the service runs without it

Dashboard​

warehouse-infra ships a Grafana dashboard for this context, terraform/dashboards/contexts/wes-work-planning.json (uid warehouse-wes-work-planning, generated by scripts/gen-context-dashboards.py). Its rows:

  • API Gateway (Kong) — request rate, 5xx rate, p95 request vs upstream latency for the httproute.warehouse-systems.wes-work-planning.* service;
  • Service HTTP RED — request rate by route, 5xx by process and p95 by process from http_server_request_duration_seconds_*, filtered to service_name=~"wes-(work-planning|projector|reports).*";
  • Business metrics — wes_work_units_released_total;
  • Go runtime — goroutines and memory used;
  • Logs (Loki, app="wes-work-planning") — live stream, volume by level, errors and warnings.

The outbox lag and pgxpool instruments are exported but not on that dashboard.

Suggested alerts​

These are suggestions derived from the instruments above; none are provisioned in this repository.

AlertCondition (PromQL-style)Why
Outbox stuckwes_outbox_lag_seconds > 60 for 5 mrelay down, Kafka unreachable, or one row failing repeatedly (check outbox_events.last_error)
Outbox row deadany log line outbox relay: row reached the attempt cap and is no longer claimedan event was excluded after OUTBOX_MAX_ATTEMPTS failed sends and will not be delivered until re-armed (Runbook)
REST 5xx ratio5xx share of http_server_request_duration_seconds_count for service_name="wes-work-planning" > 1 % for 10 mPostgres/pool problems surface as internal-error
Release stalledrate(wes_work_units_released_total[15m]) == 0 while backlog exists (GET /paths/{pathId}/telemetry backlogDepth > 0)WIP limit reached, pool wedged, or no release caller
DLQ trafficany log line sending to dead-letter topic, or the <topic>.dlq end offset growingpoison or unprocessable upstream events
Report staleGET /reports/throughput/freshness lagSeconds > 30 (the freshness SLA)projector down or lagging
Consumer deadlog kafka consumer stoppedintegration consumption halted until the pod restarts