Skip to content

Commit 5a827bb

Browse files
author
Kartik Raj
committed
Bring back telemetry for prompt
1 parent 7505051 commit 5a827bb

File tree

4 files changed

+43
-37
lines changed

4 files changed

+43
-37
lines changed

src/client/application/diagnostics/checks/pythonInterpreter.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,18 @@ import { BaseDiagnostic, BaseDiagnosticsService } from '../base';
1414
import { IDiagnosticsCommandFactory } from '../commands/types';
1515
import { DiagnosticCodes } from '../constants';
1616
import { DiagnosticCommandPromptHandlerServiceId, MessageCommandPrompt } from '../promptHandler';
17-
import { DiagnosticScope, IDiagnostic, IDiagnosticCommand, IDiagnosticHandlerService } from '../types';
17+
import {
18+
DiagnosticScope,
19+
IDiagnostic,
20+
IDiagnosticCommand,
21+
IDiagnosticHandlerService,
22+
IDiagnosticMessageOnCloseHandler,
23+
} from '../types';
1824
import { Common } from '../../../common/utils/localize';
1925
import { Commands } from '../../../common/constants';
2026
import { IWorkspaceService } from '../../../common/application/types';
27+
import { sendTelemetryEvent } from '../../../telemetry';
28+
import { EventName } from '../../../telemetry/constants';
2129

2230
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
2331

@@ -125,7 +133,8 @@ export class InvalidPythonInterpreterService extends BaseDiagnosticsService {
125133
return;
126134
}
127135
const commandPrompts = this.getCommandPrompts(diagnostic);
128-
await messageService.handle(diagnostic, { commandPrompts, message: diagnostic.message });
136+
const onClose = getOnCloseHandler(diagnostic);
137+
await messageService.handle(diagnostic, { commandPrompts, message: diagnostic.message, onClose });
129138
}),
130139
);
131140
}
@@ -143,3 +152,14 @@ export class InvalidPythonInterpreterService extends BaseDiagnosticsService {
143152
];
144153
}
145154
}
155+
156+
function getOnCloseHandler(diagnostic: IDiagnostic): IDiagnosticMessageOnCloseHandler | undefined {
157+
if (diagnostic.code === DiagnosticCodes.NoPythonInterpretersDiagnostic) {
158+
return (response?: string) => {
159+
sendTelemetryEvent(EventName.PYTHON_NOT_INSTALLED_PROMPT, undefined, {
160+
selection: response ? 'Download' : 'Ignore',
161+
});
162+
};
163+
}
164+
return undefined;
165+
}

src/client/telemetry/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export enum EventName {
2626
PYTHON_INTERPRETER_ACTIVATION_FOR_TERMINAL = 'PYTHON_INTERPRETER_ACTIVATION_FOR_TERMINAL',
2727
TERMINAL_SHELL_IDENTIFICATION = 'TERMINAL_SHELL_IDENTIFICATION',
2828
PYTHON_INTERPRETER_ACTIVATE_ENVIRONMENT_PROMPT = 'PYTHON_INTERPRETER_ACTIVATE_ENVIRONMENT_PROMPT',
29+
PYTHON_NOT_INSTALLED_PROMPT = 'PYTHON_NOT_INSTALLED_PROMPT',
2930
CONDA_INHERIT_ENV_PROMPT = 'CONDA_INHERIT_ENV_PROMPT',
3031
ENVFILE_VARIABLE_SUBSTITUTION = 'ENVFILE_VARIABLE_SUBSTITUTION',
3132
ENVFILE_WORKSPACE = 'ENVFILE_WORKSPACE',

src/client/telemetry/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,24 @@ export interface IEventNamePropertyMapping {
13181318
*/
13191319
selection: 'Yes' | 'No' | 'Ignore' | undefined;
13201320
};
1321+
/**
1322+
* Telemetry event sent with details when the user clicks a button in the "Python is not installed" prompt.
1323+
* * `Prompt message` :- 'Python is not installed. Please download and install Python before using the extension.'
1324+
*/
1325+
/* __GDPR__
1326+
"python_not_installed_prompt" : {
1327+
"selection" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "owner": "karrtikr" }
1328+
}
1329+
*/
1330+
[EventName.PYTHON_NOT_INSTALLED_PROMPT]: {
1331+
/**
1332+
* `Download` When the 'Download' option is clicked
1333+
* `Ignore` When the prompt is dismissed
1334+
*
1335+
* @type {('Download' | 'Ignore' | undefined)}
1336+
*/
1337+
selection: 'Download' | 'Ignore' | undefined;
1338+
};
13211339
/**
13221340
* Telemetry event sent when the experiments service is initialized for the first time.
13231341
*/

src/test/application/diagnostics/checks/pythonInterpreter.unit.test.ts

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
182182
settings.verifyAll();
183183
interpreterService.verifyAll();
184184
});
185-
test('Handling no interpreters diagnostic should return download link', async () => {
185+
test('Handling no interpreters diagnostic should return select interpreter cmd', async () => {
186186
const diagnostic = new InvalidPythonInterpreterDiagnostic(
187187
DiagnosticCodes.NoPythonInterpretersDiagnostic,
188188
undefined,
@@ -219,6 +219,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
219219
command: cmd,
220220
},
221221
]);
222+
expect(messagePrompt!.onClose).to.not.be.equal(undefined, 'onClose handler should be set.');
222223
});
223224

224225
test('Handling no currently selected interpreter diagnostic should show select interpreter message', async () => {
@@ -254,41 +255,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
254255
expect(messagePrompt!.commandPrompts).to.be.deep.equal([
255256
{ prompt: Common.selectPythonInterpreter, command: cmd },
256257
]);
257-
});
258-
test('Handling no interpreters diagnostic should return select interpreter cmd', async () => {
259-
const diagnostic = new InvalidPythonInterpreterDiagnostic(
260-
DiagnosticCodes.InvalidPythonInterpreterDiagnostic,
261-
undefined,
262-
workspaceService.object,
263-
);
264-
const cmd = ({} as any) as IDiagnosticCommand;
265-
let messagePrompt: MessageCommandPrompt | undefined;
266-
messageHandler
267-
.setup((i) => i.handle(typemoq.It.isValue(diagnostic), typemoq.It.isAny()))
268-
.callback((_d, p: MessageCommandPrompt) => (messagePrompt = p))
269-
.returns(() => Promise.resolve())
270-
.verifiable(typemoq.Times.once());
271-
commandFactory
272-
.setup((f) =>
273-
f.createCommand(
274-
typemoq.It.isAny(),
275-
typemoq.It.isObjectWith<CommandOption<'executeVSCCommand', CommandsWithoutArgs>>({
276-
type: 'executeVSCCommand',
277-
}),
278-
),
279-
)
280-
.returns(() => cmd)
281-
.verifiable(typemoq.Times.once());
282-
283-
await diagnosticService.handle([diagnostic]);
284-
285-
messageHandler.verifyAll();
286-
commandFactory.verifyAll();
287-
expect(messagePrompt).not.be.equal(undefined, 'Message prompt not set');
288258
expect(messagePrompt!.onClose).be.equal(undefined, 'onClose handler should not be set.');
289-
expect(messagePrompt!.commandPrompts).to.be.deep.equal([
290-
{ prompt: 'Select Python Interpreter', command: cmd },
291-
]);
292259
});
293260
test('Handling an empty diagnostic should not show a message nor return a command', async () => {
294261
const diagnostics: IDiagnostic[] = [];

0 commit comments

Comments
 (0)