Telemetry Adjustments (#182)

This commit is contained in:
Steve Faulkner
2020-09-08 12:44:46 -05:00
committed by GitHub
parent faf923f647
commit e6ac5a7043
53 changed files with 230 additions and 260 deletions

View File

@@ -1,13 +1,3 @@
/**
* Defines constants related to logging telemetry. Everything except Action should be kept in sync with the one in the Portal code as much as possible.
*
* TODO: Move this to ExplorerContracts (265329)
*/
export class General {
public static ExtensionName: string = "Microsoft_Azure_DocumentDB";
public static BladeNamePrefix: string = "Extension/Microsoft_Azure_DocumentDB/Blade/";
}
// Data Explorer specific actions. No need to keep this in sync with the one in Portal.
export enum Action {
CollapseTreeNode,
@@ -83,24 +73,19 @@ export enum Action {
NotebooksGitHubDisconnect
}
export class ActionModifiers {
public static Start: string = "start";
public static Success: string = "success";
public static Failed: string = "failed";
public static Mark: string = "mark";
public static Open: string = "open";
public static IFrameReady: string = "iframeready";
public static Close: string = "close";
public static Submit: string = "submit";
public static IndexAll: string = "index all properties";
public static NoIndex: string = "no indexing";
public static Cancel: string = "cancel";
}
export class CosmosDBEndpointNames {
public static Gateway: string = "CosmosDBGateway";
public static ResourceProvider: string = "DocumentDBResourceProvider";
}
export const ActionModifiers = {
Start: "start",
Success: "success",
Failed: "failed",
Mark: "mark",
Open: "open",
IFrameReady: "iframeready",
Close: "close",
Submit: "submit",
IndexAll: "index all properties",
NoIndex: "no indexing",
Cancel: "cancel"
} as const;
export enum SourceBlade {
AddCollection,
@@ -126,17 +111,3 @@ export enum SourceBlade {
ScriptExplorer,
Keys
}
export class BladeLoadRequirements {
public static collections: string = "Collections";
public static collectionsWithOffers: string = "CollectionsWithOffers";
public static databaseAccount: string = "DatabaseAccount";
public static keys: string = "Keys";
public static metrics: string = "Metrics";
public static notifications: string = "Notifications";
public static singleCollection: string = "SingleCollection";
public static keysBlade: string[] = [BladeLoadRequirements.databaseAccount, BladeLoadRequirements.keys];
public static metricsBlade: string[] = [BladeLoadRequirements.databaseAccount];
public static overview: string[] = [BladeLoadRequirements.databaseAccount, BladeLoadRequirements.notifications];
}

View File

@@ -8,123 +8,124 @@ import { userContext } from "../../UserContext";
/**
* Class that persists telemetry data to the portal tables.
*/
// TODO: Move to a separate Diagnostics folder
// TODO: Log telemetry for StorageExplorer case/other clients as well
export default class TelemetryProcessor {
public static trace(action: Action, actionModifier: string = ActionModifiers.Mark, data?: any): void {
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: actionModifier,
data: JSON.stringify(data)
}
});
appInsights.trackEvent({ name: Action[action] }, TelemetryProcessor.getData(data));
}
public static traceStart(action: Action, data?: any): number {
const timestamp: number = Date.now();
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: ActionModifiers.Start,
timestamp: timestamp,
data: JSON.stringify(data)
}
});
appInsights.startTrackEvent(Action[action]);
return timestamp;
}
public static traceSuccess(action: Action, data?: any, timestamp?: number): void {
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: ActionModifiers.Success,
timestamp: timestamp || Date.now(),
data: JSON.stringify(data)
}
});
appInsights.stopTrackEvent(Action[action], TelemetryProcessor.getData(data));
}
public static traceFailure(action: Action, data?: any, timestamp?: number): void {
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: ActionModifiers.Failed,
timestamp: timestamp || Date.now(),
data: JSON.stringify(data)
}
});
appInsights.stopTrackEvent(Action[action], TelemetryProcessor.getData(data));
}
public static traceCancel(action: Action, data?: any, timestamp?: number): void {
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: ActionModifiers.Cancel,
timestamp: timestamp || Date.now(),
data: JSON.stringify(data)
}
});
appInsights.stopTrackEvent(Action[action], TelemetryProcessor.getData(data));
}
public static traceOpen(action: Action, data?: any, timestamp?: number): number {
const validTimestamp = timestamp || Date.now();
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: ActionModifiers.Open,
timestamp: validTimestamp,
data: JSON.stringify(data)
}
});
appInsights.startTrackEvent(Action[action]);
return validTimestamp;
}
public static traceMark(action: Action, data?: any, timestamp?: number): number {
const validTimestamp = timestamp || Date.now();
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: ActionModifiers.Mark,
timestamp: validTimestamp,
data: JSON.stringify(data)
}
});
appInsights.startTrackEvent(Action[action]);
return validTimestamp;
}
private static getData(data: any = {}): any {
if (typeof data === "string") {
data = { message: data };
export function trace(action: Action, actionModifier: string = ActionModifiers.Mark, data?: unknown): void {
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: actionModifier,
data: JSON.stringify(data)
}
});
appInsights.trackEvent({ name: Action[action] }, getData(data));
}
export function traceStart(action: Action, data?: unknown): number {
const timestamp: number = Date.now();
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: ActionModifiers.Start,
timestamp: timestamp,
data: JSON.stringify(data)
}
});
appInsights.startTrackEvent(Action[action]);
return timestamp;
}
export function traceSuccess(action: Action, data?: unknown, timestamp?: number): void {
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: ActionModifiers.Success,
timestamp: timestamp || Date.now(),
data: JSON.stringify(data)
}
});
appInsights.stopTrackEvent(Action[action], getData(data));
}
export function traceFailure(action: Action, data?: unknown, timestamp?: number): void {
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: ActionModifiers.Failed,
timestamp: timestamp || Date.now(),
data: JSON.stringify(data)
}
});
appInsights.stopTrackEvent(Action[action], getData(data));
}
export function traceCancel(action: Action, data?: unknown, timestamp?: number): void {
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: ActionModifiers.Cancel,
timestamp: timestamp || Date.now(),
data: JSON.stringify(data)
}
});
appInsights.stopTrackEvent(Action[action], getData(data));
}
export function traceOpen(action: Action, data?: unknown, timestamp?: number): number {
const validTimestamp = timestamp || Date.now();
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: ActionModifiers.Open,
timestamp: validTimestamp,
data: JSON.stringify(data)
}
});
appInsights.startTrackEvent(Action[action]);
return validTimestamp;
}
export function traceMark(action: Action, data?: unknown, timestamp?: number): number {
const validTimestamp = timestamp || Date.now();
sendMessage({
type: MessageTypes.TelemetryInfo,
data: {
action: Action[action],
actionModifier: ActionModifiers.Mark,
timestamp: validTimestamp,
data: JSON.stringify(data)
}
});
appInsights.startTrackEvent(Action[action]);
return validTimestamp;
}
function getData(data: unknown = {}): { [key: string]: string } | undefined {
if (typeof data === "string") {
data = { message: data };
}
if (typeof data === "object") {
return {
// TODO: Need to `any` here since the window imports Explorer which can't be in strict mode yet
// eslint-disable-next-line @typescript-eslint/no-explicit-any
authType: (window as any).authType,
subscriptionId: userContext.subscriptionId,
subscriptionId: userContext.subscriptionId as string,
platform: configContext.platform,
env: process.env.NODE_ENV,
env: process.env.NODE_ENV as string,
...data
};
}
return undefined;
}

View File

@@ -1,7 +1,9 @@
import { ApplicationInsights } from "@microsoft/applicationinsights-web";
const appInsights = new ApplicationInsights({
config: {
instrumentationKey: "fa645d97-6237-4656-9559-0ee0cb55ee49"
instrumentationKey: "fa645d97-6237-4656-9559-0ee0cb55ee49",
disableFetchTracking: false
}
});
appInsights.loadAppInsights();