@aicrew/openclaw-otel-patch
v1.2.0
Published
OpenClaw OTEL diagnostics patches - fixes bundler listener isolation + adds gen_ai.completion spans
Downloads
118
Maintainers
Readme
@aicrew/openclaw-otel-patch
Patches for OpenClaw's diagnostics-otel plugin to fix telemetry export and add GenAI semantic convention spans.
What It Fixes
1. Bundler Listener Isolation (Critical)
The tsdown bundler duplicates diagnostic-events.ts into 5+ separate JS chunks, each with its own listeners Set. The gateway emits events into one copy, but the OTEL plugin subscribes via a different copy — so events never reach the plugin.
Fix: Share listeners via globalThis.__openclaw_diag_listeners.
Related: openclaw/openclaw#5190, PR #11168
2. GenAI Semantic Convention Spans
Adds gen_ai.completion trace spans following the OpenTelemetry GenAI Semantic Conventions, including:
gen_ai.system,gen_ai.response.model,gen_ai.request.modelgen_ai.usage.input_tokens,gen_ai.usage.output_tokensgen_ai.usage.cache_read_tokens,gen_ai.usage.cache_write_tokensopenclaw.cost.usd
Related: PR #11100
Compatibility
- Base: OpenClaw v2026.2.18 (
fa4772b4ce) - Node.js: 22+
Usage
# Install globally
npm install -g @aicrew/openclaw-otel-patch
# Apply to your OpenClaw installation
openclaw-otel-patch ~/openclaw
# Hard restart (required — SIGUSR1 won't reinitialize OTEL SDK)
openclaw gateway stop && openclaw gateway startRequired Config
Add to ~/.openclaw/openclaw.json:
{
"diagnostics": {
"enabled": true,
"otel": {
"enabled": true,
"endpoint": "https://your-otlp-endpoint",
"protocol": "http/protobuf",
"serviceName": "your-service-name",
"traces": true,
"metrics": true,
"logs": true,
"flushIntervalMs": 5000
}
},
"models": {
"providers": {
"anthropic": {
"models": [
{ "id": "claude-opus-4-6", "cost": { "input": 15, "output": 75, "cacheRead": 1.5, "cacheWrite": 18.75 } },
{ "id": "claude-sonnet-4-6", "cost": { "input": 3, "output": 15, "cacheRead": 0.3, "cacheWrite": 3.75 } },
{ "id": "claude-haiku-3-5", "cost": { "input": 0.8, "output": 4, "cacheRead": 0.08, "cacheWrite": 1 } }
]
}
}
}
}Metrics Exported
| Metric | Description |
|--------|-------------|
| openclaw.tokens | Token counts by type (input/output/cache_read/cache_write/total) |
| openclaw.cost.usd | Estimated USD cost per model call |
| openclaw.run.duration_ms | Agent run duration |
| openclaw.context.tokens | Context window usage |
| openclaw.message.queued | Messages queued |
| openclaw.message.processed | Messages processed by outcome |
| openclaw.queue.depth | Queue depth |
| openclaw.queue.lane.enqueue | Lane enqueue events |
| openclaw.session.state | Session state transitions |
Traces Exported
| Span | Description |
|------|-------------|
| gen_ai.completion | GenAI semantic convention span with token/cost attributes |
| openclaw.model.usage | Legacy span with session/token details |
| openclaw.webhook.processed | Webhook processing spans |
| openclaw.message.processed | Message processing spans |
⚠️ Notes
- Dist patches are fragile — re-run after any
pnpm buildor OpenClaw update - The resource attributes (agent ID, org ID) are hardcoded — edit
service.tsfor your own values - Once PR #11168 merges, the dist patch becomes unnecessary
- Once PR #11100 merges, the gen_ai spans will be built-in with full tool tracing
License
MIT
