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 Website ID in context for desktop extension #853

Open
wants to merge 2 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: 1 addition & 1 deletion src/client/PortalWebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class PortalWebView {
return html;
}

private static getPortalRootFolder(): vscode.Uri | null {
public static getPortalRootFolder(): vscode.Uri | null {
const fileBeingEdited = vscode.window.activeTextEditor as vscode.TextEditor;
if (fileBeingEdited) {
for (let i = 0; !!(vscode.workspace.workspaceFolders) && (i < vscode.workspace.workspaceFolders?.length); i++) {
Expand Down
50 changes: 31 additions & 19 deletions src/common/OneDSLoggerTelemetry/oneDSLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { ITelemetryLogger } from "./ITelemetryLogger";
import { IContextInfo, IUserInfo } from "./IEventTypes";
import { EventType, Severity } from "./telemetryConstants";
import * as vscode from "vscode";
import {getExtensionType, getExtensionVersion} from "../../common/Utils";
import { getExtensionType, getExtensionVersion, getWebsiteIdFromPACData } from "../../common/Utils";
import { EXTENSION_ID } from "../../client/constants";
import {OneDSCollectorEventName} from "./EventContants";
import { OneDSCollectorEventName } from "./EventContants";
import { telemetryEventNames } from "../../web/client/telemetry/constants";
import { region } from "../telemetry-generated/buildRegionConfiguration";
import { telemetryEventNames as desktopExtTelemetryEventNames } from "../../client/telemetry/TelemetryEventNames";
Expand Down Expand Up @@ -190,11 +190,14 @@ export class OneDSLogger implements ITelemetryLogger{
return instrumentationSettings;
}

/// Trace info log
public traceInfo(eventName:string, eventInfo?:object, measurement?: object) {
const event = {
name: OneDSCollectorEventName.VSCODE_EVENT,
data: {
/// Trace info log
public async traceInfo(eventName: string, eventInfo?: object, measurement?: object) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't make traceInfo as async. Neither putting this kind of condition is generic. This method should be as simple as calling 1DSLogger.

Copy link
Contributor Author

@gshivi gshivi Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading website Id from pac data is an async operation. This can't be put in method populateCommonAttributes function - as this function is itself returning a function & it can't be async by definition - else gives error.

As the requirement is - for every trace being logged websiteId for the activeEditor needs to be logged. This can't be a one time-thing. Will sync offline more on this.

if (getExtensionType() == 'Desktop') {
OneDSLogger.contextInfo.websiteId = await getWebsiteIdFromPACData();
}
const event = {
name: OneDSCollectorEventName.VSCODE_EVENT,
data: {
eventName: eventName,
eventType: EventType.TRACE,
severity: Severity.INFO,
Expand All @@ -206,11 +209,14 @@ export class OneDSLogger implements ITelemetryLogger{
this.appInsightsCore.track(event);
}

/// Trace warning log
public traceWarning(eventName:string, eventInfo?: object, measurement?: object) {
const event = {
name: OneDSCollectorEventName.VSCODE_EVENT,
data: {
/// Trace warning log
public async traceWarning(eventName: string, eventInfo?: object, measurement?: object) {
if (getExtensionType() == 'Desktop') {
OneDSLogger.contextInfo.websiteId = await getWebsiteIdFromPACData();
}
const event = {
name: OneDSCollectorEventName.VSCODE_EVENT,
data: {
eventName: eventName,
eventType: EventType.TRACE,
severity: Severity.WARN,
Expand All @@ -223,10 +229,14 @@ export class OneDSLogger implements ITelemetryLogger{
}

// Trace error log
public traceError(eventName: string, errorMessage: string, exception: Error, eventInfo?:object, measurement?: object) {
const event = {
name: OneDSCollectorEventName.VSCODE_EVENT,
data: {
public async traceError(eventName: string, errorMessage: string, exception: Error, eventInfo?: object, measurement?: object) {
if (getExtensionType() == 'Desktop') {
OneDSLogger.contextInfo.websiteId = await getWebsiteIdFromPACData();
}

const event = {
name: OneDSCollectorEventName.VSCODE_EVENT,
data: {
eventName: eventName,
eventType: EventType.TRACE,
severity: Severity.ERROR,
Expand All @@ -240,12 +250,14 @@ export class OneDSLogger implements ITelemetryLogger{
this.appInsightsCore.track(event);
}

public featureUsage(
public async featureUsage(
featureName: string,
eventName: string,
customDimensions?: object
) {

) {
if (getExtensionType() == 'Desktop') {
OneDSLogger.contextInfo.websiteId = await getWebsiteIdFromPACData();
}
const event = {
name: OneDSCollectorEventName.VSCODE_EVENT,
data: {
Expand Down
16 changes: 16 additions & 0 deletions src/common/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import * as vscode from "vscode";
import { EXTENSION_ID, SETTINGS_EXPERIMENTAL_STORE_NAME } from "../client/constants";
import { CUSTOM_TELEMETRY_FOR_POWER_PAGES_SETTING_NAME } from "./OneDSLoggerTelemetry/telemetryConstants";
import { PortalWebView } from "../client/PortalWebView";

export function getSelectedCode(editor: vscode.TextEditor): string {
if (!editor) {
Expand Down Expand Up @@ -123,3 +124,18 @@ export function isCustomTelemetryEnabled():boolean {
.get(CUSTOM_TELEMETRY_FOR_POWER_PAGES_SETTING_NAME);
return isCustomTelemetryEnabled as boolean;
}

export const getWebsiteIdFromPACData = async (): Promise<string> => {
const rootFolder = PortalWebView.getPortalRootFolder();
if (!rootFolder) return '';
const l = rootFolder?.with({ path: rootFolder.path + "/.portalconfig/websitebinding.yml" });
const websiteBindingYmlContent = new TextDecoder().decode(await vscode.workspace.fs.readFile(l));
const regex = /adx_websitebindingid:\s*([^\s]+)/i;
// Use the regular expression to find a match in the fileContent
const match = regex.exec(websiteBindingYmlContent);
// If a match is found, return the value of adx_websitebindingid
if (match && match[1]) {
return match[1];
}
return '';
}
Loading