Switch to getting the telemetry settings from the Host Bridge (#6079)
This commit is contained in:
1 parent
87c4965110
commit
8f9de630b3
14 files changed
+118
-92
No files matched your search
@@ -18,6 +18,8 @@ service EnvService {
|
||||
rpc getMachineId(cline.EmptyRequest) returns (cline.String);
|
||||
|
||||
rpc getHostVersion(cline.EmptyRequest) returns (GetHostVersionResponse);
|
||||
|
||||
rpc getTelemetrySettings(cline.EmptyRequest) returns (GetTelemetrySettingsResponse);
|
||||
}
|
||||
|
||||
message GetHostVersionResponse {
|
||||
@@ -26,3 +28,12 @@ message GetHostVersionResponse {
|
||||
// The version of the host platform, e.g. 1.103.0
|
||||
optional string version = 2;
|
||||
}
|
||||
|
||||
enum Setting {
|
||||
UNSUPPORTED = 0; // This host does not support this setting.
|
||||
ENABLED = 1;
|
||||
DISABLED = 2;
|
||||
}
|
||||
message GetTelemetrySettingsResponse {
|
||||
Setting is_enabled = 1;
|
||||
}
|
||||
+5
-2
@@ -12,7 +12,7 @@ import "./utils/path" // necessary to have access to String.prototype.toPosix
|
||||
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { FileContextTracker } from "./core/context/context-tracking/FileContextTracker"
|
||||
import { errorService } from "./services/error"
|
||||
import { ErrorService } from "./services/error"
|
||||
import { featureFlagsService } from "./services/feature-flags"
|
||||
import { initializeDistinctId } from "./services/logging/distinctId"
|
||||
import { PostHogClientProvider } from "./services/posthog/PostHogClientProvider"
|
||||
@@ -32,6 +32,9 @@ export async function initialize(context: vscode.ExtensionContext): Promise<Webv
|
||||
// Initialize PostHog client provider
|
||||
PostHogClientProvider.getInstance()
|
||||
|
||||
// Setup the ErrorService
|
||||
await ErrorService.initialize()
|
||||
|
||||
// Migrate custom instructions to global Cline rules (one-time cleanup)
|
||||
await migrateCustomInstructionsToGlobalRules(context)
|
||||
|
||||
@@ -96,7 +99,7 @@ async function showVersionUpdateAnnouncement(context: vscode.ExtensionContext) {
|
||||
export async function tearDown(): Promise<void> {
|
||||
PostHogClientProvider.getInstance().dispose()
|
||||
telemetryService.dispose()
|
||||
errorService.dispose()
|
||||
ErrorService.get().dispose()
|
||||
featureFlagsService.dispose()
|
||||
// Dispose all webview instances
|
||||
await WebviewProvider.disposeAllInstances()
|
||||
|
||||
@@ -68,7 +68,7 @@ import * as vscode from "vscode"
|
||||
import type { SystemPromptContext } from "@/core/prompts/system-prompt"
|
||||
import { getSystemPrompt } from "@/core/prompts/system-prompt"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { errorService } from "@/services/error"
|
||||
import { ErrorService } from "@/services/error"
|
||||
import { TerminalHangStage, TerminalUserInterventionAction, telemetryService } from "@/services/telemetry"
|
||||
import { ShowMessageType } from "@/shared/proto/index.host"
|
||||
import { isInTestMode } from "../../services/test/TestMode"
|
||||
@@ -1379,12 +1379,12 @@ export class Task {
|
||||
} catch (error) {
|
||||
const isContextWindowExceededError = checkContextWindowExceededError(error)
|
||||
const { model, providerId } = this.getCurrentProviderInfo()
|
||||
const clineError = errorService.toClineError(error, model.id, providerId)
|
||||
const clineError = ErrorService.get().toClineError(error, model.id, providerId)
|
||||
|
||||
// Capture provider failure telemetry using clineError
|
||||
// TODO: Move into errorService
|
||||
errorService.logMessage(clineError.message)
|
||||
errorService.logException(clineError)
|
||||
ErrorService.get().logMessage(clineError.message)
|
||||
ErrorService.get().logException(clineError)
|
||||
|
||||
if (isContextWindowExceededError && !this.taskState.didAutomaticallyRetryFailedApiRequest) {
|
||||
await this.handleContextWindowExceededError()
|
||||
@@ -2037,7 +2037,7 @@ export class Task {
|
||||
// abandoned happens when extension is no longer waiting for the cline instance to finish aborting (error is thrown here when any function in the for loop throws due to this.abort)
|
||||
if (!this.taskState.abandoned) {
|
||||
this.abortTask() // if the stream failed, there's various states the task could be in (i.e. could have streamed some tools the user may have executed), so we just resort to replicating a cancel task
|
||||
const clineError = errorService.toClineError(error, this.api.getModel().id)
|
||||
const clineError = ErrorService.get().toClineError(error, this.api.getModel().id)
|
||||
const errorMessage = clineError.serialize()
|
||||
|
||||
await abortStream("streaming_failed", errorMessage)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import * as vscode from "vscode"
|
||||
import { EmptyRequest } from "@/shared/proto/index.cline"
|
||||
import { GetTelemetrySettingsResponse, Setting } from "@/shared/proto/index.host"
|
||||
|
||||
export async function getTelemetrySettings(_: EmptyRequest): Promise<GetTelemetrySettingsResponse> {
|
||||
if (vscode.env.isTelemetryEnabled) {
|
||||
return { isEnabled: Setting.ENABLED }
|
||||
} else {
|
||||
return { isEnabled: Setting.DISABLED }
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { GithubAuthProvider, GoogleAuthProvider, getAuth, type OAuthCredential,
|
||||
import { jwtDecode } from "jwt-decode"
|
||||
import { clineEnvConfig } from "@/config"
|
||||
import { Controller } from "@/core/controller"
|
||||
import { errorService } from "@/services/error"
|
||||
import { ErrorService } from "@/services/error"
|
||||
import type { ClineAccountUserInfo, ClineAuthInfo } from "../AuthService"
|
||||
|
||||
export class FirebaseAuthProvider {
|
||||
@@ -88,8 +88,8 @@ export class FirebaseAuthProvider {
|
||||
// return userCredential.user
|
||||
} catch (error) {
|
||||
console.error("Firebase restore token error", error)
|
||||
errorService.logMessage("Firebase restore token error", "error")
|
||||
errorService.logException(error)
|
||||
ErrorService.get().logMessage("Firebase restore token error", "error")
|
||||
ErrorService.get().logException(error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -124,16 +124,16 @@ export class FirebaseAuthProvider {
|
||||
try {
|
||||
controller.stateManager.setSecret("clineAccountId", userCredential.refreshToken)
|
||||
} catch (error) {
|
||||
errorService.logMessage("Firebase store token error", "error")
|
||||
errorService.logException(error)
|
||||
ErrorService.get().logMessage("Firebase store token error", "error")
|
||||
ErrorService.get().logException(error)
|
||||
throw error
|
||||
}
|
||||
|
||||
// userCredential = await this._signInWithCredential(context, credential)
|
||||
return await this.retrieveClineAuthInfo(controller)
|
||||
} catch (error) {
|
||||
errorService.logMessage("Firebase sign-in error", "error")
|
||||
errorService.logException(error)
|
||||
ErrorService.get().logMessage("Firebase sign-in error", "error")
|
||||
ErrorService.get().logException(error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,16 +25,16 @@ export class ErrorProviderFactory {
|
||||
* @param config Configuration for the error provider
|
||||
* @returns IErrorProvider instance
|
||||
*/
|
||||
public static createProvider(config: ErrorProviderConfig): IErrorProvider {
|
||||
public static async createProvider(config: ErrorProviderConfig): Promise<IErrorProvider> {
|
||||
switch (config.type) {
|
||||
case "posthog":
|
||||
if (config.config.apiKey !== undefined && config.config.errorTrackingApiKey !== undefined) {
|
||||
return new PostHogErrorProvider({
|
||||
return await new PostHogErrorProvider({
|
||||
apiKey: config.config.apiKey,
|
||||
errorTrackingApiKey: config.config.errorTrackingApiKey,
|
||||
host: config.config.host,
|
||||
uiHost: config.config.uiHost,
|
||||
})
|
||||
}).initialize()
|
||||
}
|
||||
return new NoOpErrorProvider()
|
||||
default:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ClineError } from "./ClineError"
|
||||
import { ErrorProviderFactory } from "./ErrorProviderFactory"
|
||||
import { IErrorProvider } from "./providers/IErrorProvider"
|
||||
|
||||
/**
|
||||
@@ -7,8 +8,33 @@ import { IErrorProvider } from "./providers/IErrorProvider"
|
||||
* Respects user privacy settings and VSCode's global telemetry configuration
|
||||
*/
|
||||
export class ErrorService {
|
||||
private static instance: ErrorService | null = null
|
||||
|
||||
private provider: IErrorProvider
|
||||
|
||||
/**
|
||||
* Sets up the ErrorService singleton.
|
||||
*/
|
||||
public static async initialize(): Promise<ErrorService> {
|
||||
if (ErrorService.instance) {
|
||||
throw new Error("ErrorService has already been initialized.")
|
||||
}
|
||||
|
||||
const provider = await ErrorProviderFactory.createProvider(ErrorProviderFactory.getDefaultConfig())
|
||||
ErrorService.instance = new ErrorService(provider)
|
||||
return ErrorService.instance
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the singleton instance
|
||||
*/
|
||||
public static get(): ErrorService {
|
||||
if (!ErrorService.instance) {
|
||||
throw new Error("ErrorService not setup. Call ErrorService.initialize() first.")
|
||||
}
|
||||
return ErrorService.instance
|
||||
}
|
||||
|
||||
constructor(provider: IErrorProvider) {
|
||||
this.provider = provider
|
||||
}
|
||||
|
||||
@@ -3,37 +3,3 @@ export { type ErrorProviderConfig, ErrorProviderFactory, type ErrorProviderType
|
||||
export { ErrorService } from "./ErrorService"
|
||||
export type { ErrorSettings, IErrorProvider } from "./providers/IErrorProvider"
|
||||
export { PostHogErrorProvider } from "./providers/PostHogErrorProvider"
|
||||
|
||||
import { ErrorProviderFactory } from "./ErrorProviderFactory"
|
||||
import { ErrorService } from "./ErrorService"
|
||||
|
||||
let _errorServiceInstance: ErrorService | null = null
|
||||
|
||||
/**
|
||||
* Get the singleton error service instance
|
||||
* @param distinctId Optional distinct ID for the error provider
|
||||
* @returns ErrorService instance
|
||||
*/
|
||||
export function getErrorService(): ErrorService {
|
||||
if (!_errorServiceInstance) {
|
||||
const provider = ErrorProviderFactory.createProvider(ErrorProviderFactory.getDefaultConfig())
|
||||
_errorServiceInstance = new ErrorService(provider)
|
||||
}
|
||||
return _errorServiceInstance
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the error service instance (useful for testing)
|
||||
*/
|
||||
export function resetErrorService(): void {
|
||||
_errorServiceInstance = null
|
||||
}
|
||||
|
||||
// Export errorService as a getter that dynamically calls getErrorService()
|
||||
// This ensures it always returns the current instance without changing call sites
|
||||
export const errorService = new Proxy({} as ErrorService, {
|
||||
get(_target, prop, _receiver) {
|
||||
const service = getErrorService()
|
||||
return Reflect.get(service, prop, service)
|
||||
},
|
||||
})
|
||||
@@ -1,7 +1,9 @@
|
||||
import { PostHog } from "posthog-node"
|
||||
import * as vscode from "vscode"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { getDistinctId } from "@/services/logging/distinctId"
|
||||
import { PostHogClientProvider } from "@/services/posthog/PostHogClientProvider"
|
||||
import { Setting } from "@/shared/proto/index.host"
|
||||
import * as pkg from "../../../../package.json"
|
||||
import { PostHogClientValidConfig } from "../../../shared/services/config/posthog-config"
|
||||
import { ClineError } from "../ClineError"
|
||||
@@ -27,22 +29,23 @@ export class PostHogErrorProvider implements IErrorProvider {
|
||||
enableExceptionAutocapture: false, // NOTE: Re-enable it once the api key is set to env var
|
||||
before_send: (event) => PostHogClientProvider.eventFilter(event),
|
||||
})
|
||||
|
||||
// Initialize error settings
|
||||
this.errorSettings = {
|
||||
enabled: true,
|
||||
hostEnabled: true,
|
||||
level: "all",
|
||||
}
|
||||
}
|
||||
|
||||
public async initialize(): Promise<PostHogErrorProvider> {
|
||||
// Listen for VS Code telemetry changes
|
||||
this.disposables.push(
|
||||
vscode.env.onDidChangeTelemetryEnabled((isTelemetryEnabled) => {
|
||||
this.errorSettings.hostEnabled = isTelemetryEnabled
|
||||
}),
|
||||
)
|
||||
|
||||
if (vscode?.env?.isTelemetryEnabled === false) {
|
||||
const hostSettings = await HostProvider.env.getTelemetrySettings({})
|
||||
if (hostSettings.isEnabled === Setting.DISABLED) {
|
||||
this.errorSettings.hostEnabled = false
|
||||
}
|
||||
|
||||
@@ -52,7 +55,8 @@ export class PostHogErrorProvider implements IErrorProvider {
|
||||
this.errorSettings.enabled = false
|
||||
}
|
||||
|
||||
this.errorSettings.level = this.getErrorLevel()
|
||||
this.errorSettings.level = await this.getErrorLevel()
|
||||
return this
|
||||
}
|
||||
|
||||
public logException(error: Error | ClineError, properties: Record<string, unknown> = {}): void {
|
||||
@@ -126,8 +130,9 @@ export class PostHogErrorProvider implements IErrorProvider {
|
||||
return { ...this.errorSettings }
|
||||
}
|
||||
|
||||
private getErrorLevel(): ErrorSettings["level"] {
|
||||
if (!vscode?.env?.isTelemetryEnabled) {
|
||||
private async getErrorLevel(): Promise<ErrorSettings["level"]> {
|
||||
const hostSettings = await HostProvider.env.getTelemetrySettings({})
|
||||
if (hostSettings.isEnabled === Setting.DISABLED) {
|
||||
return "off"
|
||||
}
|
||||
const config = vscode.workspace.getConfiguration("telemetry")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { errorService } from "../error"
|
||||
import { ErrorService } from "../error"
|
||||
|
||||
/**
|
||||
* Simple logging utility for the extension's backend code.
|
||||
@@ -8,12 +8,12 @@ export class Logger {
|
||||
public readonly channelName = "Cline Dev Logger"
|
||||
static error(message: string, error?: Error) {
|
||||
Logger.#output("ERROR", message, error)
|
||||
errorService.logMessage(message, "error")
|
||||
error && errorService.logException(error)
|
||||
ErrorService.get().logMessage(message, "error")
|
||||
error && ErrorService.get().logException(error)
|
||||
}
|
||||
static warn(message: string) {
|
||||
Logger.#output("WARN", message)
|
||||
errorService.logMessage(message, "warning")
|
||||
ErrorService.get().logMessage(message, "warning")
|
||||
}
|
||||
static log(message: string) {
|
||||
Logger.#output("LOG", message)
|
||||
|
||||
@@ -24,13 +24,13 @@ export class TelemetryProviderFactory {
|
||||
* @param config Configuration for the telemetry provider
|
||||
* @returns ITelemetryProvider instance
|
||||
*/
|
||||
public static createProvider(config: TelemetryProviderConfig): ITelemetryProvider {
|
||||
public static async createProvider(config: TelemetryProviderConfig): Promise<ITelemetryProvider> {
|
||||
// Get the shared PostHog client from PostHogClientProvider
|
||||
const sharedClient = PostHogClientProvider.getClient()
|
||||
switch (config.type) {
|
||||
case "posthog":
|
||||
if (sharedClient) {
|
||||
return new PostHogTelemetryProvider(sharedClient)
|
||||
return await new PostHogTelemetryProvider(sharedClient).initialize()
|
||||
}
|
||||
return new NoOpTelemetryProvider()
|
||||
case "none":
|
||||
@@ -56,7 +56,7 @@ export class TelemetryProviderFactory {
|
||||
* No-operation telemetry provider for when telemetry is disabled
|
||||
* or for testing purposes
|
||||
*/
|
||||
class NoOpTelemetryProvider implements ITelemetryProvider {
|
||||
export class NoOpTelemetryProvider implements ITelemetryProvider {
|
||||
public log(_event: string, _properties?: Record<string, unknown>): void {
|
||||
// No-op
|
||||
}
|
||||
|
||||
+17
-21
@@ -6,10 +6,15 @@
|
||||
|
||||
import * as assert from "assert"
|
||||
import * as sinon from "sinon"
|
||||
import { TelemetryProviderFactory, type TelemetryProviderType } from "../TelemetryProviderFactory"
|
||||
import { TelemetryService } from "../TelemetryService"
|
||||
import { setVscodeHostProviderMock } from "@/test/host-provider-test-utils"
|
||||
import { NoOpTelemetryProvider, TelemetryProviderFactory, type TelemetryProviderType } from "./TelemetryProviderFactory"
|
||||
import { TelemetryService } from "./TelemetryService"
|
||||
|
||||
describe("Telemetry system is abstracted and can easily switch between providers", () => {
|
||||
before(() => {
|
||||
setVscodeHostProviderMock()
|
||||
})
|
||||
|
||||
const MOCK_USER_INFO = {
|
||||
id: "test-user-123",
|
||||
email: "test@example.com",
|
||||
@@ -28,7 +33,7 @@ describe("Telemetry system is abstracted and can easily switch between providers
|
||||
|
||||
describe("Telemetry Service", () => {
|
||||
it("should include correct metadata with telemetry events", async () => {
|
||||
const noOpProvider = TelemetryProviderFactory.createProvider({
|
||||
const noOpProvider = await TelemetryProviderFactory.createProvider({
|
||||
type: "none",
|
||||
})
|
||||
|
||||
@@ -80,7 +85,7 @@ describe("Telemetry system is abstracted and can easily switch between providers
|
||||
describe("PostHog Provider", () => {
|
||||
it("should create PostHog provider and track events", async () => {
|
||||
console.log("=== Testing PostHog Provider ===")
|
||||
const posthogProvider = TelemetryProviderFactory.createProvider({
|
||||
const posthogProvider = await TelemetryProviderFactory.createProvider({
|
||||
type: "posthog",
|
||||
})
|
||||
|
||||
@@ -111,7 +116,7 @@ describe("Telemetry system is abstracted and can easily switch between providers
|
||||
describe("No-Op Provider", () => {
|
||||
it("should create No-Op provider and handle all operations safely", async () => {
|
||||
console.log("\n=== Testing No-Op Provider ===")
|
||||
const noOpProvider = TelemetryProviderFactory.createProvider({
|
||||
const noOpProvider = await TelemetryProviderFactory.createProvider({
|
||||
type: "none",
|
||||
})
|
||||
|
||||
@@ -156,22 +161,16 @@ describe("Telemetry system is abstracted and can easily switch between providers
|
||||
|
||||
it("should handle unsupported provider types by returning No-Op provider", async () => {
|
||||
console.log("\n=== Testing Unsupported Provider Type ===")
|
||||
|
||||
// Spy on console.error to verify error logging
|
||||
const consoleSpy = sinon.stub(console, "error")
|
||||
|
||||
// Test unsupported type by casting to bypass TypeScript checking
|
||||
const unsupportedProvider = TelemetryProviderFactory.createProvider({
|
||||
const unsupportedProvider = await TelemetryProviderFactory.createProvider({
|
||||
type: "unsupported_provider" as TelemetryProviderType,
|
||||
})
|
||||
|
||||
// Should have logged an error
|
||||
assert.ok(
|
||||
consoleSpy.calledWith("Unsupported telemetry provider type: unsupported_provider"),
|
||||
"Should log error for unsupported provider type",
|
||||
)
|
||||
|
||||
// Should return NoOp provider
|
||||
assert.ok(
|
||||
unsupportedProvider instanceof NoOpTelemetryProvider,
|
||||
"Unsupported provider should be an instance of NoOpTelemetryProvider",
|
||||
)
|
||||
assert.strictEqual(unsupportedProvider.isEnabled(), false, "Unsupported provider should return NoOp provider")
|
||||
assert.deepStrictEqual(
|
||||
unsupportedProvider.getSettings(),
|
||||
@@ -189,9 +188,6 @@ describe("Telemetry system is abstracted and can easily switch between providers
|
||||
telemetryService.identifyAccount(MOCK_USER_INFO)
|
||||
|
||||
await unsupportedProvider.dispose()
|
||||
|
||||
// Restore console.error
|
||||
consoleSpy.restore()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -212,7 +208,7 @@ describe("Telemetry system is abstracted and can easily switch between providers
|
||||
console.log("\n=== Testing Provider Switching ===")
|
||||
|
||||
// Start with PostHog provider
|
||||
const posthogProvider = TelemetryProviderFactory.createProvider({
|
||||
const posthogProvider = await TelemetryProviderFactory.createProvider({
|
||||
type: "posthog",
|
||||
})
|
||||
let telemetryService = new TelemetryService(posthogProvider, MOCK_METADATA)
|
||||
@@ -223,7 +219,7 @@ describe("Telemetry system is abstracted and can easily switch between providers
|
||||
await posthogProvider.dispose()
|
||||
|
||||
// Switch to No-Op provider
|
||||
const noOpProvider = TelemetryProviderFactory.createProvider({
|
||||
const noOpProvider = await TelemetryProviderFactory.createProvider({
|
||||
type: "none",
|
||||
})
|
||||
telemetryService = new TelemetryService(noOpProvider, MOCK_METADATA)
|
||||
@@ -5,6 +5,7 @@ import type { TaskFeedbackType } from "@shared/WebviewMessage"
|
||||
import * as os from "os"
|
||||
import * as vscode from "vscode"
|
||||
import { ClineAccountUserInfo } from "@/services/auth/AuthService"
|
||||
import { Setting } from "@/shared/proto/index.host"
|
||||
import { Mode } from "@/shared/storage/types"
|
||||
import { version as extensionVersion } from "../../../package.json"
|
||||
import { setDistinctId } from "../logging/distinctId"
|
||||
@@ -173,7 +174,7 @@ export class TelemetryService {
|
||||
}
|
||||
|
||||
public static async create(): Promise<TelemetryService> {
|
||||
const provider = TelemetryProviderFactory.createProvider({
|
||||
const provider = await TelemetryProviderFactory.createProvider({
|
||||
type: "posthog",
|
||||
})
|
||||
const hostVersion = await HostProvider.env.getHostVersion({})
|
||||
@@ -209,7 +210,8 @@ export class TelemetryService {
|
||||
// First check global telemetry level - telemetry should only be enabled when level is "all"
|
||||
|
||||
// We only enable telemetry if global vscode telemetry is enabled
|
||||
if (!vscode.env.isTelemetryEnabled) {
|
||||
const telemetrySettings = await HostProvider.env.getTelemetrySettings({})
|
||||
if (telemetrySettings.isEnabled === Setting.DISABLED) {
|
||||
// Only show warning if user has opted in to Cline telemetry but VS Code telemetry is disabled
|
||||
if (didUserOptIn) {
|
||||
const isVsCodeHost = vscode?.env?.uriScheme === "vscode"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { PostHog } from "posthog-node"
|
||||
import * as vscode from "vscode"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { getDistinctId, setDistinctId } from "@/services/logging/distinctId"
|
||||
import { Setting } from "@/shared/proto/index.host"
|
||||
import { posthogConfig } from "../../../shared/services/config/posthog-config"
|
||||
import type { ClineAccountUserInfo } from "../../auth/AuthService"
|
||||
import type { ITelemetryProvider, TelemetrySettings } from "./ITelemetryProvider"
|
||||
@@ -35,13 +37,15 @@ export class PostHogTelemetryProvider implements ITelemetryProvider {
|
||||
hostEnabled: true,
|
||||
level: "all",
|
||||
}
|
||||
|
||||
}
|
||||
public async initialize(): Promise<PostHogTelemetryProvider> {
|
||||
// Listen for VS Code telemetry changes
|
||||
vscode.env.onDidChangeTelemetryEnabled((isTelemetryEnabled) => {
|
||||
this.telemetrySettings.hostEnabled = isTelemetryEnabled
|
||||
})
|
||||
|
||||
if (vscode?.env?.isTelemetryEnabled === false) {
|
||||
const hostSettings = await HostProvider.env.getTelemetrySettings({})
|
||||
if (hostSettings.isEnabled === Setting.DISABLED) {
|
||||
this.telemetrySettings.hostEnabled = false
|
||||
}
|
||||
|
||||
@@ -51,7 +55,8 @@ export class PostHogTelemetryProvider implements ITelemetryProvider {
|
||||
this.telemetrySettings.extensionEnabled = false
|
||||
}
|
||||
|
||||
this.telemetrySettings.level = this.getTelemetryLevel()
|
||||
this.telemetrySettings.level = await this.getTelemetryLevel()
|
||||
return this
|
||||
}
|
||||
|
||||
public log(event: string, properties?: Record<string, unknown>): void {
|
||||
@@ -124,8 +129,9 @@ export class PostHogTelemetryProvider implements ITelemetryProvider {
|
||||
/**
|
||||
* Get the current telemetry level from VS Code settings
|
||||
*/
|
||||
private getTelemetryLevel(): TelemetrySettings["level"] {
|
||||
if (!vscode?.env?.isTelemetryEnabled) {
|
||||
private async getTelemetryLevel(): Promise<TelemetrySettings["level"]> {
|
||||
const hostSettings = await HostProvider.env.getTelemetrySettings({})
|
||||
if (hostSettings.isEnabled === Setting.DISABLED) {
|
||||
return "off"
|
||||
}
|
||||
const config = vscode.workspace.getConfiguration("telemetry")
|
||||
|
||||
Reference in new issue
Block a user