Skip to content

Commit

Permalink
Update PowerPagesCopilot to initialize EnvId for Desktop extension fl…
Browse files Browse the repository at this point in the history
…ow of copilot; Cleanup web extension Artemis calls (#953)
  • Loading branch information
tyaginidhi authored May 20, 2024
1 parent d8ca537 commit dfe3289
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 29 deletions.
5 changes: 3 additions & 2 deletions src/common/copilot/PowerPagesCopilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let orgID: string;
let environmentName: string;
let activeOrgUrl: string;
let tenantId: string | undefined;
let environmentId: string | undefined;
let environmentId: string;

declare const IS_DESKTOP: string | undefined;
//TODO: Check if it can be converted to singleton
Expand Down Expand Up @@ -393,11 +393,12 @@ export class PowerPagesCopilot implements vscode.WebviewViewProvider {
environmentName = activeOrg.FriendlyName;
userID = activeOrg.UserId;
activeOrgUrl = activeOrg.OrgUrl;
environmentId = activeOrg.EnvironmentId

sessionID = uuidv4(); // Generate a new session ID on org change
sendTelemetryEvent(this.telemetry, { eventName: CopilotOrgChangedEvent, copilotSessionId: sessionID, orgId: orgID });

const intelligenceAPIEndpointInfo = await ArtemisService.getIntelligenceEndpoint(orgID, this.telemetry, sessionID, environmentId ?? '');
const intelligenceAPIEndpointInfo = await ArtemisService.getIntelligenceEndpoint(orgID, this.telemetry, sessionID, environmentId);
this.aibEndpoint = intelligenceAPIEndpointInfo.intelligenceEndpoint;
this.geoName = intelligenceAPIEndpointInfo.geoName;
this.crossGeoDataMovementEnabledPPACFlag = intelligenceAPIEndpointInfo.crossGeoDataMovementEnabledPPACFlag;
Expand Down
36 changes: 10 additions & 26 deletions src/web/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ 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);
const { geoName, geoLongName } = await fetchArtemisData(orgId);
WebExtensionContext.telemetry.sendInfoTelemetry(telemetryEventNames.WEB_EXTENSION_ORG_GEO, { orgId: orgId, orgGeo: geoName });
oneDSLoggerWrapper.instantiate(geoName, geoLongName);

WebExtensionContext.telemetry.sendExtensionInitPathParametersTelemetry(
appName,
Expand Down Expand Up @@ -172,8 +172,6 @@ export function activate(context: vscode.ExtensionContext): void {
context.extensionUri
);
}

await logArtemisTelemetry();
}
break;
default:
Expand Down Expand Up @@ -651,32 +649,18 @@ function isActiveDocument(fileFsPath: string): boolean {
);
}

async function fetchArtemisData(orgId: string): Promise<string> {
async function fetchArtemisData(orgId: string): Promise<IArtemisAPIOrgResponse> {
const artemisResponse = await ArtemisService.fetchArtemisResponse(orgId, WebExtensionContext.telemetry.getTelemetryReporter());
if (artemisResponse === null || artemisResponse.length === 0) {
// Todo: Log in error telemetry. Runtime maintains another table for this kind of failure. We should do the same.
return '';
}

return (artemisResponse[0]?.response as unknown as IArtemisAPIOrgResponse).geoName as string;
}

async function logArtemisTelemetry() {

try {
const orgId = WebExtensionContext.urlParametersMap.get(
queryParameters.ORG_ID
) as string

const geoName = await fetchArtemisData(orgId);
WebExtensionContext.telemetry.sendInfoTelemetry(telemetryEventNames.WEB_EXTENSION_ARTEMIS_RESPONSE,
{ orgId: orgId, geoName: String(geoName) });
} catch (error) {
WebExtensionContext.telemetry.sendErrorTelemetry(
telemetryEventNames.WEB_EXTENSION_ARTEMIS_RESPONSE_FAILED,
logArtemisTelemetry.name,
ARTEMIS_RESPONSE_FAILED);
fetchArtemisData.name,
ARTEMIS_RESPONSE_FAILED
);
return { geo: "", geoLongName: "" } as unknown as IArtemisAPIOrgResponse;
}

return artemisResponse[0]?.response as unknown as IArtemisAPIOrgResponse;
}

function logOneDSLogger(queryParamsMap: Map<string, string>) {
Expand Down
1 change: 0 additions & 1 deletion src/web/client/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export enum telemetryEventNames {
WEB_EXTENSION_FETCH_WORKER_SCRIPT_FAILED = 'webExtensionFetchWorkerScriptFailed',
WEB_EXTENSION_WEB_WORKER_REGISTERED = 'webExtensionWebWorkerRegistered',
WEB_EXTENSION_WEB_WORKER_REGISTRATION_FAILED = 'webExtensionWebWorkerRegistrationFailed',
WEB_EXTENSION_ARTEMIS_RESPONSE = 'webExtensionArtemisResponse',
WEB_EXTENSION_ARTEMIS_RESPONSE_FAILED = 'webExtensionArtemisResponseFailed',
WEB_EXTENSION_FAILED_TO_UPDATE_FOREIGN_KEY_DETAILS = 'webExtensionFailedToUpdateForeignKeyDetails',
WEB_EXTENSION_GRAPH_CLIENT_AUTHENTICATION_FAILED = "WebExtensionGraphClientAuthenticationFailed",
Expand Down

0 comments on commit dfe3289

Please sign in to comment.