Add actionModifier to appInsights telemetry (#202)

This commit is contained in:
Tanuj Mittal 2020-09-15 11:21:18 -07:00 committed by GitHub
parent 5ccf26e403
commit d6a4924710
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,7 +19,7 @@ export function trace(action: Action, actionModifier: string = ActionModifiers.M
} }
}); });
appInsights.trackEvent({ name: Action[action] }, getData(data)); appInsights.trackEvent({ name: Action[action] }, getData(actionModifier, data));
} }
export function traceStart(action: Action, data?: unknown): number { export function traceStart(action: Action, data?: unknown): number {
@ -49,7 +49,7 @@ export function traceSuccess(action: Action, data?: unknown, timestamp?: number)
} }
}); });
appInsights.stopTrackEvent(Action[action], getData(data)); appInsights.stopTrackEvent(Action[action], getData(ActionModifiers.Success, data));
} }
export function traceFailure(action: Action, data?: unknown, timestamp?: number): void { export function traceFailure(action: Action, data?: unknown, timestamp?: number): void {
@ -63,7 +63,7 @@ export function traceFailure(action: Action, data?: unknown, timestamp?: number)
} }
}); });
appInsights.stopTrackEvent(Action[action], getData(data)); appInsights.stopTrackEvent(Action[action], getData(ActionModifiers.Failed, data));
} }
export function traceCancel(action: Action, data?: unknown, timestamp?: number): void { export function traceCancel(action: Action, data?: unknown, timestamp?: number): void {
@ -77,7 +77,7 @@ export function traceCancel(action: Action, data?: unknown, timestamp?: number):
} }
}); });
appInsights.stopTrackEvent(Action[action], getData(data)); appInsights.stopTrackEvent(Action[action], getData(ActionModifiers.Cancel, data));
} }
export function traceOpen(action: Action, data?: unknown, timestamp?: number): number { export function traceOpen(action: Action, data?: unknown, timestamp?: number): number {
@ -112,7 +112,7 @@ export function traceMark(action: Action, data?: unknown, timestamp?: number): n
return validTimestamp; return validTimestamp;
} }
function getData(data: unknown = {}): { [key: string]: string } | undefined { function getData(actionModifier: string, data: unknown = {}): { [key: string]: string } | undefined {
if (typeof data === "string") { if (typeof data === "string") {
data = { message: data }; data = { message: data };
} }
@ -124,6 +124,7 @@ function getData(data: unknown = {}): { [key: string]: string } | undefined {
subscriptionId: userContext.subscriptionId as string, subscriptionId: userContext.subscriptionId as string,
platform: configContext.platform, platform: configContext.platform,
env: process.env.NODE_ENV as string, env: process.env.NODE_ENV as string,
actionModifier,
...data ...data
}; };
} }