Skip to content

Commit 9783834

Browse files
committed
add create env trigger telemetry
1 parent 804716f commit 9783834

3 files changed

Lines changed: 43 additions & 4 deletions

File tree

src/common/pickers/environments.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { Uri, ThemeIcon, QuickPickItem, QuickPickItemKind, ProgressLocation, QuickInputButtons } from 'vscode';
1+
import { ProgressLocation, QuickInputButtons, QuickPickItem, QuickPickItemKind, ThemeIcon, Uri } from 'vscode';
22
import { IconPath, PythonEnvironment, PythonProject } from '../../api';
33
import { InternalEnvironmentManager } from '../../internal.api';
44
import { Common, Interpreter, Pickers } from '../localize';
5-
import { showQuickPickWithButtons, showQuickPick, showOpenDialog, withProgress } from '../window.apis';
65
import { traceError } from '../logging';
7-
import { pickEnvironmentManager } from './managers';
8-
import { handlePythonPath } from '../utils/pythonPath';
6+
import { EventNames } from '../telemetry/constants';
7+
import { sendTelemetryEvent } from '../telemetry/sender';
98
import { isWindows } from '../utils/platformUtils';
9+
import { handlePythonPath } from '../utils/pythonPath';
10+
import { showOpenDialog, showQuickPick, showQuickPickWithButtons, withProgress } from '../window.apis';
11+
import { pickEnvironmentManager } from './managers';
1012

1113
type QuickPickIcon =
1214
| Uri
@@ -80,6 +82,7 @@ async function createEnvironment(
8082
const manager = managers.find((m) => m.id === managerId);
8183
if (manager) {
8284
try {
85+
// add telemetry here
8386
const env = await manager.create(
8487
options.projects.map((p) => p.uri),
8588
undefined,
@@ -111,6 +114,10 @@ async function pickEnvironmentImpl(
111114
if (selected.label === Interpreter.browsePath) {
112115
return browseForPython(managers, projectEnvManagers);
113116
} else if (selected.label === Interpreter.createVirtualEnvironment) {
117+
sendTelemetryEvent(EventNames.CREATE_ENVIRONMENT, undefined, {
118+
manager: 'none',
119+
triggeredLocation: 'pickEnv',
120+
});
114121
return createEnvironment(managers, projectEnvManagers, options);
115122
}
116123
return (selected as { result: PythonEnvironment })?.result;

src/common/telemetry/constants.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ export enum EventNames {
1212

1313
PACKAGE_MANAGEMENT = 'PACKAGE_MANAGEMENT',
1414
ADD_PROJECT = 'ADD_PROJECT',
15+
/**
16+
* Telemetry event for when a Python environment is created via command.
17+
* Properties:
18+
* - manager: string (the id of the environment manager used, or 'none')
19+
* - triggeredLocation: string (where the create command is called from)
20+
*/
21+
CREATE_ENVIRONMENT = 'CREATE_ENVIRONMENT',
1522
}
1623

1724
// Map all events to their properties
@@ -102,4 +109,15 @@ export interface IEventNamePropertyMapping {
102109
totalProjectCount: number;
103110
triggeredLocation: 'templateCreate' | 'add' | 'addGivenResource';
104111
};
112+
113+
/* __GDPR__
114+
"create_environment": {
115+
"manager": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "owner": "eleanorjboyd" },
116+
"triggeredLocation": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "owner": "eleanorjboyd" }
117+
}
118+
*/
119+
[EventNames.CREATE_ENVIRONMENT]: {
120+
manager: string;
121+
triggeredLocation: string;
122+
};
105123
}

src/extension.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,23 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
231231
await refreshPackagesCommand(item, envManagers);
232232
}),
233233
commands.registerCommand('python-envs.create', async (item) => {
234+
// Telemetry: record environment creation attempt with selected manager
235+
let managerId = 'unknown';
236+
if (item && item.manager && item.manager.id) {
237+
managerId = item.manager.id;
238+
}
239+
sendTelemetryEvent(EventNames.CREATE_ENVIRONMENT, undefined, {
240+
manager: managerId,
241+
triggeredLocation: 'createSpecifiedCommand',
242+
});
234243
return await createEnvironmentCommand(item, envManagers, projectManager);
235244
}),
236245
commands.registerCommand('python-envs.createAny', async (options) => {
246+
// Telemetry: record environment creation attempt with no specific manager
247+
sendTelemetryEvent(EventNames.CREATE_ENVIRONMENT, undefined, {
248+
manager: 'none',
249+
triggeredLocation: 'createAnyCommand',
250+
});
237251
return await createAnyEnvironmentCommand(
238252
envManagers,
239253
projectManager,

0 commit comments

Comments
 (0)