Why Observability Matters

Running AI agents in production is fundamentally different from running stateless services. Each agent invocation spawns multiple LLM calls, tool executions, memory reads, and asynchronous steps — any of which can stall, fail, or produce unexpected output. Without proper observability you're debugging production incidents blind.

OpenClaw ships with built-in support for the three pillars of observability: logs capture event context and decision rationale, metrics expose quantitative health signals, and traces map the complete request flow from user input to final output. Together they give you a real-time picture of every agent run.

Enable Monitoring in 60 Seconds

Add the following block to your openclaw.yaml to activate all three observability pillars at once:

monitoring:
  enabled: true
  log_level: INFO          # DEBUG | INFO | WARNING | ERROR
  log_format: json         # json | text
  metrics:
    enabled: true
    port: 9090             # Prometheus /metrics scrape endpoint
    prefix: openclaw
  tracing:
    enabled: true
    exporter: otlp         # otlp | jaeger | zipkin
    endpoint: http://localhost:4317
    sample_rate: 1.0       # 1.0 = trace every request

The Three Pillars of AI Agent Observability

PillarWhat It CapturesRecommended StackTypical Retention
LogsAgent decisions, tool calls, LLM responses, errors, contextLoki + Grafana30–90 days
MetricsLatency p50/p99, token budget, error rate, active agentsPrometheus + Grafana90–365 days
TracesEnd-to-end span tree, LLM call durations, tool dependenciesTempo / Jaeger7–30 days

Sections

Key Metrics to Track

MetricTypeAlert Threshold
openclaw_task_duration_secondsHistogramp99 > 30s
openclaw_token_usage_totalCounterBudget alert
openclaw_tool_errors_totalCounterRate > 5%
openclaw_agent_activeGauge> 100
openclaw_llm_requests_totalCounterRate limit

Grafana Dashboard Setup

Import the official OpenClaw Grafana dashboard (ID 19842) or download the JSON from the GitHub repo. It includes pre-built panels for:

  • Agent throughput — tasks/min over a rolling 1-hour window
  • LLM latency heatmap — p50 / p95 / p99 response times per model
  • Token budget tracker — cumulative spend vs daily budget ceiling
  • Tool error breakdown — error rate per tool with drill-down into stack traces via Loki
  • Active agents gauge — current concurrent agent count vs configured limit
  • Memory utilisation — vector store size, retrieval latency, eviction frequency
# Add Prometheus data source then import dashboard
curl -X POST http://admin:admin@localhost:3000/api/dashboards/import \
  -H "Content-Type: application/json" \
  -d '{ "dashboard": {"id": 19842}, "overwrite": true, "inputs": [{"name": "DS_PROMETHEUS","type": "datasource","pluginId": "prometheus","value": "Prometheus"}] }'

Structured Log Reference

When log_format: json is set, every log line is a JSON object. Common fields and their meanings:

FieldTypeExampleDescription
tsstring2026-03-16T12:00:00ZISO-8601 UTC timestamp
levelstringINFOLog level
agent_idstringagnt_abc123Unique agent instance ID
task_idstringtask_xyzTask correlation ID
iterationint3Current think/act iteration number
toolstringweb_searchTool being invoked (tool calls only)
duration_msint1420Duration of the current operation
tokens_usedint843Tokens consumed by this LLM call
errorstringtool_timeoutError code if the step failed
trace_idstring4bf92f3577b3…OpenTelemetry trace ID for correlation

Prometheus Alerting Rules

Add these rules to your Alertmanager config to catch the most common production issues:

groups:
  - name: openclaw
    rules:
      - alert: HighAgentErrorRate
        expr: rate(openclaw_tool_errors_total[5m]) / rate(openclaw_llm_requests_total[5m]) > 0.05
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: "OpenClaw tool error rate > 5% for 2 minutes"

      - alert: AgentTaskTimeout
        expr: increase(openclaw_task_timeout_total[5m]) > 3
        for: 1m
        labels:
          severity: critical
        annotations:
          summary: "More than 3 agent tasks timed out in the last 5 minutes"

      - alert: TokenBudgetNear90Pct
        expr: openclaw_token_usage_total / openclaw_token_budget_total > 0.9
        for: 0m
        labels:
          severity: warning
        annotations:
          summary: "Token budget is over 90% consumed"

      - alert: LLMProviderUnreachable
        expr: openclaw_llm_provider_up == 0
        for: 1m
        labels:
          severity: critical
        annotations:
          summary: "LLM provider health check failing — agents cannot execute"

OpenTelemetry Distributed Tracing

OpenClaw emits OpenTelemetry spans for every step in an agent run. Each task creates a root span with child spans for LLM calls, tool invocations, and memory operations. This lets you visualise the complete agent execution tree in Jaeger or Grafana Tempo.

# openclaw.yaml — full tracing config
monitoring:
  tracing:
    enabled: true
    exporter: otlp
    endpoint: http://otel-collector:4317  # OTLP gRPC endpoint
    sample_rate: 0.1       # sample 10% in high-volume production
    propagation: w3c       # w3c | b3 | b3multi
    resource:
      service.name: openclaw-agents
      deployment.environment: production

Useful Loki Log Queries

If you are using Grafana Loki for log aggregation, these LogQL queries are useful for debugging agent behaviour:

# All errors in the last hour
{app="openclaw"} |= "error" | json | level="ERROR"

# Slow tool calls (> 5 seconds)
{app="openclaw"} | json | duration_ms > 5000 | line_format "{{.tool}} took {{.duration_ms}}ms on task {{.task_id}}"

# Token usage per agent session (last 24h)
sum by (agent_id) (
  sum_over_time({app="openclaw"} | json | unwrap tokens_used [24h])
)

# Tasks that exceeded max_iterations
{app="openclaw"} |= "max_iterations_reached" | json

Defining SLOs for Agent Workloads

Recommended Service Level Objectives for production OpenClaw deployments:

SLOTargetMeasurement WindowPrometheus Query
Task completion rate≥ 99.0%30 days rolling1 - (rate(openclaw_task_failed_total[30d]) / rate(openclaw_task_total[30d]))
p95 task latency≤ 20s1 hour rollinghistogram_quantile(0.95, rate(openclaw_task_duration_seconds_bucket[1h]))
API availability≥ 99.9%30 days rollingavg_over_time(openclaw_api_up[30d])
Tool error rate≤ 2%5 min rollingrate(openclaw_tool_errors_total[5m]) / rate(openclaw_tool_calls_total[5m])