@akilium/telemetry-collector 0.1.0 → 0.1.1

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 CHANGED
@@ -18,10 +18,20 @@ Use a source-approved HTTPS completion receiver URL and pass its one-time enroll
18
18
  printf '%s' "$AKILA_CODEX_TOKEN" | akilium-telemetry enroll --endpoint https://YOUR_PROJECT.supabase.co/functions/v1/codex-usage-ingestion/v1/logs
19
19
  ```
20
20
 
21
- The CLI validates the URL and token, writes `akila-forwarding.env` with mode 0600, preserves unrelated variables, and never prints the credential. New overlays use the identity-free v1 mapping by default. Specify `--mapping v2` only for a source already approved for v2 identity hints; existing custom overlays are preserved and must be reviewed manually before changing mappings. Docker Compose mounts the allowlisted, metadata-only `akila-forwarding.yaml`; native services use a local launcher that reads the protected environment file. Enroll does not restart a running collector. Rotate by running `enroll` again with a new authorized token, then restart the service and check hosted connection health. Action lineage uses a separate capability-bound receiver and the `@akilium/instrumentation` SDK token; a completion credential cannot authorize action reports.
21
+ The CLI validates the URL and token, writes `akila-forwarding.env` with mode 0600, preserves unrelated variables, and never prints the credential. New overlays use the identity-free v1 mapping by default. Specify `--mapping v2` only for a source already approved for v2 identity hints; existing custom overlays are preserved and must be reviewed manually before changing mappings. Docker Compose mounts the allowlisted, metadata-only `akila-forwarding.yaml`; native services use a local launcher that reads the protected environment file. Enroll does not restart a running collector. Rotate by running `enroll` again with a new authorized token, then restart the service and check hosted connection health.
22
+
23
+ ## Codex action attempts
24
+
25
+ After the source and connection are active, issue a separate action capture token from the Codex connection controls. Read it without echo and enroll it independently:
26
+
27
+ ```sh
28
+ printf 'Lineage token: '; read -r -s AKILA_LINEAGE_TOKEN; printf '\n'; printf '%s' "$AKILA_LINEAGE_TOKEN" | npx --yes @akilium/telemetry-collector@0.1.1 enroll-lineage --endpoint https://YOUR_PROJECT.supabase.co/functions/v1/codex-lineage-otel-ingestion; unset AKILA_LINEAGE_TOKEN
29
+ ```
30
+
31
+ Restart the collector after enrollment. The second pipeline forwards only Codex `tool_result` records to the capability-bound lineage receiver. It retains the call ID, completion time, duration, success state, and Codex service version; arguments, output, prompts, resource identifiers, and tool names are dropped before export. Each tool result becomes a completed action attempt, including attempts with no durable artifact. The completion credential is never accepted by this receiver.
22
32
 
23
33
  ## Operational limits and diagnostics, v1
24
34
 
25
- The Collector retains local rotated archive files for seven days with up to 20 backups of 10 MiB each per signal. File-backed queue storage is capped at 64 MiB. Newly rendered generic forwarding uses a 1,000-entry queue and a one-hour retry window; inherited custom configurations keep their existing settings until reviewed. The Codex completion overlay forwards only allowlisted metadata after dropping bodies, resource and scope attributes. The receiver independently enforces privacy and authorization.
35
+ The Collector retains local rotated archive files for seven days with up to 20 backups of 10 MiB each per signal. Local log capture drops bodies and known prompt, argument, output, and identity attributes before archiving. File-backed queue storage is capped at 64 MiB. Newly rendered generic forwarding uses a 1,000-entry queue and a one-hour retry window; inherited custom configurations keep their existing settings until reviewed. The Codex completion and action overlays forward separate allowlisted metadata after dropping bodies and unapproved attributes. Each receiver independently enforces privacy and authorization.
26
36
 
27
- The SDK's action export queue is in memory: 128 reports, one-hour expiry, exponential retries capped at a 60-second delay by default. `lineage.status()` exposes queued, dropped, accepted, duplicate, rejected, and unavailable counts; `lineage.flush()` retries due reports. Process exit or queue overflow can lose reports. `akilium-telemetry status` shows local service/archive state, while hosted receipt, normalization, and artifact linkage remain explicitly unknown until checked through their respective Akila health/read surfaces. `doctor` checks only local OTLP receipt and archive capture.
37
+ The SDK's action export queue is in memory: 128 reports, one-hour expiry, exponential retries capped at a 60-second delay by default. `lineage.status()` exposes queued, dropped, accepted, duplicate, rejected, and unavailable counts; `lineage.flush()` retries due reports. Process exit or queue overflow can lose SDK reports. The Codex OTel action pipeline uses the Collector's persistent file-backed queue and retries for up to one hour. `akilium-telemetry status` shows local service/archive state, while hosted receipt, normalization, and artifact linkage remain explicitly unknown until checked through their respective Akila health/read surfaces. `doctor` checks only local OTLP receipt and archive capture.
@@ -263,11 +263,12 @@ function enroll() {
263
263
  const token = readFileSync(0, "utf8").trim();
264
264
  if (!/^[A-Za-z0-9_-]{32,128}$/.test(token)) throw new Error("Invalid enrollment token on stdin");
265
265
  backupExisting(manifest);
266
- if (!existsSync(overlay)) atomicWrite(overlay, renderAkilaForwarding(mappingVersion));
266
+ const previous = existsSync(envFile) ? readFileSync(envFile, "utf8").split("\n") : [];
267
+ const hasLineage = previous.some((line) => line.startsWith("AKILA_LINEAGE_TOKEN="));
268
+ if (!existsSync(overlay) || hasLineage) atomicWrite(overlay, renderAkilaForwarding(mappingVersion, hasLineage));
267
269
  if (manifest.mode === "docker" && (!currentCompose || currentCompose === plainCompose))
268
270
  atomicWrite(p.compose, renderCompose(p.root, true));
269
271
  // Replace only our protected variables. No credential value is printed or stored in the manifest.
270
- const previous = existsSync(envFile) ? readFileSync(envFile, "utf8").split("\n") : [];
271
272
  const retained = previous.filter((line) => line && !/^AKILA_(INGESTION_ENDPOINT|CODEX_TOKEN)=/.test(line));
272
273
  atomicWrite(envFile, [...retained, `AKILA_INGESTION_ENDPOINT=${url.toString()}`,
273
274
  `AKILA_CODEX_TOKEN=${token}`, ""].join("\n"));
@@ -281,6 +282,36 @@ function enroll() {
281
282
  console.log("Protected completion forwarding configured; restart the collector and check hosted acceptance");
282
283
  }
283
284
 
285
+ function enrollLineage() {
286
+ const manifest = readJson(p.manifest);
287
+ if (!manifest) throw new Error("Install or migrate the collector first");
288
+ const endpoint = option("--endpoint");
289
+ if (!endpoint) throw new Error("--endpoint is required");
290
+ const url = new URL(endpoint);
291
+ if (url.protocol !== "https:" || url.username || url.password || url.search || url.hash ||
292
+ !url.pathname.endsWith("/functions/v1/codex-lineage-otel-ingestion")) {
293
+ throw new Error("Enrollment requires a verified HTTPS Codex lineage OTel receiver URL");
294
+ }
295
+ const envFile = join(p.root, "akila-forwarding.env");
296
+ const overlay = join(p.root, "akila-forwarding.yaml");
297
+ if (!existsSync(envFile) || !existsSync(overlay)) throw new Error("Configure completion forwarding before lineage forwarding");
298
+ const lines = readFileSync(envFile, "utf8").split("\n");
299
+ if (!lines.some((line) => line.startsWith("AKILA_CODEX_TOKEN="))) throw new Error("Completion forwarding enrollment is incomplete");
300
+ const token = readFileSync(0, "utf8").trim();
301
+ if (!/^[A-Za-z0-9_-]{32,128}$/.test(token)) throw new Error("Invalid lineage enrollment token on stdin");
302
+ const oldConfig = readFileSync(overlay, "utf8");
303
+ const mappingVersion = oldConfig.includes('"user.account_id"') ? "v2" : "v1";
304
+ backupExisting(manifest);
305
+ atomicWrite(overlay, renderAkilaForwarding(mappingVersion, true));
306
+ const retained = lines.filter((line) => line && !/^AKILA_LINEAGE_(ENDPOINT|TOKEN)=/.test(line));
307
+ atomicWrite(envFile, [...retained, `AKILA_LINEAGE_ENDPOINT=${url.toString()}`,
308
+ `AKILA_LINEAGE_TOKEN=${token}`, ""].join("\n"));
309
+ chmodSync(envFile, 0o600);
310
+ manifest.akilaLineageForwarding = true;
311
+ saveManifest(manifest);
312
+ console.log("Protected action-lineage forwarding configured; restart the collector and check hosted lineage coverage");
313
+ }
314
+
284
315
  function setDestination() {
285
316
  const manifest = readJson(p.manifest);
286
317
  if (!manifest) throw new Error("Install the collector first");
@@ -393,12 +424,13 @@ try {
393
424
  else if (action === "upgrade") await upgrade();
394
425
  else if (action === "rollback") rollback();
395
426
  else if (action === "enroll") enroll();
427
+ else if (action === "enroll-lineage") enrollLineage();
396
428
  else if (action === "configure") installAgents(readJson(p.manifest) || (() => { throw new Error("Install the collector first"); })());
397
429
  else if (action === "set-destination") setDestination();
398
430
  else if (action === "status") status();
399
431
  else if (action === "doctor") await doctor();
400
432
  else if (action === "uninstall") uninstall();
401
- else if (action === "help") console.log("Usage: akilium-telemetry <install|migrate|enroll|configure|status|doctor|upgrade|rollback|set-destination|uninstall> [--mode native|docker] [--agents codex,claude] [--endpoint URL|--clear] [--mapping v1|v2]; enroll reads token from stdin");
433
+ else if (action === "help") console.log("Usage: akilium-telemetry <install|migrate|enroll|enroll-lineage|configure|status|doctor|upgrade|rollback|set-destination|uninstall> [--mode native|docker] [--agents codex,claude] [--endpoint URL|--clear] [--mapping v1|v2]; enroll and enroll-lineage read tokens from stdin");
402
434
  else throw new Error(`Unknown action: ${action}`);
403
435
  } catch (error) {
404
436
  if (!quiet) console.error(`agent-telemetry: ${error.message}`);
@@ -10,7 +10,7 @@ if ((stat.mode & 0o077) !== 0) throw new Error("Collector enrollment file must b
10
10
  const env = { ...process.env };
11
11
  for (const line of readFileSync(envFile, "utf8").split("\n")) {
12
12
  if (!line) continue;
13
- const match = /^(AKILA_INGESTION_ENDPOINT|AKILA_CODEX_TOKEN)=(.*)$/.exec(line);
13
+ const match = /^(AKILA_INGESTION_ENDPOINT|AKILA_CODEX_TOKEN|AKILA_LINEAGE_ENDPOINT|AKILA_LINEAGE_TOKEN)=(.*)$/.exec(line);
14
14
  if (match) env[match[1]] = match[2];
15
15
  }
16
16
  if (!env.AKILA_INGESTION_ENDPOINT || !env.AKILA_CODEX_TOKEN) throw new Error("Collector enrollment is incomplete");
@@ -61,8 +61,8 @@ export function renderCollector(destination = null, dataDir = "/data", bindHost
61
61
  const archive = `${dataDir}/archive`;
62
62
  const receiver = destination ? SIGNALS.map((signal) => ` otlp_json_file/${signal}:\n include: [${quoteYaml(`${archive}/${signal}*.json`)}]\n start_at: beginning\n storage: file_storage\n include_file_name: false`).join("\n") : "";
63
63
  const forwarding = destination ? ` otlp_http/forward:\n endpoint: ${quoteYaml(destination)}\n sending_queue:\n enabled: true\n storage: file_storage\n queue_size: 1000\n retry_on_failure:\n enabled: true\n max_elapsed_time: 1h\n` : "";
64
- const pipelines = SIGNALS.map((signal) => ` ${signal}/capture:\n receivers: [otlp]\n processors: [memory_limiter, batch]\n exporters: [file/${signal}]${destination ? `\n ${signal}/forward:\n receivers: [otlp_json_file/${signal}]\n processors: [memory_limiter, batch]\n exporters: [otlp_http/forward]` : ""}`).join("\n");
65
- return `# Generated by Akilium agent-telemetry. Edit via the CLI.\nreceivers:\n otlp:\n protocols:\n grpc:\n endpoint: ${bindHost}:4317\n http:\n endpoint: ${bindHost}:4318\n${receiver ? receiver + "\n" : ""}processors:\n memory_limiter:\n check_interval: 1s\n limit_mib: 256\n spike_limit_mib: 64\n batch:\n timeout: 1s\nexporters:\n${SIGNALS.map((signal) => ` file/${signal}:\n path: ${quoteYaml(`${archive}/${signal}.json`)}\n create_directory: true\n rotation:\n max_megabytes: 10\n max_days: 7\n max_backups: 20`).join("\n")}\n${forwarding}extensions:\n file_storage:\n directory: ${quoteYaml(storage)}\n max_size: 67108864\n create_directory: true\n health_check:\n endpoint: 127.0.0.1:13133\nservice:\n extensions: [file_storage, health_check]\n pipelines:\n${pipelines}\n`;
64
+ const pipelines = SIGNALS.map((signal) => ` ${signal}/capture:\n receivers: [otlp]\n processors: [memory_limiter, ${signal === "logs" ? "transform/redact_log_content, " : ""}batch]\n exporters: [file/${signal}]${destination ? `\n ${signal}/forward:\n receivers: [otlp_json_file/${signal}]\n processors: [memory_limiter, batch]\n exporters: [otlp_http/forward]` : ""}`).join("\n");
65
+ return `# Generated by Akilium agent-telemetry. Edit via the CLI.\nreceivers:\n otlp:\n protocols:\n grpc:\n endpoint: ${bindHost}:4317\n http:\n endpoint: ${bindHost}:4318\n${receiver ? receiver + "\n" : ""}processors:\n memory_limiter:\n check_interval: 1s\n limit_mib: 256\n spike_limit_mib: 64\n transform/redact_log_content:\n error_mode: ignore\n log_statements:\n - delete_key(log.attributes, "arguments")\n - delete_key(log.attributes, "output")\n - delete_key(log.attributes, "prompt")\n - delete_key(log.attributes, "response")\n - delete_key(log.attributes, "content")\n - delete_key(log.attributes, "stdout")\n - delete_key(log.attributes, "stderr")\n - delete_key(log.attributes, "input")\n - delete_key(log.attributes, "user.email")\n - delete_key(log.attributes, "user.account_id")\n - set(log.body, nil)\n batch:\n timeout: 1s\nexporters:\n${SIGNALS.map((signal) => ` file/${signal}:\n path: ${quoteYaml(`${archive}/${signal}.json`)}\n create_directory: true\n rotation:\n max_megabytes: 10\n max_days: 7\n max_backups: 20`).join("\n")}\n${forwarding}extensions:\n file_storage:\n directory: ${quoteYaml(storage)}\n max_size: 67108864\n create_directory: true\n health_check:\n endpoint: 127.0.0.1:13133\nservice:\n extensions: [file_storage, health_check]\n pipelines:\n${pipelines}\n`;
66
66
  }
67
67
 
68
68
  export function renderCompose(root, akilaForwarding = false) {
@@ -70,14 +70,17 @@ export function renderCompose(root, akilaForwarding = false) {
70
70
  return `services:\n collector:\n image: otel/opentelemetry-collector-contrib:${VERSION}\n restart: unless-stopped\n command: ["--config=/etc/otelcol-contrib/config.yaml"${overlay ? ', "--config=/etc/otelcol-contrib/akila-forwarding.yaml"' : ""}]\n${overlay ? ` env_file: [${quoteYaml(join(root, "akila-forwarding.env"))}]\n` : ""} ports:\n - "127.0.0.1:4317:4317"\n - "127.0.0.1:4318:4318"\n volumes:\n - ${quoteYaml(`${join(root, "collector.yaml")}:/etc/otelcol-contrib/config.yaml:ro`)}\n - ${quoteYaml(`${join(root, "data")}:/data`)}\n${overlay ? ` - ${quoteYaml(`${join(root, overlay)}:/etc/otelcol-contrib/${overlay}:ro`)}\n` : ""}`;
71
71
  }
72
72
 
73
- /** Completion-only allowlist. A lineage action report uses the separate SDK receiver. */
74
- export function renderAkilaForwarding(mappingVersion = "v1") {
73
+ /** Completion forwarding remains separate from the independently authenticated action lineage path. */
74
+ export function renderAkilaForwarding(mappingVersion = "v1", includeLineage = false) {
75
75
  if (!["v1", "v2"].includes(mappingVersion)) throw new Error("Unsupported Codex mapping version");
76
76
  const keys = ["event.name", "event.kind", "input_token_count", "output_token_count",
77
77
  "cached_token_count", "cache_write_token_count", "reasoning_token_count", "tool_token_count",
78
78
  "model", "app.version", "auth_mode", "conversation.id"];
79
79
  if (mappingVersion === "v2") keys.push("user.account_id", "user.email");
80
- return `processors:\n filter/codex_completion:\n error_mode: ignore\n log_conditions:\n - 'log.attributes["event.name"] != "codex.sse_event"'\n - 'log.attributes["event.kind"] != "response.completed"'\n transform/codex_allowlist:\n error_mode: propagate\n log_statements:\n - keep_keys(log.attributes, ${JSON.stringify(keys)})\n - keep_keys(resource.attributes, [])\n - keep_keys(scope.attributes, [])\n - set(log.body, nil)\nexporters:\n otlphttp/akila:\n logs_endpoint: \${env:AKILA_INGESTION_ENDPOINT}\n encoding: json\n compression: none\n headers:\n Authorization: "Bearer \${env:AKILA_CODEX_TOKEN}"\nservice:\n pipelines:\n logs/akila:\n receivers: [otlp]\n processors: [filter/codex_completion, transform/codex_allowlist]\n exporters: [otlphttp/akila]\n`;
80
+ const lineage = includeLineage ? ` filter/codex_tool_result:\n error_mode: ignore\n log_conditions:\n - 'log.attributes["event.name"] != "codex.tool_result"'\n transform/codex_tool_result_allowlist:\n error_mode: propagate\n log_statements:\n - keep_keys(log.attributes, ["event.name", "event.timestamp", "call_id", "success", "duration_ms"])\n - keep_keys(resource.attributes, ["service.name", "service.version"])\n - keep_keys(scope.attributes, [])\n - set(log.body, nil)\n` : "";
81
+ const lineageExporter = includeLineage ? ` otlphttp/lineage:\n logs_endpoint: \${env:AKILA_LINEAGE_ENDPOINT}\n encoding: json\n compression: none\n headers:\n Authorization: "Bearer \${env:AKILA_LINEAGE_TOKEN}"\n sending_queue:\n enabled: true\n storage: file_storage\n queue_size: 1000\n retry_on_failure:\n enabled: true\n max_elapsed_time: 1h\n` : "";
82
+ const lineagePipeline = includeLineage ? ` logs/akila_lineage:\n receivers: [otlp]\n processors: [filter/codex_tool_result, transform/codex_tool_result_allowlist]\n exporters: [otlphttp/lineage]\n` : "";
83
+ return `processors:\n filter/codex_completion:\n error_mode: ignore\n log_conditions:\n - 'log.attributes["event.name"] != "codex.sse_event"'\n - 'log.attributes["event.kind"] != "response.completed"'\n transform/codex_allowlist:\n error_mode: propagate\n log_statements:\n - keep_keys(log.attributes, ${JSON.stringify(keys)})\n - keep_keys(resource.attributes, [])\n - keep_keys(scope.attributes, [])\n - set(log.body, nil)\n${lineage}exporters:\n otlphttp/akila:\n logs_endpoint: \${env:AKILA_INGESTION_ENDPOINT}\n encoding: json\n compression: none\n headers:\n Authorization: "Bearer \${env:AKILA_CODEX_TOKEN}"\n${lineageExporter}service:\n pipelines:\n logs/akila:\n receivers: [otlp]\n processors: [filter/codex_completion, transform/codex_allowlist]\n exporters: [otlphttp/akila]\n${lineagePipeline}`;
81
84
  }
82
85
 
83
86
  export function codexBlock() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akilium/telemetry-collector",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Akilium local OpenTelemetry Collector installer and diagnostic CLI",
5
5
  "type": "module",
6
6
  "engines": { "node": ">=22" },