@akilium/telemetry-collector 0.1.1 → 0.1.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/README.md +17 -2
- package/bin/akilium-telemetry.mjs +32 -2
- package/lib/agent-telemetry.mjs +1 -1
- package/lib/session-capture.mjs +28 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,13 +25,28 @@ The CLI validates the URL and token, writes `akila-forwarding.env` with mode 060
|
|
|
25
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
26
|
|
|
27
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.
|
|
28
|
+
printf 'Lineage token: '; read -r -s AKILA_LINEAGE_TOKEN; printf '\n'; printf '%s' "$AKILA_LINEAGE_TOKEN" | npx --yes @akilium/telemetry-collector@0.1.2 enroll-lineage --endpoint https://YOUR_PROJECT.supabase.co/functions/v1/codex-lineage-otel-ingestion; unset AKILA_LINEAGE_TOKEN
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
For Docker, recreate the container after enrollment so the new environment variables are loaded:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
docker compose -f "$HOME/.local/share/akilium-agent-telemetry/compose.yaml" up -d --force-recreate collector
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
For native installations, stop and relaunch the collector with the updated protected environment. A Docker restart alone keeps the previous environment. The second pipeline forwards Codex `tool_result` records and explicitly structured `akila.activity` records to the capability-bound receiver. For activity records, use allowlisted attributes such as `activity.call_id`, `activity.report_id`, `activity.purpose.category_id`, `activity.purpose.category_version`, `activity.purpose.category_scope`, `activity.purpose.declared_at`, `activity.purpose.evidence_references`, `activity.membership.*`, and `activity.output.*`. Purpose and output attributes require their independently enrolled capabilities. They reuse the deterministic action identity derived from the same Codex call ID. Arguments, output bodies, prompts, resource identifiers, and tool names are dropped before export. The completion credential is never accepted by this receiver.
|
|
32
38
|
|
|
33
39
|
## Operational limits and diagnostics, v1
|
|
34
40
|
|
|
35
41
|
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.
|
|
36
42
|
|
|
37
43
|
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.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## Session capture (0.1.3)
|
|
47
|
+
|
|
48
|
+
Session capture requires an active approved Codex completion source with protected conversation references. In **Connections → Codex telemetry → Session capture**, issue a separate session capture token. Existing usage/action tokens do not enable this capability. The source administrator's controls show enrollment validity, captured sessions/revisions and pending/failed processing.
|
|
49
|
+
|
|
50
|
+
Use the displayed hidden-prompt commands with `npx --yes @akilium/telemetry-collector@0.1.3 preview-sessions --endpoint https://YOUR_PROJECT.supabase.co/functions/v1/ai-session-evidence/enroll` and then `enroll-sessions` at that same endpoint. Both read the token from stdin; never put it in a command argument or URL. Preview reports exact retained sessions/completion revisions, missing-identity records and already captured revisions without changing any data. Add `--include-history` to enrollment only after reviewing that preview if you want retained exact history; default enrollment captures new completions.
|
|
51
|
+
|
|
52
|
+
Enrollment reuses the existing completion exporter and protected source-qualified canonical metadata. It adds no exporter, does not collect prompts/responses, and does not restart or overwrite the Collector. It stores only public enrollment metadata locally, not the session credential. Token rotation, revocation, expiry or lost source approval stops session capture; issue and enroll a replacement token to resume. `status` distinguishes local configuration from hosted validity; inspect Connections health, then refresh Sessions after processing. Missing protected identity remains unresolved, and a captured session may be unscored or have unavailable monetary cost.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { configureSessionCapture } from "../lib/session-capture.mjs";
|
|
2
3
|
/** Install and operate the local OTLP receiver. Runtime files live outside Git. */
|
|
3
4
|
import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
4
5
|
import { homedir, platform, arch } from "node:os";
|
|
@@ -309,7 +310,31 @@ function enrollLineage() {
|
|
|
309
310
|
chmodSync(envFile, 0o600);
|
|
310
311
|
manifest.akilaLineageForwarding = true;
|
|
311
312
|
saveManifest(manifest);
|
|
312
|
-
console.log("Protected action-lineage forwarding configured;
|
|
313
|
+
console.log("Protected action-lineage forwarding configured; reload the collector configuration and environment, then check hosted lineage coverage");
|
|
314
|
+
if (manifest.mode === "docker") console.log(`Run: docker compose -f "${join(p.root, "compose.yaml")}" up -d --force-recreate collector`);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async function enrollSessions(previewOnly = false) {
|
|
318
|
+
const manifest = readJson(p.manifest);
|
|
319
|
+
if (!manifest) throw new Error("Install or migrate the collector first");
|
|
320
|
+
const envFile = join(p.root, "akila-forwarding.env");
|
|
321
|
+
if (!existsSync(envFile) || (statSync(envFile).mode & 0o077) !== 0) throw new Error("Protected completion forwarding enrollment is required");
|
|
322
|
+
const lines = readFileSync(envFile, "utf8").split("\n");
|
|
323
|
+
if (!lines.some(line => /^AKILA_CODEX_TOKEN=.+/.test(line))) throw new Error("Completion forwarding enrollment is required");
|
|
324
|
+
const endpoint = option("--endpoint");
|
|
325
|
+
if (!endpoint) throw new Error("--endpoint is required");
|
|
326
|
+
const completionEndpoint = lines.find(line => line.startsWith("AKILA_INGESTION_ENDPOINT="))?.slice("AKILA_INGESTION_ENDPOINT=".length);
|
|
327
|
+
if (!completionEndpoint || new URL(completionEndpoint).origin !== new URL(endpoint).origin) throw new Error("Session and completion endpoints must use the same project");
|
|
328
|
+
const token = readFileSync(0, "utf8").trim();
|
|
329
|
+
const preview = await configureSessionCapture({ endpoint, token, action: "preview" });
|
|
330
|
+
console.log(`Retained history: ${preview.eligibleSessions} exact sessions / ${preview.eligibleRecords} completion revisions; ${preview.unresolvedRecords} unresolved; ${preview.capturedRecords} already captured.`);
|
|
331
|
+
if (previewOnly) { console.log("Preview only; no capture settings or session data changed."); return; }
|
|
332
|
+
const includeHistory = args.includes("--include-history");
|
|
333
|
+
const result = await configureSessionCapture({ endpoint, token, action: "enroll", includeHistory });
|
|
334
|
+
manifest.akilaSessionCapture = { endpoint, sourceId: result.sourceId, expiresAt: result.expiresAt, includeHistory };
|
|
335
|
+
saveManifest(manifest);
|
|
336
|
+
console.log(`Session capture enrolled until ${result.expiresAt}. ${includeHistory ? "Exact retained history included." : "New completions only."}`);
|
|
337
|
+
console.log("Existing completion forwarding is reused; no collector restart or additional exporter is required. Check Connections for hosted processing health, then refresh Sessions.");
|
|
313
338
|
}
|
|
314
339
|
|
|
315
340
|
function setDestination() {
|
|
@@ -372,6 +397,9 @@ function status() {
|
|
|
372
397
|
if (manifest.mode === "docker") console.log(run("docker", ["compose", "-f", p.compose, "ps", "--status", "running"], true) || "Docker service unavailable");
|
|
373
398
|
else if (manifest.mode === "systemd") console.log(`Service: ${run("systemctl", ["--user", "is-active", "akilium-agent-telemetry.service"], true) || "inactive"}`);
|
|
374
399
|
else console.log(`Service: ${run("launchctl", ["list", "ai.akilium.agent-telemetry"], true) ? "loaded" : "inactive"}`);
|
|
400
|
+
if (manifest.akilaSessionCapture) {
|
|
401
|
+
console.log(`Session capture: locally enrolled until ${manifest.akilaSessionCapture.expiresAt}; hosted validity/processing must be checked in Connections`);
|
|
402
|
+
} else console.log("Session capture: not enrolled on this installation (use enroll-sessions)");
|
|
375
403
|
console.log("Hosted receipt: unknown (inspect Akila connection health)");
|
|
376
404
|
console.log("Normalization: unknown (inspect Akila worker/inbox health)");
|
|
377
405
|
console.log("Artifact linkage: unknown (inspect authorized event and artifact views)");
|
|
@@ -425,12 +453,14 @@ try {
|
|
|
425
453
|
else if (action === "rollback") rollback();
|
|
426
454
|
else if (action === "enroll") enroll();
|
|
427
455
|
else if (action === "enroll-lineage") enrollLineage();
|
|
456
|
+
else if (action === "enroll-sessions") await enrollSessions();
|
|
457
|
+
else if (action === "preview-sessions") await enrollSessions(true);
|
|
428
458
|
else if (action === "configure") installAgents(readJson(p.manifest) || (() => { throw new Error("Install the collector first"); })());
|
|
429
459
|
else if (action === "set-destination") setDestination();
|
|
430
460
|
else if (action === "status") status();
|
|
431
461
|
else if (action === "doctor") await doctor();
|
|
432
462
|
else if (action === "uninstall") uninstall();
|
|
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];
|
|
463
|
+
else if (action === "help") console.log("Usage: akilium-telemetry <install|migrate|enroll|enroll-lineage|preview-sessions|enroll-sessions|configure|status|doctor|upgrade|rollback|set-destination|uninstall> [--mode native|docker] [--agents codex,claude] [--endpoint URL|--clear] [--mapping v1|v2] [--include-history]; all enrollment/preview commands read tokens from stdin");
|
|
434
464
|
else throw new Error(`Unknown action: ${action}`);
|
|
435
465
|
} catch (error) {
|
|
436
466
|
if (!quiet) console.error(`agent-telemetry: ${error.message}`);
|
package/lib/agent-telemetry.mjs
CHANGED
|
@@ -77,7 +77,7 @@ export function renderAkilaForwarding(mappingVersion = "v1", includeLineage = fa
|
|
|
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
|
-
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` : "";
|
|
80
|
+
const lineage = includeLineage ? ` filter/codex_tool_result:\n error_mode: ignore\n log_conditions:\n - 'log.attributes["event.name"] != "codex.tool_result" and log.attributes["event.name"] != "akila.activity"'\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", "activity.call_id", "activity.report_id", "activity.occurred_at", "activity.purpose.category_id", "activity.purpose.category_version", "activity.purpose.category_scope", "activity.purpose.tenant_id", "activity.purpose.team_id", "activity.purpose.declared_at", "activity.purpose.evidence_references", "activity.membership.context_id", "activity.membership.context_kind", "activity.membership.established_at", "activity.output.output_id", "activity.output.kind", "activity.output.lifetime", "activity.output.evidence_reference", "activity.output.no_output_assertion_id", "activity.output.no_output_occurred_at", "activity.output.no_output_origin", "activity.output.no_output_qualification", "activity.output.no_output_evidence_reference", "activity.output.no_output_supersedes_id"])\n - keep_keys(resource.attributes, ["service.name", "service.version"])\n - keep_keys(scope.attributes, [])\n - set(log.body, nil)\n` : "";
|
|
81
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
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
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}`;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** No raw identifiers or tokens are persisted or returned by this client. */
|
|
2
|
+
export async function configureSessionCapture({ endpoint, token, action, includeHistory = false, request = fetch }) {
|
|
3
|
+
const url = new URL(endpoint);
|
|
4
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash ||
|
|
5
|
+
!url.pathname.endsWith('/functions/v1/ai-session-evidence/enroll')) {
|
|
6
|
+
throw new Error('Session enrollment requires a verified HTTPS session receiver URL');
|
|
7
|
+
}
|
|
8
|
+
if (!/^[A-Za-z0-9_-]{32,128}$/.test(token)) throw new Error('Invalid session enrollment token on stdin');
|
|
9
|
+
if (!['preview', 'enroll'].includes(action) || typeof includeHistory !== 'boolean') throw new Error('Invalid capture options');
|
|
10
|
+
let response;
|
|
11
|
+
try {
|
|
12
|
+
response = await request(url, { method: 'POST', redirect: 'error',
|
|
13
|
+
headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },
|
|
14
|
+
body: JSON.stringify({ action, includeHistory }), signal: AbortSignal.timeout(15_000) });
|
|
15
|
+
} catch { throw new Error('Session receiver unavailable; existing usage capture is unchanged'); }
|
|
16
|
+
if (!response.ok) throw new Error(`Session enrollment rejected (HTTP ${response.status}); check token expiry, capability and source approval`);
|
|
17
|
+
let value;
|
|
18
|
+
try { value = await response.json(); } catch { throw new Error('Invalid session enrollment response'); }
|
|
19
|
+
if (!value || value.state !== (action === 'preview' ? 'preview' : 'enrolled') ||
|
|
20
|
+
typeof value.sourceId !== 'string' || !/^[0-9a-f-]{36}$/i.test(value.sourceId) ||
|
|
21
|
+
typeof value.expiresAt !== 'string' || !Number.isFinite(Date.parse(value.expiresAt)) ||
|
|
22
|
+
['eligibleRecords', 'eligibleSessions', 'unresolvedRecords', 'capturedRecords'].some(key => !Number.isSafeInteger(value[key]) || value[key] < 0)) {
|
|
23
|
+
throw new Error('Invalid session enrollment response');
|
|
24
|
+
}
|
|
25
|
+
return { state: value.state, sourceId: value.sourceId, expiresAt: value.expiresAt,
|
|
26
|
+
eligibleRecords: value.eligibleRecords, eligibleSessions: value.eligibleSessions,
|
|
27
|
+
unresolvedRecords: value.unresolvedRecords, capturedRecords: value.capturedRecords };
|
|
28
|
+
}
|