Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3 Code Health/3901.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add telemetry to check if global interpreter is used in workspace.
13 changes: 11 additions & 2 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,14 @@ async function sendStartupTelemetry(activatedPromise: Promise<any>, serviceConta
traceError('sendStartupTelemetry() failed.', ex);
}
}

function isUsingGlobalInterpreterInWorkspace(currentPythonPath: string, serviceContainer: IServiceContainer): boolean {
const service = serviceContainer.get<IInterpreterAutoSelectionService>(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>(IWorkspaceService);
const settings = workspaceService.getConfiguration('python', resource)!.inspect<string>('pyhontPath')!;
Expand Down Expand Up @@ -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)
Expand All @@ -368,7 +376,8 @@ async function getActivationTelemetryProps(serviceContainer: IServiceContainer):
workspaceFolderCount,
hasPython3,
hasUserDefinedInterpreter,
isAutoSelectedWorkspaceInterpreterUsed
isAutoSelectedWorkspaceInterpreterUsed,
isUsingGlobalInterpreter
};
}

Expand Down