diff --git a/packages/salesforcedx-utils-vscode/src/commands/commandletExecutors.ts b/packages/salesforcedx-utils-vscode/src/commands/commandletExecutors.ts index 71f77cb6a6..e703d63559 100644 --- a/packages/salesforcedx-utils-vscode/src/commands/commandletExecutors.ts +++ b/packages/salesforcedx-utils-vscode/src/commands/commandletExecutors.ts @@ -4,13 +4,14 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -import { Properties, Measurements, TelemetryData } from '@salesforce/vscode-service-provider'; +import { + Properties, + Measurements, + TelemetryData +} from '@salesforce/vscode-service-provider'; import * as vscode from 'vscode'; import { CliCommandExecutor, Command, CommandExecution } from '../cli'; -import { - TelemetryBuilder, - TelemetryService -} from '../index'; +import { TelemetryBuilder, TelemetryService } from '../index'; import { nls } from '../messages'; import { SettingsService } from '../settings'; import { CommandletExecutor, ContinueResponse } from '../types'; @@ -118,7 +119,8 @@ export abstract class SfCommandletExecutor implements CommandletExecutor { } export abstract class LibraryCommandletExecutor - implements CommandletExecutor { + implements CommandletExecutor +{ protected cancellable: boolean = false; private cancelled: boolean = false; private readonly executionName: string; @@ -219,7 +221,10 @@ export abstract class LibraryCommandletExecutor ); } catch (e) { if (e instanceof Error) { - telemetryService.sendException(e.name, e.message); + telemetryService.sendException( + `LibraryCommandletExecutor - ${this.logName}`, + `Error: name = ${e.name} message = ${e.message}` + ); notificationService.showFailedExecution(this.executionName); channelService.appendLine(e.message); } diff --git a/packages/salesforcedx-vscode-core/src/commands/auth/orgLogout.ts b/packages/salesforcedx-vscode-core/src/commands/auth/orgLogout.ts index 8410001ad8..33115bb65f 100644 --- a/packages/salesforcedx-vscode-core/src/commands/auth/orgLogout.ts +++ b/packages/salesforcedx-vscode-core/src/commands/auth/orgLogout.ts @@ -82,7 +82,10 @@ export class OrgLogoutDefault extends LibraryCommandletExecutor { try { await removeUsername(response.data); } catch (e) { - telemetryService.sendException(e.name, e.message); + telemetryService.sendException( + 'org_logout_default', + `Error: name = ${e.name} message = ${e.message}` + ); return false; } return true; @@ -92,7 +95,7 @@ export class OrgLogoutDefault extends LibraryCommandletExecutor { export const orgLogoutDefault = async () => { const { username, isScratch, alias, error } = await resolveTargetOrg(); if (error) { - telemetryService.sendException(error.name, error.message); + telemetryService.sendException('org_logout_default', error.message); void notificationService.showErrorMessage('Logout failed to run'); } else if (username) { // confirm logout for scratch orgs due to special considerations: diff --git a/packages/salesforcedx-vscode-core/src/commands/index.ts b/packages/salesforcedx-vscode-core/src/commands/index.ts index ef0fe77c70..363ad23f1a 100644 --- a/packages/salesforcedx-vscode-core/src/commands/index.ts +++ b/packages/salesforcedx-vscode-core/src/commands/index.ts @@ -61,7 +61,6 @@ export { } from './packageInstall'; export { RefreshSObjectsExecutor, - checkSObjectsAndRefresh, refreshSObjects, initSObjectDefinitions } from './refreshSObjects'; diff --git a/packages/salesforcedx-vscode-core/src/commands/projectDeployStart.ts b/packages/salesforcedx-vscode-core/src/commands/projectDeployStart.ts index 4c8080f7ff..1fd864e640 100644 --- a/packages/salesforcedx-vscode-core/src/commands/projectDeployStart.ts +++ b/packages/salesforcedx-vscode-core/src/commands/projectDeployStart.ts @@ -158,7 +158,10 @@ export class ProjectDeployStartExecutor extends SfCommandletExecutor<{}> { e.message = 'Error while creating diagnostics for vscode problem view.'; } - telemetryService.sendException(e.name, e.message); + telemetryService.sendException( + execution.command.logName, + `Error: name = ${e.name} message = ${e.message}` + ); console.error(e.message); } telemetry.addProperty('success', String(success)); diff --git a/packages/salesforcedx-vscode-core/src/commands/refreshSObjects.ts b/packages/salesforcedx-vscode-core/src/commands/refreshSObjects.ts index faaf46d176..6486568c4a 100644 --- a/packages/salesforcedx-vscode-core/src/commands/refreshSObjects.ts +++ b/packages/salesforcedx-vscode-core/src/commands/refreshSObjects.ts @@ -30,7 +30,6 @@ import * as fs from 'fs'; import * as path from 'path'; import * as vscode from 'vscode'; import { channelService } from '../channels'; -import { WorkspaceContext } from '../context'; import { nls } from '../messages'; import { telemetryService } from '../telemetry'; @@ -178,7 +177,10 @@ export class RefreshSObjectsExecutor extends SfCommandletExecutor<{}> { ); } catch (error) { console.log('Generate error ' + error.error); - telemetryService.sendException(error.name, error.error); + telemetryService.sendException( + 'generate_faux_classes_create', + `Error: name = ${error.name} message = ${error.error}` + ); RefreshSObjectsExecutor.isActive = false; throw error; @@ -201,32 +203,28 @@ export const refreshSObjects = async (source?: SObjectRefreshSource) => { await commandlet.run(); }; -export const verifyUsernameAndInitSObjectDefinitions = async ( - projectPath: string +export const initSObjectDefinitions = async ( + projectPath: string, + isSettingEnabled: boolean ) => { - const hasTargetOrgSet = - (await WorkspaceContext.getInstance().getConnection()).getUsername() !== - undefined; - if (hasTargetOrgSet) { - initSObjectDefinitions(projectPath).catch(e => - telemetryService.sendException(e.name, e.message) - ); - } -}; - -export const initSObjectDefinitions = async (projectPath: string) => { if (projectPath) { - const sobjectFolder = getSObjectsDirectory(); + const sobjectFolder = isSettingEnabled + ? getSObjectsDirectory() + : getStandardSObjectsDirectory(); + const refreshSource = isSettingEnabled + ? SObjectRefreshSource.Startup + : SObjectRefreshSource.StartupMin; + if (!fs.existsSync(sobjectFolder)) { telemetryService.sendEventData( 'sObjectRefreshNotification', - { type: SObjectRefreshSource.Startup }, + { type: refreshSource }, undefined ); try { - await refreshSObjects(SObjectRefreshSource.Startup); + await refreshSObjects(refreshSource); } catch (e) { - telemetryService.sendException(e.name, e.message); + telemetryService.sendException('initSObjectDefinitions', e.message); throw e; } } @@ -244,19 +242,3 @@ const getStandardSObjectsDirectory = () => { STANDARDOBJECTS_DIR ); }; - -export const checkSObjectsAndRefresh = async (projectPath: string) => { - if (projectPath && !fs.existsSync(getStandardSObjectsDirectory())) { - telemetryService.sendEventData( - 'sObjectRefreshNotification', - { type: SObjectRefreshSource.StartupMin }, - undefined - ); - try { - await refreshSObjects(SObjectRefreshSource.StartupMin); - } catch (e) { - telemetryService.sendException(e.name, e.message); - throw e; - } - } -}; diff --git a/packages/salesforcedx-vscode-core/src/conflict/directoryDiffer.ts b/packages/salesforcedx-vscode-core/src/conflict/directoryDiffer.ts index 30d3dfbca4..e9552d5fb1 100644 --- a/packages/salesforcedx-vscode-core/src/conflict/directoryDiffer.ts +++ b/packages/salesforcedx-vscode-core/src/conflict/directoryDiffer.ts @@ -173,7 +173,10 @@ export const diffOneFile = async ( await notificationService.showErrorMessage(err.message); channelService.appendLine(err.message); channelService.showChannelOutput(); - telemetryService.sendException(err.name, err.message); + telemetryService.sendException( + 'source_diff_file', + `Error: name = ${err.name} message = ${err.message}` + ); } return; } diff --git a/packages/salesforcedx-vscode-core/src/index.ts b/packages/salesforcedx-vscode-core/src/index.ts index 52d830a9c1..a8d7f31586 100644 --- a/packages/salesforcedx-vscode-core/src/index.ts +++ b/packages/salesforcedx-vscode-core/src/index.ts @@ -26,7 +26,6 @@ import { apexGenerateClass, apexGenerateTrigger, apexGenerateUnitTestClass, - checkSObjectsAndRefresh, configList, configSet, dataQuery, @@ -118,7 +117,10 @@ import { orgBrowser } from './orgBrowser'; import { OrgList } from './orgPicker'; import { isSalesforceProjectOpened } from './predicates'; import { SalesforceProjectConfig } from './salesforceProject'; -import { getCoreLoggerService, registerGetTelemetryServiceCommand } from './services'; +import { + getCoreLoggerService, + registerGetTelemetryServiceCommand +} from './services'; import { registerPushOrDeployOnSave, salesforceCoreSettings } from './settings'; import { taskViewService } from './statuses'; import { showTelemetryMessage, telemetryService } from './telemetry'; @@ -582,7 +584,11 @@ export const activate = async (extensionContext: vscode.ExtensionContext) => { // Set internal dev context const internalDev = salesforceCoreSettings.getInternalDev(); - void vscode.commands.executeCommand('setContext', 'sf:internal_dev', internalDev); + void vscode.commands.executeCommand( + 'setContext', + 'sf:internal_dev', + internalDev + ); if (internalDev) { // Internal Dev commands @@ -685,15 +691,15 @@ export const activate = async (extensionContext: vscode.ExtensionContext) => { .getConfiguration(SFDX_CORE_CONFIGURATION_NAME) .get(ENABLE_SOBJECT_REFRESH_ON_STARTUP, false); - if (sobjectRefreshStartup) { - initSObjectDefinitions( - vscode.workspace.workspaceFolders[0].uri.fsPath - ).catch(e => telemetryService.sendException(e.name, e.message)); - } else { - checkSObjectsAndRefresh( - vscode.workspace.workspaceFolders[0].uri.fsPath - ).catch(e => telemetryService.sendException(e.name, e.message)); - } + initSObjectDefinitions( + vscode.workspace.workspaceFolders[0].uri.fsPath, + sobjectRefreshStartup + ).catch(e => + telemetryService.sendException( + 'initSObjectDefinitionsError', + `Error: name = ${e.name} message = ${e.message} with sobjectRefreshStartup = ${sobjectRefreshStartup}` + ) + ); } void activateTracker.markActivationStop(); diff --git a/packages/salesforcedx-vscode-core/test/vscode-integration/commands/refreshSObjects.test.ts b/packages/salesforcedx-vscode-core/test/vscode-integration/commands/refreshSObjects.test.ts index 6744cf9b17..e9b83f02ee 100644 --- a/packages/salesforcedx-vscode-core/test/vscode-integration/commands/refreshSObjects.test.ts +++ b/packages/salesforcedx-vscode-core/test/vscode-integration/commands/refreshSObjects.test.ts @@ -30,35 +30,31 @@ import * as path from 'path'; import { createSandbox, SinonSandbox, SinonStub } from 'sinon'; import { ProgressLocation, window } from 'vscode'; import { - checkSObjectsAndRefresh, RefreshSObjectsExecutor, RefreshSelection, SObjectRefreshGatherer, - verifyUsernameAndInitSObjectDefinitions + initSObjectDefinitions } from '../../../src/commands/refreshSObjects'; -import { WorkspaceContext } from '../../../src/context'; import { nls } from '../../../src/messages'; import { telemetryService } from '../../../src/telemetry'; describe('GenerateFauxClasses', () => { const sobjectsPath = path.join(projectPaths.toolsFolder(), SOBJECTS_DIR); + const standardSobjectsPath = path.join(sobjectsPath, STANDARDOBJECTS_DIR); describe('initSObjectDefinitions', () => { let sandboxStub: SinonSandbox; let existsSyncStub: SinonStub; - let getUsernameStub: SinonStub; let commandletSpy: SinonStub; let notificationStub: SinonStub; + let telemetryEventStub: SinonStub; const projectPath = path.join('sample', 'path'); beforeEach(() => { sandboxStub = createSandbox(); existsSyncStub = sandboxStub.stub(fs, 'existsSync'); - getUsernameStub = sandboxStub.stub(); - sandboxStub - .stub(WorkspaceContext.prototype, 'getConnection') - .resolves({ getUsername: getUsernameStub }); commandletSpy = sandboxStub.stub(SfCommandlet.prototype, 'run'); + telemetryEventStub = sandboxStub.stub(telemetryService, 'sendEventData'); notificationStub = sandboxStub.stub( notificationService, 'showInformationMessage' @@ -71,9 +67,8 @@ describe('GenerateFauxClasses', () => { it('Should execute sobject refresh if no sobjects folder is present', async () => { existsSyncStub.returns(false); - getUsernameStub.returns(new Map([['target-org', 'Sample']])); - await verifyUsernameAndInitSObjectDefinitions(projectPath); + await initSObjectDefinitions(projectPath, true); expect(existsSyncStub.calledWith(sobjectsPath)).to.be.true; expect(commandletSpy.calledOnce).to.be.true; @@ -86,46 +81,16 @@ describe('GenerateFauxClasses', () => { it('Should not execute sobject refresh if sobjects folder is present', async () => { existsSyncStub.returns(true); - getUsernameStub.returns('Sample'); - await verifyUsernameAndInitSObjectDefinitions(projectPath); + await initSObjectDefinitions(projectPath, true); expect(existsSyncStub.calledWith(sobjectsPath)).to.be.true; expect(commandletSpy.notCalled).to.be.true; }); - - it('Should not execute sobject refresh if no target org set', async () => { - existsSyncStub.returns(false); - getUsernameStub.returns(undefined); - - await verifyUsernameAndInitSObjectDefinitions(projectPath); - - expect(commandletSpy.notCalled).to.be.true; - }); - }); - - describe('checkSObjectsAndRefresh', () => { - let sandboxStub: SinonSandbox; - let existsSyncStub: SinonStub; - let telemetryEventStub: SinonStub; - - const projectPath = path.join('sample', 'path'); - const standardSobjectsPath = path.join(sobjectsPath, STANDARDOBJECTS_DIR); - - beforeEach(() => { - sandboxStub = createSandbox(); - existsSyncStub = sandboxStub.stub(fs, 'existsSync'); - telemetryEventStub = sandboxStub.stub(telemetryService, 'sendEventData'); - }); - - afterEach(() => { - sandboxStub.restore(); - }); - it('Should call refreshSObjects service when sobjects do not exist', async () => { existsSyncStub.returns(false); - await checkSObjectsAndRefresh(projectPath); + await initSObjectDefinitions(projectPath, false); expect(existsSyncStub.calledWith(standardSobjectsPath)).to.be.true; expect(telemetryEventStub.callCount).to.equal(1); @@ -136,11 +101,10 @@ describe('GenerateFauxClasses', () => { }); expect(telemetryCallArgs[2]).to.equal(undefined); }); - it('Should not call refreshSObjects service when sobjects already exist', async () => { existsSyncStub.returns(true); - await checkSObjectsAndRefresh(projectPath); + await initSObjectDefinitions(projectPath, false); expect(existsSyncStub.calledWith(standardSobjectsPath)).to.be.true; expect(telemetryEventStub.notCalled).to.be.true;