Skip to content

Commit c13bb07

Browse files
REPL Telemetry for Terminal REPL and Native REPL (#23941)
Resolves: #23740 Also organize Telemetry for Terminal REPL vs. Native REPL. Now we can sort them out with new attribute 'replType' on the REPL Event. With this PR: - (EventName.REPL, { replType: 'Terminal' }) for when people launch Terminal REPL via Command Palette, Manually type Python in terminal (tried to account for all Python cases that will trigger REPL). - (EventName.REPL, { replType: 'Native' }) for when people launch Native REPL via Command Palette. --------- Co-authored-by: Karthik Nadig <[email protected]>
1 parent f417024 commit c13bb07

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

src/client/extensionActivation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { logAndNotifyOnLegacySettings } from './logging/settingLogs';
5353
import { DebuggerTypeName } from './debugger/constants';
5454
import { StopWatch } from './common/utils/stopWatch';
5555
import { registerReplCommands, registerReplExecuteOnEnter, registerStartNativeReplCommand } from './repl/replCommands';
56+
import { registerTriggerForTerminalREPL } from './terminals/codeExecution/terminalReplWatcher';
5657

5758
export async function activateComponents(
5859
// `ext` is passed to any extra activation funcs.
@@ -108,6 +109,7 @@ export function activateFeatures(ext: ExtensionState, _components: Components):
108109
);
109110
const executionHelper = ext.legacyIOC.serviceContainer.get<ICodeExecutionHelper>(ICodeExecutionHelper);
110111
const commandManager = ext.legacyIOC.serviceContainer.get<ICommandManager>(ICommandManager);
112+
registerTriggerForTerminalREPL(ext.disposables);
111113
registerStartNativeReplCommand(ext.disposables, interpreterService);
112114
registerReplCommands(ext.disposables, interpreterService, executionHelper, commandManager);
113115
registerReplExecuteOnEnter(ext.disposables, interpreterService, commandManager);

src/client/providers/replProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class ReplProvider implements Disposable {
2828
this.disposables.push(disposable);
2929
}
3030

31-
@captureTelemetry(EventName.REPL)
31+
@captureTelemetry(EventName.REPL, { replType: 'Terminal' })
3232
private async commandHandler() {
3333
const resource = this.activeResourceService.getActiveResource();
3434
const interpreterService = this.serviceContainer.get<IInterpreterService>(IInterpreterService);

src/client/repl/replCommands.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
isMultiLineText,
1616
} from './replUtils';
1717
import { registerCommand } from '../common/vscodeApis/commandApis';
18+
import { sendTelemetryEvent } from '../telemetry';
19+
import { EventName } from '../telemetry/constants';
1820

1921
/**
2022
* Register Start Native REPL command in the command palette
@@ -30,6 +32,7 @@ export async function registerStartNativeReplCommand(
3032
): Promise<void> {
3133
disposables.push(
3234
registerCommand(Commands.Start_Native_REPL, async (uri: Uri) => {
35+
sendTelemetryEvent(EventName.REPL, undefined, { replType: 'Native' });
3336
const interpreter = await getActiveInterpreter(uri, interpreterService);
3437
if (interpreter) {
3538
if (interpreter) {
@@ -61,7 +64,6 @@ export async function registerReplCommands(
6164
await executeInTerminal();
6265
return;
6366
}
64-
6567
const interpreter = await getActiveInterpreter(uri, interpreterService);
6668

6769
if (interpreter) {

src/client/telemetry/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,10 +2305,15 @@ export interface IEventNamePropertyMapping {
23052305
*/
23062306
/* __GDPR__
23072307
"repl" : {
2308-
"duration" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "owner": "karthiknadig" }
2308+
"duration" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "owner": "anthonykim1" }
23092309
}
23102310
*/
2311-
[EventName.REPL]: never | undefined;
2311+
[EventName.REPL]: {
2312+
/**
2313+
* Whether the user launched the Terminal REPL or Native REPL
2314+
*/
2315+
replType: 'Terminal' | 'Native';
2316+
};
23122317
/**
23132318
* Telemetry event sent if and when user configure tests command. This command can be trigerred from multiple places in the extension. (Command palette, prompt etc.)
23142319
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Disposable, TerminalShellExecutionStartEvent } from 'vscode';
2+
import { onDidStartTerminalShellExecution } from '../../common/vscodeApis/windowApis';
3+
import { sendTelemetryEvent } from '../../telemetry';
4+
import { EventName } from '../../telemetry/constants';
5+
6+
function checkREPLCommand(command: string): boolean {
7+
const lower = command.toLowerCase().trimStart();
8+
return lower.startsWith('python ') || lower.startsWith('py ');
9+
}
10+
11+
export function registerTriggerForTerminalREPL(disposables: Disposable[]): void {
12+
disposables.push(
13+
onDidStartTerminalShellExecution(async (e: TerminalShellExecutionStartEvent) => {
14+
if (e.execution.commandLine.isTrusted && checkREPLCommand(e.execution.commandLine.value)) {
15+
sendTelemetryEvent(EventName.REPL, undefined, { replType: 'Terminal' });
16+
}
17+
}),
18+
);
19+
}

0 commit comments

Comments
 (0)