Skip to content

Commit

Permalink
adding telemetry and moving api path in constant
Browse files Browse the repository at this point in the history
  • Loading branch information
ritikramuka committed Oct 30, 2023
1 parent 1e6e2bf commit 231efe4
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 61 deletions.
54 changes: 28 additions & 26 deletions src/web/client/WebExtensionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,7 @@ class WebExtensionContext implements IWebExtensionContext {
const headers = getCommonHeaders(this._dataverseAccessToken);

// Populate shared workspace for Co-Presence
try {
await this.populateSharedworkspace(headers, dataverseOrgUrl, websiteid);
this.telemetry.sendInfoTelemetry(
telemetryEventNames.WEB_EXTENSION_POPULATE_SHARED_WORKSPACE_SUCCESS
);
} catch (error) {
this.telemetry.sendErrorTelemetry(
telemetryEventNames.WEB_EXTENSION_POPULATE_SHARED_WORKSPACE_SYSTEM_ERROR,
this.populateSharedworkspace.name,
(error as Error)?.message,
error as Error
);
}
await this.populateSharedworkspace(headers, dataverseOrgUrl, websiteid);
}

public async dataverseAuthentication(firstTimeAuth = false) {
Expand Down Expand Up @@ -718,21 +706,35 @@ class WebExtensionContext implements IWebExtensionContext {
dataverseOrgUrl: string,
websiteid: string
) {
const sharedworkspace = await getOrCreateSharedWorkspace({
headers,
dataverseOrgUrl,
websiteid,
});

const sharedWorkSpaceParamsMap = new Map<string, string>();
for (const key in sharedworkspace) {
sharedWorkSpaceParamsMap.set(
String(key).trim().toLocaleLowerCase(),
String(sharedworkspace[key]).trim()
try {
const sharedworkspace = await getOrCreateSharedWorkspace({
headers,
dataverseOrgUrl,
websiteid,
});

const sharedWorkSpaceParamsMap = new Map<string, string>();
for (const key in sharedworkspace) {
sharedWorkSpaceParamsMap.set(
String(key).trim().toLocaleLowerCase(),
String(sharedworkspace[key]).trim()
);
}

this._sharedWorkSpaceMap = sharedWorkSpaceParamsMap;

this.telemetry.sendInfoTelemetry(
telemetryEventNames.WEB_EXTENSION_POPULATE_SHARED_WORKSPACE_SUCCESS,
{ count: this._sharedWorkSpaceMap.size.toString() }
);
} catch (error) {
this.telemetry.sendErrorTelemetry(
telemetryEventNames.WEB_EXTENSION_POPULATE_SHARED_WORKSPACE_SYSTEM_ERROR,
this.populateSharedworkspace.name,
(error as Error)?.message,
error as Error
);
}

this._sharedWorkSpaceMap = sharedWorkSpaceParamsMap;
}

public async updateConnectedUsersInContext(
Expand Down
2 changes: 2 additions & 0 deletions src/web/client/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export const MULTI_FILE_FEATURE_SETTING_NAME = "enableMultiFileFeature";
export const CO_PRESENCE_FEATURE_SETTING_NAME = "enableCoPresenceFeature";

// Co-presence constants
export const GET_OR_CREATE_SHARED_WORK_SPACE = "/api/data/v9.2/GetOrCreateSharedWorkspace";

export enum sharedWorkspaceParameters {
SHAREWORKSPACE_ID = "sharedworkspaceid",
TENANT_ID = "tenantid",
Expand Down
78 changes: 44 additions & 34 deletions src/web/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,47 +302,57 @@ export function processWillStartCollaboartion(context: vscode.ExtensionContext)
export function createWebWorkerInstance(
context: vscode.ExtensionContext
) {
const webworkerMain = vscode.Uri.joinPath(
context.extensionUri,
"dist",
"web",
"webworker.worker.js"
);
try {
const webworkerMain = vscode.Uri.joinPath(
context.extensionUri,
"dist",
"web",
"webworker.worker.js"
);

const workerUrl = new URL(webworkerMain.toString());
const workerUrl = new URL(webworkerMain.toString());

WebExtensionContext.getWorkerScript(workerUrl)
.then((workerScript) => {
const workerBlob = new Blob([workerScript], {
type: "application/javascript",
});
WebExtensionContext.getWorkerScript(workerUrl)
.then((workerScript) => {
const workerBlob = new Blob([workerScript], {
type: "application/javascript",
});

const urlObj = URL.createObjectURL(workerBlob);
const urlObj = URL.createObjectURL(workerBlob);

WebExtensionContext.setWorker(new Worker(urlObj));
WebExtensionContext.setWorker(new Worker(urlObj));

if (WebExtensionContext.worker !== undefined) {
WebExtensionContext.worker.onmessage = (event) => {
const { data } = event;
if (WebExtensionContext.worker !== undefined) {
WebExtensionContext.worker.onmessage = (event) => {
const { data } = event;

WebExtensionContext.containerId = event.data.containerId;
WebExtensionContext.containerId = event.data.containerId;

if (data.type === Constants.workerEventMessages.REMOVE_CONNECTED_USER) {
WebExtensionContext.removeConnectedUserInContext(
data.userId
);
}
if (data.type === Constants.workerEventMessages.UPDATE_CONNECTED_USERS) {
WebExtensionContext.updateConnectedUsersInContext(
data.containerId,
data.userName,
data.userId,
data.entityId
);
}
};
}
});
if (data.type === Constants.workerEventMessages.REMOVE_CONNECTED_USER) {
WebExtensionContext.removeConnectedUserInContext(
data.userId
);
}
if (data.type === Constants.workerEventMessages.UPDATE_CONNECTED_USERS) {
WebExtensionContext.updateConnectedUsersInContext(
data.containerId,
data.userName,
data.userId,
data.entityId
);
}
};
}
})

WebExtensionContext.telemetry.sendInfoTelemetry(telemetryEventNames.WEB_EXTENSION_WEB_WORKER_REGISTERED);
} catch(error) {
WebExtensionContext.telemetry.sendErrorTelemetry(
telemetryEventNames.WEB_EXTENSION_WEB_WORKER_REGISTRATION_FAILED,
createWebWorkerInstance.name,
(error as Error)?.message,
error as Error);
}
}

export async function showSiteVisibilityDialog() {
Expand Down
2 changes: 2 additions & 0 deletions src/web/client/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,6 @@ export enum telemetryEventNames {
WEB_EXTENSION_FETCH_WORKER_SCRIPT = 'webExtensionFetchWorkerScript',
WEB_EXTENSION_FETCH_WORKER_SCRIPT_SUCCESS = 'webExtensionFetchWorkerScriptSuccess',
WEB_EXTENSION_FETCH_WORKER_SCRIPT_FAILED = 'webExtensionFetchWorkerScriptFailed',
WEB_EXTENSION_WEB_WORKER_REGISTERED = 'webExtensionWebWorkerRegistered',
WEB_EXTENSION_WEB_WORKER_REGISTRATION_FAILED = 'webExtensionWebWorkerRegistrationFailed',
}
5 changes: 4 additions & 1 deletion src/web/client/utilities/urlBuilderUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getAttributePath, getEntity, getEntityFetchQuery } from "./schemaHelper
import { getWorkSpaceName } from "./commonUtil";
import * as Constants from "../common/constants";
import { telemetryEventNames } from "../telemetry/constants";
import path from "path";

export const getParameterizedRequestUrlTemplate = (
useSingleEntityUrl: boolean
Expand Down Expand Up @@ -250,7 +251,9 @@ export function isWebFileWithLazyLoad(fsPath: string): boolean {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export async function getOrCreateSharedWorkspace(config: any) {
let requestSentAtTime = new Date().getTime();
const requestUrl = `${config.dataverseOrgUrl}/api/data/v9.2/GetOrCreateSharedWorkspace`;
const requestUrl = path.join(config.dataverseOrgUrl, Constants.GET_OR_CREATE_SHARED_WORK_SPACE);

console.log("requestUrl: ", requestUrl);

try {
WebExtensionContext.telemetry.sendAPITelemetry(
Expand Down

0 comments on commit 231efe4

Please sign in to comment.