@microsoft/applicationinsights-core-js 3.4.0-nightlybeta3.2504-20 → 3.4.0-nightlybeta3.2505-13
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.
- package/browser/es5/applicationinsights-core-js.cjs.js +163 -89
- package/browser/es5/applicationinsights-core-js.cjs.js.map +1 -1
- package/browser/es5/applicationinsights-core-js.cjs.min.js +2 -2
- package/browser/es5/applicationinsights-core-js.cjs.min.js.map +1 -1
- package/browser/es5/applicationinsights-core-js.gbl.js +165 -91
- package/browser/es5/applicationinsights-core-js.gbl.js.map +1 -1
- package/browser/es5/applicationinsights-core-js.gbl.min.js +2 -2
- package/browser/es5/applicationinsights-core-js.gbl.min.js.map +1 -1
- package/browser/es5/applicationinsights-core-js.integrity.json +25 -25
- package/browser/es5/applicationinsights-core-js.js +165 -91
- package/browser/es5/applicationinsights-core-js.js.map +1 -1
- package/browser/es5/applicationinsights-core-js.min.js +2 -2
- package/browser/es5/applicationinsights-core-js.min.js.map +1 -1
- package/dist/es5/applicationinsights-core-js.js +163 -89
- package/dist/es5/applicationinsights-core-js.js.map +1 -1
- package/dist/es5/applicationinsights-core-js.min.js +2 -2
- package/dist/es5/applicationinsights-core-js.min.js.map +1 -1
- package/dist-es5/Config/ConfigDefaultHelpers.js +1 -1
- package/dist-es5/Config/ConfigDefaults.js +1 -1
- package/dist-es5/Config/DynamicConfig.js +1 -1
- package/dist-es5/Config/DynamicProperty.js +1 -1
- package/dist-es5/Config/DynamicState.js +1 -1
- package/dist-es5/Config/DynamicSupport.js +1 -1
- package/dist-es5/Config/IConfigDefaults.js +1 -1
- package/dist-es5/Config/IDynamicConfigHandler.js +1 -1
- package/dist-es5/Config/IDynamicPropertyHandler.js +1 -1
- package/dist-es5/Config/IDynamicWatcher.js +1 -1
- package/dist-es5/Config/_IDynamicConfigHandlerState.js +1 -1
- package/dist-es5/JavaScriptSDK/AggregationError.js +1 -1
- package/dist-es5/JavaScriptSDK/AppInsightsCore.js +73 -25
- package/dist-es5/JavaScriptSDK/AppInsightsCore.js.map +1 -1
- package/dist-es5/JavaScriptSDK/AsyncUtils.js +1 -1
- package/dist-es5/JavaScriptSDK/BaseTelemetryPlugin.js +1 -1
- package/dist-es5/JavaScriptSDK/Constants.js +1 -1
- package/dist-es5/JavaScriptSDK/CookieMgr.js +1 -1
- package/dist-es5/JavaScriptSDK/CoreUtils.js +1 -1
- package/dist-es5/JavaScriptSDK/DataCacheHelper.js +2 -2
- package/dist-es5/JavaScriptSDK/DataCacheHelper.js.map +1 -1
- package/dist-es5/JavaScriptSDK/DbgExtensionUtils.js +1 -1
- package/dist-es5/JavaScriptSDK/DiagnosticLogger.js +1 -1
- package/dist-es5/JavaScriptSDK/EnvUtils.js +1 -1
- package/dist-es5/JavaScriptSDK/EventHelpers.js +1 -1
- package/dist-es5/JavaScriptSDK/HelperFuncs.js +18 -5
- package/dist-es5/JavaScriptSDK/HelperFuncs.js.map +1 -1
- package/dist-es5/JavaScriptSDK/InstrumentHooks.js +1 -1
- package/dist-es5/JavaScriptSDK/InternalConstants.js +1 -1
- package/dist-es5/JavaScriptSDK/NotificationManager.js +1 -1
- package/dist-es5/JavaScriptSDK/PerfManager.js +1 -1
- package/dist-es5/JavaScriptSDK/ProcessTelemetryContext.js +1 -1
- package/dist-es5/JavaScriptSDK/RandomHelper.js +1 -1
- package/dist-es5/JavaScriptSDK/ResponseHelpers.js +1 -1
- package/dist-es5/JavaScriptSDK/SenderPostManager.js +73 -3
- package/dist-es5/JavaScriptSDK/SenderPostManager.js.map +1 -1
- package/dist-es5/JavaScriptSDK/StatsBeat.js +309 -135
- package/dist-es5/JavaScriptSDK/StatsBeat.js.map +1 -1
- package/dist-es5/JavaScriptSDK/TelemetryHelpers.js +1 -2
- package/dist-es5/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
- package/dist-es5/JavaScriptSDK/TelemetryInitializerPlugin.js +1 -1
- package/dist-es5/JavaScriptSDK/UnloadHandlerContainer.js +1 -1
- package/dist-es5/JavaScriptSDK/UnloadHookContainer.js +1 -1
- package/dist-es5/JavaScriptSDK/W3cTraceParent.js +1 -1
- package/dist-es5/JavaScriptSDK.Enums/EnumHelperFuncs.js +1 -1
- package/dist-es5/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
- package/dist-es5/JavaScriptSDK.Enums/FeatureOptInEnums.js +1 -1
- package/dist-es5/JavaScriptSDK.Enums/InitActiveStatusEnum.js +1 -1
- package/dist-es5/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
- package/dist-es5/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-es5/JavaScriptSDK.Enums/StatsType.js +9 -0
- package/dist-es5/JavaScriptSDK.Enums/StatsType.js.map +1 -0
- package/dist-es5/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
- package/dist-es5/JavaScriptSDK.Enums/TelemetryUpdateReason.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IChannelControlsHost.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IConfiguration.js +2 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IConfiguration.js.map +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IDistributedTraceContext.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IExceptionConfig.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IFeatureOptIn.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/INetworkStatsbeat.js +8 -0
- package/dist-es5/JavaScriptSDK.Interfaces/INetworkStatsbeat.js.map +1 -0
- package/dist-es5/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/ISenderPostManager.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IStatsBeat.js +3 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IStatsBeat.js.map +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/{IStatsBeatEvent.js → IStatsEventData.js} +2 -2
- package/dist-es5/JavaScriptSDK.Interfaces/IStatsEventData.js.map +1 -0
- package/dist-es5/JavaScriptSDK.Interfaces/IStatsMgr.js +8 -0
- package/dist-es5/JavaScriptSDK.Interfaces/IStatsMgr.js.map +1 -0
- package/dist-es5/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/ITraceParent.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IUnloadHook.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IUnloadableComponent.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IXDomainRequest.js +1 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IXHROverride.js +1 -1
- package/dist-es5/__DynamicConstants.js +12 -12
- package/dist-es5/__DynamicConstants.js.map +1 -1
- package/dist-es5/applicationinsights-core-js.js +5 -1
- package/dist-es5/applicationinsights-core-js.js.map +1 -1
- package/package.json +1 -1
- package/types/applicationinsights-core-js.d.ts +14 -44
- package/types/applicationinsights-core-js.namespaced.d.ts +14 -44
- package/dist-es5/JavaScriptSDK/NetworkStatsbeat.js +0 -20
- package/dist-es5/JavaScriptSDK/NetworkStatsbeat.js.map +0 -1
- package/dist-es5/JavaScriptSDK.Interfaces/IStatsBeatEvent.js.map +0 -1
|
@@ -1,41 +1,194 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Core, 3.4.0-nightlybeta3.
|
|
2
|
+
* Application Insights JavaScript SDK - Core, 3.4.0-nightlybeta3.2505-13
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import { arrForEach, isNumber, makeGlobRegex, objDefineProps, scheduleTimeout, strIndexOf, strLower, utcNow } from "@nevware21/ts-utils";
|
|
8
|
+
import { onConfigChange } from "../Config/DynamicConfig";
|
|
9
|
+
import { _DYN_CANCEL, _DYN_EXCEPTION, _DYN_FAILURE, _DYN_INDEX_OF, _DYN_IS_INITIALIZED, _DYN_REQUEST_DURATION, _DYN_THROTTLE, _DYN_TOTAL_REQUEST, _DYN_TYPE } from "../__DynamicConstants";
|
|
10
|
+
import { _throwInternal, safeGetLogger } from "./DiagnosticLogger";
|
|
11
|
+
import { isFeatureEnabled } from "./HelperFuncs";
|
|
12
|
+
import { STR_EMPTY } from "./InternalConstants";
|
|
10
13
|
var STATS_COLLECTION_SHORT_INTERVAL = 900000; // 15 minutes
|
|
14
|
+
var STATS_MIN_INTERVAL_SECONDS = 60; // 1 minute
|
|
11
15
|
var STATSBEAT_LANGUAGE = "JavaScript";
|
|
12
16
|
var STATSBEAT_TYPE = "Browser";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
/**
|
|
18
|
+
* This function checks if the provided endpoint matches the provided urlMatch. It
|
|
19
|
+
* compares the endpoint with the urlMatch in a case-insensitive manner and also checks
|
|
20
|
+
* if the endpoint is a substring of the urlMatch. The urlMatch can also be a regex
|
|
21
|
+
* pattern, in which case it will be checked against the endpoint using regex.
|
|
22
|
+
* @param endpoint - The endpoint to check against the URL.
|
|
23
|
+
* @param urlMatch - The URL to check against the endpoint.
|
|
24
|
+
* @returns true if the URL matches the endpoint, false otherwise.
|
|
25
|
+
*/
|
|
26
|
+
function _isMatchEndpoint(endpoint, urlMatch) {
|
|
27
|
+
var lwrUrl = strLower(urlMatch);
|
|
28
|
+
// Check if the endpoint is a substring of the URL
|
|
29
|
+
if (strIndexOf(endpoint, lwrUrl) !== -1) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
// If it looks like a regex pattern, check if the endpoint matches the regex
|
|
33
|
+
if (strIndexOf(lwrUrl, "*") != -1 || strIndexOf(lwrUrl, "?") != -1) {
|
|
34
|
+
// Check if the endpoint is a regex pattern
|
|
35
|
+
var regex = makeGlobRegex(lwrUrl);
|
|
36
|
+
if (regex.test(endpoint)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new INetworkStatsbeat instance with the specified host.
|
|
44
|
+
* @param host - The host for the INetworkStatsbeat instance.
|
|
45
|
+
* @returns A new INetworkStatsbeat instance.
|
|
46
|
+
*/
|
|
47
|
+
function _createNetworkStatsbeat(host) {
|
|
48
|
+
return {
|
|
49
|
+
host: host,
|
|
50
|
+
totalRequest: 0,
|
|
51
|
+
success: 0,
|
|
52
|
+
throttle: {},
|
|
53
|
+
failure: {},
|
|
54
|
+
retry: {},
|
|
55
|
+
exception: {},
|
|
56
|
+
requestDuration: 0
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new IStatsBeat instance with the specified manager callbacks and statsbeat state.
|
|
61
|
+
* @param mgr - The manager callbacks to use for the IStatsBeat instance.
|
|
62
|
+
* @param statsBeatStats - The statsbeat state to use for the IStatsBeat instance.
|
|
63
|
+
* @returns A new IStatsBeat instance.
|
|
64
|
+
*/
|
|
65
|
+
function _createStatsBeat(mgr, statsBeatStats) {
|
|
66
|
+
var _networkCounter = _createNetworkStatsbeat(statsBeatStats.endpoint);
|
|
67
|
+
var _timeoutHandle; // Handle to the timer for sending telemetry. This way, we would not send telemetry when system sleep.
|
|
68
|
+
var _isEnabled = true; // Flag to check if statsbeat is enabled or not
|
|
69
|
+
function _setupTimer() {
|
|
70
|
+
if (_isEnabled && !_timeoutHandle) {
|
|
71
|
+
_timeoutHandle = mgr.start(function () {
|
|
72
|
+
_timeoutHandle = null;
|
|
73
|
+
trackStatsbeats();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function trackStatsbeats() {
|
|
78
|
+
if (_isEnabled) {
|
|
79
|
+
_trackSendRequestDuration();
|
|
80
|
+
_trackSendRequestsCount();
|
|
81
|
+
_networkCounter = _createNetworkStatsbeat(_networkCounter.host);
|
|
82
|
+
_timeoutHandle && _timeoutHandle[_DYN_CANCEL /* @min:%2ecancel */]();
|
|
83
|
+
_timeoutHandle = null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* This is a simple helper that checks if the currently reporting endpoint is the same as this instance was
|
|
88
|
+
* created with. This is used to ensure that we only send statsbeat events to the endpoint that was used
|
|
89
|
+
* when the instance was created. This is important as the endpoint can change during the lifetime of the
|
|
90
|
+
* instance and we don't want to send statsbeat events to the wrong endpoint.
|
|
91
|
+
* @param endpoint
|
|
92
|
+
* @returns true if the endpoint is the same as the one used to create the instance, false otherwise
|
|
93
|
+
*/
|
|
94
|
+
function _checkEndpoint(endpoint) {
|
|
95
|
+
return _networkCounter.host === endpoint;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Attempt to send statsbeat events to the server. This is done by creating a new event and sending it to the core.
|
|
99
|
+
* The event is created with the name and value passed in, and any additional properties are added to the event as well.
|
|
100
|
+
* This will only send the event when
|
|
101
|
+
* - the statsbeat is enabled
|
|
102
|
+
* - the statsbeat key is set for the current endpoint
|
|
103
|
+
* - the value is greater than 0
|
|
104
|
+
* @param name - The name of the event to send
|
|
105
|
+
* @param val - The value of the event to send
|
|
106
|
+
* @param properties - Optional additional properties to add to the event
|
|
107
|
+
*/
|
|
108
|
+
function _sendStatsbeats(name, val, properties) {
|
|
109
|
+
if (_isEnabled && val && val > 0) {
|
|
110
|
+
// Add extra properties
|
|
111
|
+
var baseProperties = {
|
|
112
|
+
"rp": "unknown",
|
|
113
|
+
"attach": "Manual",
|
|
114
|
+
"cikey": statsBeatStats.cKey,
|
|
115
|
+
"os": STATSBEAT_TYPE,
|
|
116
|
+
"language": STATSBEAT_LANGUAGE,
|
|
117
|
+
"version": statsBeatStats.sdkVer || "unknown",
|
|
118
|
+
"endpoint": "breeze",
|
|
119
|
+
"host": _networkCounter.host
|
|
34
120
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
121
|
+
// Manually merge properties instead of using spread syntax
|
|
122
|
+
var combinedProps = { "host": _networkCounter.host };
|
|
123
|
+
// Add properties if present
|
|
124
|
+
if (properties) {
|
|
125
|
+
for (var key in properties) {
|
|
126
|
+
if (properties.hasOwnProperty(key)) {
|
|
127
|
+
combinedProps[key] = properties[key];
|
|
128
|
+
}
|
|
38
129
|
}
|
|
130
|
+
}
|
|
131
|
+
// Add base properties
|
|
132
|
+
for (var key in baseProperties) {
|
|
133
|
+
if (baseProperties.hasOwnProperty(key)) {
|
|
134
|
+
combinedProps[key] = baseProperties[key];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
var statsbeatEvent = {
|
|
138
|
+
name: name,
|
|
139
|
+
baseData: {
|
|
140
|
+
name: name,
|
|
141
|
+
average: val,
|
|
142
|
+
properties: combinedProps
|
|
143
|
+
},
|
|
144
|
+
baseType: "MetricData"
|
|
145
|
+
};
|
|
146
|
+
mgr.track(statsBeat, statsbeatEvent);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function _trackSendRequestDuration() {
|
|
150
|
+
var totalRequest = _networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */];
|
|
151
|
+
if (_networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */] > 0) {
|
|
152
|
+
var averageRequestExecutionTime = _networkCounter[_DYN_REQUEST_DURATION /* @min:%2erequestDuration */] / totalRequest;
|
|
153
|
+
_sendStatsbeats("Request_Duration", averageRequestExecutionTime);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function _trackSendRequestsCount() {
|
|
157
|
+
var currentCounter = _networkCounter;
|
|
158
|
+
_sendStatsbeats("Request_Success_Count", currentCounter.success);
|
|
159
|
+
for (var code in currentCounter[_DYN_FAILURE /* @min:%2efailure */]) {
|
|
160
|
+
var count = currentCounter[_DYN_FAILURE /* @min:%2efailure */][code];
|
|
161
|
+
_sendStatsbeats("failure", count, { statusCode: code });
|
|
162
|
+
}
|
|
163
|
+
for (var code in currentCounter.retry) {
|
|
164
|
+
var count = currentCounter.retry[code];
|
|
165
|
+
_sendStatsbeats("retry", count, { statusCode: code });
|
|
166
|
+
}
|
|
167
|
+
for (var code in currentCounter[_DYN_EXCEPTION /* @min:%2eexception */]) {
|
|
168
|
+
var count = currentCounter[_DYN_EXCEPTION /* @min:%2eexception */][code];
|
|
169
|
+
_sendStatsbeats("exception", count, { exceptionType: code });
|
|
170
|
+
}
|
|
171
|
+
for (var code in currentCounter[_DYN_THROTTLE /* @min:%2ethrottle */]) {
|
|
172
|
+
var count = currentCounter[_DYN_THROTTLE /* @min:%2ethrottle */][code];
|
|
173
|
+
_sendStatsbeats("Throttle_Count", count, { statusCode: code });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function _setEnabled(isEnabled) {
|
|
177
|
+
_isEnabled = isEnabled;
|
|
178
|
+
if (!_isEnabled) {
|
|
179
|
+
if (_timeoutHandle) {
|
|
180
|
+
_timeoutHandle[_DYN_CANCEL /* @min:%2ecancel */]();
|
|
181
|
+
_timeoutHandle = null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// THE statsbeat instance being created and returned
|
|
186
|
+
var statsBeat = {
|
|
187
|
+
enabled: !!_isEnabled,
|
|
188
|
+
endpoint: STR_EMPTY,
|
|
189
|
+
type: 0 /* eStatsType.SDK */,
|
|
190
|
+
count: function (status, payloadData, endpoint) {
|
|
191
|
+
if (_isEnabled && _checkEndpoint(endpoint)) {
|
|
39
192
|
if (payloadData && payloadData["statsBeatData"] && payloadData["statsBeatData"]["startTime"]) {
|
|
40
193
|
_networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */] = (_networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */] || 0) + 1;
|
|
41
194
|
_networkCounter[_DYN_REQUEST_DURATION /* @min:%2erequestDuration */] += utcNow() - payloadData["statsBeatData"]["startTime"];
|
|
@@ -55,122 +208,143 @@ var Statsbeat = /** @class */ (function () {
|
|
|
55
208
|
_networkCounter[_DYN_FAILURE /* @min:%2efailure */][status] = (_networkCounter[_DYN_FAILURE /* @min:%2efailure */][status] || 0) + 1;
|
|
56
209
|
}
|
|
57
210
|
_setupTimer();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
_self.countException = function (endpoint, exceptionType) {
|
|
63
|
-
if (!_isEnabled || !_checkEndpoint(endpoint)) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
countException: function (endpoint, exceptionType) {
|
|
214
|
+
if (_isEnabled && _checkEndpoint(endpoint)) {
|
|
66
215
|
_networkCounter[_DYN_EXCEPTION /* @min:%2eexception */][exceptionType] = (_networkCounter[_DYN_EXCEPTION /* @min:%2eexception */][exceptionType] || 0) + 1;
|
|
67
216
|
_setupTimer();
|
|
68
|
-
};
|
|
69
|
-
function _setupTimer() {
|
|
70
|
-
if (!_timeoutHandle) {
|
|
71
|
-
_timeoutHandle = scheduleTimeout(function () {
|
|
72
|
-
_timeoutHandle = null;
|
|
73
|
-
trackStatsbeats();
|
|
74
|
-
}, STATS_COLLECTION_SHORT_INTERVAL);
|
|
75
|
-
}
|
|
76
217
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
// Make the properties readonly / reactive to changes
|
|
221
|
+
return objDefineProps(statsBeat, {
|
|
222
|
+
enabled: { g: function () { return _isEnabled; }, s: _setEnabled },
|
|
223
|
+
type: { g: function () { return statsBeatStats[_DYN_TYPE /* @min:%2etype */]; } },
|
|
224
|
+
endpoint: { g: function () { return _networkCounter.host; } }
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function _getEndpointCfg(statsBeatConfig, type) {
|
|
228
|
+
var endpointCfg = null;
|
|
229
|
+
if (statsBeatConfig && statsBeatConfig.endCfg) {
|
|
230
|
+
arrForEach(statsBeatConfig.endCfg, function (value) {
|
|
231
|
+
if (value[_DYN_TYPE /* @min:%2etype */] === type) {
|
|
232
|
+
endpointCfg = value;
|
|
233
|
+
return -1; // Stop the loop if we found a match
|
|
83
234
|
}
|
|
84
|
-
|
|
85
|
-
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return endpointCfg;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* This function retrieves the stats instrumentation key (iKey) for the given endpoint from
|
|
241
|
+
* the statsBeatConfig. It iterates through the keys in the statsBeatConfig and checks if
|
|
242
|
+
* the endpoint matches any of the URLs associated with that key. If a match is found, it
|
|
243
|
+
* returns the corresponding iKey.
|
|
244
|
+
* @param statsBeatConfig - The configuration object for StatsBeat.
|
|
245
|
+
* @param endpoint - The endpoint to check against the URLs in the configuration.
|
|
246
|
+
* @returns The iKey associated with the matching endpoint, or null if no match is found.
|
|
247
|
+
*/
|
|
248
|
+
function _getIKey(endpointCfg, endpoint) {
|
|
249
|
+
var statsKey = null;
|
|
250
|
+
if (endpointCfg.keyMap) {
|
|
251
|
+
arrForEach(endpointCfg.keyMap, function (keyMap) {
|
|
252
|
+
if (keyMap.match) {
|
|
253
|
+
arrForEach(keyMap.match, function (url) {
|
|
254
|
+
if (_isMatchEndpoint(url, endpoint)) {
|
|
255
|
+
statsKey = keyMap.key || null;
|
|
256
|
+
// Stop the loop if we found a match
|
|
257
|
+
return -1;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
86
260
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
_os = STATSBEAT_TYPE;
|
|
261
|
+
if (statsKey) {
|
|
262
|
+
// Stop the loop if we found a match
|
|
263
|
+
return -1;
|
|
91
264
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
return statsKey;
|
|
268
|
+
}
|
|
269
|
+
export function createStatsMgr() {
|
|
270
|
+
var _isMgrEnabled = false; // Flag to check if statsbeat is enabled or not
|
|
271
|
+
var _core; // The core instance that is used to send telemetry
|
|
272
|
+
var _shortInterval = STATS_COLLECTION_SHORT_INTERVAL;
|
|
273
|
+
var _statsBeatConfig;
|
|
274
|
+
// Lazily initialize the manager and start listening for configuration changes
|
|
275
|
+
// This is also required to handle "unloading" and then re-initializing again
|
|
276
|
+
function _init(core, statsConfig, featureName) {
|
|
277
|
+
if (_core) {
|
|
278
|
+
// If the core is already set, then just return with an empty unload hook
|
|
279
|
+
_throwInternal(safeGetLogger(core), 2 /* eLoggingSeverity.WARNING */, 113 /* _eInternalMessageId.StatsBeatManagerException */, "StatsBeat manager is already initialized");
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
_core = core;
|
|
283
|
+
if (core && core[_DYN_IS_INITIALIZED /* @min:%2eisInitialized */]()) {
|
|
284
|
+
// Start listening for configuration changes from the core config, within a config change handler
|
|
285
|
+
// This will support the scenario where the config is changed after the statsbeat has been created
|
|
286
|
+
return onConfigChange(core.config, function (details) {
|
|
287
|
+
// Check the feature state again to see if it has changed
|
|
288
|
+
_isMgrEnabled = false;
|
|
289
|
+
if (statsConfig && isFeatureEnabled(statsConfig.feature, details.cfg, false) === true) {
|
|
290
|
+
// Call the getCfg function to get the latest configuration for the statsbeat instance
|
|
291
|
+
// This should also evaluate the throttling level and other settings for the statsbeat instance
|
|
292
|
+
// to determine if it should be enabled or not.
|
|
293
|
+
_statsBeatConfig = statsConfig.getCfg(core, details.cfg);
|
|
294
|
+
if (_statsBeatConfig) {
|
|
295
|
+
_isMgrEnabled = true;
|
|
296
|
+
_shortInterval = STATS_COLLECTION_SHORT_INTERVAL; // Reset to the default in-case the config is removed / changed
|
|
297
|
+
if (isNumber(_statsBeatConfig.shrtInt) && _statsBeatConfig.shrtInt > STATS_MIN_INTERVAL_SECONDS) {
|
|
298
|
+
_shortInterval = _statsBeatConfig.shrtInt * 1000; // Convert to milliseconds
|
|
114
299
|
}
|
|
115
300
|
}
|
|
116
301
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
var totalRequest = _networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */];
|
|
137
|
-
if (_networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */] > 0) {
|
|
138
|
-
var averageRequestExecutionTime = _networkCounter[_DYN_REQUEST_DURATION /* @min:%2erequestDuration */] / totalRequest;
|
|
139
|
-
_sendStatsbeats("Request_Duration", averageRequestExecutionTime);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
function _trackSendRequestsCount() {
|
|
143
|
-
var currentCounter = _networkCounter;
|
|
144
|
-
_sendStatsbeats("Request_Success_Count", currentCounter.success);
|
|
145
|
-
for (var code in currentCounter[_DYN_FAILURE /* @min:%2efailure */]) {
|
|
146
|
-
var count = currentCounter[_DYN_FAILURE /* @min:%2efailure */][code];
|
|
147
|
-
_sendStatsbeats("failure", count, { statusCode: code });
|
|
148
|
-
}
|
|
149
|
-
for (var code in currentCounter.retry) {
|
|
150
|
-
var count = currentCounter.retry[code];
|
|
151
|
-
_sendStatsbeats("retry", count, { statusCode: code });
|
|
152
|
-
}
|
|
153
|
-
for (var code in currentCounter[_DYN_EXCEPTION /* @min:%2eexception */]) {
|
|
154
|
-
var count = currentCounter[_DYN_EXCEPTION /* @min:%2eexception */][code];
|
|
155
|
-
_sendStatsbeats("exception", count, { exceptionType: code });
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function _track(statsBeat, statsBeatEvent) {
|
|
306
|
+
if (_isMgrEnabled && _statsBeatConfig) {
|
|
307
|
+
var endpoint = statsBeat.endpoint;
|
|
308
|
+
var sendEvt = !!statsBeat[_DYN_TYPE /* @min:%2etype */];
|
|
309
|
+
// Fetching the stats key for the endpoint here to support the scenario where the endpoint is changed
|
|
310
|
+
// after the statsbeat instance is created. This will ensure that the correct stats key is used for the endpoint.
|
|
311
|
+
// It also avoids the tracking of the statsbeat event if the endpoint is not in the config.
|
|
312
|
+
var endpointCfg = _getEndpointCfg(_statsBeatConfig, statsBeat[_DYN_TYPE /* @min:%2etype */]);
|
|
313
|
+
if (endpointCfg) {
|
|
314
|
+
// Check for key remapping
|
|
315
|
+
var statsKey = _getIKey(endpointCfg, endpoint);
|
|
316
|
+
if (statsKey) {
|
|
317
|
+
// Using this iKey for the statsbeat event
|
|
318
|
+
statsBeatEvent.iKey = statsKey;
|
|
319
|
+
// We have specific config for this endpoint, so we can send the event
|
|
320
|
+
sendEvt = true;
|
|
156
321
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
_sendStatsbeats("Throttle_Count", count, { statusCode: code });
|
|
322
|
+
if (sendEvt) {
|
|
323
|
+
_core.track(statsBeatEvent);
|
|
160
324
|
}
|
|
161
325
|
}
|
|
162
|
-
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function _createInstance(state) {
|
|
329
|
+
var instance = null;
|
|
330
|
+
if (_isMgrEnabled) {
|
|
331
|
+
var callbacks = {
|
|
332
|
+
start: function (cb) {
|
|
333
|
+
return scheduleTimeout(cb, _shortInterval);
|
|
334
|
+
},
|
|
335
|
+
track: _track
|
|
336
|
+
};
|
|
337
|
+
instance = _createStatsBeat(callbacks, state);
|
|
338
|
+
}
|
|
339
|
+
return instance;
|
|
163
340
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return Statsbeat;
|
|
174
|
-
}());
|
|
175
|
-
export { Statsbeat };
|
|
341
|
+
var theMgr = {
|
|
342
|
+
enabled: false,
|
|
343
|
+
newInst: _createInstance,
|
|
344
|
+
init: _init
|
|
345
|
+
};
|
|
346
|
+
return objDefineProps(theMgr, {
|
|
347
|
+
"enabled": { g: function () { return _isMgrEnabled; } }
|
|
348
|
+
});
|
|
349
|
+
}
|
|
176
350
|
//# sourceMappingURL=StatsBeat.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatsBeat.js.map","sources":["StatsBeat.js"],"sourcesContent":["import dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { scheduleTimeout, utcNow } from \"@nevware21/ts-utils\";\r\nimport { _DYN_CANCEL, _DYN_EXCEPTION, _DYN_FAILURE, _DYN_INDEX_OF, _DYN_INITIALIZE, _DYN_IS_INITIALIZED, _DYN_REQUEST_DURATION, _DYN_THROTTLE, _DYN_TOTAL_REQUEST, _DYN_VERSION } from \"../__DynamicConstants\";\r\nimport { createNetworkStatsbeat } from \"./NetworkStatsbeat\";\r\nvar INSTRUMENTATION_KEY = \"c4a29126-a7cb-47e5-b348-11414998b11e\";\r\nvar STATS_COLLECTION_SHORT_INTERVAL = 900000; // 15 minutes\r\nvar STATSBEAT_LANGUAGE = \"JavaScript\";\r\nvar STATSBEAT_TYPE = \"Browser\";\r\nvar Statsbeat = /** @class */ (function () {\r\n function Statsbeat() {\r\n var _networkCounter;\r\n var _isEnabled = false;\r\n var _core;\r\n var _timeoutHandle; // Handle to the timer for sending telemetry. This way, we would not send telemetry when system sleep.\r\n // Custom dimensions\r\n var _cikey;\r\n var _language;\r\n var _sdkVersion;\r\n var _os;\r\n dynamicProto(Statsbeat, this, function (_self, _base) {\r\n _self[_DYN_INITIALIZE /* @min:%2einitialize */] = function (core, statsBeatConfig) {\r\n _core = core;\r\n _networkCounter = createNetworkStatsbeat(statsBeatConfig.endpoint);\r\n _isEnabled = true;\r\n _sdkVersion = statsBeatConfig[_DYN_VERSION /* @min:%2eversion */];\r\n _getCustomProperties(statsBeatConfig.ikey);\r\n };\r\n _self[_DYN_IS_INITIALIZED /* @min:%2eisInitialized */] = function () {\r\n return !!_isEnabled;\r\n };\r\n _self.count = function (status, payloadData, endpoint) {\r\n if (!_isEnabled || !_checkEndpoint(endpoint)) {\r\n return;\r\n }\r\n if (payloadData && payloadData[\"statsBeatData\"] && payloadData[\"statsBeatData\"][\"startTime\"]) {\r\n _networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */] = (_networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */] || 0) + 1;\r\n _networkCounter[_DYN_REQUEST_DURATION /* @min:%2erequestDuration */] += utcNow() - payloadData[\"statsBeatData\"][\"startTime\"];\r\n }\r\n var retryArray = [401, 403, 408, 429, 500, 502, 503, 504];\r\n var throttleArray = [402, 439];\r\n if (status >= 200 && status < 300) {\r\n _networkCounter.success++;\r\n }\r\n else if (retryArray[_DYN_INDEX_OF /* @min:%2eindexOf */](status) !== -1) {\r\n _networkCounter.retry[status] = (_networkCounter.retry[status] || 0) + 1;\r\n }\r\n else if (throttleArray[_DYN_INDEX_OF /* @min:%2eindexOf */](status) !== -1) {\r\n _networkCounter[_DYN_THROTTLE /* @min:%2ethrottle */][status] = (_networkCounter[_DYN_THROTTLE /* @min:%2ethrottle */][status] || 0) + 1;\r\n }\r\n else if (status !== 307 && status !== 308) {\r\n _networkCounter[_DYN_FAILURE /* @min:%2efailure */][status] = (_networkCounter[_DYN_FAILURE /* @min:%2efailure */][status] || 0) + 1;\r\n }\r\n _setupTimer();\r\n };\r\n _self.getEndpoint = function () {\r\n return _networkCounter ? _networkCounter.host : null;\r\n };\r\n _self.countException = function (endpoint, exceptionType) {\r\n if (!_isEnabled || !_checkEndpoint(endpoint)) {\r\n return;\r\n }\r\n _networkCounter[_DYN_EXCEPTION /* @min:%2eexception */][exceptionType] = (_networkCounter[_DYN_EXCEPTION /* @min:%2eexception */][exceptionType] || 0) + 1;\r\n _setupTimer();\r\n };\r\n function _setupTimer() {\r\n if (!_timeoutHandle) {\r\n _timeoutHandle = scheduleTimeout(function () {\r\n _timeoutHandle = null;\r\n trackStatsbeats();\r\n }, STATS_COLLECTION_SHORT_INTERVAL);\r\n }\r\n }\r\n function trackStatsbeats() {\r\n _trackSendRequestDuration();\r\n _trackSendRequestsCount();\r\n _networkCounter = createNetworkStatsbeat(_networkCounter.host);\r\n _timeoutHandle && _timeoutHandle[_DYN_CANCEL /* @min:%2ecancel */]();\r\n _timeoutHandle = null;\r\n }\r\n function _checkEndpoint(endpoint) {\r\n return _networkCounter && _networkCounter.host === endpoint;\r\n }\r\n function _getCustomProperties(ikey) {\r\n _cikey = ikey;\r\n _language = STATSBEAT_LANGUAGE;\r\n _os = STATSBEAT_TYPE;\r\n }\r\n function _sendStatsbeats(name, val, properties) {\r\n if (!val || val <= 0) {\r\n return;\r\n }\r\n // Add extra properties\r\n var baseProperties = {\r\n \"rp\": \"unknown\",\r\n \"attach\": \"Manual\",\r\n \"cikey\": _cikey,\r\n \"os\": _os,\r\n \"language\": _language,\r\n \"version\": _sdkVersion,\r\n \"endpoint\": \"breeze\",\r\n \"host\": _networkCounter.host\r\n };\r\n // Manually merge properties instead of using spread syntax\r\n var combinedProps = { \"host\": _networkCounter.host };\r\n // Add properties if present\r\n if (properties) {\r\n for (var key in properties) {\r\n if (properties.hasOwnProperty(key)) {\r\n combinedProps[key] = properties[key];\r\n }\r\n }\r\n }\r\n // Add base properties\r\n for (var key in baseProperties) {\r\n if (baseProperties.hasOwnProperty(key)) {\r\n combinedProps[key] = baseProperties[key];\r\n }\r\n }\r\n var statsbeatEvent = {\r\n iKey: INSTRUMENTATION_KEY,\r\n name: name,\r\n baseData: {\r\n name: name,\r\n average: val,\r\n properties: combinedProps\r\n },\r\n baseType: \"MetricData\"\r\n };\r\n _core.track(statsbeatEvent);\r\n }\r\n function _trackSendRequestDuration() {\r\n var totalRequest = _networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */];\r\n if (_networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */] > 0) {\r\n var averageRequestExecutionTime = _networkCounter[_DYN_REQUEST_DURATION /* @min:%2erequestDuration */] / totalRequest;\r\n _sendStatsbeats(\"Request_Duration\", averageRequestExecutionTime);\r\n }\r\n }\r\n function _trackSendRequestsCount() {\r\n var currentCounter = _networkCounter;\r\n _sendStatsbeats(\"Request_Success_Count\", currentCounter.success);\r\n for (var code in currentCounter[_DYN_FAILURE /* @min:%2efailure */]) {\r\n var count = currentCounter[_DYN_FAILURE /* @min:%2efailure */][code];\r\n _sendStatsbeats(\"failure\", count, { statusCode: code });\r\n }\r\n for (var code in currentCounter.retry) {\r\n var count = currentCounter.retry[code];\r\n _sendStatsbeats(\"retry\", count, { statusCode: code });\r\n }\r\n for (var code in currentCounter[_DYN_EXCEPTION /* @min:%2eexception */]) {\r\n var count = currentCounter[_DYN_EXCEPTION /* @min:%2eexception */][code];\r\n _sendStatsbeats(\"exception\", count, { exceptionType: code });\r\n }\r\n for (var code in currentCounter[_DYN_THROTTLE /* @min:%2ethrottle */]) {\r\n var count = currentCounter[_DYN_THROTTLE /* @min:%2ethrottle */][code];\r\n _sendStatsbeats(\"Throttle_Count\", count, { statusCode: code });\r\n }\r\n }\r\n });\r\n }\r\n Statsbeat.prototype.initialize = function (core, statsBeatConfig) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n Statsbeat.prototype.isInitialized = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n Statsbeat.prototype.count = function (status, payloadData, endpoint) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n Statsbeat.prototype.countException = function (endpoint, exceptionType) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n Statsbeat.prototype.getEndpoint = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n return Statsbeat;\r\n}());\r\nexport { Statsbeat };\r\n//# sourceMappingURL=StatsBeat.js.map"],"names":[],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;oDAgBM,CAAC;;;;;qBACc;AACrB;AACA;AACA"}
|
|
1
|
+
{"version":3,"file":"StatsBeat.js.map","sources":["StatsBeat.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { arrForEach, isNumber, makeGlobRegex, objDefineProps, scheduleTimeout, strIndexOf, strLower, utcNow } from \"@nevware21/ts-utils\";\r\nimport { onConfigChange } from \"../Config/DynamicConfig\";\r\nimport { _DYN_CANCEL, _DYN_EXCEPTION, _DYN_FAILURE, _DYN_INDEX_OF, _DYN_IS_INITIALIZED, _DYN_REQUEST_DURATION, _DYN_THROTTLE, _DYN_TOTAL_REQUEST, _DYN_TYPE } from \"../__DynamicConstants\";\r\nimport { _throwInternal, safeGetLogger } from \"./DiagnosticLogger\";\r\nimport { isFeatureEnabled } from \"./HelperFuncs\";\r\nimport { STR_EMPTY } from \"./InternalConstants\";\r\nvar STATS_COLLECTION_SHORT_INTERVAL = 900000; // 15 minutes\r\nvar STATS_MIN_INTERVAL_SECONDS = 60; // 1 minute\r\nvar STATSBEAT_LANGUAGE = \"JavaScript\";\r\nvar STATSBEAT_TYPE = \"Browser\";\r\n/**\r\n * This function checks if the provided endpoint matches the provided urlMatch. It\r\n * compares the endpoint with the urlMatch in a case-insensitive manner and also checks\r\n * if the endpoint is a substring of the urlMatch. The urlMatch can also be a regex\r\n * pattern, in which case it will be checked against the endpoint using regex.\r\n * @param endpoint - The endpoint to check against the URL.\r\n * @param urlMatch - The URL to check against the endpoint.\r\n * @returns true if the URL matches the endpoint, false otherwise.\r\n */\r\nfunction _isMatchEndpoint(endpoint, urlMatch) {\r\n var lwrUrl = strLower(urlMatch);\r\n // Check if the endpoint is a substring of the URL\r\n if (strIndexOf(endpoint, lwrUrl) !== -1) {\r\n return true;\r\n }\r\n // If it looks like a regex pattern, check if the endpoint matches the regex\r\n if (strIndexOf(lwrUrl, \"*\") != -1 || strIndexOf(lwrUrl, \"?\") != -1) {\r\n // Check if the endpoint is a regex pattern\r\n var regex = makeGlobRegex(lwrUrl);\r\n if (regex.test(endpoint)) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n/**\r\n * Creates a new INetworkStatsbeat instance with the specified host.\r\n * @param host - The host for the INetworkStatsbeat instance.\r\n * @returns A new INetworkStatsbeat instance.\r\n */\r\nfunction _createNetworkStatsbeat(host) {\r\n return {\r\n host: host,\r\n totalRequest: 0,\r\n success: 0,\r\n throttle: {},\r\n failure: {},\r\n retry: {},\r\n exception: {},\r\n requestDuration: 0\r\n };\r\n}\r\n/**\r\n * Creates a new IStatsBeat instance with the specified manager callbacks and statsbeat state.\r\n * @param mgr - The manager callbacks to use for the IStatsBeat instance.\r\n * @param statsBeatStats - The statsbeat state to use for the IStatsBeat instance.\r\n * @returns A new IStatsBeat instance.\r\n */\r\nfunction _createStatsBeat(mgr, statsBeatStats) {\r\n var _networkCounter = _createNetworkStatsbeat(statsBeatStats.endpoint);\r\n var _timeoutHandle; // Handle to the timer for sending telemetry. This way, we would not send telemetry when system sleep.\r\n var _isEnabled = true; // Flag to check if statsbeat is enabled or not\r\n function _setupTimer() {\r\n if (_isEnabled && !_timeoutHandle) {\r\n _timeoutHandle = mgr.start(function () {\r\n _timeoutHandle = null;\r\n trackStatsbeats();\r\n });\r\n }\r\n }\r\n function trackStatsbeats() {\r\n if (_isEnabled) {\r\n _trackSendRequestDuration();\r\n _trackSendRequestsCount();\r\n _networkCounter = _createNetworkStatsbeat(_networkCounter.host);\r\n _timeoutHandle && _timeoutHandle[_DYN_CANCEL /* @min:%2ecancel */]();\r\n _timeoutHandle = null;\r\n }\r\n }\r\n /**\r\n * This is a simple helper that checks if the currently reporting endpoint is the same as this instance was\r\n * created with. This is used to ensure that we only send statsbeat events to the endpoint that was used\r\n * when the instance was created. This is important as the endpoint can change during the lifetime of the\r\n * instance and we don't want to send statsbeat events to the wrong endpoint.\r\n * @param endpoint\r\n * @returns true if the endpoint is the same as the one used to create the instance, false otherwise\r\n */\r\n function _checkEndpoint(endpoint) {\r\n return _networkCounter.host === endpoint;\r\n }\r\n /**\r\n * Attempt to send statsbeat events to the server. This is done by creating a new event and sending it to the core.\r\n * The event is created with the name and value passed in, and any additional properties are added to the event as well.\r\n * This will only send the event when\r\n * - the statsbeat is enabled\r\n * - the statsbeat key is set for the current endpoint\r\n * - the value is greater than 0\r\n * @param name - The name of the event to send\r\n * @param val - The value of the event to send\r\n * @param properties - Optional additional properties to add to the event\r\n */\r\n function _sendStatsbeats(name, val, properties) {\r\n if (_isEnabled && val && val > 0) {\r\n // Add extra properties\r\n var baseProperties = {\r\n \"rp\": \"unknown\",\r\n \"attach\": \"Manual\",\r\n \"cikey\": statsBeatStats.cKey,\r\n \"os\": STATSBEAT_TYPE,\r\n \"language\": STATSBEAT_LANGUAGE,\r\n \"version\": statsBeatStats.sdkVer || \"unknown\",\r\n \"endpoint\": \"breeze\",\r\n \"host\": _networkCounter.host\r\n };\r\n // Manually merge properties instead of using spread syntax\r\n var combinedProps = { \"host\": _networkCounter.host };\r\n // Add properties if present\r\n if (properties) {\r\n for (var key in properties) {\r\n if (properties.hasOwnProperty(key)) {\r\n combinedProps[key] = properties[key];\r\n }\r\n }\r\n }\r\n // Add base properties\r\n for (var key in baseProperties) {\r\n if (baseProperties.hasOwnProperty(key)) {\r\n combinedProps[key] = baseProperties[key];\r\n }\r\n }\r\n var statsbeatEvent = {\r\n name: name,\r\n baseData: {\r\n name: name,\r\n average: val,\r\n properties: combinedProps\r\n },\r\n baseType: \"MetricData\"\r\n };\r\n mgr.track(statsBeat, statsbeatEvent);\r\n }\r\n }\r\n function _trackSendRequestDuration() {\r\n var totalRequest = _networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */];\r\n if (_networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */] > 0) {\r\n var averageRequestExecutionTime = _networkCounter[_DYN_REQUEST_DURATION /* @min:%2erequestDuration */] / totalRequest;\r\n _sendStatsbeats(\"Request_Duration\", averageRequestExecutionTime);\r\n }\r\n }\r\n function _trackSendRequestsCount() {\r\n var currentCounter = _networkCounter;\r\n _sendStatsbeats(\"Request_Success_Count\", currentCounter.success);\r\n for (var code in currentCounter[_DYN_FAILURE /* @min:%2efailure */]) {\r\n var count = currentCounter[_DYN_FAILURE /* @min:%2efailure */][code];\r\n _sendStatsbeats(\"failure\", count, { statusCode: code });\r\n }\r\n for (var code in currentCounter.retry) {\r\n var count = currentCounter.retry[code];\r\n _sendStatsbeats(\"retry\", count, { statusCode: code });\r\n }\r\n for (var code in currentCounter[_DYN_EXCEPTION /* @min:%2eexception */]) {\r\n var count = currentCounter[_DYN_EXCEPTION /* @min:%2eexception */][code];\r\n _sendStatsbeats(\"exception\", count, { exceptionType: code });\r\n }\r\n for (var code in currentCounter[_DYN_THROTTLE /* @min:%2ethrottle */]) {\r\n var count = currentCounter[_DYN_THROTTLE /* @min:%2ethrottle */][code];\r\n _sendStatsbeats(\"Throttle_Count\", count, { statusCode: code });\r\n }\r\n }\r\n function _setEnabled(isEnabled) {\r\n _isEnabled = isEnabled;\r\n if (!_isEnabled) {\r\n if (_timeoutHandle) {\r\n _timeoutHandle[_DYN_CANCEL /* @min:%2ecancel */]();\r\n _timeoutHandle = null;\r\n }\r\n }\r\n }\r\n // THE statsbeat instance being created and returned\r\n var statsBeat = {\r\n enabled: !!_isEnabled,\r\n endpoint: STR_EMPTY,\r\n type: 0 /* eStatsType.SDK */,\r\n count: function (status, payloadData, endpoint) {\r\n if (_isEnabled && _checkEndpoint(endpoint)) {\r\n if (payloadData && payloadData[\"statsBeatData\"] && payloadData[\"statsBeatData\"][\"startTime\"]) {\r\n _networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */] = (_networkCounter[_DYN_TOTAL_REQUEST /* @min:%2etotalRequest */] || 0) + 1;\r\n _networkCounter[_DYN_REQUEST_DURATION /* @min:%2erequestDuration */] += utcNow() - payloadData[\"statsBeatData\"][\"startTime\"];\r\n }\r\n var retryArray = [401, 403, 408, 429, 500, 502, 503, 504];\r\n var throttleArray = [402, 439];\r\n if (status >= 200 && status < 300) {\r\n _networkCounter.success++;\r\n }\r\n else if (retryArray[_DYN_INDEX_OF /* @min:%2eindexOf */](status) !== -1) {\r\n _networkCounter.retry[status] = (_networkCounter.retry[status] || 0) + 1;\r\n }\r\n else if (throttleArray[_DYN_INDEX_OF /* @min:%2eindexOf */](status) !== -1) {\r\n _networkCounter[_DYN_THROTTLE /* @min:%2ethrottle */][status] = (_networkCounter[_DYN_THROTTLE /* @min:%2ethrottle */][status] || 0) + 1;\r\n }\r\n else if (status !== 307 && status !== 308) {\r\n _networkCounter[_DYN_FAILURE /* @min:%2efailure */][status] = (_networkCounter[_DYN_FAILURE /* @min:%2efailure */][status] || 0) + 1;\r\n }\r\n _setupTimer();\r\n }\r\n },\r\n countException: function (endpoint, exceptionType) {\r\n if (_isEnabled && _checkEndpoint(endpoint)) {\r\n _networkCounter[_DYN_EXCEPTION /* @min:%2eexception */][exceptionType] = (_networkCounter[_DYN_EXCEPTION /* @min:%2eexception */][exceptionType] || 0) + 1;\r\n _setupTimer();\r\n }\r\n }\r\n };\r\n // Make the properties readonly / reactive to changes\r\n return objDefineProps(statsBeat, {\r\n enabled: { g: function () { return _isEnabled; }, s: _setEnabled },\r\n type: { g: function () { return statsBeatStats[_DYN_TYPE /* @min:%2etype */]; } },\r\n endpoint: { g: function () { return _networkCounter.host; } }\r\n });\r\n}\r\nfunction _getEndpointCfg(statsBeatConfig, type) {\r\n var endpointCfg = null;\r\n if (statsBeatConfig && statsBeatConfig.endCfg) {\r\n arrForEach(statsBeatConfig.endCfg, function (value) {\r\n if (value[_DYN_TYPE /* @min:%2etype */] === type) {\r\n endpointCfg = value;\r\n return -1; // Stop the loop if we found a match\r\n }\r\n });\r\n }\r\n return endpointCfg;\r\n}\r\n/**\r\n * This function retrieves the stats instrumentation key (iKey) for the given endpoint from\r\n * the statsBeatConfig. It iterates through the keys in the statsBeatConfig and checks if\r\n * the endpoint matches any of the URLs associated with that key. If a match is found, it\r\n * returns the corresponding iKey.\r\n * @param statsBeatConfig - The configuration object for StatsBeat.\r\n * @param endpoint - The endpoint to check against the URLs in the configuration.\r\n * @returns The iKey associated with the matching endpoint, or null if no match is found.\r\n */\r\nfunction _getIKey(endpointCfg, endpoint) {\r\n var statsKey = null;\r\n if (endpointCfg.keyMap) {\r\n arrForEach(endpointCfg.keyMap, function (keyMap) {\r\n if (keyMap.match) {\r\n arrForEach(keyMap.match, function (url) {\r\n if (_isMatchEndpoint(url, endpoint)) {\r\n statsKey = keyMap.key || null;\r\n // Stop the loop if we found a match\r\n return -1;\r\n }\r\n });\r\n }\r\n if (statsKey) {\r\n // Stop the loop if we found a match\r\n return -1;\r\n }\r\n });\r\n }\r\n return statsKey;\r\n}\r\nexport function createStatsMgr() {\r\n var _isMgrEnabled = false; // Flag to check if statsbeat is enabled or not\r\n var _core; // The core instance that is used to send telemetry\r\n var _shortInterval = STATS_COLLECTION_SHORT_INTERVAL;\r\n var _statsBeatConfig;\r\n // Lazily initialize the manager and start listening for configuration changes\r\n // This is also required to handle \"unloading\" and then re-initializing again\r\n function _init(core, statsConfig, featureName) {\r\n if (_core) {\r\n // If the core is already set, then just return with an empty unload hook\r\n _throwInternal(safeGetLogger(core), 2 /* eLoggingSeverity.WARNING */, 113 /* _eInternalMessageId.StatsBeatManagerException */, \"StatsBeat manager is already initialized\");\r\n return null;\r\n }\r\n _core = core;\r\n if (core && core[_DYN_IS_INITIALIZED /* @min:%2eisInitialized */]()) {\r\n // Start listening for configuration changes from the core config, within a config change handler\r\n // This will support the scenario where the config is changed after the statsbeat has been created\r\n return onConfigChange(core.config, function (details) {\r\n // Check the feature state again to see if it has changed\r\n _isMgrEnabled = false;\r\n if (statsConfig && isFeatureEnabled(statsConfig.feature, details.cfg, false) === true) {\r\n // Call the getCfg function to get the latest configuration for the statsbeat instance\r\n // This should also evaluate the throttling level and other settings for the statsbeat instance\r\n // to determine if it should be enabled or not.\r\n _statsBeatConfig = statsConfig.getCfg(core, details.cfg);\r\n if (_statsBeatConfig) {\r\n _isMgrEnabled = true;\r\n _shortInterval = STATS_COLLECTION_SHORT_INTERVAL; // Reset to the default in-case the config is removed / changed\r\n if (isNumber(_statsBeatConfig.shrtInt) && _statsBeatConfig.shrtInt > STATS_MIN_INTERVAL_SECONDS) {\r\n _shortInterval = _statsBeatConfig.shrtInt * 1000; // Convert to milliseconds\r\n }\r\n }\r\n }\r\n });\r\n }\r\n }\r\n function _track(statsBeat, statsBeatEvent) {\r\n if (_isMgrEnabled && _statsBeatConfig) {\r\n var endpoint = statsBeat.endpoint;\r\n var sendEvt = !!statsBeat[_DYN_TYPE /* @min:%2etype */];\r\n // Fetching the stats key for the endpoint here to support the scenario where the endpoint is changed\r\n // after the statsbeat instance is created. This will ensure that the correct stats key is used for the endpoint.\r\n // It also avoids the tracking of the statsbeat event if the endpoint is not in the config.\r\n var endpointCfg = _getEndpointCfg(_statsBeatConfig, statsBeat[_DYN_TYPE /* @min:%2etype */]);\r\n if (endpointCfg) {\r\n // Check for key remapping\r\n var statsKey = _getIKey(endpointCfg, endpoint);\r\n if (statsKey) {\r\n // Using this iKey for the statsbeat event\r\n statsBeatEvent.iKey = statsKey;\r\n // We have specific config for this endpoint, so we can send the event\r\n sendEvt = true;\r\n }\r\n if (sendEvt) {\r\n _core.track(statsBeatEvent);\r\n }\r\n }\r\n }\r\n }\r\n function _createInstance(state) {\r\n var instance = null;\r\n if (_isMgrEnabled) {\r\n var callbacks = {\r\n start: function (cb) {\r\n return scheduleTimeout(cb, _shortInterval);\r\n },\r\n track: _track\r\n };\r\n instance = _createStatsBeat(callbacks, state);\r\n }\r\n return instance;\r\n }\r\n var theMgr = {\r\n enabled: false,\r\n newInst: _createInstance,\r\n init: _init\r\n };\r\n return objDefineProps(theMgr, {\r\n \"enabled\": { g: function () { return _isMgrEnabled; } }\r\n });\r\n}\r\n//# sourceMappingURL=StatsBeat.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Core, 3.4.0-nightlybeta3.
|
|
2
|
+
* Application Insights JavaScript SDK - Core, 3.4.0-nightlybeta3.2505-13
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
"use strict";
|
|
8
7
|
import { arrForEach, isFunction } from "@nevware21/ts-utils";
|
|
9
8
|
import { _DYN_GET_NEXT, _DYN_GET_PLUGIN, _DYN_INITIALIZE, _DYN_IS_INITIALIZED, _DYN_LENGTH, _DYN_NAME, _DYN_PUSH, _DYN_SET_NEXT_PLUGIN, _DYN_TEARDOWN, _DYN_TRACE_FLAGS, _DYN__DO_TEARDOWN } from "../__DynamicConstants";
|
|
10
9
|
import { createElmNodeData } from "./DataCacheHelper";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TelemetryHelpers.js.map","sources":["TelemetryHelpers.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\
|
|
1
|
+
{"version":3,"file":"TelemetryHelpers.js.map","sources":["TelemetryHelpers.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { arrForEach, isFunction } from \"@nevware21/ts-utils\";\r\nimport { _DYN_GET_NEXT, _DYN_GET_PLUGIN, _DYN_INITIALIZE, _DYN_IS_INITIALIZED, _DYN_LENGTH, _DYN_NAME, _DYN_PUSH, _DYN_SET_NEXT_PLUGIN, _DYN_TEARDOWN, _DYN_TRACE_FLAGS, _DYN__DO_TEARDOWN } from \"../__DynamicConstants\";\r\nimport { createElmNodeData } from \"./DataCacheHelper\";\r\nimport { STR_CORE, STR_PRIORITY, STR_PROCESS_TELEMETRY } from \"./InternalConstants\";\r\nimport { isValidSpanId, isValidTraceId } from \"./W3cTraceParent\";\r\nvar pluginStateData = createElmNodeData(\"plugin\");\r\nexport function _getPluginState(plugin) {\r\n return pluginStateData.get(plugin, \"state\", {}, true);\r\n}\r\n/**\r\n * Initialize the queue of plugins\r\n * @param plugins - The array of plugins to initialize and setting of the next plugin\r\n * @param config - The current config for the instance\r\n * @param core - THe current core instance\r\n * @param extensions - The extensions\r\n */\r\nexport function initializePlugins(processContext, extensions) {\r\n // Set the next plugin and identified the uninitialized plugins\r\n var initPlugins = [];\r\n var lastPlugin = null;\r\n var proxy = processContext[_DYN_GET_NEXT /* @min:%2egetNext */]();\r\n var pluginState;\r\n while (proxy) {\r\n var thePlugin = proxy[_DYN_GET_PLUGIN /* @min:%2egetPlugin */]();\r\n if (thePlugin) {\r\n if (lastPlugin && lastPlugin[_DYN_SET_NEXT_PLUGIN /* @min:%2esetNextPlugin */] && thePlugin[STR_PROCESS_TELEMETRY /* @min:%2eprocessTelemetry */]) {\r\n // Set this plugin as the next for the previous one\r\n lastPlugin[_DYN_SET_NEXT_PLUGIN /* @min:%2esetNextPlugin */](thePlugin);\r\n }\r\n pluginState = _getPluginState(thePlugin);\r\n var isInitialized = !!pluginState[_DYN_IS_INITIALIZED /* @min:%2eisInitialized */];\r\n if (thePlugin[_DYN_IS_INITIALIZED /* @min:%2eisInitialized */]) {\r\n isInitialized = thePlugin[_DYN_IS_INITIALIZED /* @min:%2eisInitialized */]();\r\n }\r\n if (!isInitialized) {\r\n initPlugins[_DYN_PUSH /* @min:%2epush */](thePlugin);\r\n }\r\n lastPlugin = thePlugin;\r\n proxy = proxy[_DYN_GET_NEXT /* @min:%2egetNext */]();\r\n }\r\n }\r\n // Now initialize the plugins\r\n arrForEach(initPlugins, function (thePlugin) {\r\n var core = processContext[STR_CORE /* @min:%2ecore */]();\r\n thePlugin[_DYN_INITIALIZE /* @min:%2einitialize */](processContext.getCfg(), core, extensions, processContext[_DYN_GET_NEXT /* @min:%2egetNext */]());\r\n pluginState = _getPluginState(thePlugin);\r\n // Only add the core to the state if the plugin didn't set it (doesn't extend from BaseTelemetryPlugin)\r\n if (!thePlugin[STR_CORE] && !pluginState[STR_CORE]) {\r\n pluginState[STR_CORE] = core;\r\n }\r\n pluginState[_DYN_IS_INITIALIZED /* @min:%2eisInitialized */] = true;\r\n delete pluginState[_DYN_TEARDOWN /* @min:%2eteardown */];\r\n });\r\n}\r\nexport function sortPlugins(plugins) {\r\n // Sort by priority\r\n return plugins.sort(function (extA, extB) {\r\n var result = 0;\r\n if (extB) {\r\n var bHasProcess = extB[STR_PROCESS_TELEMETRY];\r\n if (extA[STR_PROCESS_TELEMETRY]) {\r\n result = bHasProcess ? extA[STR_PRIORITY] - extB[STR_PRIORITY] : 1;\r\n }\r\n else if (bHasProcess) {\r\n result = -1;\r\n }\r\n }\r\n else {\r\n result = extA ? 1 : -1;\r\n }\r\n return result;\r\n });\r\n // sort complete\r\n}\r\n/**\r\n * Teardown / Unload helper to perform teardown/unloading operations for the provided components synchronously or asynchronously, this will call any\r\n * _doTeardown() or _doUnload() functions on the provided components to allow them to finish removal.\r\n * @param components - The components you want to unload\r\n * @param unloadCtx - This is the context that should be used during unloading.\r\n * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.\r\n * @param asyncCallback - An optional callback that the plugin must call if it returns true to inform the caller that it has completed any async unload/teardown operations.\r\n * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.\r\n */\r\nexport function unloadComponents(components, unloadCtx, unloadState, asyncCallback) {\r\n var idx = 0;\r\n function _doUnload() {\r\n while (idx < components[_DYN_LENGTH /* @min:%2elength */]) {\r\n var component = components[idx++];\r\n if (component) {\r\n var func = component._doUnload || component[_DYN__DO_TEARDOWN /* @min:%2e_doTeardown */];\r\n if (isFunction(func)) {\r\n if (func.call(component, unloadCtx, unloadState, _doUnload) === true) {\r\n return true;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n return _doUnload();\r\n}\r\n/**\r\n * Creates a IDistributedTraceContext which optionally also \"sets\" the value on a parent\r\n * @param parentCtx - An optional parent distributed trace instance\r\n * @returns A new IDistributedTraceContext instance that uses an internal temporary object\r\n */\r\nexport function createDistributedTraceContext(parentCtx) {\r\n var trace = {};\r\n return {\r\n getName: function () {\r\n return trace[_DYN_NAME /* @min:%2ename */];\r\n },\r\n setName: function (newValue) {\r\n parentCtx && parentCtx.setName(newValue);\r\n trace[_DYN_NAME /* @min:%2ename */] = newValue;\r\n },\r\n getTraceId: function () {\r\n return trace.traceId;\r\n },\r\n setTraceId: function (newValue) {\r\n parentCtx && parentCtx.setTraceId(newValue);\r\n if (isValidTraceId(newValue)) {\r\n trace.traceId = newValue;\r\n }\r\n },\r\n getSpanId: function () {\r\n return trace.spanId;\r\n },\r\n setSpanId: function (newValue) {\r\n parentCtx && parentCtx.setSpanId(newValue);\r\n if (isValidSpanId(newValue)) {\r\n trace.spanId = newValue;\r\n }\r\n },\r\n getTraceFlags: function () {\r\n return trace[_DYN_TRACE_FLAGS /* @min:%2etraceFlags */];\r\n },\r\n setTraceFlags: function (newTraceFlags) {\r\n parentCtx && parentCtx.setTraceFlags(newTraceFlags);\r\n trace[_DYN_TRACE_FLAGS /* @min:%2etraceFlags */] = newTraceFlags;\r\n }\r\n };\r\n}\r\n//# sourceMappingURL=TelemetryHelpers.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|