@microsoft/applicationinsights-channel-js 2.7.4-nightly.2202-09 → 2.8.0-beta.2202-06

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 - Channel, 2.7.4-nightly.2202-09
2
+ * Application Insights JavaScript SDK - Channel, 2.8.0-beta.2202-06
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -109,11 +109,11 @@
109
109
  var DynAllowInstChkTag = DynInstChkTag;
110
110
  var DynProtoDefaultOptions = '_dfOpts';
111
111
  var UnknownValue = '_unknown_';
112
- var str__Proto = "__proto__";
112
+ var str__Proto$1 = "__proto__";
113
113
  var strUseBaseInst = 'useBaseInst';
114
114
  var strSetInstFuncs = 'setInstFuncs';
115
115
  var Obj = Object;
116
- var _objGetPrototypeOf = Obj["getPrototypeOf"];
116
+ var _objGetPrototypeOf$1 = Obj["getPrototypeOf"];
117
117
  var _dynamicNames = 0;
118
118
  function _hasOwnProperty(obj, prop) {
119
119
  return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
@@ -124,12 +124,12 @@
124
124
  function _isObjectArrayOrFunctionPrototype(target) {
125
125
  return _isObjectOrArrayPrototype(target) || target === Function[Prototype];
126
126
  }
127
- function _getObjProto(target) {
127
+ function _getObjProto$1(target) {
128
128
  if (target) {
129
- if (_objGetPrototypeOf) {
130
- return _objGetPrototypeOf(target);
129
+ if (_objGetPrototypeOf$1) {
130
+ return _objGetPrototypeOf$1(target);
131
131
  }
132
- var newProto = target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
132
+ var newProto = target[str__Proto$1] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
133
133
  if (newProto) {
134
134
  return newProto;
135
135
  }
@@ -195,16 +195,16 @@
195
195
  _forEachProp(instFuncs, function (name) {
196
196
  baseFuncs[name] = _instFuncProxy(thisTarget, instFuncs, name);
197
197
  });
198
- var baseProto = _getObjProto(classProto);
198
+ var baseProto = _getObjProto$1(classProto);
199
199
  var visited = [];
200
200
  while (baseProto && !_isObjectArrayOrFunctionPrototype(baseProto) && !_hasVisited(visited, baseProto)) {
201
201
  _forEachProp(baseProto, function (name) {
202
- if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf)) {
202
+ if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf$1)) {
203
203
  baseFuncs[name] = _instFuncProxy(thisTarget, baseProto, name);
204
204
  }
205
205
  });
206
206
  visited.push(baseProto);
207
- baseProto = _getObjProto(baseProto);
207
+ baseProto = _getObjProto$1(baseProto);
208
208
  }
209
209
  return baseFuncs;
210
210
  }
@@ -218,7 +218,7 @@
218
218
  }
219
219
  if (!instFunc[DynInstChkTag] && instFuncTable[DynAllowInstChkTag] !== false) {
220
220
  var canAddInst = !_hasOwnProperty(target, funcName);
221
- var objProto = _getObjProto(target);
221
+ var objProto = _getObjProto$1(target);
222
222
  var visited = [];
223
223
  while (canAddInst && objProto && !_isObjectArrayOrFunctionPrototype(objProto) && !_hasVisited(visited, objProto)) {
224
224
  var protoFunc = objProto[funcName];
@@ -227,7 +227,7 @@
227
227
  break;
228
228
  }
229
229
  visited.push(objProto);
230
- objProto = _getObjProto(objProto);
230
+ objProto = _getObjProto$1(objProto);
231
231
  }
232
232
  try {
233
233
  if (canAddInst) {
@@ -245,7 +245,7 @@
245
245
  function _getProtoFunc(funcName, proto, currentDynProtoProxy) {
246
246
  var protoFunc = proto[funcName];
247
247
  if (protoFunc === currentDynProtoProxy) {
248
- protoFunc = _getObjProto(proto)[funcName];
248
+ protoFunc = _getObjProto$1(proto)[funcName];
249
249
  }
250
250
  if (typeof protoFunc !== strFunction) {
251
251
  _throwTypeError("[" + funcName + "] is not a " + strFunction);
@@ -279,15 +279,15 @@
279
279
  }
280
280
  }
281
281
  function _checkPrototype(classProto, thisTarget) {
282
- if (_objGetPrototypeOf) {
282
+ if (_objGetPrototypeOf$1) {
283
283
  var visited = [];
284
- var thisProto = _getObjProto(thisTarget);
284
+ var thisProto = _getObjProto$1(thisTarget);
285
285
  while (thisProto && !_isObjectArrayOrFunctionPrototype(thisProto) && !_hasVisited(visited, thisProto)) {
286
286
  if (thisProto === classProto) {
287
287
  return true;
288
288
  }
289
289
  visited.push(thisProto);
290
- thisProto = _getObjProto(thisProto);
290
+ thisProto = _getObjProto$1(thisProto);
291
291
  }
292
292
  }
293
293
  return false;
@@ -323,7 +323,7 @@
323
323
  var instFuncs = _getInstanceFuncs(target);
324
324
  var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
325
325
  delegateFunc(target, baseFuncs);
326
- var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
326
+ var setInstanceFunc = !!_objGetPrototypeOf$1 && !!perfOptions[strSetInstFuncs];
327
327
  if (setInstanceFunc && options) {
328
328
  setInstanceFunc = !!options[strSetInstFuncs];
329
329
  }
@@ -433,7 +433,10 @@
433
433
  var strMap = "map";
434
434
  var cStrTrim = "trim";
435
435
  var strToString = "toString";
436
+ var str__Proto = "__proto__";
437
+ var strConstructor = "constructor";
436
438
  var _objDefineProperty = ObjDefineProperty;
439
+ var _objFreeze = ObjClass.freeze;
437
440
  var _objKeys = ObjClass.keys;
438
441
  var StringProto = String[strShimPrototype];
439
442
  var _strTrim = StringProto[cStrTrim];
@@ -442,7 +445,20 @@
442
445
  var _isArray = Array.isArray;
443
446
  var _objToString = ObjProto[strToString];
444
447
  var _fnToString = ObjHasOwnProperty[strToString];
445
- _fnToString.call(ObjClass);
448
+ var _objFunctionString = _fnToString.call(ObjClass);
449
+ var _objGetPrototypeOf = Object["getPrototypeOf"];
450
+ function _getObjProto(target) {
451
+ if (target) {
452
+ if (_objGetPrototypeOf) {
453
+ return _objGetPrototypeOf(target);
454
+ }
455
+ var newProto = target[str__Proto] || target[strShimPrototype] || target[strConstructor];
456
+ if (newProto) {
457
+ return newProto;
458
+ }
459
+ }
460
+ return null;
461
+ }
446
462
  function isUndefined(value) {
447
463
  return value === undefined || typeof value === strShimUndefined;
448
464
  }
@@ -502,6 +518,25 @@
502
518
  function isNumber(value) {
503
519
  return typeof value === "number";
504
520
  }
521
+ function isBoolean(value) {
522
+ return typeof value === "boolean";
523
+ }
524
+ function isPlainObject(value) {
525
+ var result = false;
526
+ if (value && typeof value === "object") {
527
+ var proto = _objGetPrototypeOf ? _objGetPrototypeOf(value) : _getObjProto(value);
528
+ if (!proto) {
529
+ result = true;
530
+ }
531
+ else {
532
+ if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
533
+ proto = proto[strConstructor];
534
+ }
535
+ result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
536
+ }
537
+ }
538
+ return result;
539
+ }
505
540
  function toISOString(date) {
506
541
  if (date) {
507
542
  return _dataToISOString ? date[strToISOString]() : _toISOStringPoly(date);
@@ -641,6 +676,10 @@
641
676
  }
642
677
  return false;
643
678
  }
679
+ function _doNothing(value) {
680
+ return value;
681
+ }
682
+ var objFreeze = _objFreeze || _doNothing;
644
683
  function dateNow() {
645
684
  var dt = Date;
646
685
  return dt.now ? dt.now() : new dt().getTime();
@@ -687,6 +726,50 @@
687
726
  }
688
727
  return theObject;
689
728
  }
729
+ function objExtend(obj, obj2, obj3, obj4, obj5, obj6) {
730
+ var theArgs = arguments;
731
+ var extended = theArgs[0] || {};
732
+ var argLen = theArgs.length;
733
+ var deep = false;
734
+ var idx = 1;
735
+ if (argLen > 0 && isBoolean(extended)) {
736
+ deep = extended;
737
+ extended = theArgs[idx] || {};
738
+ idx++;
739
+ }
740
+ if (!isObject(extended)) {
741
+ extended = {};
742
+ }
743
+ for (; idx < argLen; idx++) {
744
+ var arg = theArgs[idx];
745
+ var isArgArray = isArray(arg);
746
+ var isArgObj = isObject(arg);
747
+ for (var prop in arg) {
748
+ var propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
749
+ if (!propOk) {
750
+ continue;
751
+ }
752
+ var newValue = arg[prop];
753
+ var isNewArray = void 0;
754
+ if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
755
+ var clone = extended[prop];
756
+ if (isNewArray) {
757
+ if (!isArray(clone)) {
758
+ clone = [];
759
+ }
760
+ }
761
+ else if (!isPlainObject(clone)) {
762
+ clone = {};
763
+ }
764
+ newValue = objExtend(deep, clone, newValue);
765
+ }
766
+ if (newValue !== undefined) {
767
+ extended[prop] = newValue;
768
+ }
769
+ }
770
+ }
771
+ return extended;
772
+ }
690
773
 
691
774
  var strWindow = "window";
692
775
  var strDocument = "document";
@@ -696,6 +779,7 @@
696
779
  var strJSON = "JSON";
697
780
  var strMsie = "msie";
698
781
  var strTrident = "trident/";
782
+ var strXMLHttpRequest = "XMLHttpRequest";
699
783
  var _useXDomainRequest = null;
700
784
  var _beaconsSupported = null;
701
785
  function _hasProperty(theClass, property) {
@@ -814,8 +898,7 @@
814
898
  function isFetchSupported(withKeepAlive) {
815
899
  var isSupported = false;
816
900
  try {
817
- var fetchApi = getGlobalInst("fetch");
818
- isSupported = !!fetchApi;
901
+ isSupported = !!getGlobalInst("fetch");
819
902
  var request = getGlobalInst("Request");
820
903
  if (isSupported && withKeepAlive && request) {
821
904
  isSupported = _hasProperty(request, "keepalive");
@@ -827,9 +910,9 @@
827
910
  }
828
911
  function useXDomainRequest() {
829
912
  if (_useXDomainRequest === null) {
830
- _useXDomainRequest = (typeof XDomainRequest !== "undefined");
913
+ _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
831
914
  if (_useXDomainRequest && isXhrSupported()) {
832
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst("XMLHttpRequest"), "withCredentials");
915
+ _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst(strXMLHttpRequest), "withCredentials");
833
916
  }
834
917
  }
835
918
  return _useXDomainRequest;
@@ -837,7 +920,7 @@
837
920
  function isXhrSupported() {
838
921
  var isSupported = false;
839
922
  try {
840
- var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
923
+ var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
841
924
  isSupported = !!xmlHttpRequest;
842
925
  }
843
926
  catch (e) {
@@ -1125,186 +1208,240 @@
1125
1208
  return func();
1126
1209
  }
1127
1210
 
1128
- var TelemetryPluginChain = /** @class */ (function () {
1129
- function TelemetryPluginChain(plugin, defItemCtx) {
1130
- var _self = this;
1131
- var _nextProxy = null;
1132
- var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1133
- var _hasSetNext = isFunction(plugin.setNextPlugin);
1134
- _self._hasRun = false;
1135
- _self.getPlugin = function () {
1136
- return plugin;
1137
- };
1138
- _self.getNext = function () {
1211
+ var strTelemetryPluginChain = "TelemetryPluginChain";
1212
+ var strHasRunFlags = "_hasRun";
1213
+ var strGetTelCtx = "_getTelCtx";
1214
+ var _chainId = 0;
1215
+ function _getNextProxyStart(proxy, config, core, startAt) {
1216
+ while (proxy) {
1217
+ if (proxy.getPlugin() === startAt) {
1218
+ return proxy;
1219
+ }
1220
+ proxy = proxy.getNext();
1221
+ }
1222
+ return createTelemetryProxyChain([startAt], config, core);
1223
+ }
1224
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1225
+ var _nextProxy = null;
1226
+ var _onComplete = null;
1227
+ if (startAt) {
1228
+ _nextProxy = _getNextProxyStart(telemetryChain, config, core, startAt);
1229
+ }
1230
+ else {
1231
+ _nextProxy = telemetryChain;
1232
+ }
1233
+ var context = {
1234
+ core: function () {
1235
+ return core;
1236
+ },
1237
+ diagLog: function () {
1238
+ return safeGetLogger(core, config);
1239
+ },
1240
+ getCfg: function () {
1241
+ return config;
1242
+ },
1243
+ getExtCfg: _getExtCfg,
1244
+ getConfig: _getConfig,
1245
+ hasNext: function () {
1246
+ return _nextProxy != null;
1247
+ },
1248
+ getNext: function () {
1139
1249
  return _nextProxy;
1140
- };
1141
- _self.setNext = function (nextPlugin) {
1250
+ },
1251
+ setNext: function (nextPlugin) {
1142
1252
  _nextProxy = nextPlugin;
1143
- };
1144
- _self.processTelemetry = function (env, itemCtx) {
1145
- if (!itemCtx) {
1146
- itemCtx = defItemCtx;
1253
+ },
1254
+ processNext: function (env) {
1255
+ _processChain(function (nextPlugin) {
1256
+ nextPlugin.processTelemetry(env, context);
1257
+ });
1258
+ },
1259
+ iterate: _iterateChain,
1260
+ createNew: function (plugins, startAt) {
1261
+ if (plugins === void 0) { plugins = null; }
1262
+ if (isArray(plugins)) {
1263
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1147
1264
  }
1148
- var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1149
- doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1150
- if (plugin && _hasProcessTelemetry) {
1151
- _self._hasRun = true;
1152
- try {
1153
- itemCtx.setNext(_nextProxy);
1154
- if (_hasSetNext) {
1155
- plugin.setNextPlugin(_nextProxy);
1156
- }
1157
- _nextProxy && (_nextProxy._hasRun = false);
1158
- plugin.processTelemetry(env, itemCtx);
1159
- }
1160
- catch (error) {
1161
- var hasRun = _nextProxy && _nextProxy._hasRun;
1162
- if (!_nextProxy || !hasRun) {
1163
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1164
- }
1165
- if (_nextProxy && !hasRun) {
1166
- _nextProxy.processTelemetry(env, itemCtx);
1265
+ return createProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1266
+ },
1267
+ onComplete: function (onComplete) {
1268
+ _onComplete = onComplete;
1269
+ }
1270
+ };
1271
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
1272
+ if (defaultValue === void 0) { defaultValue = {}; }
1273
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
1274
+ var theConfig;
1275
+ if (config) {
1276
+ var extConfig = config.extensionConfig;
1277
+ if (extConfig && identifier) {
1278
+ theConfig = extConfig[identifier];
1279
+ }
1280
+ }
1281
+ if (!theConfig) {
1282
+ theConfig = defaultValue;
1283
+ }
1284
+ else if (isObject(defaultValue)) {
1285
+ if (mergeDefault !== 0 ) {
1286
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
1287
+ if (config && mergeDefault === 2 ) {
1288
+ objForEachKey(defaultValue, function (field) {
1289
+ if (isNullOrUndefined(newConfig_1[field])) {
1290
+ var cfgValue = config[field];
1291
+ if (!isNullOrUndefined(cfgValue)) {
1292
+ newConfig_1[field] = cfgValue;
1293
+ }
1167
1294
  }
1168
- }
1169
- }
1170
- else if (_nextProxy) {
1171
- _self._hasRun = true;
1172
- _nextProxy.processTelemetry(env, itemCtx);
1173
- }
1174
- }, function () { return ({ item: env }); }, !(env.sync));
1175
- };
1176
- }
1177
- return TelemetryPluginChain;
1178
- }());
1179
-
1180
- function _createProxyChain(plugins, itemCtx) {
1181
- var proxies = [];
1182
- if (plugins && plugins.length > 0) {
1183
- var lastProxy = null;
1184
- for (var idx = 0; idx < plugins.length; idx++) {
1185
- var thePlugin = plugins[idx];
1186
- if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1187
- var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1188
- proxies.push(newProxy);
1189
- if (lastProxy) {
1190
- lastProxy.setNext(newProxy);
1295
+ });
1191
1296
  }
1192
- lastProxy = newProxy;
1193
1297
  }
1194
1298
  }
1299
+ return theConfig;
1300
+ }
1301
+ function _getConfig(identifier, field, defaultValue) {
1302
+ if (defaultValue === void 0) { defaultValue = false; }
1303
+ var theValue;
1304
+ var extConfig = _getExtCfg(identifier, null);
1305
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1306
+ theValue = extConfig[field];
1307
+ }
1308
+ else if (config && !isNullOrUndefined(config[field])) {
1309
+ theValue = config[field];
1310
+ }
1311
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1195
1312
  }
1196
- return proxies.length > 0 ? proxies[0] : null;
1197
- }
1198
- function _copyProxyChain(proxy, itemCtx, startAt) {
1199
- var plugins = [];
1200
- var add = startAt ? false : true;
1201
- if (proxy) {
1202
- while (proxy) {
1203
- var thePlugin = proxy.getPlugin();
1204
- if (add || thePlugin === startAt) {
1205
- add = true;
1206
- plugins.push(thePlugin);
1313
+ function _processChain(cb) {
1314
+ var nextPlugin = _nextProxy;
1315
+ if (nextPlugin) {
1316
+ _nextProxy = nextPlugin.getNext();
1317
+ cb(nextPlugin);
1318
+ }
1319
+ else {
1320
+ if (_onComplete) {
1321
+ _onComplete();
1322
+ _onComplete = null;
1207
1323
  }
1208
- proxy = proxy.getNext();
1209
1324
  }
1210
1325
  }
1211
- if (!add) {
1212
- plugins.push(startAt);
1326
+ function _iterateChain(cb) {
1327
+ while (_nextProxy) {
1328
+ _processChain(function (nextPlugin) {
1329
+ var plugin = nextPlugin.getPlugin();
1330
+ if (plugin) {
1331
+ cb(plugin);
1332
+ }
1333
+ });
1334
+ }
1213
1335
  }
1214
- return _createProxyChain(plugins, itemCtx);
1336
+ return context;
1215
1337
  }
1216
- function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1217
- var plugins = srcPlugins;
1218
- var add = false;
1219
- if (startAt && srcPlugins) {
1220
- plugins = [];
1221
- arrForEach(srcPlugins, function (thePlugin) {
1222
- if (add || thePlugin === startAt) {
1338
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
1339
+ var firstProxy = null;
1340
+ var add = startAt ? false : true;
1341
+ if (isArray(plugins) && plugins.length > 0) {
1342
+ var lastProxy_1 = null;
1343
+ arrForEach(plugins, function (thePlugin) {
1344
+ if (!add && startAt === thePlugin) {
1223
1345
  add = true;
1224
- plugins.push(thePlugin);
1346
+ }
1347
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1348
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1349
+ if (!firstProxy) {
1350
+ firstProxy = newProxy;
1351
+ }
1352
+ if (lastProxy_1) {
1353
+ lastProxy_1._setNext(newProxy);
1354
+ }
1355
+ lastProxy_1 = newProxy;
1225
1356
  }
1226
1357
  });
1227
1358
  }
1228
- if (startAt && !add) {
1229
- if (!plugins) {
1230
- plugins = [];
1231
- }
1232
- plugins.push(startAt);
1359
+ if (startAt && !firstProxy) {
1360
+ return createTelemetryProxyChain([startAt], config, core);
1233
1361
  }
1234
- return _createProxyChain(plugins, itemCtx);
1362
+ return firstProxy;
1235
1363
  }
1236
- var ProcessTelemetryContext = /** @class */ (function () {
1237
- function ProcessTelemetryContext(plugins, config, core, startAt) {
1238
- var _self = this;
1239
- var _nextProxy = null;
1240
- if (startAt !== null) {
1241
- if (plugins && isFunction(plugins.getPlugin)) {
1242
- _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1364
+ function createTelemetryPluginProxy(plugin, config, core) {
1365
+ var nextProxy = null;
1366
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1367
+ var hasSetNext = isFunction(plugin.setNextPlugin);
1368
+ var chainId;
1369
+ if (plugin) {
1370
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1371
+ }
1372
+ else {
1373
+ chainId = "Unknown-0-" + _chainId++;
1374
+ }
1375
+ var proxyChain = {
1376
+ getPlugin: function () {
1377
+ return plugin;
1378
+ },
1379
+ getNext: function () {
1380
+ return nextProxy;
1381
+ },
1382
+ processTelemetry: _processTelemetry,
1383
+ _id: chainId,
1384
+ _setNext: function (nextPlugin) {
1385
+ nextProxy = nextPlugin;
1386
+ }
1387
+ };
1388
+ function _processChain(itemCtx, processPluginFn, processProxyFn, name, details, isAsync) {
1389
+ if (!itemCtx) {
1390
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1391
+ itemCtx = plugin[strGetTelCtx]();
1243
1392
  }
1244
- else {
1245
- if (startAt) {
1246
- _nextProxy = _copyPluginChain(plugins, _self, startAt);
1247
- }
1248
- else if (isUndefined(startAt)) {
1249
- _nextProxy = _createProxyChain(plugins, _self);
1250
- }
1393
+ if (!itemCtx) {
1394
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1251
1395
  }
1252
1396
  }
1253
- _self.core = function () {
1254
- return core;
1255
- };
1256
- _self.diagLog = function () {
1257
- return safeGetLogger(core, config);
1258
- };
1259
- _self.getCfg = function () {
1260
- return config;
1261
- };
1262
- _self.getExtCfg = function (identifier, defaultValue) {
1263
- if (defaultValue === void 0) { defaultValue = {}; }
1264
- var theConfig;
1265
- if (config) {
1266
- var extConfig = config.extensionConfig;
1267
- if (extConfig && identifier) {
1268
- theConfig = extConfig[identifier];
1397
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1398
+ var hasRunContext = itemCtx[strHasRunFlags];
1399
+ if (!hasRunContext) {
1400
+ hasRunContext = itemCtx[strHasRunFlags] = {};
1401
+ }
1402
+ doPerf(itemCtx.core(), function () { return identifier + ":" + name; }, function () {
1403
+ hasRunContext[chainId] = true;
1404
+ var hasRun = false;
1405
+ itemCtx.setNext(nextProxy);
1406
+ if (plugin) {
1407
+ try {
1408
+ var nextId = nextProxy ? nextProxy._id : "";
1409
+ if (nextId) {
1410
+ hasRunContext[nextId] = false;
1411
+ }
1412
+ hasRun = processPluginFn(itemCtx);
1413
+ }
1414
+ catch (error) {
1415
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1416
+ if (hasNextRun) {
1417
+ hasRun = true;
1418
+ }
1419
+ if (!nextProxy || !hasNextRun) {
1420
+ itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1421
+ }
1269
1422
  }
1270
1423
  }
1271
- return (theConfig ? theConfig : defaultValue);
1272
- };
1273
- _self.getConfig = function (identifier, field, defaultValue) {
1274
- if (defaultValue === void 0) { defaultValue = false; }
1275
- var theValue;
1276
- var extConfig = _self.getExtCfg(identifier, null);
1277
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1278
- theValue = extConfig[field];
1424
+ if (nextProxy && !hasRun) {
1425
+ processProxyFn(itemCtx);
1279
1426
  }
1280
- else if (config && !isNullOrUndefined(config[field])) {
1281
- theValue = config[field];
1427
+ }, details, isAsync);
1428
+ }
1429
+ function _processTelemetry(env, itemCtx) {
1430
+ _processChain(itemCtx, function (itemCtx) {
1431
+ if (!hasProcessTelemetry) {
1432
+ return false;
1282
1433
  }
1283
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1284
- };
1285
- _self.hasNext = function () {
1286
- return _nextProxy != null;
1287
- };
1288
- _self.getNext = function () {
1289
- return _nextProxy;
1290
- };
1291
- _self.setNext = function (nextPlugin) {
1292
- _nextProxy = nextPlugin;
1293
- };
1294
- _self.processNext = function (env) {
1295
- var nextPlugin = _nextProxy;
1296
- if (nextPlugin) {
1297
- _nextProxy = nextPlugin.getNext();
1298
- nextPlugin.processTelemetry(env, _self);
1434
+ if (hasSetNext) {
1435
+ plugin.setNextPlugin(nextProxy);
1299
1436
  }
1300
- };
1301
- _self.createNew = function (plugins, startAt) {
1302
- if (plugins === void 0) { plugins = null; }
1303
- return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1304
- };
1437
+ plugin.processTelemetry(env, itemCtx);
1438
+ return true;
1439
+ }, function (itemCtx) {
1440
+ nextProxy.processTelemetry(env, itemCtx);
1441
+ }, "processTelemetry", function () { return ({ item: env }); }, !(env.sync));
1305
1442
  }
1306
- return ProcessTelemetryContext;
1307
- }());
1443
+ return objFreeze(proxyChain);
1444
+ }
1308
1445
 
1309
1446
  var strExtensionConfig = "extensionConfig";
1310
1447
 
@@ -1312,12 +1449,29 @@
1312
1449
  var BaseTelemetryPlugin = /** @class */ (function () {
1313
1450
  function BaseTelemetryPlugin() {
1314
1451
  var _self = this;
1315
- var _isinitialized = false;
1316
- var _rootCtx = null;
1317
- var _nextPlugin = null;
1318
- _self.core = null;
1452
+ var _isinitialized;
1453
+ var _rootCtx;
1454
+ var _nextPlugin;
1455
+ var _hooks;
1456
+ _initDefaults();
1457
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1458
+ _self.initialize = function (config, core, extensions, pluginChain) {
1459
+ _setDefaults(config, core, pluginChain);
1460
+ _isinitialized = true;
1461
+ };
1462
+ _self._addHook = function (hooks) {
1463
+ if (hooks) {
1464
+ if (isArray(hooks)) {
1465
+ _hooks = _hooks.concat(hooks);
1466
+ }
1467
+ else {
1468
+ _hooks.push(hooks);
1469
+ }
1470
+ }
1471
+ };
1472
+ });
1319
1473
  _self.diagLog = function (itemCtx) {
1320
- return _self._getTelCtx(itemCtx).diagLog();
1474
+ return _getTelCtx(itemCtx).diagLog();
1321
1475
  };
1322
1476
  _self.isInitialized = function () {
1323
1477
  return _isinitialized;
@@ -1336,11 +1490,12 @@
1336
1490
  _nextPlugin.processTelemetry(env, null);
1337
1491
  }
1338
1492
  };
1339
- _self._getTelCtx = function (currentCtx) {
1493
+ _self._getTelCtx = _getTelCtx;
1494
+ function _getTelCtx(currentCtx) {
1340
1495
  if (currentCtx === void 0) { currentCtx = null; }
1341
1496
  var itemCtx = currentCtx;
1342
1497
  if (!itemCtx) {
1343
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1498
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1344
1499
  if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1345
1500
  itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1346
1501
  }
@@ -1349,8 +1504,8 @@
1349
1504
  }
1350
1505
  }
1351
1506
  return itemCtx;
1352
- };
1353
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
1507
+ }
1508
+ function _setDefaults(config, core, pluginChain) {
1354
1509
  if (config) {
1355
1510
  setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1356
1511
  }
@@ -1362,13 +1517,16 @@
1362
1517
  nextPlugin = _nextPlugin[strGetPlugin]();
1363
1518
  }
1364
1519
  _self.core = core;
1365
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1366
- _isinitialized = true;
1367
- };
1520
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1521
+ }
1522
+ function _initDefaults() {
1523
+ _isinitialized = false;
1524
+ _self.core = null;
1525
+ _rootCtx = null;
1526
+ _nextPlugin = null;
1527
+ _hooks = [];
1528
+ }
1368
1529
  }
1369
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1370
- this._baseTelInit(config, core, extensions, pluginChain);
1371
- };
1372
1530
  return BaseTelemetryPlugin;
1373
1531
  }());
1374
1532
 
@@ -2861,7 +3019,7 @@
2861
3019
  }
2862
3020
  }
2863
3021
  var EnvelopeCreator = {
2864
- Version: "2.7.4-nightly.2202-09"
3022
+ Version: "2.8.0-beta.2202-06"
2865
3023
  };
2866
3024
  function DependencyEnvelopeCreator(logger, telemetryItem, customUndefinedValue) {
2867
3025
  EnvelopeCreatorInit(logger, telemetryItem);
@@ -3372,11 +3530,12 @@
3372
3530
  _setupTimer();
3373
3531
  }
3374
3532
  };
3375
- _self.flush = function () {
3533
+ _self.flush = function (isAsync, callBack, sendReason) {
3534
+ if (isAsync === void 0) { isAsync = true; }
3376
3535
  if (!_paused) {
3377
3536
  _clearScheduledTimer();
3378
3537
  try {
3379
- _self.triggerSend(true, null, 1 );
3538
+ _self.triggerSend(isAsync, null, sendReason || 1 );
3380
3539
  }
3381
3540
  catch (e) {
3382
3541
  _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });