Skip to content

Commit

Permalink
Add telemetry event when creating environment using button (#21172)
Browse files Browse the repository at this point in the history
A temporary command to understand the usage of the create environment
button.

Fixes #21168
  • Loading branch information
karthiknadig authored May 3, 2023
1 parent f5eded2 commit 7dfa631
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@
"command": "python.createEnvironment",
"title": "%python.command.python.createEnvironment.title%"
},
{
"category": "Python",
"command": "python.createEnvironment-button",
"title": "%python.command.python.createEnvironment.title%"
},
{
"category": "Python",
"command": "python.enableLinting",
Expand Down Expand Up @@ -1700,12 +1705,12 @@
"editor/content": [
{
"group": "Python",
"command": "python.createEnvironment",
"command": "python.createEnvironment-button",
"when": "resourceLangId == pip-requirements && !virtualWorkspace && shellExecutionSupported && !inDiffEditor"
},
{
"group": "Python",
"command": "python.createEnvironment",
"command": "python.createEnvironment-button",
"when": "resourceFilename == pyproject.toml && pipInstallableToml && !virtualWorkspace && shellExecutionSupported && !inDiffEditor"
}
],
Expand Down
1 change: 1 addition & 0 deletions src/client/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export namespace Commands {
export const CreateNewFile = 'python.createNewFile';
export const ClearWorkspaceInterpreter = 'python.clearWorkspaceInterpreter';
export const Create_Environment = 'python.createEnvironment';
export const Create_Environment_Button = 'python.createEnvironment-button';
export const Create_Terminal = 'python.createTerminal';
export const Debug_In_Terminal = 'python.debugInTerminal';
export const Enable_Linter = 'python.enableLinting';
Expand Down
11 changes: 10 additions & 1 deletion src/client/pythonEnvironments/creation/createEnvApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { ConfigurationTarget, Disposable } from 'vscode';
import { Commands } from '../../common/constants';
import { IDisposableRegistry, IInterpreterPathService, IPathUtils } from '../../common/types';
import { registerCommand } from '../../common/vscodeApis/commandApis';
import { executeCommand, registerCommand } from '../../common/vscodeApis/commandApis';
import { IInterpreterQuickPick } from '../../interpreter/configuration/types';
import { getCreationEvents, handleCreateEnvironmentCommand } from './createEnvironment';
import { condaCreationProvider } from './provider/condaCreationProvider';
Expand All @@ -18,6 +18,8 @@ import {
ProposedCreateEnvironmentAPI,
EnvironmentDidCreateEvent,
} from './proposed.createEnvApis';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';

class CreateEnvironmentProviders {
private _createEnvProviders: CreateEnvironmentProvider[] = [];
Expand Down Expand Up @@ -67,6 +69,13 @@ export function registerCreateEnvironmentFeatures(
return handleCreateEnvironmentCommand(providers, options);
},
),
registerCommand(
Commands.Create_Environment_Button,
async (): Promise<void> => {
sendTelemetryEvent(EventName.ENVIRONMENT_BUTTON, undefined, undefined);
await executeCommand(Commands.Create_Environment);
},
),
registerCreateEnvironmentProvider(new VenvCreationProvider(interpreterQuickPick)),
registerCreateEnvironmentProvider(condaCreationProvider()),
onCreateEnvironmentExited(async (e: EnvironmentDidCreateEvent) => {
Expand Down
1 change: 1 addition & 0 deletions src/client/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export enum EventName {
ENVIRONMENT_INSTALLING_PACKAGES = 'ENVIRONMENT.INSTALLING_PACKAGES',
ENVIRONMENT_INSTALLED_PACKAGES = 'ENVIRONMENT.INSTALLED_PACKAGES',
ENVIRONMENT_INSTALLING_PACKAGES_FAILED = 'ENVIRONMENT.INSTALLING_PACKAGES_FAILED',
ENVIRONMENT_BUTTON = 'ENVIRONMENT.BUTTON',

TOOLS_EXTENSIONS_ALREADY_INSTALLED = 'TOOLS_EXTENSIONS.ALREADY_INSTALLED',
TOOLS_EXTENSIONS_PROMPT_SHOWN = 'TOOLS_EXTENSIONS.PROMPT_SHOWN',
Expand Down
7 changes: 7 additions & 0 deletions src/client/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2098,6 +2098,13 @@ export interface IEventNamePropertyMapping {
environmentType: 'venv' | 'conda' | 'microvenv';
using: 'pipUpgrade' | 'requirements.txt' | 'pyproject.toml' | 'environment.yml' | 'pipDownload' | 'pipInstall';
};
/**
* Telemetry event sent if create environment button was used to trigger the command.
*/
/* __GDPR__
"environment.button" : {"owner": "karthiknadig" }
*/
[EventName.ENVIRONMENT_BUTTON]: never | undefined;
/**
* Telemetry event sent when a linter or formatter extension is already installed.
*/
Expand Down

0 comments on commit 7dfa631

Please sign in to comment.