ai-otel-setup 1.0.9 → 1.0.10

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.
Files changed (3) hide show
  1. package/LICENSE +17 -16
  2. package/cli.js +54 -28
  3. package/package.json +1 -1
package/LICENSE CHANGED
@@ -1,20 +1,21 @@
1
- Proprietary License - iFlyTek BG Internal
1
+ MIT License
2
2
 
3
- Copyright (c) 2026 iFlyTek BG Productivity. All rights reserved.
3
+ Copyright (c) 2026 decent-yu
4
4
 
5
- The source code in this repository is visible publicly to enable installation
6
- via `npx github:decent-yu/cc-otel-setup` from corporate machines. Visibility
7
- does NOT grant any license to use, modify, distribute, or sublicense the code
8
- outside of authorized iFlyTek internal contexts.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
9
11
 
10
- Permitted use:
11
- - Running the installer (`npx -y github:decent-yu/cc-otel-setup ...`)
12
- on machines authorized to send observability data to iFlyTek-internal
13
- OTel collectors.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
14
 
15
- Prohibited without prior written permission:
16
- - Copying, forking, vendoring the source for non-iFlyTek deployments
17
- - Republishing under a different name or marketplace
18
- - Embedding the code in third-party products
19
-
20
- For licensing questions: productivity@iflytek.example
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/cli.js CHANGED
@@ -187,25 +187,19 @@ function readGlobalGitUser() {
187
187
  };
188
188
  }
189
189
 
190
- // ---------- 装机上报到 cc-view-server ----------
190
+ // ---------- 装机上报:走同一条 OTel 管线 ----------
191
+ //
192
+ // 历史:原 POST 到 cc-view-server :8081/api/installer/report 直写 Doris。
193
+ // otel-prod 部署到公网、cc-view-web 留在内网后,installer 只能跟 OTel collector
194
+ // 说话;改成发一条 OTLP/HTTP log(event.name = installer_register),由 forwarder
195
+ // 走同一条管线落到 iData,cc-view-server 端从事件表 reduce 出装机记录。
196
+ // 这样 installer 命令依旧只暴露一个 url,跟数据上报完全同源。
191
197
  //
192
- // 安装完成时打一发 POST 到 cc-view-server,让运营侧能看到"谁/在哪台机/装了哪个版本"。
193
198
  // 设计原则:
194
- // - fire-and-forget:3s 超时、不重试、任何失败绝不让安装本身退出非 0
195
- // - 复用用户传给 OTel collector 的 host:172.31.250.57port 8081 写死
196
- // - URL 本身是公司内网地址,自带隐式凭据,不带 SSO header
199
+ // - fire-and-forget:2.5s 超时、不重试、任何失败绝不让安装本身退出非 0
200
+ // - 复用 logsEndpointFromGrpc:4317 4318path 自动补 /v1/logs
197
201
  // - debug 模式下才打错误,正常运行不污染 stdout
198
202
 
199
- function buildReportUrl(otelEndpoint) {
200
- try {
201
- const u = new URL(otelEndpoint);
202
- // cc-view-server 跑在同机 :8081(与 collector 4317/4318 同主机)
203
- return `http://${u.hostname}:8081/api/installer/report`;
204
- } catch (_) {
205
- return null;
206
- }
207
- }
208
-
209
203
  function postJsonWithTimeout(targetUrl, payload, timeoutMs) {
210
204
  return new Promise((resolve, reject) => {
211
205
  let u;
@@ -250,24 +244,56 @@ async function reportInstall(otelEndpoint, gitUser, allResults, debug) {
250
244
  if (debug) console.error("[ai-otel-setup] 跳过装机上报:无 git user.email");
251
245
  return;
252
246
  }
253
- const reportUrl = buildReportUrl(otelEndpoint);
254
- if (!reportUrl) return;
247
+ const logsUrl = logsEndpointFromGrpc(otelEndpoint);
248
+ if (!logsUrl) return;
255
249
  const findOk = (tool) =>
256
250
  allResults.find((r) => r.tool === tool)?.status === "installed";
251
+
252
+ // OTLP/HTTP log record。translator (lib/translate/installer_register.js) 按
253
+ // event.name = "installer_register" 路由到对应 eid,把 git.user.* / hostname
254
+ // 经 contextBlocksFromAttrs 落进 user 块,installer_* / os_* / node_version /
255
+ // *_cli_detected 走 phase1UdmapFields 白名单进 udmap。
256
+ const sessionId = `installer-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
257
+ const attrs = {
258
+ "tool_kind": "installer",
259
+ "event.name": "installer_register",
260
+ "event.timestamp": new Date().toISOString(),
261
+ "session.id": sessionId,
262
+ "git.user.email": gitUser.email,
263
+ "git.user.name": gitUser.name || "",
264
+ "hostname": os.hostname() || "",
265
+ "installer_version": PKG_VERSION,
266
+ "os_platform": os.platform(),
267
+ "os_arch": os.arch(),
268
+ "node_version": process.version,
269
+ "cc_cli_detected": findOk("claude") ? "1" : "0",
270
+ "codex_cli_detected": findOk("codex") ? "1" : "0",
271
+ };
257
272
  const payload = {
258
- git_email: gitUser.email,
259
- git_name: gitUser.name || "",
260
- hostname: os.hostname(),
261
- installer_version: PKG_VERSION,
262
- os_platform: os.platform(),
263
- os_arch: os.arch(),
264
- node_version: process.version,
265
- cc_cli_detected: findOk("claude") ? 1 : 0,
266
- codex_cli_detected: findOk("codex") ? 1 : 0,
273
+ resourceLogs: [
274
+ {
275
+ resource: { attributes: [] },
276
+ scopeLogs: [
277
+ {
278
+ logRecords: [
279
+ {
280
+ timeUnixNano: `${Date.now()}000000`,
281
+ body: { stringValue: "installer_register" },
282
+ attributes: Object.entries(attrs).map(([k, v]) => ({
283
+ key: k,
284
+ value: { stringValue: String(v ?? "") },
285
+ })),
286
+ },
287
+ ],
288
+ },
289
+ ],
290
+ },
291
+ ],
267
292
  };
293
+
268
294
  try {
269
- await postJsonWithTimeout(reportUrl, payload, 3000);
270
- if (debug) console.error("[ai-otel-setup] 装机上报已发送");
295
+ await postJsonWithTimeout(logsUrl, payload, 2500);
296
+ if (debug) console.error("[ai-otel-setup] 装机上报已发送", logsUrl);
271
297
  } catch (e) {
272
298
  if (debug) {
273
299
  console.error("[ai-otel-setup] 装机上报失败(不影响安装):", e.message || e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-otel-setup",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "One-shot installer for AI CLI OpenTelemetry forwarding. Writes Claude Code, Codex CLI, and Gemini CLI telemetry config in a single npx command.",
5
5
  "bin": {
6
6
  "ai-otel-setup": "cli.js",