Skip to content

Commit

Permalink
Add telemetry reporting on VS analysis engine usage (#1382)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Mikhail Arkhipov authored Apr 13, 2018
1 parent 7cd5095 commit 472ae49
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/client/activation/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import { IProcessService } from '../common/process/types';
import { StopWatch } from '../common/stopWatch';
import { IConfigurationService, IOutputChannel, IPythonSettings } from '../common/types';
import { IServiceContainer } from '../ioc/types';
import {
PYTHON_ANALYSIS_ENGINE_DOWNLOADED,
PYTHON_ANALYSIS_ENGINE_ENABLED,
PYTHON_ANALYSIS_ENGINE_ERROR,
PYTHON_ANALYSIS_ENGINE_STARTUP
} from '../telemetry/constants';
import { getTelemetryReporter } from '../telemetry/telemetry';
import { AnalysisEngineDownloader } from './downloader';
import { InterpreterDataService } from './interpreterDataService';
import { PlatformData } from './platformData';
Expand All @@ -26,7 +33,7 @@ const analysisEngineFolder = 'analysis';
class LanguageServerStartupErrorHandler implements ErrorHandler {
constructor(private readonly deferred: Deferred<void>) { }
public error(error: Error, message: Message, count: number): ErrorAction {
this.deferred.reject();
this.deferred.reject(error);
return ErrorAction.Shutdown;
}
public closed(): CloseAction {
Expand Down Expand Up @@ -71,6 +78,9 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
const mscorlib = path.join(context.extensionPath, analysisEngineFolder, 'mscorlib.dll');
let downloadPackage = false;

const reporter = getTelemetryReporter();
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_ENABLED);

if (!await this.fs.fileExistsAsync(mscorlib)) {
// Depends on .NET Runtime or SDK
this.languageClient = this.createSimpleLanguageClient(context, clientOptions);
Expand All @@ -80,6 +90,7 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
} catch (ex) {
if (await this.isDotNetInstalled()) {
this.appShell.showErrorMessage(`.NET Runtime appears to be installed but the language server did not start. Error ${ex}`);
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_ERROR, { error: 'Failed to start (MSIL)' });
return false;
}
// No .NET Runtime, no mscorlib - need to download self-contained package.
Expand All @@ -90,6 +101,7 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
if (downloadPackage) {
const downloader = new AnalysisEngineDownloader(this.services, analysisEngineFolder);
await downloader.downloadAnalysisEngine(context);
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_DOWNLOADED);
}

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

disposable = lc.start();
lc.onReady()
.then(() => deferred.resolve())
.catch(ex => deferred.reject());
.catch(deferred.reject);
await deferred.promise;

this.output.appendLine(`Language server ready: ${this.sw.elapsedTime} ms`);
context.subscriptions.push(disposable);

const reporter = getTelemetryReporter();
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_STARTUP, {}, { startup_time: sw.elapsedTime });
} catch (ex) {
if (disposable) {
disposable.dispose();
Expand Down
4 changes: 4 additions & 0 deletions src/client/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ export const UNITTEST_STOP = 'UNITTEST.STOP';
export const UNITTEST_RUN = 'UNITTEST.RUN';
export const UNITTEST_DISCOVER = 'UNITTEST.DISCOVER';
export const UNITTEST_VIEW_OUTPUT = 'UNITTEST.VIEW_OUTPUT';
export const PYTHON_ANALYSIS_ENGINE_ENABLED = 'PYTHON_ANALYSIS_ENGINE.ENABLED';
export const PYTHON_ANALYSIS_ENGINE_DOWNLOADED = 'PYTHON_ANALYSIS_ENGINE.DOWNLOADED';
export const PYTHON_ANALYSIS_ENGINE_ERROR = 'PYTHON_ANALYSIS_ENGINE.ERROR';
export const PYTHON_ANALYSIS_ENGINE_STARTUP = 'PYTHON_ANALYSIS_ENGINE.STARTUP';

0 comments on commit 472ae49

Please sign in to comment.