Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3 Code Health/2904.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use enums for event names instead of constants.
6 changes: 3 additions & 3 deletions src/client/activation/activationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '../common/types';
import { IServiceContainer } from '../ioc/types';
import { sendTelemetryEvent } from '../telemetry';
import { PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED } from '../telemetry/constants';
import { EventName } from '../telemetry/constants';
import {
ExtensionActivators, IExtensionActivationService,
IExtensionActivator
Expand Down Expand Up @@ -58,8 +58,8 @@ export class ExtensionActivationService implements IExtensionActivationService,
if (!jedi) {
const diagnostic = await this.lsNotSupportedDiagnosticService.diagnose();
this.lsNotSupportedDiagnosticService.handle(diagnostic).ignoreErrors();
if (diagnostic.length) {
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED);
if (diagnostic.length){
sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED);
jedi = true;
}
}
Expand Down
17 changes: 8 additions & 9 deletions src/client/activation/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import { createDeferred } from '../common/utils/async';
import { Common, LanguageService } from '../common/utils/localize';
import { StopWatch } from '../common/utils/stopWatch';
import { sendTelemetryEvent } from '../telemetry';
import { EventName } from '../telemetry/constants';
import {
PYTHON_LANGUAGE_SERVER_DOWNLOADED,
PYTHON_LANGUAGE_SERVER_ERROR,
PYTHON_LANGUAGE_SERVER_EXTRACTED
} from '../telemetry/constants';
import { IHttpClient, ILanguageServerDownloader, ILanguageServerFolderService, IPlatformData } from './types';
IHttpClient, ILanguageServerDownloader, ILanguageServerFolderService,
IPlatformData
} from './types';

const downloadFileExtension = '.nupkg';

Expand Down Expand Up @@ -53,11 +52,11 @@ export class LanguageServerDownloader implements ILanguageServerDownloader {
this.output.appendLine(err);
success = false;
this.showMessageAndOptionallyShowOutput(LanguageService.lsFailedToDownload()).ignoreErrors();
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_ERROR, undefined, { error: 'Failed to download (platform)' }, err);
sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_ERROR, undefined, { error: 'Failed to download (platform)' }, err);
throw new Error(err);
} finally {
sendTelemetryEvent(
PYTHON_LANGUAGE_SERVER_DOWNLOADED,
EventName.PYTHON_LANGUAGE_SERVER_DOWNLOADED,
timer.elapsedTime,
{ success, lsVersion }
);
Expand All @@ -71,11 +70,11 @@ export class LanguageServerDownloader implements ILanguageServerDownloader {
this.output.appendLine(err);
success = false;
this.showMessageAndOptionallyShowOutput(LanguageService.lsFailedToExtract()).ignoreErrors();
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_ERROR, undefined, { error: 'Failed to extract (platform)' }, err);
sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_ERROR, undefined, { error: 'Failed to extract (platform)' }, err);
throw new Error(err);
} finally {
sendTelemetryEvent(
PYTHON_LANGUAGE_SERVER_EXTRACTED,
EventName.PYTHON_LANGUAGE_SERVER_EXTRACTED,
timer.elapsedTime,
{ success, lsVersion }
);
Expand Down
12 changes: 4 additions & 8 deletions src/client/activation/languageServer/languageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import { Resource } from '../../common/types';
import { createDeferred, Deferred, sleep } from '../../common/utils/async';
import { noop } from '../../common/utils/misc';
import { captureTelemetry, sendTelemetryEvent } from '../../telemetry';
import {
PYTHON_LANGUAGE_SERVER_ENABLED,
PYTHON_LANGUAGE_SERVER_READY,
PYTHON_LANGUAGE_SERVER_TELEMETRY
} from '../../telemetry/constants';
import { EventName } from '../../telemetry/constants';
import { ProgressReporting } from '../progress';
import { ILanaguageServer as ILanguageServer, ILanguageClientFactory, LanguageClientFactory } from '../types';

Expand Down Expand Up @@ -51,15 +47,15 @@ export class LanguageServer implements ILanguageServer {
}

@traceDecorators.error('Failed to start language server')
@captureTelemetry(PYTHON_LANGUAGE_SERVER_ENABLED, undefined, true)
@captureTelemetry(EventName.PYTHON_LANGUAGE_SERVER_ENABLED, undefined, true)
public async start(resource: Resource, options: LanguageClientOptions): Promise<void> {
this.languageClient = await this.factory.createLanguageClient(resource, options);
this.disposables.push(this.languageClient!.start());
await this.serverReady();
const progressReporting = new ProgressReporting(this.languageClient!);
this.disposables.push(progressReporting);
this.languageClient.onTelemetry(telemetryEvent => {
const eventName = telemetryEvent.EventName || PYTHON_LANGUAGE_SERVER_TELEMETRY;
const eventName = telemetryEvent.EventName || EventName.PYTHON_LANGUAGE_SERVER_TELEMETRY;
sendTelemetryEvent(eventName, telemetryEvent.Measurements, telemetryEvent.Properties);
});
}
Expand All @@ -77,7 +73,7 @@ export class LanguageServer implements ILanguageServer {
)
.ignoreErrors();
}
@captureTelemetry(PYTHON_LANGUAGE_SERVER_READY, undefined, true)
@captureTelemetry(EventName.PYTHON_LANGUAGE_SERVER_READY, undefined, true)
private async serverReady(): Promise<void> {
while (this.languageClient && !this.languageClient!.initializeResult) {
await sleep(100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { inject, injectable } from 'inversify';
import { IDotNetCompatibilityService } from '../../common/dotnet/types';
import { traceError } from '../../common/logger';
import { sendTelemetryEvent } from '../../telemetry';
import { PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED } from '../../telemetry/constants';
import { EventName } from '../../telemetry/constants';
import { ILanguageServerCompatibilityService } from '../types';

@injectable()
Expand All @@ -16,11 +16,11 @@ export class LanguageServerCompatibilityService implements ILanguageServerCompat
public async isSupported(): Promise<boolean> {
try {
const supported = await this.dotnetCompatibility.isSupported();
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported });
sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported });
return supported;
} catch (ex) {
traceError('Unable to determine whether LS is supported', ex);
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported: false, failureType: 'UnknownError' });
sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported: false, failureType: 'UnknownError' });
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/activation/languageServer/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IDisposable, Resource } from '../../common/types';
import { debounce } from '../../common/utils/decorators';
import { IServiceContainer } from '../../ioc/types';
import { captureTelemetry } from '../../telemetry';
import { PYTHON_LANGUAGE_SERVER_STARTUP } from '../../telemetry/constants';
import { EventName } from '../../telemetry/constants';
import { ILanaguageServer, ILanguageServerAnalysisOptions, ILanguageServerManager } from '../types';

const loadExtensionCommand = 'python._loadLanguageServerExtension';
Expand Down Expand Up @@ -64,7 +64,7 @@ export class LanguageServerManager implements ILanguageServerManager {
}
await this.startLanguageServer();
}
@captureTelemetry(PYTHON_LANGUAGE_SERVER_STARTUP, undefined, true)
@captureTelemetry(EventName.PYTHON_LANGUAGE_SERVER_STARTUP, undefined, true)
@traceDecorators.verbose('Starting Language Server')
protected async startLanguageServer(): Promise<void> {
this.languageServer = this.serviceContainer.get<ILanaguageServer>(ILanaguageServer);
Expand Down
9 changes: 3 additions & 6 deletions src/client/activation/progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Disposable, LanguageClient } from 'vscode-languageclient';
import { createDeferred, Deferred } from '../common/utils/async';
import { StopWatch } from '../common/utils/stopWatch';
import { sendTelemetryEvent } from '../telemetry';
import { PYTHON_LANGUAGE_SERVER_ANALYSISTIME } from '../telemetry/constants';
import { EventName } from '../telemetry/constants';

// Draw the line at Language Server analysis 'timing out'
// and becoming a failure-case at 1 minute:
Expand All @@ -17,8 +17,6 @@ export class ProgressReporting implements Disposable {
private progress: Progress<{ message?: string; increment?: number }> | undefined;
private progressDeferred: Deferred<void> | undefined;
private progressTimer?: StopWatch;
// tslint:disable-next-line:no-unused-variable
private progressTimeout?: NodeJS.Timer;

constructor(private readonly languageClient: LanguageClient) {
this.languageClient.onNotification('python/setStatusBarMessage', (m: string) => {
Expand All @@ -35,7 +33,7 @@ export class ProgressReporting implements Disposable {

this.progressDeferred = createDeferred<void>();
this.progressTimer = new StopWatch();
this.progressTimeout = setTimeout(
setTimeout(
this.handleTimeout.bind(this),
ANALYSIS_TIMEOUT_MS
);
Expand Down Expand Up @@ -73,13 +71,12 @@ export class ProgressReporting implements Disposable {
private completeAnalysisTracking(success: boolean): void {
if (this.progressTimer) {
sendTelemetryEvent(
PYTHON_LANGUAGE_SERVER_ANALYSISTIME,
EventName.PYTHON_LANGUAGE_SERVER_ANALYSISTIME,
this.progressTimer.elapsedTime,
{ success }
);
}
this.progressTimer = undefined;
this.progressTimeout = undefined;
}

// tslint:disable-next-line:no-any
Expand Down
4 changes: 2 additions & 2 deletions src/client/application/diagnostics/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { injectable, unmanaged } from 'inversify';
import { DiagnosticSeverity } from 'vscode';
import { IServiceContainer } from '../../ioc/types';
import { sendTelemetryEvent } from '../../telemetry';
import { DIAGNOSTICS_MESSAGE } from '../../telemetry/constants';
import { EventName } from '../../telemetry/constants';
import { DiagnosticScope, IDiagnostic, IDiagnosticFilterService, IDiagnosticsService } from './types';

@injectable()
Expand All @@ -26,7 +26,7 @@ export abstract class BaseDiagnosticsService implements IDiagnosticsService {
public abstract diagnose(): Promise<IDiagnostic[]>;
public abstract handle(diagnostics: IDiagnostic[]): Promise<void>;
public async canHandle(diagnostic: IDiagnostic): Promise<boolean> {
sendTelemetryEvent(DIAGNOSTICS_MESSAGE, undefined, { code: diagnostic.code });
sendTelemetryEvent(EventName.DIAGNOSTICS_MESSAGE, undefined, { code: diagnostic.code });
return this.supportedDiagnosticCodes.filter(item => item === diagnostic.code).length > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useCommandPromptAsDefaultShell } from '../../../common/terminal/command
import { IConfigurationService, ICurrentProcess } from '../../../common/types';
import { IServiceContainer } from '../../../ioc/types';
import { sendTelemetryEvent } from '../../../telemetry';
import { DIAGNOSTICS_ACTION } from '../../../telemetry/constants';
import { EventName } from '../../../telemetry/constants';
import { BaseDiagnostic, BaseDiagnosticsService } from '../base';
import { IDiagnosticsCommandFactory } from '../commands/types';
import { DiagnosticCodes } from '../constants';
Expand Down Expand Up @@ -58,7 +58,7 @@ export class PowerShellActivationHackDiagnosticsService extends BaseDiagnosticsS
// tslint:disable-next-line:no-object-literal-type-assertion
command: {
diagnostic, invoke: async (): Promise<void> => {
sendTelemetryEvent(DIAGNOSTICS_ACTION, undefined, { action: 'switchToCommandPrompt' });
sendTelemetryEvent(EventName.DIAGNOSTICS_ACTION, undefined, { action: 'switchToCommandPrompt' });
useCommandPromptAsDefaultShell(currentProcess, configurationService)
.catch(ex => Logger.error('Use Command Prompt as default shell', ex));
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/application/diagnostics/commands/execVSCCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { ICommandManager } from '../../../common/application/types';
import { IServiceContainer } from '../../../ioc/types';
import { sendTelemetryEvent } from '../../../telemetry';
import { DIAGNOSTICS_ACTION } from '../../../telemetry/constants';
import { EventName } from '../../../telemetry/constants';
import { IDiagnostic } from '../types';
import { BaseDiagnosticCommand } from './base';

Expand All @@ -15,7 +15,7 @@ export class ExecuteVSCCommand extends BaseDiagnosticCommand {
super(diagnostic);
}
public async invoke(): Promise<void> {
sendTelemetryEvent(DIAGNOSTICS_ACTION, undefined, { commandName: this.commandName });
sendTelemetryEvent(EventName.DIAGNOSTICS_ACTION, undefined, { commandName: this.commandName });
const cmdManager = this.serviceContainer.get<ICommandManager>(ICommandManager);
return cmdManager.executeCommand(this.commandName).then(() => undefined);
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/application/diagnostics/commands/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { IServiceContainer } from '../../../ioc/types';
import { sendTelemetryEvent } from '../../../telemetry';
import { DIAGNOSTICS_ACTION } from '../../../telemetry/constants';
import { EventName } from '../../../telemetry/constants';
import { DiagnosticScope, IDiagnostic, IDiagnosticFilterService } from '../types';
import { BaseDiagnosticCommand } from './base';

Expand All @@ -14,7 +14,7 @@ export class IgnoreDiagnosticCommand extends BaseDiagnosticCommand {
super(diagnostic);
}
public invoke(): Promise<void> {
sendTelemetryEvent(DIAGNOSTICS_ACTION, undefined, { ignoreCode: this.diagnostic.code });
sendTelemetryEvent(EventName.DIAGNOSTICS_ACTION, undefined, { ignoreCode: this.diagnostic.code });
const filter = this.serviceContainer.get<IDiagnosticFilterService>(IDiagnosticFilterService);
return filter.ignoreDiagnostic(this.diagnostic.code, this.scope);
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/application/diagnostics/commands/launchBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { IBrowserService } from '../../../common/types';
import { IServiceContainer } from '../../../ioc/types';
import { sendTelemetryEvent } from '../../../telemetry';
import { DIAGNOSTICS_ACTION } from '../../../telemetry/constants';
import { EventName } from '../../../telemetry/constants';
import { IDiagnostic } from '../types';
import { BaseDiagnosticCommand } from './base';

Expand All @@ -15,7 +15,7 @@ export class LaunchBrowserCommand extends BaseDiagnosticCommand {
super(diagnostic);
}
public async invoke(): Promise<void> {
sendTelemetryEvent(DIAGNOSTICS_ACTION, undefined, { url: this.url });
sendTelemetryEvent(EventName.DIAGNOSTICS_ACTION, undefined, { url: this.url });
const browser = this.serviceContainer.get<IBrowserService>(IBrowserService);
return browser.launch(this.url);
}
Expand Down
6 changes: 3 additions & 3 deletions src/client/common/configSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ConfigurationChangeEvent, ConfigurationTarget, DiagnosticSeverity, Disp
import '../common/extensions';
import { IInterpreterAutoSeletionProxyService } from '../interpreter/autoSelection/types';
import { sendTelemetryEvent } from '../telemetry';
import { COMPLETION_ADD_BRACKETS, FORMAT_ON_TYPE } from '../telemetry/constants';
import { EventName } from '../telemetry/constants';
import { IWorkspaceService } from './application/types';
import { WorkspaceService } from './application/workspace';
import { isTestExecution } from './constants';
Expand Down Expand Up @@ -82,8 +82,8 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
// tslint:disable-next-line:no-any
const config = workspace.getConfiguration('editor', resource ? resource : null as any);
const formatOnType = config ? config.get('formatOnType', false) : false;
sendTelemetryEvent(COMPLETION_ADD_BRACKETS, undefined, { enabled: settings.autoComplete ? settings.autoComplete.addBrackets : false });
sendTelemetryEvent(FORMAT_ON_TYPE, undefined, { enabled: formatOnType });
sendTelemetryEvent(EventName.COMPLETION_ADD_BRACKETS, undefined, { enabled: settings.autoComplete ? settings.autoComplete.addBrackets : false });
sendTelemetryEvent(EventName.FORMAT_ON_TYPE, undefined, { enabled: formatOnType });
}
// tslint:disable-next-line:no-non-null-assertion
return PythonSettings.pythonSettings.get(workspaceFolderKey)!;
Expand Down
8 changes: 4 additions & 4 deletions src/client/common/installer/productInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '../../common/extensions';
import { IServiceContainer } from '../../ioc/types';
import { LinterId } from '../../linters/types';
import { sendTelemetryEvent } from '../../telemetry';
import { LINTER_NOT_INSTALLED_PROMPT } from '../../telemetry/constants';
import { EventName } from '../../telemetry/constants';
import { IApplicationShell, ICommandManager, IWorkspaceService } from '../application/types';
import { Commands, STANDARD_OUTPUT_CHANNEL } from '../constants';
import { IPlatformService } from '../platform/types';
Expand Down Expand Up @@ -197,16 +197,16 @@ export class LinterInstaller extends BaseInstaller {
}
const response = await this.appShell.showErrorMessage(message, ...options);
if (response === install) {
sendTelemetryEvent(LINTER_NOT_INSTALLED_PROMPT, undefined, { tool: productName as LinterId, action: 'install' });
sendTelemetryEvent(EventName.LINTER_NOT_INSTALLED_PROMPT, undefined, { tool: productName as LinterId, action: 'install' });
return this.install(product, resource);
} else if (response === disableInstallPrompt) {
await this.setStoredResponse(disableLinterInstallPromptKey, true);
sendTelemetryEvent(LINTER_NOT_INSTALLED_PROMPT, undefined, { tool: productName as LinterId, action: 'disablePrompt' });
sendTelemetryEvent(EventName.LINTER_NOT_INSTALLED_PROMPT, undefined, { tool: productName as LinterId, action: 'disablePrompt' });
return InstallerResponse.Ignore;
}

if (response === selectLinter) {
sendTelemetryEvent(LINTER_NOT_INSTALLED_PROMPT, undefined, { action: 'select' });
sendTelemetryEvent(EventName.LINTER_NOT_INSTALLED_PROMPT, undefined, { action: 'select' });
const commandManager = this.serviceContainer.get<ICommandManager>(ICommandManager);
await commandManager.executeCommand(Commands.Set_Linter);
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/common/nuget/azureBlobStoreNugetRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { inject, injectable, unmanaged } from 'inversify';
import { IServiceContainer } from '../../ioc/types';
import { captureTelemetry } from '../../telemetry';
import { PYTHON_LANGUAGE_SERVER_LIST_BLOB_STORE_PACKAGES } from '../../telemetry/constants';
import { EventName } from '../../telemetry/constants';
import { traceDecorators } from '../logger';
import { INugetRepository, INugetService, NugetPackage } from './types';

Expand All @@ -20,7 +20,7 @@ export class AzureBlobStoreNugetRepository implements INugetRepository {
return this.listPackages(this.azureBlobStorageAccount, this.azureBlobStorageContainer, packageName, this.azureCDNBlobStorageAccount);
}

@captureTelemetry(PYTHON_LANGUAGE_SERVER_LIST_BLOB_STORE_PACKAGES)
@captureTelemetry(EventName.PYTHON_LANGUAGE_SERVER_LIST_BLOB_STORE_PACKAGES)
@traceDecorators.verbose('Listing Nuget Packages')
protected async listPackages(azureBlobStorageAccount: string, azureBlobStorageContainer: string, packageName: string, azureCDNBlobStorageAccount: string) {
// tslint:disable-next-line:no-require-imports
Expand Down
Loading