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/oneDSLogger.ts b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts index 6ede8564..6ff0519a 100644 --- a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts +++ b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts @@ -296,6 +296,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(); diff --git a/src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts b/src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts index 47c034e9..5ae879cb 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, geoLongName?: string) { oneDSLoggerWrapper.oneDSLoggerIntance = new OneDSLogger(geo, geoLongName); @@ -27,6 +29,26 @@ export class oneDSLoggerWrapper { oneDSLoggerWrapper.instance = new oneDSLoggerWrapper(geo, geoLongName); } + 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 168d6ac4..db3ef8ee 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 { ECSFeaturesClient } from "../../common/ecs-features/ecsFeatureClient"; import { PowerPagesAppName, PowerPagesClientName } from "../../common/ecs-features/constants"; @@ -52,7 +51,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, @@ -84,7 +82,6 @@ export function activate(context: vscode.ExtensionContext): void { "microsoft-powerapps-portals.webExtension.init", } ); - const { appName, entity, entityId, searchParams } = args; const queryParamsMap = new Map(); @@ -116,8 +113,10 @@ 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 }); oneDSLoggerWrapper.instantiate(orgGeo); + oneDSLoggerWrapper.flushCache(); + WebExtensionContext.telemetry.sendInfoTelemetry(telemetryEventNames.WEB_EXTENSION_ORG_GEO,{orgGeo: orgGeo}); + WebExtensionContext.telemetry.sendExtensionInitPathParametersTelemetry( appName, @@ -702,5 +701,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..fabfc97d 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,17 @@ 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); + this.pushData1DSLogger(eventName, properties); } public sendAPITelemetry( @@ -132,10 +132,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 +194,23 @@ 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) { + if(!oneDSLoggerWrapper.isInstantiated()) { + oneDSLoggerWrapper.pushToCache(eventName, eventInfo, measurement, errorMessage, error); + return; + } + 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); + } + } }