Initial updates for minimal support in AI layer
This commit is contained in:
Родитель
1b4ad5ea6d
Коммит
8f059a8600
|
@ -12,12 +12,15 @@ import { AppInsightsCore, IPlugin, IConfiguration, IAppInsightsCore } from "appl
|
||||||
import { TelemetryContext, ITelemetryConfig } from "./TelemetryContext";
|
import { TelemetryContext, ITelemetryConfig } from "./TelemetryContext";
|
||||||
import { PageVisitTimeManager } from "./Telemetry/PageVisitTimeManager";
|
import { PageVisitTimeManager } from "./Telemetry/PageVisitTimeManager";
|
||||||
import { IAI } from "../JavascriptSDK.Interfaces/IAI";
|
import { IAI } from "../JavascriptSDK.Interfaces/IAI";
|
||||||
|
import { CoreUtils } from "JavaScriptSDK/CoreUtils";
|
||||||
|
|
||||||
export class AI implements IAI, IPlugin, IAppInsightsInternal {
|
export class AI implements IAI, IPlugin, IAppInsightsInternal {
|
||||||
public initialize: (config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[]) => void;
|
public initialize: (config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[]) => void;
|
||||||
|
|
||||||
public static Version = "0.0.1";
|
public static Version = "0.0.1";
|
||||||
|
|
||||||
|
private _core: IAppInsightsCore;
|
||||||
|
|
||||||
// Counts number of trackAjax invokations.
|
// Counts number of trackAjax invokations.
|
||||||
// By default we only monitor X ajax call per view to avoid too much load.
|
// By default we only monitor X ajax call per view to avoid too much load.
|
||||||
// Default value is set in config.
|
// Default value is set in config.
|
||||||
|
@ -284,7 +287,7 @@ export class AI implements IAI, IPlugin, IAppInsightsInternal {
|
||||||
* @param properties map[string, string] - additional data used to filter events and metrics in the portal. Defaults to empty.
|
* @param properties map[string, string] - additional data used to filter events and metrics in the portal. Defaults to empty.
|
||||||
* @param measurements map[string, number] - metrics associated with this event, displayed in Metrics Explorer on the portal. Defaults to empty.
|
* @param measurements map[string, number] - metrics associated with this event, displayed in Metrics Explorer on the portal. Defaults to empty.
|
||||||
*/
|
*/
|
||||||
public trackDependency(id: string, method: string, absoluteUrl: string, command: string, totalTime: number, success: boolean, resultCode: number, properties?: Object, measurements?: Object) {
|
private trackDependency(id: string, method: string, absoluteUrl: string, command: string, totalTime: number, success: boolean, resultCode: number, properties?: Object, measurements?: Object) {
|
||||||
if (this.config.maxAjaxCallsPerView === -1 ||
|
if (this.config.maxAjaxCallsPerView === -1 ||
|
||||||
this._trackAjaxAttempts < this.config.maxAjaxCallsPerView) {
|
this._trackAjaxAttempts < this.config.maxAjaxCallsPerView) {
|
||||||
var dependency = new RemoteDependencyData(id, absoluteUrl, command, totalTime, success, resultCode, method, properties, measurements);
|
var dependency = new RemoteDependencyData(id, absoluteUrl, command, totalTime, success, resultCode, method, properties, measurements);
|
||||||
|
@ -306,7 +309,7 @@ export class AI implements IAI, IPlugin, IAppInsightsInternal {
|
||||||
* Logs dependency call
|
* Logs dependency call
|
||||||
* @param dependencyData dependency data object
|
* @param dependencyData dependency data object
|
||||||
*/
|
*/
|
||||||
public trackDependencyData(dependency: RemoteDependencyData) {
|
private trackDependencyData(dependency: RemoteDependencyData) {
|
||||||
if (this.config.maxAjaxCallsPerView === -1 || this._trackAjaxAttempts < this.config.maxAjaxCallsPerView) {
|
if (this.config.maxAjaxCallsPerView === -1 || this._trackAjaxAttempts < this.config.maxAjaxCallsPerView) {
|
||||||
var dependencyData = new Data<RemoteDependencyData>(
|
var dependencyData = new Data<RemoteDependencyData>(
|
||||||
RemoteDependencyData.dataType, dependency);
|
RemoteDependencyData.dataType, dependency);
|
||||||
|
@ -325,7 +328,7 @@ export class AI implements IAI, IPlugin, IAppInsightsInternal {
|
||||||
/**
|
/**
|
||||||
* trackAjax method is obsolete, use trackDependency instead
|
* trackAjax method is obsolete, use trackDependency instead
|
||||||
*/
|
*/
|
||||||
public trackAjax(id: string, absoluteUrl: string, pathName: string, totalTime: number, success: boolean, resultCode: number, method?: string) {
|
private trackAjax(id: string, absoluteUrl: string, pathName: string, totalTime: number, success: boolean, resultCode: number, method?: string) {
|
||||||
this.trackDependency(id, null, absoluteUrl, pathName, totalTime, success, resultCode);
|
this.trackDependency(id, null, absoluteUrl, pathName, totalTime, success, resultCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,7 +340,7 @@ export class AI implements IAI, IPlugin, IAppInsightsInternal {
|
||||||
* @param measurements map[string, number] - metrics associated with this event, displayed in Metrics Explorer on the portal. Defaults to empty.
|
* @param measurements map[string, number] - metrics associated with this event, displayed in Metrics Explorer on the portal. Defaults to empty.
|
||||||
* @param severityLevel AI.SeverityLevel - severity level
|
* @param severityLevel AI.SeverityLevel - severity level
|
||||||
*/
|
*/
|
||||||
public trackException(exception: Error, handledAt?: string, properties?: Object, measurements?: Object, severityLevel?: SeverityLevel) {
|
private trackException(exception: Error, handledAt?: string, properties?: Object, measurements?: Object, severityLevel?: SeverityLevel) {
|
||||||
try {
|
try {
|
||||||
if (!Util.isError(exception)) {
|
if (!Util.isError(exception)) {
|
||||||
// ensure that we have an error object (user could pass a string/message)
|
// ensure that we have an error object (user could pass a string/message)
|
||||||
|
@ -370,7 +373,7 @@ export class AI implements IAI, IPlugin, IAppInsightsInternal {
|
||||||
* @param min The smallest measurement in the sample. Defaults to the average.
|
* @param min The smallest measurement in the sample. Defaults to the average.
|
||||||
* @param max The largest measurement in the sample. Defaults to the average.
|
* @param max The largest measurement in the sample. Defaults to the average.
|
||||||
*/
|
*/
|
||||||
public trackMetric(name: string, average: number, sampleCount?: number, min?: number, max?: number, properties?: Object) {
|
private trackMetric(name: string, average: number, sampleCount?: number, min?: number, max?: number, properties?: Object) {
|
||||||
try {
|
try {
|
||||||
var telemetry = new Metric(name, average, sampleCount, min, max, properties);
|
var telemetry = new Metric(name, average, sampleCount, min, max, properties);
|
||||||
var data = new Data<Metric>(Metric.dataType, telemetry);
|
var data = new Data<Metric>(Metric.dataType, telemetry);
|
||||||
|
@ -391,7 +394,7 @@ export class AI implements IAI, IPlugin, IAppInsightsInternal {
|
||||||
* @param properties map[string, string] - additional data used to filter traces in the portal. Defaults to empty.
|
* @param properties map[string, string] - additional data used to filter traces in the portal. Defaults to empty.
|
||||||
* @param severityLevel AI.SeverityLevel - severity level
|
* @param severityLevel AI.SeverityLevel - severity level
|
||||||
*/
|
*/
|
||||||
public trackTrace(message: string, properties?: Object, severityLevel?: SeverityLevel) {
|
private trackTrace(message: string, properties?: Object, severityLevel?: SeverityLevel) {
|
||||||
try {
|
try {
|
||||||
var telemetry = new Trace(message, properties, severityLevel);
|
var telemetry = new Trace(message, properties, severityLevel);
|
||||||
var data = new Data<Trace>(Trace.dataType, telemetry);
|
var data = new Data<Trace>(Trace.dataType, telemetry);
|
||||||
|
@ -416,20 +419,6 @@ export class AI implements IAI, IPlugin, IAppInsightsInternal {
|
||||||
this.trackMetric("PageVisitTime", pageVisitTime, 1, pageVisitTime, pageVisitTime, properties);
|
this.trackMetric("PageVisitTime", pageVisitTime, 1, pageVisitTime, pageVisitTime, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Immediately send all queued telemetry.
|
|
||||||
// * @param {boolean} async - If flush should be call asynchronously
|
|
||||||
// */
|
|
||||||
// public flush(async = true) {
|
|
||||||
// try {
|
|
||||||
// this.context._sender.triggerSend(async);
|
|
||||||
// } catch (e) {
|
|
||||||
// _InternalLogging.throwInternal(LoggingSeverity.CRITICAL,
|
|
||||||
// _InternalMessageId.FlushFailed,
|
|
||||||
// "flush failed, telemetry will not be collected: " + Util.getExceptionName(e),
|
|
||||||
// { exception: Util.dump(e) });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the authenticated user id and the account id.
|
* Sets the authenticated user id and the account id.
|
||||||
|
@ -442,7 +431,7 @@ export class AI implements IAI, IPlugin, IAppInsightsInternal {
|
||||||
* @param accountId {string} - An optional string to represent the account associated with the authenticated user.
|
* @param accountId {string} - An optional string to represent the account associated with the authenticated user.
|
||||||
* @param storeInCookie {boolean} - AuthenticateUserID will be stored in a cookie and added to all events within this session.
|
* @param storeInCookie {boolean} - AuthenticateUserID will be stored in a cookie and added to all events within this session.
|
||||||
*/
|
*/
|
||||||
public setAuthenticatedUserContext(authenticatedUserId: string, accountId?: string, storeInCookie = false) {
|
private setAuthenticatedUserContext(authenticatedUserId: string, accountId?: string, storeInCookie = false) {
|
||||||
try {
|
try {
|
||||||
this.context.user.setAuthenticatedUserContext(authenticatedUserId, accountId, storeInCookie);
|
this.context.user.setAuthenticatedUserContext(authenticatedUserId, accountId, storeInCookie);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -457,7 +446,7 @@ export class AI implements IAI, IPlugin, IAppInsightsInternal {
|
||||||
/**
|
/**
|
||||||
* Clears the authenticated user id and the account id from the user context.
|
* Clears the authenticated user id and the account id from the user context.
|
||||||
*/
|
*/
|
||||||
public clearAuthenticatedUserContext() {
|
private clearAuthenticatedUserContext() {
|
||||||
try {
|
try {
|
||||||
this.context.user.clearAuthenticatedUserContext();
|
this.context.user.clearAuthenticatedUserContext();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -494,7 +483,7 @@ export class AI implements IAI, IPlugin, IAppInsightsInternal {
|
||||||
* @param {number} columnNumber - The column number for the line where the error was raised
|
* @param {number} columnNumber - The column number for the line where the error was raised
|
||||||
* @param {Error} error - The Error object
|
* @param {Error} error - The Error object
|
||||||
*/
|
*/
|
||||||
public _onerror(message: string, url: string, lineNumber: number, columnNumber: number, error: Error) {
|
private _onerror(message: string, url: string, lineNumber: number, columnNumber: number, error: Error) {
|
||||||
try {
|
try {
|
||||||
var properties = { url: url ? url : document.URL };
|
var properties = { url: url ? url : document.URL };
|
||||||
|
|
||||||
|
@ -522,7 +511,11 @@ export class AI implements IAI, IPlugin, IAppInsightsInternal {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[]) {
|
private _initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[]) {
|
||||||
// Todo: implement
|
if (CoreUtils.isNullOrUndefined(core)) {
|
||||||
|
throw Error("Error initializing");
|
||||||
|
}
|
||||||
|
|
||||||
|
this._core = core;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ export class TelemetryContext implements ITelemetryContext {
|
||||||
|
|
||||||
constructor(config: ITelemetryConfig) {
|
constructor(config: ITelemetryConfig) {
|
||||||
this._config = config;
|
this._config = config;
|
||||||
// this._sender = new Sender(config);
|
// this._sender = new Sender(config);
|
||||||
// this.appId = () => this._sender._appId;
|
// this.appId = () => this._sender._appId;
|
||||||
|
|
||||||
// // use appId set in config instead of getting it from the backend
|
// // use appId set in config instead of getting it from the backend
|
||||||
|
@ -152,6 +152,7 @@ export class TelemetryContext implements ITelemetryContext {
|
||||||
return envelope;
|
return envelope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Todo: move to separate extension
|
||||||
private _addDefaultTelemetryInitializers() {
|
private _addDefaultTelemetryInitializers() {
|
||||||
if (!this._config.isBrowserLinkTrackingEnabled()) {
|
if (!this._config.isBrowserLinkTrackingEnabled()) {
|
||||||
const browserLinkPaths = ['/browserLinkSignalR/', '/__browserLink/'];
|
const browserLinkPaths = ['/browserLinkSignalR/', '/__browserLink/'];
|
||||||
|
@ -197,6 +198,7 @@ export class TelemetryContext implements ITelemetryContext {
|
||||||
|
|
||||||
var doNotSendItem = false;
|
var doNotSendItem = false;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
var telemetryInitializersCount = this.telemetryInitializers.length;
|
var telemetryInitializersCount = this.telemetryInitializers.length;
|
||||||
for (var i = 0; i < telemetryInitializersCount; ++i) {
|
for (var i = 0; i < telemetryInitializersCount; ++i) {
|
||||||
var telemetryInitializer = this.telemetryInitializers[i];
|
var telemetryInitializer = this.telemetryInitializers[i];
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
import { IApplication } from './Context/IApplication';
|
|
||||||
import { IDevice } from './Context/IDevice';
|
|
||||||
import { IInternal } from './Context/IInternal';
|
|
||||||
import { ILocation } from './Context/ILocation';
|
|
||||||
import { IOperation } from './Context/IOperation';
|
|
||||||
import { ISample } from './Context/ISample';
|
|
||||||
import { IUser } from './Context/IUser';
|
|
||||||
import { ISession } from './Context/ISession';
|
|
||||||
import { IEnvelope } from './Telemetry/IEnvelope';
|
|
||||||
import { Envelope } from './Contracts/Generated/Envelope';
|
|
||||||
|
|
||||||
export interface ITelemetryContext {
|
|
||||||
/**
|
|
||||||
* The object describing a component tracked by this object.
|
|
||||||
*/
|
|
||||||
application: IApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The object describing a device tracked by this object.
|
|
||||||
*/
|
|
||||||
device: IDevice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The object describing internal settings.
|
|
||||||
*/
|
|
||||||
internal: IInternal;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The object describing a location tracked by this object.
|
|
||||||
*/
|
|
||||||
location: ILocation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The object describing a operation tracked by this object.
|
|
||||||
*/
|
|
||||||
operation: IOperation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The object describing sampling settings.
|
|
||||||
*/
|
|
||||||
sample: ISample;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The object describing a user tracked by this object.
|
|
||||||
*/
|
|
||||||
user: IUser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The object describing a session tracked by this object.
|
|
||||||
*/
|
|
||||||
session: ISession;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a telemetry initializer to the collection. Telemetry initializers will be called one by one,
|
|
||||||
* in the order they were added, before the telemetry item is pushed for sending.
|
|
||||||
* If one of the telemetry initializers returns false or throws an error then the telemetry item will not be sent.
|
|
||||||
* If it returns true or doesn't return any value the event will be passed to the next telemetry initializer and
|
|
||||||
* send to the cloud (if not rejected by other initializers).
|
|
||||||
*/
|
|
||||||
addTelemetryInitializer(telemetryInitializer: (envelope: IEnvelope) => boolean | void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tracks telemetry object.
|
|
||||||
*/
|
|
||||||
track(envelope: IEnvelope);
|
|
||||||
}
|
|
Загрузка…
Ссылка в новой задаче