Skip to main content

Observability

Synced from warehouse-ops-agent

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.

The agent pushes traces and metrics over OTLP/gRPC to an OpenTelemetry Collector and writes JSON logs to stdout. It exposes no /metrics scrape endpoint of its own. Everything below is read from the code on this branch; the Prometheus series names are derived with the fleet's naming rule and were not observed live.

Export pipeline​

SignalHow it leaves the processSource
TracesOTLP/gRPC, insecure, batch span processor, to OTEL_EXPORTER_OTLP_ENDPOINT (default localhost:4317; a bare host:port gets http:// prepended)internal/observability/telemetry.go (Setup)
MetricsOTLP/gRPC, periodic reader, same endpointinternal/observability/telemetry.go
LogsJSON (log/slog JSONHandler) on stdout; Alloy tails pod stdout into Loki in the kind clustercmd/agent/main.go (newLogger)

Resource attributes on every span and metric: service.name (OTEL_SERVICE_NAME, default warehouse-ops-agent), service.version (SERVICE_VERSION, default dev) and deployment.environment.name (ENVIRONMENT, default local), merged with the SDK defaults. The propagator is W3C tracecontext plus baggage.

An unreachable Collector never blocks startup: the exporters dial lazily, and export errors are logged as opentelemetry error at warn level. If Setup itself fails, the agent logs opentelemetry setup degraded and opentelemetry disabled; traces and metrics will not be exported, and keeps serving.

The chart sets the OTel variables only when otel.enabled is true (the default), pointing at otel-collector.observability.svc.cluster.local:4317.

Metric instruments​

Instruments this repo creates​

InstrumentTypeUnitAttributesWhen it is recordedSource
ops_agent.llm.arbitrationsInt64Counter{arbitration}use.case (today only flow_balance_advisory), mode (shadow or on), source (deterministic, llm, fallback)once per flow-balance decision that went through the reasonerinternal/adapters/outbound/telemetry/arbitration_metrics.go
ops_agent.llm.agreementInt64Counter{agreement}use.case, mode, agree (bool)only when the model returned a valid plan; agree is true when its action equals the deterministic onesame file
circuit_breaker.stateInt64Gauge{state}dependency (today only anthropic-llm)on every breaker state change: 0 closed, 1 half-open, 2 openinternal/adapters/outbound/telemetry/circuit_breaker_metrics.go

All three are registered by wireReasoner (cmd/agent/reasoner.go), and only when LLM_MODE is shadow or on. With the default off none of them exists. The breaker gauge has no data point until the first state change, so "no series" means "closed since startup", not "unknown".

The meters are named warehouse-ops-agent/llm and warehouse-ops-agent/resilience. Through the Collector's Prometheus exporter the dot-separated OTel instrument names and attribute keys above (ADR-0013's Tier-2 naming convention) still become the SAME Prometheus series as before this convention was adopted — ops_agent_llm_arbitrations_total, ops_agent_llm_agreement_total and circuit_breaker_state, with the use_case label unchanged — because the exporter already converts . to _ and appends _total to a counter whose name doesn't already end in it. No dashboard or alert built on those Prometheus names needs to change.

The shadow-mode rollout gate from ADR 0004 is the agreement ratio:

sum(rate(ops_agent_llm_agreement_total{use_case="flow_balance_advisory", agree="true"}[1h]))
/
sum(rate(ops_agent_llm_agreement_total{use_case="flow_balance_advisory"}[1h]))

Instruments from libraries​

internal/adapters/inbound/http/router.go installs two otelchi v0.12.3 metric middlewares on every route, /mcp included (ADR 0010):

InstrumentTypeUnitAttributes
http.server.request.durationFloat64Histogramshttp.method, http.scheme, http.route (the chi pattern, e.g. /flow-balance/{pathId}); scope attribute service.name
http.server.active_requestsInt64UpDownCounter{request}same as above

otelchi v0.12.3's default attribute set has no status-code attribute, so a 5xx rate cannot be computed from these series. Use Kong's kong_http_requests_total{code=~"5.."}, the http request log line's status field, or Istio's istio_requests_total instead.

go.opentelemetry.io/contrib/instrumentation/runtime v0.71.0 (runtime.Start in telemetry.go) adds the Go runtime instruments: go.memory.used, go.memory.limit, go.memory.allocated, go.memory.allocations, go.memory.gc.goal, go.goroutine.count, go.processor.limit and go.config.gogc.

No other instrument exists. In particular there is no counter per upstream call, per MCP tool call or per degraded section; those show up only in logs.

Traces​

SpanKindAttributesCreated by
the chi route pattern, e.g. /daily-brief, /flow-balance/{pathId}, /mcpserverotelchi's standard HTTP attributesotelchi.Middleware with WithChiRoutes (router.go)
mcp.tool <name>, e.g. mcp.tool get_daily_briefinternalmcp.tool.name; status Error with the message when the tool failsaddTool in internal/adapters/inbound/mcp/tools.go
llm.tool_callinternalllm.tool_call.upstream, llm.tool_call.tool; status Error on a refusal or a failed callexecuteToolCall in internal/adapters/outbound/llm/anthropic/reasoner.go
HTTP GET, HTTP POST, HTTP DELETE (otelhttp's default name)clientotelhttp's standard HTTP client attributes (method, URL, server address, status code)every outbound call: the MCP clients, the console-bff REST clients, the Prometheus and Loki readers and the Anthropic reasoner, all built by httpclient.New in internal/adapters/outbound/httpclient/httpclient.go

Outbound calls are instrumented. Every outbound http.Client comes from httpclient.New, whose transport is otelhttp.NewTransport. Each call gets a client span and sends a W3C traceparent, so a trace continues from this agent into the upstream context (its MCP or REST server span becomes a child of the agent's client span). The same transport records otelhttp's client metrics http.client.request.duration and http.client.request.body.size.

The fitness test TestOutboundHTTPClientsUseOtelhttp (internal/architecture/otelhttp_fitness_test.go) fails when a non-test file outside internal/adapters/outbound/httpclient builds an http.Client literal, calls new(http.Client) or uses http.DefaultClient.

Logs​

Every record is a JSON object with slog's time, level and msg. observability.TraceHandler adds trace_id and span_id to any record logged with a context that carries an active span. Only the request logger (http request) and the reasoner's llm.tool_call line log with the request context; the use-case warnings below call Warn without a context, so they carry no trace_id. Correlate them by time and by the pathId, orderId or section field instead.

msgLevelFieldsEmitted when
http requestinfo, error for status at least 500method, path (CR/LF stripped), status, duration_ms, bytes, request_idevery request, /mcp included (RequestLogger, internal/adapters/inbound/http/logging.go)
warehouse-ops-agent listeninginfoaddr, http_routes, mcp_route, one *_endpoint_configured bool per MCP upstream, path_targetsstartup
llm reasoner disabled / llm reasoner configuredinfomode; when configured also model, timeout, toolsstartup
llm reasoner: tool discovery failed for an upstreamwarnerrorstartup, per upstream that did not answer tools/list
llm reasoner: circuit breaker metrics unavailablewarnerrorstartup, if the gauge could not be registered
flow_balance_advisory: <upstream> unavailablewarnpathId, errorwes-work-planning, workforce-management, fulfillment-execution or labor-performance failed
flow_balance_advisory: partial decisionwarnpathId, missingSignalsthe decision lacked a signal
flow_balance_advisory: llm arbitrationinfopathId, mode, source, model, latency_ms, tool_calls, deterministic_action, and when present llm_action, llm_heads, agree, reasonevery reasoner run
llm.tool_callinfoupstream, tool, outcome, args_sha256, latency_msevery tool call the model asked for, refusals included; raw arguments are never logged
explain_travel_factor: facility-layout unavailablewarnpathId, from, to, errorthe facility-layout call failed
order_lifecycle: <context> unavailablewarnorderId, error, and workUnitId for fulfillment-executionone stage of the lifecycle failed
console_reports: section unwired / section unavailable / freshness unavailablewarnsection, sourceContext, errora dashboard section had no client, its report failed, or only its /freshness call failed
transfer_watch: network-inventory-planning call failedwarntool, errorany transfer-watch upstream error
opentelemetry errorwarnerroran OTel export or SDK error
warehouse-ops-agent exited with errorerrorerrorstartup failed (config or reasoner wiring); the process exits 1
http server failederrorerrorListenAndServe failed, e.g. the port is taken

Every user-supplied value in a log field passes through sanitizeForLog, which strips CR and LF (CWE-117).

Dashboards​

No dashboard in this repo. In warehouse-infra (origin/develop):

  • terraform/dashboards/kong-gateway-overview.json shows request rate, 5xx rate and upstream latency per Kong service, which includes the agent's /api/warehouse-ops-agent route.
  • terraform/dashboards/go-runtime.json has a service_name variable (label_values(service_name)) and plots go.goroutine.count and go.memory.used, so warehouse-ops-agent can be selected there.
  • There is no per-context dashboard for the agent: scripts/gen-context-dashboards.py generates them only for the bounded contexts, and logs-overview.json explicitly excludes app="warehouse-ops-agent" from its fleet-wide error panels. Query Loki directly with {app="warehouse-ops-agent"}.

Suggested alerts​

None of these exist yet; they are proposals grounded in the instruments above.

AlertExpression (Prometheus or LogQL)Why
LLM breaker openmax(circuit_breaker_state{dependency="anthropic-llm"}) == 2 for 5mthe model is being skipped; in on mode every flow-balance answer is a fallback
Shadow agreement lowthe agreement ratio above < 0.8 over 1h with at least 20 samplesgate for moving from shadow to on
on-mode fallbackssum(rate(ops_agent_llm_arbitrations_total{mode="on", source="fallback"}[15m])) > 0the model is failing or producing invalid plans
Upstream degradationsum by (msg) (count_over_time({app="warehouse-ops-agent"} | json | level="WARN" | msg=~".*unavailable.*" [10m])) > 10a sibling context is down; answers are partial
Agent 5xx at the edgesum(rate(kong_http_requests_total{service=~".*warehouse-ops-agent.*", code=~"5.."}[5m])) > 0502 from explain-travel-factor, master-data gaps, inbound outlook or transfer watch means an upstream failed
Slow answershistogram_quantile(0.95, sum by (le, http_route) (rate(http_server_request_duration_seconds_bucket{service_name="warehouse-ops-agent"}[5m]))) > 10each MCP call may take up to 10 s, and the brief runs them in sequence