Skip to main content

Observability

All four binaries call the same telemetry.Setup (internal/adapters/outbound/telemetry/telemetry.go): traces and metrics are pushed over OTLP/gRPC to OTEL_EXPORTER_OTLP_ENDPOINT (default localhost:4317; in the cluster the chart points it at otel-collector.observability.svc.cluster.local:4317). There is no /metrics endpoint and no Prometheus registry in the process: Prometheus names such as inventory_reservations_total exist only after the collector converts the OTLP stream. Metrics are exported every 15 s; export failures are logged at DEBUG and never affect requests. Propagation is W3C traceparent + baggage.

Every signal carries the resource attributes service.name (OTEL_SERVICE_NAME), service.version (SERVICE_VERSION) and deployment.environment.name (ENVIRONMENT).

Source: internal/adapters/outbound/telemetry/telemetry.go, charts/inventory-storage/values.yaml (otel.endpoint).

Metrics​

Application instruments​

Meter github.com/claudioed/inventory-storage (ADR 0016).

InstrumentTypeUnitAttributesEmitted byMeaning
inventory.reservationsInt64 counter{reservation}outcome = created | revokedcmd/inventory (ReserveStock, RevokeReservation), cmd/mcp (revoke_reservation)Reservations made against usable inventory and revoked. Source: internal/adapters/outbound/telemetry/metrics.go.
inventory.pick_confirmationsInt64 counter{reservation}outcome = confirmed | expired | already_picked | revokedcmd/inventory, TaskCompleted consumerReservations settled by a completed PICK task. Source: pick_metrics.go.
inventory.inbound_receipt_unitsInt64 counter{unit}outcome = booked | heldcmd/inventory, inbound-receipt consumerUnits on ReceiptLineReceived lines, booked (Good) or held out of usable stock (Damaged, ADR 0052). Source: inbound_receipt_metrics.go.
inventory.held_unitsInt64 up-down counter{unit}reason = DAMAGED | QC_PENDING | SUSPECT | OTHERcmd/inventory, inbound-receipt consumer and disposition endpointUnits currently held out of usable stock: + on a hold, - when a RELEASE, RETURN_TO_VENDOR or SCRAP settles it (a REWORK moves units between reasons). Moved only after the transaction commits. Source: held_stock_metrics.go.
circuit_breaker.stateInt64 gauge{state}dependency = facility-layoutcmd/inventory with LOCATION_LOOKUP_MODE=http0 closed, 1 half-open, 2 open; recorded on every state change. Source: circuit_breaker_metrics.go.

Library instruments​

InstrumentType / unitAttributesEmitted by
http.server.request.durationFloat64 histogram, s (buckets 5 ms … 10 s)http.method, http.scheme, http.route (chi pattern). No status-code attribute in otelchi v0.12.3.cmd/inventory, cmd/inventory-reports, cmd/mcp (otelchi)
http.server.active_requestsInt64 up-down countersamecmd/inventory-reports, cmd/mcp only (the OLTP router does not register it)
pgxpool.acquires, pgxpool.acquire_duration (ns), pgxpool.acquired_connections, pgxpool.idle_connections, pgxpool.total_connections, pgxpool.max_connections, pgxpool.empty_acquire, pgxpool.empty_acquire_wait_time (ns), pgxpool.canceled_acquires, pgxpool.constructing_connections, pgxpool.new_connections, pgxpool.max_idle_destroys, pgxpool.max_lifetime_destroysobservable counters / gaugesdb.system.name, db.client.connection.pool.name (host:port/db)cmd/inventory-projector and cmd/inventory-reports only (analyticsstore.RecordPoolStats); the OLTP pool records traces but no pool metrics
go.memory.used, go.memory.limit, go.memory.allocated, go.memory.allocations, go.memory.gc.goal, go.goroutine.count, go.processor.limit, go.config.gogc, go.schedule.durationruntime—all four (go.opentelemetry.io/contrib/instrumentation/runtime v0.71.0)

The projector's admin server is a plain net/http mux: it emits no HTTP metrics or spans.

Traces​

Span nameKindWhereNotes
chi route pattern, e.g. /reservations/{id}servercmd/inventory, cmd/inventory-reports, cmd/mcp (otelchi)One per HTTP request; MCP requests appear under /mcp or /*.
mcp.tool <tool name>internalcmd/mcp (internal/adapters/inbound/mcp/tools.go)Attribute mcp.tool.name; status Error when the tool returns an error.
kafka.publish warehouse.inventory.eventsproducerdirect (no-outbox) integration publishAttributes messaging.system=kafka, messaging.destination.name, messaging.operation.name=publish, messaging.message.event_type.
kafka.publish warehouse.inventory.analyticsproducerdirect analytics publishSame messaging attributes.
kafka.consume warehouse.inventory.analyticsconsumercmd/inventory-projectorParent extracted from the message's W3C headers.
query <operation>, batch query …, connect, …clientevery pgx pool (otelpgx v0.12.0)One per SQL statement.

With the transactional outbox, the trace headers written into outbox_events.headers are those of the span active when the use case committed, so downstream consumers parent onto the originating HTTP request even though the relay sends the message later.

Logs​

Every binary logs JSON to stdout through log/slog (level from LOG_LEVEL). Common fields: time, level, msg, plus trace_id and span_id whenever the record is written with a span on the context (internal/adapters/outbound/telemetry/slogotel.go).

MessageFieldsSource
http request (INFO; ERROR for 5xx)method, path, status, duration_ms, bytes, request_id (chi X-Request-Id)internal/adapters/inbound/http/logging.go (API and reports)
event publisher configuredpublisher, integration_topic, analytics_topic, brokersstartup (publisher is always the transactional outbox + relay)
outbox relay: send failed, stopping this pass at the failed row (WARN)outbox_id, topic, attempts, errorrelay
outbox relay: row reached the attempt cap and is excluded from future claims; ... (ERROR)outbox_id, topic, event_type, key, attempts, max_attempts, errorrelay, once per row when it reaches OUTBOX_MAX_ATTEMPTS (ADR 0038)
outbox relay startedinterval, max_attemptscmd/inventory/adapters.go
retrying (WARN) / succeeded after retryop, attempt, in, errbootretry
... consumer configuredtopic, consumer_group, reasoneach consumer at startup (all four always start)
... retrying same message (WARN), ... dead-lettering ... (ERROR), skipping ... not a valid CloudEvent (WARN, sampled for TaskCompleted)error, attempt, partition, offsetKafka consumers
facility location cache is ready / ... ready but EMPTY ... (WARN)slots, zones, topiccmd/inventory/lookup.go
... consumer stopped (ERROR)errora consumer returned without a shutdown signal; the process then exits non-zero (ADR 0042)
readiness: dependency is not ready (WARN)dependency (postgres / kafka), error/readyz check
housekeeping sweeper startedinterval, idempotency_key_ttl, outbox_retention, order_pick_progress_retentioncmd/inventory/housekeeping.go

Dashboards​

warehouse-infra provisions Warehouse — Inventory & Storage (uid warehouse-inventory-storage) from terraform/dashboards/contexts/inventory-storage.json. Rows: Kong request rate / 5xx ratio / p95 for the httproute.warehouse-systems.inventory-storage.* route; service HTTP RED by service_name and http_route; the inventory_reservations_total rate by outcome; Go runtime goroutines and memory; Loki log stream, volume by level, and errors/warnings.

Its per-process 5xx panel filters on http_response_status_code / http_status_code, which otelchi v0.12.3 never sets, so that panel stays empty; use the Kong 5xx panel or the http request log lines with status >= 500 instead.

Suggested alerts​

AlertSignalWhy
Outbox backlogSELECT count(*), min(created_at) FROM outbox_events WHERE published_at IS NULL growing for > 5 minRelay is stuck on a failing row (no metric exists for this; query the DB).
Outbox row excludedany ERROR outbox relay: row reached the attempt cap ... (log alert), or SELECT count(*) FROM outbox_events WHERE published_at IS NULL AND attempts >= 20 > 0An event that consumers never received; re-arm it after fixing the cause (Runbook).
facility-layout breaker opencircuit_breaker_state{dependency="facility-layout"} == 2 for > 1 minStows fall back to permissive (fail-open) classification.
DLQ trafficany new message on warehouse.fulfillment.events.dlq or warehouse.facility.events.dlqEach one is a pick confirmation or a location fact that was not applied.
Consumer laglag of groups inventory-storage-confirm-pick, inventory-storage-transfer-allocation, inventory-analytics and the configured product-master / inbound-receipt groupsThose consumers retry a failing message in place; lag is the only symptom.
Analytics freshnessGET /reports/flow-accuracy/freshness → lagSeconds above an agreed boundProjector down or behind.
Pick confirmations expiringrate of inventory_pick_confirmations_total{outcome="expired"}Picks completing after their reservation expired; stock was already returned to usable.
Damaged receiptsrate of inventory_inbound_receipt_units_total{outcome="held"}Inbound quality signal.
Held stock ageinginventory_held_units by reason staying above zeroDamaged or suspect units waiting for a disposition.
HTTP latencyp95 of http_server_request_duration_seconds by http_routeNote: the OLTP pool's statement_timeout is 5 s.