Skip to content

Commit 7f5dae9

Browse files
authored
Add telemetry for pipenv interpreter discovery (#11507)
* Add pipenv discovery telemetry (update when getInterpreters signature change gets merged) * Update after master merge + add unit test
1 parent 0950f21 commit 7f5dae9

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

news/3 Code Health/11128.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add telemetry for pipenv interpreter discovery.

src/client/interpreter/locators/services/pipEnvService.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ import { traceError, traceWarning } from '../../../common/logger';
99
import { IFileSystem, IPlatformService } from '../../../common/platform/types';
1010
import { IProcessServiceFactory } from '../../../common/process/types';
1111
import { IConfigurationService, ICurrentProcess } from '../../../common/types';
12+
import { StopWatch } from '../../../common/utils/stopWatch';
1213
import { IServiceContainer } from '../../../ioc/types';
13-
import { IInterpreterHelper, InterpreterType, IPipEnvService, PythonInterpreter } from '../../contracts';
14+
import { sendTelemetryEvent } from '../../../telemetry';
15+
import { EventName } from '../../../telemetry/constants';
16+
import {
17+
GetInterpreterLocatorOptions,
18+
IInterpreterHelper,
19+
InterpreterType,
20+
IPipEnvService,
21+
PythonInterpreter
22+
} from '../../contracts';
1423
import { IPipEnvServiceHelper } from '../types';
1524
import { CacheableLocatorService } from './cacheableLocatorService';
1625

@@ -49,6 +58,18 @@ export class PipEnvService extends CacheableLocatorService implements IPipEnvSer
4958
return this.configService.getSettings().pipenvPath;
5059
}
5160

61+
public async getInterpreters(resource?: Uri, options?: GetInterpreterLocatorOptions): Promise<PythonInterpreter[]> {
62+
const stopwatch = new StopWatch();
63+
const startDiscoveryTime = stopwatch.elapsedTime;
64+
65+
const interpreters = await super.getInterpreters(resource, options);
66+
67+
const discoveryDuration = stopwatch.elapsedTime - startDiscoveryTime;
68+
sendTelemetryEvent(EventName.PIPENV_INTERPRETER_DISCOVERY, discoveryDuration);
69+
70+
return interpreters;
71+
}
72+
5273
protected getInterpretersImplementation(resource?: Uri): Promise<PythonInterpreter[]> {
5374
const pipenvCwd = this.getPipenvWorkingDirectory(resource);
5475
if (!pipenvCwd) {

src/client/telemetry/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export enum EventName {
2828
PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES = 'PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES',
2929
PYTHON_INTERPRETER_ACTIVATION_FOR_RUNNING_CODE = 'PYTHON_INTERPRETER_ACTIVATION_FOR_RUNNING_CODE',
3030
PYTHON_INTERPRETER_ACTIVATION_FOR_TERMINAL = 'PYTHON_INTERPRETER_ACTIVATION_FOR_TERMINAL',
31+
PIPENV_INTERPRETER_DISCOVERY = 'PIPENV_INTERPRETER_DISCOVERY',
3132
TERMINAL_SHELL_IDENTIFICATION = 'TERMINAL_SHELL_IDENTIFICATION',
3233
PYTHON_INTERPRETER_ACTIVATE_ENVIRONMENT_PROMPT = 'PYTHON_INTERPRETER_ACTIVATE_ENVIRONMENT_PROMPT',
3334
PYTHON_NOT_INSTALLED_PROMPT = 'PYTHON_NOT_INSTALLED_PROMPT',

src/client/telemetry/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,10 @@ export interface IEventNamePropertyMapping {
10421042
*/
10431043
interpreters?: number;
10441044
};
1045+
/**
1046+
* Telemetry event sent when pipenv interpreter discovery is executed.
1047+
*/
1048+
[EventName.PIPENV_INTERPRETER_DISCOVERY]: never | undefined;
10451049
/**
10461050
* Telemetry event sent with details when user clicks the prompt with the following message
10471051
* `Prompt message` :- 'We noticed you're using a conda environment. If you are experiencing issues with this environment in the integrated terminal, we suggest the "terminal.integrated.inheritEnv" setting to be changed to false. Would you like to update this setting?'

src/test/interpreters/pipEnvService.unit.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as assert from 'assert';
99
import { expect } from 'chai';
1010
import * as path from 'path';
1111
import { SemVer } from 'semver';
12+
import * as sinon from 'sinon';
1213
import { anything, instance, mock, when } from 'ts-mockito';
1314
import * as TypeMoq from 'typemoq';
1415
import { Uri, WorkspaceFolder } from 'vscode';
@@ -29,6 +30,8 @@ import { PipEnvService } from '../../client/interpreter/locators/services/pipEnv
2930
import { PipEnvServiceHelper } from '../../client/interpreter/locators/services/pipEnvServiceHelper';
3031
import { IPipEnvServiceHelper } from '../../client/interpreter/locators/types';
3132
import { IServiceContainer } from '../../client/ioc/types';
33+
import * as Telemetry from '../../client/telemetry';
34+
import { EventName } from '../../client/telemetry/constants';
3235

3336
enum OS {
3437
Mac,
@@ -271,6 +274,15 @@ suite('Interpreters - PipEnv', () => {
271274
const pipenvExe = pipEnvService.executable;
272275
assert.equal(pipenvExe, 'spam-spam-pipenv-spam-spam', 'Failed to identify pipenv.exe');
273276
});
277+
278+
test('Should send telemetry event when calling getInterpreters', async () => {
279+
const sendTelemetryStub = sinon.stub(Telemetry, 'sendTelemetryEvent');
280+
281+
await pipEnvService.getInterpreters(resource);
282+
283+
sinon.assert.calledWith(sendTelemetryStub, EventName.PIPENV_INTERPRETER_DISCOVERY);
284+
sinon.restore();
285+
});
274286
});
275287
});
276288
});

0 commit comments

Comments
 (0)