From 4b02a3af714c4dee83106e98f41451265e9cc2ed Mon Sep 17 00:00:00 2001 From: Shivika Gupta Date: Tue, 6 Feb 2024 01:30:32 +0530 Subject: [PATCH 1/7] Init telemetry logger fro desktop extension --- src/client/extension.ts | 70 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/src/client/extension.ts b/src/client/extension.ts index 2a8f8d6a..e3ff245a 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -34,7 +34,12 @@ import { disposeDiagnostics } from "./power-pages/validationDiagnostics"; import { bootstrapDiff } from "./power-pages/bootstrapdiff/BootstrapDiff"; import { CopilotNotificationShown } from "../common/copilot/telemetry/telemetryConstants"; import { copilotNotificationPanel, disposeNotificationPanel } from "../common/copilot/welcome-notification/CopilotNotificationPanel"; -import { COPILOT_NOTIFICATION_DISABLED } from "../common/copilot/constants"; +import { COPILOT_NOTIFICATION_DISABLED, PAC_SUCCESS } from "../common/copilot/constants"; +import { PacInterop, PacWrapper } from "./pac/PacWrapper"; +import { PacWrapperContext } from "./pac/PacWrapperContext"; +import { fetchArtemisResponse } from "../common/ArtemisService"; +import { oneDSLoggerWrapper } from "../common/OneDSLoggerTelemetry/oneDSLoggerWrapper"; +import { GetAuthProfileWatchPattern } from "./lib/AuthPanelView"; let client: LanguageClient; let _context: vscode.ExtensionContext; @@ -61,9 +66,14 @@ export async function activate( appInsightsResource.instrumentationKey ); context.subscriptions.push(_telemetry); + oneDSLoggerWrapper.instantiate("us"); + _telemetry.sendTelemetryEvent("Start", { "pac.userId": readUserSettings().uniqueId, }); + oneDSLoggerWrapper.getLogger().traceInfo("Start", { + "pac.userId": readUserSettings().uniqueId + }); // Setup context switches if ( @@ -95,6 +105,9 @@ export async function activate( _telemetry.sendTelemetryEvent("StartCommand", { commandId: "microsoft-powerapps-portals.preview-show", }); + oneDSLoggerWrapper.getLogger().traceInfo("StartCommand", { + commandId: "microsoft-powerapps-portals.preview-show" + }); PortalWebView.createOrShow(); } ) @@ -106,6 +119,9 @@ export async function activate( _telemetry.sendTelemetryEvent("StartCommand", { commandId: "microsoft-powerapps-portals.bootstrap-diff", }); + oneDSLoggerWrapper.getLogger().traceInfo("StartCommand", { + commandId: "microsoft-powerapps-portals.bootstrap-diff", + }); bootstrapDiff(); } ) @@ -123,6 +139,9 @@ export async function activate( _telemetry.sendTelemetryEvent("PortalWebPagePreview", { page: "NewPage", }); + oneDSLoggerWrapper.getLogger().traceInfo("PortalWebPagePreview", { + page: "NewPage", + }); PortalWebView?.currentPanel?._update(); } } @@ -137,6 +156,9 @@ export async function activate( _telemetry.sendTelemetryEvent("PortalWebPagePreview", { page: "ExistingPage", }); + oneDSLoggerWrapper.getLogger().traceInfo("PortalWebPagePreview", { + page: "ExistingPage", + }); PortalWebView?.currentPanel?._update(); } } @@ -172,10 +194,18 @@ export async function activate( listOfActivePortals = getPortalsOrgURLs(workspaceFolders, _telemetry); telemetryData = JSON.stringify(listOfActivePortals); _telemetry.sendTelemetryEvent("VscodeDesktopUsage", { listOfActivePortals: telemetryData, countOfActivePortals: listOfActivePortals.length.toString() }); + oneDSLoggerWrapper.getLogger().traceInfo("VscodeDesktopUsage", { listOfActivePortals: telemetryData, countOfActivePortals: listOfActivePortals.length.toString() }); } catch (exception) { - _telemetry.sendTelemetryException(exception as Error, { eventName: 'VscodeDesktopUsage' }); + const exceptionError = exception as Error; + _telemetry.sendTelemetryException(exceptionError, { eventName: 'VscodeDesktopUsage' }); + oneDSLoggerWrapper.getLogger().traceError(exceptionError.name, exceptionError.message, exceptionError, { eventName: 'VscodeDesktopUsage' }); } + + handleOrgChange(); + setupAuthFileWatcher(); + _telemetry.sendTelemetryEvent("PowerPagesWebsiteYmlExists"); // Capture's PowerPages Users + oneDSLoggerWrapper.getLogger().traceInfo("PowerPagesWebsiteYmlExists"); vscode.commands.executeCommand('setContext', 'powerpages.websiteYmlExists', true); initializeGenerator(_context, cliContext, _telemetry); // Showing the create command only if website.yml exists showNotificationForCopilot(_telemetry, telemetryData, listOfActivePortals.length.toString()); @@ -192,13 +222,41 @@ export async function activate( } _telemetry.sendTelemetryEvent("activated"); + oneDSLoggerWrapper.getLogger().traceInfo("activated"); +} +export function setupAuthFileWatcher() { + const watchPath = GetAuthProfileWatchPattern(); + if (watchPath) { + const watcher = vscode.workspace.createFileSystemWatcher(watchPath); + watcher.onDidChange(() => handleOrgChange()); + watcher.onDidCreate(() => handleOrgChange()); + watcher.onDidDelete(() => handleOrgChange()); + } +} + +async function handleOrgChange() { + const cliContext = new CliAcquisitionContext(_context, _telemetry); + const cli = new CliAcquisition(cliContext); + const cliPath = await cli.ensureInstalled(); + const pacContext = new PacWrapperContext(_context, _telemetry); + const interop = new PacInterop(pacContext, cliPath); + const pacWrapper = new PacWrapper(pacContext, interop); + const pacActiveOrg = await pacWrapper?.activeOrg(); + if (pacActiveOrg && pacActiveOrg.Status === PAC_SUCCESS) { + const orgID = pacActiveOrg.Results.OrgId; + const artemisResponse = await fetchArtemisResponse(orgID, _telemetry); + if (artemisResponse) { + const { geoName } = artemisResponse[0]; + oneDSLoggerWrapper.instantiate(geoName); + } + } } export async function deactivate(): Promise { if (_telemetry) { _telemetry.sendTelemetryEvent("End"); - + oneDSLoggerWrapper.getLogger().traceInfo("End"); // dispose() will flush any events not sent // Note, while dispose() returns a promise, we don't await it so that we can unblock the rest of unloading logic _telemetry.dispose(); @@ -320,6 +378,11 @@ function registerClientToReceiveNotifications(client: LanguageClient) { serverTelemetry.properties, serverTelemetry.measurements ); + oneDSLoggerWrapper.getLogger().traceInfo( + serverTelemetry.eventName, + serverTelemetry.properties, + serverTelemetry.measurements + ); } }); }); @@ -363,6 +426,7 @@ function showNotificationForCopilot(telemetry: TelemetryReporter, telemetryData: if (!isCopilotNotificationDisabled) { telemetry.sendTelemetryEvent(CopilotNotificationShown, { listOfOrgs: telemetryData, countOfActivePortals }); + oneDSLoggerWrapper.getLogger().traceInfo(CopilotNotificationShown, { listOfOrgs: telemetryData, countOfActivePortals }); copilotNotificationPanel(_context, telemetry, telemetryData, countOfActivePortals); } From b72262db3a6219557e8edd6389d155b496438ea8 Mon Sep 17 00:00:00 2001 From: Shivika Gupta Date: Tue, 6 Feb 2024 12:01:10 +0530 Subject: [PATCH 2/7] Changes --- src/client/extension.ts | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/client/extension.ts b/src/client/extension.ts index e3ff245a..a67ed7c0 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -66,14 +66,12 @@ export async function activate( appInsightsResource.instrumentationKey ); context.subscriptions.push(_telemetry); + // TODO: Need to decide on data residency part on unauthenticated scenario oneDSLoggerWrapper.instantiate("us"); _telemetry.sendTelemetryEvent("Start", { "pac.userId": readUserSettings().uniqueId, }); - oneDSLoggerWrapper.getLogger().traceInfo("Start", { - "pac.userId": readUserSettings().uniqueId - }); // Setup context switches if ( @@ -105,9 +103,6 @@ export async function activate( _telemetry.sendTelemetryEvent("StartCommand", { commandId: "microsoft-powerapps-portals.preview-show", }); - oneDSLoggerWrapper.getLogger().traceInfo("StartCommand", { - commandId: "microsoft-powerapps-portals.preview-show" - }); PortalWebView.createOrShow(); } ) @@ -119,9 +114,6 @@ export async function activate( _telemetry.sendTelemetryEvent("StartCommand", { commandId: "microsoft-powerapps-portals.bootstrap-diff", }); - oneDSLoggerWrapper.getLogger().traceInfo("StartCommand", { - commandId: "microsoft-powerapps-portals.bootstrap-diff", - }); bootstrapDiff(); } ) @@ -139,9 +131,6 @@ export async function activate( _telemetry.sendTelemetryEvent("PortalWebPagePreview", { page: "NewPage", }); - oneDSLoggerWrapper.getLogger().traceInfo("PortalWebPagePreview", { - page: "NewPage", - }); PortalWebView?.currentPanel?._update(); } } @@ -156,9 +145,6 @@ export async function activate( _telemetry.sendTelemetryEvent("PortalWebPagePreview", { page: "ExistingPage", }); - oneDSLoggerWrapper.getLogger().traceInfo("PortalWebPagePreview", { - page: "ExistingPage", - }); PortalWebView?.currentPanel?._update(); } } @@ -194,18 +180,15 @@ export async function activate( listOfActivePortals = getPortalsOrgURLs(workspaceFolders, _telemetry); telemetryData = JSON.stringify(listOfActivePortals); _telemetry.sendTelemetryEvent("VscodeDesktopUsage", { listOfActivePortals: telemetryData, countOfActivePortals: listOfActivePortals.length.toString() }); - oneDSLoggerWrapper.getLogger().traceInfo("VscodeDesktopUsage", { listOfActivePortals: telemetryData, countOfActivePortals: listOfActivePortals.length.toString() }); } catch (exception) { const exceptionError = exception as Error; _telemetry.sendTelemetryException(exceptionError, { eventName: 'VscodeDesktopUsage' }); - oneDSLoggerWrapper.getLogger().traceError(exceptionError.name, exceptionError.message, exceptionError, { eventName: 'VscodeDesktopUsage' }); } handleOrgChange(); setupAuthFileWatcher(); _telemetry.sendTelemetryEvent("PowerPagesWebsiteYmlExists"); // Capture's PowerPages Users - oneDSLoggerWrapper.getLogger().traceInfo("PowerPagesWebsiteYmlExists"); vscode.commands.executeCommand('setContext', 'powerpages.websiteYmlExists', true); initializeGenerator(_context, cliContext, _telemetry); // Showing the create command only if website.yml exists showNotificationForCopilot(_telemetry, telemetryData, listOfActivePortals.length.toString()); @@ -222,7 +205,6 @@ export async function activate( } _telemetry.sendTelemetryEvent("activated"); - oneDSLoggerWrapper.getLogger().traceInfo("activated"); } export function setupAuthFileWatcher() { @@ -256,7 +238,6 @@ async function handleOrgChange() { export async function deactivate(): Promise { if (_telemetry) { _telemetry.sendTelemetryEvent("End"); - oneDSLoggerWrapper.getLogger().traceInfo("End"); // dispose() will flush any events not sent // Note, while dispose() returns a promise, we don't await it so that we can unblock the rest of unloading logic _telemetry.dispose(); @@ -378,11 +359,6 @@ function registerClientToReceiveNotifications(client: LanguageClient) { serverTelemetry.properties, serverTelemetry.measurements ); - oneDSLoggerWrapper.getLogger().traceInfo( - serverTelemetry.eventName, - serverTelemetry.properties, - serverTelemetry.measurements - ); } }); }); @@ -426,7 +402,6 @@ function showNotificationForCopilot(telemetry: TelemetryReporter, telemetryData: if (!isCopilotNotificationDisabled) { telemetry.sendTelemetryEvent(CopilotNotificationShown, { listOfOrgs: telemetryData, countOfActivePortals }); - oneDSLoggerWrapper.getLogger().traceInfo(CopilotNotificationShown, { listOfOrgs: telemetryData, countOfActivePortals }); copilotNotificationPanel(_context, telemetry, telemetryData, countOfActivePortals); } From 5880c679e181a6cad138857ea15305cf501369da Mon Sep 17 00:00:00 2001 From: Shivika Gupta Date: Wed, 7 Feb 2024 17:23:53 +0530 Subject: [PATCH 3/7] Populate attributes for desktop extension telemetry --- src/client/extension.ts | 2 ++ src/client/telemetry/TelemetryEventNames.ts | 9 +++++++++ src/common/OneDSLoggerTelemetry/oneDSLogger.ts | 12 ++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/client/telemetry/TelemetryEventNames.ts diff --git a/src/client/extension.ts b/src/client/extension.ts index a67ed7c0..f49fe920 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -40,6 +40,7 @@ import { PacWrapperContext } from "./pac/PacWrapperContext"; import { fetchArtemisResponse } from "../common/ArtemisService"; import { oneDSLoggerWrapper } from "../common/OneDSLoggerTelemetry/oneDSLoggerWrapper"; import { GetAuthProfileWatchPattern } from "./lib/AuthPanelView"; +import { telemetryEventNames } from "./telemetry/TelemetryEventNames"; let client: LanguageClient; let _context: vscode.ExtensionContext; @@ -231,6 +232,7 @@ async function handleOrgChange() { if (artemisResponse) { const { geoName } = artemisResponse[0]; oneDSLoggerWrapper.instantiate(geoName); + oneDSLoggerWrapper.getLogger().traceInfo(telemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT, pacActiveOrg.Results); } } } diff --git a/src/client/telemetry/TelemetryEventNames.ts b/src/client/telemetry/TelemetryEventNames.ts new file mode 100644 index 00000000..392b6902 --- /dev/null +++ b/src/client/telemetry/TelemetryEventNames.ts @@ -0,0 +1,9 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + */ + +export enum telemetryEventNames { + DESKTOP_EXTENSION_INIT_CONTEXT = "DesktopExtensionInitContext", + +} diff --git a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts index a0b8eac8..65060df6 100644 --- a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts +++ b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts @@ -17,6 +17,7 @@ import {OneDSCollectorEventName} from "./EventContants"; import { telemetryEventNames } from "../../web/client/telemetry/constants"; import { region } from "../telemetry-generated/buildRegionConfiguration"; import { geoMappingsToAzureRegion } from "./shortNameMappingToAzureRegion"; +import { telemetryEventNames as desktopExtTelemetryEventNames } from "../../client/telemetry/TelemetryEventNames"; interface IInstrumentationSettings { endpointURL: string; @@ -345,8 +346,15 @@ export class OneDSLogger implements ITelemetryLogger{ // eslint-disable-next-line @typescript-eslint/no-explicit-any private populateVscodeDesktopAttributes(envelope: any){ - // TODO: this method helps in populating desktop attributes. - console.log(envelope); + if (envelope.data.eventName == desktopExtTelemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT) { + OneDSLogger.contextInfo.orgId = JSON.parse(envelope.data.eventInfo).OrgId; + OneDSLogger.contextInfo.envId = JSON.parse(envelope.data.eventInfo).EnvironmentId; + // TODO: Populate website id + OneDSLogger.contextInfo.websiteId = 'test' + } + envelope.data.measurements = envelope.data.measurement; + envelope.data.timestamp = envelope.time; + envelope.data.sdkVersion = envelope.ext.sdk.ver; } //// Redact Sensitive data for the fields susceptible to contain codes/tokens/keys/secrets etc. From 0e72c5bccfbae8258e744c8ff2b1f35bd4814908 Mon Sep 17 00:00:00 2001 From: Shivika Gupta Date: Tue, 13 Feb 2024 11:51:59 +0530 Subject: [PATCH 4/7] Removing machine id --- src/common/OneDSLoggerTelemetry/oneDSLogger.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts index 65060df6..a1161fff 100644 --- a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts +++ b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts @@ -275,7 +275,6 @@ export class OneDSLogger implements ITelemetryLogger{ envelope.data.clientSessionId = vscode.env.sessionId; envelope.data.vscodeSurface = getExtensionType(); - envelope.data.vscodeMachineId = vscode.env.machineId; envelope.data.vscodeExtensionName = EXTENSION_ID; envelope.data.vscodeExtensionVersion = getExtensionVersion(); envelope.data.vscodeVersion = vscode.version; From 0c7edc91d55f3d76b7400a9a7ac12ec1f599f64a Mon Sep 17 00:00:00 2001 From: Shivika Gupta Date: Tue, 27 Feb 2024 14:24:39 +0530 Subject: [PATCH 5/7] Updating import for event name --- src/common/OneDSLoggerTelemetry/oneDSLogger.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts index 2d6cfe57..6f415d6a 100644 --- a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts +++ b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts @@ -16,6 +16,7 @@ import { EXTENSION_ID } from "../../client/constants"; import {OneDSCollectorEventName} from "./EventContants"; import { telemetryEventNames } from "../../web/client/telemetry/constants"; import { region } from "../telemetry-generated/buildRegionConfiguration"; +import { telemetryEventNames as desktopExtTelemetryEventNames } from "../../client/telemetry/TelemetryEventNames"; interface IInstrumentationSettings { endpointURL: string; From 24a3ee958f391417087051fe0543f91a53d01389 Mon Sep 17 00:00:00 2001 From: Shivika Gupta Date: Mon, 4 Mar 2024 16:32:37 +0530 Subject: [PATCH 6/7] update for attributes - timestamp/measurements/sdkver --- src/common/OneDSLoggerTelemetry/oneDSLogger.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts index 6f415d6a..6af4b25d 100644 --- a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts +++ b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts @@ -275,12 +275,13 @@ export class OneDSLogger implements ITelemetryLogger{ envelope.data.vscodeExtensionVersion = getExtensionVersion(); envelope.data.vscodeVersion = vscode.version; envelope.data.domain = vscode.env.appHost; + envelope.data.measurements = envelope.data.measurement; + envelope.data.timestamp = envelope.time; // Adding below attributes so they get populated in Geneva. // TODO: It needs implementation for populating the actual value envelope.data.eventSubType = "test"; envelope.data.scenarioId = "test"; envelope.data.eventModifier = "test"; - envelope.data.timestamp = "test"; envelope.data.country = "test"; envelope.data.userLocale = "test"; envelope.data.userDataBoundary = "test"; @@ -348,9 +349,6 @@ export class OneDSLogger implements ITelemetryLogger{ // TODO: Populate website id OneDSLogger.contextInfo.websiteId = 'test' } - envelope.data.measurements = envelope.data.measurement; - envelope.data.timestamp = envelope.time; - envelope.data.sdkVersion = envelope.ext.sdk.ver; } //// Redact Sensitive data for the fields susceptible to contain codes/tokens/keys/secrets etc. From 3a856a5b4b3a89b69f758ce8ef7228e8c0bcfe0d Mon Sep 17 00:00:00 2001 From: Shivika Gupta Date: Mon, 4 Mar 2024 17:51:42 +0530 Subject: [PATCH 7/7] Removing timestamp mapping --- src/common/OneDSLoggerTelemetry/oneDSLogger.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts index 6af4b25d..f31df5b1 100644 --- a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts +++ b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts @@ -276,7 +276,6 @@ export class OneDSLogger implements ITelemetryLogger{ envelope.data.vscodeVersion = vscode.version; envelope.data.domain = vscode.env.appHost; envelope.data.measurements = envelope.data.measurement; - envelope.data.timestamp = envelope.time; // Adding below attributes so they get populated in Geneva. // TODO: It needs implementation for populating the actual value envelope.data.eventSubType = "test";