ai-otel-setup 1.0.2 → 1.0.3

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/cli.js CHANGED
@@ -432,6 +432,15 @@ function main() {
432
432
  fs.copyFileSync(hookScriptSrc, hookScriptDest);
433
433
  fs.chmodSync(hookScriptDest, 0o755);
434
434
 
435
+ // v1.0.3:把 endpoint 写盘,给 hook 脚本的 resolveLogsEndpoint 当兜底。
436
+ // 修的是 v1.0.2 的真实事故:settings.json 的 env 不一定能继承到 hook 子进程
437
+ // (Windows / 已运行的 CC 实例都会踩到),导致 hook fallback 到 localhost
438
+ // 拿 ECONNREFUSED 静默失败、marker 已写但 POST 永不到达。
439
+ writeJSONAtomic(path.join(installDir, "endpoint.json"), {
440
+ endpoint,
441
+ logsEndpoint: logsEndpointFromGrpc(endpoint),
442
+ });
443
+
435
444
  const existing = readJSONSafe(settingsPath);
436
445
  const bak = backup(settingsPath);
437
446
  const merged = mergeSettings(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-otel-setup",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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",
@@ -44,13 +44,30 @@ const PROMPT_THROTTLE_MS = 5 * 60 * 1000;
44
44
  * 优先级:
45
45
  * 1. 显式 OTEL_EXPORTER_OTLP_LOGS_ENDPOINT(用户指定 logs 端点)
46
46
  * 2. OTEL_EXPORTER_OTLP_ENDPOINT(通用端点,自动补 /v1/logs,把 4317 换成 4318)
47
- * 3. fallback http://localhost:4318/v1/logs
47
+ * 3. installer 写盘的 ~/.claude/cc-otel/endpoint.json(救 CC 父进程未传 env 的场景;
48
+ * v1.0.2 实测 settings.json 的 env 不一定继承到 hook 子进程,导致 fallback 到
49
+ * localhost 后 ECONNREFUSED 静默失败)
50
+ * 4. fallback http://localhost:4318/v1/logs
48
51
  */
49
52
  function resolveLogsEndpoint() {
50
53
  const logsEndpoint = process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT;
51
54
  if (logsEndpoint) return logsEndpoint;
52
55
 
53
- const base = process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4317";
56
+ let base = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
57
+
58
+ // env 没拿到 → 读 installer 写的 endpoint.json
59
+ if (!base) {
60
+ try {
61
+ const cfgPath = path.join(os.homedir(), ".claude", "cc-otel", "endpoint.json");
62
+ const cfg = JSON.parse(fs.readFileSync(cfgPath, "utf8"));
63
+ if (cfg && cfg.logsEndpoint) return cfg.logsEndpoint;
64
+ if (cfg && cfg.endpoint) base = cfg.endpoint;
65
+ } catch (_) {
66
+ // 文件不存在或解析失败:继续走 localhost fallback,与历史行为一致
67
+ }
68
+ }
69
+
70
+ if (!base) base = "http://localhost:4317";
54
71
  const url = new URL(base);
55
72
  // gRPC 默认 4317 → OTLP/HTTP 默认 4318
56
73
  if (url.port === "4317") url.port = "4318";