Skip to content

Commit 6dad67c

Browse files
authored
feat: add telemetry for install/uninstall packages (#302)
1 parent 0a2c7b1 commit 6dad67c

File tree

6 files changed

+55
-12
lines changed

6 files changed

+55
-12
lines changed

src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ export interface PackageManager {
596596
/**
597597
* Installs/Uninstall packages in the specified Python environment.
598598
* @param environment - The Python environment in which to install packages.
599-
* @param packages - The packages to install.
599+
* @param options - Options for managing packages.
600600
* @returns A promise that resolves when the installation is complete.
601601
*/
602602
manage(environment: PythonEnvironment, options: PackageManagementOptions): Promise<void>;

src/common/telemetry/constants.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export enum EventNames {
77

88
VENV_USING_UV = 'VENV.USING_UV',
99
VENV_CREATION = 'VENV.CREATION',
10+
11+
PACKAGE_MANAGEMENT = 'PACKAGE_MANAGEMENT',
1012
}
1113

1214
// Map all events to their properties
@@ -45,14 +47,23 @@ export interface IEventNamePropertyMapping {
4547
/* __GDPR__
4648
"venv.using_uv": {"owner": "karthiknadig" }
4749
*/
48-
[EventNames.VENV_USING_UV]: never | undefined;
49-
50-
/* __GDPR__
50+
[EventNames.VENV_USING_UV]: never | undefined /* __GDPR__
5151
"venv.creation": {
5252
"creationType": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "owner": "karthiknadig" }
5353
}
54-
*/
54+
*/;
5555
[EventNames.VENV_CREATION]: {
5656
creationType: 'quick' | 'custom';
5757
};
58+
59+
/* __GDPR__
60+
"package.install": {
61+
"managerId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "owner": "karthiknadig" },
62+
"result": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "owner": "karthiknadig" }
63+
}
64+
*/
65+
[EventNames.PACKAGE_MANAGEMENT]: {
66+
managerId: string;
67+
result: 'success' | 'error' | 'cancelled';
68+
};
5869
}

src/extension.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { commands, ExtensionContext, LogOutputChannel, Terminal, Uri } from 'vscode';
22

33
import { PythonEnvironmentManagers } from './features/envManagers';
4-
import { registerLogger, traceInfo } from './common/logging';
4+
import { registerLogger, traceError, traceInfo } from './common/logging';
55
import { EnvManagerView } from './features/views/envManagersView';
66
import {
77
addPythonProject,
@@ -138,7 +138,11 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
138138
envManagers,
139139
projectManager,
140140
);
141-
packageManager.manage(environment, { install: [] });
141+
try {
142+
packageManager.manage(environment, { install: [] });
143+
} catch (err) {
144+
traceError('Error when running command python-envs.packages', err);
145+
}
142146
}),
143147
commands.registerCommand('python-envs.uninstallPackage', async (context: unknown) => {
144148
await handlePackageUninstall(context, envManagers);

src/internal.api.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Disposable, Event, LogOutputChannel, MarkdownString, Uri } from 'vscode';
1+
import { CancellationError, Disposable, Event, LogOutputChannel, MarkdownString, Uri } from 'vscode';
22
import {
33
PythonEnvironment,
44
EnvironmentManager,
@@ -28,6 +28,8 @@ import {
2828
CreateEnvironmentOptions,
2929
} from './api';
3030
import { CreateEnvironmentNotSupported, RemoveEnvironmentNotSupported } from './common/errors/NotSupportedError';
31+
import { sendTelemetryEvent } from './common/telemetry/sender';
32+
import { EventNames } from './common/telemetry/constants';
3133

3234
export type EnvironmentManagerScope = undefined | string | Uri | PythonEnvironment;
3335
export type PackageManagerScope = undefined | string | Uri | PythonEnvironment | Package;
@@ -241,8 +243,21 @@ export class InternalPackageManager implements PackageManager {
241243
return this.manager.log;
242244
}
243245

244-
manage(environment: PythonEnvironment, options: PackageManagementOptions): Promise<void> {
245-
return this.manager.manage(environment, options);
246+
async manage(environment: PythonEnvironment, options: PackageManagementOptions): Promise<void> {
247+
try {
248+
await this.manager.manage(environment, options);
249+
sendTelemetryEvent(EventNames.PACKAGE_MANAGEMENT, undefined, { managerId: this.id, result: 'success' });
250+
} catch (error) {
251+
if (error instanceof CancellationError) {
252+
sendTelemetryEvent(EventNames.PACKAGE_MANAGEMENT, undefined, {
253+
managerId: this.id,
254+
result: 'cancelled',
255+
});
256+
throw error;
257+
}
258+
sendTelemetryEvent(EventNames.PACKAGE_MANAGEMENT, undefined, { managerId: this.id, result: 'error' });
259+
throw error;
260+
}
246261
}
247262

248263
refresh(environment: PythonEnvironment): Promise<void> {

src/managers/builtin/pipManager.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { Event, EventEmitter, LogOutputChannel, MarkdownString, ProgressLocation, ThemeIcon, window } from 'vscode';
1+
import {
2+
CancellationError,
3+
Event,
4+
EventEmitter,
5+
LogOutputChannel,
6+
MarkdownString,
7+
ProgressLocation,
8+
ThemeIcon,
9+
window,
10+
} from 'vscode';
211
import {
312
DidChangePackagesEventArgs,
413
IconPath,
@@ -82,13 +91,17 @@ export class PipPackageManager implements PackageManager, Disposable {
8291
this.packages.set(environment.envId.id, after);
8392
this._onDidChangePackages.fire({ environment, manager: this, changes });
8493
} catch (e) {
94+
if (e instanceof CancellationError) {
95+
throw e;
96+
}
8597
this.log.error('Error managing packages', e);
8698
setImmediate(async () => {
8799
const result = await window.showErrorMessage('Error managing packages', 'View Output');
88100
if (result === 'View Output') {
89101
this.log.show();
90102
}
91103
});
104+
throw e;
92105
}
93106
},
94107
);

src/managers/conda/condaPackageManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class CondaPackageManager implements PackageManager, Disposable {
8585
this._onDidChangePackages.fire({ environment: environment, manager: this, changes });
8686
} catch (e) {
8787
if (e instanceof CancellationError) {
88-
return;
88+
throw e;
8989
}
9090

9191
this.log.error('Error installing packages', e);

0 commit comments

Comments
 (0)