Skip to main content

Observability

What each binary emits, built from internal/adapters/outbound/telemetry, the chi routers and the pinned library versions in go.mod (otelchi v0.12.3, OTel contrib runtime v0.72.0, prometheus client_golang).

Export pipeline​

BinaryOTel traces + metrics (OTLP/gRPC)Prometheus GET /metricsservice.name
cmd/apiyesyesinbound-receiving
cmd/mcpyesnoinbound-receiving-mcp
cmd/inbound-reportsyesnoinbound-receiving-reports
cmd/inbound-projectoryes since gap fix D21 (ADR 0008): providers, propagator and Go runtime metrics; no spans of its ownnoinbound-receiving-projector
  • OTLP: telemetry.Setup installs a batching TracerProvider and a MeterProvider with a periodic reader every 30 s, both exporting insecure OTLP/gRPC to OTEL_EXPORTER_OTLP_ENDPOINT (default localhost:4317; the chart sets otel-collector.observability.svc.cluster.local:4317 when otel.enabled). The exporter connects lazily: with no collector, telemetry is dropped and the service runs normally (expect periodic export errors in the log).
  • Resource attributes: service.name, service.version (SERVICE_VERSION, default dev; the chart sets the image tag) and deployment.environment.name (ENVIRONMENT, default local), merged with the SDK defaults.
  • Propagation: W3C traceparent + baggage on inbound HTTP, and across the outbox to Kafka (gap fix D27, ADR 0009): postgres.OutboxRepo.Insert injects the request span's trace context with the global propagator into outbox_events.headers (after content-type), and the relay copies those headers onto the Kafka message, so a consumer that extracts them continues the producing request's trace. A row written without an active span carries only content-type. This service's own consumers open no spans, so they do not extract.
  • GET /metrics (api only): a private Prometheus registry with the Go collector (go_*) and the process collector (process_*). The HTTP and runtime OTel metrics below are not on this endpoint; they go through OTLP. The route is not in apis/openapi.yaml.

Metric instruments​

The repo defines one custom (business) instrument, inbound_receiving.receipts.units_received (ADR 0013); every other metric comes from a library:

InstrumentTypeUnitAttributesEmitted by
inbound_receiving.advice.issuedInt64 counter{advice}within_sla (true, false)telemetry.AdviceMetrics, incremented by CloseReceipt once per receiving advice issued (ADR 0023); OTLP only. The KPI "% receipts with advice inside the SLA" is true / (true + false); the same share is in GET /reports/receiving-performance (advice block)
inbound_receiving.advice.overdueInt64 counter{receipt}nonetelemetry.AdviceMetrics, incremented by the housekeeping sweep once per Open receipt past the advice SLA (it also logs a WARN receiving advice overdue and raises ReceivingAdviceOverdue); OTLP only, exported by Prometheus-style backends as inbound_receiving_advice_overdue_total
inbound_receiving.receipts.units_receivedInt64 counter{unit}outcome (good, damaged; the receipt line's condition)telemetry.ReceiptMetrics, created in cmd/api/main.go and incremented by ReceiveLine with the line quantity; OTLP only. The damaged share never becomes stock (ADR 0003)
http.server.request.durationFloat64Histogram (buckets 5 ms … 10 s)shttp.method, http.scheme, http.route (chi pattern, e.g. /asns/{asnNumber})otelchi NewServerRequestDuration on the api, mcp and reports routers
go.memory.usedUpDownCounter (observable)Bygo.memory.type (stack, other)contrib runtime (api, mcp, reports, projector)
go.memory.limitUpDownCounter (observable)By—contrib runtime
go.memory.allocatedCounter (observable)By—contrib runtime
go.memory.allocationsCounter (observable){allocation}—contrib runtime
go.memory.gc.goalUpDownCounter (observable)By—contrib runtime
go.goroutine.countUpDownCounter (observable){goroutine}—contrib runtime
go.processor.limitUpDownCounter (observable){thread}—contrib runtime
go.config.gogcUpDownCounter (observable)%—contrib runtime

runtime.Start is the only runtime hook wired; the contrib runtime NewProducer (which would add go.schedule.duration) is not registered.

http.server.request.duration carries no status-code attribute in otelchi v0.12.3, so error rates cannot be derived from it; use logs or the Kong gateway's metrics for 4xx/5xx rates. The instrumentation scope also carries service.name of the router (inbound-receiving, inbound-receiving-mcp or inbound-receiving-reports).

Traces​

BinarySpan sourceSpan name
cmd/apiotelchi.Middleware("inbound-receiving", WithChiRoutes)the chi route pattern, e.g. /asns, /asns/{asnNumber}/cancellations, /receipts/{receiptId}/lines, /readyz
cmd/mcpotelchi.Middleware("inbound-receiving-mcp")the mount pattern (/mcp/* or /*), one span per Streamable HTTP request; individual tool calls do not get their own span
cmd/inbound-reportsotelchi.Middleware("inbound-receiving-reports")/reports/receiving-performance, /reports/freshness, /healthz

There are no manual spans (tracer.Start) anywhere in cmd/ or internal/, and no database or Kafka client instrumentation: the outbox relay, the consumers and the projector produce no spans.

Logs​

All four binaries log JSON to stdout via log/slog (LOG_LEVEL, default info). Log lines are not correlated with trace ids. Fields worth indexing:

MessageLevelFieldsBinary
http server listening / mcp server listening (Streamable HTTP) / reports server listening / projector admin server listeningINFOaddreach
telemetry configuredINFOservice_name, service_version, environment, otlp_endpointprojector
retrying / succeeded after retryWARN / INFOop (run migrations, ping postgres, run analytics migrations, ping analytics database), attempt, in, errall (boot retry)
outbox relay runningINFOpublisher, interval, max_attempts, topicsapi
outbox relay pass failedERRORerror (contains outbox row <id> (<type>))api
outbox relay: row reached the attempt cap and is excluded from future claims; re-arm it with attempts = 0 after fixing the causeERROR (once per row)outbox_id, topic, event_type, key, attempts, max_attempts, errorapi (ADR 0007)
invalid OUTBOX_MAX_ATTEMPTS; using the defaultWARNvalue, defaultapi
readiness: dependency is not readyWARNdependency (postgres, kafka, analytics-postgres), errorapi, projector
product consumer running / dock door consumer running / analytics consumer runningINFOtopic, group_id, brokersapi / projector
<worker> stopped unexpectedly: exiting so the orchestrator restarts the serviceERROR (process exit 1)—api (a consumer or the relay returned on its own, ADR 0011)
product registered processed / location slot event processedINFOevent_id, sku or location_code, type, outcomeapi
skipping a message that is not a valid CloudEvent, skipping a malformed ... payload, skipping an invalid ...WARNtopic or event_id, type, errorapi consumers
<name> handling failed; retrying the same message / <name> offset commit failed; ...ERRORerror, partition, offset, attempt, retry_inapi consumers, projector
analytics: skipping message that is not a CloudEvents 1.0 event ...WARN (at most once a minute)topic, partition, offset, suppressed_since_last_warningprojector
analytics: dead-lettering a message that can never be projectedERRORerror, dlq_topic, partition, offsetprojector
housekeeping sweeper running / analytics housekeeping sweeper runningINFO—api (Postgres only) / projector
housekeeping sweepINFO (only when rows were deleted)idempotency_keys_deleted, outbox_events_deleted, processed_events_deletedapi (ADR 0010)
analytics housekeeping sweepINFO (only when rows were deleted)analytics_processed_events_deletedprojector
housekeeping sweep failed / analytics housekeeping sweep failedERRORerror and the counts deleted before the failureapi / projector
invalid housekeeping duration; using the defaultWARNkey, value, defaultapi, projector
idempotency store failedERRORerror, method, pathapi
report query failedERRORerror, pathreports
shutdown: readiness flipped to not-ready; waiting for traffic to drainINFOdrain_delayapi
worker did not stop before the shutdown drain deadlineWARNworker (product-consumer, dock-door-consumer, outbox-relay)api

Health endpoints​

BinaryGET /healthzGET /readyz
cmd/api200 {"status":"ok"}200 {"status":"ready"}; 503 {"status":"not_ready"} once shutdown starts
cmd/mcp200 {"status":"ok"}—
cmd/inbound-projector (:8091)200 {"status":"ok"}as api
cmd/inbound-reports200 {"status":"ok"}—

The analytics freshness endpoint GET /reports/freshness (reports binary) is the projector's lag signal: lag_seconds = now − time of the newest applied event.

Dashboards​

warehouse-infra has no Grafana dashboard for this context: terraform/dashboards/contexts/ on origin/develop holds dashboards for eleven other contexts but no inbound-receiving.json. This repo has none either.

Suggested alerts​

These are suggestions built from the signals above; none exist today.

AlertSignalWhy
Outbox backlogSELECT count(*) FROM outbox_events WHERE published_at IS NULL above a threshold for 5 min, or any row with attempts > 5the relay stops at the first failing row; a stuck head blocks every later event until it reaches the attempt cap
Outbox row excludedany outbox relay: row reached the attempt cap ... ERROR line, or SELECT count(*) FROM outbox_events WHERE published_at IS NULL AND attempts >= 20 > 0the row will never be delivered until an operator re-arms it (runbook)
Relay failingrate of outbox relay pass failed log linesKafka unreachable or rejecting writes
Consumer stuckrepeated handling failed; retrying the same message for the same partition/offseta transient failure blocks the partition indefinitely
Analytics DLQ growthany message on warehouse.inbound-receiving.analytics.dlqevery DLQ entry is a deterministic projection failure
Projection lagGET /reports/freshness lag_seconds above e.g. 300 while receipts are being workedprojector down, lagging or blocked
Latencyp95 of http.server.request.duration by http.route above 1 seach query has a 5 s statement_timeout on the OLTP pool
Pod restartskube restarts on any componentboot retry exhausted (Postgres unreachable) or projector consumer exited