Skip to content

Commit

Permalink
Populate Vscode extension data in common attribute and modifying few …
Browse files Browse the repository at this point in the history
…APIs of ITelemetry interface (#811)

* First cut of telemetry

* First cut of telemetry

* changes in 1DSCollector

* renamed from collector to logger

* merged to remote

* Added wrapper

* consumed in client

* added types

* changes

* Created common interfaces and wrapper

* reverted back changes

* removed blank line

* removed blank line

* removed blank line

* populate data

* Removed platformType

* Removed platformType

* changes

* changes

* changes

* revert this changes

* revert this changes
  • Loading branch information
BidishaMS authored Jan 17, 2024
1 parent 099226f commit cfc45d3
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 36 deletions.
124 changes: 101 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1066,12 +1066,16 @@
"webpack": "^5.76.0",
"webpack-cli": "^4.7.0",
"webpack-stream": "^7.0.0",
"yargs": "^16.2.0"
"yargs": "^16.2.0",
"@microsoft/1ds-core-js": "4.0.5",
"@microsoft/1ds-post-js": "4.0.5"
},
"dependencies": {
"@fluidframework/azure-client": "^1.1.1",
"@microsoft/generator-powerpages": "1.21.19",
"@types/jwt-decode": "2.2.0",
"@microsoft/1ds-core-js": "4.0.5",
"@microsoft/1ds-post-js": "4.0.5",
"@types/node-fetch": "^2.6.2",
"@vscode/extension-telemetry": "^0.6.2",
"cockatiel": "^3.1.1",
Expand Down
4 changes: 4 additions & 0 deletions src/common/OneDSLoggerTelemetry/EventContants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ export enum CustomType {
*/
Scenario = 'Scenario',

}

export enum EventTableName {
CUSTOM_EVENT = 'CustomEvent',
}
7 changes: 6 additions & 1 deletion src/common/OneDSLoggerTelemetry/ITelemetryLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ traceWarning(eventName:string, customDimension?:Record<string, string>, customMe
* Send error telemetry event
* @param eventName - Event to send
*/
traceError(eventName: string, customDimension?:Record<string, string>, customMeasurement?: Record<string, number>, exceptionMessage?:string, exceptionSource?:string, exceptionDetails?:string) : void
traceError(eventName: string, error?:Error, customDimension?:Record<string, string>, customMeasurement?: Record<string, number>, exceptionMessage?:string, exceptionSource?:string, exceptionDetails?:string) : void
/**
* Send featureName and eventName telemetry event
* @param eventName - Event to send
*/
featureUsage(featureName: string, eventName: string, customDimensions?: Record<string, string>) : void
}
70 changes: 61 additions & 9 deletions src/common/OneDSLoggerTelemetry/oneDSLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { AppInsightsCore, type IExtendedConfiguration } from "@microsoft/1ds-cor
import { PostChannel, type IChannelConfiguration, type IXHROverride } from "@microsoft/1ds-post-js";
import { ITelemetryLogger } from "./ITelemetryLogger";
import { EventType } from "./telemetryConstants";
import * as vscode from "vscode";
import {getExtensionType, getExtensionVersion} from "../../common/Utils";
import { EXTENSION_ID } from "../../client/constants";
import {EventTableName} from "./EventContants";

interface IInstrumentationSettings {
endpointURL: string;
Expand All @@ -15,8 +19,9 @@ interface IInstrumentationSettings {

export class OneDSLogger implements ITelemetryLogger{

private readonly appInsightsCore = new AppInsightsCore();
private readonly postChannel: PostChannel = new PostChannel();
private readonly appInsightsCore :AppInsightsCore;
private readonly postChannel: PostChannel;



private readonly fetchHttpXHROverride: IXHROverride = {
Expand Down Expand Up @@ -65,6 +70,9 @@ export class OneDSLogger implements ITelemetryLogger{

public constructor(geo?:string ) {

this.appInsightsCore = new AppInsightsCore();
this.postChannel = new PostChannel();

const channelConfig: IChannelConfiguration = {
alwaysUseXhrOverride: true,
httpXHROverride: this.fetchHttpXHROverride,
Expand All @@ -86,11 +94,16 @@ export class OneDSLogger implements ITelemetryLogger{
extensionConfig: {
[this.postChannel.identifier]: channelConfig,
},

};

if ((coreConfig.instrumentationKey ?? "") !== "") {
this.appInsightsCore.initialize(coreConfig, []);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.appInsightsCore.addTelemetryInitializer((envelope: any) => {
OneDSLogger.populateCommonAttributes(envelope);
});
}

private static getInstrumentationSettings(geo?:string): IInstrumentationSettings {
Expand Down Expand Up @@ -135,10 +148,10 @@ export class OneDSLogger implements ITelemetryLogger{
/// Trace info log
public traceInfo(eventName:string, customDimension?:Record<string, string>, customMeasurement?: Record<string, number>, message?:string) {
const event = {
name: "CustomEvent",
name: EventTableName.CUSTOM_EVENT,
data: {
eventName: eventName,
eventType: EventType.INFO,
eventType: EventType.INFO,
message: message,
customDimension: customDimension,
customMeasurement: customMeasurement
Expand All @@ -151,7 +164,7 @@ export class OneDSLogger implements ITelemetryLogger{
/// Trace warning log
public traceWarning(eventName:string, customDimension?:Record<string, string>, customMeasurement?: Record<string, number>, message?:string) {
const event = {
name: "CustomEvent",
name: EventTableName.CUSTOM_EVENT,
data: {
eventName: eventName,
eventType: EventType.WARNING,
Expand All @@ -165,20 +178,59 @@ export class OneDSLogger implements ITelemetryLogger{
}

// Trace error log
public traceError(eventName: string, customDimension?:Record<string, string>, customMeasurement?: Record<string, number>, exceptionMessage?:string, exceptionSource?:string, exceptionDetails?:string) {
public traceError(eventName: string, error?:Error, customDimension?:Record<string, string>, customMeasurement?: Record<string, number>, exceptionMessage?:string, exceptionSource?:string, exceptionDetails?:string) {
const event = {
name: "CustomEvent",
name: EventTableName.CUSTOM_EVENT,
data: {
eventName: eventName,
eventType: EventType.ERROR,
exceptionMessage: exceptionMessage,
exceptionMessage: error?.message,
exceptionDetails: exceptionDetails,
exceptionSource: exceptionSource,
customDimension: customDimension,
customMeasurement: customMeasurement
}
};
this.appInsightsCore.track(event);
}

this.appInsightsCore.track(event);
public featureUsage(
featureName: string,
eventName: string,
customDimensions?: object
) {

const event = {
name: EventTableName.CUSTOM_EVENT,
data: {
eventName: 'Portal_Metrics_Event',
eventType: EventType.INFO,
eventInfo: JSON.stringify({
featureName: featureName,
customDimensions: customDimensions,
eventName: eventName
})
}
};
this.appInsightsCore.track(event);
}

/// Populate attributes that are common to all events
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private static populateCommonAttributes(envelope: any) {
envelope.data = envelope.data || {}; // create data nested object if doesn't exist already'

envelope.data.SessionId = vscode.env.sessionId;
envelope.data.surface = getExtensionType();
envelope.data.extensionVersion = getExtensionVersion();
envelope.data.extensionName = EXTENSION_ID;
envelope.data.dataDomain = vscode.env.appHost;
envelope.data.cloudRoleName = vscode.env.appName;
envelope.data.vscodeVersion = vscode.version;
envelope.data.vscodeMachineId = vscode.env.machineId
}

public flushAndTeardown(): void {
this.appInsightsCore.flush();
}
}
13 changes: 11 additions & 2 deletions src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,18 @@ export class oneDSLoggerWrapper {
}

/// Trace exception log
public traceError(eventName:string, customDimension?:Record<string, string>, customMeasurement?: Record<string, number>, message?:string) {
public traceError(eventName:string, error?:Error, customDimension?:Record<string, string>, customMeasurement?: Record<string, number>, message?:string) {
try{
oneDSLoggerWrapper.oneDSLoggerIntance.traceError(eventName, customDimension, customMeasurement, message);
oneDSLoggerWrapper.oneDSLoggerIntance.traceError(eventName, error, customDimension, customMeasurement, message);
}catch (exception) {
console.warn(exception);
}
}

/// Trace featureName
public featureUsage( featureName: string,eventName: string,customDimensions?: object) {
try{
oneDSLoggerWrapper.oneDSLoggerIntance.featureUsage(featureName, eventName, customDimensions);
}catch (exception) {
console.warn(exception);
}
Expand Down

0 comments on commit cfc45d3

Please sign in to comment.