diff --git a/news/3 Code Health/3901.md b/news/3 Code Health/3901.md new file mode 100644 index 000000000000..17a47f769bce --- /dev/null +++ b/news/3 Code Health/3901.md @@ -0,0 +1 @@ +Add telemetry to check if global interpreter is used in workspace. diff --git a/src/client/extension.ts b/src/client/extension.ts index 359e58f54da0..fdc24bf5522c 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -311,7 +311,14 @@ async function sendStartupTelemetry(activatedPromise: Promise, serviceConta traceError('sendStartupTelemetry() failed.', ex); } } - +function isUsingGlobalInterpreterInWorkspace(currentPythonPath: string, serviceContainer: IServiceContainer): boolean { + const service = serviceContainer.get(IInterpreterAutoSelectionService); + const globalInterpreter = service.getAutoSelectedInterpreter(undefined); + if (!globalInterpreter) { + return false; + } + return currentPythonPath === globalInterpreter.path; +} function hasUserDefinedPythonPath(resource: Resource, serviceContainer: IServiceContainer) { const workspaceService = serviceContainer.get(IWorkspaceService); const settings = workspaceService.getConfiguration('python', resource)!.inspect('pyhontPath')!; @@ -355,6 +362,7 @@ async function getActivationTelemetryProps(serviceContainer: IServiceContainer): const interpreterType = interpreter ? interpreter.type : undefined; const hasUserDefinedInterpreter = hasUserDefinedPythonPath(mainWorkspaceUri, serviceContainer); const preferredWorkspaceInterpreter = getPreferredWorkspaceInterpreter(mainWorkspaceUri, serviceContainer); + const isUsingGlobalInterpreter = isUsingGlobalInterpreterInWorkspace(settings.pythonPath, serviceContainer); const isAutoSelectedWorkspaceInterpreterUsed = preferredWorkspaceInterpreter ? settings.pythonPath === getPreferredWorkspaceInterpreter(mainWorkspaceUri, serviceContainer) : undefined; const hasPython3 = interpreters .filter(item => item && item.version ? item.version.major === 3 : false) @@ -368,7 +376,8 @@ async function getActivationTelemetryProps(serviceContainer: IServiceContainer): workspaceFolderCount, hasPython3, hasUserDefinedInterpreter, - isAutoSelectedWorkspaceInterpreterUsed + isAutoSelectedWorkspaceInterpreterUsed, + isUsingGlobalInterpreter }; }