@microsoft/applicationinsights-analytics-js 3.0.0-beta.2303-11 → 3.0.0-beta.2304-09
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/es5/applicationinsights-analytics-js.cjs.js +5452 -0
- package/browser/es5/applicationinsights-analytics-js.cjs.js.map +1 -0
- package/browser/es5/applicationinsights-analytics-js.cjs.min.js +6 -0
- package/browser/es5/applicationinsights-analytics-js.cjs.min.js.map +1 -0
- package/browser/es5/applicationinsights-analytics-js.gbl.js +5456 -0
- package/browser/es5/applicationinsights-analytics-js.gbl.js.map +1 -0
- package/browser/es5/applicationinsights-analytics-js.gbl.min.js +6 -0
- package/browser/es5/applicationinsights-analytics-js.gbl.min.js.map +1 -0
- package/browser/es5/applicationinsights-analytics-js.integrity.json +66 -0
- package/browser/{applicationinsights-analytics-js.js → es5/applicationinsights-analytics-js.js} +898 -867
- package/browser/es5/applicationinsights-analytics-js.js.map +1 -0
- package/browser/es5/applicationinsights-analytics-js.min.js +6 -0
- package/browser/es5/applicationinsights-analytics-js.min.js.map +1 -0
- package/dist/{applicationinsights-analytics-js.js → es5/applicationinsights-analytics-js.js} +898 -867
- package/dist/es5/applicationinsights-analytics-js.js.map +1 -0
- package/dist/es5/applicationinsights-analytics-js.min.js +6 -0
- package/dist/es5/applicationinsights-analytics-js.min.js.map +1 -0
- package/{dist-esm → dist-es5}/JavaScriptSDK/AnalyticsPlugin.js +2 -2
- package/{dist-esm → dist-es5}/JavaScriptSDK/AnalyticsPlugin.js.map +1 -1
- package/{dist-esm → dist-es5}/JavaScriptSDK/Telemetry/PageViewManager.js +1 -1
- package/{dist-esm → dist-es5}/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js +1 -1
- package/{dist-esm → dist-es5}/JavaScriptSDK/Telemetry/PageVisitTimeManager.js +1 -1
- package/{dist-esm → dist-es5}/JavaScriptSDK/Timing.js +1 -1
- package/{dist-esm → dist-es5}/JavaScriptSDK.Interfaces/ITelemetryConfig.js +1 -1
- package/{dist-esm → dist-es5}/__DynamicConstants.js +1 -1
- package/{dist-esm → dist-es5}/applicationinsights-analytics-js.js +1 -1
- package/package.json +19 -18
- package/tsconfig.json +5 -4
- package/types/applicationinsights-analytics-js.d.ts +181 -2
- package/{dist/applicationinsights-analytics-js.d.ts → types/applicationinsights-analytics-js.namespaced.d.ts} +1 -1
- package/browser/applicationinsights-analytics-js.integrity.json +0 -26
- package/browser/applicationinsights-analytics-js.js.map +0 -1
- package/browser/applicationinsights-analytics-js.min.js +0 -6
- package/browser/applicationinsights-analytics-js.min.js.map +0 -1
- package/dist/applicationinsights-analytics-js.api.json +0 -1845
- package/dist/applicationinsights-analytics-js.api.md +0 -100
- package/dist/applicationinsights-analytics-js.js.map +0 -1
- package/dist/applicationinsights-analytics-js.min.js +0 -6
- package/dist/applicationinsights-analytics-js.min.js.map +0 -1
- package/dist/applicationinsights-analytics-js.rollup.d.ts +0 -182
- package/src/JavaScriptSDK/AnalyticsPlugin.ts +0 -1064
- package/src/JavaScriptSDK/Telemetry/PageViewManager.ts +0 -249
- package/src/JavaScriptSDK/Telemetry/PageViewPerformanceManager.ts +0 -221
- package/src/JavaScriptSDK/Telemetry/PageVisitTimeManager.ts +0 -128
- package/src/JavaScriptSDK/Timing.ts +0 -46
- package/src/JavaScriptSDK.Interfaces/ITelemetryConfig.ts +0 -13
- package/src/__DynamicConstants.ts +0 -56
- package/src/applicationinsights-analytics-js.ts +0 -5
- package/types/JavaScriptSDK/AnalyticsPlugin.d.ts +0 -140
- package/types/JavaScriptSDK/Telemetry/PageViewManager.d.ts +0 -30
- package/types/JavaScriptSDK/Telemetry/PageViewPerformanceManager.d.ts +0 -23
- package/types/JavaScriptSDK/Telemetry/PageVisitTimeManager.d.ts +0 -25
- package/types/JavaScriptSDK/Timing.d.ts +0 -18
- package/types/JavaScriptSDK.Interfaces/ITelemetryConfig.d.ts +0 -10
- package/types/__DynamicConstants.d.ts +0 -44
- package/types/tsdoc-metadata.json +0 -11
- /package/{dist-esm → dist-es5}/JavaScriptSDK/Telemetry/PageViewManager.js.map +0 -0
- /package/{dist-esm → dist-es5}/JavaScriptSDK/Telemetry/PageViewPerformanceManager.js.map +0 -0
- /package/{dist-esm → dist-es5}/JavaScriptSDK/Telemetry/PageVisitTimeManager.js.map +0 -0
- /package/{dist-esm → dist-es5}/JavaScriptSDK/Timing.js.map +0 -0
- /package/{dist-esm → dist-es5}/JavaScriptSDK.Interfaces/ITelemetryConfig.js.map +0 -0
- /package/{dist-esm → dist-es5}/__DynamicConstants.js.map +0 -0
- /package/{dist-esm → dist-es5}/applicationinsights-analytics-js.js.map +0 -0
|
@@ -1,1064 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ApplicationInsights.ts
|
|
3
|
-
* @copyright Microsoft 2018
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
7
|
-
import {
|
|
8
|
-
AnalyticsPluginIdentifier, Event as EventTelemetry, Exception, IAppInsights, IAutoExceptionTelemetry, IConfig, IDependencyTelemetry,
|
|
9
|
-
IEventTelemetry, IExceptionInternal, IExceptionTelemetry, IMetricTelemetry, IPageViewPerformanceTelemetry,
|
|
10
|
-
IPageViewPerformanceTelemetryInternal, IPageViewTelemetry, IPageViewTelemetryInternal, ITraceTelemetry, Metric, PageView,
|
|
11
|
-
PageViewPerformance, PropertiesPluginIdentifier, RemoteDependencyData, Trace, createDistributedTraceContextFromTrace, createDomEvent,
|
|
12
|
-
createTelemetryItem, dataSanitizeString, eSeverityLevel, isCrossOriginError, strNotSpecified, utlDisableStorage, utlEnableStorage
|
|
13
|
-
} from "@microsoft/applicationinsights-common";
|
|
14
|
-
import {
|
|
15
|
-
BaseTelemetryPlugin, IAppInsightsCore, IConfigDefaults, IConfiguration, ICookieMgr, ICustomProperties, IDistributedTraceContext,
|
|
16
|
-
IInstrumentCallDetails, IPlugin, IProcessTelemetryContext, IProcessTelemetryUnloadContext, ITelemetryInitializerHandler, ITelemetryItem,
|
|
17
|
-
ITelemetryPluginChain, ITelemetryUnloadState, InstrumentEvent, TelemetryInitializerFunction, _eInternalMessageId, arrForEach,
|
|
18
|
-
cfgDfBoolean, cfgDfSet, cfgDfString, cfgDfValidate, createProcessTelemetryContext, createUniqueNamespace, dumpObj, eLoggingSeverity,
|
|
19
|
-
eventOff, eventOn, generateW3CId, getDocument, getExceptionName, getHistory, getLocation, getWindow, hasHistory, hasWindow, isFunction,
|
|
20
|
-
isNullOrUndefined, isString, isUndefined, mergeEvtNamespace, onConfigChange, safeGetCookieMgr, strUndefined, throwError
|
|
21
|
-
} from "@microsoft/applicationinsights-core-js";
|
|
22
|
-
import { PropertiesPlugin } from "@microsoft/applicationinsights-properties-js";
|
|
23
|
-
import { isError, objDeepFreeze, objDefine, scheduleTimeout, strIndexOf } from "@nevware21/ts-utils";
|
|
24
|
-
import { IAppInsightsInternal, PageViewManager } from "./Telemetry/PageViewManager";
|
|
25
|
-
import { PageViewPerformanceManager } from "./Telemetry/PageViewPerformanceManager";
|
|
26
|
-
import { PageVisitTimeManager } from "./Telemetry/PageVisitTimeManager";
|
|
27
|
-
import { Timing } from "./Timing";
|
|
28
|
-
|
|
29
|
-
const strEvent = "event";
|
|
30
|
-
|
|
31
|
-
function _dispatchEvent(target:EventTarget, evnt: Event) {
|
|
32
|
-
if (target && target.dispatchEvent && evnt) {
|
|
33
|
-
target.dispatchEvent(evnt);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function _getReason(error: any) {
|
|
38
|
-
if (error && error.reason) {
|
|
39
|
-
const reason = error.reason;
|
|
40
|
-
if (!isString(reason) && isFunction(reason.toString)) {
|
|
41
|
-
return reason.toString();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return dumpObj(reason);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Pass the original object down which will eventually get evaluated for any message or description
|
|
48
|
-
return error || "";
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const MinMilliSeconds = 60000;
|
|
52
|
-
|
|
53
|
-
const defaultValues: IConfigDefaults<IConfig> = objDeepFreeze({
|
|
54
|
-
sessionRenewalMs: cfgDfSet(_chkConfigMilliseconds, 30 * 60 * 1000),
|
|
55
|
-
sessionExpirationMs: cfgDfSet(_chkConfigMilliseconds, 24 * 60 * 60 * 1000),
|
|
56
|
-
disableExceptionTracking: cfgDfBoolean(),
|
|
57
|
-
autoTrackPageVisitTime: cfgDfBoolean(),
|
|
58
|
-
overridePageViewDuration: cfgDfBoolean(),
|
|
59
|
-
enableUnhandledPromiseRejectionTracking: cfgDfBoolean(),
|
|
60
|
-
autoUnhandledPromiseInstrumented: false,
|
|
61
|
-
samplingPercentage: cfgDfValidate(_chkSampling, 100),
|
|
62
|
-
isStorageUseDisabled: cfgDfBoolean(),
|
|
63
|
-
isBrowserLinkTrackingEnabled: cfgDfBoolean(),
|
|
64
|
-
enableAutoRouteTracking: cfgDfBoolean(),
|
|
65
|
-
namePrefix: cfgDfString(),
|
|
66
|
-
enableDebug: cfgDfBoolean(),
|
|
67
|
-
disableFlushOnBeforeUnload: cfgDfBoolean(),
|
|
68
|
-
disableFlushOnUnload: cfgDfBoolean(false, "disableFlushOnBeforeUnload")
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
function _chkConfigMilliseconds(value: number, defValue: number): number {
|
|
72
|
-
value = value || defValue;
|
|
73
|
-
if (value < MinMilliSeconds) {
|
|
74
|
-
value = MinMilliSeconds;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return +value;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function _chkSampling(value: number) {
|
|
81
|
-
return !isNaN(value) && value > 0 && value <= 100;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function _updateStorageUsage(extConfig: IConfig) {
|
|
85
|
-
// Not resetting the storage usage as someone may have manually called utlDisableStorage, so this will only
|
|
86
|
-
// reset based if the configuration option is provided
|
|
87
|
-
if (!isUndefined(extConfig.isStorageUseDisabled)) {
|
|
88
|
-
if (extConfig.isStorageUseDisabled) {
|
|
89
|
-
utlDisableStorage();
|
|
90
|
-
} else {
|
|
91
|
-
utlEnableStorage();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export class AnalyticsPlugin extends BaseTelemetryPlugin implements IAppInsights, IAppInsightsInternal {
|
|
97
|
-
public static Version = "#version#"; // Not currently used anywhere
|
|
98
|
-
|
|
99
|
-
public identifier: string = AnalyticsPluginIdentifier; // do not change name or priority
|
|
100
|
-
public priority: number = 180; // take from reserved priority range 100- 200
|
|
101
|
-
public readonly config: IConfig;
|
|
102
|
-
public queue: Array<() => void>;
|
|
103
|
-
public autoRoutePVDelay = 500; // ms; Time to wait after a route change before triggering a pageview to allow DOM changes to take place
|
|
104
|
-
|
|
105
|
-
constructor() {
|
|
106
|
-
super();
|
|
107
|
-
let _eventTracking: Timing;
|
|
108
|
-
let _pageTracking: Timing;
|
|
109
|
-
let _pageViewManager: PageViewManager;
|
|
110
|
-
let _pageViewPerformanceManager: PageViewPerformanceManager;
|
|
111
|
-
let _pageVisitTimeManager: PageVisitTimeManager;
|
|
112
|
-
let _preInitTelemetryInitializers: TelemetryInitializerFunction[];
|
|
113
|
-
let _isBrowserLinkTrackingEnabled: boolean;
|
|
114
|
-
let _browserLinkInitializerAdded: boolean;
|
|
115
|
-
let _enableAutoRouteTracking: boolean;
|
|
116
|
-
let _historyListenerAdded: boolean;
|
|
117
|
-
let _disableExceptionTracking: boolean;
|
|
118
|
-
let _autoExceptionInstrumented: boolean;
|
|
119
|
-
let _enableUnhandledPromiseRejectionTracking: boolean;
|
|
120
|
-
let _autoUnhandledPromiseInstrumented: boolean;
|
|
121
|
-
let _extConfig: IConfig;
|
|
122
|
-
let _autoTrackPageVisitTime: boolean;
|
|
123
|
-
|
|
124
|
-
// Counts number of trackAjax invocations.
|
|
125
|
-
// By default we only monitor X ajax call per view to avoid too much load.
|
|
126
|
-
// Default value is set in config.
|
|
127
|
-
// This counter keeps increasing even after the limit is reached.
|
|
128
|
-
let _trackAjaxAttempts: number = 0;
|
|
129
|
-
|
|
130
|
-
// array with max length of 2 that store current url and previous url for SPA page route change trackPageview use.
|
|
131
|
-
let _prevUri: string; // Assigned in the constructor
|
|
132
|
-
let _currUri: string;
|
|
133
|
-
let _evtNamespace: string | string[];
|
|
134
|
-
|
|
135
|
-
dynamicProto(AnalyticsPlugin, this, (_self, _base) => {
|
|
136
|
-
let _addHook = _base._addHook;
|
|
137
|
-
|
|
138
|
-
_initDefaults();
|
|
139
|
-
|
|
140
|
-
_self.getCookieMgr = () => {
|
|
141
|
-
return safeGetCookieMgr(_self.core);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
_self.processTelemetry = (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => {
|
|
145
|
-
_self.processNext(env, itemCtx);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
_self.trackEvent = (event: IEventTelemetry, customProperties?: ICustomProperties): void => {
|
|
149
|
-
try {
|
|
150
|
-
let telemetryItem = createTelemetryItem<IEventTelemetry>(
|
|
151
|
-
event,
|
|
152
|
-
EventTelemetry.dataType,
|
|
153
|
-
EventTelemetry.envelopeType,
|
|
154
|
-
_self.diagLog(),
|
|
155
|
-
customProperties
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
_self.core.track(telemetryItem);
|
|
159
|
-
} catch (e) {
|
|
160
|
-
_throwInternal(eLoggingSeverity.WARNING,
|
|
161
|
-
_eInternalMessageId.TrackTraceFailed,
|
|
162
|
-
"trackTrace failed, trace will not be collected: " + getExceptionName(e),
|
|
163
|
-
{ exception: dumpObj(e) });
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Start timing an extended event. Call `stopTrackEvent` to log the event when it ends.
|
|
169
|
-
* @param name A string that identifies this event uniquely within the document.
|
|
170
|
-
*/
|
|
171
|
-
_self.startTrackEvent = (name: string) => {
|
|
172
|
-
try {
|
|
173
|
-
_eventTracking.start(name);
|
|
174
|
-
} catch (e) {
|
|
175
|
-
_throwInternal(eLoggingSeverity.CRITICAL,
|
|
176
|
-
_eInternalMessageId.StartTrackEventFailed,
|
|
177
|
-
"startTrackEvent failed, event will not be collected: " + getExceptionName(e),
|
|
178
|
-
{ exception: dumpObj(e) });
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Log an extended event that you started timing with `startTrackEvent`.
|
|
184
|
-
* @param name The string you used to identify this event in `startTrackEvent`.
|
|
185
|
-
* @param properties map[string, string] - additional data used to filter events and metrics in the portal. Defaults to empty.
|
|
186
|
-
* @param measurements map[string, number] - metrics associated with this event, displayed in Metrics Explorer on the portal. Defaults to empty.
|
|
187
|
-
*/
|
|
188
|
-
_self.stopTrackEvent = (name: string, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) => {
|
|
189
|
-
try {
|
|
190
|
-
_eventTracking.stop(name, undefined, properties, measurements);
|
|
191
|
-
} catch (e) {
|
|
192
|
-
_throwInternal(eLoggingSeverity.CRITICAL,
|
|
193
|
-
_eInternalMessageId.StopTrackEventFailed,
|
|
194
|
-
"stopTrackEvent failed, event will not be collected: " + getExceptionName(e),
|
|
195
|
-
{ exception: dumpObj(e) });
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* @description Log a diagnostic message
|
|
201
|
-
* @param trace
|
|
202
|
-
* @param ICustomProperties.
|
|
203
|
-
* @memberof ApplicationInsights
|
|
204
|
-
*/
|
|
205
|
-
_self.trackTrace = (trace: ITraceTelemetry, customProperties?: ICustomProperties): void => {
|
|
206
|
-
try {
|
|
207
|
-
let telemetryItem = createTelemetryItem<ITraceTelemetry>(
|
|
208
|
-
trace,
|
|
209
|
-
Trace.dataType,
|
|
210
|
-
Trace.envelopeType,
|
|
211
|
-
_self.diagLog(),
|
|
212
|
-
customProperties);
|
|
213
|
-
|
|
214
|
-
_self.core.track(telemetryItem);
|
|
215
|
-
} catch (e) {
|
|
216
|
-
_throwInternal(eLoggingSeverity.WARNING,
|
|
217
|
-
_eInternalMessageId.TrackTraceFailed,
|
|
218
|
-
"trackTrace failed, trace will not be collected: " + getExceptionName(e),
|
|
219
|
-
{ exception: dumpObj(e) });
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* @description Log a numeric value that is not associated with a specific event. Typically
|
|
225
|
-
* used to send regular reports of performance indicators. To send single measurement, just
|
|
226
|
-
* use the name and average fields of {@link IMetricTelemetry}. If you take measurements
|
|
227
|
-
* frequently, you can reduce the telemetry bandwidth by aggregating multiple measurements
|
|
228
|
-
* and sending the resulting average at intervals
|
|
229
|
-
* @param metric - input object argument. Only name and average are mandatory.
|
|
230
|
-
* @param } customProperties additional data used to filter metrics in the
|
|
231
|
-
* portal. Defaults to empty.
|
|
232
|
-
* @memberof ApplicationInsights
|
|
233
|
-
*/
|
|
234
|
-
_self.trackMetric = (metric: IMetricTelemetry, customProperties?: ICustomProperties): void => {
|
|
235
|
-
try {
|
|
236
|
-
let telemetryItem = createTelemetryItem<IMetricTelemetry>(
|
|
237
|
-
metric,
|
|
238
|
-
Metric.dataType,
|
|
239
|
-
Metric.envelopeType,
|
|
240
|
-
_self.diagLog(),
|
|
241
|
-
customProperties
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
_self.core.track(telemetryItem);
|
|
245
|
-
} catch (e) {
|
|
246
|
-
_throwInternal(eLoggingSeverity.CRITICAL,
|
|
247
|
-
_eInternalMessageId.TrackMetricFailed,
|
|
248
|
-
"trackMetric failed, metric will not be collected: " + getExceptionName(e),
|
|
249
|
-
{ exception: dumpObj(e) });
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Logs that a page or other item was viewed.
|
|
255
|
-
* @param IPageViewTelemetry - The string you used as the name in startTrackPage. Defaults to the document title.
|
|
256
|
-
* @param customProperties - Additional data used to filter events and metrics. Defaults to empty.
|
|
257
|
-
* If a user wants to provide duration for pageLoad, it'll have to be in pageView.properties.duration
|
|
258
|
-
*/
|
|
259
|
-
_self.trackPageView = (pageView?: IPageViewTelemetry, customProperties?: ICustomProperties) => {
|
|
260
|
-
try {
|
|
261
|
-
let inPv = pageView || {};
|
|
262
|
-
_pageViewManager.trackPageView(inPv, {...inPv.properties, ...inPv.measurements, ...customProperties});
|
|
263
|
-
|
|
264
|
-
if (_autoTrackPageVisitTime) {
|
|
265
|
-
_pageVisitTimeManager.trackPreviousPageVisit(inPv.name, inPv.uri);
|
|
266
|
-
}
|
|
267
|
-
} catch (e) {
|
|
268
|
-
_throwInternal(
|
|
269
|
-
eLoggingSeverity.CRITICAL,
|
|
270
|
-
_eInternalMessageId.TrackPVFailed,
|
|
271
|
-
"trackPageView failed, page view will not be collected: " + getExceptionName(e),
|
|
272
|
-
{ exception: dumpObj(e) });
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Create a page view telemetry item and send it to the SDK pipeline through the core.track API
|
|
278
|
-
* @param pageView - Page view item to be sent
|
|
279
|
-
* @param properties - Custom properties (Part C) that a user can add to the telemetry item
|
|
280
|
-
* @param systemProperties - System level properties (Part A) that a user can add to the telemetry item
|
|
281
|
-
*/
|
|
282
|
-
_self.sendPageViewInternal = (pageView: IPageViewTelemetryInternal, properties?: { [key: string]: any }, systemProperties?: { [key: string]: any }) => {
|
|
283
|
-
let doc = getDocument();
|
|
284
|
-
if (doc) {
|
|
285
|
-
pageView.refUri = pageView.refUri === undefined ? doc.referrer : pageView.refUri;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
let telemetryItem = createTelemetryItem<IPageViewTelemetryInternal>(
|
|
289
|
-
pageView,
|
|
290
|
-
PageView.dataType,
|
|
291
|
-
PageView.envelopeType,
|
|
292
|
-
_self.diagLog(),
|
|
293
|
-
properties,
|
|
294
|
-
systemProperties);
|
|
295
|
-
|
|
296
|
-
_self.core.track(telemetryItem);
|
|
297
|
-
|
|
298
|
-
// reset ajaxes counter
|
|
299
|
-
_trackAjaxAttempts = 0;
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* @ignore INTERNAL ONLY
|
|
304
|
-
* @param pageViewPerformance
|
|
305
|
-
* @param properties
|
|
306
|
-
*/
|
|
307
|
-
_self.sendPageViewPerformanceInternal = (pageViewPerformance: IPageViewPerformanceTelemetryInternal, properties?: { [key: string]: any }, systemProperties?: { [key: string]: any }) => {
|
|
308
|
-
let telemetryItem = createTelemetryItem<IPageViewPerformanceTelemetryInternal>(
|
|
309
|
-
pageViewPerformance,
|
|
310
|
-
PageViewPerformance.dataType,
|
|
311
|
-
PageViewPerformance.envelopeType,
|
|
312
|
-
_self.diagLog(),
|
|
313
|
-
properties,
|
|
314
|
-
systemProperties);
|
|
315
|
-
|
|
316
|
-
_self.core.track(telemetryItem);
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Send browser performance metrics.
|
|
321
|
-
* @param pageViewPerformance
|
|
322
|
-
* @param customProperties
|
|
323
|
-
*/
|
|
324
|
-
_self.trackPageViewPerformance = (pageViewPerformance: IPageViewPerformanceTelemetry, customProperties?: ICustomProperties): void => {
|
|
325
|
-
let inPvp = pageViewPerformance || {};
|
|
326
|
-
try {
|
|
327
|
-
_pageViewPerformanceManager.populatePageViewPerformanceEvent(inPvp);
|
|
328
|
-
_self.sendPageViewPerformanceInternal(inPvp, customProperties);
|
|
329
|
-
} catch (e) {
|
|
330
|
-
_throwInternal(
|
|
331
|
-
eLoggingSeverity.CRITICAL,
|
|
332
|
-
_eInternalMessageId.TrackPVFailed,
|
|
333
|
-
"trackPageViewPerformance failed, page view will not be collected: " + getExceptionName(e),
|
|
334
|
-
{ exception: dumpObj(e) });
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Starts the timer for tracking a page load time. Use this instead of `trackPageView` if you want to control when the page view timer starts and stops,
|
|
340
|
-
* but don't want to calculate the duration yourself. This method doesn't send any telemetry. Call `stopTrackPage` to log the end of the page view
|
|
341
|
-
* and send the event.
|
|
342
|
-
* @param name - A string that idenfities this item, unique within this HTML document. Defaults to the document title.
|
|
343
|
-
*/
|
|
344
|
-
_self.startTrackPage = (name?: string) => {
|
|
345
|
-
try {
|
|
346
|
-
if (typeof name !== "string") {
|
|
347
|
-
let doc = getDocument();
|
|
348
|
-
name = doc && doc.title || "";
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
_pageTracking.start(name);
|
|
352
|
-
} catch (e) {
|
|
353
|
-
_throwInternal(
|
|
354
|
-
eLoggingSeverity.CRITICAL,
|
|
355
|
-
_eInternalMessageId.StartTrackFailed,
|
|
356
|
-
"startTrackPage failed, page view may not be collected: " + getExceptionName(e),
|
|
357
|
-
{ exception: dumpObj(e) });
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Stops the timer that was started by calling `startTrackPage` and sends the pageview load time telemetry with the specified properties and measurements.
|
|
363
|
-
* The duration of the page view will be the time between calling `startTrackPage` and `stopTrackPage`.
|
|
364
|
-
* @param name The string you used as the name in startTrackPage. Defaults to the document title.
|
|
365
|
-
* @param url String - a relative or absolute URL that identifies the page or other item. Defaults to the window location.
|
|
366
|
-
* @param properties map[string, string] - additional data used to filter pages and metrics in the portal. Defaults to empty.
|
|
367
|
-
* @param measurements map[string, number] - metrics associated with this page, displayed in Metrics Explorer on the portal. Defaults to empty.
|
|
368
|
-
*/
|
|
369
|
-
_self.stopTrackPage = (name?: string, url?: string, properties?: { [key: string]: string }, measurement?: { [key: string]: number }) => {
|
|
370
|
-
try {
|
|
371
|
-
if (typeof name !== "string") {
|
|
372
|
-
let doc = getDocument();
|
|
373
|
-
name = doc && doc.title || "";
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
if (typeof url !== "string") {
|
|
377
|
-
let loc = getLocation();
|
|
378
|
-
url = loc && loc.href || "";
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
_pageTracking.stop(name, url, properties, measurement);
|
|
382
|
-
|
|
383
|
-
if (_autoTrackPageVisitTime) {
|
|
384
|
-
_pageVisitTimeManager.trackPreviousPageVisit(name, url);
|
|
385
|
-
}
|
|
386
|
-
} catch (e) {
|
|
387
|
-
_throwInternal(
|
|
388
|
-
eLoggingSeverity.CRITICAL,
|
|
389
|
-
_eInternalMessageId.StopTrackFailed,
|
|
390
|
-
"stopTrackPage failed, page view will not be collected: " + getExceptionName(e),
|
|
391
|
-
{ exception: dumpObj(e) });
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* @ignore INTERNAL ONLY
|
|
397
|
-
* @param exception
|
|
398
|
-
* @param properties
|
|
399
|
-
* @param systemProperties
|
|
400
|
-
*/
|
|
401
|
-
_self.sendExceptionInternal = (exception: IExceptionTelemetry, customProperties?: { [key: string]: any }, systemProperties?: { [key: string]: any }) => {
|
|
402
|
-
// Adding additional edge cases to handle
|
|
403
|
-
// - Not passing anything (null / undefined)
|
|
404
|
-
const theError = (exception && (exception.exception || exception.error)) ||
|
|
405
|
-
// - Handle someone calling trackException based of v1 API where the exception was the Error
|
|
406
|
-
isError(exception) && exception ||
|
|
407
|
-
// - Handles no error being defined and instead of creating a new Error() instance attempt to map so any stacktrace
|
|
408
|
-
// is preserved and does not list ApplicationInsights code as the source
|
|
409
|
-
{ name: (exception && typeof exception) as string, message: exception as any || strNotSpecified };
|
|
410
|
-
|
|
411
|
-
// If no exception object was passed assign to an empty object to avoid internal exceptions
|
|
412
|
-
exception = exception || {};
|
|
413
|
-
let exceptionPartB = new Exception(
|
|
414
|
-
_self.diagLog(),
|
|
415
|
-
theError,
|
|
416
|
-
exception.properties || customProperties,
|
|
417
|
-
exception.measurements,
|
|
418
|
-
exception.severityLevel,
|
|
419
|
-
exception.id
|
|
420
|
-
).toInterface();
|
|
421
|
-
|
|
422
|
-
let telemetryItem: ITelemetryItem = createTelemetryItem<IExceptionInternal>(
|
|
423
|
-
exceptionPartB,
|
|
424
|
-
Exception.dataType,
|
|
425
|
-
Exception.envelopeType,
|
|
426
|
-
_self.diagLog(),
|
|
427
|
-
customProperties,
|
|
428
|
-
systemProperties
|
|
429
|
-
);
|
|
430
|
-
_self.core.track(telemetryItem);
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* Log an exception you have caught.
|
|
435
|
-
*
|
|
436
|
-
* @param exception - Object which contains exception to be sent
|
|
437
|
-
* @param } customProperties Additional data used to filter pages and metrics in the portal. Defaults to empty.
|
|
438
|
-
*
|
|
439
|
-
* Any property of type double will be considered a measurement, and will be treated by Application Insights as a metric.
|
|
440
|
-
* @memberof ApplicationInsights
|
|
441
|
-
*/
|
|
442
|
-
_self.trackException = (exception: IExceptionTelemetry, customProperties?: ICustomProperties): void => {
|
|
443
|
-
if (exception && !exception.exception && (exception as any).error) {
|
|
444
|
-
exception.exception = (exception as any).error;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
try {
|
|
448
|
-
_self.sendExceptionInternal(exception, customProperties);
|
|
449
|
-
} catch (e) {
|
|
450
|
-
_throwInternal(
|
|
451
|
-
eLoggingSeverity.CRITICAL,
|
|
452
|
-
_eInternalMessageId.TrackExceptionFailed,
|
|
453
|
-
"trackException failed, exception will not be collected: " + getExceptionName(e),
|
|
454
|
-
{ exception: dumpObj(e) });
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* @description Custom error handler for Application Insights Analytics
|
|
460
|
-
* @param exception
|
|
461
|
-
* @memberof ApplicationInsights
|
|
462
|
-
*/
|
|
463
|
-
_self._onerror = (exception: IAutoExceptionTelemetry): void => {
|
|
464
|
-
let error = exception && exception.error;
|
|
465
|
-
let evt = exception && exception.evt;
|
|
466
|
-
|
|
467
|
-
try {
|
|
468
|
-
if (!evt) {
|
|
469
|
-
let _window = getWindow();
|
|
470
|
-
if (_window) {
|
|
471
|
-
evt = _window[strEvent];
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
const url = (exception && exception.url) || (getDocument() || {} as any).URL;
|
|
475
|
-
// If no error source is provided assume the default window.onerror handler
|
|
476
|
-
const errorSrc = exception.errorSrc || "window.onerror@" + url + ":" + (exception.lineNumber || 0) + ":" + (exception.columnNumber || 0);
|
|
477
|
-
let properties = {
|
|
478
|
-
errorSrc,
|
|
479
|
-
url,
|
|
480
|
-
lineNumber: exception.lineNumber || 0,
|
|
481
|
-
columnNumber: exception.columnNumber || 0,
|
|
482
|
-
message: exception.message
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
if (isCrossOriginError(exception.message, exception.url, exception.lineNumber, exception.columnNumber, exception.error)) {
|
|
486
|
-
_sendCORSException(Exception.CreateAutoException(
|
|
487
|
-
"Script error: The browser's same-origin policy prevents us from getting the details of this exception. Consider using the 'crossorigin' attribute.",
|
|
488
|
-
url,
|
|
489
|
-
exception.lineNumber || 0,
|
|
490
|
-
exception.columnNumber || 0,
|
|
491
|
-
error,
|
|
492
|
-
evt,
|
|
493
|
-
null,
|
|
494
|
-
errorSrc
|
|
495
|
-
), properties);
|
|
496
|
-
} else {
|
|
497
|
-
if (!exception.errorSrc) {
|
|
498
|
-
exception.errorSrc = errorSrc;
|
|
499
|
-
}
|
|
500
|
-
_self.trackException({ exception, severityLevel: eSeverityLevel.Error }, properties);
|
|
501
|
-
}
|
|
502
|
-
} catch (e) {
|
|
503
|
-
const errorString = error ? (error.name + ", " + error.message) : "null";
|
|
504
|
-
|
|
505
|
-
_throwInternal(
|
|
506
|
-
eLoggingSeverity.CRITICAL,
|
|
507
|
-
_eInternalMessageId.ExceptionWhileLoggingError,
|
|
508
|
-
"_onError threw exception while logging error, error will not be collected: "
|
|
509
|
-
+ getExceptionName(e),
|
|
510
|
-
{ exception: dumpObj(e), errorString }
|
|
511
|
-
);
|
|
512
|
-
}
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
_self.addTelemetryInitializer = (telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler => {
|
|
516
|
-
if (_self.core) {
|
|
517
|
-
// Just add to the core
|
|
518
|
-
return _self.core.addTelemetryInitializer(telemetryInitializer);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
// Handle "pre-initialization" telemetry initializers (for backward compatibility)
|
|
522
|
-
if (!_preInitTelemetryInitializers) {
|
|
523
|
-
_preInitTelemetryInitializers = [];
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
_preInitTelemetryInitializers.push(telemetryInitializer);
|
|
527
|
-
};
|
|
528
|
-
|
|
529
|
-
_self.initialize = (config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?:ITelemetryPluginChain) => {
|
|
530
|
-
if (_self.isInitialized()) {
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
if (isNullOrUndefined(core)) {
|
|
535
|
-
throwError("Error initializing");
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
_base.initialize(config, core, extensions, pluginChain);
|
|
539
|
-
try {
|
|
540
|
-
_evtNamespace = mergeEvtNamespace(createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
|
|
541
|
-
if (_preInitTelemetryInitializers) {
|
|
542
|
-
arrForEach(_preInitTelemetryInitializers, (initializer) => {
|
|
543
|
-
core.addTelemetryInitializer(initializer);
|
|
544
|
-
});
|
|
545
|
-
|
|
546
|
-
_preInitTelemetryInitializers = null;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
_populateDefaults(config);
|
|
550
|
-
|
|
551
|
-
_pageViewPerformanceManager = new PageViewPerformanceManager(_self.core);
|
|
552
|
-
_pageViewManager = new PageViewManager(this, _extConfig.overridePageViewDuration, _self.core, _pageViewPerformanceManager);
|
|
553
|
-
_pageVisitTimeManager = new PageVisitTimeManager(_self.diagLog(), (pageName, pageUrl, pageVisitTime) => trackPageVisitTime(pageName, pageUrl, pageVisitTime))
|
|
554
|
-
|
|
555
|
-
_eventTracking = new Timing(_self.diagLog(), "trackEvent");
|
|
556
|
-
_eventTracking.action =
|
|
557
|
-
(name?: string, url?: string, duration?: number, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) => {
|
|
558
|
-
if (!properties) {
|
|
559
|
-
properties = {};
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
if (!measurements) {
|
|
563
|
-
measurements = {};
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
properties.duration = duration.toString();
|
|
567
|
-
_self.trackEvent({ name, properties, measurements } as IEventTelemetry);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// initialize page view timing
|
|
571
|
-
_pageTracking = new Timing(_self.diagLog(), "trackPageView");
|
|
572
|
-
_pageTracking.action = (name, url, duration, properties, measurements) => {
|
|
573
|
-
|
|
574
|
-
// duration must be a custom property in order for the collector to extract it
|
|
575
|
-
if (isNullOrUndefined(properties)) {
|
|
576
|
-
properties = {};
|
|
577
|
-
}
|
|
578
|
-
properties.duration = duration.toString();
|
|
579
|
-
|
|
580
|
-
let pageViewItem: IPageViewTelemetry = {
|
|
581
|
-
name,
|
|
582
|
-
uri: url,
|
|
583
|
-
properties,
|
|
584
|
-
measurements
|
|
585
|
-
};
|
|
586
|
-
|
|
587
|
-
_self.sendPageViewInternal(pageViewItem, properties);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
if (hasWindow()) {
|
|
591
|
-
_updateExceptionTracking();
|
|
592
|
-
_updateLocationChange();
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
} catch (e) {
|
|
596
|
-
// resetting the initialized state because of failure
|
|
597
|
-
_self.setInitialized(false);
|
|
598
|
-
throw e;
|
|
599
|
-
}
|
|
600
|
-
};
|
|
601
|
-
|
|
602
|
-
_self._doTeardown = (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => {
|
|
603
|
-
_pageViewManager && _pageViewManager.teardown(unloadCtx, unloadState)
|
|
604
|
-
|
|
605
|
-
// Just register to remove all events associated with this namespace
|
|
606
|
-
eventOff(window, null, null, _evtNamespace);
|
|
607
|
-
_initDefaults();
|
|
608
|
-
};
|
|
609
|
-
|
|
610
|
-
function _populateDefaults(config: IConfiguration) {
|
|
611
|
-
let identifier = _self.identifier;
|
|
612
|
-
let core = _self.core;
|
|
613
|
-
|
|
614
|
-
_self._addHook(onConfigChange(config, () => {
|
|
615
|
-
let ctx = createProcessTelemetryContext(null, config, core);
|
|
616
|
-
_extConfig = ctx.getExtCfg(identifier, defaultValues);
|
|
617
|
-
|
|
618
|
-
_autoTrackPageVisitTime = _extConfig.autoTrackPageVisitTime;
|
|
619
|
-
|
|
620
|
-
_updateStorageUsage(_extConfig);
|
|
621
|
-
|
|
622
|
-
// _updateBrowserLinkTracking
|
|
623
|
-
_isBrowserLinkTrackingEnabled = _extConfig.isBrowserLinkTrackingEnabled;
|
|
624
|
-
_addDefaultTelemetryInitializers();
|
|
625
|
-
}));
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
/**
|
|
629
|
-
* Log a page visit time
|
|
630
|
-
* @param pageName Name of page
|
|
631
|
-
* @param pageVisitDuration Duration of visit to the page in milliseconds
|
|
632
|
-
*/
|
|
633
|
-
function trackPageVisitTime(pageName: string, pageUrl: string, pageVisitTime: number) {
|
|
634
|
-
let properties = { PageName: pageName, PageUrl: pageUrl };
|
|
635
|
-
_self.trackMetric({
|
|
636
|
-
name: "PageVisitTime",
|
|
637
|
-
average: pageVisitTime,
|
|
638
|
-
max: pageVisitTime,
|
|
639
|
-
min: pageVisitTime,
|
|
640
|
-
sampleCount: 1
|
|
641
|
-
}, properties);
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
function _addDefaultTelemetryInitializers() {
|
|
645
|
-
if (!_browserLinkInitializerAdded && _isBrowserLinkTrackingEnabled) {
|
|
646
|
-
const browserLinkPaths = ["/browserLinkSignalR/", "/__browserLink/"];
|
|
647
|
-
const dropBrowserLinkRequests = (envelope: ITelemetryItem) => {
|
|
648
|
-
if (_isBrowserLinkTrackingEnabled && envelope.baseType === RemoteDependencyData.dataType) {
|
|
649
|
-
let remoteData = envelope.baseData as IDependencyTelemetry;
|
|
650
|
-
if (remoteData) {
|
|
651
|
-
for (let i = 0; i < browserLinkPaths.length; i++) {
|
|
652
|
-
if (remoteData.target && strIndexOf(remoteData.target, browserLinkPaths[i]) >= 0) {
|
|
653
|
-
return false;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
return true;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
_self._addHook(_self.addTelemetryInitializer(dropBrowserLinkRequests));
|
|
663
|
-
_browserLinkInitializerAdded = true;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
function _sendCORSException(exception: IAutoExceptionTelemetry, properties?: ICustomProperties) {
|
|
668
|
-
let telemetryItem: ITelemetryItem = createTelemetryItem<IAutoExceptionTelemetry>(
|
|
669
|
-
exception,
|
|
670
|
-
Exception.dataType,
|
|
671
|
-
Exception.envelopeType,
|
|
672
|
-
_self.diagLog(),
|
|
673
|
-
properties
|
|
674
|
-
);
|
|
675
|
-
|
|
676
|
-
_self.core.track(telemetryItem);
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
function _updateExceptionTracking() {
|
|
680
|
-
let _window = getWindow();
|
|
681
|
-
let locn = getLocation(true);
|
|
682
|
-
|
|
683
|
-
_self._addHook(onConfigChange(_extConfig, () => {
|
|
684
|
-
_disableExceptionTracking = _extConfig.disableExceptionTracking;
|
|
685
|
-
|
|
686
|
-
if (!_disableExceptionTracking && !_autoExceptionInstrumented && !_extConfig.autoExceptionInstrumented) {
|
|
687
|
-
// We want to enable exception auto collection and it has not been done so yet
|
|
688
|
-
_addHook(InstrumentEvent(_window, "onerror", {
|
|
689
|
-
ns: _evtNamespace,
|
|
690
|
-
rsp: (callDetails: IInstrumentCallDetails, message, url, lineNumber, columnNumber, error) => {
|
|
691
|
-
if (!_disableExceptionTracking && callDetails.rslt !== true) {
|
|
692
|
-
_self._onerror(Exception.CreateAutoException(
|
|
693
|
-
message,
|
|
694
|
-
url,
|
|
695
|
-
lineNumber,
|
|
696
|
-
columnNumber,
|
|
697
|
-
error,
|
|
698
|
-
callDetails.evt
|
|
699
|
-
));
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}, false));
|
|
703
|
-
|
|
704
|
-
_autoExceptionInstrumented = true;
|
|
705
|
-
}
|
|
706
|
-
}));
|
|
707
|
-
|
|
708
|
-
_addUnhandledPromiseRejectionTracking(_window, locn);
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
function _updateLocationChange() {
|
|
712
|
-
let win = getWindow();
|
|
713
|
-
let locn = getLocation(true);
|
|
714
|
-
|
|
715
|
-
_self._addHook(onConfigChange(_extConfig, () => {
|
|
716
|
-
_enableAutoRouteTracking = _extConfig.enableAutoRouteTracking === true;
|
|
717
|
-
|
|
718
|
-
/**
|
|
719
|
-
* Create a custom "locationchange" event which is triggered each time the history object is changed
|
|
720
|
-
*/
|
|
721
|
-
if (win && _enableAutoRouteTracking && !_historyListenerAdded && hasHistory()) {
|
|
722
|
-
let _history = getHistory();
|
|
723
|
-
|
|
724
|
-
if (isFunction(_history.pushState) && isFunction(_history.replaceState) && typeof Event !== strUndefined) {
|
|
725
|
-
_addHistoryListener(win, _history, locn);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
}));
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
function _getDistributedTraceCtx(): IDistributedTraceContext {
|
|
732
|
-
let distributedTraceCtx: IDistributedTraceContext = null;
|
|
733
|
-
if (_self.core && _self.core.getTraceCtx) {
|
|
734
|
-
distributedTraceCtx = _self.core.getTraceCtx(false);
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
if (!distributedTraceCtx) {
|
|
738
|
-
// Fallback when using an older Core and PropertiesPlugin
|
|
739
|
-
let properties = _self.core.getPlugin<PropertiesPlugin>(PropertiesPluginIdentifier);
|
|
740
|
-
if (properties) {
|
|
741
|
-
let context = properties.plugin.context;
|
|
742
|
-
if (context) {
|
|
743
|
-
distributedTraceCtx = createDistributedTraceContextFromTrace(context.telemetryTrace);
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
return distributedTraceCtx;
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
/**
|
|
752
|
-
* Create a custom "locationchange" event which is triggered each time the history object is changed
|
|
753
|
-
*/
|
|
754
|
-
function _addHistoryListener(win: Window, history: History, locn: Location) {
|
|
755
|
-
if (_historyListenerAdded) {
|
|
756
|
-
return;
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
// Name Prefix is only referenced during the initial initialization and cannot be changed afterwards
|
|
760
|
-
let namePrefix = _extConfig.namePrefix || "";
|
|
761
|
-
|
|
762
|
-
function _popstateHandler() {
|
|
763
|
-
if (_enableAutoRouteTracking) {
|
|
764
|
-
_dispatchEvent(win, createDomEvent(namePrefix + "locationchange"));
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
function _locationChangeHandler() {
|
|
769
|
-
// We always track the changes (if the handler is installed) to handle the feature being disabled between location changes
|
|
770
|
-
if (_currUri) {
|
|
771
|
-
_prevUri = _currUri;
|
|
772
|
-
_currUri = locn && locn.href || "";
|
|
773
|
-
} else {
|
|
774
|
-
_currUri = locn && locn.href || "";
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
if (_enableAutoRouteTracking) {
|
|
778
|
-
let distributedTraceCtx = _getDistributedTraceCtx();
|
|
779
|
-
if (distributedTraceCtx) {
|
|
780
|
-
distributedTraceCtx.setTraceId(generateW3CId());
|
|
781
|
-
let traceLocationName = "_unknown_";
|
|
782
|
-
if (locn && locn.pathname) {
|
|
783
|
-
traceLocationName = locn.pathname + (locn.hash || "");
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
// This populates the ai.operation.name which has a maximum size of 1024 so we need to sanitize it
|
|
787
|
-
distributedTraceCtx.setName(dataSanitizeString(_self.diagLog(), traceLocationName));
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
scheduleTimeout(((uri: string) => {
|
|
791
|
-
// todo: override start time so that it is not affected by autoRoutePVDelay
|
|
792
|
-
_self.trackPageView({ refUri: uri, properties: { duration: 0 } }); // SPA route change loading durations are undefined, so send 0
|
|
793
|
-
}).bind(this, _prevUri), _self.autoRoutePVDelay);
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
_addHook(InstrumentEvent(history, "pushState", {
|
|
798
|
-
ns: _evtNamespace,
|
|
799
|
-
rsp: () => {
|
|
800
|
-
if (_enableAutoRouteTracking) {
|
|
801
|
-
_dispatchEvent(win, createDomEvent(namePrefix + "pushState"));
|
|
802
|
-
_dispatchEvent(win, createDomEvent(namePrefix + "locationchange"));
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
}, true));
|
|
806
|
-
|
|
807
|
-
_addHook(InstrumentEvent(history, "replaceState", {
|
|
808
|
-
ns: _evtNamespace,
|
|
809
|
-
rsp: () => {
|
|
810
|
-
if (_enableAutoRouteTracking) {
|
|
811
|
-
_dispatchEvent(win, createDomEvent(namePrefix + "replaceState"));
|
|
812
|
-
_dispatchEvent(win, createDomEvent(namePrefix + "locationchange"));
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}, true));
|
|
816
|
-
|
|
817
|
-
eventOn(win, namePrefix + "popstate", _popstateHandler, _evtNamespace);
|
|
818
|
-
eventOn(win, namePrefix + "locationchange", _locationChangeHandler, _evtNamespace);
|
|
819
|
-
|
|
820
|
-
_historyListenerAdded = true;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
function _addUnhandledPromiseRejectionTracking(_window: Window, _location: Location) {
|
|
824
|
-
_self._addHook(onConfigChange(_extConfig, () => {
|
|
825
|
-
|
|
826
|
-
_enableUnhandledPromiseRejectionTracking = _extConfig.enableUnhandledPromiseRejectionTracking === true;
|
|
827
|
-
_autoExceptionInstrumented = _autoExceptionInstrumented || _extConfig.autoUnhandledPromiseInstrumented;
|
|
828
|
-
|
|
829
|
-
if (_enableUnhandledPromiseRejectionTracking && !_autoUnhandledPromiseInstrumented) {
|
|
830
|
-
// We want to enable exception auto collection and it has not been done so yet
|
|
831
|
-
_addHook(InstrumentEvent(_window, "onunhandledrejection", {
|
|
832
|
-
ns: _evtNamespace,
|
|
833
|
-
rsp: (callDetails: IInstrumentCallDetails, error: PromiseRejectionEvent) => {
|
|
834
|
-
if (_enableUnhandledPromiseRejectionTracking && callDetails.rslt !== true) { // handled could be typeof function
|
|
835
|
-
_self._onerror(Exception.CreateAutoException(
|
|
836
|
-
_getReason(error),
|
|
837
|
-
_location ? _location.href : "",
|
|
838
|
-
0,
|
|
839
|
-
0,
|
|
840
|
-
error,
|
|
841
|
-
callDetails.evt
|
|
842
|
-
));
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
}, false));
|
|
846
|
-
|
|
847
|
-
_extConfig.autoUnhandledPromiseInstrumented = _autoUnhandledPromiseInstrumented = true;
|
|
848
|
-
}
|
|
849
|
-
}));
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
/**
|
|
853
|
-
* This method will throw exceptions in debug mode or attempt to log the error as a console warning.
|
|
854
|
-
* @param severity - {eLoggingSeverity} - The severity of the log message
|
|
855
|
-
* @param msgId - {_eInternalLogMessage} - The log message.
|
|
856
|
-
*/
|
|
857
|
-
function _throwInternal(severity: eLoggingSeverity, msgId: _eInternalMessageId, msg: string, properties?: Object, isUserAct?: boolean): void {
|
|
858
|
-
_self.diagLog().throwInternal(severity, msgId, msg, properties, isUserAct);
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
function _initDefaults() {
|
|
862
|
-
_eventTracking = null;
|
|
863
|
-
_pageTracking = null;
|
|
864
|
-
_pageViewManager = null;
|
|
865
|
-
_pageViewPerformanceManager = null;
|
|
866
|
-
_pageVisitTimeManager = null;
|
|
867
|
-
_preInitTelemetryInitializers = null;
|
|
868
|
-
_isBrowserLinkTrackingEnabled = false;
|
|
869
|
-
_browserLinkInitializerAdded = false;
|
|
870
|
-
_enableAutoRouteTracking = false;
|
|
871
|
-
_historyListenerAdded = false;
|
|
872
|
-
_disableExceptionTracking = false;
|
|
873
|
-
_autoExceptionInstrumented = false;
|
|
874
|
-
_enableUnhandledPromiseRejectionTracking = false;
|
|
875
|
-
_autoUnhandledPromiseInstrumented = false;
|
|
876
|
-
_autoTrackPageVisitTime = false;
|
|
877
|
-
|
|
878
|
-
// Counts number of trackAjax invocations.
|
|
879
|
-
// By default we only monitor X ajax call per view to avoid too much load.
|
|
880
|
-
// Default value is set in config.
|
|
881
|
-
// This counter keeps increasing even after the limit is reached.
|
|
882
|
-
_trackAjaxAttempts = 0;
|
|
883
|
-
|
|
884
|
-
// array with max length of 2 that store current url and previous url for SPA page route change trackPageview use.
|
|
885
|
-
let location = getLocation(true);
|
|
886
|
-
_prevUri = location && location.href || "";
|
|
887
|
-
_currUri = null;
|
|
888
|
-
_evtNamespace = null;
|
|
889
|
-
_extConfig = null;
|
|
890
|
-
|
|
891
|
-
// Define _self.config
|
|
892
|
-
objDefine(_self, "config", {
|
|
893
|
-
g: () => _extConfig
|
|
894
|
-
});
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
// For backward compatibility
|
|
898
|
-
objDefine<any>(_self, "_pageViewManager", { g: () => _pageViewManager });
|
|
899
|
-
objDefine<any>(_self, "_pageViewPerformanceManager", { g: () => _pageViewPerformanceManager });
|
|
900
|
-
objDefine<any>(_self, "_pageVisitTimeManager", { g: () => _pageVisitTimeManager });
|
|
901
|
-
objDefine<any>(_self, "_evtNamespace", { g: () => "." + _evtNamespace });
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* Get the current cookie manager for this instance
|
|
907
|
-
*/
|
|
908
|
-
public getCookieMgr(): ICookieMgr {
|
|
909
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
910
|
-
return null;
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
public processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) {
|
|
914
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
public trackEvent(event: IEventTelemetry, customProperties?: ICustomProperties): void {
|
|
918
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
/**
|
|
922
|
-
* Start timing an extended event. Call `stopTrackEvent` to log the event when it ends.
|
|
923
|
-
* @param name A string that identifies this event uniquely within the document.
|
|
924
|
-
*/
|
|
925
|
-
public startTrackEvent(name: string) {
|
|
926
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
/**
|
|
930
|
-
* Log an extended event that you started timing with `startTrackEvent`.
|
|
931
|
-
* @param name The string you used to identify this event in `startTrackEvent`.
|
|
932
|
-
* @param properties map[string, string] - additional data used to filter events and metrics in the portal. Defaults to empty.
|
|
933
|
-
* @param measurements map[string, number] - metrics associated with this event, displayed in Metrics Explorer on the portal. Defaults to empty.
|
|
934
|
-
*/
|
|
935
|
-
public stopTrackEvent(name: string, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) {
|
|
936
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
/**
|
|
940
|
-
* @description Log a diagnostic message
|
|
941
|
-
* @param trace
|
|
942
|
-
* @param ICustomProperties.
|
|
943
|
-
* @memberof ApplicationInsights
|
|
944
|
-
*/
|
|
945
|
-
public trackTrace(trace: ITraceTelemetry, customProperties?: ICustomProperties): void {
|
|
946
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
/**
|
|
950
|
-
* @description Log a numeric value that is not associated with a specific event. Typically
|
|
951
|
-
* used to send regular reports of performance indicators. To send single measurement, just
|
|
952
|
-
* use the name and average fields of {@link IMetricTelemetry}. If you take measurements
|
|
953
|
-
* frequently, you can reduce the telemetry bandwidth by aggregating multiple measurements
|
|
954
|
-
* and sending the resulting average at intervals
|
|
955
|
-
* @param metric - input object argument. Only name and average are mandatory.
|
|
956
|
-
* @param } customProperties additional data used to filter metrics in the
|
|
957
|
-
* portal. Defaults to empty.
|
|
958
|
-
* @memberof ApplicationInsights
|
|
959
|
-
*/
|
|
960
|
-
public trackMetric(metric: IMetricTelemetry, customProperties?: ICustomProperties): void {
|
|
961
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
/**
|
|
965
|
-
* Logs that a page or other item was viewed.
|
|
966
|
-
* @param IPageViewTelemetry - The string you used as the name in startTrackPage. Defaults to the document title.
|
|
967
|
-
* @param customProperties - Additional data used to filter events and metrics. Defaults to empty.
|
|
968
|
-
* If a user wants to provide duration for pageLoad, it'll have to be in pageView.properties.duration
|
|
969
|
-
*/
|
|
970
|
-
public trackPageView(pageView?: IPageViewTelemetry, customProperties?: ICustomProperties) {
|
|
971
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
/**
|
|
975
|
-
* Create a page view telemetry item and send it to the SDK pipeline through the core.track API
|
|
976
|
-
* @param pageView - Page view item to be sent
|
|
977
|
-
* @param properties - Custom properties (Part C) that a user can add to the telemetry item
|
|
978
|
-
* @param systemProperties - System level properties (Part A) that a user can add to the telemetry item
|
|
979
|
-
*/
|
|
980
|
-
public sendPageViewInternal(pageView: IPageViewTelemetryInternal, properties?: { [key: string]: any }, systemProperties?: { [key: string]: any }) {
|
|
981
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
/**
|
|
985
|
-
* @ignore INTERNAL ONLY
|
|
986
|
-
* @param pageViewPerformance
|
|
987
|
-
* @param properties
|
|
988
|
-
*/
|
|
989
|
-
public sendPageViewPerformanceInternal(pageViewPerformance: IPageViewPerformanceTelemetryInternal, properties?: { [key: string]: any }, systemProperties?: { [key: string]: any }) {
|
|
990
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
/**
|
|
994
|
-
* Send browser performance metrics.
|
|
995
|
-
* @param pageViewPerformance
|
|
996
|
-
* @param customProperties
|
|
997
|
-
*/
|
|
998
|
-
public trackPageViewPerformance(pageViewPerformance: IPageViewPerformanceTelemetry, customProperties?: ICustomProperties): void {
|
|
999
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
/**
|
|
1003
|
-
* Starts the timer for tracking a page load time. Use this instead of `trackPageView` if you want to control when the page view timer starts and stops,
|
|
1004
|
-
* but don't want to calculate the duration yourself. This method doesn't send any telemetry. Call `stopTrackPage` to log the end of the page view
|
|
1005
|
-
* and send the event.
|
|
1006
|
-
* @param name - A string that idenfities this item, unique within this HTML document. Defaults to the document title.
|
|
1007
|
-
*/
|
|
1008
|
-
public startTrackPage(name?: string) {
|
|
1009
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
/**
|
|
1013
|
-
* Stops the timer that was started by calling `startTrackPage` and sends the pageview load time telemetry with the specified properties and measurements.
|
|
1014
|
-
* The duration of the page view will be the time between calling `startTrackPage` and `stopTrackPage`.
|
|
1015
|
-
* @param name The string you used as the name in startTrackPage. Defaults to the document title.
|
|
1016
|
-
* @param url String - a relative or absolute URL that identifies the page or other item. Defaults to the window location.
|
|
1017
|
-
* @param properties map[string, string] - additional data used to filter pages and metrics in the portal. Defaults to empty.
|
|
1018
|
-
* @param measurements map[string, number] - metrics associated with this page, displayed in Metrics Explorer on the portal. Defaults to empty.
|
|
1019
|
-
*/
|
|
1020
|
-
public stopTrackPage(name?: string, url?: string, properties?: { [key: string]: string }, measurement?: { [key: string]: number }) {
|
|
1021
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
/**
|
|
1025
|
-
* @ignore INTERNAL ONLY
|
|
1026
|
-
* @param exception
|
|
1027
|
-
* @param properties
|
|
1028
|
-
* @param systemProperties
|
|
1029
|
-
*/
|
|
1030
|
-
public sendExceptionInternal(exception: IExceptionTelemetry, customProperties?: { [key: string]: any }, systemProperties?: { [key: string]: any }) {
|
|
1031
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
/**
|
|
1035
|
-
* Log an exception you have caught.
|
|
1036
|
-
*
|
|
1037
|
-
* @param exception - Object which contains exception to be sent
|
|
1038
|
-
* @param } customProperties Additional data used to filter pages and metrics in the portal. Defaults to empty.
|
|
1039
|
-
*
|
|
1040
|
-
* Any property of type double will be considered a measurement, and will be treated by Application Insights as a metric.
|
|
1041
|
-
* @memberof ApplicationInsights
|
|
1042
|
-
*/
|
|
1043
|
-
public trackException(exception: IExceptionTelemetry, customProperties?: ICustomProperties): void {
|
|
1044
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
/**
|
|
1048
|
-
* @description Custom error handler for Application Insights Analytics
|
|
1049
|
-
* @param exception
|
|
1050
|
-
* @memberof ApplicationInsights
|
|
1051
|
-
*/
|
|
1052
|
-
public _onerror(exception: IAutoExceptionTelemetry): void {
|
|
1053
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
public addTelemetryInitializer(telemetryInitializer: (item: ITelemetryItem) => boolean | void): ITelemetryInitializerHandler {
|
|
1057
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
1058
|
-
return null;
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
public initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?:ITelemetryPluginChain) {
|
|
1062
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
1063
|
-
}
|
|
1064
|
-
}
|