OpenTelemetry observability for OpenClaw AI agents.
π Full Documentation β Setup guides, configuration reference, and backend examples.
This repository documents two complementary approaches to monitoring OpenClaw:
| Approach | Best For | Setup Complexity |
|---|---|---|
| Official Plugin | Operational metrics, Gateway health, cost tracking | Simple config |
| Custom Plugin | Deep tracing, tool call visibility, request lifecycle | Plugin installation |
Recommendation: Use both for complete observability.
OpenClaw v2026.2+ includes built-in OpenTelemetry support. Just add to openclaw.json:
{
"diagnostics": {
"enabled": true,
"otel": {
"enabled": true,
"endpoint": "http://localhost:4318",
"serviceName": "openclaw-gateway",
"traces": true,
"metrics": true,
"logs": true
}
}
}Then restart:
openclaw gateway restartMetrics:
openclaw.tokensβ Token usage by type (input/output/cache)openclaw.cost.usdβ Estimated model costopenclaw.run.duration_msβ Agent run durationopenclaw.context.tokensβ Context window usageopenclaw.webhook.*β Webhook processing statsopenclaw.message.*β Message processing statsopenclaw.queue.*β Queue depth and wait timesopenclaw.session.*β Session state transitions
Traces: Model usage, webhook processing, message processing, stuck sessions
Logs: All Gateway logs via OTLP with severity, subsystem, and code location
For deeper observability, install the custom plugin from this repo. It uses OpenClaw's typed plugin hooks to capture the full agent lifecycle.
Connected Traces:
openclaw.request (root span)
βββ openclaw.agent.turn
β βββ tool.Read (file read)
β βββ tool.exec (shell command)
β βββ tool.Write (file write)
β βββ tool.web_search
βββ (child spans connected via trace context)
Per-Tool Visibility:
- Individual spans for each tool call
- Tool execution time
- Result size (characters)
- Error tracking per tool
Request Lifecycle:
- Full message β response tracing
- Session context propagation
- Agent turn duration with token breakdown
-
Clone this repository:
git clone https://github.com/henrikrexed/openclaw-observability-plugin.git
-
Add to your
openclaw.json:{ "plugins": { "load": { "paths": ["/path/to/openclaw-observability-plugin"] }, "entries": { "otel-observability": { "enabled": true } } } } -
Clear cache and restart:
rm -rf /tmp/jiti systemctl --user restart openclaw-gateway
| Feature | Official Plugin | Custom Plugin |
|---|---|---|
| Token metrics | β Per model | β Per session + model |
| Cost tracking | β Yes | β Yes (from diagnostics) |
| Gateway health | β Webhooks, queues, sessions | β Not focused |
| Session state | β State transitions | β Not tracked |
| Tool call tracing | β No | β Individual tool spans |
| Request lifecycle | β No | β Full request β response |
| Connected traces | β Separate spans | β Parent-child hierarchy |
| Setup complexity | π’ Config only | π‘ Plugin installation |
{
"diagnostics": {
"enabled": true,
"otel": {
"enabled": true,
"endpoint": "https://{env-id}.live.dynatrace.com/api/v2/otlp",
"headers": {
"Authorization": "Api-Token {your-token}"
},
"serviceName": "openclaw-gateway",
"traces": true,
"metrics": true,
"logs": true
}
}
}{
"diagnostics": {
"enabled": true,
"otel": {
"enabled": true,
"endpoint": "https://otlp-gateway-{region}.grafana.net/otlp",
"headers": {
"Authorization": "Basic {base64-credentials}"
},
"serviceName": "openclaw-gateway",
"traces": true,
"metrics": true
}
}
}{
"diagnostics": {
"enabled": true,
"otel": {
"enabled": true,
"endpoint": "http://localhost:4318",
"serviceName": "openclaw-gateway",
"traces": true,
"metrics": true,
"logs": true
}
}
}| Option | Type | Default | Description |
|---|---|---|---|
diagnostics.enabled |
boolean | false | Enable diagnostics system |
diagnostics.otel.enabled |
boolean | false | Enable OTel export |
diagnostics.otel.endpoint |
string | β | OTLP endpoint URL |
diagnostics.otel.protocol |
string | "http/protobuf" | Protocol |
diagnostics.otel.headers |
object | β | Custom headers |
diagnostics.otel.serviceName |
string | "openclaw" | Service name |
diagnostics.otel.traces |
boolean | true | Enable traces |
diagnostics.otel.metrics |
boolean | true | Enable metrics |
diagnostics.otel.logs |
boolean | false | Enable logs |
diagnostics.otel.sampleRate |
number | 1.0 | Trace sampling (0-1) |
Important: Do NOT add a
configblock inside the plugin entry β OpenClaw's plugin framework rejects unknown properties. The plugin reads its configuration from thediagnostics.otelsection instead.
The following settings are controlled via the diagnostics.otel config block:
| Option | Type | Default | Description |
|---|---|---|---|
endpoint |
string | http://localhost:4318 |
OTLP endpoint URL |
serviceName |
string | openclaw-gateway |
Service name |
protocol |
string | http/protobuf |
OTLP protocol |
traces |
boolean | true | Enable traces |
metrics |
boolean | true | Enable metrics |
logs |
boolean | true | Enable logs |
- Getting Started β Setup guide
- Configuration β All options
- Architecture β How it works
- Limitations β Known constraints
- Backends β Backend-specific guides
For defense in depth, add Tetragon eBPF-based monitoring. While the plugins above capture application-level telemetry, Tetragon sees what happens at the kernel level β file access, process execution, network connections, and privilege changes.
- Tamper-proof: Even a compromised agent can't hide its kernel-level actions
- Sensitive file detection: Alert when
.env, SSH keys, or credentials are accessed - Dangerous command detection: Catch
rm,curl | sh,chmod 777, etc. - Privilege escalation: Detect
setuid/setgidattempts
# Install Tetragon
curl -LO https://github.com/cilium/tetragon/releases/latest/download/tetragon-v1.6.0-amd64.tar.gz
tar -xzf tetragon-v1.6.0-amd64.tar.gz && cd tetragon-v1.6.0-amd64
sudo ./install.sh
# Create OpenClaw policies directory
sudo mkdir -p /etc/tetragon/tetragon.tp.d/openclaw
# Add policies (see docs/security/tetragon.md for full examples)
# Start Tetragon
sudo systemctl enable --now tetragonTetragon events are exported to /var/log/tetragon/tetragon.log and can be ingested by the OTel Collector using the filelog receiver.
| Layer | Source | What It Shows |
|---|---|---|
| Application | Custom Plugin | Tool calls, tokens, request flow |
| Gateway | Official Plugin | Session health, queues, costs |
| Kernel | Tetragon | System calls, file access, network |
See Security: Tetragon for full installation and configuration guide.
Auto-instrumentation not possible: OpenLLMetry/IITM breaks @mariozechner/pi-ai named exports due to ESM/CJS module isolation. All telemetry is captured via hooks, not direct SDK instrumentation.
No per-LLM-call spans: Individual API calls to Claude/OpenAI cannot be traced. Token usage is aggregated per agent turn.
See Limitations for details.
MIT