@microsoft/applicationinsights-dependencies-js 2.8.0-beta.2203-01 → 2.8.0-beta.2203-04

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript SDK - Dependencies Plugin, 2.8.0-beta.2203-01
2
+ * Application Insights JavaScript SDK - Dependencies Plugin, 2.8.0-beta.2203-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -335,105 +335,20 @@
335
335
  };
336
336
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
337
337
 
338
- var LoggingSeverity;
339
- (function (LoggingSeverity) {
340
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
341
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
342
- })(LoggingSeverity || (LoggingSeverity = {}));
343
- var _InternalMessageId = {
344
- BrowserDoesNotSupportLocalStorage: 0,
345
- BrowserCannotReadLocalStorage: 1,
346
- BrowserCannotReadSessionStorage: 2,
347
- BrowserCannotWriteLocalStorage: 3,
348
- BrowserCannotWriteSessionStorage: 4,
349
- BrowserFailedRemovalFromLocalStorage: 5,
350
- BrowserFailedRemovalFromSessionStorage: 6,
351
- CannotSendEmptyTelemetry: 7,
352
- ClientPerformanceMathError: 8,
353
- ErrorParsingAISessionCookie: 9,
354
- ErrorPVCalc: 10,
355
- ExceptionWhileLoggingError: 11,
356
- FailedAddingTelemetryToBuffer: 12,
357
- FailedMonitorAjaxAbort: 13,
358
- FailedMonitorAjaxDur: 14,
359
- FailedMonitorAjaxOpen: 15,
360
- FailedMonitorAjaxRSC: 16,
361
- FailedMonitorAjaxSend: 17,
362
- FailedMonitorAjaxGetCorrelationHeader: 18,
363
- FailedToAddHandlerForOnBeforeUnload: 19,
364
- FailedToSendQueuedTelemetry: 20,
365
- FailedToReportDataLoss: 21,
366
- FlushFailed: 22,
367
- MessageLimitPerPVExceeded: 23,
368
- MissingRequiredFieldSpecification: 24,
369
- NavigationTimingNotSupported: 25,
370
- OnError: 26,
371
- SessionRenewalDateIsZero: 27,
372
- SenderNotInitialized: 28,
373
- StartTrackEventFailed: 29,
374
- StopTrackEventFailed: 30,
375
- StartTrackFailed: 31,
376
- StopTrackFailed: 32,
377
- TelemetrySampledAndNotSent: 33,
378
- TrackEventFailed: 34,
379
- TrackExceptionFailed: 35,
380
- TrackMetricFailed: 36,
381
- TrackPVFailed: 37,
382
- TrackPVFailedCalc: 38,
383
- TrackTraceFailed: 39,
384
- TransmissionFailed: 40,
385
- FailedToSetStorageBuffer: 41,
386
- FailedToRestoreStorageBuffer: 42,
387
- InvalidBackendResponse: 43,
388
- FailedToFixDepricatedValues: 44,
389
- InvalidDurationValue: 45,
390
- TelemetryEnvelopeInvalid: 46,
391
- CreateEnvelopeError: 47,
392
- CannotSerializeObject: 48,
393
- CannotSerializeObjectNonSerializable: 49,
394
- CircularReferenceDetected: 50,
395
- ClearAuthContextFailed: 51,
396
- ExceptionTruncated: 52,
397
- IllegalCharsInName: 53,
398
- ItemNotInArray: 54,
399
- MaxAjaxPerPVExceeded: 55,
400
- MessageTruncated: 56,
401
- NameTooLong: 57,
402
- SampleRateOutOfRange: 58,
403
- SetAuthContextFailed: 59,
404
- SetAuthContextFailedAccountName: 60,
405
- StringValueTooLong: 61,
406
- StartCalledMoreThanOnce: 62,
407
- StopCalledWithoutStart: 63,
408
- TelemetryInitializerFailed: 64,
409
- TrackArgumentsNotSpecified: 65,
410
- UrlTooLong: 66,
411
- SessionStorageBufferFull: 67,
412
- CannotAccessCookie: 68,
413
- IdTooLong: 69,
414
- InvalidEvent: 70,
415
- FailedMonitorAjaxSetRequestHeader: 71,
416
- SendBrowserInfoOnUserInit: 72,
417
- PluginException: 73,
418
- NotificationException: 74,
419
- SnippetScriptLoadFailure: 99,
420
- InvalidInstrumentationKey: 100,
421
- CannotParseAiBlobValue: 101,
422
- InvalidContentBlob: 102,
423
- TrackPageActionEventFailed: 103,
424
- FailedAddingCustomDefinedRequestContext: 104,
425
- InMemoryStorageBufferFull: 105
426
- };
338
+ var strEmpty$1 = "";
339
+ var strSetNextPlugin = "setNextPlugin";
340
+ var strIsInitialized = "isInitialized";
341
+ var strTeardown = "teardown";
342
+ var strCore = "core";
343
+ var strDisabled = "disabled";
344
+ var strDoTeardown = "_doTeardown";
427
345
 
428
- var strOnPrefix = "on";
429
- var strAttachEvent = "attachEvent";
430
- var strAddEventHelper = "addEventListener";
431
346
  var strToISOString = "toISOString";
432
347
  var cStrTrim = "trim";
433
348
  var strToString = "toString";
434
349
  var str__Proto = "__proto__";
435
350
  var strConstructor = "constructor";
436
- var _objDefineProperty = ObjDefineProperty;
351
+ var _objDefineProperty$1 = ObjDefineProperty;
437
352
  var _objFreeze = ObjClass.freeze;
438
353
  var _objKeys = ObjClass.keys;
439
354
  var StringProto = String[strShimPrototype];
@@ -475,25 +390,6 @@
475
390
  function isFunction(value) {
476
391
  return !!(value && typeof value === strShimFunction);
477
392
  }
478
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
479
- if (useCapture === void 0) { useCapture = false; }
480
- var result = false;
481
- if (!isNullOrUndefined(obj)) {
482
- try {
483
- if (!isNullOrUndefined(obj[strAddEventHelper])) {
484
- obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
485
- result = true;
486
- }
487
- else if (!isNullOrUndefined(obj[strAttachEvent])) {
488
- obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
489
- result = true;
490
- }
491
- }
492
- catch (e) {
493
- }
494
- }
495
- return result;
496
- }
497
393
  function normalizeJsName(name) {
498
394
  var value = name;
499
395
  if (value && isString(value)) {
@@ -630,7 +526,7 @@
630
526
  return result;
631
527
  }
632
528
  function objDefineAccessors(target, prop, getProp, setProp) {
633
- if (_objDefineProperty) {
529
+ if (_objDefineProperty$1) {
634
530
  try {
635
531
  var descriptor = {
636
532
  enumerable: true,
@@ -642,7 +538,7 @@
642
538
  if (setProp) {
643
539
  descriptor.set = setProp;
644
540
  }
645
- _objDefineProperty(target, prop, descriptor);
541
+ _objDefineProperty$1(target, prop, descriptor);
646
542
  return true;
647
543
  }
648
544
  catch (e) {
@@ -669,6 +565,47 @@
669
565
  }
670
566
  return theValue;
671
567
  }
568
+ function throwError(message) {
569
+ throw new Error(message);
570
+ }
571
+ function _createProxyFunction(source, funcName) {
572
+ var srcFunc = null;
573
+ var src = null;
574
+ if (isFunction(source)) {
575
+ srcFunc = source;
576
+ }
577
+ else {
578
+ src = source;
579
+ }
580
+ return function () {
581
+ var originalArguments = arguments;
582
+ if (srcFunc) {
583
+ src = srcFunc();
584
+ }
585
+ if (src) {
586
+ return src[funcName].apply(src, originalArguments);
587
+ }
588
+ };
589
+ }
590
+ function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
591
+ if (overwriteTarget === void 0) { overwriteTarget = true; }
592
+ if (target && name && source) {
593
+ if (overwriteTarget || isUndefined(target[name])) {
594
+ target[name] = _createProxyFunction(source, theFunc);
595
+ }
596
+ }
597
+ }
598
+ function createEnumStyle(values) {
599
+ var enumClass = {};
600
+ objForEachKey(values, function (field, value) {
601
+ enumClass[field] = value;
602
+ if (!isUndefined(enumClass[value])) {
603
+ throwError("[" + value + "] exists for " + field);
604
+ }
605
+ enumClass[value] = field;
606
+ });
607
+ return objFreeze(enumClass);
608
+ }
672
609
  function objExtend(obj, obj2, obj3, obj4, obj5, obj6) {
673
610
  var theArgs = arguments;
674
611
  var extended = theArgs[0] || {};
@@ -801,7 +738,7 @@
801
738
  var nav = getNavigator();
802
739
  if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
803
740
  _navUserAgentCheck = nav.userAgent;
804
- var userAgent = (_navUserAgentCheck || "").toLowerCase();
741
+ var userAgent = (_navUserAgentCheck || strEmpty$1).toLowerCase();
805
742
  _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
806
743
  }
807
744
  return _isTrident;
@@ -810,9 +747,9 @@
810
747
  if (userAgentStr === void 0) { userAgentStr = null; }
811
748
  if (!userAgentStr) {
812
749
  var navigator_1 = getNavigator() || {};
813
- userAgentStr = navigator_1 ? (navigator_1.userAgent || "").toLowerCase() : "";
750
+ userAgentStr = navigator_1 ? (navigator_1.userAgent || strEmpty$1).toLowerCase() : strEmpty$1;
814
751
  }
815
- var ua = (userAgentStr || "").toLowerCase();
752
+ var ua = (userAgentStr || strEmpty$1).toLowerCase();
816
753
  if (strContains(ua, strMsie)) {
817
754
  var doc = getDocument() || {};
818
755
  return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
@@ -827,7 +764,7 @@
827
764
  }
828
765
  function dumpObj(object) {
829
766
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
830
- var propertyValueDump = "";
767
+ var propertyValueDump = strEmpty$1;
831
768
  if (objectTypeDump === "[object Error]") {
832
769
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
833
770
  }
@@ -870,9 +807,9 @@
870
807
  var strWarnToConsole = "warnToConsole";
871
808
  function _sanitizeDiagnosticText(text) {
872
809
  if (text) {
873
- return "\"" + text.replace(/\"/g, "") + "\"";
810
+ return "\"" + text.replace(/\"/g, strEmpty$1) + "\"";
874
811
  }
875
- return "";
812
+ return strEmpty$1;
876
813
  }
877
814
  function _logToConsole(func, message) {
878
815
  var theConsole = getConsole();
@@ -894,12 +831,12 @@
894
831
  _self.message =
895
832
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
896
833
  msgId;
897
- var strProps = "";
834
+ var strProps = strEmpty$1;
898
835
  if (hasJSON()) {
899
836
  strProps = getJSON().stringify(properties);
900
837
  }
901
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
902
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
838
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty$1) +
839
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty$1);
903
840
  _self.message += diagnosticText;
904
841
  }
905
842
  _InternalLogMessage.dataType = "MessageData";
@@ -929,7 +866,7 @@
929
866
  throw message;
930
867
  }
931
868
  else {
932
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
869
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
933
870
  if (!isUndefined(message.message)) {
934
871
  var logLevel = _self.consoleLoggingLevel();
935
872
  if (isUserAct) {
@@ -947,7 +884,7 @@
947
884
  _self.logInternalMessage(severity, message);
948
885
  }
949
886
  else {
950
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
887
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
951
888
  }
952
889
  }
953
890
  };
@@ -979,13 +916,13 @@
979
916
  if (severity <= _self.telemetryLoggingLevel()) {
980
917
  _self.queue.push(message);
981
918
  _messageCount++;
982
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
919
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
983
920
  }
984
921
  if (_messageCount === _self.maxInternalMessageLimit()) {
985
922
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
986
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
923
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
987
924
  _self.queue.push(throttleMessage);
988
- if (severity === LoggingSeverity.CRITICAL) {
925
+ if (severity === 1 ) {
989
926
  _self.errorToConsole(throttleLimitMessage);
990
927
  }
991
928
  else {
@@ -1127,6 +1064,151 @@
1127
1064
  return func();
1128
1065
  }
1129
1066
 
1067
+ var UInt32Mask = 0x100000000;
1068
+ var MaxUInt32 = 0xffffffff;
1069
+ var _mwcSeeded = false;
1070
+ var _mwcW = 123456789;
1071
+ var _mwcZ = 987654321;
1072
+ function _mwcSeed(seedValue) {
1073
+ if (seedValue < 0) {
1074
+ seedValue >>>= 0;
1075
+ }
1076
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1077
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1078
+ _mwcSeeded = true;
1079
+ }
1080
+ function _autoSeedMwc() {
1081
+ try {
1082
+ var now = dateNow() & 0x7fffffff;
1083
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1084
+ }
1085
+ catch (e) {
1086
+ }
1087
+ }
1088
+ function random32(signed) {
1089
+ var value = 0;
1090
+ var c = getCrypto() || getMsCrypto();
1091
+ if (c && c.getRandomValues) {
1092
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1093
+ }
1094
+ if (value === 0 && isIE()) {
1095
+ if (!_mwcSeeded) {
1096
+ _autoSeedMwc();
1097
+ }
1098
+ value = mwcRandom32() & MaxUInt32;
1099
+ }
1100
+ if (value === 0) {
1101
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1102
+ }
1103
+ if (!signed) {
1104
+ value >>>= 0;
1105
+ }
1106
+ return value;
1107
+ }
1108
+ function mwcRandom32(signed) {
1109
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1110
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1111
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1112
+ if (!signed) {
1113
+ value >>>= 0;
1114
+ }
1115
+ return value;
1116
+ }
1117
+ function newId(maxLength) {
1118
+ if (maxLength === void 0) { maxLength = 22; }
1119
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1120
+ var number = random32() >>> 0;
1121
+ var chars = 0;
1122
+ var result = strEmpty$1;
1123
+ while (result.length < maxLength) {
1124
+ chars++;
1125
+ result += base64chars.charAt(number & 0x3F);
1126
+ number >>>= 6;
1127
+ if (chars === 5) {
1128
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1129
+ chars = 0;
1130
+ }
1131
+ }
1132
+ return result;
1133
+ }
1134
+
1135
+ var _objDefineProperty = ObjDefineProperty;
1136
+ var version = "2.7.3";
1137
+ var instanceName = "." + newId(6);
1138
+ var _dataUid = 0;
1139
+ function _createAccessor(target, prop, value) {
1140
+ if (_objDefineProperty) {
1141
+ try {
1142
+ _objDefineProperty(target, prop, {
1143
+ value: value,
1144
+ enumerable: false,
1145
+ configurable: true
1146
+ });
1147
+ return true;
1148
+ }
1149
+ catch (e) {
1150
+ }
1151
+ }
1152
+ return false;
1153
+ }
1154
+ function _canAcceptData(target) {
1155
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1156
+ }
1157
+ function _getCache(data, target) {
1158
+ var theCache = target[data.id];
1159
+ if (!theCache) {
1160
+ theCache = {};
1161
+ try {
1162
+ if (_canAcceptData(target)) {
1163
+ if (!_createAccessor(target, data.id, theCache)) {
1164
+ target[data.id] = theCache;
1165
+ }
1166
+ }
1167
+ }
1168
+ catch (e) {
1169
+ }
1170
+ }
1171
+ return theCache;
1172
+ }
1173
+ function createUniqueNamespace(name, includeVersion) {
1174
+ if (includeVersion === void 0) { includeVersion = false; }
1175
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1176
+ }
1177
+ function createElmNodeData(name) {
1178
+ var data = {
1179
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1180
+ accept: function (target) {
1181
+ return _canAcceptData(target);
1182
+ },
1183
+ get: function (target, name, defValue, addDefault) {
1184
+ var theCache = target[data.id];
1185
+ if (!theCache) {
1186
+ if (addDefault) {
1187
+ theCache = _getCache(data, target);
1188
+ theCache[normalizeJsName(name)] = defValue;
1189
+ }
1190
+ return defValue;
1191
+ }
1192
+ return theCache[normalizeJsName(name)];
1193
+ },
1194
+ kill: function (target, name) {
1195
+ if (target && target[name]) {
1196
+ try {
1197
+ delete target[name];
1198
+ }
1199
+ catch (e) {
1200
+ }
1201
+ }
1202
+ }
1203
+ };
1204
+ return data;
1205
+ }
1206
+
1207
+ var pluginStateData = createElmNodeData("plugin");
1208
+ function _getPluginState(plugin) {
1209
+ return pluginStateData.get(plugin, "state", {}, true);
1210
+ }
1211
+
1130
1212
  var strTelemetryPluginChain = "TelemetryPluginChain";
1131
1213
  var strHasRunFlags = "_hasRun";
1132
1214
  var strGetTelCtx = "_getTelCtx";
@@ -1140,53 +1222,69 @@
1140
1222
  }
1141
1223
  return createTelemetryProxyChain([startAt], config, core);
1142
1224
  }
1143
- function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1225
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1144
1226
  var _nextProxy = null;
1145
- var _onComplete = null;
1146
- if (startAt) {
1147
- _nextProxy = _getNextProxyStart(telemetryChain, config, core, startAt);
1148
- }
1149
- else {
1150
- _nextProxy = telemetryChain;
1227
+ var _onComplete = [];
1228
+ if (startAt !== null) {
1229
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1151
1230
  }
1152
1231
  var context = {
1153
- core: function () {
1154
- return core;
1155
- },
1156
- diagLog: function () {
1157
- return safeGetLogger(core, config);
1158
- },
1159
- getCfg: function () {
1160
- return config;
1161
- },
1162
- getExtCfg: _getExtCfg,
1163
- getConfig: _getConfig,
1164
- hasNext: function () {
1165
- return _nextProxy != null;
1166
- },
1167
- getNext: function () {
1168
- return _nextProxy;
1169
- },
1170
- setNext: function (nextPlugin) {
1171
- _nextProxy = nextPlugin;
1172
- },
1173
- processNext: function (env) {
1174
- _processChain(function (nextPlugin) {
1175
- nextPlugin.processTelemetry(env, context);
1232
+ _next: _moveNext,
1233
+ ctx: {
1234
+ core: function () { return core; },
1235
+ diagLog: function () {
1236
+ return safeGetLogger(core, config);
1237
+ },
1238
+ getCfg: function () {
1239
+ return config;
1240
+ },
1241
+ getExtCfg: _getExtCfg,
1242
+ getConfig: _getConfig,
1243
+ hasNext: function () {
1244
+ return !!_nextProxy;
1245
+ },
1246
+ getNext: function () {
1247
+ return _nextProxy;
1248
+ },
1249
+ setNext: function (nextPlugin) {
1250
+ _nextProxy = nextPlugin;
1251
+ },
1252
+ iterate: _iterateChain,
1253
+ onComplete: _addOnComplete
1254
+ }
1255
+ };
1256
+ function _addOnComplete(onComplete, that) {
1257
+ var args = [];
1258
+ for (var _i = 2; _i < arguments.length; _i++) {
1259
+ args[_i - 2] = arguments[_i];
1260
+ }
1261
+ if (onComplete) {
1262
+ _onComplete.push({
1263
+ func: onComplete,
1264
+ self: !isUndefined(that) ? that : context.ctx,
1265
+ args: args
1176
1266
  });
1177
- },
1178
- iterate: _iterateChain,
1179
- createNew: function (plugins, startAt) {
1180
- if (plugins === void 0) { plugins = null; }
1181
- if (isArray(plugins)) {
1182
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1267
+ }
1268
+ }
1269
+ function _moveNext() {
1270
+ var nextProxy = _nextProxy;
1271
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1272
+ if (!nextProxy) {
1273
+ var onComplete = _onComplete;
1274
+ if (onComplete && onComplete.length > 0) {
1275
+ arrForEach(onComplete, function (completeDetails) {
1276
+ try {
1277
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1278
+ }
1279
+ catch (e) {
1280
+ core.logger.throwInternal(2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1281
+ }
1282
+ });
1283
+ _onComplete = [];
1183
1284
  }
1184
- return createProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1185
- },
1186
- onComplete: function (onComplete) {
1187
- _onComplete = onComplete;
1188
1285
  }
1189
- };
1286
+ return nextProxy;
1287
+ }
1190
1288
  function _getExtCfg(identifier, defaultValue, mergeDefault) {
1191
1289
  if (defaultValue === void 0) { defaultValue = {}; }
1192
1290
  if (mergeDefault === void 0) { mergeDefault = 0 ; }
@@ -1229,29 +1327,53 @@
1229
1327
  }
1230
1328
  return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1231
1329
  }
1232
- function _processChain(cb) {
1233
- var nextPlugin = _nextProxy;
1234
- if (nextPlugin) {
1235
- _nextProxy = nextPlugin.getNext();
1236
- cb(nextPlugin);
1237
- }
1238
- else {
1239
- if (_onComplete) {
1240
- _onComplete();
1241
- _onComplete = null;
1330
+ function _iterateChain(cb) {
1331
+ var nextPlugin;
1332
+ while (!!(nextPlugin = context._next())) {
1333
+ var plugin = nextPlugin.getPlugin();
1334
+ if (plugin) {
1335
+ cb(plugin);
1242
1336
  }
1243
1337
  }
1244
1338
  }
1245
- function _iterateChain(cb) {
1246
- while (_nextProxy) {
1247
- _processChain(function (nextPlugin) {
1248
- var plugin = nextPlugin.getPlugin();
1249
- if (plugin) {
1250
- cb(plugin);
1251
- }
1252
- });
1339
+ return context;
1340
+ }
1341
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1342
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1343
+ var context = internalContext.ctx;
1344
+ function _processNext(env) {
1345
+ var nextPlugin = internalContext._next();
1346
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1347
+ return !nextPlugin;
1348
+ }
1349
+ function _createNew(plugins, startAt) {
1350
+ if (plugins === void 0) { plugins = null; }
1351
+ if (isArray(plugins)) {
1352
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1353
+ }
1354
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1355
+ }
1356
+ context.processNext = _processNext;
1357
+ context.createNew = _createNew;
1358
+ return context;
1359
+ }
1360
+ function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
1361
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1362
+ var context = internalContext.ctx;
1363
+ function _processNext(unloadState) {
1364
+ var nextPlugin = internalContext._next();
1365
+ nextPlugin && nextPlugin.unload(context, unloadState);
1366
+ return !nextPlugin;
1367
+ }
1368
+ function _createNew(plugins, startAt) {
1369
+ if (plugins === void 0) { plugins = null; }
1370
+ if (isArray(plugins)) {
1371
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1253
1372
  }
1373
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
1254
1374
  }
1375
+ context.processNext = _processNext;
1376
+ context.createNew = _createNew;
1255
1377
  return context;
1256
1378
  }
1257
1379
  function createTelemetryProxyChain(plugins, config, core, startAt) {
@@ -1299,32 +1421,35 @@
1299
1421
  return nextProxy;
1300
1422
  },
1301
1423
  processTelemetry: _processTelemetry,
1424
+ unload: _unloadPlugin,
1302
1425
  _id: chainId,
1303
1426
  _setNext: function (nextPlugin) {
1304
1427
  nextProxy = nextPlugin;
1305
1428
  }
1306
1429
  };
1307
- function _processChain(itemCtx, processPluginFn, processProxyFn, name, details, isAsync) {
1430
+ function _getTelCtx() {
1431
+ var itemCtx;
1432
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1433
+ itemCtx = plugin[strGetTelCtx]();
1434
+ }
1308
1435
  if (!itemCtx) {
1309
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1310
- itemCtx = plugin[strGetTelCtx]();
1311
- }
1312
- if (!itemCtx) {
1313
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1314
- }
1436
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1315
1437
  }
1438
+ return itemCtx;
1439
+ }
1440
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1441
+ var hasRun = false;
1316
1442
  var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1317
1443
  var hasRunContext = itemCtx[strHasRunFlags];
1318
1444
  if (!hasRunContext) {
1319
1445
  hasRunContext = itemCtx[strHasRunFlags] = {};
1320
1446
  }
1321
- doPerf(itemCtx.core(), function () { return identifier + ":" + name; }, function () {
1322
- hasRunContext[chainId] = true;
1323
- var hasRun = false;
1324
- itemCtx.setNext(nextProxy);
1325
- if (plugin) {
1447
+ itemCtx.setNext(nextProxy);
1448
+ if (plugin) {
1449
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1450
+ hasRunContext[chainId] = true;
1326
1451
  try {
1327
- var nextId = nextProxy ? nextProxy._id : "";
1452
+ var nextId = nextProxy ? nextProxy._id : strEmpty$1;
1328
1453
  if (nextId) {
1329
1454
  hasRunContext[nextId] = false;
1330
1455
  }
@@ -1336,18 +1461,21 @@
1336
1461
  hasRun = true;
1337
1462
  }
1338
1463
  if (!nextProxy || !hasNextRun) {
1339
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1464
+ itemCtx.diagLog().throwInternal(1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1340
1465
  }
1341
1466
  }
1342
- }
1343
- if (nextProxy && !hasRun) {
1344
- processProxyFn(itemCtx);
1345
- }
1346
- }, details, isAsync);
1467
+ }, details, isAsync);
1468
+ }
1469
+ return hasRun;
1347
1470
  }
1348
1471
  function _processTelemetry(env, itemCtx) {
1349
- _processChain(itemCtx, function (itemCtx) {
1350
- if (!hasProcessTelemetry) {
1472
+ itemCtx = itemCtx || _getTelCtx();
1473
+ function _callProcessTelemetry(itemCtx) {
1474
+ if (!plugin || !hasProcessTelemetry) {
1475
+ return false;
1476
+ }
1477
+ var pluginState = _getPluginState(plugin);
1478
+ if (pluginState[strTeardown] || pluginState[strDisabled]) {
1351
1479
  return false;
1352
1480
  }
1353
1481
  if (hasSetNext) {
@@ -1355,15 +1483,61 @@
1355
1483
  }
1356
1484
  plugin.processTelemetry(env, itemCtx);
1357
1485
  return true;
1358
- }, function (itemCtx) {
1359
- nextProxy.processTelemetry(env, itemCtx);
1360
- }, "processTelemetry", function () { return ({ item: env }); }, !(env.sync));
1486
+ }
1487
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1488
+ itemCtx.processNext(env);
1489
+ }
1490
+ }
1491
+ function _unloadPlugin(unloadCtx, unloadState) {
1492
+ function _callTeardown() {
1493
+ var hasRun = false;
1494
+ if (plugin) {
1495
+ var pluginState = _getPluginState(plugin);
1496
+ var pluginCore = plugin[strCore] || pluginState.core;
1497
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1498
+ pluginState[strCore] = null;
1499
+ pluginState[strTeardown] = true;
1500
+ pluginState[strIsInitialized] = false;
1501
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1502
+ hasRun = true;
1503
+ }
1504
+ }
1505
+ }
1506
+ return hasRun;
1507
+ }
1508
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1509
+ unloadCtx.processNext(unloadState);
1510
+ }
1361
1511
  }
1362
1512
  return objFreeze(proxyChain);
1363
1513
  }
1364
1514
 
1365
1515
  var strExtensionConfig = "extensionConfig";
1366
1516
 
1517
+ function createUnloadHandlerContainer() {
1518
+ var handlers = [];
1519
+ function _addHandler(handler) {
1520
+ if (handler) {
1521
+ handlers.push(handler);
1522
+ }
1523
+ }
1524
+ function _runHandlers(unloadCtx, unloadState) {
1525
+ arrForEach(handlers, function (handler) {
1526
+ try {
1527
+ handler(unloadCtx, unloadState);
1528
+ }
1529
+ catch (e) {
1530
+ unloadCtx.diagLog().throwInternal(2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1531
+ }
1532
+ });
1533
+ handlers = [];
1534
+ }
1535
+ return {
1536
+ add: _addHandler,
1537
+ run: _runHandlers
1538
+ };
1539
+ }
1540
+
1367
1541
  var strGetPlugin = "getPlugin";
1368
1542
  var BaseTelemetryPlugin = /** @class */ (function () {
1369
1543
  function BaseTelemetryPlugin() {
@@ -1371,6 +1545,7 @@
1371
1545
  var _isinitialized;
1372
1546
  var _rootCtx;
1373
1547
  var _nextPlugin;
1548
+ var _unloadHandlerContainer;
1374
1549
  var _hooks;
1375
1550
  _initDefaults();
1376
1551
  dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
@@ -1378,6 +1553,39 @@
1378
1553
  _setDefaults(config, core, pluginChain);
1379
1554
  _isinitialized = true;
1380
1555
  };
1556
+ _self.teardown = function (unloadCtx, unloadState) {
1557
+ if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
1558
+ return;
1559
+ }
1560
+ var result;
1561
+ var unloadDone = false;
1562
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1563
+ var theUnloadState = unloadState || {
1564
+ reason: 0 ,
1565
+ isAsync: false
1566
+ };
1567
+ function _unloadCallback() {
1568
+ if (!unloadDone) {
1569
+ unloadDone = true;
1570
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1571
+ arrForEach(_hooks, function (fn) {
1572
+ fn.rm();
1573
+ });
1574
+ _hooks = [];
1575
+ if (result === true) {
1576
+ theUnloadCtx.processNext(theUnloadState);
1577
+ }
1578
+ _initDefaults();
1579
+ }
1580
+ }
1581
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1582
+ _unloadCallback();
1583
+ }
1584
+ else {
1585
+ result = true;
1586
+ }
1587
+ return result;
1588
+ };
1381
1589
  _self._addHook = function (hooks) {
1382
1590
  if (hooks) {
1383
1591
  if (isArray(hooks)) {
@@ -1388,17 +1596,18 @@
1388
1596
  }
1389
1597
  }
1390
1598
  };
1599
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1391
1600
  });
1392
1601
  _self.diagLog = function (itemCtx) {
1393
1602
  return _getTelCtx(itemCtx).diagLog();
1394
1603
  };
1395
- _self.isInitialized = function () {
1604
+ _self[strIsInitialized] = function () {
1396
1605
  return _isinitialized;
1397
1606
  };
1398
1607
  _self.setInitialized = function (isInitialized) {
1399
1608
  _isinitialized = isInitialized;
1400
1609
  };
1401
- _self.setNextPlugin = function (next) {
1610
+ _self[strSetNextPlugin] = function (next) {
1402
1611
  _nextPlugin = next;
1403
1612
  };
1404
1613
  _self.processNext = function (env, itemCtx) {
@@ -1444,65 +1653,122 @@
1444
1653
  _rootCtx = null;
1445
1654
  _nextPlugin = null;
1446
1655
  _hooks = [];
1656
+ _unloadHandlerContainer = createUnloadHandlerContainer();
1447
1657
  }
1448
1658
  }
1449
1659
  return BaseTelemetryPlugin;
1450
1660
  }());
1451
1661
 
1452
- var UInt32Mask = 0x100000000;
1453
- var MaxUInt32 = 0xffffffff;
1454
- var _mwcSeeded = false;
1455
- var _mwcW = 123456789;
1456
- var _mwcZ = 987654321;
1457
- function _mwcSeed(seedValue) {
1458
- if (seedValue < 0) {
1459
- seedValue >>>= 0;
1662
+ var strOnPrefix = "on";
1663
+ var strAttachEvent = "attachEvent";
1664
+ var strAddEventHelper = "addEventListener";
1665
+ var strEvents = "events";
1666
+ createUniqueNamespace("aiEvtPageHide");
1667
+ createUniqueNamespace("aiEvtPageShow");
1668
+ var _guid = 1;
1669
+ var elmNodeData = createElmNodeData("events");
1670
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1671
+ function _normalizeNamespace(name) {
1672
+ if (name && name.replace) {
1673
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
1674
+ }
1675
+ return name;
1676
+ }
1677
+ function _getEvtNamespace(eventName, namespaces) {
1678
+ if (namespaces) {
1679
+ var theNamespace_1 = "";
1680
+ if (isArray(namespaces)) {
1681
+ theNamespace_1 = "";
1682
+ arrForEach(namespaces, function (name) {
1683
+ name = _normalizeNamespace(name);
1684
+ if (name) {
1685
+ if (name[0] !== ".") {
1686
+ name = "." + name;
1687
+ }
1688
+ theNamespace_1 += name;
1689
+ }
1690
+ });
1691
+ }
1692
+ else {
1693
+ theNamespace_1 = _normalizeNamespace(namespaces);
1694
+ }
1695
+ if (theNamespace_1) {
1696
+ if (theNamespace_1[0] !== ".") {
1697
+ theNamespace_1 = "." + theNamespace_1;
1698
+ }
1699
+ eventName = (eventName || "") + theNamespace_1;
1700
+ }
1460
1701
  }
1461
- _mwcW = (123456789 + seedValue) & MaxUInt32;
1462
- _mwcZ = (987654321 - seedValue) & MaxUInt32;
1463
- _mwcSeeded = true;
1702
+ var parsedEvent = (eventNamespace.exec(eventName) || []);
1703
+ return {
1704
+ type: parsedEvent[1],
1705
+ ns: ((parsedEvent[2] || "").split(".").sort()).join(".")
1706
+ };
1464
1707
  }
1465
- function _autoSeedMwc() {
1466
- try {
1467
- var now = dateNow() & 0x7fffffff;
1468
- _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1469
- }
1470
- catch (e) {
1708
+ function _getRegisteredEvents(target, evtName, addDefault) {
1709
+ if (addDefault === void 0) { addDefault = true; }
1710
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1711
+ var registeredEvents = aiEvts[evtName];
1712
+ if (!registeredEvents) {
1713
+ registeredEvents = aiEvts[evtName] = [];
1471
1714
  }
1715
+ return registeredEvents;
1472
1716
  }
1473
- function random32(signed) {
1474
- var value = 0;
1475
- var c = getCrypto() || getMsCrypto();
1476
- if (c && c.getRandomValues) {
1477
- value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1478
- }
1479
- if (value === 0 && isIE()) {
1480
- if (!_mwcSeeded) {
1481
- _autoSeedMwc();
1717
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
1718
+ var result = false;
1719
+ if (obj && evtName && evtName.type && handlerRef) {
1720
+ if (obj[strAddEventHelper]) {
1721
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1722
+ result = true;
1723
+ }
1724
+ else if (obj[strAttachEvent]) {
1725
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1726
+ result = true;
1482
1727
  }
1483
- value = mwcRandom32() & MaxUInt32;
1484
1728
  }
1485
- if (value === 0) {
1486
- value = Math.floor((UInt32Mask * Math.random()) | 0);
1729
+ return result;
1730
+ }
1731
+ function mergeEvtNamespace(theNamespace, namespaces) {
1732
+ var newNamespaces;
1733
+ if (namespaces) {
1734
+ if (isArray(namespaces)) {
1735
+ newNamespaces = [theNamespace].concat(namespaces);
1736
+ }
1737
+ else {
1738
+ newNamespaces = [theNamespace, namespaces];
1739
+ }
1487
1740
  }
1488
- if (!signed) {
1489
- value >>>= 0;
1741
+ else {
1742
+ newNamespaces = theNamespace;
1490
1743
  }
1491
- return value;
1744
+ return newNamespaces;
1492
1745
  }
1493
- function mwcRandom32(signed) {
1494
- _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1495
- _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1496
- var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1497
- if (!signed) {
1498
- value >>>= 0;
1746
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
1747
+ if (useCapture === void 0) { useCapture = false; }
1748
+ var result = false;
1749
+ if (target) {
1750
+ try {
1751
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
1752
+ result = _doAttach(target, evtName, handlerRef, useCapture);
1753
+ if (result && elmNodeData.accept(target)) {
1754
+ var registeredEvent = {
1755
+ guid: _guid++,
1756
+ evtName: evtName,
1757
+ handler: handlerRef,
1758
+ capture: useCapture
1759
+ };
1760
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
1761
+ }
1762
+ }
1763
+ catch (e) {
1764
+ }
1499
1765
  }
1500
- return value;
1766
+ return result;
1501
1767
  }
1502
1768
 
1503
1769
  function generateW3CId() {
1504
1770
  var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
1505
- var oct = "", tmp;
1771
+ var oct = strEmpty$1, tmp;
1506
1772
  for (var a = 0; a < 4; a++) {
1507
1773
  tmp = random32();
1508
1774
  oct +=
@@ -1519,6 +1785,95 @@
1519
1785
  return oct.substr(0, 8) + oct.substr(9, 4) + "4" + oct.substr(13, 3) + clockSequenceHi + oct.substr(16, 3) + oct.substr(19, 12);
1520
1786
  }
1521
1787
 
1788
+ var LoggingSeverity = createEnumStyle({
1789
+ CRITICAL: 1 ,
1790
+ WARNING: 2
1791
+ });
1792
+ var _InternalMessageId = createEnumStyle({
1793
+ BrowserDoesNotSupportLocalStorage: 0 ,
1794
+ BrowserCannotReadLocalStorage: 1 ,
1795
+ BrowserCannotReadSessionStorage: 2 ,
1796
+ BrowserCannotWriteLocalStorage: 3 ,
1797
+ BrowserCannotWriteSessionStorage: 4 ,
1798
+ BrowserFailedRemovalFromLocalStorage: 5 ,
1799
+ BrowserFailedRemovalFromSessionStorage: 6 ,
1800
+ CannotSendEmptyTelemetry: 7 ,
1801
+ ClientPerformanceMathError: 8 ,
1802
+ ErrorParsingAISessionCookie: 9 ,
1803
+ ErrorPVCalc: 10 ,
1804
+ ExceptionWhileLoggingError: 11 ,
1805
+ FailedAddingTelemetryToBuffer: 12 ,
1806
+ FailedMonitorAjaxAbort: 13 ,
1807
+ FailedMonitorAjaxDur: 14 ,
1808
+ FailedMonitorAjaxOpen: 15 ,
1809
+ FailedMonitorAjaxRSC: 16 ,
1810
+ FailedMonitorAjaxSend: 17 ,
1811
+ FailedMonitorAjaxGetCorrelationHeader: 18 ,
1812
+ FailedToAddHandlerForOnBeforeUnload: 19 ,
1813
+ FailedToSendQueuedTelemetry: 20 ,
1814
+ FailedToReportDataLoss: 21 ,
1815
+ FlushFailed: 22 ,
1816
+ MessageLimitPerPVExceeded: 23 ,
1817
+ MissingRequiredFieldSpecification: 24 ,
1818
+ NavigationTimingNotSupported: 25 ,
1819
+ OnError: 26 ,
1820
+ SessionRenewalDateIsZero: 27 ,
1821
+ SenderNotInitialized: 28 ,
1822
+ StartTrackEventFailed: 29 ,
1823
+ StopTrackEventFailed: 30 ,
1824
+ StartTrackFailed: 31 ,
1825
+ StopTrackFailed: 32 ,
1826
+ TelemetrySampledAndNotSent: 33 ,
1827
+ TrackEventFailed: 34 ,
1828
+ TrackExceptionFailed: 35 ,
1829
+ TrackMetricFailed: 36 ,
1830
+ TrackPVFailed: 37 ,
1831
+ TrackPVFailedCalc: 38 ,
1832
+ TrackTraceFailed: 39 ,
1833
+ TransmissionFailed: 40 ,
1834
+ FailedToSetStorageBuffer: 41 ,
1835
+ FailedToRestoreStorageBuffer: 42 ,
1836
+ InvalidBackendResponse: 43 ,
1837
+ FailedToFixDepricatedValues: 44 ,
1838
+ InvalidDurationValue: 45 ,
1839
+ TelemetryEnvelopeInvalid: 46 ,
1840
+ CreateEnvelopeError: 47 ,
1841
+ CannotSerializeObject: 48 ,
1842
+ CannotSerializeObjectNonSerializable: 49 ,
1843
+ CircularReferenceDetected: 50 ,
1844
+ ClearAuthContextFailed: 51 ,
1845
+ ExceptionTruncated: 52 ,
1846
+ IllegalCharsInName: 53 ,
1847
+ ItemNotInArray: 54 ,
1848
+ MaxAjaxPerPVExceeded: 55 ,
1849
+ MessageTruncated: 56 ,
1850
+ NameTooLong: 57 ,
1851
+ SampleRateOutOfRange: 58 ,
1852
+ SetAuthContextFailed: 59 ,
1853
+ SetAuthContextFailedAccountName: 60 ,
1854
+ StringValueTooLong: 61 ,
1855
+ StartCalledMoreThanOnce: 62 ,
1856
+ StopCalledWithoutStart: 63 ,
1857
+ TelemetryInitializerFailed: 64 ,
1858
+ TrackArgumentsNotSpecified: 65 ,
1859
+ UrlTooLong: 66 ,
1860
+ SessionStorageBufferFull: 67 ,
1861
+ CannotAccessCookie: 68 ,
1862
+ IdTooLong: 69 ,
1863
+ InvalidEvent: 70 ,
1864
+ FailedMonitorAjaxSetRequestHeader: 71 ,
1865
+ SendBrowserInfoOnUserInit: 72 ,
1866
+ PluginException: 73 ,
1867
+ NotificationException: 74 ,
1868
+ SnippetScriptLoadFailure: 99 ,
1869
+ InvalidInstrumentationKey: 100 ,
1870
+ CannotParseAiBlobValue: 101 ,
1871
+ InvalidContentBlob: 102 ,
1872
+ TrackPageActionEventFailed: 103 ,
1873
+ FailedAddingCustomDefinedRequestContext: 104 ,
1874
+ InMemoryStorageBufferFull: 105
1875
+ });
1876
+
1522
1877
  var aiInstrumentHooks = "_aiHooks";
1523
1878
  var cbNames = [
1524
1879
  "req", "rsp", "hkErr", "fnErr"
@@ -1694,7 +2049,7 @@
1694
2049
  name = strTrim(name.toString());
1695
2050
  if (name.length > 150 ) {
1696
2051
  nameTrunc = name.substring(0, 150 );
1697
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
2052
+ logger && logger.throwInternal(2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
1698
2053
  }
1699
2054
  }
1700
2055
  return nameTrunc || name;
@@ -1707,7 +2062,7 @@
1707
2062
  value = strTrim(value);
1708
2063
  if (value.toString().length > maxLength) {
1709
2064
  valueTrunc = value.toString().substring(0, maxLength);
1710
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
2065
+ logger && logger.throwInternal(2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
1711
2066
  }
1712
2067
  }
1713
2068
  return valueTrunc || value;
@@ -1724,7 +2079,7 @@
1724
2079
  value = getJSON().stringify(value);
1725
2080
  }
1726
2081
  catch (e) {
1727
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
2082
+ logger && logger.throwInternal(2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
1728
2083
  }
1729
2084
  }
1730
2085
  value = dataSanitizeString(logger, value, 8192 );
@@ -1752,7 +2107,7 @@
1752
2107
  input = strTrim(input);
1753
2108
  if (input.length > maxLength) {
1754
2109
  inputTrunc = input.substring(0, maxLength);
1755
- logger && logger.throwInternal(LoggingSeverity.WARNING, _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
2110
+ logger && logger.throwInternal(2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
1756
2111
  }
1757
2112
  }
1758
2113
  return inputTrunc || input;
@@ -1762,39 +2117,28 @@
1762
2117
  return s.substr(s.length - 3);
1763
2118
  }
1764
2119
 
2120
+ var strEmpty = "";
1765
2121
  function msToTimeSpan(totalms) {
1766
2122
  if (isNaN(totalms) || totalms < 0) {
1767
2123
  totalms = 0;
1768
2124
  }
1769
2125
  totalms = Math.round(totalms);
1770
- var ms = "" + totalms % 1000;
1771
- var sec = "" + Math.floor(totalms / 1000) % 60;
1772
- var min = "" + Math.floor(totalms / (1000 * 60)) % 60;
1773
- var hour = "" + Math.floor(totalms / (1000 * 60 * 60)) % 24;
2126
+ var ms = strEmpty + totalms % 1000;
2127
+ var sec = strEmpty + Math.floor(totalms / 1000) % 60;
2128
+ var min = strEmpty + Math.floor(totalms / (1000 * 60)) % 60;
2129
+ var hour = strEmpty + Math.floor(totalms / (1000 * 60 * 60)) % 24;
1774
2130
  var days = Math.floor(totalms / (1000 * 60 * 60 * 24));
1775
2131
  ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
1776
2132
  sec = sec.length < 2 ? "0" + sec : sec;
1777
2133
  min = min.length < 2 ? "0" + min : min;
1778
2134
  hour = hour.length < 2 ? "0" + hour : hour;
1779
- return (days > 0 ? days + "." : "") + hour + ":" + min + ":" + sec + "." + ms;
2135
+ return (days > 0 ? days + "." : strEmpty) + hour + ":" + min + ":" + sec + "." + ms;
1780
2136
  }
1781
2137
 
1782
2138
  var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
1783
2139
  var strNotSpecified = "not_specified";
1784
2140
  var strIkey = "iKey";
1785
2141
 
1786
- var StorageType;
1787
- (function (StorageType) {
1788
- StorageType[StorageType["LocalStorage"] = 0] = "LocalStorage";
1789
- StorageType[StorageType["SessionStorage"] = 1] = "SessionStorage";
1790
- })(StorageType || (StorageType = {}));
1791
- var DistributedTracingModes;
1792
- (function (DistributedTracingModes) {
1793
- DistributedTracingModes[DistributedTracingModes["AI"] = 0] = "AI";
1794
- DistributedTracingModes[DistributedTracingModes["AI_AND_W3C"] = 1] = "AI_AND_W3C";
1795
- DistributedTracingModes[DistributedTracingModes["W3C"] = 2] = "W3C";
1796
- })(DistributedTracingModes || (DistributedTracingModes = {}));
1797
-
1798
2142
  var _document = getDocument() || {};
1799
2143
  var _htmlAnchorIdx = 0;
1800
2144
  var _htmlAnchorElement = [null, null, null, null, null];
@@ -2419,19 +2763,21 @@
2419
2763
  var _enableAjaxPerfTracking = false;
2420
2764
  var _maxAjaxCallsPerView = 0;
2421
2765
  var _enableResponseHeaderTracking = false;
2422
- var _hooks = [];
2423
2766
  var _disabledUrls = {};
2424
2767
  var _excludeRequestFromAutoTrackingPatterns;
2425
2768
  var _addRequestContext;
2426
- dynamicProto(AjaxMonitor, _this, function (_self, base) {
2769
+ var _evtNamespace;
2770
+ dynamicProto(AjaxMonitor, _this, function (_self, _base) {
2771
+ var _addHook = _base._addHook;
2427
2772
  _self.initialize = function (config, core, extensions, pluginChain) {
2428
2773
  if (!_self.isInitialized()) {
2429
- base.initialize(config, core, extensions, pluginChain);
2774
+ _base.initialize(config, core, extensions, pluginChain);
2430
2775
  var ctx_1 = _self._getTelCtx();
2431
2776
  var defaultConfig = AjaxMonitor.getDefaultConfig();
2432
2777
  objForEachKey(defaultConfig, function (field, value) {
2433
2778
  _config[field] = ctx_1.getConfig(AjaxMonitor.identifier, field, value);
2434
2779
  });
2780
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace("ajax"), core && core.evtNamespace && core.evtNamespace());
2435
2781
  var distributedTracingMode = _config.distributedTracingMode;
2436
2782
  _enableRequestHeaderTracking = _config.enableRequestHeaderTracking;
2437
2783
  _enableAjaxErrorStatusText = _config.enableAjaxErrorStatusText;
@@ -2440,8 +2786,8 @@
2440
2786
  _enableResponseHeaderTracking = _config.enableResponseHeaderTracking;
2441
2787
  _excludeRequestFromAutoTrackingPatterns = _config.excludeRequestFromAutoTrackingPatterns;
2442
2788
  _addRequestContext = _config.addRequestContext;
2443
- _isUsingAIHeaders = distributedTracingMode === DistributedTracingModes.AI || distributedTracingMode === DistributedTracingModes.AI_AND_W3C;
2444
- _isUsingW3CHeaders = distributedTracingMode === DistributedTracingModes.AI_AND_W3C || distributedTracingMode === DistributedTracingModes.W3C;
2789
+ _isUsingAIHeaders = distributedTracingMode === 0 || distributedTracingMode === 1 ;
2790
+ _isUsingW3CHeaders = distributedTracingMode === 1 || distributedTracingMode === 2 ;
2445
2791
  if (_enableAjaxPerfTracking) {
2446
2792
  var iKey = config.instrumentationKey || "unkwn";
2447
2793
  if (iKey.length > 5) {
@@ -2469,14 +2815,9 @@
2469
2815
  }
2470
2816
  }
2471
2817
  };
2472
- _self.teardown = function () {
2473
- arrForEach(_hooks, function (fn) {
2474
- fn.rm();
2475
- });
2476
- _hooks = [];
2818
+ _self._doTeardown = function () {
2477
2819
  _fetchInitialized = false;
2478
2820
  _xhrInitialized = false;
2479
- _self.setInitialized(false);
2480
2821
  };
2481
2822
  _self.trackDependencyData = function (dependency, properties) {
2482
2823
  _self[strTrackDependencyDataInternal](dependency, properties);
@@ -2543,8 +2884,8 @@
2543
2884
  };
2544
2885
  _self[strTrackDependencyDataInternal] = function (dependency, properties, systemProperties) {
2545
2886
  if (_maxAjaxCallsPerView === -1 || _trackAjaxAttempts < _maxAjaxCallsPerView) {
2546
- if ((_config.distributedTracingMode === DistributedTracingModes.W3C
2547
- || _config.distributedTracingMode === DistributedTracingModes.AI_AND_W3C)
2887
+ if ((_config.distributedTracingMode === 2
2888
+ || _config.distributedTracingMode === 1 )
2548
2889
  && typeof dependency.id === "string" && dependency.id[dependency.id.length - 1] !== ".") {
2549
2890
  dependency.id += ".";
2550
2891
  }
@@ -2579,7 +2920,7 @@
2579
2920
  var global = getGlobal();
2580
2921
  var isPolyfill = fetch.polyfill;
2581
2922
  if (_config.disableFetchTracking === false) {
2582
- _hooks.push(InstrumentFunc(global, strFetch, {
2923
+ _addHook(InstrumentFunc(global, strFetch, {
2583
2924
  req: function (callDetails, input, init) {
2584
2925
  var fetchData;
2585
2926
  if (_fetchInitialized &&
@@ -2627,7 +2968,7 @@
2627
2968
  _fetchInitialized = true;
2628
2969
  }
2629
2970
  else if (isPolyfill) {
2630
- _hooks.push(InstrumentFunc(global, strFetch, {
2971
+ _addHook(InstrumentFunc(global, strFetch, {
2631
2972
  req: function (callDetails, input, init) {
2632
2973
  _isDisabledRequest(null, input, init);
2633
2974
  }
@@ -2638,7 +2979,7 @@
2638
2979
  }
2639
2980
  }
2640
2981
  function _hookProto(target, funcName, callbacks) {
2641
- _hooks.push(InstrumentProto(target, funcName, callbacks));
2982
+ _addHook(InstrumentProto(target, funcName, callbacks));
2642
2983
  }
2643
2984
  function _instrumentXhr() {
2644
2985
  if (_supportsAjaxMonitoring(_self) && !_xhrInitialized) {
@@ -2760,7 +3101,7 @@
2760
3101
  xhr[strAjaxData] = ajaxData;
2761
3102
  }
2762
3103
  function _attachToOnReadyStateChange(xhr) {
2763
- xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = attachEvent(xhr, "readystatechange", function () {
3104
+ xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = eventOn(xhr, "readystatechange", function () {
2764
3105
  try {
2765
3106
  if (xhr && xhr.readyState === 4 && _isMonitoredXhrInstance(xhr)) {
2766
3107
  _onAjaxComplete(xhr);
@@ -2775,7 +3116,7 @@
2775
3116
  });
2776
3117
  }
2777
3118
  }
2778
- });
3119
+ }, _evtNamespace);
2779
3120
  }
2780
3121
  function _getResponseText(xhr) {
2781
3122
  try {
@@ -3060,7 +3401,7 @@
3060
3401
  disableFetchTracking: true,
3061
3402
  excludeRequestFromAutoTrackingPatterns: undefined,
3062
3403
  disableCorrelationHeaders: false,
3063
- distributedTracingMode: DistributedTracingModes.AI_AND_W3C,
3404
+ distributedTracingMode: 1 ,
3064
3405
  correlationHeaderExcludedDomains: [
3065
3406
  "*.blob.core.windows.net",
3066
3407
  "*.blob.core.chinacloudapi.cn",