Compare commits

...
Author SHA1 Message Date
abeatrix a0d9f192bb Add persistent storage for distinct ID in logging service
- Introduce `storeDistinctId` function to update global state with new ID
- Modify `initializeDistinctId` to set up persistent storage callback
- Update `setDistinctId` to persist changes to global state
- Ensures telemetry distinct ID survives application restarts
2025-09-04 11:50:04 -07:00
+9 -1
View File
@@ -8,10 +8,15 @@ import { Logger } from "./Logger"
* Unique identifier for the current installation.
*/
let _distinctId: string = ""
/*
* Function to store the distinct ID persistently.
*/
let storeDistinctId: ((id: string) => void) | null = null
export async function initializeDistinctId(context: ExtensionContext, uuid: () => string = uuidv4) {
// NOTE: Backward compatibility in case where cline.distinctId was set in older versions
const existingId = context.globalState.get<string>("cline.distinctId")
const globalStore = context.globalState
const existingId = globalStore?.get<string>("cline.distinctId")
const machineId = await getMachineId()
let distinctId = existingId || machineId
@@ -25,6 +30,8 @@ export async function initializeDistinctId(context: ExtensionContext, uuid: () =
if (process.env.IS_DEV) {
console.log("Telemetry distinct ID initialized:", distinctId)
}
storeDistinctId = (id: string) => globalStore.update("cline.distinctId", id)
}
/*
@@ -46,6 +53,7 @@ async function getMachineId(): Promise<string | undefined> {
*/
export function setDistinctId(newId: string) {
if (_distinctId && _distinctId !== newId) {
storeDistinctId?.(newId)
console.log(`Changing telemetry ID from ${_distinctId} to ${newId}.`)
}
_distinctId = newId