Skip to content

Commit

Permalink
Populate ContextInfo object values
Browse files Browse the repository at this point in the history
  • Loading branch information
BidishaMS committed Jan 23, 2024
1 parent 556a9c5 commit fed2a21
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/common/OneDSLoggerTelemetry/IEventTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {IProDevCopilotTelemetryData} from '../copilot/telemetry/ITelemetry';
export interface IUserInfo {
oid: string;
tid: string;
puid ?: string;
}

export interface IEvent {
Expand All @@ -34,4 +35,15 @@ export interface ICustomEvent {
exceptionSource?: string;
exceptionCauseCode?: string | number;
exceptionDetails?: string;
}

export interface IContextInfo {
orgId?: string;
portalId?: string;
websiteId?: string;
dataSource?: string;
schema?: string;
correlationId?: string;
referrer? :string;
envId?: string;
}
51 changes: 41 additions & 10 deletions src/common/OneDSLoggerTelemetry/oneDSLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import { AppInsightsCore, type IExtendedConfiguration } from "@microsoft/1ds-core-js";
import { PostChannel, type IChannelConfiguration, type IXHROverride } from "@microsoft/1ds-post-js";
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 { EXTENSION_ID } from "../../client/constants";
import {OneDSCollectorEventName} from "./EventContants";
import { telemetryEventNames } from "../../web/client/telemetry/constants";

interface IInstrumentationSettings {
endpointURL: string;
Expand All @@ -24,6 +26,10 @@ export class OneDSLogger implements ITelemetryLogger{
private readonly appInsightsCore :AppInsightsCore;
private readonly postChannel: PostChannel;

private static userInfo: IUserInfo = {oid: "", tid: "", puid: ""};
private static contextInfo: IContextInfo ;
private static userRegion : string = "";

Check failure on line 31 in src/common/OneDSLoggerTelemetry/oneDSLogger.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Type string trivially inferred from a string literal, remove type annotation

Check failure on line 31 in src/common/OneDSLoggerTelemetry/oneDSLogger.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Type string trivially inferred from a string literal, remove type annotation

Check failure on line 31 in src/common/OneDSLoggerTelemetry/oneDSLogger.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Type string trivially inferred from a string literal, remove type annotation

private readonly regexPatternsToRedact = [
/key["\\ ']*[:=]+["\\ ']*([a-zA-Z0-9]*)/igm,
/token["\\ ']*[:=]+["\\ ']*([a-zA-Z0-9]*)/igm,
Expand Down Expand Up @@ -106,10 +112,24 @@ export class OneDSLogger implements ITelemetryLogger{
if ((coreConfig.instrumentationKey ?? "") !== "") {
this.appInsightsCore.initialize(coreConfig, []);
}
this.intitializeContextInfo();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.appInsightsCore.addTelemetryInitializer(this.populateCommonAttributes());
}

private intitializeContextInfo(){
OneDSLogger.contextInfo = {
orgId: "",
portalId: "",
websiteId: "",
dataSource: "",
schema: "",
correlationId: "",
referrer: "",
envId: ""
}
}

private static getInstrumentationSettings(geo?:string): IInstrumentationSettings {
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
const region:string = "test"; // TODO: Remove it from here and replace it with value getting from build. Check gulp.mjs (setTelemetryTarget)
Expand Down Expand Up @@ -237,14 +257,9 @@ export class OneDSLogger implements ITelemetryLogger{
envelope.data.domain = vscode.env.appHost;
// Adding below attributes so they get populated in Geneva.
// TODO: It needs implementation for populating the actual value
envelope.data.tenantId = "test";
envelope.data.principalObjectId = "test";
envelope.data.puid = "test";
envelope.data.eventSubType = "test";
envelope.data.scenarioId = "test";
envelope.data.eventModifier = "test";
envelope.data.userRegion = "test";
envelope.data.context = "test";
envelope.data.timestamp = "test";
envelope.data.country = "test";
envelope.data.userLocale = "test";
Expand All @@ -257,11 +272,27 @@ export class OneDSLogger implements ITelemetryLogger{
envelope.data.screenResolution = "test";
envelope.data.osName = "test";
envelope.data.osVersion = "test";
// envelope.data.timestamp = envelope.ext.user.locale;
// envelope.data.userLocale = envelope.ext.user.locale;
// envelope.data.userTimeZone = envelope.ext.loc.tz;
// envelope.data.appLanguage = envelope.ext.app.locale;

if (envelope.data.eventName == telemetryEventNames.WEB_EXTENSION_INIT_QUERY_PARAMETERS){
OneDSLogger.userInfo.tid= JSON.parse(envelope.data.eventInfo).tenantId;
OneDSLogger.userRegion = JSON.parse(envelope.data.eventInfo).geo;
OneDSLogger.contextInfo.orgId = JSON.parse(envelope.data.eventInfo).orgId;
OneDSLogger.contextInfo.portalId = JSON.parse(envelope.data.eventInfo).portalId;
OneDSLogger.contextInfo.websiteId = JSON.parse(envelope.data.eventInfo).websiteId;
OneDSLogger.contextInfo.dataSource = JSON.parse(envelope.data.eventInfo).dataSource;
OneDSLogger.contextInfo.schema = JSON.parse(envelope.data.eventInfo).schema;
OneDSLogger.contextInfo.correlationId = JSON.parse(envelope.data.eventInfo).referrerSessionId;
OneDSLogger.contextInfo.referrer = JSON.parse(envelope.data.eventInfo).referrer;
OneDSLogger.contextInfo.envId = JSON.parse(envelope.data.eventInfo).envId;
}
if (envelope.data.eventName == telemetryEventNames.WEB_EXTENSION_DATAVERSE_AUTHENTICATION_COMPLETED){

OneDSLogger.userInfo.oid= JSON.parse(envelope.data.eventInfo).userId;
}
envelope.data.tenantId = OneDSLogger.userInfo?.tid!

Check failure on line 291 in src/common/OneDSLoggerTelemetry/oneDSLogger.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong

Check failure on line 291 in src/common/OneDSLoggerTelemetry/oneDSLogger.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong

Check failure on line 291 in src/common/OneDSLoggerTelemetry/oneDSLogger.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong
envelope.data.principalObjectId = OneDSLogger.userInfo?.oid!

Check failure on line 292 in src/common/OneDSLoggerTelemetry/oneDSLogger.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong

Check failure on line 292 in src/common/OneDSLoggerTelemetry/oneDSLogger.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong

Check failure on line 292 in src/common/OneDSLoggerTelemetry/oneDSLogger.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong
envelope.data.puid = OneDSLogger.userInfo?.puid!

Check failure on line 293 in src/common/OneDSLoggerTelemetry/oneDSLogger.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong

Check failure on line 293 in src/common/OneDSLoggerTelemetry/oneDSLogger.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong

Check failure on line 293 in src/common/OneDSLoggerTelemetry/oneDSLogger.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong
envelope.data.context = JSON.stringify(OneDSLogger.contextInfo);
envelope.data.userRegion = OneDSLogger.userRegion;
// At the end of event enrichment, redact the sensitive data for all the applicable fields
// envelope = this.redactSensitiveDataFromEvent(envelope);
}
Expand Down

0 comments on commit fed2a21

Please sign in to comment.