@microsoft/applicationinsights-dependencies-js 2.8.0-nightly.2202-06 → 2.8.0-nightly.2204-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-nightly.2202-06
2
+ * Application Insights JavaScript SDK - Dependencies Plugin, 2.8.0-nightly.2204-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -75,7 +75,9 @@
75
75
  var __assignFn = ObjAssign || __objAssignFnImpl;
76
76
  var extendStaticsFn = function (d, b) {
77
77
  extendStaticsFn = ObjClass["setPrototypeOf"] ||
78
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
78
+ ({ __proto__: [] } instanceof Array && function (d, b) {
79
+ d.__proto__ = b;
80
+ }) ||
79
81
  function (d, b) {
80
82
  for (var p in b) {
81
83
  if (b[strShimHasOwnProperty](p)) {
@@ -90,7 +92,9 @@
90
92
  throwTypeError("Class extends value " + String(b) + " is not a constructor or null");
91
93
  }
92
94
  extendStaticsFn(d, b);
93
- function __() { this.constructor = d; }
95
+ function __() {
96
+ this.constructor = d;
97
+ }
94
98
  d[strShimPrototype] = b === null ? objCreateFn(b) : (__[strShimPrototype] = b[strShimPrototype], new __());
95
99
  }
96
100
 
@@ -335,105 +339,22 @@
335
339
  };
336
340
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
337
341
 
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
- };
342
+ var strEmpty$1 = "";
343
+ var strSetNextPlugin = "setNextPlugin";
344
+ var strIsInitialized = "isInitialized";
345
+ var strTeardown = "teardown";
346
+ var strCore = "core";
347
+ var strUpdate = "update";
348
+ var strDisabled = "disabled";
349
+ var strDoTeardown = "_doTeardown";
427
350
 
428
- var strOnPrefix = "on";
429
- var strAttachEvent = "attachEvent";
430
- var strAddEventHelper = "addEventListener";
431
351
  var strToISOString = "toISOString";
432
352
  var cStrTrim = "trim";
433
353
  var strToString = "toString";
434
354
  var str__Proto = "__proto__";
435
355
  var strConstructor = "constructor";
436
- var _objDefineProperty = ObjDefineProperty;
356
+ var _objDefineProperty$1 = ObjDefineProperty;
357
+ var _objFreeze = ObjClass.freeze;
437
358
  var _objKeys = ObjClass.keys;
438
359
  var StringProto = String[strShimPrototype];
439
360
  var _strTrim = StringProto[cStrTrim];
@@ -442,7 +363,7 @@
442
363
  var _isArray = Array.isArray;
443
364
  var _objToString = ObjProto[strToString];
444
365
  var _fnToString = ObjHasOwnProperty[strToString];
445
- _fnToString.call(ObjClass);
366
+ var _objFunctionString = _fnToString.call(ObjClass);
446
367
  var rCamelCase = /-([a-z])/g;
447
368
  var rNormalizeInvalid = /([^\w\d_$])/g;
448
369
  var rLeadingNumeric = /^(\d+[\w\d_$])/;
@@ -474,25 +395,6 @@
474
395
  function isFunction(value) {
475
396
  return !!(value && typeof value === strShimFunction);
476
397
  }
477
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
478
- if (useCapture === void 0) { useCapture = false; }
479
- var result = false;
480
- if (!isNullOrUndefined(obj)) {
481
- try {
482
- if (!isNullOrUndefined(obj[strAddEventHelper])) {
483
- obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
484
- result = true;
485
- }
486
- else if (!isNullOrUndefined(obj[strAttachEvent])) {
487
- obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
488
- result = true;
489
- }
490
- }
491
- catch (e) {
492
- }
493
- }
494
- return result;
495
- }
496
398
  function normalizeJsName(name) {
497
399
  var value = name;
498
400
  if (value && isString(value)) {
@@ -531,6 +433,25 @@
531
433
  function isNumber(value) {
532
434
  return typeof value === "number";
533
435
  }
436
+ function isBoolean(value) {
437
+ return typeof value === "boolean";
438
+ }
439
+ function isPlainObject(value) {
440
+ var result = false;
441
+ if (value && typeof value === "object") {
442
+ var proto = _objGetPrototypeOf ? _objGetPrototypeOf(value) : _getObjProto(value);
443
+ if (!proto) {
444
+ result = true;
445
+ }
446
+ else {
447
+ if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
448
+ proto = proto[strConstructor];
449
+ }
450
+ result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
451
+ }
452
+ }
453
+ return result;
454
+ }
534
455
  function toISOString(date) {
535
456
  if (date) {
536
457
  return _dataToISOString ? date[strToISOString]() : _toISOStringPoly(date);
@@ -610,7 +531,7 @@
610
531
  return result;
611
532
  }
612
533
  function objDefineAccessors(target, prop, getProp, setProp) {
613
- if (_objDefineProperty) {
534
+ if (_objDefineProperty$1) {
614
535
  try {
615
536
  var descriptor = {
616
537
  enumerable: true,
@@ -622,7 +543,7 @@
622
543
  if (setProp) {
623
544
  descriptor.set = setProp;
624
545
  }
625
- _objDefineProperty(target, prop, descriptor);
546
+ _objDefineProperty$1(target, prop, descriptor);
626
547
  return true;
627
548
  }
628
549
  catch (e) {
@@ -630,6 +551,10 @@
630
551
  }
631
552
  return false;
632
553
  }
554
+ function _doNothing(value) {
555
+ return value;
556
+ }
557
+ var objFreeze = _objFreeze || _doNothing;
633
558
  function dateNow() {
634
559
  var dt = Date;
635
560
  return dt.now ? dt.now() : new dt().getTime();
@@ -645,6 +570,91 @@
645
570
  }
646
571
  return theValue;
647
572
  }
573
+ function throwError(message) {
574
+ throw new Error(message);
575
+ }
576
+ function _createProxyFunction(source, funcName) {
577
+ var srcFunc = null;
578
+ var src = null;
579
+ if (isFunction(source)) {
580
+ srcFunc = source;
581
+ }
582
+ else {
583
+ src = source;
584
+ }
585
+ return function () {
586
+ var originalArguments = arguments;
587
+ if (srcFunc) {
588
+ src = srcFunc();
589
+ }
590
+ if (src) {
591
+ return src[funcName].apply(src, originalArguments);
592
+ }
593
+ };
594
+ }
595
+ function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
596
+ if (overwriteTarget === void 0) { overwriteTarget = true; }
597
+ if (target && name && source) {
598
+ if (overwriteTarget || isUndefined(target[name])) {
599
+ target[name] = _createProxyFunction(source, theFunc);
600
+ }
601
+ }
602
+ }
603
+ function createEnumStyle(values) {
604
+ var enumClass = {};
605
+ objForEachKey(values, function (field, value) {
606
+ enumClass[field] = value;
607
+ if (!isUndefined(enumClass[value])) {
608
+ throwError("[" + value + "] exists for " + field);
609
+ }
610
+ enumClass[value] = field;
611
+ });
612
+ return objFreeze(enumClass);
613
+ }
614
+ function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
615
+ var theArgs = arguments;
616
+ var extended = theArgs[0] || {};
617
+ var argLen = theArgs.length;
618
+ var deep = false;
619
+ var idx = 1;
620
+ if (argLen > 0 && isBoolean(extended)) {
621
+ deep = extended;
622
+ extended = theArgs[idx] || {};
623
+ idx++;
624
+ }
625
+ if (!isObject(extended)) {
626
+ extended = {};
627
+ }
628
+ for (; idx < argLen; idx++) {
629
+ var arg = theArgs[idx];
630
+ var isArgArray = isArray(arg);
631
+ var isArgObj = isObject(arg);
632
+ for (var prop in arg) {
633
+ var propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
634
+ if (!propOk) {
635
+ continue;
636
+ }
637
+ var newValue = arg[prop];
638
+ var isNewArray = void 0;
639
+ if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
640
+ var clone = extended[prop];
641
+ if (isNewArray) {
642
+ if (!isArray(clone)) {
643
+ clone = [];
644
+ }
645
+ }
646
+ else if (!isPlainObject(clone)) {
647
+ clone = {};
648
+ }
649
+ newValue = objExtend(deep, clone, newValue);
650
+ }
651
+ if (newValue !== undefined) {
652
+ extended[prop] = newValue;
653
+ }
654
+ }
655
+ }
656
+ return extended;
657
+ }
648
658
 
649
659
  var strWindow = "window";
650
660
  var strDocument = "document";
@@ -658,6 +668,7 @@
658
668
  var strMsCrypto = "msCrypto";
659
669
  var strMsie = "msie";
660
670
  var strTrident = "trident/";
671
+ var strXMLHttpRequest = "XMLHttpRequest";
661
672
  var _isTrident = null;
662
673
  var _navUserAgentCheck = null;
663
674
  var _enableMocks = false;
@@ -732,7 +743,7 @@
732
743
  var nav = getNavigator();
733
744
  if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
734
745
  _navUserAgentCheck = nav.userAgent;
735
- var userAgent = (_navUserAgentCheck || "").toLowerCase();
746
+ var userAgent = (_navUserAgentCheck || strEmpty$1).toLowerCase();
736
747
  _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
737
748
  }
738
749
  return _isTrident;
@@ -741,9 +752,9 @@
741
752
  if (userAgentStr === void 0) { userAgentStr = null; }
742
753
  if (!userAgentStr) {
743
754
  var navigator_1 = getNavigator() || {};
744
- userAgentStr = navigator_1 ? (navigator_1.userAgent || "").toLowerCase() : "";
755
+ userAgentStr = navigator_1 ? (navigator_1.userAgent || strEmpty$1).toLowerCase() : strEmpty$1;
745
756
  }
746
- var ua = (userAgentStr || "").toLowerCase();
757
+ var ua = (userAgentStr || strEmpty$1).toLowerCase();
747
758
  if (strContains(ua, strMsie)) {
748
759
  var doc = getDocument() || {};
749
760
  return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
@@ -758,7 +769,7 @@
758
769
  }
759
770
  function dumpObj(object) {
760
771
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
761
- var propertyValueDump = "";
772
+ var propertyValueDump = strEmpty$1;
762
773
  if (objectTypeDump === "[object Error]") {
763
774
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
764
775
  }
@@ -770,7 +781,7 @@
770
781
  function isXhrSupported() {
771
782
  var isSupported = false;
772
783
  try {
773
- var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
784
+ var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
774
785
  isSupported = !!xmlHttpRequest;
775
786
  }
776
787
  catch (e) {
@@ -801,9 +812,9 @@
801
812
  var strWarnToConsole = "warnToConsole";
802
813
  function _sanitizeDiagnosticText(text) {
803
814
  if (text) {
804
- return "\"" + text.replace(/\"/g, "") + "\"";
815
+ return "\"" + text.replace(/\"/g, strEmpty$1) + "\"";
805
816
  }
806
- return "";
817
+ return strEmpty$1;
807
818
  }
808
819
  function _logToConsole(func, message) {
809
820
  var theConsole = getConsole();
@@ -825,12 +836,12 @@
825
836
  _self.message =
826
837
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
827
838
  msgId;
828
- var strProps = "";
839
+ var strProps = strEmpty$1;
829
840
  if (hasJSON()) {
830
841
  strProps = getJSON().stringify(properties);
831
842
  }
832
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
833
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
843
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty$1) +
844
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty$1);
834
845
  _self.message += diagnosticText;
835
846
  }
836
847
  _InternalLogMessage.dataType = "MessageData";
@@ -860,7 +871,7 @@
860
871
  throw message;
861
872
  }
862
873
  else {
863
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
874
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
864
875
  if (!isUndefined(message.message)) {
865
876
  var logLevel = _self.consoleLoggingLevel();
866
877
  if (isUserAct) {
@@ -878,7 +889,7 @@
878
889
  _self.logInternalMessage(severity, message);
879
890
  }
880
891
  else {
881
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
892
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
882
893
  }
883
894
  }
884
895
  };
@@ -910,13 +921,13 @@
910
921
  if (severity <= _self.telemetryLoggingLevel()) {
911
922
  _self.queue.push(message);
912
923
  _messageCount++;
913
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
924
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
914
925
  }
915
926
  if (_messageCount === _self.maxInternalMessageLimit()) {
916
927
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
917
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
928
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
918
929
  _self.queue.push(throttleMessage);
919
- if (severity === LoggingSeverity.CRITICAL) {
930
+ if (severity === 1 ) {
920
931
  _self.errorToConsole(throttleLimitMessage);
921
932
  }
922
933
  else {
@@ -945,6 +956,10 @@
945
956
  }
946
957
  return DiagnosticLogger;
947
958
  }());
959
+ function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
960
+ if (isUserAct === void 0) { isUserAct = false; }
961
+ (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
962
+ }
948
963
 
949
964
  var strExecutionContextKey = "ctx";
950
965
  var PerfEvent = /** @class */ (function () {
@@ -1058,207 +1073,616 @@
1058
1073
  return func();
1059
1074
  }
1060
1075
 
1061
- var TelemetryPluginChain = /** @class */ (function () {
1062
- function TelemetryPluginChain(plugin, defItemCtx) {
1063
- var _self = this;
1064
- var _nextProxy = null;
1065
- var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1066
- var _hasSetNext = isFunction(plugin.setNextPlugin);
1067
- _self._hasRun = false;
1068
- _self.getPlugin = function () {
1069
- return plugin;
1070
- };
1071
- _self.getNext = function () {
1072
- return _nextProxy;
1073
- };
1074
- _self.setNext = function (nextPlugin) {
1075
- _nextProxy = nextPlugin;
1076
- };
1077
- _self.processTelemetry = function (env, itemCtx) {
1078
- if (!itemCtx) {
1079
- itemCtx = defItemCtx;
1076
+ var UInt32Mask = 0x100000000;
1077
+ var MaxUInt32 = 0xffffffff;
1078
+ var _mwcSeeded = false;
1079
+ var _mwcW = 123456789;
1080
+ var _mwcZ = 987654321;
1081
+ function _mwcSeed(seedValue) {
1082
+ if (seedValue < 0) {
1083
+ seedValue >>>= 0;
1084
+ }
1085
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1086
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1087
+ _mwcSeeded = true;
1088
+ }
1089
+ function _autoSeedMwc() {
1090
+ try {
1091
+ var now = dateNow() & 0x7fffffff;
1092
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1093
+ }
1094
+ catch (e) {
1095
+ }
1096
+ }
1097
+ function random32(signed) {
1098
+ var value = 0;
1099
+ var c = getCrypto() || getMsCrypto();
1100
+ if (c && c.getRandomValues) {
1101
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1102
+ }
1103
+ if (value === 0 && isIE()) {
1104
+ if (!_mwcSeeded) {
1105
+ _autoSeedMwc();
1106
+ }
1107
+ value = mwcRandom32() & MaxUInt32;
1108
+ }
1109
+ if (value === 0) {
1110
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1111
+ }
1112
+ if (!signed) {
1113
+ value >>>= 0;
1114
+ }
1115
+ return value;
1116
+ }
1117
+ function mwcRandom32(signed) {
1118
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1119
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1120
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1121
+ if (!signed) {
1122
+ value >>>= 0;
1123
+ }
1124
+ return value;
1125
+ }
1126
+ function newId(maxLength) {
1127
+ if (maxLength === void 0) { maxLength = 22; }
1128
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1129
+ var number = random32() >>> 0;
1130
+ var chars = 0;
1131
+ var result = strEmpty$1;
1132
+ while (result.length < maxLength) {
1133
+ chars++;
1134
+ result += base64chars.charAt(number & 0x3F);
1135
+ number >>>= 6;
1136
+ if (chars === 5) {
1137
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1138
+ chars = 0;
1139
+ }
1140
+ }
1141
+ return result;
1142
+ }
1143
+
1144
+ var _objDefineProperty = ObjDefineProperty;
1145
+ var version = "2.8.0-nightly.2204-04";
1146
+ var instanceName = "." + newId(6);
1147
+ var _dataUid = 0;
1148
+ function _createAccessor(target, prop, value) {
1149
+ if (_objDefineProperty) {
1150
+ try {
1151
+ _objDefineProperty(target, prop, {
1152
+ value: value,
1153
+ enumerable: false,
1154
+ configurable: true
1155
+ });
1156
+ return true;
1157
+ }
1158
+ catch (e) {
1159
+ }
1160
+ }
1161
+ return false;
1162
+ }
1163
+ function _canAcceptData(target) {
1164
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1165
+ }
1166
+ function _getCache(data, target) {
1167
+ var theCache = target[data.id];
1168
+ if (!theCache) {
1169
+ theCache = {};
1170
+ try {
1171
+ if (_canAcceptData(target)) {
1172
+ if (!_createAccessor(target, data.id, theCache)) {
1173
+ target[data.id] = theCache;
1174
+ }
1175
+ }
1176
+ }
1177
+ catch (e) {
1178
+ }
1179
+ }
1180
+ return theCache;
1181
+ }
1182
+ function createUniqueNamespace(name, includeVersion) {
1183
+ if (includeVersion === void 0) { includeVersion = false; }
1184
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1185
+ }
1186
+ function createElmNodeData(name) {
1187
+ var data = {
1188
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1189
+ accept: function (target) {
1190
+ return _canAcceptData(target);
1191
+ },
1192
+ get: function (target, name, defValue, addDefault) {
1193
+ var theCache = target[data.id];
1194
+ if (!theCache) {
1195
+ if (addDefault) {
1196
+ theCache = _getCache(data, target);
1197
+ theCache[normalizeJsName(name)] = defValue;
1198
+ }
1199
+ return defValue;
1080
1200
  }
1081
- var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1082
- doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1083
- if (plugin && _hasProcessTelemetry) {
1084
- _self._hasRun = true;
1201
+ return theCache[normalizeJsName(name)];
1202
+ },
1203
+ kill: function (target, name) {
1204
+ if (target && target[name]) {
1205
+ try {
1206
+ delete target[name];
1207
+ }
1208
+ catch (e) {
1209
+ }
1210
+ }
1211
+ }
1212
+ };
1213
+ return data;
1214
+ }
1215
+
1216
+ var pluginStateData = createElmNodeData("plugin");
1217
+ function _getPluginState(plugin) {
1218
+ return pluginStateData.get(plugin, "state", {}, true);
1219
+ }
1220
+
1221
+ var strTelemetryPluginChain = "TelemetryPluginChain";
1222
+ var strHasRunFlags = "_hasRun";
1223
+ var strGetTelCtx = "_getTelCtx";
1224
+ var _chainId = 0;
1225
+ function _getNextProxyStart(proxy, config, core, startAt) {
1226
+ while (proxy) {
1227
+ if (proxy.getPlugin() === startAt) {
1228
+ return proxy;
1229
+ }
1230
+ proxy = proxy.getNext();
1231
+ }
1232
+ return createTelemetryProxyChain([startAt], config, core);
1233
+ }
1234
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1235
+ var _nextProxy = null;
1236
+ var _onComplete = [];
1237
+ if (startAt !== null) {
1238
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1239
+ }
1240
+ var context = {
1241
+ _next: _moveNext,
1242
+ ctx: {
1243
+ core: function () {
1244
+ return core;
1245
+ },
1246
+ diagLog: function () {
1247
+ return safeGetLogger(core, config);
1248
+ },
1249
+ getCfg: function () {
1250
+ return config;
1251
+ },
1252
+ getExtCfg: _getExtCfg,
1253
+ getConfig: _getConfig,
1254
+ hasNext: function () {
1255
+ return !!_nextProxy;
1256
+ },
1257
+ getNext: function () {
1258
+ return _nextProxy;
1259
+ },
1260
+ setNext: function (nextPlugin) {
1261
+ _nextProxy = nextPlugin;
1262
+ },
1263
+ iterate: _iterateChain,
1264
+ onComplete: _addOnComplete
1265
+ }
1266
+ };
1267
+ function _addOnComplete(onComplete, that) {
1268
+ var args = [];
1269
+ for (var _i = 2; _i < arguments.length; _i++) {
1270
+ args[_i - 2] = arguments[_i];
1271
+ }
1272
+ if (onComplete) {
1273
+ _onComplete.push({
1274
+ func: onComplete,
1275
+ self: !isUndefined(that) ? that : context.ctx,
1276
+ args: args
1277
+ });
1278
+ }
1279
+ }
1280
+ function _moveNext() {
1281
+ var nextProxy = _nextProxy;
1282
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1283
+ if (!nextProxy) {
1284
+ var onComplete = _onComplete;
1285
+ if (onComplete && onComplete.length > 0) {
1286
+ arrForEach(onComplete, function (completeDetails) {
1085
1287
  try {
1086
- itemCtx.setNext(_nextProxy);
1087
- if (_hasSetNext) {
1088
- plugin.setNextPlugin(_nextProxy);
1089
- }
1090
- _nextProxy && (_nextProxy._hasRun = false);
1091
- plugin.processTelemetry(env, itemCtx);
1288
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1092
1289
  }
1093
- catch (error) {
1094
- var hasRun = _nextProxy && _nextProxy._hasRun;
1095
- if (!_nextProxy || !hasRun) {
1096
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1097
- }
1098
- if (_nextProxy && !hasRun) {
1099
- _nextProxy.processTelemetry(env, itemCtx);
1100
- }
1290
+ catch (e) {
1291
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1101
1292
  }
1102
- }
1103
- else if (_nextProxy) {
1104
- _self._hasRun = true;
1105
- _nextProxy.processTelemetry(env, itemCtx);
1106
- }
1107
- }, function () { return ({ item: env }); }, !(env.sync));
1108
- };
1293
+ });
1294
+ _onComplete = [];
1295
+ }
1296
+ }
1297
+ return nextProxy;
1109
1298
  }
1110
- return TelemetryPluginChain;
1111
- }());
1112
-
1113
- function _createProxyChain(plugins, itemCtx) {
1114
- var proxies = [];
1115
- if (plugins && plugins.length > 0) {
1116
- var lastProxy = null;
1117
- for (var idx = 0; idx < plugins.length; idx++) {
1118
- var thePlugin = plugins[idx];
1119
- if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1120
- var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1121
- proxies.push(newProxy);
1122
- if (lastProxy) {
1123
- lastProxy.setNext(newProxy);
1299
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
1300
+ if (defaultValue === void 0) { defaultValue = {}; }
1301
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
1302
+ var theConfig;
1303
+ if (config) {
1304
+ var extConfig = config.extensionConfig;
1305
+ if (extConfig && identifier) {
1306
+ theConfig = extConfig[identifier];
1307
+ }
1308
+ }
1309
+ if (!theConfig) {
1310
+ theConfig = defaultValue;
1311
+ }
1312
+ else if (isObject(defaultValue)) {
1313
+ if (mergeDefault !== 0 ) {
1314
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
1315
+ if (config && mergeDefault === 2 ) {
1316
+ objForEachKey(defaultValue, function (field) {
1317
+ if (isNullOrUndefined(newConfig_1[field])) {
1318
+ var cfgValue = config[field];
1319
+ if (!isNullOrUndefined(cfgValue)) {
1320
+ newConfig_1[field] = cfgValue;
1321
+ }
1322
+ }
1323
+ });
1124
1324
  }
1125
- lastProxy = newProxy;
1126
1325
  }
1127
1326
  }
1327
+ return theConfig;
1128
1328
  }
1129
- return proxies.length > 0 ? proxies[0] : null;
1130
- }
1131
- function _copyProxyChain(proxy, itemCtx, startAt) {
1132
- var plugins = [];
1133
- var add = startAt ? false : true;
1134
- if (proxy) {
1135
- while (proxy) {
1136
- var thePlugin = proxy.getPlugin();
1137
- if (add || thePlugin === startAt) {
1138
- add = true;
1139
- plugins.push(thePlugin);
1329
+ function _getConfig(identifier, field, defaultValue) {
1330
+ if (defaultValue === void 0) { defaultValue = false; }
1331
+ var theValue;
1332
+ var extConfig = _getExtCfg(identifier, null);
1333
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1334
+ theValue = extConfig[field];
1335
+ }
1336
+ else if (config && !isNullOrUndefined(config[field])) {
1337
+ theValue = config[field];
1338
+ }
1339
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1340
+ }
1341
+ function _iterateChain(cb) {
1342
+ var nextPlugin;
1343
+ while (!!(nextPlugin = context._next())) {
1344
+ var plugin = nextPlugin.getPlugin();
1345
+ if (plugin) {
1346
+ cb(plugin);
1140
1347
  }
1141
- proxy = proxy.getNext();
1142
1348
  }
1143
1349
  }
1144
- if (!add) {
1145
- plugins.push(startAt);
1350
+ return context;
1351
+ }
1352
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1353
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1354
+ var context = internalContext.ctx;
1355
+ function _processNext(env) {
1356
+ var nextPlugin = internalContext._next();
1357
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1358
+ return !nextPlugin;
1359
+ }
1360
+ function _createNew(plugins, startAt) {
1361
+ if (plugins === void 0) { plugins = null; }
1362
+ if (isArray(plugins)) {
1363
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1364
+ }
1365
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1366
+ }
1367
+ context.processNext = _processNext;
1368
+ context.createNew = _createNew;
1369
+ return context;
1370
+ }
1371
+ function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
1372
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1373
+ var context = internalContext.ctx;
1374
+ function _processNext(unloadState) {
1375
+ var nextPlugin = internalContext._next();
1376
+ nextPlugin && nextPlugin.unload(context, unloadState);
1377
+ return !nextPlugin;
1378
+ }
1379
+ function _createNew(plugins, startAt) {
1380
+ if (plugins === void 0) { plugins = null; }
1381
+ if (isArray(plugins)) {
1382
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1383
+ }
1384
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
1146
1385
  }
1147
- return _createProxyChain(plugins, itemCtx);
1386
+ context.processNext = _processNext;
1387
+ context.createNew = _createNew;
1388
+ return context;
1148
1389
  }
1149
- function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1150
- var plugins = srcPlugins;
1151
- var add = false;
1152
- if (startAt && srcPlugins) {
1153
- plugins = [];
1154
- arrForEach(srcPlugins, function (thePlugin) {
1155
- if (add || thePlugin === startAt) {
1156
- add = true;
1157
- plugins.push(thePlugin);
1390
+ function createProcessTelemetryUpdateContext(telemetryChain, config, core, startAt) {
1391
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1392
+ var context = internalContext.ctx;
1393
+ function _processNext(updateState) {
1394
+ return context.iterate(function (plugin) {
1395
+ if (isFunction(plugin[strUpdate])) {
1396
+ plugin[strUpdate](context, updateState);
1158
1397
  }
1159
1398
  });
1160
1399
  }
1161
- if (startAt && !add) {
1162
- if (!plugins) {
1163
- plugins = [];
1400
+ function _createNew(plugins, startAt) {
1401
+ if (plugins === void 0) { plugins = null; }
1402
+ if (isArray(plugins)) {
1403
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1164
1404
  }
1165
- plugins.push(startAt);
1405
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), config, core, startAt);
1166
1406
  }
1167
- return _createProxyChain(plugins, itemCtx);
1407
+ context.processNext = _processNext;
1408
+ context.createNew = _createNew;
1409
+ return context;
1168
1410
  }
1169
- var ProcessTelemetryContext = /** @class */ (function () {
1170
- function ProcessTelemetryContext(plugins, config, core, startAt) {
1171
- var _self = this;
1172
- var _nextProxy = null;
1173
- if (startAt !== null) {
1174
- if (plugins && isFunction(plugins.getPlugin)) {
1175
- _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1411
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
1412
+ var firstProxy = null;
1413
+ var add = startAt ? false : true;
1414
+ if (isArray(plugins) && plugins.length > 0) {
1415
+ var lastProxy_1 = null;
1416
+ arrForEach(plugins, function (thePlugin) {
1417
+ if (!add && startAt === thePlugin) {
1418
+ add = true;
1176
1419
  }
1177
- else {
1178
- if (startAt) {
1179
- _nextProxy = _copyPluginChain(plugins, _self, startAt);
1420
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1421
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1422
+ if (!firstProxy) {
1423
+ firstProxy = newProxy;
1180
1424
  }
1181
- else if (isUndefined(startAt)) {
1182
- _nextProxy = _createProxyChain(plugins, _self);
1425
+ if (lastProxy_1) {
1426
+ lastProxy_1._setNext(newProxy);
1183
1427
  }
1428
+ lastProxy_1 = newProxy;
1184
1429
  }
1430
+ });
1431
+ }
1432
+ if (startAt && !firstProxy) {
1433
+ return createTelemetryProxyChain([startAt], config, core);
1434
+ }
1435
+ return firstProxy;
1436
+ }
1437
+ function createTelemetryPluginProxy(plugin, config, core) {
1438
+ var nextProxy = null;
1439
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1440
+ var hasSetNext = isFunction(plugin.setNextPlugin);
1441
+ var chainId;
1442
+ if (plugin) {
1443
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1444
+ }
1445
+ else {
1446
+ chainId = "Unknown-0-" + _chainId++;
1447
+ }
1448
+ var proxyChain = {
1449
+ getPlugin: function () {
1450
+ return plugin;
1451
+ },
1452
+ getNext: function () {
1453
+ return nextProxy;
1454
+ },
1455
+ processTelemetry: _processTelemetry,
1456
+ unload: _unloadPlugin,
1457
+ update: _updatePlugin,
1458
+ _id: chainId,
1459
+ _setNext: function (nextPlugin) {
1460
+ nextProxy = nextPlugin;
1185
1461
  }
1186
- _self.core = function () {
1187
- return core;
1188
- };
1189
- _self.diagLog = function () {
1190
- return safeGetLogger(core, config);
1191
- };
1192
- _self.getCfg = function () {
1193
- return config;
1194
- };
1195
- _self.getExtCfg = function (identifier, defaultValue) {
1196
- if (defaultValue === void 0) { defaultValue = {}; }
1197
- var theConfig;
1198
- if (config) {
1199
- var extConfig = config.extensionConfig;
1200
- if (extConfig && identifier) {
1201
- theConfig = extConfig[identifier];
1462
+ };
1463
+ function _getTelCtx() {
1464
+ var itemCtx;
1465
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1466
+ itemCtx = plugin[strGetTelCtx]();
1467
+ }
1468
+ if (!itemCtx) {
1469
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1470
+ }
1471
+ return itemCtx;
1472
+ }
1473
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1474
+ var hasRun = false;
1475
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1476
+ var hasRunContext = itemCtx[strHasRunFlags];
1477
+ if (!hasRunContext) {
1478
+ hasRunContext = itemCtx[strHasRunFlags] = {};
1479
+ }
1480
+ itemCtx.setNext(nextProxy);
1481
+ if (plugin) {
1482
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1483
+ hasRunContext[chainId] = true;
1484
+ try {
1485
+ var nextId = nextProxy ? nextProxy._id : strEmpty$1;
1486
+ if (nextId) {
1487
+ hasRunContext[nextId] = false;
1488
+ }
1489
+ hasRun = processPluginFn(itemCtx);
1202
1490
  }
1491
+ catch (error) {
1492
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1493
+ if (hasNextRun) {
1494
+ hasRun = true;
1495
+ }
1496
+ if (!nextProxy || !hasNextRun) {
1497
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1498
+ }
1499
+ }
1500
+ }, details, isAsync);
1501
+ }
1502
+ return hasRun;
1503
+ }
1504
+ function _processTelemetry(env, itemCtx) {
1505
+ itemCtx = itemCtx || _getTelCtx();
1506
+ function _callProcessTelemetry(itemCtx) {
1507
+ if (!plugin || !hasProcessTelemetry) {
1508
+ return false;
1203
1509
  }
1204
- return (theConfig ? theConfig : defaultValue);
1205
- };
1206
- _self.getConfig = function (identifier, field, defaultValue) {
1207
- if (defaultValue === void 0) { defaultValue = false; }
1208
- var theValue;
1209
- var extConfig = _self.getExtCfg(identifier, null);
1210
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1211
- theValue = extConfig[field];
1510
+ var pluginState = _getPluginState(plugin);
1511
+ if (pluginState[strTeardown] || pluginState[strDisabled]) {
1512
+ return false;
1212
1513
  }
1213
- else if (config && !isNullOrUndefined(config[field])) {
1214
- theValue = config[field];
1514
+ if (hasSetNext) {
1515
+ plugin.setNextPlugin(nextProxy);
1215
1516
  }
1216
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1217
- };
1218
- _self.hasNext = function () {
1219
- return _nextProxy != null;
1220
- };
1221
- _self.getNext = function () {
1222
- return _nextProxy;
1223
- };
1224
- _self.setNext = function (nextPlugin) {
1225
- _nextProxy = nextPlugin;
1226
- };
1227
- _self.processNext = function (env) {
1228
- var nextPlugin = _nextProxy;
1229
- if (nextPlugin) {
1230
- _nextProxy = nextPlugin.getNext();
1231
- nextPlugin.processTelemetry(env, _self);
1517
+ plugin.processTelemetry(env, itemCtx);
1518
+ return true;
1519
+ }
1520
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1521
+ itemCtx.processNext(env);
1522
+ }
1523
+ }
1524
+ function _unloadPlugin(unloadCtx, unloadState) {
1525
+ function _callTeardown() {
1526
+ var hasRun = false;
1527
+ if (plugin) {
1528
+ var pluginState = _getPluginState(plugin);
1529
+ var pluginCore = plugin[strCore] || pluginState.core;
1530
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1531
+ pluginState[strCore] = null;
1532
+ pluginState[strTeardown] = true;
1533
+ pluginState[strIsInitialized] = false;
1534
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1535
+ hasRun = true;
1536
+ }
1537
+ }
1232
1538
  }
1233
- };
1234
- _self.createNew = function (plugins, startAt) {
1235
- if (plugins === void 0) { plugins = null; }
1236
- return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1237
- };
1539
+ return hasRun;
1540
+ }
1541
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1542
+ unloadCtx.processNext(unloadState);
1543
+ }
1238
1544
  }
1239
- return ProcessTelemetryContext;
1240
- }());
1545
+ function _updatePlugin(updateCtx, updateState) {
1546
+ function _callUpdate() {
1547
+ var hasRun = false;
1548
+ if (plugin) {
1549
+ var pluginState = _getPluginState(plugin);
1550
+ var pluginCore = plugin[strCore] || pluginState.core;
1551
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1552
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1553
+ hasRun = true;
1554
+ }
1555
+ }
1556
+ }
1557
+ return hasRun;
1558
+ }
1559
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1560
+ updateCtx.processNext(updateState);
1561
+ }
1562
+ }
1563
+ return objFreeze(proxyChain);
1564
+ }
1241
1565
 
1242
1566
  var strExtensionConfig = "extensionConfig";
1243
1567
 
1568
+ function createUnloadHandlerContainer() {
1569
+ var handlers = [];
1570
+ function _addHandler(handler) {
1571
+ if (handler) {
1572
+ handlers.push(handler);
1573
+ }
1574
+ }
1575
+ function _runHandlers(unloadCtx, unloadState) {
1576
+ arrForEach(handlers, function (handler) {
1577
+ try {
1578
+ handler(unloadCtx, unloadState);
1579
+ }
1580
+ catch (e) {
1581
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1582
+ }
1583
+ });
1584
+ handlers = [];
1585
+ }
1586
+ return {
1587
+ add: _addHandler,
1588
+ run: _runHandlers
1589
+ };
1590
+ }
1591
+
1244
1592
  var strGetPlugin = "getPlugin";
1245
1593
  var BaseTelemetryPlugin = /** @class */ (function () {
1246
1594
  function BaseTelemetryPlugin() {
1247
1595
  var _self = this;
1248
- var _isinitialized = false;
1249
- var _rootCtx = null;
1250
- var _nextPlugin = null;
1251
- _self.core = null;
1596
+ var _isinitialized;
1597
+ var _rootCtx;
1598
+ var _nextPlugin;
1599
+ var _unloadHandlerContainer;
1600
+ var _hooks;
1601
+ _initDefaults();
1602
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1603
+ _self.initialize = function (config, core, extensions, pluginChain) {
1604
+ _setDefaults(config, core, pluginChain);
1605
+ _isinitialized = true;
1606
+ };
1607
+ _self.teardown = function (unloadCtx, unloadState) {
1608
+ if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
1609
+ return;
1610
+ }
1611
+ var result;
1612
+ var unloadDone = false;
1613
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1614
+ var theUnloadState = unloadState || {
1615
+ reason: 0 ,
1616
+ isAsync: false
1617
+ };
1618
+ function _unloadCallback() {
1619
+ if (!unloadDone) {
1620
+ unloadDone = true;
1621
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1622
+ arrForEach(_hooks, function (fn) {
1623
+ fn.rm();
1624
+ });
1625
+ _hooks = [];
1626
+ if (result === true) {
1627
+ theUnloadCtx.processNext(theUnloadState);
1628
+ }
1629
+ _initDefaults();
1630
+ }
1631
+ }
1632
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1633
+ _unloadCallback();
1634
+ }
1635
+ else {
1636
+ result = true;
1637
+ }
1638
+ return result;
1639
+ };
1640
+ _self.update = function (updateCtx, updateState) {
1641
+ if (!_self.core || (updateCtx && _self.core !== updateCtx.core())) {
1642
+ return;
1643
+ }
1644
+ var result;
1645
+ var updateDone = false;
1646
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1647
+ var theUpdateState = updateState || {
1648
+ reason: 0
1649
+ };
1650
+ function _updateCallback() {
1651
+ if (!updateDone) {
1652
+ updateDone = true;
1653
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
1654
+ }
1655
+ }
1656
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
1657
+ _updateCallback();
1658
+ }
1659
+ else {
1660
+ result = true;
1661
+ }
1662
+ return result;
1663
+ };
1664
+ _self._addHook = function (hooks) {
1665
+ if (hooks) {
1666
+ if (isArray(hooks)) {
1667
+ _hooks = _hooks.concat(hooks);
1668
+ }
1669
+ else {
1670
+ _hooks.push(hooks);
1671
+ }
1672
+ }
1673
+ };
1674
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1675
+ });
1252
1676
  _self.diagLog = function (itemCtx) {
1253
- return _self._getTelCtx(itemCtx).diagLog();
1677
+ return _getTelCtx(itemCtx).diagLog();
1254
1678
  };
1255
- _self.isInitialized = function () {
1679
+ _self[strIsInitialized] = function () {
1256
1680
  return _isinitialized;
1257
1681
  };
1258
1682
  _self.setInitialized = function (isInitialized) {
1259
1683
  _isinitialized = isInitialized;
1260
1684
  };
1261
- _self.setNextPlugin = function (next) {
1685
+ _self[strSetNextPlugin] = function (next) {
1262
1686
  _nextPlugin = next;
1263
1687
  };
1264
1688
  _self.processNext = function (env, itemCtx) {
@@ -1269,11 +1693,12 @@
1269
1693
  _nextPlugin.processTelemetry(env, null);
1270
1694
  }
1271
1695
  };
1272
- _self._getTelCtx = function (currentCtx) {
1696
+ _self._getTelCtx = _getTelCtx;
1697
+ function _getTelCtx(currentCtx) {
1273
1698
  if (currentCtx === void 0) { currentCtx = null; }
1274
1699
  var itemCtx = currentCtx;
1275
1700
  if (!itemCtx) {
1276
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1701
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1277
1702
  if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1278
1703
  itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1279
1704
  }
@@ -1282,8 +1707,8 @@
1282
1707
  }
1283
1708
  }
1284
1709
  return itemCtx;
1285
- };
1286
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
1710
+ }
1711
+ function _setDefaults(config, core, pluginChain) {
1287
1712
  if (config) {
1288
1713
  setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1289
1714
  }
@@ -1295,70 +1720,133 @@
1295
1720
  nextPlugin = _nextPlugin[strGetPlugin]();
1296
1721
  }
1297
1722
  _self.core = core;
1298
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1299
- _isinitialized = true;
1300
- };
1723
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1724
+ }
1725
+ function _initDefaults() {
1726
+ _isinitialized = false;
1727
+ _self.core = null;
1728
+ _rootCtx = null;
1729
+ _nextPlugin = null;
1730
+ _hooks = [];
1731
+ _unloadHandlerContainer = createUnloadHandlerContainer();
1732
+ }
1301
1733
  }
1302
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1303
- this._baseTelInit(config, core, extensions, pluginChain);
1304
- };
1305
1734
  return BaseTelemetryPlugin;
1306
1735
  }());
1307
1736
 
1308
- var UInt32Mask = 0x100000000;
1309
- var MaxUInt32 = 0xffffffff;
1310
- var _mwcSeeded = false;
1311
- var _mwcW = 123456789;
1312
- var _mwcZ = 987654321;
1313
- function _mwcSeed(seedValue) {
1314
- if (seedValue < 0) {
1315
- seedValue >>>= 0;
1737
+ var strOnPrefix = "on";
1738
+ var strAttachEvent = "attachEvent";
1739
+ var strAddEventHelper = "addEventListener";
1740
+ var strEvents = "events";
1741
+ createUniqueNamespace("aiEvtPageHide");
1742
+ createUniqueNamespace("aiEvtPageShow");
1743
+ var rRemoveEmptyNs = /\.[\.]+/g;
1744
+ var rRemoveTrailingEmptyNs = /[\.]+$/;
1745
+ var _guid = 1;
1746
+ var elmNodeData = createElmNodeData("events");
1747
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1748
+ function _normalizeNamespace(name) {
1749
+ if (name && name.replace) {
1750
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
1751
+ }
1752
+ return name;
1753
+ }
1754
+ function _getEvtNamespace(eventName, evtNamespace) {
1755
+ if (evtNamespace) {
1756
+ var theNamespace_1 = "";
1757
+ if (isArray(evtNamespace)) {
1758
+ theNamespace_1 = "";
1759
+ arrForEach(evtNamespace, function (name) {
1760
+ name = _normalizeNamespace(name);
1761
+ if (name) {
1762
+ if (name[0] !== ".") {
1763
+ name = "." + name;
1764
+ }
1765
+ theNamespace_1 += name;
1766
+ }
1767
+ });
1768
+ }
1769
+ else {
1770
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
1771
+ }
1772
+ if (theNamespace_1) {
1773
+ if (theNamespace_1[0] !== ".") {
1774
+ theNamespace_1 = "." + theNamespace_1;
1775
+ }
1776
+ eventName = (eventName || "") + theNamespace_1;
1777
+ }
1316
1778
  }
1317
- _mwcW = (123456789 + seedValue) & MaxUInt32;
1318
- _mwcZ = (987654321 - seedValue) & MaxUInt32;
1319
- _mwcSeeded = true;
1779
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1780
+ return {
1781
+ type: parsedEvent[1],
1782
+ ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1783
+ };
1320
1784
  }
1321
- function _autoSeedMwc() {
1322
- try {
1323
- var now = dateNow() & 0x7fffffff;
1324
- _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1325
- }
1326
- catch (e) {
1785
+ function _getRegisteredEvents(target, evtName, addDefault) {
1786
+ if (addDefault === void 0) { addDefault = true; }
1787
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1788
+ var registeredEvents = aiEvts[evtName];
1789
+ if (!registeredEvents) {
1790
+ registeredEvents = aiEvts[evtName] = [];
1327
1791
  }
1792
+ return registeredEvents;
1328
1793
  }
1329
- function random32(signed) {
1330
- var value;
1331
- var c = getCrypto() || getMsCrypto();
1332
- if (c && c.getRandomValues) {
1333
- value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1794
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
1795
+ var result = false;
1796
+ if (obj && evtName && evtName.type && handlerRef) {
1797
+ if (obj[strAddEventHelper]) {
1798
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1799
+ result = true;
1800
+ }
1801
+ else if (obj[strAttachEvent]) {
1802
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1803
+ result = true;
1804
+ }
1334
1805
  }
1335
- else if (isIE()) {
1336
- if (!_mwcSeeded) {
1337
- _autoSeedMwc();
1806
+ return result;
1807
+ }
1808
+ function mergeEvtNamespace(theNamespace, namespaces) {
1809
+ var newNamespaces;
1810
+ if (namespaces) {
1811
+ if (isArray(namespaces)) {
1812
+ newNamespaces = [theNamespace].concat(namespaces);
1338
1813
  }
1339
- value = mwcRandom32() & MaxUInt32;
1814
+ else {
1815
+ newNamespaces = [theNamespace, namespaces];
1816
+ }
1817
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1340
1818
  }
1341
1819
  else {
1342
- value = Math.floor((UInt32Mask * Math.random()) | 0);
1343
- }
1344
- if (!signed) {
1345
- value >>>= 0;
1820
+ newNamespaces = theNamespace;
1346
1821
  }
1347
- return value;
1822
+ return newNamespaces;
1348
1823
  }
1349
- function mwcRandom32(signed) {
1350
- _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1351
- _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1352
- var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1353
- if (!signed) {
1354
- value >>>= 0;
1824
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
1825
+ if (useCapture === void 0) { useCapture = false; }
1826
+ var result = false;
1827
+ if (target) {
1828
+ try {
1829
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
1830
+ result = _doAttach(target, evtName, handlerRef, useCapture);
1831
+ if (result && elmNodeData.accept(target)) {
1832
+ var registeredEvent = {
1833
+ guid: _guid++,
1834
+ evtName: evtName,
1835
+ handler: handlerRef,
1836
+ capture: useCapture
1837
+ };
1838
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
1839
+ }
1840
+ }
1841
+ catch (e) {
1842
+ }
1355
1843
  }
1356
- return value;
1844
+ return result;
1357
1845
  }
1358
1846
 
1359
1847
  function generateW3CId() {
1360
1848
  var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
1361
- var oct = "", tmp;
1849
+ var oct = strEmpty$1, tmp;
1362
1850
  for (var a = 0; a < 4; a++) {
1363
1851
  tmp = random32();
1364
1852
  oct +=
@@ -1375,6 +1863,95 @@
1375
1863
  return oct.substr(0, 8) + oct.substr(9, 4) + "4" + oct.substr(13, 3) + clockSequenceHi + oct.substr(16, 3) + oct.substr(19, 12);
1376
1864
  }
1377
1865
 
1866
+ var LoggingSeverity = createEnumStyle({
1867
+ CRITICAL: 1 ,
1868
+ WARNING: 2
1869
+ });
1870
+ var _InternalMessageId = createEnumStyle({
1871
+ BrowserDoesNotSupportLocalStorage: 0 ,
1872
+ BrowserCannotReadLocalStorage: 1 ,
1873
+ BrowserCannotReadSessionStorage: 2 ,
1874
+ BrowserCannotWriteLocalStorage: 3 ,
1875
+ BrowserCannotWriteSessionStorage: 4 ,
1876
+ BrowserFailedRemovalFromLocalStorage: 5 ,
1877
+ BrowserFailedRemovalFromSessionStorage: 6 ,
1878
+ CannotSendEmptyTelemetry: 7 ,
1879
+ ClientPerformanceMathError: 8 ,
1880
+ ErrorParsingAISessionCookie: 9 ,
1881
+ ErrorPVCalc: 10 ,
1882
+ ExceptionWhileLoggingError: 11 ,
1883
+ FailedAddingTelemetryToBuffer: 12 ,
1884
+ FailedMonitorAjaxAbort: 13 ,
1885
+ FailedMonitorAjaxDur: 14 ,
1886
+ FailedMonitorAjaxOpen: 15 ,
1887
+ FailedMonitorAjaxRSC: 16 ,
1888
+ FailedMonitorAjaxSend: 17 ,
1889
+ FailedMonitorAjaxGetCorrelationHeader: 18 ,
1890
+ FailedToAddHandlerForOnBeforeUnload: 19 ,
1891
+ FailedToSendQueuedTelemetry: 20 ,
1892
+ FailedToReportDataLoss: 21 ,
1893
+ FlushFailed: 22 ,
1894
+ MessageLimitPerPVExceeded: 23 ,
1895
+ MissingRequiredFieldSpecification: 24 ,
1896
+ NavigationTimingNotSupported: 25 ,
1897
+ OnError: 26 ,
1898
+ SessionRenewalDateIsZero: 27 ,
1899
+ SenderNotInitialized: 28 ,
1900
+ StartTrackEventFailed: 29 ,
1901
+ StopTrackEventFailed: 30 ,
1902
+ StartTrackFailed: 31 ,
1903
+ StopTrackFailed: 32 ,
1904
+ TelemetrySampledAndNotSent: 33 ,
1905
+ TrackEventFailed: 34 ,
1906
+ TrackExceptionFailed: 35 ,
1907
+ TrackMetricFailed: 36 ,
1908
+ TrackPVFailed: 37 ,
1909
+ TrackPVFailedCalc: 38 ,
1910
+ TrackTraceFailed: 39 ,
1911
+ TransmissionFailed: 40 ,
1912
+ FailedToSetStorageBuffer: 41 ,
1913
+ FailedToRestoreStorageBuffer: 42 ,
1914
+ InvalidBackendResponse: 43 ,
1915
+ FailedToFixDepricatedValues: 44 ,
1916
+ InvalidDurationValue: 45 ,
1917
+ TelemetryEnvelopeInvalid: 46 ,
1918
+ CreateEnvelopeError: 47 ,
1919
+ CannotSerializeObject: 48 ,
1920
+ CannotSerializeObjectNonSerializable: 49 ,
1921
+ CircularReferenceDetected: 50 ,
1922
+ ClearAuthContextFailed: 51 ,
1923
+ ExceptionTruncated: 52 ,
1924
+ IllegalCharsInName: 53 ,
1925
+ ItemNotInArray: 54 ,
1926
+ MaxAjaxPerPVExceeded: 55 ,
1927
+ MessageTruncated: 56 ,
1928
+ NameTooLong: 57 ,
1929
+ SampleRateOutOfRange: 58 ,
1930
+ SetAuthContextFailed: 59 ,
1931
+ SetAuthContextFailedAccountName: 60 ,
1932
+ StringValueTooLong: 61 ,
1933
+ StartCalledMoreThanOnce: 62 ,
1934
+ StopCalledWithoutStart: 63 ,
1935
+ TelemetryInitializerFailed: 64 ,
1936
+ TrackArgumentsNotSpecified: 65 ,
1937
+ UrlTooLong: 66 ,
1938
+ SessionStorageBufferFull: 67 ,
1939
+ CannotAccessCookie: 68 ,
1940
+ IdTooLong: 69 ,
1941
+ InvalidEvent: 70 ,
1942
+ FailedMonitorAjaxSetRequestHeader: 71 ,
1943
+ SendBrowserInfoOnUserInit: 72 ,
1944
+ PluginException: 73 ,
1945
+ NotificationException: 74 ,
1946
+ SnippetScriptLoadFailure: 99 ,
1947
+ InvalidInstrumentationKey: 100 ,
1948
+ CannotParseAiBlobValue: 101 ,
1949
+ InvalidContentBlob: 102 ,
1950
+ TrackPageActionEventFailed: 103 ,
1951
+ FailedAddingCustomDefinedRequestContext: 104 ,
1952
+ InMemoryStorageBufferFull: 105
1953
+ });
1954
+
1378
1955
  var aiInstrumentHooks = "_aiHooks";
1379
1956
  var cbNames = [
1380
1957
  "req", "rsp", "hkErr", "fnErr"
@@ -1433,6 +2010,7 @@
1433
2010
  };
1434
2011
  var hookCtx = [];
1435
2012
  var cbArgs = _createArgs([funcArgs], orgArgs);
2013
+ funcArgs.evt = getGlobalInst("event");
1436
2014
  function _createArgs(target, theArgs) {
1437
2015
  _arrLoop(theArgs, function (arg) {
1438
2016
  target.push(arg);
@@ -1549,7 +2127,7 @@
1549
2127
  name = strTrim(name.toString());
1550
2128
  if (name.length > 150 ) {
1551
2129
  nameTrunc = name.substring(0, 150 );
1552
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
2130
+ _throwInternal(logger, 2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
1553
2131
  }
1554
2132
  }
1555
2133
  return nameTrunc || name;
@@ -1562,7 +2140,7 @@
1562
2140
  value = strTrim(value);
1563
2141
  if (value.toString().length > maxLength) {
1564
2142
  valueTrunc = value.toString().substring(0, maxLength);
1565
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
2143
+ _throwInternal(logger, 2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
1566
2144
  }
1567
2145
  }
1568
2146
  return valueTrunc || value;
@@ -1579,7 +2157,7 @@
1579
2157
  value = getJSON().stringify(value);
1580
2158
  }
1581
2159
  catch (e) {
1582
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
2160
+ _throwInternal(logger, 2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
1583
2161
  }
1584
2162
  }
1585
2163
  value = dataSanitizeString(logger, value, 8192 );
@@ -1607,7 +2185,7 @@
1607
2185
  input = strTrim(input);
1608
2186
  if (input.length > maxLength) {
1609
2187
  inputTrunc = input.substring(0, maxLength);
1610
- logger && logger.throwInternal(LoggingSeverity.WARNING, _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
2188
+ _throwInternal(logger, 2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
1611
2189
  }
1612
2190
  }
1613
2191
  return inputTrunc || input;
@@ -1617,39 +2195,28 @@
1617
2195
  return s.substr(s.length - 3);
1618
2196
  }
1619
2197
 
2198
+ var strEmpty = "";
1620
2199
  function msToTimeSpan(totalms) {
1621
2200
  if (isNaN(totalms) || totalms < 0) {
1622
2201
  totalms = 0;
1623
2202
  }
1624
2203
  totalms = Math.round(totalms);
1625
- var ms = "" + totalms % 1000;
1626
- var sec = "" + Math.floor(totalms / 1000) % 60;
1627
- var min = "" + Math.floor(totalms / (1000 * 60)) % 60;
1628
- var hour = "" + Math.floor(totalms / (1000 * 60 * 60)) % 24;
2204
+ var ms = strEmpty + totalms % 1000;
2205
+ var sec = strEmpty + Math.floor(totalms / 1000) % 60;
2206
+ var min = strEmpty + Math.floor(totalms / (1000 * 60)) % 60;
2207
+ var hour = strEmpty + Math.floor(totalms / (1000 * 60 * 60)) % 24;
1629
2208
  var days = Math.floor(totalms / (1000 * 60 * 60 * 24));
1630
2209
  ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
1631
2210
  sec = sec.length < 2 ? "0" + sec : sec;
1632
2211
  min = min.length < 2 ? "0" + min : min;
1633
2212
  hour = hour.length < 2 ? "0" + hour : hour;
1634
- return (days > 0 ? days + "." : "") + hour + ":" + min + ":" + sec + "." + ms;
2213
+ return (days > 0 ? days + "." : strEmpty) + hour + ":" + min + ":" + sec + "." + ms;
1635
2214
  }
1636
2215
 
1637
2216
  var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
1638
2217
  var strNotSpecified = "not_specified";
1639
2218
  var strIkey = "iKey";
1640
2219
 
1641
- var StorageType;
1642
- (function (StorageType) {
1643
- StorageType[StorageType["LocalStorage"] = 0] = "LocalStorage";
1644
- StorageType[StorageType["SessionStorage"] = 1] = "SessionStorage";
1645
- })(StorageType || (StorageType = {}));
1646
- var DistributedTracingModes;
1647
- (function (DistributedTracingModes) {
1648
- DistributedTracingModes[DistributedTracingModes["AI"] = 0] = "AI";
1649
- DistributedTracingModes[DistributedTracingModes["AI_AND_W3C"] = 1] = "AI_AND_W3C";
1650
- DistributedTracingModes[DistributedTracingModes["W3C"] = 2] = "W3C";
1651
- })(DistributedTracingModes || (DistributedTracingModes = {}));
1652
-
1653
2220
  var _document = getDocument() || {};
1654
2221
  var _htmlAnchorIdx = 0;
1655
2222
  var _htmlAnchorElement = [null, null, null, null, null];
@@ -1835,22 +2402,10 @@
1835
2402
  return result;
1836
2403
  }
1837
2404
 
1838
- var RemoteDependencyData$1 = /** @class */ (function () {
1839
- function RemoteDependencyData() {
1840
- this.ver = 2;
1841
- this.success = true;
1842
- this.properties = {};
1843
- this.measurements = {};
1844
- }
1845
- return RemoteDependencyData;
1846
- }());
1847
-
1848
- var RemoteDependencyData = /** @class */ (function (_super) {
1849
- __extendsFn(RemoteDependencyData, _super);
2405
+ var RemoteDependencyData = /** @class */ (function () {
1850
2406
  function RemoteDependencyData(logger, id, absoluteUrl, commandName, value, success, resultCode, method, requestAPI, correlationContext, properties, measurements) {
1851
2407
  if (requestAPI === void 0) { requestAPI = "Ajax"; }
1852
- var _this = _super.call(this) || this;
1853
- _this.aiDataContract = {
2408
+ this.aiDataContract = {
1854
2409
  id: 1 ,
1855
2410
  ver: 1 ,
1856
2411
  name: 0 ,
@@ -1873,26 +2428,27 @@
1873
2428
  commandName: 0 ,
1874
2429
  dependencyTypeName: 0
1875
2430
  };
1876
- _this.id = id;
1877
- _this.duration = msToTimeSpan(value);
1878
- _this.success = success;
1879
- _this.resultCode = resultCode + "";
1880
- _this.type = dataSanitizeString(logger, requestAPI);
2431
+ var _self = this;
2432
+ _self.ver = 2;
2433
+ _self.id = id;
2434
+ _self.duration = msToTimeSpan(value);
2435
+ _self.success = success;
2436
+ _self.resultCode = resultCode + "";
2437
+ _self.type = dataSanitizeString(logger, requestAPI);
1881
2438
  var dependencyFields = AjaxHelperParseDependencyPath(logger, absoluteUrl, method, commandName);
1882
- _this.data = dataSanitizeUrl(logger, commandName) || dependencyFields.data;
1883
- _this.target = dataSanitizeString(logger, dependencyFields.target);
2439
+ _self.data = dataSanitizeUrl(logger, commandName) || dependencyFields.data;
2440
+ _self.target = dataSanitizeString(logger, dependencyFields.target);
1884
2441
  if (correlationContext) {
1885
- _this.target = "".concat(_this.target, " | ").concat(correlationContext);
2442
+ _self.target = "".concat(_self.target, " | ").concat(correlationContext);
1886
2443
  }
1887
- _this.name = dataSanitizeString(logger, dependencyFields.name);
1888
- _this.properties = dataSanitizeProperties(logger, properties);
1889
- _this.measurements = dataSanitizeMeasurements(logger, measurements);
1890
- return _this;
2444
+ _self.name = dataSanitizeString(logger, dependencyFields.name);
2445
+ _self.properties = dataSanitizeProperties(logger, properties);
2446
+ _self.measurements = dataSanitizeMeasurements(logger, measurements);
1891
2447
  }
1892
2448
  RemoteDependencyData.envelopeType = "Microsoft.ApplicationInsights.{0}.RemoteDependency";
1893
2449
  RemoteDependencyData.dataType = "RemoteDependencyData";
1894
2450
  return RemoteDependencyData;
1895
- }(RemoteDependencyData$1));
2451
+ }());
1896
2452
 
1897
2453
  var TelemetryItemCreator = /** @class */ (function () {
1898
2454
  function TelemetryItemCreator() {
@@ -2179,6 +2735,7 @@
2179
2735
  var strAjaxData = "ajaxData";
2180
2736
  var strThrowInternal = "throwInternal";
2181
2737
  var strFetch = "fetch";
2738
+ var strTrackDependencyDataInternal = "trackDependencyDataInternal";
2182
2739
  var _markCount = 0;
2183
2740
  function _supportsFetch() {
2184
2741
  var _global = getGlobal();
@@ -2258,80 +2815,41 @@
2258
2815
  var _this = _super.call(this) || this;
2259
2816
  _this.identifier = AjaxMonitor.identifier;
2260
2817
  _this.priority = 120;
2261
- var strTrackDependencyDataInternal = "trackDependencyDataInternal";
2262
- var location = getLocation();
2263
- var _fetchInitialized = false;
2264
- var _xhrInitialized = false;
2265
- var _currentWindowHost = location && location.host && location.host.toLowerCase();
2266
- var _config = AjaxMonitor.getEmptyConfig();
2267
- var _enableRequestHeaderTracking = false;
2268
- var _enableAjaxErrorStatusText = false;
2269
- var _trackAjaxAttempts = 0;
2818
+ var _fetchInitialized;
2819
+ var _xhrInitialized;
2820
+ var _currentWindowHost;
2821
+ var _config;
2822
+ var _enableRequestHeaderTracking;
2823
+ var _enableAjaxErrorStatusText;
2824
+ var _trackAjaxAttempts;
2270
2825
  var _context;
2271
2826
  var _isUsingW3CHeaders;
2272
2827
  var _isUsingAIHeaders;
2273
2828
  var _markPrefix;
2274
- var _enableAjaxPerfTracking = false;
2275
- var _maxAjaxCallsPerView = 0;
2276
- var _enableResponseHeaderTracking = false;
2277
- var _hooks = [];
2278
- var _disabledUrls = {};
2829
+ var _enableAjaxPerfTracking;
2830
+ var _maxAjaxCallsPerView;
2831
+ var _enableResponseHeaderTracking;
2832
+ var _disabledUrls;
2833
+ var _disableAjaxTracking;
2834
+ var _disableFetchTracking;
2279
2835
  var _excludeRequestFromAutoTrackingPatterns;
2280
2836
  var _addRequestContext;
2281
- dynamicProto(AjaxMonitor, _this, function (_self, base) {
2837
+ var _evtNamespace;
2838
+ dynamicProto(AjaxMonitor, _this, function (_self, _base) {
2839
+ var _addHook = _base._addHook;
2840
+ _initDefaults();
2282
2841
  _self.initialize = function (config, core, extensions, pluginChain) {
2283
2842
  if (!_self.isInitialized()) {
2284
- base.initialize(config, core, extensions, pluginChain);
2285
- var ctx_1 = _self._getTelCtx();
2286
- var defaultConfig = AjaxMonitor.getDefaultConfig();
2287
- objForEachKey(defaultConfig, function (field, value) {
2288
- _config[field] = ctx_1.getConfig(AjaxMonitor.identifier, field, value);
2289
- });
2290
- var distributedTracingMode = _config.distributedTracingMode;
2291
- _enableRequestHeaderTracking = _config.enableRequestHeaderTracking;
2292
- _enableAjaxErrorStatusText = _config.enableAjaxErrorStatusText;
2293
- _enableAjaxPerfTracking = _config.enableAjaxPerfTracking;
2294
- _maxAjaxCallsPerView = _config.maxAjaxCallsPerView;
2295
- _enableResponseHeaderTracking = _config.enableResponseHeaderTracking;
2296
- _excludeRequestFromAutoTrackingPatterns = _config.excludeRequestFromAutoTrackingPatterns;
2297
- _addRequestContext = _config.addRequestContext;
2298
- _isUsingAIHeaders = distributedTracingMode === DistributedTracingModes.AI || distributedTracingMode === DistributedTracingModes.AI_AND_W3C;
2299
- _isUsingW3CHeaders = distributedTracingMode === DistributedTracingModes.AI_AND_W3C || distributedTracingMode === DistributedTracingModes.W3C;
2300
- if (_enableAjaxPerfTracking) {
2301
- var iKey = config.instrumentationKey || "unkwn";
2302
- if (iKey.length > 5) {
2303
- _markPrefix = AJAX_MONITOR_PREFIX + iKey.substring(iKey.length - 5) + ".";
2304
- }
2305
- else {
2306
- _markPrefix = AJAX_MONITOR_PREFIX + iKey + ".";
2307
- }
2308
- }
2309
- if (_config.disableAjaxTracking === false) {
2310
- _instrumentXhr();
2311
- }
2843
+ _base.initialize(config, core, extensions, pluginChain);
2844
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace("ajax"), core && core.evtNamespace && core.evtNamespace());
2845
+ _populateDefaults(config);
2846
+ _instrumentXhr();
2312
2847
  _instrumentFetch();
2313
- if (extensions.length > 0 && extensions) {
2314
- var propExt = void 0, extIx = 0;
2315
- while (!propExt && extIx < extensions.length) {
2316
- if (extensions[extIx] && extensions[extIx].identifier === PropertiesPluginIdentifier) {
2317
- propExt = extensions[extIx];
2318
- }
2319
- extIx++;
2320
- }
2321
- if (propExt) {
2322
- _context = propExt.context;
2323
- }
2324
- }
2848
+ _populateContext();
2325
2849
  }
2326
2850
  };
2327
- _self.teardown = function () {
2328
- arrForEach(_hooks, function (fn) {
2329
- fn.rm();
2330
- });
2331
- _hooks = [];
2332
- _fetchInitialized = false;
2333
- _xhrInitialized = false;
2334
- _self.setInitialized(false);
2851
+ _self._doTeardown = function () {
2852
+ _initDefaults();
2335
2853
  };
2336
2854
  _self.trackDependencyData = function (dependency, properties) {
2337
2855
  _self[strTrackDependencyDataInternal](dependency, properties);
@@ -2398,8 +2916,8 @@
2398
2916
  };
2399
2917
  _self[strTrackDependencyDataInternal] = function (dependency, properties, systemProperties) {
2400
2918
  if (_maxAjaxCallsPerView === -1 || _trackAjaxAttempts < _maxAjaxCallsPerView) {
2401
- if ((_config.distributedTracingMode === DistributedTracingModes.W3C
2402
- || _config.distributedTracingMode === DistributedTracingModes.AI_AND_W3C)
2919
+ if ((_config.distributedTracingMode === 2
2920
+ || _config.distributedTracingMode === 1 )
2403
2921
  && typeof dependency.id === "string" && dependency.id[dependency.id.length - 1] !== ".") {
2404
2922
  dependency.id += ".";
2405
2923
  }
@@ -2414,6 +2932,64 @@
2414
2932
  }
2415
2933
  ++_trackAjaxAttempts;
2416
2934
  };
2935
+ function _initDefaults() {
2936
+ var location = getLocation();
2937
+ _fetchInitialized = false;
2938
+ _xhrInitialized = false;
2939
+ _currentWindowHost = location && location.host && location.host.toLowerCase();
2940
+ _config = AjaxMonitor.getEmptyConfig();
2941
+ _enableRequestHeaderTracking = false;
2942
+ _enableAjaxErrorStatusText = false;
2943
+ _trackAjaxAttempts = 0;
2944
+ _context = null;
2945
+ _isUsingW3CHeaders = false;
2946
+ _isUsingAIHeaders = false;
2947
+ _markPrefix = null;
2948
+ _enableAjaxPerfTracking = false;
2949
+ _maxAjaxCallsPerView = 0;
2950
+ _enableResponseHeaderTracking = false;
2951
+ _disabledUrls = {};
2952
+ _disableAjaxTracking = false;
2953
+ _disableFetchTracking = true;
2954
+ _excludeRequestFromAutoTrackingPatterns = null;
2955
+ _addRequestContext = null;
2956
+ _evtNamespace = null;
2957
+ }
2958
+ function _populateDefaults(config) {
2959
+ var ctx = createProcessTelemetryContext(null, config, _self.core);
2960
+ _config = AjaxMonitor.getEmptyConfig();
2961
+ var defaultConfig = AjaxMonitor.getDefaultConfig();
2962
+ objForEachKey(defaultConfig, function (field, value) {
2963
+ _config[field] = ctx.getConfig(AjaxMonitor.identifier, field, value);
2964
+ });
2965
+ var distributedTracingMode = _config.distributedTracingMode;
2966
+ _enableRequestHeaderTracking = _config.enableRequestHeaderTracking;
2967
+ _enableAjaxErrorStatusText = _config.enableAjaxErrorStatusText;
2968
+ _enableAjaxPerfTracking = _config.enableAjaxPerfTracking;
2969
+ _maxAjaxCallsPerView = _config.maxAjaxCallsPerView;
2970
+ _enableResponseHeaderTracking = _config.enableResponseHeaderTracking;
2971
+ _excludeRequestFromAutoTrackingPatterns = _config.excludeRequestFromAutoTrackingPatterns;
2972
+ _addRequestContext = _config.addRequestContext;
2973
+ _isUsingAIHeaders = distributedTracingMode === 0 || distributedTracingMode === 1 ;
2974
+ _isUsingW3CHeaders = distributedTracingMode === 1 || distributedTracingMode === 2 ;
2975
+ if (_enableAjaxPerfTracking) {
2976
+ var iKey = config.instrumentationKey || "unkwn";
2977
+ if (iKey.length > 5) {
2978
+ _markPrefix = AJAX_MONITOR_PREFIX + iKey.substring(iKey.length - 5) + ".";
2979
+ }
2980
+ else {
2981
+ _markPrefix = AJAX_MONITOR_PREFIX + iKey + ".";
2982
+ }
2983
+ }
2984
+ _disableAjaxTracking = !!_config.disableAjaxTracking;
2985
+ _disableFetchTracking = !!_config.disableFetchTracking;
2986
+ }
2987
+ function _populateContext() {
2988
+ var propExt = _self.core.getPlugin(PropertiesPluginIdentifier);
2989
+ if (propExt) {
2990
+ _context = propExt.plugin.context;
2991
+ }
2992
+ }
2417
2993
  function _canIncludeHeaders(header) {
2418
2994
  var rlt = true;
2419
2995
  if (header || _config.ignoreHeaders) {
@@ -2433,11 +3009,12 @@
2433
3009
  }
2434
3010
  var global = getGlobal();
2435
3011
  var isPolyfill = fetch.polyfill;
2436
- if (_config.disableFetchTracking === false) {
2437
- _hooks.push(InstrumentFunc(global, strFetch, {
3012
+ if (!_disableFetchTracking && !_fetchInitialized) {
3013
+ _addHook(InstrumentFunc(global, strFetch, {
3014
+ ns: _evtNamespace,
2438
3015
  req: function (callDetails, input, init) {
2439
3016
  var fetchData;
2440
- if (_fetchInitialized &&
3017
+ if (!_disableFetchTracking && _fetchInitialized &&
2441
3018
  !_isDisabledRequest(null, input, init) &&
2442
3019
  !(isPolyfill && _xhrInitialized)) {
2443
3020
  var ctx = callDetails.ctx();
@@ -2450,31 +3027,33 @@
2450
3027
  }
2451
3028
  },
2452
3029
  rsp: function (callDetails, input) {
2453
- var fetchData = callDetails.ctx().data;
2454
- if (fetchData) {
2455
- callDetails.rslt = callDetails.rslt.then(function (response) {
2456
- _reportFetchMetrics(callDetails, (response || {}).status, input, response, fetchData, function () {
2457
- var ajaxResponse = {
2458
- statusText: response.statusText,
2459
- headerMap: null,
2460
- correlationContext: _getFetchCorrelationContext(response)
2461
- };
2462
- if (_enableResponseHeaderTracking) {
2463
- var responseHeaderMap_1 = {};
2464
- response.headers.forEach(function (value, name) {
2465
- if (_canIncludeHeaders(name)) {
2466
- responseHeaderMap_1[name] = value;
2467
- }
2468
- });
2469
- ajaxResponse.headerMap = responseHeaderMap_1;
2470
- }
2471
- return ajaxResponse;
3030
+ if (!_disableFetchTracking) {
3031
+ var fetchData_1 = callDetails.ctx().data;
3032
+ if (fetchData_1) {
3033
+ callDetails.rslt = callDetails.rslt.then(function (response) {
3034
+ _reportFetchMetrics(callDetails, (response || {}).status, input, response, fetchData_1, function () {
3035
+ var ajaxResponse = {
3036
+ statusText: response.statusText,
3037
+ headerMap: null,
3038
+ correlationContext: _getFetchCorrelationContext(response)
3039
+ };
3040
+ if (_enableResponseHeaderTracking) {
3041
+ var responseHeaderMap_1 = {};
3042
+ response.headers.forEach(function (value, name) {
3043
+ if (_canIncludeHeaders(name)) {
3044
+ responseHeaderMap_1[name] = value;
3045
+ }
3046
+ });
3047
+ ajaxResponse.headerMap = responseHeaderMap_1;
3048
+ }
3049
+ return ajaxResponse;
3050
+ });
3051
+ return response;
3052
+ })["catch"](function (reason) {
3053
+ _reportFetchMetrics(callDetails, 0, input, null, fetchData_1, null, { error: reason.message });
3054
+ throw reason;
2472
3055
  });
2473
- return response;
2474
- })["catch"](function (reason) {
2475
- _reportFetchMetrics(callDetails, 0, input, null, fetchData, null, { error: reason.message });
2476
- throw reason;
2477
- });
3056
+ }
2478
3057
  }
2479
3058
  },
2480
3059
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxOpen, "Failed to monitor Window.fetch, monitoring data for this fetch call may be incorrect.")
@@ -2482,7 +3061,8 @@
2482
3061
  _fetchInitialized = true;
2483
3062
  }
2484
3063
  else if (isPolyfill) {
2485
- _hooks.push(InstrumentFunc(global, strFetch, {
3064
+ _addHook(InstrumentFunc(global, strFetch, {
3065
+ ns: _evtNamespace,
2486
3066
  req: function (callDetails, input, init) {
2487
3067
  _isDisabledRequest(null, input, init);
2488
3068
  }
@@ -2493,58 +3073,68 @@
2493
3073
  }
2494
3074
  }
2495
3075
  function _hookProto(target, funcName, callbacks) {
2496
- _hooks.push(InstrumentProto(target, funcName, callbacks));
3076
+ _addHook(InstrumentProto(target, funcName, callbacks));
2497
3077
  }
2498
3078
  function _instrumentXhr() {
2499
- if (_supportsAjaxMonitoring(_self) && !_xhrInitialized) {
3079
+ if (_supportsAjaxMonitoring(_self) && !_disableAjaxTracking && !_xhrInitialized) {
2500
3080
  _hookProto(XMLHttpRequest, "open", {
3081
+ ns: _evtNamespace,
2501
3082
  req: function (args, method, url, async) {
2502
- var xhr = args.inst;
2503
- var ajaxData = xhr[strAjaxData];
2504
- if (!_isDisabledRequest(xhr, url) && _isMonitoredXhrInstance(xhr, true)) {
2505
- if (!ajaxData || !ajaxData.xhrMonitoringState.openDone) {
2506
- _openHandler(xhr, method, url, async);
3083
+ if (!_disableAjaxTracking) {
3084
+ var xhr = args.inst;
3085
+ var ajaxData = xhr[strAjaxData];
3086
+ if (!_isDisabledRequest(xhr, url) && _isMonitoredXhrInstance(xhr, true)) {
3087
+ if (!ajaxData || !ajaxData.xhrMonitoringState.openDone) {
3088
+ _openHandler(xhr, method, url, async);
3089
+ }
3090
+ _attachToOnReadyStateChange(xhr);
2507
3091
  }
2508
- _attachToOnReadyStateChange(xhr);
2509
3092
  }
2510
3093
  },
2511
3094
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxOpen, "Failed to monitor XMLHttpRequest.open, monitoring data for this ajax call may be incorrect.")
2512
3095
  });
2513
3096
  _hookProto(XMLHttpRequest, "send", {
3097
+ ns: _evtNamespace,
2514
3098
  req: function (args, context) {
2515
- var xhr = args.inst;
2516
- var ajaxData = xhr[strAjaxData];
2517
- if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.sendDone) {
2518
- _createMarkId("xhr", ajaxData);
2519
- ajaxData.requestSentTime = dateTimeUtilsNow();
2520
- _self.includeCorrelationHeaders(ajaxData, undefined, undefined, xhr);
2521
- ajaxData.xhrMonitoringState.sendDone = true;
3099
+ if (!_disableAjaxTracking) {
3100
+ var xhr = args.inst;
3101
+ var ajaxData = xhr[strAjaxData];
3102
+ if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.sendDone) {
3103
+ _createMarkId("xhr", ajaxData);
3104
+ ajaxData.requestSentTime = dateTimeUtilsNow();
3105
+ _self.includeCorrelationHeaders(ajaxData, undefined, undefined, xhr);
3106
+ ajaxData.xhrMonitoringState.sendDone = true;
3107
+ }
2522
3108
  }
2523
3109
  },
2524
3110
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxSend, "Failed to monitor XMLHttpRequest, monitoring data for this ajax call may be incorrect.")
2525
3111
  });
2526
3112
  _hookProto(XMLHttpRequest, "abort", {
3113
+ ns: _evtNamespace,
2527
3114
  req: function (args) {
2528
- var xhr = args.inst;
2529
- var ajaxData = xhr[strAjaxData];
2530
- if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.abortDone) {
2531
- ajaxData.aborted = 1;
2532
- ajaxData.xhrMonitoringState.abortDone = true;
3115
+ if (!_disableAjaxTracking) {
3116
+ var xhr = args.inst;
3117
+ var ajaxData = xhr[strAjaxData];
3118
+ if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.abortDone) {
3119
+ ajaxData.aborted = 1;
3120
+ ajaxData.xhrMonitoringState.abortDone = true;
3121
+ }
2533
3122
  }
2534
3123
  },
2535
3124
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxAbort, "Failed to monitor XMLHttpRequest.abort, monitoring data for this ajax call may be incorrect.")
2536
3125
  });
2537
- if (_enableRequestHeaderTracking) {
2538
- _hookProto(XMLHttpRequest, "setRequestHeader", {
2539
- req: function (args, header, value) {
3126
+ _hookProto(XMLHttpRequest, "setRequestHeader", {
3127
+ ns: _evtNamespace,
3128
+ req: function (args, header, value) {
3129
+ if (!_disableAjaxTracking && _enableRequestHeaderTracking) {
2540
3130
  var xhr = args.inst;
2541
3131
  if (_isMonitoredXhrInstance(xhr) && _canIncludeHeaders(header)) {
2542
3132
  xhr[strAjaxData].requestHeaders[header] = value;
2543
3133
  }
2544
- },
2545
- hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxSetRequestHeader, "Failed to monitor XMLHttpRequest.setRequestHeader, monitoring data for this ajax call may be incorrect.")
2546
- });
2547
- }
3134
+ }
3135
+ },
3136
+ hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxSetRequestHeader, "Failed to monitor XMLHttpRequest.setRequestHeader, monitoring data for this ajax call may be incorrect.")
3137
+ });
2548
3138
  _xhrInitialized = true;
2549
3139
  }
2550
3140
  }
@@ -2615,7 +3205,7 @@
2615
3205
  xhr[strAjaxData] = ajaxData;
2616
3206
  }
2617
3207
  function _attachToOnReadyStateChange(xhr) {
2618
- xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = attachEvent(xhr, "readystatechange", function () {
3208
+ xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = eventOn(xhr, "readystatechange", function () {
2619
3209
  try {
2620
3210
  if (xhr && xhr.readyState === 4 && _isMonitoredXhrInstance(xhr)) {
2621
3211
  _onAjaxComplete(xhr);
@@ -2630,7 +3220,7 @@
2630
3220
  });
2631
3221
  }
2632
3222
  }
2633
- });
3223
+ }, _evtNamespace);
2634
3224
  }
2635
3225
  function _getResponseText(xhr) {
2636
3226
  try {
@@ -2915,7 +3505,7 @@
2915
3505
  disableFetchTracking: true,
2916
3506
  excludeRequestFromAutoTrackingPatterns: undefined,
2917
3507
  disableCorrelationHeaders: false,
2918
- distributedTracingMode: DistributedTracingModes.AI_AND_W3C,
3508
+ distributedTracingMode: 1 ,
2919
3509
  correlationHeaderExcludedDomains: [
2920
3510
  "*.blob.core.windows.net",
2921
3511
  "*.blob.core.chinacloudapi.cn",