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

Populate attributes for desktop extension telemetry #832

Merged
merged 11 commits into from
Mar 5, 2024
47 changes: 44 additions & 3 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ import { disposeDiagnostics } from "./power-pages/validationDiagnostics";
import { bootstrapDiff } from "./power-pages/bootstrapdiff/BootstrapDiff";
import { CopilotNotificationShown } from "../common/copilot/telemetry/telemetryConstants";
import { copilotNotificationPanel, disposeNotificationPanel } from "../common/copilot/welcome-notification/CopilotNotificationPanel";
import { COPILOT_NOTIFICATION_DISABLED } from "../common/copilot/constants";
import { COPILOT_NOTIFICATION_DISABLED, PAC_SUCCESS } from "../common/copilot/constants";
import { PacInterop, PacWrapper } from "./pac/PacWrapper";
import { PacWrapperContext } from "./pac/PacWrapperContext";
import { fetchArtemisResponse } from "../common/ArtemisService";
import { oneDSLoggerWrapper } from "../common/OneDSLoggerTelemetry/oneDSLoggerWrapper";
import { GetAuthProfileWatchPattern } from "./lib/AuthPanelView";
import { telemetryEventNames } from "./telemetry/TelemetryEventNames";

let client: LanguageClient;
let _context: vscode.ExtensionContext;
Expand All @@ -61,6 +67,9 @@ export async function activate(
appInsightsResource.instrumentationKey
);
context.subscriptions.push(_telemetry);
// TODO: Need to decide on data residency part on unauthenticated scenario
oneDSLoggerWrapper.instantiate("us");

_telemetry.sendTelemetryEvent("Start", {
"pac.userId": readUserSettings().uniqueId,
});
Expand Down Expand Up @@ -173,8 +182,13 @@ export async function activate(
telemetryData = JSON.stringify(listOfActivePortals);
_telemetry.sendTelemetryEvent("VscodeDesktopUsage", { listOfActivePortals: telemetryData, countOfActivePortals: listOfActivePortals.length.toString() });
} catch (exception) {
_telemetry.sendTelemetryException(exception as Error, { eventName: 'VscodeDesktopUsage' });
const exceptionError = exception as Error;
_telemetry.sendTelemetryException(exceptionError, { eventName: 'VscodeDesktopUsage' });
}

handleOrgChange();
setupAuthFileWatcher();

_telemetry.sendTelemetryEvent("PowerPagesWebsiteYmlExists"); // Capture's PowerPages Users
vscode.commands.executeCommand('setContext', 'powerpages.websiteYmlExists', true);
initializeGenerator(_context, cliContext, _telemetry); // Showing the create command only if website.yml exists
Expand All @@ -192,13 +206,40 @@ export async function activate(
}

_telemetry.sendTelemetryEvent("activated");
}

export function setupAuthFileWatcher() {
const watchPath = GetAuthProfileWatchPattern();
if (watchPath) {
const watcher = vscode.workspace.createFileSystemWatcher(watchPath);
watcher.onDidChange(() => handleOrgChange());
watcher.onDidCreate(() => handleOrgChange());
watcher.onDidDelete(() => handleOrgChange());
}
}

async function handleOrgChange() {
const cliContext = new CliAcquisitionContext(_context, _telemetry);
const cli = new CliAcquisition(cliContext);
const cliPath = await cli.ensureInstalled();
const pacContext = new PacWrapperContext(_context, _telemetry);
const interop = new PacInterop(pacContext, cliPath);
const pacWrapper = new PacWrapper(pacContext, interop);
const pacActiveOrg = await pacWrapper?.activeOrg();
if (pacActiveOrg && pacActiveOrg.Status === PAC_SUCCESS) {
const orgID = pacActiveOrg.Results.OrgId;
const artemisResponse = await fetchArtemisResponse(orgID, _telemetry);
if (artemisResponse) {
const { geoName } = artemisResponse[0];
oneDSLoggerWrapper.instantiate(geoName);
oneDSLoggerWrapper.getLogger().traceInfo(telemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT, pacActiveOrg.Results);
}
}
gshivi marked this conversation as resolved.
Show resolved Hide resolved
}

export async function deactivate(): Promise<void> {
if (_telemetry) {
_telemetry.sendTelemetryEvent("End");

// dispose() will flush any events not sent
// Note, while dispose() returns a promise, we don't await it so that we can unblock the rest of unloading logic
_telemetry.dispose();
Expand Down
9 changes: 9 additions & 0 deletions src/client/telemetry/TelemetryEventNames.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

export enum telemetryEventNames {
gshivi marked this conversation as resolved.
Show resolved Hide resolved
DESKTOP_EXTENSION_INIT_CONTEXT = "DesktopExtensionInitContext",

}
12 changes: 10 additions & 2 deletions src/common/OneDSLoggerTelemetry/oneDSLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {OneDSCollectorEventName} from "./EventContants";
import { telemetryEventNames } from "../../web/client/telemetry/constants";
import { region } from "../telemetry-generated/buildRegionConfiguration";
import { geoMappingsToAzureRegion } from "./shortNameMappingToAzureRegion";
import { telemetryEventNames as desktopExtTelemetryEventNames } from "../../client/telemetry/TelemetryEventNames";

interface IInstrumentationSettings {
endpointURL: string;
Expand Down Expand Up @@ -345,8 +346,15 @@ export class OneDSLogger implements ITelemetryLogger{

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private populateVscodeDesktopAttributes(envelope: any){
// TODO: this method helps in populating desktop attributes.
console.log(envelope);
if (envelope.data.eventName == desktopExtTelemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT) {
OneDSLogger.contextInfo.orgId = JSON.parse(envelope.data.eventInfo).OrgId;
OneDSLogger.contextInfo.envId = JSON.parse(envelope.data.eventInfo).EnvironmentId;
// TODO: Populate website id
gshivi marked this conversation as resolved.
Show resolved Hide resolved
OneDSLogger.contextInfo.websiteId = 'test'
gshivi marked this conversation as resolved.
Show resolved Hide resolved
}
envelope.data.measurements = envelope.data.measurement;
envelope.data.timestamp = envelope.time;
gshivi marked this conversation as resolved.
Show resolved Hide resolved
envelope.data.sdkVersion = envelope.ext.sdk.ver;
gshivi marked this conversation as resolved.
Show resolved Hide resolved
}

//// Redact Sensitive data for the fields susceptible to contain codes/tokens/keys/secrets etc.
Expand Down
Loading