Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching Vscode web telemetry data until we get response from Artemis Service about Geo location #921

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/OneDSLoggerTelemetry/IEventTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface IEvent {
customMeasurements?: IWebExtensionTelemetryData| object; // TODO: Use IPortalTelemetryData
eventSeverity?: SeverityLevel;
correlationId?: string;
errorMessage?:string;
error?:Error;
}

export interface ICustomEvent {
Expand Down
1 change: 1 addition & 0 deletions src/common/OneDSLoggerTelemetry/oneDSLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions src/web/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
Expand Down Expand Up @@ -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<string, string>();

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -702,5 +701,6 @@ function logOneDSLogger(queryParamsMap: Map<string, string>) {
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);
}
29 changes: 21 additions & 8 deletions src/web/client/telemetry/webExtensionTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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<string, string>) {
this._telemetry?.sendTelemetryEvent(eventName, properties);
oneDSLoggerWrapper.getLogger().traceInfo(eventName, properties);
this.pushData1DSLogger(eventName, properties);
}

public sendAPITelemetry(
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}
}
Loading