From f21aefa0463732582604ee62e71882bba0a48f63 Mon Sep 17 00:00:00 2001 From: gshivi <123095952+gshivi@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:15:01 +0530 Subject: [PATCH] Log AadObjectId for desktop extension telemetry (#1009) * Changed for AAD Id * Updates * Removing extra line * change * Adding null check --------- Co-authored-by: Shivika Gupta --- src/client/extension.ts | 13 ++++++++++++- src/client/pac/PacTypes.ts | 7 +++++++ src/client/pac/PacWrapper.ts | 6 +++++- src/common/OneDSLoggerTelemetry/oneDSLogger.ts | 1 + .../OneDSLoggerTelemetry/telemetryConstants.ts | 2 ++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/client/extension.ts b/src/client/extension.ts index 3997797e..df44d599 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -41,6 +41,8 @@ import { desktopTelemetryEventNames } from "../common/OneDSLoggerTelemetry/clien import { ArtemisService } from "../common/services/ArtemisService"; import { workspaceContainsPortalConfigFolder } from "../common/utilities/PathFinderUtil"; import { getPortalsOrgURLs } from "../common/utilities/WorkspaceInfoFinderUtil"; +import { SUCCESS } from "../common/constants"; +import { AadIdKey } from "../common/OneDSLoggerTelemetry/telemetryConstants"; let client: LanguageClient; let _context: vscode.ExtensionContext; @@ -191,9 +193,18 @@ export async function activate( const orgID = orgDetails.OrgId; const artemisResponse = await ArtemisService.getArtemisResponse(orgID, _telemetry, ""); if (artemisResponse !== null && artemisResponse.response !== null) { + const pacActiveAuth = await pacTerminal.getWrapper()?.activeAuth(); + let AadIdObject; + if ((pacActiveAuth && pacActiveAuth.Status === SUCCESS)) { + AadIdObject = pacActiveAuth.Results?.filter(obj => obj.Key === AadIdKey); + } const { geoName, geoLongName } = artemisResponse.response; oneDSLoggerWrapper.instantiate(geoName, geoLongName); - oneDSLoggerWrapper.getLogger().traceInfo(desktopTelemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT, { ...orgDetails, orgGeo: geoName }); + let initContext: object = { ...orgDetails, orgGeo: geoName }; + if (AadIdObject?.[0]?.Value) { + initContext = { ...initContext, AadId: AadIdObject[0].Value } + } + oneDSLoggerWrapper.getLogger().traceInfo(desktopTelemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT, initContext); } }) ); diff --git a/src/client/pac/PacTypes.ts b/src/client/pac/PacTypes.ts index b4960914..d18e62b6 100644 --- a/src/client/pac/PacTypes.ts +++ b/src/client/pac/PacTypes.ts @@ -73,3 +73,10 @@ export type ActiveOrgOutput = { } export type PacOrgWhoOutput = PacOutputWithResult; + +export type ActiveAuthOutput = { + Key: string, + Value: string +} + +export type PacAuthWhoOutput = PacOutputWithResultList; diff --git a/src/client/pac/PacWrapper.ts b/src/client/pac/PacWrapper.ts index 2fd655bb..884b2503 100644 --- a/src/client/pac/PacWrapper.ts +++ b/src/client/pac/PacWrapper.ts @@ -10,7 +10,7 @@ import * as fs from "fs-extra"; import { ChildProcessWithoutNullStreams, spawn } from "child_process"; import { BlockingQueue } from "../../common/utilities/BlockingQueue"; import { ITelemetry } from "../../common/OneDSLoggerTelemetry/telemetry/ITelemetry"; -import { PacOutput, PacAdminListOutput, PacAuthListOutput, PacSolutionListOutput, PacOrgListOutput, PacOrgWhoOutput } from "./PacTypes"; +import { PacOutput, PacAdminListOutput, PacAuthListOutput, PacSolutionListOutput, PacOrgListOutput, PacOrgWhoOutput, PacAuthWhoOutput } from "./PacTypes"; import { v4 } from "uuid"; import { oneDSLoggerWrapper } from "../../common/OneDSLoggerTelemetry/oneDSLoggerWrapper"; @@ -168,6 +168,10 @@ export class PacWrapper { return this.executeCommandAndParseResults(new PacArguments("org", "who")); } + public async activeAuth(): Promise { + return this.executeCommandAndParseResults(new PacArguments("auth", "who")); + } + public async pcfInit(outputDirectory: string): Promise { return this.executeCommandAndParseResults(new PacArguments("pcf", "init", "--outputDirectory", outputDirectory)); } diff --git a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts index 4eb69d43..0402ea8a 100644 --- a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts +++ b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts @@ -380,6 +380,7 @@ export class OneDSLogger implements ITelemetryLogger { OneDSLogger.contextInfo.orgId = JSON.parse(envelope.data.eventInfo).OrgId; OneDSLogger.contextInfo.envId = JSON.parse(envelope.data.eventInfo).EnvironmentId; OneDSLogger.contextInfo.orgGeo = JSON.parse(envelope.data.eventInfo).orgGeo; + OneDSLogger.userInfo.oid = JSON.parse(envelope.data.eventInfo).AadId; // TODO: Populate website id OneDSLogger.contextInfo.websiteId = 'test' } diff --git a/src/common/OneDSLoggerTelemetry/telemetryConstants.ts b/src/common/OneDSLoggerTelemetry/telemetryConstants.ts index 9e934e65..eab9ad97 100644 --- a/src/common/OneDSLoggerTelemetry/telemetryConstants.ts +++ b/src/common/OneDSLoggerTelemetry/telemetryConstants.ts @@ -38,3 +38,5 @@ export enum GeoNames { } // Custom telemetry feature flag export const CUSTOM_TELEMETRY_FOR_POWER_PAGES_SETTING_NAME = 'enableTelemetry'; + +export const AadIdKey= 'Entra ID Object Id:'; \ No newline at end of file