Skip to content

Commit

Permalink
Update telemetry for dirType on command events (#1224)
Browse files Browse the repository at this point in the history
@W-6007844@
  • Loading branch information
lcampos authored Apr 3, 2019
1 parent 6801027 commit b8c0c1c
Show file tree
Hide file tree
Showing 22 changed files with 70 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,8 @@ export class TelemetryService {
}
}

public sendCommandEvent(commandName: string): void {
if (this.reporter !== undefined && this.isTelemetryEnabled) {
this.reporter.sendTelemetryEvent('commandExecution', {
extensionName: EXTENSION_NAME,
commandName
});
}
}

private getEndHRTime(hrstart: [number, number]): string {
const hrend = process.hrtime(hrstart);
return util.format('%ds %dms', hrend[0], hrend[1] / 1000000);
return util.format('%d%d', hrend[0], hrend[1] / 1000000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,10 @@ describe('Telemetry', () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, false);

telemetryService.sendCommandEvent('debugger_command');
telemetryService.sendExtensionActivationEvent([0, 400]);
assert.notCalled(sendEvent);
});

it('Should send correct data format on sendCommandEvent', async () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, true);

telemetryService.sendCommandEvent('debugger_command');
assert.calledOnce(sendEvent);

const expectedData = {
extensionName: 'salesforcedx-vscode-apex-debugger',
commandName: 'debugger_command'
};
assert.calledWith(sendEvent, 'commandExecution', expectedData);
});

it('Should send correct data format on sendExtensionActivationEvent', async () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ export class TelemetryService {
}
}

public sendCommandEvent(commandName: string): void {
if (this.reporter !== undefined && this.isTelemetryEnabled) {
this.reporter.sendTelemetryEvent('commandExecution', {
extensionName: EXTENSION_NAME,
commandName
});
}
}

public sendLaunchEvent(logSizeStr: string, errorMsg: string): void {
if (this.reporter !== undefined && this.isTelemetryEnabled) {
this.reporter.sendTelemetryEvent('launchDebuggerSession', {
Expand Down Expand Up @@ -92,6 +83,6 @@ export class TelemetryService {

private getEndHRTime(hrstart: [number, number]): string {
const hrend = process.hrtime(hrstart);
return util.format('%ds %dms', hrend[0], hrend[1] / 1000000);
return util.format('%d%d', hrend[0], hrend[1] / 1000000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,10 @@ describe('Telemetry', () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, false);

telemetryService.sendCommandEvent('create_apex_class_command');
telemetryService.sendLaunchEvent('test', 'test2');
assert.notCalled(sendEvent);
});

it('Should send correct data format on sendCommandEvent', async () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, true);

telemetryService.sendCommandEvent('create_apex_class_command');
assert.calledOnce(sendEvent);

const expectedData = {
extensionName: 'salesforcedx-vscode-apex-replay-debugger',
commandName: 'create_apex_class_command'
};
assert.calledWith(sendEvent, 'commandExecution', expectedData);
});

it('Should send correct data format on sendExtensionActivationEvent', async () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, true);
Expand Down
11 changes: 1 addition & 10 deletions packages/salesforcedx-vscode-apex/src/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ export class TelemetryService {
}
}

public sendCommandEvent(commandName: string): void {
if (this.reporter !== undefined && this.isTelemetryEnabled) {
this.reporter.sendTelemetryEvent('commandExecution', {
extensionName: EXTENSION_NAME,
commandName
});
}
}

public sendApexLSPActivationEvent(hrstart: [number, number]): void {
if (this.reporter !== undefined && this.isTelemetryEnabled) {
const startupTime = this.getEndHRTime(hrstart);
Expand Down Expand Up @@ -90,6 +81,6 @@ export class TelemetryService {

private getEndHRTime(hrstart: [number, number]): string {
const hrend = process.hrtime(hrstart);
return util.format('%ds %dms', hrend[0], hrend[1] / 1000000);
return util.format('%d%d', hrend[0], hrend[1] / 1000000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,10 @@ describe('Telemetry', () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, false);

telemetryService.sendCommandEvent('some_apex_command');
telemetryService.sendExtensionActivationEvent([1, 700]);
assert.notCalled(sendEvent);
});

it('Should send correct data format on sendCommandEvent', async () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, true);

telemetryService.sendCommandEvent('some_apex_command');
assert.calledOnce(sendEvent);

const expectedData = {
extensionName: 'salesforcedx-vscode-apex',
commandName: 'some_apex_command'
};
assert.calledWith(sendEvent, 'commandExecution', expectedData);
});

it('Should send correct data format on sendExtensionActivationEvent', async () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, true);
Expand Down
5 changes: 3 additions & 2 deletions packages/salesforcedx-vscode-core/src/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,10 @@ export abstract class SfdxCommandletExecutor<T>

public logMetric(
logName: string | undefined,
executionTime: [number, number]
executionTime: [number, number],
additionalData?: any
) {
telemetryService.sendCommandEvent(logName, executionTime);
telemetryService.sendCommandEvent(logName, executionTime, additionalData);
}

public execute(response: ContinueResponse<T>): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ForceApexClassCreateExecutor extends SfdxCommandletExecutor<
)
? 'defaultDir'
: 'customDir';
this.logMetric(`${execution.command.logName}_${dirType}`, startTime);
this.logMetric(execution.command.logName, startTime, { dirType });
if (
data !== undefined &&
data.toString() === '0' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class ForceApexTriggerCreateExecutor extends SfdxCommandletExecutor<
)
? 'defaultDir'
: 'customDir';
this.logMetric(`${execution.command.logName}_${dirType}`, startTime);
this.logMetric(execution.command.logName, startTime, { dirType });
if (data !== undefined && data.toString() === '0' && hasRootWorkspace()) {
vscode.workspace
.openTextDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ForceLightningAppCreateExecutor extends SfdxCommandletExecutor<
)
? 'defaultDir'
: 'customDir';
this.logMetric(`${execution.command.logName}_${dirType}`, startTime);
this.logMetric(execution.command.logName, startTime, { dirType });
if (data !== undefined && data.toString() === '0' && hasRootWorkspace()) {
vscode.workspace
.openTextDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ForceLightningComponentCreateExecutor extends SfdxCommandletExecutor<
)
? 'defaultDir'
: 'customDir';
this.logMetric(`${execution.command.logName}_${dirType}`, startTime);
this.logMetric(execution.command.logName, startTime, { dirType });
if (data !== undefined && data.toString() === '0' && hasRootWorkspace()) {
vscode.workspace
.openTextDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ForceLightningEventCreateExecutor extends SfdxCommandletExecutor<
)
? 'defaultDir'
: 'customDir';
this.logMetric(`${execution.command.logName}_${dirType}`, startTime);
this.logMetric(execution.command.logName, startTime, { dirType });
if (data !== undefined && data.toString() === '0' && hasRootWorkspace()) {
vscode.workspace
.openTextDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ForceLightningInterfaceCreateExecutor extends SfdxCommandletExecutor<
)
? 'defaultDir'
: 'customDir';
this.logMetric(`${execution.command.logName}_${dirType}`, startTime);
this.logMetric(execution.command.logName, startTime, { dirType });
if (data !== undefined && data.toString() === '0' && hasRootWorkspace()) {
vscode.workspace
.openTextDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ForceVisualForceComponentCreateExecutor extends SfdxCommandletExecutor<
)
? 'defaultDir'
: 'customDir';
this.logMetric(`${execution.command.logName}_${dirType}`, startTime);
this.logMetric(execution.command.logName, startTime, { dirType });
if (data !== undefined && data.toString() === '0' && hasRootWorkspace()) {
vscode.workspace
.openTextDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ForceVisualForcePageCreateExecutor extends SfdxCommandletExecutor<
)
? 'defaultDir'
: 'customDir';
this.logMetric(`${execution.command.logName}_${dirType}`, startTime);
this.logMetric(execution.command.logName, startTime, { dirType });
if (
data !== undefined &&
data.toString() === '0' &&
Expand Down
29 changes: 20 additions & 9 deletions packages/salesforcedx-vscode-core/src/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import TelemetryReporter from './telemetryReporter';
const TELEMETRY_GLOBAL_VALUE = 'sfdxTelemetryMessage';
const EXTENSION_NAME = 'salesforcedx-vscode-core';

interface CommandMetric {
extensionName: string;
commandName: string;
executionTime?: string;
}

export class TelemetryService {
private static instance: TelemetryService;
private context: vscode.ExtensionContext | undefined;
Expand Down Expand Up @@ -127,20 +133,25 @@ export class TelemetryService {

public sendCommandEvent(
commandName?: string,
hrstart?: [number, number]
hrstart?: [number, number],
additionalData?: any
): void {
if (
this.reporter !== undefined &&
this.isTelemetryEnabled() &&
commandName &&
hrstart
commandName
) {
const executionTime = this.getEndHRTime(hrstart);
this.reporter.sendTelemetryEvent('commandExecution', {
const baseTelemetry: CommandMetric = {
extensionName: EXTENSION_NAME,
commandName,
executionTime
});
commandName
};

if (hrstart) {
baseTelemetry['executionTime'] = this.getEndHRTime(hrstart);
}

const aggregatedTelemetry = Object.assign(baseTelemetry, additionalData);
this.reporter.sendTelemetryEvent('commandExecution', aggregatedTelemetry);
}
}

Expand Down Expand Up @@ -171,6 +182,6 @@ export class TelemetryService {

private getEndHRTime(hrstart: [number, number]): string {
const hrend = process.hrtime(hrstart);
return util.format('%ds %dms', hrend[0], hrend[1] / 1000000);
return util.format('%d%d', hrend[0], hrend[1] / 1000000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,33 @@ describe('Telemetry', () => {
};
assert.calledWith(reporter, 'commandExecution', match(expectedData));
});

it('Should send correct data format on sendCommandEvent with additionalData', async () => {
// create vscode extensionContext
mockContext = new MockContext(true);

const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(mockContext, machineId);
const additionalData = {
dirType: 'testDirectoryType',
secondParam: 'value'
};

telemetryService.sendCommandEvent(
'create_apex_class_command',
[0, 678],
additionalData
);
assert.calledOnce(reporter);

const expectedData = {
extensionName: 'salesforcedx-vscode-core',
commandName: 'create_apex_class_command',
executionTime: match.string,
dirType: 'testDirectoryType',
secondParam: 'value'
};
assert.calledWith(reporter, 'commandExecution', match(expectedData));
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,8 @@ export class TelemetryService {
}
}

public async sendCommandEvent(commandName?: string): Promise<void> {
if (this.reporter !== undefined && this.isTelemetryEnabled && commandName) {
this.reporter.sendTelemetryEvent('commandExecution', {
extensionName: EXTENSION_NAME,
commandName
});
}
}

private getEndHRTime(hrstart: [number, number]): string {
const hrend = process.hrtime(hrstart);
return util.format('%ds %dms', hrend[0], hrend[1] / 1000000);
return util.format('%d%d', hrend[0], hrend[1] / 1000000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ForceLightningLwcCreateExecutor extends SfdxCommandletExecutor<
)
? 'defaultDir'
: 'customDir';
this.logMetric(`${execution.command.logName}_${dirType}`, startTime);
this.logMetric(execution.command.logName, startTime, { dirType });
if (
data !== undefined &&
data.toString() === '0' &&
Expand Down
12 changes: 1 addition & 11 deletions packages/salesforcedx-vscode-lwc/src/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,8 @@ export class TelemetryService {
}
}

public async sendCommandEvent(commandName?: string): Promise<void> {
await this.setupVSCodeTelemetry();
if (this.reporter !== undefined && this.isTelemetryEnabled && commandName) {
this.reporter.sendTelemetryEvent('commandExecution', {
extensionName: EXTENSION_NAME,
commandName
});
}
}

private getEndHRTime(hrstart: [number, number]): string {
const hrend = process.hrtime(hrstart);
return util.format('%ds %dms', hrend[0], hrend[1] / 1000000);
return util.format('%d%d', hrend[0], hrend[1] / 1000000);
}
}
Loading

0 comments on commit b8c0c1c

Please sign in to comment.