Skip to content

Commit 85e0400

Browse files
authored
Additional telemetry captured during startup (DonJayamanne#1864)
* Additional telemetry captured during startup * Add telemetry to capture type of python interpreter used in workspace
1 parent f81bc6b commit 85e0400

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

news/3 Code Health/1237.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add telemetry to capture type of python interpreter used in workspace.

news/3 Code Health/1545.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add telemetry to capture availability of Python 3, version of Python used in workspace and the number of workspace folders.

src/client/extension.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ if ((Reflect as any).metadata === undefined) {
55
// tslint:disable-next-line:no-require-imports no-var-requires
66
require('reflect-metadata');
77
}
8+
import { StopWatch } from './common/stopWatch';
9+
// Do not move this linne of code (used to measure extension load times).
10+
const stopWatch = new StopWatch();
11+
812
import { Container } from 'inversify';
9-
import {
10-
debug, Disposable, ExtensionContext,
11-
extensions, IndentAction, languages, Memento,
12-
OutputChannel, window
13-
} from 'vscode';
13+
import { debug, Disposable, ExtensionContext, extensions, IndentAction, languages, Memento, OutputChannel, window } from 'vscode';
1414
import { registerTypes as activationRegisterTypes } from './activation/serviceRegistry';
1515
import { IExtensionActivationService } from './activation/types';
16+
import { IWorkspaceService } from './common/application/types';
1617
import { PythonSettings } from './common/configSettings';
1718
import { PYTHON, PYTHON_LANGUAGE, STANDARD_OUTPUT_CHANNEL } from './common/constants';
1819
import { FeatureDeprecationManager } from './common/featureDeprecationManager';
@@ -22,7 +23,6 @@ import { registerTypes as installerRegisterTypes } from './common/installer/serv
2223
import { registerTypes as platformRegisterTypes } from './common/platform/serviceRegistry';
2324
import { registerTypes as processRegisterTypes } from './common/process/serviceRegistry';
2425
import { registerTypes as commonRegisterTypes } from './common/serviceRegistry';
25-
import { StopWatch } from './common/stopWatch';
2626
import { ITerminalHelper } from './common/terminal/types';
2727
import { GLOBAL_MEMENTO, IConfigurationService, IDisposableRegistry, IExtensionContext, ILogger, IMemento, IOutputChannel, IPersistentStateFactory, WORKSPACE_MEMENTO } from './common/types';
2828
import { registerTypes as variableRegisterTypes } from './common/variables/serviceRegistry';
@@ -32,7 +32,7 @@ import { registerTypes as debugConfigurationRegisterTypes } from './debugger/con
3232
import { IDebugConfigurationProvider } from './debugger/types';
3333
import { registerTypes as formattersRegisterTypes } from './formatters/serviceRegistry';
3434
import { IInterpreterSelector } from './interpreter/configuration/types';
35-
import { ICondaService, IInterpreterService } from './interpreter/contracts';
35+
import { ICondaService, IInterpreterService, PythonInterpreter } from './interpreter/contracts';
3636
import { registerTypes as interpretersRegisterTypes } from './interpreter/serviceRegistry';
3737
import { ServiceContainer } from './ioc/container';
3838
import { ServiceManager } from './ioc/serviceManager';
@@ -180,16 +180,28 @@ function registerServices(context: ExtensionContext, serviceManager: ServiceMana
180180
}
181181

182182
async function sendStartupTelemetry(activatedPromise: Promise<void>, serviceContainer: IServiceContainer) {
183-
const stopWatch = new StopWatch();
184183
const logger = serviceContainer.get<ILogger>(ILogger);
185184
try {
186185
await activatedPromise;
187186
const terminalHelper = serviceContainer.get<ITerminalHelper>(ITerminalHelper);
188187
const terminalShellType = terminalHelper.identifyTerminalShell(terminalHelper.getTerminalShellPath());
189188
const duration = stopWatch.elapsedTime;
190189
const condaLocator = serviceContainer.get<ICondaService>(ICondaService);
191-
const condaVersion = await condaLocator.getCondaVersion().catch(() => undefined);
192-
const props = { condaVersion, terminal: terminalShellType };
190+
const interpreterService = serviceContainer.get<IInterpreterService>(IInterpreterService);
191+
const [condaVersion, interpreter, interpreters] = await Promise.all([
192+
condaLocator.getCondaVersion().catch(() => undefined),
193+
interpreterService.getActiveInterpreter().catch<PythonInterpreter | undefined>(() => undefined),
194+
interpreterService.getInterpreters().catch<PythonInterpreter[]>(() => [])
195+
]);
196+
const workspaceService = serviceContainer.get<IWorkspaceService>(IWorkspaceService);
197+
const workspaceFolderCount = workspaceService.hasWorkspaceFolders ? workspaceService.workspaceFolders!.length : 0;
198+
const pythonVersion = interpreter ? interpreter.version_info.join('.') : undefined;
199+
const interpreterType = interpreter ? interpreter.type : undefined;
200+
const hasPython3 = interpreters
201+
.filter(item => item && Array.isArray(item.version_info) ? item.version_info[0] === 3 : false)
202+
.length > 0;
203+
204+
const props = { condaVersion, terminal: terminalShellType, pythonVersion, interpreterType, workspaceFolderCount, hasPython3 };
193205
sendTelemetryEvent(EDITOR_LOAD, duration, props);
194206
} catch (ex) {
195207
logger.logError('sendStartupTelemetry failed.', ex);

0 commit comments

Comments
 (0)