From c3dbf6b486810c857c6bda38ff485645553b6c51 Mon Sep 17 00:00:00 2001 From: Bidisha Das Date: Tue, 30 Apr 2024 13:17:47 +0530 Subject: [PATCH 1/3] Caching data until we are aware of Geo --- .../OneDSLoggerTelemetry/IEventTypes.ts | 2 ++ .../oneDSLoggerWrapper.ts | 23 +++++++++++++ src/web/client/extension.ts | 11 ++++--- .../client/telemetry/webExtensionTelemetry.ts | 33 ++++++++++++++----- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/common/OneDSLoggerTelemetry/IEventTypes.ts b/src/common/OneDSLoggerTelemetry/IEventTypes.ts index 2ee615f4..69c79614 100644 --- a/src/common/OneDSLoggerTelemetry/IEventTypes.ts +++ b/src/common/OneDSLoggerTelemetry/IEventTypes.ts @@ -21,6 +21,8 @@ export interface IEvent { customMeasurements?: IWebExtensionTelemetryData| object; // TODO: Use IPortalTelemetryData eventSeverity?: SeverityLevel; correlationId?: string; + errorMessage?:string; + error?:Error; } export interface ICustomEvent { diff --git a/src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts b/src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts index 6a85c269..52cf790d 100644 --- a/src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts +++ b/src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts @@ -5,6 +5,7 @@ import { isCustomTelemetryEnabled } from "../Utils"; import { OneDSLogger } from "./oneDSLogger"; +import { IEvent } from "./IEventTypes"; //// Wrapper class of oneDSLogger for below purposes //// 1. Abstracting code from manual trace log APIs. @@ -13,6 +14,7 @@ import { OneDSLogger } from "./oneDSLogger"; export class oneDSLoggerWrapper { private static instance: oneDSLoggerWrapper; private static oneDSLoggerIntance: OneDSLogger; + private static telemetryCache: IEvent[] = []; private constructor(geo?: string) { oneDSLoggerWrapper.oneDSLoggerIntance = new OneDSLogger(geo); @@ -24,9 +26,30 @@ export class oneDSLoggerWrapper { } static instantiate(geo?: string) { + console.log("Instantiating oneDSLoggerWrapper"); oneDSLoggerWrapper.instance = new oneDSLoggerWrapper(geo); } + static isInstantiated() { + return oneDSLoggerWrapper.instance !== undefined; + } + + static pushToCache(eventName: string, eventInfo?: object, measurement?: object,errorMessage?:string, error?:Error ) { + this.telemetryCache.push({eventName, customDimension: eventInfo, customMeasurements: measurement, errorMessage, error} as IEvent); + } + + static flushCache() { + this.telemetryCache.forEach(event => { + if (event.errorMessage || event.error) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + oneDSLoggerWrapper.oneDSLoggerIntance.traceError(event.eventName, event.errorMessage!,event.error!, event.customMeasurements); + }else{ + oneDSLoggerWrapper.oneDSLoggerIntance.traceInfo(event.eventName, event.customDimension, event.customMeasurements); + } + }); + this.telemetryCache = []; + } + /// Trace info log public traceInfo(eventName: string, eventInfo?: object, measurement?: object) { try { diff --git a/src/web/client/extension.ts b/src/web/client/extension.ts index dba6862d..a970159d 100644 --- a/src/web/client/extension.ts +++ b/src/web/client/extension.ts @@ -38,7 +38,6 @@ import { COPILOT_NOTIFICATION_DISABLED } from "../../common/copilot/constants"; import * as Constants from "./common/constants" import { fetchArtemisResponse } from "../../common/ArtemisService"; import { oneDSLoggerWrapper } from "../../common/OneDSLoggerTelemetry/oneDSLoggerWrapper"; -import { GeoNames } from "../../common/OneDSLoggerTelemetry/telemetryConstants"; import { sendingMessageToWebWorkerForCoPresence } from "./utilities/collaborationUtils"; import {IPortalWebExtensionInitQueryParametersTelemetryData} from "./telemetry/webExtensionTelemetryInterface"; @@ -50,7 +49,6 @@ export function activate(context: vscode.ExtensionContext): void { vscodeExtAppInsightsResourceProvider.GetAppInsightsResourceForDataBoundary( dataBoundary ); - oneDSLoggerWrapper.instantiate(GeoNames.US); WebExtensionContext.setVscodeWorkspaceState(context.workspaceState); WebExtensionContext.telemetry.setTelemetryReporter( context.extension.id, @@ -82,7 +80,6 @@ export function activate(context: vscode.ExtensionContext): void { "microsoft-powerapps-portals.webExtension.init", } ); - const { appName, entity, entityId, searchParams } = args; const queryParamsMap = new Map(); @@ -114,8 +111,11 @@ export function activate(context: vscode.ExtensionContext): void { logOneDSLogger(queryParamsMap); const orgId = queryParamsMap.get(queryParameters.ORG_ID) as string; const orgGeo = await fetchArtemisData(orgId); - WebExtensionContext.telemetry.sendInfoTelemetry(telemetryEventNames.WEB_EXTENSION_ORG_GEO,{orgGeo: orgGeo}); + console.log("in extension instantiating oneDSLoggerWrapper"); oneDSLoggerWrapper.instantiate(orgGeo); + oneDSLoggerWrapper.flushCache(); + WebExtensionContext.telemetry.sendInfoTelemetry(telemetryEventNames.WEB_EXTENSION_ORG_GEO,{orgGeo: orgGeo}); + WebExtensionContext.telemetry.sendExtensionInitPathParametersTelemetry( appName, @@ -682,5 +682,6 @@ function logOneDSLogger (queryParamsMap: Map) { telemetryData.properties.entity = queryParamsMap.get(queryParameters.ENTITY); telemetryData.properties.entityId = queryParamsMap.get(queryParameters.ENTITY_ID); } - oneDSLoggerWrapper.getLogger().traceInfo(telemetryData.eventName, telemetryData.properties); + + WebExtensionContext.telemetry.pushData1DSLogger(telemetryData.eventName, telemetryData.properties); } diff --git a/src/web/client/telemetry/webExtensionTelemetry.ts b/src/web/client/telemetry/webExtensionTelemetry.ts index fe00ad9a..bb891867 100644 --- a/src/web/client/telemetry/webExtensionTelemetry.ts +++ b/src/web/client/telemetry/webExtensionTelemetry.ts @@ -38,7 +38,7 @@ export class WebExtensionTelemetry { } this._telemetry?.sendTelemetryEvent(telemetryData.eventName, telemetryData.properties); - oneDSLoggerWrapper.getLogger().traceInfo(telemetryData.eventName, telemetryData.properties); + this.pushData1DSLogger(telemetryData.eventName, telemetryData.properties); } public sendExtensionInitQueryParametersTelemetry(queryParamsMap: Map) { @@ -68,7 +68,7 @@ export class WebExtensionTelemetry { } this._telemetry?.sendTelemetryEvent(telemetryData.eventName, telemetryData.properties); - oneDSLoggerWrapper.getLogger().traceInfo(telemetryData.eventName, telemetryData.properties); + this.pushData1DSLogger(telemetryData.eventName, telemetryData.properties); } public sendErrorTelemetry(eventName: string, methodName: string, errorMessage?: string, error?: Error) { @@ -87,17 +87,18 @@ export class WebExtensionTelemetry { const error: Error = new Error(errorMessage); this._telemetry?.sendTelemetryException(error, telemetryData.properties); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - oneDSLoggerWrapper.getLogger().traceError(eventName, errorMessage!, error, telemetryData.properties); + oneDSLoggerWrapper.pushToCache(eventName, telemetryData.properties, undefined, errorMessage, error); } else { this._telemetry?.sendTelemetryException(new Error(), telemetryData.properties); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - oneDSLoggerWrapper.getLogger().traceError(eventName, errorMessage!, new Error(), telemetryData.properties); + oneDSLoggerWrapper.pushToCache(eventName, telemetryData.properties, undefined, errorMessage!, new Error()); } } public sendInfoTelemetry(eventName: string, properties?: Record) { this._telemetry?.sendTelemetryEvent(eventName, properties); - oneDSLoggerWrapper.getLogger().traceInfo(eventName, properties); + console.log("sendInfoTelemetry eventName--"+ eventName); + this.pushData1DSLogger(eventName, properties); } public sendAPITelemetry( @@ -132,10 +133,10 @@ export class WebExtensionTelemetry { if (errorMessage) { const error: Error = new Error(errorMessage); this._telemetry?.sendTelemetryException(error, { ...telemetryData.properties, eventName: eventName }, telemetryData.measurements); - oneDSLoggerWrapper.getLogger().traceError(eventName, errorMessage, error, telemetryData.properties, telemetryData.measurements); + this.pushData1DSLogger(eventName, telemetryData.properties, telemetryData.measurements, errorMessage, error); } else { this._telemetry?.sendTelemetryEvent(telemetryData.eventName, telemetryData.properties, telemetryData.measurements); - oneDSLoggerWrapper.getLogger().traceInfo(telemetryData.eventName, telemetryData.properties, telemetryData.measurements); + this.pushData1DSLogger(telemetryData.eventName, telemetryData.properties, telemetryData.measurements); } } @@ -194,10 +195,26 @@ export class WebExtensionTelemetry { } } this._telemetry?.sendTelemetryEvent(telemetryData.eventName, undefined, telemetryData.measurements); - oneDSLoggerWrapper.getLogger().traceInfo(telemetryData.eventName, undefined, telemetryData.measurements); + this.pushData1DSLogger(telemetryData.eventName, undefined, telemetryData.measurements); } private getPathParameterValue(parameter: string | undefined | null): string { return (parameter) ? parameter : ''; } + + public pushData1DSLogger(eventName: string, eventInfo?: object, measurement?: object, errorMessage?: string, error?: Error) { + console.log("pushData1DSLogger instantiated--"+ oneDSLoggerWrapper.isInstantiated()); + console.log("pushData1DSLogger eventName--"+ eventName); + if(!oneDSLoggerWrapper.isInstantiated()) { + oneDSLoggerWrapper.pushToCache(eventName, eventInfo, measurement, errorMessage, error); + return; + } + console.log("pushData1DSLogger after instantiating check--"+ oneDSLoggerWrapper.isInstantiated()); + if (errorMessage || error) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + oneDSLoggerWrapper.getLogger().traceError(eventName, errorMessage!, error!, eventInfo, measurement); + } else { + oneDSLoggerWrapper.getLogger().traceInfo(eventName, eventInfo, measurement); + } + } } From 33b0ba5cc1e4a2826217b306dfd36554a0fe12fb Mon Sep 17 00:00:00 2001 From: Bidisha Das Date: Tue, 30 Apr 2024 13:26:41 +0530 Subject: [PATCH 2/3] Caching data until we are aware of Geo --- src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts | 1 - src/web/client/extension.ts | 1 - src/web/client/telemetry/webExtensionTelemetry.ts | 4 ---- 3 files changed, 6 deletions(-) diff --git a/src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts b/src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts index 52cf790d..4b26e0cd 100644 --- a/src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts +++ b/src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts @@ -26,7 +26,6 @@ export class oneDSLoggerWrapper { } static instantiate(geo?: string) { - console.log("Instantiating oneDSLoggerWrapper"); oneDSLoggerWrapper.instance = new oneDSLoggerWrapper(geo); } diff --git a/src/web/client/extension.ts b/src/web/client/extension.ts index a970159d..364fbf7b 100644 --- a/src/web/client/extension.ts +++ b/src/web/client/extension.ts @@ -111,7 +111,6 @@ export function activate(context: vscode.ExtensionContext): void { logOneDSLogger(queryParamsMap); const orgId = queryParamsMap.get(queryParameters.ORG_ID) as string; const orgGeo = await fetchArtemisData(orgId); - console.log("in extension instantiating oneDSLoggerWrapper"); oneDSLoggerWrapper.instantiate(orgGeo); oneDSLoggerWrapper.flushCache(); WebExtensionContext.telemetry.sendInfoTelemetry(telemetryEventNames.WEB_EXTENSION_ORG_GEO,{orgGeo: orgGeo}); diff --git a/src/web/client/telemetry/webExtensionTelemetry.ts b/src/web/client/telemetry/webExtensionTelemetry.ts index bb891867..fabfc97d 100644 --- a/src/web/client/telemetry/webExtensionTelemetry.ts +++ b/src/web/client/telemetry/webExtensionTelemetry.ts @@ -97,7 +97,6 @@ export class WebExtensionTelemetry { public sendInfoTelemetry(eventName: string, properties?: Record) { this._telemetry?.sendTelemetryEvent(eventName, properties); - console.log("sendInfoTelemetry eventName--"+ eventName); this.pushData1DSLogger(eventName, properties); } @@ -203,13 +202,10 @@ export class WebExtensionTelemetry { } public pushData1DSLogger(eventName: string, eventInfo?: object, measurement?: object, errorMessage?: string, error?: Error) { - console.log("pushData1DSLogger instantiated--"+ oneDSLoggerWrapper.isInstantiated()); - console.log("pushData1DSLogger eventName--"+ eventName); if(!oneDSLoggerWrapper.isInstantiated()) { oneDSLoggerWrapper.pushToCache(eventName, eventInfo, measurement, errorMessage, error); return; } - console.log("pushData1DSLogger after instantiating check--"+ oneDSLoggerWrapper.isInstantiated()); if (errorMessage || error) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion oneDSLoggerWrapper.getLogger().traceError(eventName, errorMessage!, error!, eventInfo, measurement); From ddf3e58e8f70feaac85f88d418bab44c7d9b167c Mon Sep 17 00:00:00 2001 From: Bidisha Das Date: Tue, 14 May 2024 14:13:17 +0530 Subject: [PATCH 3/3] Changes --- 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 c603840b..880e5fdf 100644 --- a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts +++ b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts @@ -273,6 +273,7 @@ export class OneDSLogger implements ITelemetryLogger { envelope.data = envelope.data || {}; // create data nested object if doesn't exist already' envelope.data.clientSessionId = vscode.env.sessionId; + envelope.data.machineId = vscode.env.machineId; envelope.data.vscodeSurface = getExtensionType(); envelope.data.vscodeExtensionName = EXTENSION_ID; envelope.data.vscodeExtensionVersion = getExtensionVersion();