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

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-02
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,20 @@
669
565
  }
670
566
  return theValue;
671
567
  }
568
+ function throwError(message) {
569
+ throw new Error(message);
570
+ }
571
+ function createEnumStyle(values) {
572
+ var enumClass = {};
573
+ objForEachKey(values, function (field, value) {
574
+ enumClass[field] = value;
575
+ if (!isUndefined(enumClass[value])) {
576
+ throwError("Value: [" + value + "] already exists for " + field);
577
+ }
578
+ enumClass[value] = field;
579
+ });
580
+ return objFreeze(enumClass);
581
+ }
672
582
  function objExtend(obj, obj2, obj3, obj4, obj5, obj6) {
673
583
  var theArgs = arguments;
674
584
  var extended = theArgs[0] || {};
@@ -801,7 +711,7 @@
801
711
  var nav = getNavigator();
802
712
  if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
803
713
  _navUserAgentCheck = nav.userAgent;
804
- var userAgent = (_navUserAgentCheck || "").toLowerCase();
714
+ var userAgent = (_navUserAgentCheck || strEmpty$1).toLowerCase();
805
715
  _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
806
716
  }
807
717
  return _isTrident;
@@ -810,9 +720,9 @@
810
720
  if (userAgentStr === void 0) { userAgentStr = null; }
811
721
  if (!userAgentStr) {
812
722
  var navigator_1 = getNavigator() || {};
813
- userAgentStr = navigator_1 ? (navigator_1.userAgent || "").toLowerCase() : "";
723
+ userAgentStr = navigator_1 ? (navigator_1.userAgent || strEmpty$1).toLowerCase() : strEmpty$1;
814
724
  }
815
- var ua = (userAgentStr || "").toLowerCase();
725
+ var ua = (userAgentStr || strEmpty$1).toLowerCase();
816
726
  if (strContains(ua, strMsie)) {
817
727
  var doc = getDocument() || {};
818
728
  return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
@@ -827,7 +737,7 @@
827
737
  }
828
738
  function dumpObj(object) {
829
739
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
830
- var propertyValueDump = "";
740
+ var propertyValueDump = strEmpty$1;
831
741
  if (objectTypeDump === "[object Error]") {
832
742
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
833
743
  }
@@ -870,9 +780,9 @@
870
780
  var strWarnToConsole = "warnToConsole";
871
781
  function _sanitizeDiagnosticText(text) {
872
782
  if (text) {
873
- return "\"" + text.replace(/\"/g, "") + "\"";
783
+ return "\"" + text.replace(/\"/g, strEmpty$1) + "\"";
874
784
  }
875
- return "";
785
+ return strEmpty$1;
876
786
  }
877
787
  function _logToConsole(func, message) {
878
788
  var theConsole = getConsole();
@@ -894,12 +804,12 @@
894
804
  _self.message =
895
805
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
896
806
  msgId;
897
- var strProps = "";
807
+ var strProps = strEmpty$1;
898
808
  if (hasJSON()) {
899
809
  strProps = getJSON().stringify(properties);
900
810
  }
901
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
902
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
811
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty$1) +
812
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty$1);
903
813
  _self.message += diagnosticText;
904
814
  }
905
815
  _InternalLogMessage.dataType = "MessageData";
@@ -929,7 +839,7 @@
929
839
  throw message;
930
840
  }
931
841
  else {
932
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
842
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
933
843
  if (!isUndefined(message.message)) {
934
844
  var logLevel = _self.consoleLoggingLevel();
935
845
  if (isUserAct) {
@@ -947,7 +857,7 @@
947
857
  _self.logInternalMessage(severity, message);
948
858
  }
949
859
  else {
950
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
860
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
951
861
  }
952
862
  }
953
863
  };
@@ -979,13 +889,13 @@
979
889
  if (severity <= _self.telemetryLoggingLevel()) {
980
890
  _self.queue.push(message);
981
891
  _messageCount++;
982
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
892
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
983
893
  }
984
894
  if (_messageCount === _self.maxInternalMessageLimit()) {
985
895
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
986
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
896
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
987
897
  _self.queue.push(throttleMessage);
988
- if (severity === LoggingSeverity.CRITICAL) {
898
+ if (severity === 1 ) {
989
899
  _self.errorToConsole(throttleLimitMessage);
990
900
  }
991
901
  else {
@@ -1127,6 +1037,151 @@
1127
1037
  return func();
1128
1038
  }
1129
1039
 
1040
+ var UInt32Mask = 0x100000000;
1041
+ var MaxUInt32 = 0xffffffff;
1042
+ var _mwcSeeded = false;
1043
+ var _mwcW = 123456789;
1044
+ var _mwcZ = 987654321;
1045
+ function _mwcSeed(seedValue) {
1046
+ if (seedValue < 0) {
1047
+ seedValue >>>= 0;
1048
+ }
1049
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1050
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1051
+ _mwcSeeded = true;
1052
+ }
1053
+ function _autoSeedMwc() {
1054
+ try {
1055
+ var now = dateNow() & 0x7fffffff;
1056
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1057
+ }
1058
+ catch (e) {
1059
+ }
1060
+ }
1061
+ function random32(signed) {
1062
+ var value = 0;
1063
+ var c = getCrypto() || getMsCrypto();
1064
+ if (c && c.getRandomValues) {
1065
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1066
+ }
1067
+ if (value === 0 && isIE()) {
1068
+ if (!_mwcSeeded) {
1069
+ _autoSeedMwc();
1070
+ }
1071
+ value = mwcRandom32() & MaxUInt32;
1072
+ }
1073
+ if (value === 0) {
1074
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1075
+ }
1076
+ if (!signed) {
1077
+ value >>>= 0;
1078
+ }
1079
+ return value;
1080
+ }
1081
+ function mwcRandom32(signed) {
1082
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1083
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1084
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1085
+ if (!signed) {
1086
+ value >>>= 0;
1087
+ }
1088
+ return value;
1089
+ }
1090
+ function newId(maxLength) {
1091
+ if (maxLength === void 0) { maxLength = 22; }
1092
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1093
+ var number = random32() >>> 0;
1094
+ var chars = 0;
1095
+ var result = strEmpty$1;
1096
+ while (result.length < maxLength) {
1097
+ chars++;
1098
+ result += base64chars.charAt(number & 0x3F);
1099
+ number >>>= 6;
1100
+ if (chars === 5) {
1101
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1102
+ chars = 0;
1103
+ }
1104
+ }
1105
+ return result;
1106
+ }
1107
+
1108
+ var _objDefineProperty = ObjDefineProperty;
1109
+ var version = "2.7.3";
1110
+ var instanceName = "." + newId(6);
1111
+ var _dataUid = 0;
1112
+ function _createAccessor(target, prop, value) {
1113
+ if (_objDefineProperty) {
1114
+ try {
1115
+ _objDefineProperty(target, prop, {
1116
+ value: value,
1117
+ enumerable: false,
1118
+ configurable: true
1119
+ });
1120
+ return true;
1121
+ }
1122
+ catch (e) {
1123
+ }
1124
+ }
1125
+ return false;
1126
+ }
1127
+ function _canAcceptData(target) {
1128
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1129
+ }
1130
+ function _getCache(data, target) {
1131
+ var theCache = target[data.id];
1132
+ if (!theCache) {
1133
+ theCache = {};
1134
+ try {
1135
+ if (_canAcceptData(target)) {
1136
+ if (!_createAccessor(target, data.id, theCache)) {
1137
+ target[data.id] = theCache;
1138
+ }
1139
+ }
1140
+ }
1141
+ catch (e) {
1142
+ }
1143
+ }
1144
+ return theCache;
1145
+ }
1146
+ function createUniqueNamespace(name, includeVersion) {
1147
+ if (includeVersion === void 0) { includeVersion = false; }
1148
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1149
+ }
1150
+ function createElmNodeData(name) {
1151
+ var data = {
1152
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1153
+ accept: function (target) {
1154
+ return _canAcceptData(target);
1155
+ },
1156
+ get: function (target, name, defValue, addDefault) {
1157
+ var theCache = target[data.id];
1158
+ if (!theCache) {
1159
+ if (addDefault) {
1160
+ theCache = _getCache(data, target);
1161
+ theCache[normalizeJsName(name)] = defValue;
1162
+ }
1163
+ return defValue;
1164
+ }
1165
+ return theCache[normalizeJsName(name)];
1166
+ },
1167
+ kill: function (target, name) {
1168
+ if (target && target[name]) {
1169
+ try {
1170
+ delete target[name];
1171
+ }
1172
+ catch (e) {
1173
+ }
1174
+ }
1175
+ }
1176
+ };
1177
+ return data;
1178
+ }
1179
+
1180
+ var pluginStateData = createElmNodeData("plugin");
1181
+ function _getPluginState(plugin) {
1182
+ return pluginStateData.get(plugin, "state", {}, true);
1183
+ }
1184
+
1130
1185
  var strTelemetryPluginChain = "TelemetryPluginChain";
1131
1186
  var strHasRunFlags = "_hasRun";
1132
1187
  var strGetTelCtx = "_getTelCtx";
@@ -1140,53 +1195,66 @@
1140
1195
  }
1141
1196
  return createTelemetryProxyChain([startAt], config, core);
1142
1197
  }
1143
- function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1144
- var _nextProxy = null;
1145
- var _onComplete = null;
1146
- if (startAt) {
1147
- _nextProxy = _getNextProxyStart(telemetryChain, config, core, startAt);
1148
- }
1149
- else {
1150
- _nextProxy = telemetryChain;
1151
- }
1198
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1199
+ var _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1200
+ var _onComplete = [];
1152
1201
  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);
1202
+ _next: _moveNext,
1203
+ ctx: {
1204
+ core: function () { return core; },
1205
+ diagLog: function () {
1206
+ return safeGetLogger(core, config);
1207
+ },
1208
+ getCfg: function () {
1209
+ return config;
1210
+ },
1211
+ getExtCfg: _getExtCfg,
1212
+ getConfig: _getConfig,
1213
+ hasNext: function () {
1214
+ return !!_nextProxy;
1215
+ },
1216
+ getNext: function () {
1217
+ return _nextProxy;
1218
+ },
1219
+ setNext: function (nextPlugin) {
1220
+ _nextProxy = nextPlugin;
1221
+ },
1222
+ iterate: _iterateChain,
1223
+ onComplete: _addOnComplete
1224
+ }
1225
+ };
1226
+ function _addOnComplete(onComplete, that) {
1227
+ var args = [];
1228
+ for (var _i = 2; _i < arguments.length; _i++) {
1229
+ args[_i - 2] = arguments[_i];
1230
+ }
1231
+ if (onComplete) {
1232
+ _onComplete.push({
1233
+ func: onComplete,
1234
+ self: !isUndefined(that) ? that : context.ctx,
1235
+ args: args
1176
1236
  });
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);
1237
+ }
1238
+ }
1239
+ function _moveNext() {
1240
+ var nextProxy = _nextProxy;
1241
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1242
+ if (!nextProxy) {
1243
+ var onComplete = _onComplete;
1244
+ if (onComplete && onComplete.length > 0) {
1245
+ arrForEach(onComplete, function (completeDetails) {
1246
+ try {
1247
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1248
+ }
1249
+ catch (e) {
1250
+ core.logger.throwInternal(2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1251
+ }
1252
+ });
1253
+ _onComplete = [];
1183
1254
  }
1184
- return createProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1185
- },
1186
- onComplete: function (onComplete) {
1187
- _onComplete = onComplete;
1188
1255
  }
1189
- };
1256
+ return nextProxy;
1257
+ }
1190
1258
  function _getExtCfg(identifier, defaultValue, mergeDefault) {
1191
1259
  if (defaultValue === void 0) { defaultValue = {}; }
1192
1260
  if (mergeDefault === void 0) { mergeDefault = 0 ; }
@@ -1229,29 +1297,53 @@
1229
1297
  }
1230
1298
  return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1231
1299
  }
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;
1300
+ function _iterateChain(cb) {
1301
+ var nextPlugin;
1302
+ while (!!(nextPlugin = context._next())) {
1303
+ var plugin = nextPlugin.getPlugin();
1304
+ if (plugin) {
1305
+ cb(plugin);
1242
1306
  }
1243
1307
  }
1244
1308
  }
1245
- function _iterateChain(cb) {
1246
- while (_nextProxy) {
1247
- _processChain(function (nextPlugin) {
1248
- var plugin = nextPlugin.getPlugin();
1249
- if (plugin) {
1250
- cb(plugin);
1251
- }
1252
- });
1309
+ return context;
1310
+ }
1311
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1312
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1313
+ var context = internalContext.ctx;
1314
+ function _processNext(env) {
1315
+ var nextPlugin = internalContext._next();
1316
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1317
+ return !nextPlugin;
1318
+ }
1319
+ function _createNew(plugins, startAt) {
1320
+ if (plugins === void 0) { plugins = null; }
1321
+ if (isArray(plugins)) {
1322
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1323
+ }
1324
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1325
+ }
1326
+ context.processNext = _processNext;
1327
+ context.createNew = _createNew;
1328
+ return context;
1329
+ }
1330
+ function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
1331
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1332
+ var context = internalContext.ctx;
1333
+ function _processNext(unloadState) {
1334
+ var nextPlugin = internalContext._next();
1335
+ nextPlugin && nextPlugin.unload(context, unloadState);
1336
+ return !nextPlugin;
1337
+ }
1338
+ function _createNew(plugins, startAt) {
1339
+ if (plugins === void 0) { plugins = null; }
1340
+ if (isArray(plugins)) {
1341
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1253
1342
  }
1343
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
1254
1344
  }
1345
+ context.processNext = _processNext;
1346
+ context.createNew = _createNew;
1255
1347
  return context;
1256
1348
  }
1257
1349
  function createTelemetryProxyChain(plugins, config, core, startAt) {
@@ -1299,32 +1391,35 @@
1299
1391
  return nextProxy;
1300
1392
  },
1301
1393
  processTelemetry: _processTelemetry,
1394
+ unload: _unloadPlugin,
1302
1395
  _id: chainId,
1303
1396
  _setNext: function (nextPlugin) {
1304
1397
  nextProxy = nextPlugin;
1305
1398
  }
1306
1399
  };
1307
- function _processChain(itemCtx, processPluginFn, processProxyFn, name, details, isAsync) {
1400
+ function _getTelCtx() {
1401
+ var itemCtx;
1402
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1403
+ itemCtx = plugin[strGetTelCtx]();
1404
+ }
1308
1405
  if (!itemCtx) {
1309
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1310
- itemCtx = plugin[strGetTelCtx]();
1311
- }
1312
- if (!itemCtx) {
1313
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1314
- }
1406
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1315
1407
  }
1408
+ return itemCtx;
1409
+ }
1410
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1411
+ var hasRun = false;
1316
1412
  var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1317
1413
  var hasRunContext = itemCtx[strHasRunFlags];
1318
1414
  if (!hasRunContext) {
1319
1415
  hasRunContext = itemCtx[strHasRunFlags] = {};
1320
1416
  }
1321
- doPerf(itemCtx.core(), function () { return identifier + ":" + name; }, function () {
1322
- hasRunContext[chainId] = true;
1323
- var hasRun = false;
1324
- itemCtx.setNext(nextProxy);
1325
- if (plugin) {
1417
+ itemCtx.setNext(nextProxy);
1418
+ if (plugin) {
1419
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1420
+ hasRunContext[chainId] = true;
1326
1421
  try {
1327
- var nextId = nextProxy ? nextProxy._id : "";
1422
+ var nextId = nextProxy ? nextProxy._id : strEmpty$1;
1328
1423
  if (nextId) {
1329
1424
  hasRunContext[nextId] = false;
1330
1425
  }
@@ -1336,18 +1431,21 @@
1336
1431
  hasRun = true;
1337
1432
  }
1338
1433
  if (!nextProxy || !hasNextRun) {
1339
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1434
+ itemCtx.diagLog().throwInternal(1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1340
1435
  }
1341
1436
  }
1342
- }
1343
- if (nextProxy && !hasRun) {
1344
- processProxyFn(itemCtx);
1345
- }
1346
- }, details, isAsync);
1437
+ }, details, isAsync);
1438
+ }
1439
+ return hasRun;
1347
1440
  }
1348
1441
  function _processTelemetry(env, itemCtx) {
1349
- _processChain(itemCtx, function (itemCtx) {
1350
- if (!hasProcessTelemetry) {
1442
+ itemCtx = itemCtx || _getTelCtx();
1443
+ function _callProcessTelemetry(itemCtx) {
1444
+ if (!plugin || !hasProcessTelemetry) {
1445
+ return false;
1446
+ }
1447
+ var pluginState = _getPluginState(plugin);
1448
+ if (pluginState[strTeardown] || pluginState[strDisabled]) {
1351
1449
  return false;
1352
1450
  }
1353
1451
  if (hasSetNext) {
@@ -1355,9 +1453,31 @@
1355
1453
  }
1356
1454
  plugin.processTelemetry(env, itemCtx);
1357
1455
  return true;
1358
- }, function (itemCtx) {
1359
- nextProxy.processTelemetry(env, itemCtx);
1360
- }, "processTelemetry", function () { return ({ item: env }); }, !(env.sync));
1456
+ }
1457
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1458
+ itemCtx.processNext(env);
1459
+ }
1460
+ }
1461
+ function _unloadPlugin(unloadCtx, unloadState) {
1462
+ function _callTeardown() {
1463
+ var hasRun = false;
1464
+ if (plugin) {
1465
+ var pluginState = _getPluginState(plugin);
1466
+ var pluginCore = plugin[strCore] || pluginState.core;
1467
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1468
+ pluginState[strCore] = null;
1469
+ pluginState[strTeardown] = true;
1470
+ pluginState[strIsInitialized] = false;
1471
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1472
+ hasRun = true;
1473
+ }
1474
+ }
1475
+ }
1476
+ return hasRun;
1477
+ }
1478
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1479
+ unloadCtx.processNext(unloadState);
1480
+ }
1361
1481
  }
1362
1482
  return objFreeze(proxyChain);
1363
1483
  }
@@ -1378,6 +1498,38 @@
1378
1498
  _setDefaults(config, core, pluginChain);
1379
1499
  _isinitialized = true;
1380
1500
  };
1501
+ _self.teardown = function (unloadCtx, unloadState) {
1502
+ if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
1503
+ return;
1504
+ }
1505
+ var result;
1506
+ var unloadDone = false;
1507
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1508
+ var theUnloadState = unloadState || {
1509
+ reason: 0 ,
1510
+ isAsync: false
1511
+ };
1512
+ function _unloadCallback() {
1513
+ if (!unloadDone) {
1514
+ unloadDone = true;
1515
+ arrForEach(_hooks, function (fn) {
1516
+ fn.rm();
1517
+ });
1518
+ _hooks = [];
1519
+ if (result === true) {
1520
+ theUnloadCtx.processNext(theUnloadState);
1521
+ }
1522
+ _initDefaults();
1523
+ }
1524
+ }
1525
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1526
+ _unloadCallback();
1527
+ }
1528
+ else {
1529
+ result = true;
1530
+ }
1531
+ return result;
1532
+ };
1381
1533
  _self._addHook = function (hooks) {
1382
1534
  if (hooks) {
1383
1535
  if (isArray(hooks)) {
@@ -1392,13 +1544,13 @@
1392
1544
  _self.diagLog = function (itemCtx) {
1393
1545
  return _getTelCtx(itemCtx).diagLog();
1394
1546
  };
1395
- _self.isInitialized = function () {
1547
+ _self[strIsInitialized] = function () {
1396
1548
  return _isinitialized;
1397
1549
  };
1398
1550
  _self.setInitialized = function (isInitialized) {
1399
1551
  _isinitialized = isInitialized;
1400
1552
  };
1401
- _self.setNextPlugin = function (next) {
1553
+ _self[strSetNextPlugin] = function (next) {
1402
1554
  _nextPlugin = next;
1403
1555
  };
1404
1556
  _self.processNext = function (env, itemCtx) {
@@ -1449,60 +1601,116 @@
1449
1601
  return BaseTelemetryPlugin;
1450
1602
  }());
1451
1603
 
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;
1604
+ var strOnPrefix = "on";
1605
+ var strAttachEvent = "attachEvent";
1606
+ var strAddEventHelper = "addEventListener";
1607
+ var strEvents = "events";
1608
+ createUniqueNamespace("aiEvtPageHide");
1609
+ createUniqueNamespace("aiEvtPageShow");
1610
+ var _guid = 1;
1611
+ var elmNodeData = createElmNodeData("events");
1612
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1613
+ function _normalizeNamespace(name) {
1614
+ if (name && name.replace) {
1615
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
1616
+ }
1617
+ return name;
1618
+ }
1619
+ function _getEvtNamespace(eventName, namespaces) {
1620
+ if (namespaces) {
1621
+ var theNamespace_1 = "";
1622
+ if (isArray(namespaces)) {
1623
+ theNamespace_1 = "";
1624
+ arrForEach(namespaces, function (name) {
1625
+ name = _normalizeNamespace(name);
1626
+ if (name) {
1627
+ if (name[0] !== ".") {
1628
+ name = "." + name;
1629
+ }
1630
+ theNamespace_1 += name;
1631
+ }
1632
+ });
1633
+ }
1634
+ else {
1635
+ theNamespace_1 = _normalizeNamespace(namespaces);
1636
+ }
1637
+ if (theNamespace_1) {
1638
+ if (theNamespace_1[0] !== ".") {
1639
+ theNamespace_1 = "." + theNamespace_1;
1640
+ }
1641
+ eventName = (eventName || "") + theNamespace_1;
1642
+ }
1460
1643
  }
1461
- _mwcW = (123456789 + seedValue) & MaxUInt32;
1462
- _mwcZ = (987654321 - seedValue) & MaxUInt32;
1463
- _mwcSeeded = true;
1644
+ var parsedEvent = (eventNamespace.exec(eventName) || []);
1645
+ return {
1646
+ type: parsedEvent[1],
1647
+ ns: ((parsedEvent[2] || "").split(".").sort()).join(".")
1648
+ };
1464
1649
  }
1465
- function _autoSeedMwc() {
1466
- try {
1467
- var now = dateNow() & 0x7fffffff;
1468
- _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1469
- }
1470
- catch (e) {
1650
+ function _getRegisteredEvents(target, evtName, addDefault) {
1651
+ if (addDefault === void 0) { addDefault = true; }
1652
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1653
+ var registeredEvents = aiEvts[evtName];
1654
+ if (!registeredEvents) {
1655
+ registeredEvents = aiEvts[evtName] = [];
1471
1656
  }
1657
+ return registeredEvents;
1472
1658
  }
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();
1659
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
1660
+ var result = false;
1661
+ if (obj && evtName && evtName.type && handlerRef) {
1662
+ if (obj[strAddEventHelper]) {
1663
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1664
+ result = true;
1665
+ }
1666
+ else if (obj[strAttachEvent]) {
1667
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1668
+ result = true;
1482
1669
  }
1483
- value = mwcRandom32() & MaxUInt32;
1484
1670
  }
1485
- if (value === 0) {
1486
- value = Math.floor((UInt32Mask * Math.random()) | 0);
1671
+ return result;
1672
+ }
1673
+ function mergeEvtNamespace(theNamespace, namespaces) {
1674
+ var newNamespaces;
1675
+ if (namespaces) {
1676
+ if (isArray(namespaces)) {
1677
+ newNamespaces = [theNamespace].concat(namespaces);
1678
+ }
1679
+ else {
1680
+ newNamespaces = [theNamespace, namespaces];
1681
+ }
1487
1682
  }
1488
- if (!signed) {
1489
- value >>>= 0;
1683
+ else {
1684
+ newNamespaces = theNamespace;
1490
1685
  }
1491
- return value;
1686
+ return newNamespaces;
1492
1687
  }
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;
1688
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
1689
+ if (useCapture === void 0) { useCapture = false; }
1690
+ var result = false;
1691
+ if (target) {
1692
+ try {
1693
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
1694
+ result = _doAttach(target, evtName, handlerRef, useCapture);
1695
+ if (result && elmNodeData.accept(target)) {
1696
+ var registeredEvent = {
1697
+ guid: _guid++,
1698
+ evtName: evtName,
1699
+ handler: handlerRef,
1700
+ capture: useCapture
1701
+ };
1702
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
1703
+ }
1704
+ }
1705
+ catch (e) {
1706
+ }
1499
1707
  }
1500
- return value;
1708
+ return result;
1501
1709
  }
1502
1710
 
1503
1711
  function generateW3CId() {
1504
1712
  var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
1505
- var oct = "", tmp;
1713
+ var oct = strEmpty$1, tmp;
1506
1714
  for (var a = 0; a < 4; a++) {
1507
1715
  tmp = random32();
1508
1716
  oct +=
@@ -1519,6 +1727,95 @@
1519
1727
  return oct.substr(0, 8) + oct.substr(9, 4) + "4" + oct.substr(13, 3) + clockSequenceHi + oct.substr(16, 3) + oct.substr(19, 12);
1520
1728
  }
1521
1729
 
1730
+ var LoggingSeverity = createEnumStyle({
1731
+ CRITICAL: 1 ,
1732
+ WARNING: 2
1733
+ });
1734
+ var _InternalMessageId = createEnumStyle({
1735
+ BrowserDoesNotSupportLocalStorage: 0 ,
1736
+ BrowserCannotReadLocalStorage: 1 ,
1737
+ BrowserCannotReadSessionStorage: 2 ,
1738
+ BrowserCannotWriteLocalStorage: 3 ,
1739
+ BrowserCannotWriteSessionStorage: 4 ,
1740
+ BrowserFailedRemovalFromLocalStorage: 5 ,
1741
+ BrowserFailedRemovalFromSessionStorage: 6 ,
1742
+ CannotSendEmptyTelemetry: 7 ,
1743
+ ClientPerformanceMathError: 8 ,
1744
+ ErrorParsingAISessionCookie: 9 ,
1745
+ ErrorPVCalc: 10 ,
1746
+ ExceptionWhileLoggingError: 11 ,
1747
+ FailedAddingTelemetryToBuffer: 12 ,
1748
+ FailedMonitorAjaxAbort: 13 ,
1749
+ FailedMonitorAjaxDur: 14 ,
1750
+ FailedMonitorAjaxOpen: 15 ,
1751
+ FailedMonitorAjaxRSC: 16 ,
1752
+ FailedMonitorAjaxSend: 17 ,
1753
+ FailedMonitorAjaxGetCorrelationHeader: 18 ,
1754
+ FailedToAddHandlerForOnBeforeUnload: 19 ,
1755
+ FailedToSendQueuedTelemetry: 20 ,
1756
+ FailedToReportDataLoss: 21 ,
1757
+ FlushFailed: 22 ,
1758
+ MessageLimitPerPVExceeded: 23 ,
1759
+ MissingRequiredFieldSpecification: 24 ,
1760
+ NavigationTimingNotSupported: 25 ,
1761
+ OnError: 26 ,
1762
+ SessionRenewalDateIsZero: 27 ,
1763
+ SenderNotInitialized: 28 ,
1764
+ StartTrackEventFailed: 29 ,
1765
+ StopTrackEventFailed: 30 ,
1766
+ StartTrackFailed: 31 ,
1767
+ StopTrackFailed: 32 ,
1768
+ TelemetrySampledAndNotSent: 33 ,
1769
+ TrackEventFailed: 34 ,
1770
+ TrackExceptionFailed: 35 ,
1771
+ TrackMetricFailed: 36 ,
1772
+ TrackPVFailed: 37 ,
1773
+ TrackPVFailedCalc: 38 ,
1774
+ TrackTraceFailed: 39 ,
1775
+ TransmissionFailed: 40 ,
1776
+ FailedToSetStorageBuffer: 41 ,
1777
+ FailedToRestoreStorageBuffer: 42 ,
1778
+ InvalidBackendResponse: 43 ,
1779
+ FailedToFixDepricatedValues: 44 ,
1780
+ InvalidDurationValue: 45 ,
1781
+ TelemetryEnvelopeInvalid: 46 ,
1782
+ CreateEnvelopeError: 47 ,
1783
+ CannotSerializeObject: 48 ,
1784
+ CannotSerializeObjectNonSerializable: 49 ,
1785
+ CircularReferenceDetected: 50 ,
1786
+ ClearAuthContextFailed: 51 ,
1787
+ ExceptionTruncated: 52 ,
1788
+ IllegalCharsInName: 53 ,
1789
+ ItemNotInArray: 54 ,
1790
+ MaxAjaxPerPVExceeded: 55 ,
1791
+ MessageTruncated: 56 ,
1792
+ NameTooLong: 57 ,
1793
+ SampleRateOutOfRange: 58 ,
1794
+ SetAuthContextFailed: 59 ,
1795
+ SetAuthContextFailedAccountName: 60 ,
1796
+ StringValueTooLong: 61 ,
1797
+ StartCalledMoreThanOnce: 62 ,
1798
+ StopCalledWithoutStart: 63 ,
1799
+ TelemetryInitializerFailed: 64 ,
1800
+ TrackArgumentsNotSpecified: 65 ,
1801
+ UrlTooLong: 66 ,
1802
+ SessionStorageBufferFull: 67 ,
1803
+ CannotAccessCookie: 68 ,
1804
+ IdTooLong: 69 ,
1805
+ InvalidEvent: 70 ,
1806
+ FailedMonitorAjaxSetRequestHeader: 71 ,
1807
+ SendBrowserInfoOnUserInit: 72 ,
1808
+ PluginException: 73 ,
1809
+ NotificationException: 74 ,
1810
+ SnippetScriptLoadFailure: 99 ,
1811
+ InvalidInstrumentationKey: 100 ,
1812
+ CannotParseAiBlobValue: 101 ,
1813
+ InvalidContentBlob: 102 ,
1814
+ TrackPageActionEventFailed: 103 ,
1815
+ FailedAddingCustomDefinedRequestContext: 104 ,
1816
+ InMemoryStorageBufferFull: 105
1817
+ });
1818
+
1522
1819
  var aiInstrumentHooks = "_aiHooks";
1523
1820
  var cbNames = [
1524
1821
  "req", "rsp", "hkErr", "fnErr"
@@ -1694,7 +1991,7 @@
1694
1991
  name = strTrim(name.toString());
1695
1992
  if (name.length > 150 ) {
1696
1993
  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);
1994
+ logger && logger.throwInternal(2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
1698
1995
  }
1699
1996
  }
1700
1997
  return nameTrunc || name;
@@ -1707,7 +2004,7 @@
1707
2004
  value = strTrim(value);
1708
2005
  if (value.toString().length > maxLength) {
1709
2006
  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);
2007
+ logger && logger.throwInternal(2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
1711
2008
  }
1712
2009
  }
1713
2010
  return valueTrunc || value;
@@ -1724,7 +2021,7 @@
1724
2021
  value = getJSON().stringify(value);
1725
2022
  }
1726
2023
  catch (e) {
1727
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
2024
+ logger && logger.throwInternal(2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
1728
2025
  }
1729
2026
  }
1730
2027
  value = dataSanitizeString(logger, value, 8192 );
@@ -1752,7 +2049,7 @@
1752
2049
  input = strTrim(input);
1753
2050
  if (input.length > maxLength) {
1754
2051
  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);
2052
+ logger && logger.throwInternal(2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
1756
2053
  }
1757
2054
  }
1758
2055
  return inputTrunc || input;
@@ -1762,39 +2059,28 @@
1762
2059
  return s.substr(s.length - 3);
1763
2060
  }
1764
2061
 
2062
+ var strEmpty = "";
1765
2063
  function msToTimeSpan(totalms) {
1766
2064
  if (isNaN(totalms) || totalms < 0) {
1767
2065
  totalms = 0;
1768
2066
  }
1769
2067
  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;
2068
+ var ms = strEmpty + totalms % 1000;
2069
+ var sec = strEmpty + Math.floor(totalms / 1000) % 60;
2070
+ var min = strEmpty + Math.floor(totalms / (1000 * 60)) % 60;
2071
+ var hour = strEmpty + Math.floor(totalms / (1000 * 60 * 60)) % 24;
1774
2072
  var days = Math.floor(totalms / (1000 * 60 * 60 * 24));
1775
2073
  ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
1776
2074
  sec = sec.length < 2 ? "0" + sec : sec;
1777
2075
  min = min.length < 2 ? "0" + min : min;
1778
2076
  hour = hour.length < 2 ? "0" + hour : hour;
1779
- return (days > 0 ? days + "." : "") + hour + ":" + min + ":" + sec + "." + ms;
2077
+ return (days > 0 ? days + "." : strEmpty) + hour + ":" + min + ":" + sec + "." + ms;
1780
2078
  }
1781
2079
 
1782
2080
  var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
1783
2081
  var strNotSpecified = "not_specified";
1784
2082
  var strIkey = "iKey";
1785
2083
 
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
2084
  var _document = getDocument() || {};
1799
2085
  var _htmlAnchorIdx = 0;
1800
2086
  var _htmlAnchorElement = [null, null, null, null, null];
@@ -2419,19 +2705,21 @@
2419
2705
  var _enableAjaxPerfTracking = false;
2420
2706
  var _maxAjaxCallsPerView = 0;
2421
2707
  var _enableResponseHeaderTracking = false;
2422
- var _hooks = [];
2423
2708
  var _disabledUrls = {};
2424
2709
  var _excludeRequestFromAutoTrackingPatterns;
2425
2710
  var _addRequestContext;
2426
- dynamicProto(AjaxMonitor, _this, function (_self, base) {
2711
+ var _evtNamespace;
2712
+ dynamicProto(AjaxMonitor, _this, function (_self, _base) {
2713
+ var _addHook = _base._addHook;
2427
2714
  _self.initialize = function (config, core, extensions, pluginChain) {
2428
2715
  if (!_self.isInitialized()) {
2429
- base.initialize(config, core, extensions, pluginChain);
2716
+ _base.initialize(config, core, extensions, pluginChain);
2430
2717
  var ctx_1 = _self._getTelCtx();
2431
2718
  var defaultConfig = AjaxMonitor.getDefaultConfig();
2432
2719
  objForEachKey(defaultConfig, function (field, value) {
2433
2720
  _config[field] = ctx_1.getConfig(AjaxMonitor.identifier, field, value);
2434
2721
  });
2722
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace("ajax"), core && core.evtNamespace && core.evtNamespace());
2435
2723
  var distributedTracingMode = _config.distributedTracingMode;
2436
2724
  _enableRequestHeaderTracking = _config.enableRequestHeaderTracking;
2437
2725
  _enableAjaxErrorStatusText = _config.enableAjaxErrorStatusText;
@@ -2440,8 +2728,8 @@
2440
2728
  _enableResponseHeaderTracking = _config.enableResponseHeaderTracking;
2441
2729
  _excludeRequestFromAutoTrackingPatterns = _config.excludeRequestFromAutoTrackingPatterns;
2442
2730
  _addRequestContext = _config.addRequestContext;
2443
- _isUsingAIHeaders = distributedTracingMode === DistributedTracingModes.AI || distributedTracingMode === DistributedTracingModes.AI_AND_W3C;
2444
- _isUsingW3CHeaders = distributedTracingMode === DistributedTracingModes.AI_AND_W3C || distributedTracingMode === DistributedTracingModes.W3C;
2731
+ _isUsingAIHeaders = distributedTracingMode === 0 || distributedTracingMode === 1 ;
2732
+ _isUsingW3CHeaders = distributedTracingMode === 1 || distributedTracingMode === 2 ;
2445
2733
  if (_enableAjaxPerfTracking) {
2446
2734
  var iKey = config.instrumentationKey || "unkwn";
2447
2735
  if (iKey.length > 5) {
@@ -2469,14 +2757,9 @@
2469
2757
  }
2470
2758
  }
2471
2759
  };
2472
- _self.teardown = function () {
2473
- arrForEach(_hooks, function (fn) {
2474
- fn.rm();
2475
- });
2476
- _hooks = [];
2760
+ _self._doTeardown = function () {
2477
2761
  _fetchInitialized = false;
2478
2762
  _xhrInitialized = false;
2479
- _self.setInitialized(false);
2480
2763
  };
2481
2764
  _self.trackDependencyData = function (dependency, properties) {
2482
2765
  _self[strTrackDependencyDataInternal](dependency, properties);
@@ -2543,8 +2826,8 @@
2543
2826
  };
2544
2827
  _self[strTrackDependencyDataInternal] = function (dependency, properties, systemProperties) {
2545
2828
  if (_maxAjaxCallsPerView === -1 || _trackAjaxAttempts < _maxAjaxCallsPerView) {
2546
- if ((_config.distributedTracingMode === DistributedTracingModes.W3C
2547
- || _config.distributedTracingMode === DistributedTracingModes.AI_AND_W3C)
2829
+ if ((_config.distributedTracingMode === 2
2830
+ || _config.distributedTracingMode === 1 )
2548
2831
  && typeof dependency.id === "string" && dependency.id[dependency.id.length - 1] !== ".") {
2549
2832
  dependency.id += ".";
2550
2833
  }
@@ -2579,7 +2862,7 @@
2579
2862
  var global = getGlobal();
2580
2863
  var isPolyfill = fetch.polyfill;
2581
2864
  if (_config.disableFetchTracking === false) {
2582
- _hooks.push(InstrumentFunc(global, strFetch, {
2865
+ _addHook(InstrumentFunc(global, strFetch, {
2583
2866
  req: function (callDetails, input, init) {
2584
2867
  var fetchData;
2585
2868
  if (_fetchInitialized &&
@@ -2627,7 +2910,7 @@
2627
2910
  _fetchInitialized = true;
2628
2911
  }
2629
2912
  else if (isPolyfill) {
2630
- _hooks.push(InstrumentFunc(global, strFetch, {
2913
+ _addHook(InstrumentFunc(global, strFetch, {
2631
2914
  req: function (callDetails, input, init) {
2632
2915
  _isDisabledRequest(null, input, init);
2633
2916
  }
@@ -2638,7 +2921,7 @@
2638
2921
  }
2639
2922
  }
2640
2923
  function _hookProto(target, funcName, callbacks) {
2641
- _hooks.push(InstrumentProto(target, funcName, callbacks));
2924
+ _addHook(InstrumentProto(target, funcName, callbacks));
2642
2925
  }
2643
2926
  function _instrumentXhr() {
2644
2927
  if (_supportsAjaxMonitoring(_self) && !_xhrInitialized) {
@@ -2760,7 +3043,7 @@
2760
3043
  xhr[strAjaxData] = ajaxData;
2761
3044
  }
2762
3045
  function _attachToOnReadyStateChange(xhr) {
2763
- xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = attachEvent(xhr, "readystatechange", function () {
3046
+ xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = eventOn(xhr, "readystatechange", function () {
2764
3047
  try {
2765
3048
  if (xhr && xhr.readyState === 4 && _isMonitoredXhrInstance(xhr)) {
2766
3049
  _onAjaxComplete(xhr);
@@ -2775,7 +3058,7 @@
2775
3058
  });
2776
3059
  }
2777
3060
  }
2778
- });
3061
+ }, _evtNamespace);
2779
3062
  }
2780
3063
  function _getResponseText(xhr) {
2781
3064
  try {
@@ -3060,7 +3343,7 @@
3060
3343
  disableFetchTracking: true,
3061
3344
  excludeRequestFromAutoTrackingPatterns: undefined,
3062
3345
  disableCorrelationHeaders: false,
3063
- distributedTracingMode: DistributedTracingModes.AI_AND_W3C,
3346
+ distributedTracingMode: 1 ,
3064
3347
  correlationHeaderExcludedDomains: [
3065
3348
  "*.blob.core.windows.net",
3066
3349
  "*.blob.core.chinacloudapi.cn",