refactor: add TelemetryProxy.tryCapture() convenience method

This commit is contained in:
Mark IJbema
2026-02-18 15:39:41 +01:00
parent 79a6fe3028
commit 3bb8b02060
4 changed files with 12 additions and 8 deletions
+1 -5
View File
@@ -399,11 +399,7 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
await this.handleResetAllSettings()
break
case "telemetry":
try {
TelemetryProxy.getInstance().capture(message.event, message.properties)
} catch {
// TelemetryProxy not initialized — safe to ignore
}
TelemetryProxy.tryCapture(message.event, message.properties)
break
}
})
@@ -133,7 +133,7 @@ export class AutocompleteServiceManager {
enableSmartInlineTaskKeybinding: false,
})
TelemetryProxy.tryGetInstance()?.capture(TelemetryEventName.GHOST_SERVICE_DISABLED)
TelemetryProxy.tryCapture(TelemetryEventName.GHOST_SERVICE_DISABLED)
await this.load()
}
@@ -231,7 +231,7 @@ export class AutocompleteServiceManager {
}
this.taskId = crypto.randomUUID()
TelemetryProxy.tryGetInstance()?.capture(TelemetryEventName.INLINE_ASSIST_AUTO_TASK, {
TelemetryProxy.tryCapture(TelemetryEventName.INLINE_ASSIST_AUTO_TASK, {
taskId: this.taskId,
})
@@ -87,7 +87,7 @@ export class AutocompleteTelemetry {
...properties,
autocompleteType: this.autocompleteType,
}
TelemetryProxy.tryGetInstance()?.capture(event, props)
TelemetryProxy.tryCapture(event, props)
}
/**
@@ -42,6 +42,14 @@ export class TelemetryProxy {
return TelemetryProxy.instance
}
/**
* Fire-and-forget capture that silently no-ops when the proxy has not been
* initialised yet.
*/
static tryCapture(event: TelemetryEventName, properties?: Record<string, unknown>) {
TelemetryProxy.tryGetInstance()?.capture(event, properties)
}
/**
* Configure the CLI server connection. Must be called before capture() will send events.
*/