Skip to main content

Observability

All four binaries push traces, metrics and logs over OTLP/gRPC to an OpenTelemetry Collector. Nothing is scraped and there is no /metrics endpoint. The setup lives in internal/adapters/outbound/telemetry (ADR-0012, ADR-0030).

Exporter configuration​

SettingValueSource
EndpointOTEL_EXPORTER_OTLP_ENDPOINT, default localhost:4317. The chart sets http://otel-collector.observability.svc.cluster.local:4317. A http(s):// scheme is stripped.telemetry.go
TransportgRPC, insecure (no TLS), 5s export timeout per attempttelemetry.go
Signalstraces (batch span processor), metrics (periodic reader, SDK default interval), logs (batch processor via the otelslog bridge)telemetry.go, slogotel.go
Resourceservice.name (OTEL_SERVICE_NAME), service.version (SERVICE_VERSION or ldflags), deployment.environment.name (ENVIRONMENT, default local), plus the SDK defaultstelemetry.go
PropagationW3C traceparent/tracestate plus baggagetelemetry.go
Collector downNon-blocking. Telemetry is dropped and export errors are logged at debug level only, so the service keeps running.telemetry.go

Service names default to facility-layout, facility-projector, facility-reports and facility-layout-mcp. The chart sets exactly these.

Metrics​

Service-defined​

InstrumentTypeUnitAttributesRecorded where
facility.location_slot.registrationsInt64Counter{registration}outcome = accepted | rejected_by_placement_rule | rejectedRegisterLocationSlot and ImportFacilityLayout use cases, once per slot attempt, so bulk-imported slots count the same as single POSTs (internal/adapters/outbound/telemetry/metrics.go, meter scope github.com/claudioed/facility-layout)

In Prometheus (through the Collector) this counter appears as facility_location_slot_registrations_total.

Library-provided​

InstrumentTypeEmitted byProcesses
http.server.request.duration (s)Float64Histogramotelchi v0.12.3 metric.NewServerRequestDuration. Attributes are http.method, http.scheme, http.route (chi pattern) and service.name, with no status-code attribute.facility, facility-projector (admin), facility-reports
http.server.active_requestsInt64UpDownCounterotelchi metric.NewServerActiveRequestssame
db.client.operation.duration (s)Histogramotelpgx v0.12.0 tracer, buckets 1ms–10sfacility, mcp (OLTP pool only)
db.client.operation.errorsInt64Counterotelpgx tracerfacility, mcp
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_connectionsasync gauges/countersotelpgx.RecordStats in postgres.NewPoolfacility, mcp
go.memory.used, go.memory.limit, go.memory.allocated, go.memory.allocations, go.memory.gc.goal, go.goroutine.count, go.processor.limit, go.config.gogcruntimego.opentelemetry.io/contrib/instrumentation/runtime v0.71.0all four

The MCP binary's router is a plain chi router without otelchi, so it emits no HTTP server metrics. The analytical pools (analyticsstore.NewPool, NewReadOnlyPool) are not instrumented with otelpgx.

The service defines no metric for outbox backlog, relay failures or consumer lag. Watch those through SQL, logs and broker-side lag (see the alerts below).

Traces​

SpanOriginNotes
Route pattern, e.g. GET /sites/{siteCode}/layoutotelchi with WithChiRoutesOne server span per HTTP request in facility, facility-reports and the projector admin server. The route pattern keeps span-name cardinality bounded.
query <normalized SQL> (also prepare, batch query, connection acquire)otelpgx (WithQuerySpanNamePrefix)Child spans of the request or use case. Statements are normalized, without literal values.
mcp.tool <tool-name>internal/adapters/inbound/mcp/tools.goOne span per tool call with attribute mcp.tool.name. Status is Error with the slug-prefixed message (ADR-0033).

Kafka trace propagation:

  • Direct publishing no longer exists (ADR 0039). Every event goes through the outbox:
  • Outbox mode stores the writing transaction's W3C trace context (traceparent, tracestate, baggage) in outbox_events.headers (migration 0010), and the relay sends it as Kafka headers next to the CloudEvents content-type (ADR-0038). A consumer that extracts the headers parents its span on the originating request. The relay never injects its own context. Rows written with no active span, or before migration 0010, have headers NULL and relay with content-type only. Check one row with SELECT id, event_type, headers FROM outbox_events ORDER BY id DESC LIMIT 5;.
  • The analytics consumer never extracts trace context and starts no spans, so projector work is not traced.

Logs​

Logs are JSON on stdout (slog.NewJSONHandler) and are fanned out to the OTel log bridge. Inside a span, every record also gets trace_id and span_id. The level comes from LOG_LEVEL.

MessageLevelFieldsEmitted by
http requestinfo, or error when status ≥ 500method, path (sanitized), status, duration_ms, bytes, request_idfacility, facility-reports (RequestLogger)
telemetry configuredinfoservice_name, service_version, environment, otlp_endpointfacility
event publisher configuredinfopublisher (kafka), mode (outbox), integration_topic, analytics_topic, brokersfacility
retrying / succeeded after retrywarn / infoop, attempt, in, errboot retry, all binaries
outbox relay pass failederrorerrorfacility
outbox relay: row reached the attempt cap and is excluded from future claims; ...erroroutbox_id, topic, event_type, key, attempts, max_attempts, errorfacility relay, once per row when it reaches OUTBOX_MAX_ATTEMPTS (ADR-0036)
invalid integer env var, using defaultwarnkey, value, default, errorfacility, at boot, when OUTBOX_MAX_ATTEMPTS is malformed or negative
outbox relay published eventsdebugcountfacility
housekeeping sweep / housekeeping sweep failedinfo / erroridempotency_keys_deleted, outbox_events_deleted, errorfacility
site capability heartbeat / site capability heartbeat failed / site capability heartbeat disabledinfo / error / infopublished, skipped, error, envfacility (ADR-0041)
analytics consumer startinginfotopic, group, brokersfacility-projector
analytics: exhausted retries, sending to dead-letter topicerrortopic, dlq_topic, attempts, errorfacility-projector
analytics: message is not a valid CloudEvent, sending to dead-letter topicwarntopic, partition, offset, errorfacility-projector
analytics consumer stoppederrorerrorfacility-projector (the consume loop has ended)
catalog-growth report tool wiredinforeports_base_urlmcp

Dashboards​

warehouse-infra provisions a Grafana dashboard "Warehouse — Facility Layout" (terraform/dashboards/contexts/facility-layout.json, generated by scripts/gen-context-dashboards.py). It has these rows:

  • Kong north-south (request rate, 5xx rate, p95 latency);
  • service HTTP RED by process (OLTP, projector, reports, MCP);
  • business metrics (facility_location_slot_registrations_total);
  • Go runtime (goroutines, memory used);
  • logs (live stream, volume by level, errors and warnings).

This repo contains no dashboard of its own.

Suggested alerts​

AlertSignalWhy
Outbox backlog growingSELECT count(*) FROM outbox_events WHERE published_at IS NULL above 0 for more than 5 min, or repeated outbox relay pass failed logsThe relay cannot reach Kafka. Events are safe but downstream consumers (inventory-storage, warehouse-planning) are going stale.
Outbox row excluded by the attempt capany ERROR outbox relay: row reached the attempt cap ..., or SELECT count(*) FROM outbox_events WHERE published_at IS NULL AND attempts >= 20 above 0A row failed OUTBOX_MAX_ATTEMPTS sends and downstream contexts will never get that event until it is re-armed (Runbook, ADR-0036).
Projector stoppedlog analytics consumer stopped, or broker-side lag of group facility-analytics risingThe consume loop does not restart by itself. The pod needs a restart.
DLQ receiving messagesany new message on warehouse.facility.analytics.dlqA poison or invalid CloudEvent: investigate the x-dlq-error header.
Report freshnessGET /reports/catalog-growth/freshness lagSeconds above the expected write cadenceThe read model is behind the OLTP writes.
Placement-rule rejections spikerate(facility_location_slot_registrations_total{outcome="rejected_by_placement_rule"}[15m])A bad import or a misconfigured placement rule.
HTTP 5xxhttp.server.request.duration count filtered by error logs (the metric has no status attribute) or Kong 5xxUse Kong's status-coded metrics for rates.
Crash-looping bootpod restarts with (after 5 attempts) in the last log lineDatabase unreachable or a migration failure. See Troubleshooting.