@cnpinsight/cnpclawinsights 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +246 -0
- package/dist/api.js +4 -0
- package/dist/index.js +1611 -0
- package/openclaw.plugin.json +100 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# @cnpinsight/cnpclawinsights
|
|
2
|
+
|
|
3
|
+
`@cnpinsight/cnpclawinsights` 是一个 OpenClaw 插件,用于把 OpenClaw 产生的 trace、log、metrics 指标通过 OTLP HTTP/Protobuf 导出到 `otel-collector`。
|
|
4
|
+
|
|
5
|
+
插件读取 `openclaw.json` 中的 `cnpclawinsights` 配置,配置结构参考 `diagnostics`。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
通过 OpenClaw 安装插件:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
openclaw plugins install @cnpinsight/cnpclawinsights
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
如果需要指定版本:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
openclaw plugins install @cnpinsight/cnpclawinsights@2.0.0
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 最小配置
|
|
22
|
+
|
|
23
|
+
在 `openclaw.json` 中添加:
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"cnpclawinsights": {
|
|
28
|
+
"enabled": true,
|
|
29
|
+
"otel": {
|
|
30
|
+
"enabled": true,
|
|
31
|
+
"endpoint": "http://127.0.0.1:4318"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
这个最小配置下:
|
|
38
|
+
|
|
39
|
+
- `traces` 默认开启
|
|
40
|
+
- `metrics` 默认开启
|
|
41
|
+
- `logs` 默认关闭
|
|
42
|
+
- OTLP 协议默认使用 `http/protobuf`
|
|
43
|
+
|
|
44
|
+
## 完整配置示例
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"cnpclawinsights": {
|
|
49
|
+
"enabled": true,
|
|
50
|
+
"otel": {
|
|
51
|
+
"enabled": true,
|
|
52
|
+
"protocol": "http/protobuf",
|
|
53
|
+
"endpoint": "http://127.0.0.1:4318",
|
|
54
|
+
"traces": true,
|
|
55
|
+
"metrics": true,
|
|
56
|
+
"logs": true,
|
|
57
|
+
"serviceName": "openclaw",
|
|
58
|
+
"sampleRate": 1,
|
|
59
|
+
"flushIntervalMs": 5000,
|
|
60
|
+
"headers": {
|
|
61
|
+
"Authorization": "Bearer <token>"
|
|
62
|
+
},
|
|
63
|
+
"captureContent": {
|
|
64
|
+
"enabled": true,
|
|
65
|
+
"inputMessages": true,
|
|
66
|
+
"outputMessages": true,
|
|
67
|
+
"toolInputs": false,
|
|
68
|
+
"toolOutputs": false,
|
|
69
|
+
"systemPrompt": false
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
如果你希望按信号单独配置 endpoint,也可以这样写:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"cnpclawinsights": {
|
|
81
|
+
"enabled": true,
|
|
82
|
+
"otel": {
|
|
83
|
+
"enabled": true,
|
|
84
|
+
"tracesEndpoint": "http://127.0.0.1:4318/v1/traces",
|
|
85
|
+
"metricsEndpoint": "http://127.0.0.1:4318/v1/metrics",
|
|
86
|
+
"logsEndpoint": "http://127.0.0.1:4318/v1/logs",
|
|
87
|
+
"logs": true
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## 配置说明
|
|
94
|
+
|
|
95
|
+
`cnpclawinsights.enabled`
|
|
96
|
+
|
|
97
|
+
- 是否启用插件本身
|
|
98
|
+
- 必须为 `true`
|
|
99
|
+
|
|
100
|
+
`cnpclawinsights.otel.enabled`
|
|
101
|
+
|
|
102
|
+
- 是否启用 OTel 导出
|
|
103
|
+
- 必须为 `true`
|
|
104
|
+
|
|
105
|
+
`cnpclawinsights.otel.protocol`
|
|
106
|
+
|
|
107
|
+
- 目前只支持 `http/protobuf`
|
|
108
|
+
- 不配置时默认也是 `http/protobuf`
|
|
109
|
+
|
|
110
|
+
`cnpclawinsights.otel.endpoint`
|
|
111
|
+
|
|
112
|
+
- 通用 OTLP endpoint
|
|
113
|
+
- 例如 `http://127.0.0.1:4318`
|
|
114
|
+
- 如果不带 `/v1/traces`、`/v1/metrics`、`/v1/logs`,插件会自动补全对应路径
|
|
115
|
+
|
|
116
|
+
`cnpclawinsights.otel.traces`
|
|
117
|
+
|
|
118
|
+
- 是否导出 traces
|
|
119
|
+
- 默认 `true`
|
|
120
|
+
|
|
121
|
+
`cnpclawinsights.otel.metrics`
|
|
122
|
+
|
|
123
|
+
- 是否导出 metrics
|
|
124
|
+
- 默认 `true`
|
|
125
|
+
|
|
126
|
+
`cnpclawinsights.otel.logs`
|
|
127
|
+
|
|
128
|
+
- 是否导出 logs
|
|
129
|
+
- 默认 `false`
|
|
130
|
+
|
|
131
|
+
`cnpclawinsights.otel.tracesEndpoint`
|
|
132
|
+
|
|
133
|
+
- 单独指定 traces 导出地址
|
|
134
|
+
- 优先级高于 `endpoint`
|
|
135
|
+
|
|
136
|
+
`cnpclawinsights.otel.metricsEndpoint`
|
|
137
|
+
|
|
138
|
+
- 单独指定 metrics 导出地址
|
|
139
|
+
- 优先级高于 `endpoint`
|
|
140
|
+
|
|
141
|
+
`cnpclawinsights.otel.logsEndpoint`
|
|
142
|
+
|
|
143
|
+
- 单独指定 logs 导出地址
|
|
144
|
+
- 优先级高于 `endpoint`
|
|
145
|
+
|
|
146
|
+
`cnpclawinsights.otel.serviceName`
|
|
147
|
+
|
|
148
|
+
- OpenTelemetry service name
|
|
149
|
+
- 不配置时优先读取环境变量 `OTEL_SERVICE_NAME`
|
|
150
|
+
- 如果环境变量也没有,默认值是 `openclaw`
|
|
151
|
+
|
|
152
|
+
`cnpclawinsights.otel.sampleRate`
|
|
153
|
+
|
|
154
|
+
- trace 采样率
|
|
155
|
+
- 取值范围 `0` 到 `1`
|
|
156
|
+
|
|
157
|
+
`cnpclawinsights.otel.flushIntervalMs`
|
|
158
|
+
|
|
159
|
+
- metrics 周期导出间隔
|
|
160
|
+
- 也用于 logs 批量刷新间隔
|
|
161
|
+
- 最小值为 `1000`
|
|
162
|
+
|
|
163
|
+
`cnpclawinsights.otel.headers`
|
|
164
|
+
|
|
165
|
+
- OTLP 请求头
|
|
166
|
+
- 适合传认证信息
|
|
167
|
+
|
|
168
|
+
`cnpclawinsights.otel.captureContent`
|
|
169
|
+
|
|
170
|
+
- 控制是否导出消息内容
|
|
171
|
+
- 默认不采集正文内容
|
|
172
|
+
|
|
173
|
+
`cnpclawinsights.otel.captureContent = true`
|
|
174
|
+
|
|
175
|
+
- 开启后会采集:
|
|
176
|
+
- `inputMessages`
|
|
177
|
+
- `outputMessages`
|
|
178
|
+
- `toolInputs`
|
|
179
|
+
- `toolOutputs`
|
|
180
|
+
- `systemPrompt` 仍默认不采集
|
|
181
|
+
|
|
182
|
+
`cnpclawinsights.otel.captureContent = { ... }`
|
|
183
|
+
|
|
184
|
+
- 可以按字段精细控制:
|
|
185
|
+
- `enabled`
|
|
186
|
+
- `inputMessages`
|
|
187
|
+
- `outputMessages`
|
|
188
|
+
- `toolInputs`
|
|
189
|
+
- `toolOutputs`
|
|
190
|
+
- `systemPrompt`
|
|
191
|
+
|
|
192
|
+
## 环境变量回退
|
|
193
|
+
|
|
194
|
+
如果部分配置未写入 `openclaw.json`,插件还会回退读取这些标准 OTel 环境变量:
|
|
195
|
+
|
|
196
|
+
- `OTEL_EXPORTER_OTLP_PROTOCOL`
|
|
197
|
+
- `OTEL_EXPORTER_OTLP_ENDPOINT`
|
|
198
|
+
- `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`
|
|
199
|
+
- `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`
|
|
200
|
+
- `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`
|
|
201
|
+
- `OTEL_SERVICE_NAME`
|
|
202
|
+
|
|
203
|
+
## 常见问题
|
|
204
|
+
|
|
205
|
+
### 1. 插件安装时报 package not found
|
|
206
|
+
|
|
207
|
+
请确认安装名使用的是:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
@cnpinsight/cnpclawinsights
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
不要写成其他名字。
|
|
214
|
+
|
|
215
|
+
### 2. 为什么没有日志
|
|
216
|
+
|
|
217
|
+
`logs` 默认关闭,需要显式配置:
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"cnpclawinsights": {
|
|
222
|
+
"enabled": true,
|
|
223
|
+
"otel": {
|
|
224
|
+
"enabled": true,
|
|
225
|
+
"endpoint": "http://127.0.0.1:4318",
|
|
226
|
+
"logs": true
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### 3. 为什么配置了但没有导出
|
|
233
|
+
|
|
234
|
+
请同时确认下面两个开关都为 `true`:
|
|
235
|
+
|
|
236
|
+
```json
|
|
237
|
+
{
|
|
238
|
+
"cnpclawinsights": {
|
|
239
|
+
"enabled": true,
|
|
240
|
+
"otel": {
|
|
241
|
+
"enabled": true
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { emptyPluginConfigSchema } from "openclaw/plugin-sdk/plugin-entry";
|
|
2
|
+
import { createChildDiagnosticTraceContext, createDiagnosticTraceContext, emitDiagnosticEvent, formatDiagnosticTraceparent, isValidDiagnosticSpanId, isValidDiagnosticTraceFlags, isValidDiagnosticTraceId, onDiagnosticEvent, parseDiagnosticTraceparent } from "openclaw/plugin-sdk/diagnostic-runtime";
|
|
3
|
+
import { redactSensitiveText } from "openclaw/plugin-sdk/security-runtime";
|
|
4
|
+
export { createChildDiagnosticTraceContext, createDiagnosticTraceContext, emitDiagnosticEvent, emptyPluginConfigSchema, formatDiagnosticTraceparent, isValidDiagnosticSpanId, isValidDiagnosticTraceFlags, isValidDiagnosticTraceId, onDiagnosticEvent, parseDiagnosticTraceparent, redactSensitiveText };
|