Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #276 from prabushi/autoclose
Browse files Browse the repository at this point in the history
Update telemetry to honor the setting
  • Loading branch information
prabushi authored Mar 11, 2021
2 parents 0d088d3 + 23ea2ac commit 451d018
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 100 deletions.
7 changes: 3 additions & 4 deletions src/api-editor/activator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { API_DESIGNER_NO_SERVICE } from '../core/messages';
import { WebViewRPCHandler, WebViewMethod, getCommonWebViewOptions } from '../utils';
import { join } from "path";
import { readFileSync } from "fs";
import { getTelemetryProperties, TM_EVENT_OPEN_API_DESIGNER, CMP_API_DESIGNER } from '../telemetry';
import { TM_EVENT_OPEN_API_DESIGNER, CMP_API_DESIGNER, sendTelemetryEvent, sendTelemetryException } from '../telemetry';

const DEBOUNCE_WAIT = 500;
const CMD_SHOW_API_EDITOR = "ballerina.showAPIEditor";
Expand Down Expand Up @@ -207,11 +207,10 @@ function createAPIEditorPanel(selectedService: string, renderHtml: string,
}

export function activate(ballerinaExtInstance: BallerinaExtension) {
const reporter = ballerinaExtInstance.telemetryReporter;
const context = <ExtensionContext>ballerinaExtInstance.context;
const langClient = <ExtendedLangClient>ballerinaExtInstance.langClient;
const showAPIRenderer = commands.registerCommand(CMD_SHOW_API_EDITOR, serviceNameArg => {
reporter.sendTelemetryEvent(TM_EVENT_OPEN_API_DESIGNER, getTelemetryProperties(ballerinaExtInstance, CMP_API_DESIGNER));
sendTelemetryEvent(ballerinaExtInstance, TM_EVENT_OPEN_API_DESIGNER, CMP_API_DESIGNER);
ballerinaExtInstance.onReady()
.then(() => {
const { experimental } = langClient.initializeResult!.capabilities;
Expand All @@ -225,7 +224,7 @@ export function activate(ballerinaExtInstance: BallerinaExtension) {
})
.catch((e) => {
ballerinaExtInstance.showPluginActivationError();
reporter.sendTelemetryException(e, getTelemetryProperties(ballerinaExtInstance, CMP_API_DESIGNER));
sendTelemetryException(ballerinaExtInstance, e, CMP_API_DESIGNER);
});
});

Expand Down
10 changes: 4 additions & 6 deletions src/bbe/activator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { render } from './renderer';
import { ExtendedLangClient } from '../core/extended-language-client';
import { ballerinaExtInstance, BallerinaExtension } from '../core';
import { WebViewRPCHandler, WebViewMethod, getCommonWebViewOptions } from '../utils';
import { getTelemetryProperties, TM_EVENT_OPEN_EXAMPLES, CMP_EXAMPLES_VIEW } from '../telemetry';
import { TM_EVENT_OPEN_EXAMPLES, CMP_EXAMPLES_VIEW, sendTelemetryEvent, sendTelemetryException } from '../telemetry';

let examplesPanel: WebviewPanel | undefined;

Expand Down Expand Up @@ -51,8 +51,7 @@ function showExamples(context: ExtensionContext, langClient: ExtendedLangClient)
window.showTextDocument(doc);
}, (err: Error) => {
window.showErrorMessage(err.message);
ballerinaExtInstance.telemetryReporter.sendTelemetryException(err,
getTelemetryProperties(ballerinaExtInstance, CMP_EXAMPLES_VIEW));
sendTelemetryException(ballerinaExtInstance, err, CMP_EXAMPLES_VIEW);
});
}
return Promise.resolve();
Expand All @@ -70,11 +69,10 @@ function showExamples(context: ExtensionContext, langClient: ExtendedLangClient)
}

export function activate(ballerinaExtInstance: BallerinaExtension) {
const reporter = ballerinaExtInstance.telemetryReporter;
const context = <ExtensionContext>ballerinaExtInstance.context;
const langClient = <ExtendedLangClient>ballerinaExtInstance.langClient;
const examplesListRenderer = commands.registerCommand('ballerina.showExamples', () => {
reporter.sendTelemetryEvent(TM_EVENT_OPEN_EXAMPLES, getTelemetryProperties(ballerinaExtInstance, CMP_EXAMPLES_VIEW));
sendTelemetryEvent(ballerinaExtInstance, TM_EVENT_OPEN_EXAMPLES, CMP_EXAMPLES_VIEW);
ballerinaExtInstance.onReady()
.then(() => {
const { experimental } = langClient.initializeResult!.capabilities;
Expand All @@ -89,7 +87,7 @@ export function activate(ballerinaExtInstance: BallerinaExtension) {
})
.catch((e) => {
ballerinaExtInstance.showPluginActivationError();
reporter.sendTelemetryException(e, getTelemetryProperties(ballerinaExtInstance, CMP_EXAMPLES_VIEW));
sendTelemetryException(ballerinaExtInstance, e, CMP_EXAMPLES_VIEW);
});
});

Expand Down
36 changes: 19 additions & 17 deletions src/core/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ import { getServerOptions } from '../server/server';
import { ExtendedLangClient } from './extended-language-client';
import { log, getOutputChannel, outputChannel } from '../utils/index';
import { AssertionError } from "assert";
import { OVERRIDE_BALLERINA_HOME, BALLERINA_HOME } from "./preferences";
import { BALLERINA_HOME, ENABLE_TELEMETRY, OVERRIDE_BALLERINA_HOME } from "./preferences";
import TelemetryReporter from "vscode-extension-telemetry";
import {
createTelemetryReporter, getTelemetryProperties, CMP_EXTENSION_CORE, TM_EVENT_ERROR_INVALID_BAL_HOME_CONFIGURED,
TM_EVENT_EXTENSION_INIT, TM_EVENT_EXTENSION_INI_FAILED, TM_EVENT_ERROR_OLD_BAL_HOME_DETECTED
createTelemetryReporter, CMP_EXTENSION_CORE, sendTelemetryEvent, sendTelemetryException,
TM_EVENT_ERROR_INVALID_BAL_HOME_CONFIGURED, TM_EVENT_EXTENSION_INIT, TM_EVENT_EXTENSION_INI_FAILED,
TM_EVENT_ERROR_OLD_BAL_HOME_DETECTED
} from "../telemetry";
const any = require('promise.any');

Expand Down Expand Up @@ -115,8 +116,7 @@ export class BallerinaExtension {
if (this.overrideBallerinaHome()) {
if (!this.overrideBallerinaHome()) {
const message = "Trying to get ballerina version without setting ballerina home.";
this.telemetryReporter.sendTelemetryEvent(TM_EVENT_ERROR_INVALID_BAL_HOME_CONFIGURED,
getTelemetryProperties(this, CMP_EXTENSION_CORE, message));
sendTelemetryEvent(this, TM_EVENT_ERROR_INVALID_BAL_HOME_CONFIGURED, CMP_EXTENSION_CORE, message);
throw new AssertionError({
message: message
});
Expand Down Expand Up @@ -147,8 +147,7 @@ export class BallerinaExtension {
this.showMessageOldBallerina();
const message = `Ballerina version ${this.ballerinaVersion} is not supported.
Please use a compatible VSCode extension version.`;
this.telemetryReporter.sendTelemetryEvent(TM_EVENT_ERROR_OLD_BAL_HOME_DETECTED, getTelemetryProperties(this,
CMP_EXTENSION_CORE, message));
sendTelemetryEvent(this, TM_EVENT_ERROR_OLD_BAL_HOME_DETECTED, CMP_EXTENSION_CORE, message);
throw new AssertionError({
message: message
});
Expand All @@ -164,8 +163,7 @@ export class BallerinaExtension {
const disposeDidChange = this.langClient.onDidChangeState(stateChangeEvent => {
if (stateChangeEvent.newState === LS_STATE.Stopped) {
const message = "Couldn't establish language server connection.";
this.telemetryReporter.sendTelemetryEvent(TM_EVENT_EXTENSION_INI_FAILED, getTelemetryProperties(this,
CMP_EXTENSION_CORE, message));
sendTelemetryEvent(this, TM_EVENT_EXTENSION_INI_FAILED, CMP_EXTENSION_CORE, message);
log(message);
this.showPluginActivationError();
}
Expand All @@ -177,34 +175,34 @@ export class BallerinaExtension {
this.context!.subscriptions.push(disposable);
});
}, (reason) => {
this.telemetryReporter.sendTelemetryException(reason, getTelemetryProperties(this, CMP_EXTENSION_CORE));
sendTelemetryException(this, reason, CMP_EXTENSION_CORE);
throw new Error(reason);
}).catch(e => {
const msg = `Error when checking ballerina version. ${e.message}`;
this.telemetryReporter.sendTelemetryException(e, getTelemetryProperties(this, CMP_EXTENSION_CORE, msg));
sendTelemetryException(this, e, CMP_EXTENSION_CORE, msg);
this.telemetryReporter.dispose();
throw new Error(msg);
});
} catch (ex) {
const msg = "Error while activating plugin. " + (ex.message ? ex.message : ex);
// If any failure occurs while initializing show an error message
this.showPluginActivationError();
this.telemetryReporter.sendTelemetryException(ex, getTelemetryProperties(this, CMP_EXTENSION_CORE, msg));
sendTelemetryException(this, ex, CMP_EXTENSION_CORE, msg);
this.telemetryReporter.dispose();
return Promise.reject(msg);
}
}

onReady(): Promise<void> {
if (!this.langClient) {
this.sdkVersion.text = `Ballerina SDK: Error`;
this.telemetryReporter.sendTelemetryEvent(TM_EVENT_EXTENSION_INI_FAILED, getTelemetryProperties(this,
CMP_EXTENSION_CORE));
const message = `Ballerina SDK: Error`;
this.sdkVersion.text = message;
sendTelemetryEvent(this, TM_EVENT_EXTENSION_INI_FAILED, CMP_EXTENSION_CORE, message);
this.telemetryReporter.dispose();
return Promise.reject('BallerinaExtension is not initialized');
}

this.telemetryReporter.sendTelemetryEvent(TM_EVENT_EXTENSION_INIT, getTelemetryProperties(this, CMP_EXTENSION_CORE));
sendTelemetryEvent(this, TM_EVENT_EXTENSION_INIT, CMP_EXTENSION_CORE);
return this.langClient.onReady();
}

Expand Down Expand Up @@ -304,7 +302,7 @@ export class BallerinaExtension {
const parsedVersion = implVersionLine.replace(replacePrefix, '').replace(/[\n\t\r]/g, '');
return Promise.resolve(parsedVersion);
} catch (error) {
this.telemetryReporter.sendTelemetryException(error, getTelemetryProperties(this, CMP_EXTENSION_CORE));
sendTelemetryException(this, error, CMP_EXTENSION_CORE);
return Promise.reject(error);
}
}
Expand Down Expand Up @@ -476,6 +474,10 @@ export class BallerinaExtension {
public getOutPutChannel(): OutputChannel | undefined {
return getOutputChannel();
}

isTelemetryEnabled(): boolean {
return <boolean>workspace.getConfiguration().get(ENABLE_TELEMETRY);
}
}

export const ballerinaExtInstance = new BallerinaExtension();
4 changes: 1 addition & 3 deletions src/core/preferences.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const BALLERINA_HOME = "ballerina.home";
export const OVERRIDE_BALLERINA_HOME = "ballerina.plugin.dev.mod";
export const ALLOW_EXPERIMENTAL = "ballerina.allowExperimental";
export const ENABLE_DEBUG_LOG = "ballerina.debugLog";
export const ENABLE_TRACE_LOG = "ballerina.traceLog";
export const ENABLE_TELEMETRY = "ballerina.enableTelemetry";
8 changes: 3 additions & 5 deletions src/debugger/config-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as path from "path";
import { ballerinaExtInstance, BallerinaExtension } from '../core/index';
import { ExtendedLangClient } from '../core/extended-language-client';
import { BALLERINA_HOME } from '../core/preferences';
import { getTelemetryProperties, TM_EVENT_START_DEBUG_SESSION, CMP_DEBUGGER } from '../telemetry';
import { TM_EVENT_START_DEBUG_SESSION, CMP_DEBUGGER, sendTelemetryEvent, sendTelemetryException } from '../telemetry';
import { log, debug as debugLog } from "../utils";
import { ExecutableOptions } from 'vscode-languageclient';

Expand Down Expand Up @@ -132,12 +132,10 @@ class BallerinaDebugAdapterDescriptorFactory implements DebugAdapterDescriptorFa
debugLog(`${data}`);
});
}).then(() => {
ballerinaExtInstance.telemetryReporter.sendTelemetryEvent(TM_EVENT_START_DEBUG_SESSION,
getTelemetryProperties(ballerinaExtInstance, CMP_DEBUGGER));
sendTelemetryEvent(ballerinaExtInstance, TM_EVENT_START_DEBUG_SESSION, CMP_DEBUGGER);
return new DebugAdapterServer(port);
}).catch((error) => {
ballerinaExtInstance.telemetryReporter.sendTelemetryException(error,
getTelemetryProperties(ballerinaExtInstance, CMP_DEBUGGER));
sendTelemetryException(ballerinaExtInstance, error, CMP_DEBUGGER);
return Promise.reject(error);
});
}
Expand Down
7 changes: 3 additions & 4 deletions src/diagram/activator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ExtendedLangClient } from '../core/extended-language-client';
import { BallerinaExtension } from '../core';
import { WebViewRPCHandler, getCommonWebViewOptions } from '../utils';
import { join } from "path";
import { getTelemetryProperties, TM_EVENT_OPEN_DIAGRAM, CMP_DIAGRAM_VIEW } from '../telemetry';
import { TM_EVENT_OPEN_DIAGRAM, CMP_DIAGRAM_VIEW, sendTelemetryEvent, sendTelemetryException } from '../telemetry';

const DEBOUNCE_WAIT = 500;

Expand Down Expand Up @@ -96,12 +96,11 @@ function showDiagramEditor(context: ExtensionContext, langClient: ExtendedLangCl
}

export function activate(ballerinaExtInstance: BallerinaExtension) {
const reporter = ballerinaExtInstance.telemetryReporter;
const context = <ExtensionContext>ballerinaExtInstance.context;
const langClient = <ExtendedLangClient>ballerinaExtInstance.langClient;

const diagramRenderDisposable = commands.registerCommand('ballerina.showDiagram', () => {
reporter.sendTelemetryEvent(TM_EVENT_OPEN_DIAGRAM, getTelemetryProperties(ballerinaExtInstance, CMP_DIAGRAM_VIEW));
sendTelemetryEvent(ballerinaExtInstance, TM_EVENT_OPEN_DIAGRAM, CMP_DIAGRAM_VIEW);
return ballerinaExtInstance.onReady()
.then(() => {
const { experimental } = langClient.initializeResult!.capabilities;
Expand All @@ -115,7 +114,7 @@ export function activate(ballerinaExtInstance: BallerinaExtension) {
})
.catch((e) => {
ballerinaExtInstance.showPluginActivationError();
reporter.sendTelemetryException(e, getTelemetryProperties(ballerinaExtInstance, CMP_DIAGRAM_VIEW));
sendTelemetryException(ballerinaExtInstance, e, CMP_DIAGRAM_VIEW);
});
});
context.subscriptions.push(diagramRenderDisposable);
Expand Down
16 changes: 6 additions & 10 deletions src/project/cli-cmds/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,22 @@
import { ballerinaExtInstance } from "../../core";
import { commands, window } from "vscode";
import {
getTelemetryProperties, TM_EVENT_PROJECT_ADD, TM_EVENT_ERROR_EXECUTE_PROJECT_ADD, CMP_PROJECT_ADD
TM_EVENT_PROJECT_ADD, TM_EVENT_ERROR_EXECUTE_PROJECT_ADD, CMP_PROJECT_ADD, sendTelemetryEvent, sendTelemetryException
} from "../../telemetry";
import { runCommand, BALLERINA_COMMANDS, MESSAGES, PROJECT_TYPE } from "./cmd-runner";
import { getCurrentBallerinaProject } from "../../utils/project-utils";

function activateAddCommand() {
const reporter = ballerinaExtInstance.telemetryReporter;

// register ballerina add handler
commands.registerCommand('ballerina.project.add', async () => {
try {
reporter.sendTelemetryEvent(TM_EVENT_PROJECT_ADD, getTelemetryProperties(ballerinaExtInstance,
CMP_PROJECT_ADD));
sendTelemetryEvent(ballerinaExtInstance, TM_EVENT_PROJECT_ADD, CMP_PROJECT_ADD);

const currentProject = await getCurrentBallerinaProject();
if (ballerinaExtInstance.isSwanLake && currentProject.kind === PROJECT_TYPE.SINGLE_FILE ||
ballerinaExtInstance.is12x && !currentProject.path) {
reporter.sendTelemetryEvent(TM_EVENT_ERROR_EXECUTE_PROJECT_ADD,
getTelemetryProperties(ballerinaExtInstance, CMP_PROJECT_ADD, MESSAGES.NOT_IN_PROJECT));
sendTelemetryEvent(ballerinaExtInstance, TM_EVENT_ERROR_EXECUTE_PROJECT_ADD, CMP_PROJECT_ADD,
MESSAGES.NOT_IN_PROJECT);
window.showErrorMessage(MESSAGES.NOT_IN_PROJECT);
return;
}
Expand All @@ -50,14 +47,13 @@ function activateAddCommand() {
} while (!moduleName || moduleName && moduleName.trim().length === 0);
runCommand(currentProject, ballerinaExtInstance.ballerinaCmd, BALLERINA_COMMANDS.ADD, moduleName);
} else {
reporter.sendTelemetryEvent(TM_EVENT_ERROR_EXECUTE_PROJECT_ADD,
getTelemetryProperties(ballerinaExtInstance, CMP_PROJECT_ADD, MESSAGES.NOT_SUPPORT));
sendTelemetryEvent(ballerinaExtInstance, TM_EVENT_ERROR_EXECUTE_PROJECT_ADD, CMP_PROJECT_ADD, MESSAGES.NOT_SUPPORT);
window.showErrorMessage(MESSAGES.NOT_SUPPORT);
return;
}

} catch (error) {
reporter.sendTelemetryException(error, getTelemetryProperties(ballerinaExtInstance, CMP_PROJECT_ADD));
sendTelemetryException(ballerinaExtInstance, error, CMP_PROJECT_ADD);
window.showErrorMessage(error);
}
});
Expand Down
14 changes: 6 additions & 8 deletions src/project/cli-cmds/build.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ballerinaExtInstance } from "../../core";
import { commands, window } from "vscode";
import {
getTelemetryProperties, TM_EVENT_PROJECT_BUILD, TM_EVENT_ERROR_EXECUTE_PROJECT_BUILD, CMP_PROJECT_BUILD
TM_EVENT_PROJECT_BUILD, TM_EVENT_ERROR_EXECUTE_PROJECT_BUILD, CMP_PROJECT_BUILD, sendTelemetryEvent,
sendTelemetryException
} from "../../telemetry";
import { runCommand, BALLERINA_COMMANDS, COMMAND_OPTIONS, MESSAGES, PROJECT_TYPE } from "./cmd-runner";
import { getCurrentBallerinaProject, getCurrenDirectoryPath, getCurrentBallerinaFile }
Expand All @@ -10,13 +11,10 @@ import { getCurrentBallerinaProject, getCurrenDirectoryPath, getCurrentBallerina
export enum BUILD_OPTIONS { BUILD_ALL = "build-all", BUILD_MODULE = "build-module" }

export function activateBuildCommand() {
const reporter = ballerinaExtInstance.telemetryReporter;

// register run project build handler
commands.registerCommand('ballerina.project.build', async () => {
try {
reporter.sendTelemetryEvent(TM_EVENT_PROJECT_BUILD, getTelemetryProperties(ballerinaExtInstance,
CMP_PROJECT_BUILD));
sendTelemetryEvent(ballerinaExtInstance, TM_EVENT_PROJECT_BUILD, CMP_PROJECT_BUILD);

const currentProject = await getCurrentBallerinaProject();
if (ballerinaExtInstance.isSwanLake) {
Expand Down Expand Up @@ -65,13 +63,13 @@ export function activateBuildCommand() {
}

} else {
reporter.sendTelemetryEvent(TM_EVENT_ERROR_EXECUTE_PROJECT_BUILD, getTelemetryProperties(ballerinaExtInstance,
CMP_PROJECT_BUILD, MESSAGES.NOT_SUPPORT));
sendTelemetryEvent(ballerinaExtInstance, TM_EVENT_ERROR_EXECUTE_PROJECT_BUILD, CMP_PROJECT_BUILD,
MESSAGES.NOT_SUPPORT);
window.showErrorMessage(MESSAGES.NOT_SUPPORT);
}

} catch (error) {
reporter.sendTelemetryException(error, getTelemetryProperties(ballerinaExtInstance, CMP_PROJECT_BUILD));
sendTelemetryException(ballerinaExtInstance, error, CMP_PROJECT_BUILD);
window.showErrorMessage(error);
}
});
Expand Down
Loading

0 comments on commit 451d018

Please sign in to comment.