diff --git a/packages/salesforcedx-vscode-apex-debugger/src/telemetry/telemetry.ts b/packages/salesforcedx-vscode-apex-debugger/src/telemetry/telemetry.ts index 456440eb4e..92fe2816fc 100644 --- a/packages/salesforcedx-vscode-apex-debugger/src/telemetry/telemetry.ts +++ b/packages/salesforcedx-vscode-apex-debugger/src/telemetry/telemetry.ts @@ -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); } } diff --git a/packages/salesforcedx-vscode-apex-debugger/test/vscode-integration/telemetry/telemetry.test.ts b/packages/salesforcedx-vscode-apex-debugger/test/vscode-integration/telemetry/telemetry.test.ts index 43f7cc480e..66db9e36be 100644 --- a/packages/salesforcedx-vscode-apex-debugger/test/vscode-integration/telemetry/telemetry.test.ts +++ b/packages/salesforcedx-vscode-apex-debugger/test/vscode-integration/telemetry/telemetry.test.ts @@ -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); diff --git a/packages/salesforcedx-vscode-apex-replay-debugger/src/telemetry/telemetry.ts b/packages/salesforcedx-vscode-apex-replay-debugger/src/telemetry/telemetry.ts index bd15d01943..fe3d81a131 100644 --- a/packages/salesforcedx-vscode-apex-replay-debugger/src/telemetry/telemetry.ts +++ b/packages/salesforcedx-vscode-apex-replay-debugger/src/telemetry/telemetry.ts @@ -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', { @@ -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); } } diff --git a/packages/salesforcedx-vscode-apex-replay-debugger/test/vscode-integration/telemetry/telemetry.test.ts b/packages/salesforcedx-vscode-apex-replay-debugger/test/vscode-integration/telemetry/telemetry.test.ts index 204e515e26..61ac8ae848 100644 --- a/packages/salesforcedx-vscode-apex-replay-debugger/test/vscode-integration/telemetry/telemetry.test.ts +++ b/packages/salesforcedx-vscode-apex-replay-debugger/test/vscode-integration/telemetry/telemetry.test.ts @@ -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); diff --git a/packages/salesforcedx-vscode-apex/src/telemetry/telemetry.ts b/packages/salesforcedx-vscode-apex/src/telemetry/telemetry.ts index 7f11503cbe..94f08f8b7e 100644 --- a/packages/salesforcedx-vscode-apex/src/telemetry/telemetry.ts +++ b/packages/salesforcedx-vscode-apex/src/telemetry/telemetry.ts @@ -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); @@ -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); } } diff --git a/packages/salesforcedx-vscode-apex/test/vscode-integration/telemetry/telemetry.test.ts b/packages/salesforcedx-vscode-apex/test/vscode-integration/telemetry/telemetry.test.ts index a276250496..9ce5030495 100644 --- a/packages/salesforcedx-vscode-apex/test/vscode-integration/telemetry/telemetry.test.ts +++ b/packages/salesforcedx-vscode-apex/test/vscode-integration/telemetry/telemetry.test.ts @@ -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); diff --git a/packages/salesforcedx-vscode-core/src/commands/commands.ts b/packages/salesforcedx-vscode-core/src/commands/commands.ts index fa8ead03ee..5e55716a3b 100644 --- a/packages/salesforcedx-vscode-core/src/commands/commands.ts +++ b/packages/salesforcedx-vscode-core/src/commands/commands.ts @@ -358,9 +358,10 @@ export abstract class SfdxCommandletExecutor 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): void { diff --git a/packages/salesforcedx-vscode-core/src/commands/forceApexClassCreate.ts b/packages/salesforcedx-vscode-core/src/commands/forceApexClassCreate.ts index 44037897c2..b6f30b2868 100644 --- a/packages/salesforcedx-vscode-core/src/commands/forceApexClassCreate.ts +++ b/packages/salesforcedx-vscode-core/src/commands/forceApexClassCreate.ts @@ -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' && diff --git a/packages/salesforcedx-vscode-core/src/commands/forceApexTriggerCreate.ts b/packages/salesforcedx-vscode-core/src/commands/forceApexTriggerCreate.ts index c693d36e22..6b5cb715c4 100644 --- a/packages/salesforcedx-vscode-core/src/commands/forceApexTriggerCreate.ts +++ b/packages/salesforcedx-vscode-core/src/commands/forceApexTriggerCreate.ts @@ -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( diff --git a/packages/salesforcedx-vscode-core/src/commands/forceLightningAppCreate.ts b/packages/salesforcedx-vscode-core/src/commands/forceLightningAppCreate.ts index 4023dc148c..560bfb1689 100644 --- a/packages/salesforcedx-vscode-core/src/commands/forceLightningAppCreate.ts +++ b/packages/salesforcedx-vscode-core/src/commands/forceLightningAppCreate.ts @@ -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( diff --git a/packages/salesforcedx-vscode-core/src/commands/forceLightningComponentCreate.ts b/packages/salesforcedx-vscode-core/src/commands/forceLightningComponentCreate.ts index c5597ad17a..4e70ccd93f 100644 --- a/packages/salesforcedx-vscode-core/src/commands/forceLightningComponentCreate.ts +++ b/packages/salesforcedx-vscode-core/src/commands/forceLightningComponentCreate.ts @@ -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( diff --git a/packages/salesforcedx-vscode-core/src/commands/forceLightningEventCreate.ts b/packages/salesforcedx-vscode-core/src/commands/forceLightningEventCreate.ts index 2f34104f71..eab6eef398 100644 --- a/packages/salesforcedx-vscode-core/src/commands/forceLightningEventCreate.ts +++ b/packages/salesforcedx-vscode-core/src/commands/forceLightningEventCreate.ts @@ -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( diff --git a/packages/salesforcedx-vscode-core/src/commands/forceLightningInterfaceCreate.ts b/packages/salesforcedx-vscode-core/src/commands/forceLightningInterfaceCreate.ts index 399c7d7a7e..0c2cd16fde 100644 --- a/packages/salesforcedx-vscode-core/src/commands/forceLightningInterfaceCreate.ts +++ b/packages/salesforcedx-vscode-core/src/commands/forceLightningInterfaceCreate.ts @@ -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( diff --git a/packages/salesforcedx-vscode-core/src/commands/forceVisualforceComponentCreate.ts b/packages/salesforcedx-vscode-core/src/commands/forceVisualforceComponentCreate.ts index 1a98a8f197..e9309aeefa 100644 --- a/packages/salesforcedx-vscode-core/src/commands/forceVisualforceComponentCreate.ts +++ b/packages/salesforcedx-vscode-core/src/commands/forceVisualforceComponentCreate.ts @@ -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( diff --git a/packages/salesforcedx-vscode-core/src/commands/forceVisualforcePageCreate.ts b/packages/salesforcedx-vscode-core/src/commands/forceVisualforcePageCreate.ts index d2415de07a..87d3191252 100644 --- a/packages/salesforcedx-vscode-core/src/commands/forceVisualforcePageCreate.ts +++ b/packages/salesforcedx-vscode-core/src/commands/forceVisualforcePageCreate.ts @@ -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' && diff --git a/packages/salesforcedx-vscode-core/src/telemetry/telemetry.ts b/packages/salesforcedx-vscode-core/src/telemetry/telemetry.ts index 1dbdc7aea1..02f1f7ff9f 100644 --- a/packages/salesforcedx-vscode-core/src/telemetry/telemetry.ts +++ b/packages/salesforcedx-vscode-core/src/telemetry/telemetry.ts @@ -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; @@ -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); } } @@ -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); } } diff --git a/packages/salesforcedx-vscode-core/test/vscode-integration/telemetry/index.test.ts b/packages/salesforcedx-vscode-core/test/vscode-integration/telemetry/index.test.ts index eb2daee44b..d3498ceec9 100644 --- a/packages/salesforcedx-vscode-core/test/vscode-integration/telemetry/index.test.ts +++ b/packages/salesforcedx-vscode-core/test/vscode-integration/telemetry/index.test.ts @@ -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)); + }); }); }); diff --git a/packages/salesforcedx-vscode-lightning/src/telemetry/telemetry.ts b/packages/salesforcedx-vscode-lightning/src/telemetry/telemetry.ts index 3f02ce83cd..26dcad3c0c 100644 --- a/packages/salesforcedx-vscode-lightning/src/telemetry/telemetry.ts +++ b/packages/salesforcedx-vscode-lightning/src/telemetry/telemetry.ts @@ -52,17 +52,8 @@ export class TelemetryService { } } - public async sendCommandEvent(commandName?: string): Promise { - 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); } } diff --git a/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcCreate.ts b/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcCreate.ts index 7951dced17..6f8bc608dd 100644 --- a/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcCreate.ts +++ b/packages/salesforcedx-vscode-lwc/src/commands/forceLightningLwcCreate.ts @@ -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' && diff --git a/packages/salesforcedx-vscode-lwc/src/telemetry/telemetry.ts b/packages/salesforcedx-vscode-lwc/src/telemetry/telemetry.ts index 2b85fe6125..f5ca9713cd 100644 --- a/packages/salesforcedx-vscode-lwc/src/telemetry/telemetry.ts +++ b/packages/salesforcedx-vscode-lwc/src/telemetry/telemetry.ts @@ -83,18 +83,8 @@ export class TelemetryService { } } - public async sendCommandEvent(commandName?: string): Promise { - 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); } } diff --git a/packages/salesforcedx-vscode-lwc/test/vscode-integration/telemetry/telemetry.test.ts b/packages/salesforcedx-vscode-lwc/test/vscode-integration/telemetry/telemetry.test.ts index 2875ae3829..a282c14e80 100644 --- a/packages/salesforcedx-vscode-lwc/test/vscode-integration/telemetry/telemetry.test.ts +++ b/packages/salesforcedx-vscode-lwc/test/vscode-integration/telemetry/telemetry.test.ts @@ -34,28 +34,10 @@ describe('Telemetry', () => { const telemetryService = TelemetryService.getInstance(); telemetryService.initializeService(reporter, false); - await telemetryService.sendCommandEvent( - 'force_lightning_lwc_component_create' - ); + await telemetryService.sendExtensionActivationEvent([0, 678]); assert.notCalled(sendEvent); }); - it('Should send correct data format on sendCommandEvent', async () => { - const telemetryService = TelemetryService.getInstance(); - telemetryService.initializeService(reporter, true); - - await telemetryService.sendCommandEvent( - 'force_lightning_lwc_component_create' - ); - assert.calledOnce(sendEvent); - - const expectedData = { - extensionName: 'salesforcedx-vscode-lwc', - commandName: 'force_lightning_lwc_component_create' - }; - assert.calledWith(sendEvent, 'commandExecution', expectedData); - }); - it('Should send correct data format on sendExtensionActivationEvent', async () => { const telemetryService = TelemetryService.getInstance(); telemetryService.initializeService(reporter, true); @@ -69,17 +51,4 @@ describe('Telemetry', () => { }; assert.calledWith(sendEvent, 'activationEvent', match(expectedData)); }); - - it('Should send correct data format on sendExtensionDeactivationEvent', async () => { - const telemetryService = TelemetryService.getInstance(); - telemetryService.initializeService(reporter, true); - - await telemetryService.sendExtensionDeactivationEvent(); - assert.calledOnce(sendEvent); - - const expectedData = { - extensionName: 'salesforcedx-vscode-lwc' - }; - assert.calledWith(sendEvent, 'deactivationEvent', expectedData); - }); }); diff --git a/packages/salesforcedx-vscode-visualforce/src/telemetry/telemetry.ts b/packages/salesforcedx-vscode-visualforce/src/telemetry/telemetry.ts index 36ec4aca71..2410be5a38 100644 --- a/packages/salesforcedx-vscode-visualforce/src/telemetry/telemetry.ts +++ b/packages/salesforcedx-vscode-visualforce/src/telemetry/telemetry.ts @@ -54,6 +54,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); } }