Skip to content

Commit 625f3f4

Browse files
suryaiyer95claude
andcommitted
feat: add persistent machine ID from \~/.altimate/machine-id\
Generated once as a random UUID and stored at \`~/.altimate/machine-id\` (alongside \`altimate.json\`, \`connections.json\`, etc.). Sent as \`machine_id\` in \`customDimensions\` on every App Insights event. No PII — pure random UUID, never tied to user identity. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ef1d1a7 commit 625f3f4

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

  • packages/opencode/src/altimate/telemetry

packages/opencode/src/altimate/telemetry/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { Account } from "@/account"
22
import { Config } from "@/config/config"
33
import { Installation } from "@/installation"
44
import { Log } from "@/util/log"
5-
import { createHash } from "crypto"
5+
import { createHash, randomUUID } from "crypto"
6+
import fs from "fs"
7+
import path from "path"
8+
import os from "os"
69

710
const log = Log.create({ service: "telemetry" })
811

@@ -528,6 +531,7 @@ export namespace Telemetry {
528531
let buffer: Event[] = []
529532
let flushTimer: ReturnType<typeof setInterval> | undefined
530533
let userEmail = ""
534+
let machineId = ""
531535
let sessionId = ""
532536
let projectId = ""
533537
let appInsights: AppInsightsConfig | undefined
@@ -557,6 +561,7 @@ export namespace Telemetry {
557561
const properties: Record<string, string> = {
558562
cli_version: Installation.VERSION,
559563
project_id: fields.project_id ?? projectId,
564+
...(machineId && { machine_id: machineId }),
560565
}
561566
const measurements: Record<string, number> = {}
562567

@@ -645,6 +650,18 @@ export namespace Telemetry {
645650
} catch {
646651
// Account unavailable — proceed without user ID
647652
}
653+
try {
654+
const machineIdPath = path.join(os.homedir(), ".altimate", "machine-id")
655+
try {
656+
machineId = fs.readFileSync(machineIdPath, "utf8").trim()
657+
} catch {
658+
machineId = randomUUID()
659+
fs.mkdirSync(path.dirname(machineIdPath), { recursive: true })
660+
fs.writeFileSync(machineIdPath, machineId, "utf8")
661+
}
662+
} catch {
663+
// Machine ID unavailable — proceed without it
664+
}
648665
enabled = true
649666
log.info("telemetry initialized", { mode: "appinsights" })
650667
const timer = setInterval(flush, FLUSH_INTERVAL_MS)
@@ -746,6 +763,7 @@ export namespace Telemetry {
746763
droppedEvents = 0
747764
sessionId = ""
748765
projectId = ""
766+
machineId = ""
749767
initPromise = undefined
750768
initDone = false
751769
}

0 commit comments

Comments
 (0)