Skip to content

Commit 3eb481f

Browse files
authored
Use enums for telemetry event names (#3992)
For #2904 (part 1 for #2904)
1 parent f713ac6 commit 3eb481f

59 files changed

Lines changed: 227 additions & 234 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

news/3 Code Health/2904.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use enums for event names instead of constants.

src/client/activation/activationService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from '../common/types';
2323
import { IServiceContainer } from '../ioc/types';
2424
import { sendTelemetryEvent } from '../telemetry';
25-
import { PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED } from '../telemetry/constants';
25+
import { EventName } from '../telemetry/constants';
2626
import {
2727
ExtensionActivators, IExtensionActivationService,
2828
IExtensionActivator
@@ -58,8 +58,8 @@ export class ExtensionActivationService implements IExtensionActivationService,
5858
if (!jedi) {
5959
const diagnostic = await this.lsNotSupportedDiagnosticService.diagnose();
6060
this.lsNotSupportedDiagnosticService.handle(diagnostic).ignoreErrors();
61-
if (diagnostic.length) {
62-
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED);
61+
if (diagnostic.length){
62+
sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED);
6363
jedi = true;
6464
}
6565
}

src/client/activation/downloader.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ import { createDeferred } from '../common/utils/async';
1414
import { Common, LanguageService } from '../common/utils/localize';
1515
import { StopWatch } from '../common/utils/stopWatch';
1616
import { sendTelemetryEvent } from '../telemetry';
17+
import { EventName } from '../telemetry/constants';
1718
import {
18-
PYTHON_LANGUAGE_SERVER_DOWNLOADED,
19-
PYTHON_LANGUAGE_SERVER_ERROR,
20-
PYTHON_LANGUAGE_SERVER_EXTRACTED
21-
} from '../telemetry/constants';
22-
import { IHttpClient, ILanguageServerDownloader, ILanguageServerFolderService, IPlatformData } from './types';
19+
IHttpClient, ILanguageServerDownloader, ILanguageServerFolderService,
20+
IPlatformData
21+
} from './types';
2322

2423
const downloadFileExtension = '.nupkg';
2524

@@ -53,11 +52,11 @@ export class LanguageServerDownloader implements ILanguageServerDownloader {
5352
this.output.appendLine(err);
5453
success = false;
5554
this.showMessageAndOptionallyShowOutput(LanguageService.lsFailedToDownload()).ignoreErrors();
56-
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_ERROR, undefined, { error: 'Failed to download (platform)' }, err);
55+
sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_ERROR, undefined, { error: 'Failed to download (platform)' }, err);
5756
throw new Error(err);
5857
} finally {
5958
sendTelemetryEvent(
60-
PYTHON_LANGUAGE_SERVER_DOWNLOADED,
59+
EventName.PYTHON_LANGUAGE_SERVER_DOWNLOADED,
6160
timer.elapsedTime,
6261
{ success, lsVersion }
6362
);
@@ -71,11 +70,11 @@ export class LanguageServerDownloader implements ILanguageServerDownloader {
7170
this.output.appendLine(err);
7271
success = false;
7372
this.showMessageAndOptionallyShowOutput(LanguageService.lsFailedToExtract()).ignoreErrors();
74-
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_ERROR, undefined, { error: 'Failed to extract (platform)' }, err);
73+
sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_ERROR, undefined, { error: 'Failed to extract (platform)' }, err);
7574
throw new Error(err);
7675
} finally {
7776
sendTelemetryEvent(
78-
PYTHON_LANGUAGE_SERVER_EXTRACTED,
77+
EventName.PYTHON_LANGUAGE_SERVER_EXTRACTED,
7978
timer.elapsedTime,
8079
{ success, lsVersion }
8180
);

src/client/activation/languageServer/languageServer.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ import { Resource } from '../../common/types';
1111
import { createDeferred, Deferred, sleep } from '../../common/utils/async';
1212
import { noop } from '../../common/utils/misc';
1313
import { captureTelemetry, sendTelemetryEvent } from '../../telemetry';
14-
import {
15-
PYTHON_LANGUAGE_SERVER_ENABLED,
16-
PYTHON_LANGUAGE_SERVER_READY,
17-
PYTHON_LANGUAGE_SERVER_TELEMETRY
18-
} from '../../telemetry/constants';
14+
import { EventName } from '../../telemetry/constants';
1915
import { ProgressReporting } from '../progress';
2016
import { ILanaguageServer as ILanguageServer, ILanguageClientFactory, LanguageClientFactory } from '../types';
2117

@@ -51,15 +47,15 @@ export class LanguageServer implements ILanguageServer {
5147
}
5248

5349
@traceDecorators.error('Failed to start language server')
54-
@captureTelemetry(PYTHON_LANGUAGE_SERVER_ENABLED, undefined, true)
50+
@captureTelemetry(EventName.PYTHON_LANGUAGE_SERVER_ENABLED, undefined, true)
5551
public async start(resource: Resource, options: LanguageClientOptions): Promise<void> {
5652
this.languageClient = await this.factory.createLanguageClient(resource, options);
5753
this.disposables.push(this.languageClient!.start());
5854
await this.serverReady();
5955
const progressReporting = new ProgressReporting(this.languageClient!);
6056
this.disposables.push(progressReporting);
6157
this.languageClient.onTelemetry(telemetryEvent => {
62-
const eventName = telemetryEvent.EventName || PYTHON_LANGUAGE_SERVER_TELEMETRY;
58+
const eventName = telemetryEvent.EventName || EventName.PYTHON_LANGUAGE_SERVER_TELEMETRY;
6359
sendTelemetryEvent(eventName, telemetryEvent.Measurements, telemetryEvent.Properties);
6460
});
6561
}
@@ -77,7 +73,7 @@ export class LanguageServer implements ILanguageServer {
7773
)
7874
.ignoreErrors();
7975
}
80-
@captureTelemetry(PYTHON_LANGUAGE_SERVER_READY, undefined, true)
76+
@captureTelemetry(EventName.PYTHON_LANGUAGE_SERVER_READY, undefined, true)
8177
private async serverReady(): Promise<void> {
8278
while (this.languageClient && !this.languageClient!.initializeResult) {
8379
await sleep(100);

src/client/activation/languageServer/languageServerCompatibilityService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { inject, injectable } from 'inversify';
77
import { IDotNetCompatibilityService } from '../../common/dotnet/types';
88
import { traceError } from '../../common/logger';
99
import { sendTelemetryEvent } from '../../telemetry';
10-
import { PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED } from '../../telemetry/constants';
10+
import { EventName } from '../../telemetry/constants';
1111
import { ILanguageServerCompatibilityService } from '../types';
1212

1313
@injectable()
@@ -16,11 +16,11 @@ export class LanguageServerCompatibilityService implements ILanguageServerCompat
1616
public async isSupported(): Promise<boolean> {
1717
try {
1818
const supported = await this.dotnetCompatibility.isSupported();
19-
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported });
19+
sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported });
2020
return supported;
2121
} catch (ex) {
2222
traceError('Unable to determine whether LS is supported', ex);
23-
sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported: false, failureType: 'UnknownError' });
23+
sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported: false, failureType: 'UnknownError' });
2424
return false;
2525
}
2626
}

src/client/activation/languageServer/manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { IDisposable, Resource } from '../../common/types';
1010
import { debounce } from '../../common/utils/decorators';
1111
import { IServiceContainer } from '../../ioc/types';
1212
import { captureTelemetry } from '../../telemetry';
13-
import { PYTHON_LANGUAGE_SERVER_STARTUP } from '../../telemetry/constants';
13+
import { EventName } from '../../telemetry/constants';
1414
import { ILanaguageServer, ILanguageServerAnalysisOptions, ILanguageServerManager } from '../types';
1515

1616
const loadExtensionCommand = 'python._loadLanguageServerExtension';
@@ -64,7 +64,7 @@ export class LanguageServerManager implements ILanguageServerManager {
6464
}
6565
await this.startLanguageServer();
6666
}
67-
@captureTelemetry(PYTHON_LANGUAGE_SERVER_STARTUP, undefined, true)
67+
@captureTelemetry(EventName.PYTHON_LANGUAGE_SERVER_STARTUP, undefined, true)
6868
@traceDecorators.verbose('Starting Language Server')
6969
protected async startLanguageServer(): Promise<void> {
7070
this.languageServer = this.serviceContainer.get<ILanaguageServer>(ILanaguageServer);

src/client/activation/progress.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Disposable, LanguageClient } from 'vscode-languageclient';
66
import { createDeferred, Deferred } from '../common/utils/async';
77
import { StopWatch } from '../common/utils/stopWatch';
88
import { sendTelemetryEvent } from '../telemetry';
9-
import { PYTHON_LANGUAGE_SERVER_ANALYSISTIME } from '../telemetry/constants';
9+
import { EventName } from '../telemetry/constants';
1010

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

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

3634
this.progressDeferred = createDeferred<void>();
3735
this.progressTimer = new StopWatch();
38-
this.progressTimeout = setTimeout(
36+
setTimeout(
3937
this.handleTimeout.bind(this),
4038
ANALYSIS_TIMEOUT_MS
4139
);
@@ -73,13 +71,12 @@ export class ProgressReporting implements Disposable {
7371
private completeAnalysisTracking(success: boolean): void {
7472
if (this.progressTimer) {
7573
sendTelemetryEvent(
76-
PYTHON_LANGUAGE_SERVER_ANALYSISTIME,
74+
EventName.PYTHON_LANGUAGE_SERVER_ANALYSISTIME,
7775
this.progressTimer.elapsedTime,
7876
{ success }
7977
);
8078
}
8179
this.progressTimer = undefined;
82-
this.progressTimeout = undefined;
8380
}
8481

8582
// tslint:disable-next-line:no-any

src/client/application/diagnostics/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { injectable, unmanaged } from 'inversify';
77
import { DiagnosticSeverity } from 'vscode';
88
import { IServiceContainer } from '../../ioc/types';
99
import { sendTelemetryEvent } from '../../telemetry';
10-
import { DIAGNOSTICS_MESSAGE } from '../../telemetry/constants';
10+
import { EventName } from '../../telemetry/constants';
1111
import { DiagnosticScope, IDiagnostic, IDiagnosticFilterService, IDiagnosticsService } from './types';
1212

1313
@injectable()
@@ -26,7 +26,7 @@ export abstract class BaseDiagnosticsService implements IDiagnosticsService {
2626
public abstract diagnose(): Promise<IDiagnostic[]>;
2727
public abstract handle(diagnostics: IDiagnostic[]): Promise<void>;
2828
public async canHandle(diagnostic: IDiagnostic): Promise<boolean> {
29-
sendTelemetryEvent(DIAGNOSTICS_MESSAGE, undefined, { code: diagnostic.code });
29+
sendTelemetryEvent(EventName.DIAGNOSTICS_MESSAGE, undefined, { code: diagnostic.code });
3030
return this.supportedDiagnosticCodes.filter(item => item === diagnostic.code).length > 0;
3131
}
3232
}

src/client/application/diagnostics/checks/powerShellActivation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useCommandPromptAsDefaultShell } from '../../../common/terminal/command
1111
import { IConfigurationService, ICurrentProcess } from '../../../common/types';
1212
import { IServiceContainer } from '../../../ioc/types';
1313
import { sendTelemetryEvent } from '../../../telemetry';
14-
import { DIAGNOSTICS_ACTION } from '../../../telemetry/constants';
14+
import { EventName } from '../../../telemetry/constants';
1515
import { BaseDiagnostic, BaseDiagnosticsService } from '../base';
1616
import { IDiagnosticsCommandFactory } from '../commands/types';
1717
import { DiagnosticCodes } from '../constants';
@@ -58,7 +58,7 @@ export class PowerShellActivationHackDiagnosticsService extends BaseDiagnosticsS
5858
// tslint:disable-next-line:no-object-literal-type-assertion
5959
command: {
6060
diagnostic, invoke: async (): Promise<void> => {
61-
sendTelemetryEvent(DIAGNOSTICS_ACTION, undefined, { action: 'switchToCommandPrompt' });
61+
sendTelemetryEvent(EventName.DIAGNOSTICS_ACTION, undefined, { action: 'switchToCommandPrompt' });
6262
useCommandPromptAsDefaultShell(currentProcess, configurationService)
6363
.catch(ex => Logger.error('Use Command Prompt as default shell', ex));
6464
}

src/client/application/diagnostics/commands/execVSCCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { ICommandManager } from '../../../common/application/types';
77
import { IServiceContainer } from '../../../ioc/types';
88
import { sendTelemetryEvent } from '../../../telemetry';
9-
import { DIAGNOSTICS_ACTION } from '../../../telemetry/constants';
9+
import { EventName } from '../../../telemetry/constants';
1010
import { IDiagnostic } from '../types';
1111
import { BaseDiagnosticCommand } from './base';
1212

@@ -15,7 +15,7 @@ export class ExecuteVSCCommand extends BaseDiagnosticCommand {
1515
super(diagnostic);
1616
}
1717
public async invoke(): Promise<void> {
18-
sendTelemetryEvent(DIAGNOSTICS_ACTION, undefined, { commandName: this.commandName });
18+
sendTelemetryEvent(EventName.DIAGNOSTICS_ACTION, undefined, { commandName: this.commandName });
1919
const cmdManager = this.serviceContainer.get<ICommandManager>(ICommandManager);
2020
return cmdManager.executeCommand(this.commandName).then(() => undefined);
2121
}

0 commit comments

Comments
 (0)