Skip to main content

Observability

Synced from network-inventory-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.

What exports telemetry​

Only the API binary (cmd/network-inventory-planning) sets up OpenTelemetry (telemetry.Setup, ADR 0012). It pushes traces and metrics over OTLP/gRPC (insecure) to OTEL_EXPORTER_OTLP_ENDPOINT (default localhost:4317; the chart sets otel-collector.observability.svc.cluster.local:4317). There is no /metrics scrape endpoint. Metrics are exported every 30s. Export never blocks: with no Collector listening, telemetry is dropped and the service runs normally.

mcp, nip-projector and nip-reports do not initialise OpenTelemetry: they emit structured logs only.

Resource attributes on every span and metric (internal/adapters/outbound/telemetry/telemetry.go):

AttributeValue
service.namenetwork-inventory-planning
service.versionSERVICE_VERSION (default dev; the chart sets the image tag)
deployment.environment.nameENVIRONMENT (default local)

Metrics​

NIP defines no custom instruments. Everything comes from two libraries, checked in the module cache at the versions pinned in go.mod:

HTTP server (otelhttp v0.70.0, wrapping Handler.Routes)​

InstrumentTypeUnitAttributes
http.server.request.durationhistogramshttp.request.method, http.route (the ServeMux pattern, e.g. /v1/transfers/{id}), http.response.status_code, network.protocol.name, network.protocol.version, server.address, url.scheme
http.server.request.body.sizehistogramBysame
http.server.response.body.sizehistogramBysame

internal/adapters/inbound/http/otel_metrics_test.go pins that http.server.request.duration carries http.route. In Prometheus these appear as http_server_request_duration_seconds_* with service_name and http_route labels.

Go runtime (contrib/instrumentation/runtime v0.72.0, runtime.Start)​

InstrumentTypeUnit
go.memory.usedup-down counter (attribute go.memory.type)By
go.memory.limitup-down counterBy
go.memory.allocatedcounterBy
go.memory.allocationscounter{allocation}
go.memory.gc.goalup-down counterBy
go.goroutine.countup-down counter{goroutine}
go.processor.limitup-down counter{thread}
go.config.gogcup-down counter%

Signals that are not metrics​

Saga health is published as events, not metrics, and reaches dashboards through the analytics read side:

QuestionWhere to look
How many transfers reached each state per day?GET /reports/transfer-funnel
How long do transfers dwell in each state (p50/p95)?GET /reports/state-dwell
Which transfers are stuck?GET /reports/stuck-transfers, MCP find_stuck_transfers
Do scheduled rebalances fail closed?GET /reports/rebalance-runs, GET /v1/rebalance-runs
Is the projection behind?GET /reports/freshness (lag_seconds)
Is the outbox draining?SELECT count(*) FROM outbox_events WHERE published_at IS NULL;

Traces​

  • Server spans: otelhttp starts one span per request, named <METHOD> <route> once the ServeMux pattern is known (for example POST /v1/transfer-approvals).
  • Propagation through Kafka: the global propagator is W3C Trace Context + Baggage. The encoders inject traceparent/tracestate from the active context into each outbox row's headers (tracedHeaders, internal/adapters/outbound/kafka/publisher.go), and the relay forwards them verbatim, so an approval's TransferAllocationRequested carries the trace of the HTTP request even though it is sent later. Every consumer extracts the headers into the handler context (internal/adapters/inbound/kafka/kafka.go), so events NIP writes while handling a consumed message carry the upstream trace. The integration tests TestOutboxTrace_TraceparentCrossesTheOutboxToKafka and TestOutboxTrace_RowWithoutTraceHeadersRelaysUnchanged (internal/adapters/inbound/kafka/kafka_integration/outbox_trace_integration_test.go) pin this across the outbox against a real Postgres and Kafka; a row without stored trace headers relays with none.
  • No spans are started for Kafka produce or consume, Postgres queries or the tickers; ticker-written rows carry no traceparent.

Logs​

The API logs with Go's default slog logger (text to stderr). mcp, nip-projector and nip-reports log JSON to stdout at LOG_LEVEL.

Message (substring)LevelFieldsMeaning
DATABASE_URL unset: running without read modelsINFOenable_withDiagnostic mode.
KAFKA_BROKERS not configured; outbox disabledWARNenable_withApproval answers 503.
work release not configured; POST /v1/transfer-approvals answers 503WARNerror, enable_withPick path or offset missing.
consumer running / consumer disabledINFOname, group_id, brokersOne line per consumer at boot.
outbox relay runningINFOtopic, brokers, max_attemptsRelay started.
outbox relay: send failed, stopping this pass at the failed rowWARNoutbox_id, topic, attempts, errorOne failed send below the attempt cap; the next tick retries the row.
outbox relay: row reached the attempt cap and is excluded from future claimsERRORoutbox_id, topic, event_type, key, attempts, max_attempts, errorLogged once, for the failure that reaches OUTBOX_MAX_ATTEMPTS; the row is no longer claimed until re-armed (ADR 0016).
invalid OUTBOX_MAX_ATTEMPTS; using the defaultWARNvalue, default, errorA negative or unparsable cap; 20 is used.
saga health check running / disabledINFO / WARN / ERRORinterval, thresholds_env, errorTicker state at boot.
scheduled rebalance running / disabledINFO / WARN / ERRORinterval, enable_withTicker state at boot.
<consumer> handling failed; retrying the same messageERRORerror, partition, offset, attempt, retry_inA transient failure blocking a partition.
skipping ... (for example skipping deterministic allocation-reply failure)WARNerror, event_id, transfer_idA message committed past without effect.
skipping SiteSkuDemandChanged older than the stored demandINFOevent_id, source_order_id, line_no, occurred_atAn older demand fact was a no-op (ADR 0014).
analytics: dead-lettering a message that can never be projectedERRORerror, dlq_topic, partition, offsetProjector DLQ write.
transfer-reply-consumer: dead-lettering a message that can never be applied / transfer-fact-consumer: ...ERRORerror, dlq_topic, source_topic, partition, offsetA poison reply or fact written to <topic>.dlq and committed past (ADR 0013).
analytics: skipping message that is not a CloudEvents 1.0 eventWARNtopic, partition, offset, suppressed_since_last_warningSampled once per minute.
retrying / succeeded after retryWARN / INFOop, attempt, in, errBoot retry of the analytics binaries.
mcp tool failed with an unexpected errorERRORerrorAn untyped error behind an internal-error tool result.

Dashboards​

warehouse-infra provisions a Grafana dashboard for this context, terraform/dashboards/contexts/network-inventory-planning.json ("Warehouse — Network Inventory Planning"). Its panels: Kong request rate, 5xx rate and p95 latency for the context's HTTPRoute; request rate by route, 5xx rate and p95 duration from http_server_request_duration_seconds{service_name=~"network-inventory-planning.*"}; goroutines (go_goroutine_count) and memory (go_memory_used_bytes); and Loki log panels for {app="network-inventory-planning"} (live stream, volume by level, errors and warnings). The "Service HTTP RED" row names the projector, reports and MCP processes too, but only the API exports metrics today.

Suggested alerts​

AlertExpression / checkWhy
API 5xx ratiosum(rate(http_server_request_duration_seconds_count{service_name="network-inventory-planning",http_response_status_code=~"5.."}[5m])) / sum(rate(http_server_request_duration_seconds_count{service_name="network-inventory-planning"}[5m])) > 0.05503s mean fail-closed read models or missing configuration.
Simulation refusing503 rate on http_route="/v1/transfer-simulations" above zero for 15mRead models stale beyond PLANNING_MAX_STALENESS.
Outbox backlogunpublished outbox_events older than 5 minutesRelay off, broker down, or a head-of-line row failing.
Outbox rows excluded by the attempt capSELECT count(*) FROM outbox_events WHERE published_at IS NULL AND attempts >= 20 (your OUTBOX_MAX_ATTEMPTS) 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).
Consumer laglag of the five NIP groups and network-inventory-planning-analytics (Kafka exporter)A transient error retries the same message forever.
Analytics DLQany message on warehouse.network-inventory-planning.analytics.dlqA poison saga-health event.
Transfer DLQsany message with x-dlq-consumer = transfer-reply-consumer / transfer-fact-consumer on warehouse.inventory.events.dlq / warehouse.fulfillment.events.dlq, or the ERROR log line aboveA producer and NIP disagree about a transfer; that transfer will not advance on its own.
Projection freshnesslag_seconds from /reports/freshness above 15 minutesProjector down or lagging.
Stuck transfersnew rows in transfer_stuck_detections (or /reports/stuck-transfers)Allocation reply or a fulfillment fact never arrived.
Rebalance failing closedconsecutive FAILED rows in rebalance_runsChronically stale read models.