@microsoft/applicationinsights-common 3.4.0-nightlybeta3.2602-06 → 3.4.0-nightlybeta3.2602-11

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 - Common, 3.4.0-nightlybeta3.2602-06
2
+ * Application Insights JavaScript SDK - Common, 3.4.0-nightlybeta3.2602-11
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  'use strict';
@@ -878,6 +878,7 @@ var _DYN_TYPE = "type";
878
878
  var _DYN_MATCH = "match";
879
879
  var _DYN_SET_TRACE_FLAGS = "setTraceFlags";
880
880
  var _DYN_PATHNAME = "pathname";
881
+ var _DYN_TRACE_STATE = "traceState";
881
882
  var _DYN_COUNT = "count";
882
883
  var _DYN_PRE_TRIGGER_DATE = "preTriggerDate";
883
884
  var _DYN_GET_UTCDATE = "getUTCDate";
@@ -1307,6 +1308,74 @@ function setProtoTypeName(target, name) {
1307
1308
  }
1308
1309
  return target;
1309
1310
  }
1311
+ /*#__NO_SIDE_EFFECTS__*/
1312
+ function stringToBoolOrDefault(str, defaultValue) {
1313
+ if (defaultValue === void 0) { defaultValue = false; }
1314
+ if (str === undefined || str === null) {
1315
+ return defaultValue;
1316
+ }
1317
+ return str.toString()[_DYN_TO_LOWER_CASE ]() === "true";
1318
+ }
1319
+ /*#__NO_SIDE_EFFECTS__*/
1320
+ function msToTimeSpan(totalms) {
1321
+ if (isTimeSpan(totalms)) {
1322
+ return totalms;
1323
+ }
1324
+ if (isNaN(totalms) || totalms < 0) {
1325
+ totalms = 0;
1326
+ }
1327
+ totalms = mathRound(totalms);
1328
+ var ms = STR_EMPTY + totalms % 1000;
1329
+ var sec = STR_EMPTY + mathFloor(totalms / 1000) % 60;
1330
+ var min = STR_EMPTY + mathFloor(totalms / (1000 * 60)) % 60;
1331
+ var hour = STR_EMPTY + mathFloor(totalms / (1000 * 60 * 60)) % 24;
1332
+ var days = mathFloor(totalms / (1000 * 60 * 60 * 24));
1333
+ ms = ms[_DYN_LENGTH ] === 1 ? "00" + ms : ms[_DYN_LENGTH ] === 2 ? "0" + ms : ms;
1334
+ sec = sec[_DYN_LENGTH ] < 2 ? "0" + sec : sec;
1335
+ min = min[_DYN_LENGTH ] < 2 ? "0" + min : min;
1336
+ hour = hour[_DYN_LENGTH ] < 2 ? "0" + hour : hour;
1337
+ return (days > 0 ? days + "." : STR_EMPTY) + hour + ":" + min + ":" + sec + "." + ms;
1338
+ }
1339
+ /*#__NO_SIDE_EFFECTS__*/
1340
+ function getExtensionByName(extensions, identifier) {
1341
+ var extension = null;
1342
+ arrForEach(extensions, function (value) {
1343
+ if (value[_DYN_IDENTIFIER ] === identifier) {
1344
+ extension = value;
1345
+ return -1;
1346
+ }
1347
+ });
1348
+ return extension;
1349
+ }
1350
+ /*#__NO_SIDE_EFFECTS__*/
1351
+ function isCrossOriginError(message, url, lineNumber, columnNumber, error) {
1352
+ return !error && isString(message) && (message === "Script error." || message === "Script error");
1353
+ }
1354
+ /*#__NO_SIDE_EFFECTS__*/
1355
+ function isTimeSpan(value) {
1356
+ var result = false;
1357
+ if (isString(value)) {
1358
+ var parts = strSplit(value, ":");
1359
+ if (parts[_DYN_LENGTH ] === 3) {
1360
+ var daysHours = strSplit(parts[0], ".");
1361
+ if (daysHours[_DYN_LENGTH ] === 2) {
1362
+ result = !isNaN(parseInt(daysHours[0] || "0")) && !isNaN(parseInt(daysHours[1] || "0"));
1363
+ }
1364
+ else {
1365
+ result = !isNaN(parseInt(daysHours[0] || "0"));
1366
+ }
1367
+ result = result && !isNaN(parseInt(parts[1] || "0"));
1368
+ var secondsParts = strSplit(parts[2], ".");
1369
+ if (secondsParts[_DYN_LENGTH ] === 2) {
1370
+ result = result && !isNaN(parseInt(secondsParts[0] || "0")) && !isNaN(parseInt(secondsParts[1] || "0"));
1371
+ }
1372
+ else {
1373
+ result = result && !isNaN(parseInt(secondsParts[0] || "0"));
1374
+ }
1375
+ }
1376
+ }
1377
+ return result;
1378
+ }
1310
1379
 
1311
1380
  var strLocation = "location";
1312
1381
  var strConsole = "console";
@@ -1627,7 +1696,7 @@ function newId(maxLength) {
1627
1696
  return result;
1628
1697
  }
1629
1698
 
1630
- var version = '3.4.0-nightlybeta3.2602-06';
1699
+ var version = '3.4.0-nightlybeta3.2602-11';
1631
1700
  var instanceName = "." + newId(6);
1632
1701
  var _dataUid = 0;
1633
1702
  function _canAcceptData(target) {
@@ -2184,7 +2253,7 @@ function _createAndUseHandler(state, configHandler) {
2184
2253
  configHandler = null;
2185
2254
  }
2186
2255
  };
2187
- objDefine(handler, "toJSON", { v: function () { return "WatcherHandler" + (handler.fn ? "" : "[X]"); } });
2256
+ objDefine(handler, "toJSON", { v: function () { return "WatcherHandler" + (handler.fn ? STR_EMPTY : "[X]"); } });
2188
2257
  state.use(handler, configHandler);
2189
2258
  return handler;
2190
2259
  }
@@ -2619,6 +2688,10 @@ function _isEmpty(items, parent) {
2619
2688
  return isEmpty;
2620
2689
  }
2621
2690
  /*#__NO_SIDE_EFFECTS__*/
2691
+ function isW3cTraceState(value) {
2692
+ return !!(value && isArray(value.keys) && isFunction(value.get) && isFunction(value.set) && isFunction(value.del) && isFunction(value.hdrs));
2693
+ }
2694
+ /*#__NO_SIDE_EFFECTS__*/
2622
2695
  function createW3cTraceState(value, parent) {
2623
2696
  var cachedItems = safeGetDeferred(_parseTraceStateList, [], [value || STR_EMPTY]);
2624
2697
  function _get(key) {
@@ -2897,6 +2970,118 @@ function findAllScripts(doc) {
2897
2970
  return result;
2898
2971
  }
2899
2972
 
2973
+ var _otelTraceState;
2974
+ function _initOTelTraceStateSymbol() {
2975
+ if (!_otelTraceState) {
2976
+ _otelTraceState = createCachedValue(symbolFor("otTraceState"));
2977
+ }
2978
+ return _otelTraceState;
2979
+ }
2980
+ /*#__NO_SIDE_EFFECTS__*/
2981
+ function _createOTelTraceState(traceState) {
2982
+ if (!_otelTraceState) {
2983
+ _otelTraceState = _initOTelTraceStateSymbol();
2984
+ }
2985
+ var otTraceState = {
2986
+ set: function (key, value) {
2987
+ var newState = createW3cTraceState(STR_EMPTY, traceState);
2988
+ newState.set(key, value);
2989
+ return _createOTelTraceState(newState);
2990
+ },
2991
+ unset: function (key) {
2992
+ var newState = createW3cTraceState(STR_EMPTY, traceState);
2993
+ newState.del(key);
2994
+ return _createOTelTraceState(newState);
2995
+ },
2996
+ get: function (key) {
2997
+ return traceState.get(key);
2998
+ },
2999
+ serialize: function () {
3000
+ var headers = traceState.hdrs(1);
3001
+ if (headers[_DYN_LENGTH ] > 0) {
3002
+ return headers[0];
3003
+ }
3004
+ return STR_EMPTY;
3005
+ }
3006
+ };
3007
+ objDefine(otTraceState, _otelTraceState.v, { g: function () { return traceState; } });
3008
+ return otTraceState;
3009
+ }
3010
+ /*#__NO_SIDE_EFFECTS__*/
3011
+ function isOTelTraceState(value) {
3012
+ if (!_otelTraceState) {
3013
+ _otelTraceState = _initOTelTraceStateSymbol();
3014
+ }
3015
+ if (value && value[_otelTraceState.v]) {
3016
+ return true;
3017
+ }
3018
+ return value && isFunction(value.serialize) && isFunction(value.unset) && isFunction(value.get) && isFunction(value.set);
3019
+ }
3020
+ /*#__NO_SIDE_EFFECTS__*/
3021
+ function createOTelTraceState(value) {
3022
+ var traceState = null;
3023
+ if (isOTelTraceState(value)) {
3024
+ var parentTraceState = void 0;
3025
+ if (_otelTraceState) {
3026
+ parentTraceState = value[_otelTraceState.v];
3027
+ }
3028
+ if (parentTraceState) {
3029
+ traceState = createW3cTraceState(STR_EMPTY, parentTraceState);
3030
+ }
3031
+ else {
3032
+ traceState = createW3cTraceState(value.serialize());
3033
+ }
3034
+ }
3035
+ else if (isW3cTraceState(value)) {
3036
+ traceState = value;
3037
+ }
3038
+ else {
3039
+ traceState = createW3cTraceState(isString(value) ? value : STR_EMPTY);
3040
+ }
3041
+ return _createOTelTraceState(traceState);
3042
+ }
3043
+
3044
+ function createOTelSpanContext(traceContext) {
3045
+ var traceId = isValidTraceId(traceContext[_DYN_TRACE_ID ]) ? traceContext[_DYN_TRACE_ID ] : INVALID_TRACE_ID;
3046
+ var spanId = isValidSpanId(traceContext[_DYN_SPAN_ID ]) ? traceContext[_DYN_SPAN_ID ] : INVALID_SPAN_ID;
3047
+ var isRemote = traceContext.isRemote;
3048
+ var traceFlags = (!isNullOrUndefined(traceContext[_DYN_TRACE_FLAGS ]) ? traceContext[_DYN_TRACE_FLAGS ] : 1 );
3049
+ var otTraceState = null;
3050
+ var traceContextObj = {
3051
+ traceId: traceId,
3052
+ spanId: spanId,
3053
+ traceFlags: traceFlags
3054
+ };
3055
+ return objDefineProps(traceContextObj, {
3056
+ traceId: {
3057
+ g: function () { return traceId; },
3058
+ s: function (value) { return traceId = isValidTraceId(value) ? value : INVALID_TRACE_ID; }
3059
+ },
3060
+ spanId: {
3061
+ g: function () { return spanId; },
3062
+ s: function (value) { return spanId = isValidSpanId(value) ? value : INVALID_SPAN_ID; }
3063
+ },
3064
+ isRemote: {
3065
+ g: function () { return isRemote; }
3066
+ },
3067
+ traceFlags: {
3068
+ g: function () { return traceFlags; },
3069
+ s: function (value) { return traceFlags = value; }
3070
+ },
3071
+ traceState: {
3072
+ g: function () {
3073
+ if (!otTraceState) {
3074
+ otTraceState = createOTelTraceState(traceContext[_DYN_TRACE_STATE ]);
3075
+ }
3076
+ return otTraceState;
3077
+ },
3078
+ s: function (value) {
3079
+ otTraceState = value;
3080
+ }
3081
+ }
3082
+ });
3083
+ }
3084
+
2900
3085
  createElmNodeData("plugin");
2901
3086
  /*#__NO_SIDE_EFFECTS__*/
2902
3087
  function isDistributedTraceContext(obj) {
@@ -2987,10 +3172,23 @@ function createDistributedTraceContext(parent) {
2987
3172
  }
2988
3173
  function _getTraceState() {
2989
3174
  if (!traceState) {
2990
- traceState = createW3cTraceState(STR_EMPTY, parentCtx ? parentCtx.traceState : (initCtx ? initCtx.traceState : undefined));
3175
+ if (!parentCtx) {
3176
+ if (initCtx) {
3177
+ if (isOTelTraceState(initCtx[_DYN_TRACE_STATE ])) {
3178
+ traceState = createW3cTraceState(initCtx[_DYN_TRACE_STATE ].serialize() || STR_EMPTY, parentCtx ? parentCtx[_DYN_TRACE_STATE ] : undefined);
3179
+ }
3180
+ else {
3181
+ traceState = createW3cTraceState(STR_EMPTY, initCtx[_DYN_TRACE_STATE ] || (parentCtx ? parentCtx[_DYN_TRACE_STATE ] : undefined));
3182
+ }
3183
+ }
3184
+ }
3185
+ if (!traceState) {
3186
+ traceState = createW3cTraceState(STR_EMPTY, parentCtx ? parentCtx[_DYN_TRACE_STATE ] : undefined);
3187
+ }
2991
3188
  }
2992
3189
  return traceState;
2993
3190
  }
3191
+ var otelSpanCtx = null;
2994
3192
  var traceCtx = setProtoTypeName((_a = {
2995
3193
  getName: _getName,
2996
3194
  setName: _setPageNameFn(true),
@@ -3007,6 +3205,12 @@ function createDistributedTraceContext(parent) {
3007
3205
  _a.traceState = traceState,
3008
3206
  _a.isRemote = isRemote,
3009
3207
  _a.pageName = pageName,
3208
+ _a.getOTelSpanContext = function () {
3209
+ if (!otelSpanCtx) {
3210
+ otelSpanCtx = createOTelSpanContext(traceCtx);
3211
+ }
3212
+ return otelSpanCtx;
3213
+ },
3010
3214
  _a), "DistributedTraceContext");
3011
3215
  return objDefineProps(traceCtx, {
3012
3216
  pageName: {
@@ -3234,32 +3438,6 @@ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
3234
3438
  }
3235
3439
  }
3236
3440
 
3237
- /*#__NO_SIDE_EFFECTS__*/
3238
- function isTimeSpan(value) {
3239
- var result = false;
3240
- if (isString(value)) {
3241
- var parts = strSplit(value, ":");
3242
- if (parts[_DYN_LENGTH ] === 3) {
3243
- var daysHours = strSplit(parts[0], ".");
3244
- if (daysHours[_DYN_LENGTH ] === 2) {
3245
- result = !isNaN(parseInt(daysHours[0] || "0")) && !isNaN(parseInt(daysHours[1] || "0"));
3246
- }
3247
- else {
3248
- result = !isNaN(parseInt(daysHours[0] || "0"));
3249
- }
3250
- result = result && !isNaN(parseInt(parts[1] || "0"));
3251
- var secondsParts = strSplit(parts[2], ".");
3252
- if (secondsParts[_DYN_LENGTH ] === 2) {
3253
- result = result && !isNaN(parseInt(secondsParts[0] || "0")) && !isNaN(parseInt(secondsParts[1] || "0"));
3254
- }
3255
- else {
3256
- result = result && !isNaN(parseInt(secondsParts[0] || "0"));
3257
- }
3258
- }
3259
- }
3260
- return result;
3261
- }
3262
-
3263
3441
  var RequestHeaders = ( /* @__PURE__ */createValueMap({
3264
3442
  requestContextHeader: [0 , "Request-Context"],
3265
3443
  requestContextTargetKey: [1 , "appId"],
@@ -4813,50 +4991,6 @@ var Metric = /** @class */ (function () {
4813
4991
  return Metric;
4814
4992
  }());
4815
4993
 
4816
- /*#__NO_SIDE_EFFECTS__*/
4817
- function stringToBoolOrDefault(str, defaultValue) {
4818
- if (defaultValue === void 0) { defaultValue = false; }
4819
- if (str === undefined || str === null) {
4820
- return defaultValue;
4821
- }
4822
- return str.toString()[_DYN_TO_LOWER_CASE ]() === "true";
4823
- }
4824
- /*#__NO_SIDE_EFFECTS__*/
4825
- function msToTimeSpan(totalms) {
4826
- if (isTimeSpan(totalms)) {
4827
- return totalms;
4828
- }
4829
- if (isNaN(totalms) || totalms < 0) {
4830
- totalms = 0;
4831
- }
4832
- totalms = mathRound(totalms);
4833
- var ms = STR_EMPTY + totalms % 1000;
4834
- var sec = STR_EMPTY + mathFloor(totalms / 1000) % 60;
4835
- var min = STR_EMPTY + mathFloor(totalms / (1000 * 60)) % 60;
4836
- var hour = STR_EMPTY + mathFloor(totalms / (1000 * 60 * 60)) % 24;
4837
- var days = mathFloor(totalms / (1000 * 60 * 60 * 24));
4838
- ms = ms[_DYN_LENGTH ] === 1 ? "00" + ms : ms[_DYN_LENGTH ] === 2 ? "0" + ms : ms;
4839
- sec = sec[_DYN_LENGTH ] < 2 ? "0" + sec : sec;
4840
- min = min[_DYN_LENGTH ] < 2 ? "0" + min : min;
4841
- hour = hour[_DYN_LENGTH ] < 2 ? "0" + hour : hour;
4842
- return (days > 0 ? days + "." : STR_EMPTY) + hour + ":" + min + ":" + sec + "." + ms;
4843
- }
4844
- /*#__NO_SIDE_EFFECTS__*/
4845
- function getExtensionByName(extensions, identifier) {
4846
- var extension = null;
4847
- arrForEach(extensions, function (value) {
4848
- if (value[_DYN_IDENTIFIER ] === identifier) {
4849
- extension = value;
4850
- return -1;
4851
- }
4852
- });
4853
- return extension;
4854
- }
4855
- /*#__NO_SIDE_EFFECTS__*/
4856
- function isCrossOriginError(message, url, lineNumber, columnNumber, error) {
4857
- return !error && isString(message) && (message === "Script error." || message === "Script error");
4858
- }
4859
-
4860
4994
  var PageView = /** @class */ (function () {
4861
4995
  function PageView(logger, name, url, durationMs, properties, measurements, id) {
4862
4996
  this.aiDataContract = {