Skip to content

Commit 472ae49

Browse files
author
Mikhail Arkhipov
authored
Add telemetry reporting on VS analysis engine usage (#1382)
* Undo changes * Test fixes * Increase timeout * Remove double event listening * Remove test * Revert "Remove test" This reverts commit e240c3f. * Revert "Remove double event listening" This reverts commit af573be. * #1096 The if statement is automatically formatted incorrectly * Merge fix * Add more tests * More tests * Typo * Test * Also better handle multiline arguments * Add a couple missing periods [skip ci] * Undo changes * Test fixes * Increase timeout * Remove double event listening * Remove test * Revert "Remove test" This reverts commit e240c3f. * Revert "Remove double event listening" This reverts commit af573be. * Merge fix * #1257 On type formatting errors for args and kwargs * Handle f-strings * Stop importing from test code * #1308 Single line statements leading to an indentation on the next line * #726 editing python after inline if statement invalid indent * Undo change * Move constant * Harden LS startup error checks * #1364 Intellisense doesn't work after specific const string * Telemetry for the analysis enging * PR feedback
1 parent 7cd5095 commit 472ae49

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/client/activation/analysis.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import { IProcessService } from '../common/process/types';
1313
import { StopWatch } from '../common/stopWatch';
1414
import { IConfigurationService, IOutputChannel, IPythonSettings } from '../common/types';
1515
import { IServiceContainer } from '../ioc/types';
16+
import {
17+
PYTHON_ANALYSIS_ENGINE_DOWNLOADED,
18+
PYTHON_ANALYSIS_ENGINE_ENABLED,
19+
PYTHON_ANALYSIS_ENGINE_ERROR,
20+
PYTHON_ANALYSIS_ENGINE_STARTUP
21+
} from '../telemetry/constants';
22+
import { getTelemetryReporter } from '../telemetry/telemetry';
1623
import { AnalysisEngineDownloader } from './downloader';
1724
import { InterpreterDataService } from './interpreterDataService';
1825
import { PlatformData } from './platformData';
@@ -26,7 +33,7 @@ const analysisEngineFolder = 'analysis';
2633
class LanguageServerStartupErrorHandler implements ErrorHandler {
2734
constructor(private readonly deferred: Deferred<void>) { }
2835
public error(error: Error, message: Message, count: number): ErrorAction {
29-
this.deferred.reject();
36+
this.deferred.reject(error);
3037
return ErrorAction.Shutdown;
3138
}
3239
public closed(): CloseAction {
@@ -71,6 +78,9 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
7178
const mscorlib = path.join(context.extensionPath, analysisEngineFolder, 'mscorlib.dll');
7279
let downloadPackage = false;
7380

81+
const reporter = getTelemetryReporter();
82+
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_ENABLED);
83+
7484
if (!await this.fs.fileExistsAsync(mscorlib)) {
7585
// Depends on .NET Runtime or SDK
7686
this.languageClient = this.createSimpleLanguageClient(context, clientOptions);
@@ -80,6 +90,7 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
8090
} catch (ex) {
8191
if (await this.isDotNetInstalled()) {
8292
this.appShell.showErrorMessage(`.NET Runtime appears to be installed but the language server did not start. Error ${ex}`);
93+
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_ERROR, { error: 'Failed to start (MSIL)' });
8394
return false;
8495
}
8596
// No .NET Runtime, no mscorlib - need to download self-contained package.
@@ -90,6 +101,7 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
90101
if (downloadPackage) {
91102
const downloader = new AnalysisEngineDownloader(this.services, analysisEngineFolder);
92103
await downloader.downloadAnalysisEngine(context);
104+
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_DOWNLOADED);
93105
}
94106

95107
const serverModule = path.join(context.extensionPath, analysisEngineFolder, this.platformData.getEngineExecutableName());
@@ -100,6 +112,7 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
100112
return true;
101113
} catch (ex) {
102114
this.appShell.showErrorMessage(`Language server failed to start. Error ${ex}`);
115+
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_ERROR, { error: 'Failed to start (platform)' });
103116
return false;
104117
}
105118
}
@@ -108,16 +121,20 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
108121
let disposable: Disposable | undefined;
109122
const deferred = createDeferred<void>();
110123
try {
124+
const sw = new StopWatch();
111125
lc.clientOptions.errorHandler = new LanguageServerStartupErrorHandler(deferred);
112126

113127
disposable = lc.start();
114128
lc.onReady()
115129
.then(() => deferred.resolve())
116-
.catch(ex => deferred.reject());
130+
.catch(deferred.reject);
117131
await deferred.promise;
118132

119133
this.output.appendLine(`Language server ready: ${this.sw.elapsedTime} ms`);
120134
context.subscriptions.push(disposable);
135+
136+
const reporter = getTelemetryReporter();
137+
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_STARTUP, {}, { startup_time: sw.elapsedTime });
121138
} catch (ex) {
122139
if (disposable) {
123140
disposable.dispose();

src/client/telemetry/constants.ts

+4
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ export const UNITTEST_STOP = 'UNITTEST.STOP';
3030
export const UNITTEST_RUN = 'UNITTEST.RUN';
3131
export const UNITTEST_DISCOVER = 'UNITTEST.DISCOVER';
3232
export const UNITTEST_VIEW_OUTPUT = 'UNITTEST.VIEW_OUTPUT';
33+
export const PYTHON_ANALYSIS_ENGINE_ENABLED = 'PYTHON_ANALYSIS_ENGINE.ENABLED';
34+
export const PYTHON_ANALYSIS_ENGINE_DOWNLOADED = 'PYTHON_ANALYSIS_ENGINE.DOWNLOADED';
35+
export const PYTHON_ANALYSIS_ENGINE_ERROR = 'PYTHON_ANALYSIS_ENGINE.ERROR';
36+
export const PYTHON_ANALYSIS_ENGINE_STARTUP = 'PYTHON_ANALYSIS_ENGINE.STARTUP';

0 commit comments

Comments
 (0)