Skip to content

Observability

The AgentStateGraph server records traces, metrics and logs under OpenTelemetry’s names, through oxtel. Nothing leaves the process until you send it somewhere. Any OTLP backend, or Prometheus, can take what it records without code changes.

The full contract, with every span, attribute and privacy rule, is docs/OBSERVABILITY.md. This page covers turning it on, the operator kit, and the metrics.

SettingWhat it does
OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318sends traces, metrics and logs over OTLP/HTTP. Release binaries and the Docker image include OTLP; a source build needs --features otlp
--metricsserves /metrics for Prometheus to scrape; with --auth, it needs an admin key
ASG_LOG, ASG_LOG_FORMATlog level, and text, json or ecs lines on standard error
ASG_SQL_SPANS=ona span for each SQL statement; off by default, as it costs a small read more than anything else
ASG_TRACE_LINKS=offstops recording the trace each commit was made in
ASG_COMMIT_EVENTS=onlogs each commit as an asg.commit event, for a log backend or SIEM
OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES, OTEL_TRACES_SAMPLER, …the standard OpenTelemetry settings

A write’s trace leads to its commit: its span carries asg.commit.id. A commit leads back to its trace: log and blame show its trace_id. Error responses carry the request’s trace_id, and every HTTP response carries an x-request-id.

deploy/observability holds:

  • an OpenTelemetry Collector config;
  • Prometheus with alert rules;
  • Grafana with a dashboard and data sources for Prometheus and Jaeger.

The observability profile in docker-compose.yml runs all of them, with Jaeger:

Terminal window
ASG_OTLP_ENDPOINT=http://otel-collector:4318 docker compose --profile observability up -d

Then open:

  • Grafana at http://localhost:3000, for the AgentStateGraph dashboard: requests, rejections, MCP tool calls, writes and conflicts, policy decisions, database statements and connections, store size, history lag and garbage collection;
  • Jaeger at http://localhost:16686, for traces;
  • Prometheus at http://localhost:9090, for metrics and alerts.

Everything is published on 127.0.0.1 only. A server running outside compose can send to the collector at http://localhost:4318.

The collector sends traces to Jaeger, serves metrics for Prometheus, and prints logs. To use your own backends, change its exporters; the server needs nothing else.

deploy/observability/alerts.yml alerts when:

  • the store stops answering;
  • the server stops reporting;
  • more than 5% of HTTP requests fail;
  • HTTP p99 latency goes over a second;
  • requests are shed (over capacity or timed out), or rejected in bulk;
  • a Postgres pool is over 90% used, or SQLite’s connection is waited on for long;
  • history extraction falls behind while the lag grows;
  • a garbage collection sweep refuses to run;
  • writes keep failing with write conflicts.

The thresholds are starting points.

Every metric the server records. Prometheus names follow OpenTelemetry’s rules: dots become underscores, the unit is appended (_seconds, _bytes), and counters end in _total. So asg.commit.duration is asg_commit_duration_seconds and asg.http.rejections is asg_http_rejections_total. A test checks this table against the instruments the server registers.

MetricInstrumentUnitLabelsMeaning
http.server.request.durationhistogramshttp.request.method, http.route, http.response.status_code, url.scheme, network.protocol.version, error.typeHTTP requests, by route template
http.server.active_requestsup-down counterhttp.request.method, url.schemeHTTP requests in flight
asg.http.rejectionscounterasg.rejection.reasonrequests turned away before a handler ran: rate_limited, over_capacity, timed_out, body_too_large, unauthenticated, forbidden, host_refused
mcp.server.operation.durationhistogramsmcp.method.name, gen_ai.tool.name, gen_ai.operation.name, mcp.protocol.version, network.transport, error.type, rpc.response.status_codeMCP requests, by tool; a failed tool call has error.type tool_error
mcp.server.session.durationhistogramsmcp.protocol.version, network.transportMCP sessions, when they end
asg.commit.durationhistogramsasg.operation.name, error.typewrites that make a commit: set, delete, merge, commit_speculation
asg.ref.cas_retriescounterasg.operation.namewrites rebuilt because another writer moved the ref first
asg.policy.decisionscounterasg.policy.decisionpolicy evaluations, by decision
asg.policy.evaluator.errorscounterasg.policy.evaluator, error.typeexternal evaluators (Rego, Cedar) that failed, so their policy was skipped
asg.gc.sweepscounterasg.gc.outcomesweeps asked to delete: swept, or refused because history wasn’t distilled
db.client.operation.durationhistogramsdb.system.name, db.query.summary, db.namespace, server.address, server.port, error.type, db.response.status_codeSQL statements
db.client.connection.countup-down counterdb.client.connection.pool.name, db.client.connection.statePostgres connections, idle and used
db.client.connection.maxup-down counterdb.client.connection.pool.namethe Postgres pool’s size
db.client.connection.pending_requestsup-down counterdb.client.connection.pool.namecallers waiting for a connection; SQLite’s one connection is the pool sqlite
db.client.connection.wait_timehistogramsdb.client.connection.pool.nametime waiting for a connection
db.client.connection.use_timehistogramsdb.client.connection.pool.nametime holding one
db.client.connection.timeoutscounterdb.client.connection.pool.namePostgres connection waits that timed out
asg.store.availablegauge1 if the store answered the last sample, else 0
asg.store.objectsgaugeobjects in the store (this tenant’s, on Postgres)
asg.store.commitsgaugecommits in the store
asg.store.sizegaugeBythe store’s file on disk (SQLite)
asg.history.undistilled_commitsgaugecommits history extraction hasn’t distilled yet: its lag
asg.gc.last_sweep.timegaugeswhen the last sweep this server ran finished, as Unix time
asg.gc.last_sweep.objects_deletedgaugewhat that sweep deleted
asg.gc.last_vacuum.bytes_reclaimedgaugeBywhat the last vacuum returned to the operating system

The store gauges are sampled every 60 seconds while a metrics pipeline exists (ASG_STORE_GAUGES_INTERVAL changes it, and 0 turns them off). The db.client.connection.* metrics are still in development in OpenTelemetry’s conventions, so their names may change.

On a busy laptop, with telemetry on and nothing exported, an HTTP read gains about 11 µs (6%) and an MCP call about 3% or less. Metrics cost nothing measurable. DESIGN.md Plan H has the measurements, and cargo bench -p agentstategraph-mcp --features otlp --bench overhead repeats them.