@akilium/telemetry-collector 0.1.2 → 0.1.4
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 +10 -1
- package/bin/akilium-telemetry.mjs +32 -1
- package/lib/agent-telemetry.mjs +1 -1
- package/lib/session-capture.mjs +31 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,10 +34,19 @@ For Docker, recreate the container after enrollment so the new environment varia
|
|
|
34
34
|
docker compose -f "$HOME/.local/share/akilium-agent-telemetry/compose.yaml" up -d --force-recreate collector
|
|
35
35
|
```
|
|
36
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
|
|
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.
|
|
38
38
|
|
|
39
39
|
## Operational limits and diagnostics, v1
|
|
40
40
|
|
|
41
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.
|
|
42
42
|
|
|
43
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.4)
|
|
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.4 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";
|
|
@@ -313,6 +314,31 @@ function enrollLineage() {
|
|
|
313
314
|
if (manifest.mode === "docker") console.log(`Run: docker compose -f "${join(p.root, "compose.yaml")}" up -d --force-recreate collector`);
|
|
314
315
|
}
|
|
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 completionToken = lines.find(line => line.startsWith("AKILA_CODEX_TOKEN="))?.slice("AKILA_CODEX_TOKEN=".length);
|
|
330
|
+
const preview = await configureSessionCapture({ endpoint, token, completionToken, action: "preview" });
|
|
331
|
+
console.log(`Retained history: ${preview.eligibleSessions} exact sessions / ${preview.eligibleRecords} completion revisions; ${preview.unresolvedRecords} unresolved; ${preview.capturedRecords} already captured.`);
|
|
332
|
+
if (preview.usageCredentialState !== "active") console.log(`Usage credential: ${preview.usageCredentialState}. Renew usage enrollment and restart/recreate the collector to resume new completions.`);
|
|
333
|
+
if (previewOnly) { console.log("Preview only; no capture settings or session data changed."); return; }
|
|
334
|
+
const includeHistory = args.includes("--include-history");
|
|
335
|
+
const result = await configureSessionCapture({ endpoint, token, completionToken, action: "enroll", includeHistory });
|
|
336
|
+
manifest.akilaSessionCapture = { endpoint, sourceId: result.sourceId, expiresAt: result.expiresAt, includeHistory };
|
|
337
|
+
saveManifest(manifest);
|
|
338
|
+
console.log(`Session capture enrolled until ${result.expiresAt}. ${includeHistory ? "Exact retained history included." : "New completions only."}`);
|
|
339
|
+
console.log("Existing completion forwarding is reused; no collector restart or additional exporter is required. Check Connections for hosted processing health, then refresh Sessions.");
|
|
340
|
+
}
|
|
341
|
+
|
|
316
342
|
function setDestination() {
|
|
317
343
|
const manifest = readJson(p.manifest);
|
|
318
344
|
if (!manifest) throw new Error("Install the collector first");
|
|
@@ -373,6 +399,9 @@ function status() {
|
|
|
373
399
|
if (manifest.mode === "docker") console.log(run("docker", ["compose", "-f", p.compose, "ps", "--status", "running"], true) || "Docker service unavailable");
|
|
374
400
|
else if (manifest.mode === "systemd") console.log(`Service: ${run("systemctl", ["--user", "is-active", "akilium-agent-telemetry.service"], true) || "inactive"}`);
|
|
375
401
|
else console.log(`Service: ${run("launchctl", ["list", "ai.akilium.agent-telemetry"], true) ? "loaded" : "inactive"}`);
|
|
402
|
+
if (manifest.akilaSessionCapture) {
|
|
403
|
+
console.log(`Session capture: locally enrolled until ${manifest.akilaSessionCapture.expiresAt}; hosted validity/processing must be checked in Connections`);
|
|
404
|
+
} else console.log("Session capture: not enrolled on this installation (use enroll-sessions)");
|
|
376
405
|
console.log("Hosted receipt: unknown (inspect Akila connection health)");
|
|
377
406
|
console.log("Normalization: unknown (inspect Akila worker/inbox health)");
|
|
378
407
|
console.log("Artifact linkage: unknown (inspect authorized event and artifact views)");
|
|
@@ -426,12 +455,14 @@ try {
|
|
|
426
455
|
else if (action === "rollback") rollback();
|
|
427
456
|
else if (action === "enroll") enroll();
|
|
428
457
|
else if (action === "enroll-lineage") enrollLineage();
|
|
458
|
+
else if (action === "enroll-sessions") await enrollSessions();
|
|
459
|
+
else if (action === "preview-sessions") await enrollSessions(true);
|
|
429
460
|
else if (action === "configure") installAgents(readJson(p.manifest) || (() => { throw new Error("Install the collector first"); })());
|
|
430
461
|
else if (action === "set-destination") setDestination();
|
|
431
462
|
else if (action === "status") status();
|
|
432
463
|
else if (action === "doctor") await doctor();
|
|
433
464
|
else if (action === "uninstall") uninstall();
|
|
434
|
-
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];
|
|
465
|
+
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");
|
|
435
466
|
else throw new Error(`Unknown action: ${action}`);
|
|
436
467
|
} catch (error) {
|
|
437
468
|
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,31 @@
|
|
|
1
|
+
/** No raw identifiers or tokens are persisted or returned by this client. */
|
|
2
|
+
export async function configureSessionCapture({ endpoint, token, completionToken, 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 (!/^[A-Za-z0-9_-]{32,128}$/.test(completionToken ?? '')) throw new Error('Protected usage enrollment is required to match this laptop to its source');
|
|
10
|
+
if (!['preview', 'enroll'].includes(action) || typeof includeHistory !== 'boolean') throw new Error('Invalid capture options');
|
|
11
|
+
let response;
|
|
12
|
+
try {
|
|
13
|
+
response = await request(url, { method: 'POST', redirect: 'error',
|
|
14
|
+
headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },
|
|
15
|
+
body: JSON.stringify({ action, includeHistory, completionToken }), signal: AbortSignal.timeout(15_000) });
|
|
16
|
+
} catch { throw new Error('Session receiver unavailable; existing usage capture is unchanged'); }
|
|
17
|
+
if (response.status === 403) throw new Error('Session token belongs to a different source than this laptop. Issue the session token from the same Codex source as its usage token');
|
|
18
|
+
if (!response.ok) throw new Error(`Session enrollment rejected (HTTP ${response.status}); check token expiry, capability and source approval`);
|
|
19
|
+
let value;
|
|
20
|
+
try { value = await response.json(); } catch { throw new Error('Invalid session enrollment response'); }
|
|
21
|
+
if (!value || value.state !== (action === 'preview' ? 'preview' : 'enrolled') ||
|
|
22
|
+
typeof value.sourceId !== 'string' || !/^[0-9a-f-]{36}$/i.test(value.sourceId) ||
|
|
23
|
+
typeof value.expiresAt !== 'string' || !Number.isFinite(Date.parse(value.expiresAt)) ||
|
|
24
|
+
['eligibleRecords', 'eligibleSessions', 'unresolvedRecords', 'capturedRecords'].some(key => !Number.isSafeInteger(value[key]) || value[key] < 0)) {
|
|
25
|
+
throw new Error('Invalid session enrollment response');
|
|
26
|
+
}
|
|
27
|
+
return { state: value.state, sourceId: value.sourceId, expiresAt: value.expiresAt,
|
|
28
|
+
eligibleRecords: value.eligibleRecords, eligibleSessions: value.eligibleSessions,
|
|
29
|
+
unresolvedRecords: value.unresolvedRecords, capturedRecords: value.capturedRecords,
|
|
30
|
+
usageCredentialState: ['active', 'expired', 'revoked'].includes(value.usageCredentialState) ? value.usageCredentialState : 'unknown' };
|
|
31
|
+
}
|