{"_id":"@aicrew/openclaw-otel-patch","_rev":"3-b4f231d24b4c246cbbe08c3477ed7f2b","name":"@aicrew/openclaw-otel-patch","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"@aicrew/openclaw-otel-patch","version":"1.0.0","keywords":["openclaw","opentelemetry","otel","diagnostics","patch"],"license":"MIT","_id":"@aicrew/openclaw-otel-patch@1.0.0","maintainers":[{"name":"aicrew","email":"support@aicrew.build"}],"homepage":"https://github.com/cubanhacker/openclaw-otel-patch#readme","bugs":{"url":"https://github.com/cubanhacker/openclaw-otel-patch/issues"},"bin":{"openclaw-otel-patch":"apply.sh"},"dist":{"shasum":"ace29234f6fd1b9bd6b5f119912e309d4fe1b9b0","tarball":"https://registry.npmjs.org/@aicrew/openclaw-otel-patch/-/openclaw-otel-patch-1.0.0.tgz","fileCount":5,"integrity":"sha512-zT/DiuGtO+cRsVE2nl8xuIWnxYPBDrLa6X4wdnqZT7vj6/eBUst3PhkxcqWRUry1myxYMQs3S+vKJH7nA5gPPw==","signatures":[{"sig":"MEUCIGI8Q+i8qtsi29M5R8ht6V9lvKGZ8LEpNaPvzbCu0FbOAiEA1n9r+KgaE27ttAwV3Y8bYAWSvGmikSdWub6mV3im0Mk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":9310},"scripts":{"postinstall":"echo 'Run: npx @aicrew/openclaw-otel-patch <openclaw-dir>'"},"_npmUser":{"name":"aicrew","email":"support@aicrew.build"},"repository":{"url":"git+https://github.com/cubanhacker/openclaw-otel-patch.git","type":"git"},"_npmVersion":"10.9.4","description":"OpenClaw OTEL diagnostics patches - fixes bundler listener isolation + adds gen_ai.completion spans","directories":{},"_nodeVersion":"22.22.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/openclaw-otel-patch_1.0.0_1771399135509_0.0704777967709691","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@aicrew/openclaw-otel-patch","version":"1.1.0","keywords":["openclaw","opentelemetry","otel","diagnostics","patch"],"license":"MIT","_id":"@aicrew/openclaw-otel-patch@1.1.0","maintainers":[{"name":"aicrew","email":"support@aicrew.build"}],"homepage":"https://github.com/cubanhacker/openclaw-otel-patch#readme","bugs":{"url":"https://github.com/cubanhacker/openclaw-otel-patch/issues"},"bin":{"openclaw-otel-patch":"apply.sh"},"dist":{"shasum":"e63322662917c33affb3d819dc98900392173b87","tarball":"https://registry.npmjs.org/@aicrew/openclaw-otel-patch/-/openclaw-otel-patch-1.1.0.tgz","fileCount":5,"integrity":"sha512-hFk2m1nNpO+tePAShkTGciu7qzeFA4JXvO3X4NDIQRDGXf6+eGfksDXBXJyGVeTVy7UdQ7dwZYETdWZ2jTLsIg==","signatures":[{"sig":"MEYCIQCjBIfTYjYTFikoMqGCp2LKqVc23+KU8dqMad8wKv+jTAIhAJH1iNnxwtoc8BOpuhEJlxGNlCy9vlX11YYGJBaxWQ8p","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12515},"scripts":{"postinstall":"echo 'Run: npx @aicrew/openclaw-otel-patch <openclaw-dir>'"},"_npmUser":{"name":"aicrew","email":"support@aicrew.build"},"repository":{"url":"git+https://github.com/cubanhacker/openclaw-otel-patch.git","type":"git"},"_npmVersion":"10.9.4","description":"OpenClaw OTEL diagnostics patches - fixes bundler listener isolation + adds gen_ai.completion spans","directories":{},"_nodeVersion":"22.22.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/openclaw-otel-patch_1.1.0_1771399288071_0.28249722911347597","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"name":"@aicrew/openclaw-otel-patch","version":"1.2.0","description":"OpenClaw OTEL diagnostics patches - fixes bundler listener isolation + adds gen_ai.completion spans","bin":{"openclaw-otel-patch":"apply.sh"},"scripts":{"postinstall":"echo 'Run: npx @aicrew/openclaw-otel-patch <openclaw-dir>'"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/cubanhacker/openclaw-otel-patch.git"},"keywords":["openclaw","opentelemetry","otel","diagnostics","patch"],"_id":"@aicrew/openclaw-otel-patch@1.2.0","bugs":{"url":"https://github.com/cubanhacker/openclaw-otel-patch/issues"},"homepage":"https://github.com/cubanhacker/openclaw-otel-patch#readme","_nodeVersion":"22.22.0","_npmVersion":"10.9.4","dist":{"integrity":"sha512-34JV+lHPa8Xp1+LJgmGFs32OomHAcGivFW7X1hUKqsnLOfO14WQSHo7n4bYNNhuJm65QXEMw/qGUse5TByBD4A==","shasum":"b781b100577594ec3144229a7773133fd6a13e23","tarball":"https://registry.npmjs.org/@aicrew/openclaw-otel-patch/-/openclaw-otel-patch-1.2.0.tgz","fileCount":5,"unpackedSize":11561,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCf1QNL2Pnync8VdmRspCsN4MYm7T3PTMY5sH/VFO7HtQIgL+xZzAHKICXH35TAO2P8364fkIpXIQL+kEZoAvO+iDA="}]},"_npmUser":{"name":"aicrew","email":"support@aicrew.build"},"directories":{},"maintainers":[{"name":"aicrew","email":"support@aicrew.build"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/openclaw-otel-patch_1.2.0_1771401458996_0.3467730269027376"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-18T07:18:55.443Z","modified":"2026-02-18T07:57:39.568Z","1.0.0":"2026-02-18T07:18:55.669Z","1.1.0":"2026-02-18T07:21:28.225Z","1.2.0":"2026-02-18T07:57:39.154Z"},"bugs":{"url":"https://github.com/cubanhacker/openclaw-otel-patch/issues"},"license":"MIT","homepage":"https://github.com/cubanhacker/openclaw-otel-patch#readme","keywords":["openclaw","opentelemetry","otel","diagnostics","patch"],"repository":{"type":"git","url":"git+https://github.com/cubanhacker/openclaw-otel-patch.git"},"description":"OpenClaw OTEL diagnostics patches - fixes bundler listener isolation + adds gen_ai.completion spans","maintainers":[{"name":"aicrew","email":"support@aicrew.build"}],"readme":"# @aicrew/openclaw-otel-patch\n\nPatches for OpenClaw's `diagnostics-otel` plugin to fix telemetry export and add GenAI semantic convention spans.\n\n## What It Fixes\n\n### 1. Bundler Listener Isolation (Critical)\nThe 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.\n\n**Fix:** Share listeners via `globalThis.__openclaw_diag_listeners`.\n\nRelated: [openclaw/openclaw#5190](https://github.com/openclaw/openclaw/issues/5190), [PR #11168](https://github.com/openclaw/openclaw/pull/11168)\n\n### 2. GenAI Semantic Convention Spans\nAdds `gen_ai.completion` trace spans following the [OpenTelemetry GenAI Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/), including:\n- `gen_ai.system`, `gen_ai.response.model`, `gen_ai.request.model`\n- `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`\n- `gen_ai.usage.cache_read_tokens`, `gen_ai.usage.cache_write_tokens`\n- `openclaw.cost.usd`\n\nRelated: [PR #11100](https://github.com/openclaw/openclaw/pull/11100)\n\n## Compatibility\n\n- **Base:** OpenClaw v2026.2.18 (`fa4772b4ce`)\n- **Node.js:** 22+\n\n## Usage\n\n```bash\n# Install globally\nnpm install -g @aicrew/openclaw-otel-patch\n\n# Apply to your OpenClaw installation\nopenclaw-otel-patch ~/openclaw\n\n# Hard restart (required — SIGUSR1 won't reinitialize OTEL SDK)\nopenclaw gateway stop && openclaw gateway start\n```\n\n## Required Config\n\nAdd to `~/.openclaw/openclaw.json`:\n\n```json\n{\n  \"diagnostics\": {\n    \"enabled\": true,\n    \"otel\": {\n      \"enabled\": true,\n      \"endpoint\": \"https://your-otlp-endpoint\",\n      \"protocol\": \"http/protobuf\",\n      \"serviceName\": \"your-service-name\",\n      \"traces\": true,\n      \"metrics\": true,\n      \"logs\": true,\n      \"flushIntervalMs\": 5000\n    }\n  },\n  \"models\": {\n    \"providers\": {\n      \"anthropic\": {\n        \"models\": [\n          { \"id\": \"claude-opus-4-6\", \"cost\": { \"input\": 15, \"output\": 75, \"cacheRead\": 1.5, \"cacheWrite\": 18.75 } },\n          { \"id\": \"claude-sonnet-4-6\", \"cost\": { \"input\": 3, \"output\": 15, \"cacheRead\": 0.3, \"cacheWrite\": 3.75 } },\n          { \"id\": \"claude-haiku-3-5\", \"cost\": { \"input\": 0.8, \"output\": 4, \"cacheRead\": 0.08, \"cacheWrite\": 1 } }\n        ]\n      }\n    }\n  }\n}\n```\n\n## Metrics Exported\n\n| Metric | Description |\n|--------|-------------|\n| `openclaw.tokens` | Token counts by type (input/output/cache_read/cache_write/total) |\n| `openclaw.cost.usd` | Estimated USD cost per model call |\n| `openclaw.run.duration_ms` | Agent run duration |\n| `openclaw.context.tokens` | Context window usage |\n| `openclaw.message.queued` | Messages queued |\n| `openclaw.message.processed` | Messages processed by outcome |\n| `openclaw.queue.depth` | Queue depth |\n| `openclaw.queue.lane.enqueue` | Lane enqueue events |\n| `openclaw.session.state` | Session state transitions |\n\n## Traces Exported\n\n| Span | Description |\n|------|-------------|\n| `gen_ai.completion` | GenAI semantic convention span with token/cost attributes |\n| `openclaw.model.usage` | Legacy span with session/token details |\n| `openclaw.webhook.processed` | Webhook processing spans |\n| `openclaw.message.processed` | Message processing spans |\n\n## ⚠️ Notes\n\n- **Dist patches are fragile** — re-run after any `pnpm build` or OpenClaw update\n- The resource attributes (agent ID, org ID) are hardcoded — edit `service.ts` for your own values\n- Once [PR #11168](https://github.com/openclaw/openclaw/pull/11168) merges, the dist patch becomes unnecessary\n- Once [PR #11100](https://github.com/openclaw/openclaw/pull/11100) merges, the gen_ai spans will be built-in with full tool tracing\n\n## License\n\nMIT\n","readmeFilename":"README.md"}