@webex/internal-plugin-metrics 2.59.8 → 2.60.0-next.1
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/dist/batcher.js +3 -3
- package/dist/batcher.js.map +1 -1
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +68 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +454 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js +795 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js +323 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
- package/dist/call-diagnostic/config.js +587 -0
- package/dist/call-diagnostic/config.js.map +1 -0
- package/dist/client-metrics-batcher.js +3 -3
- package/dist/client-metrics-batcher.js.map +1 -1
- package/dist/config.js +6 -9
- package/dist/config.js.map +1 -1
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/metrics.js +24 -22
- package/dist/metrics.js.map +1 -1
- package/dist/metrics.types.js +7 -0
- package/dist/metrics.types.js.map +1 -0
- package/dist/new-metrics.js +336 -0
- package/dist/new-metrics.js.map +1 -0
- package/dist/utils.js +26 -0
- package/dist/utils.js.map +1 -0
- package/package.json +22 -17
- package/src/batcher.js +1 -0
- package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +83 -0
- package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +414 -0
- package/src/call-diagnostic/call-diagnostic-metrics.ts +863 -0
- package/src/call-diagnostic/call-diagnostic-metrics.util.ts +362 -0
- package/src/call-diagnostic/config.ts +660 -0
- package/src/client-metrics-batcher.js +1 -0
- package/src/config.js +1 -0
- package/src/index.ts +43 -0
- package/src/metrics.js +17 -16
- package/src/metrics.types.ts +159 -0
- package/src/new-metrics.ts +317 -0
- package/src/utils.ts +17 -0
- package/test/unit/spec/batcher.js +2 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +467 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +477 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +1943 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +565 -0
- package/test/unit/spec/client-metrics-batcher.js +2 -0
- package/test/unit/spec/metrics.js +65 -94
- package/test/unit/spec/new-metrics.ts +269 -0
- package/test/unit/spec/utils.ts +22 -0
- package/tsconfig.json +6 -0
- package/dist/call-diagnostic-events-batcher.js +0 -60
- package/dist/call-diagnostic-events-batcher.js.map +0 -1
- package/src/call-diagnostic-events-batcher.js +0 -62
- package/src/index.js +0 -15
- package/test/unit/spec/call-diagnostic-events-batcher.js +0 -195
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Reflect$construct = require("@babel/runtime-corejs2/core-js/reflect/construct");
|
|
4
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.default = void 0;
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
|
|
11
|
+
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
12
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
|
|
13
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
|
|
14
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
|
|
15
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/assertThisInitialized"));
|
|
16
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));
|
|
17
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));
|
|
18
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));
|
|
19
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
20
|
+
var _webexCore = require("@webex/webex-core");
|
|
21
|
+
var _callDiagnosticMetrics = _interopRequireDefault(require("./call-diagnostic/call-diagnostic-metrics"));
|
|
22
|
+
var _callDiagnosticMetricsLatencies = _interopRequireDefault(require("./call-diagnostic/call-diagnostic-metrics-latencies"));
|
|
23
|
+
var _callDiagnosticMetrics2 = require("./call-diagnostic/call-diagnostic-metrics.util");
|
|
24
|
+
var _utils = require("./utils");
|
|
25
|
+
var _class;
|
|
26
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
27
|
+
/* eslint-disable class-methods-use-this */
|
|
28
|
+
/* eslint-disable valid-jsdoc */
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
31
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
32
|
+
/**
|
|
33
|
+
* Metrics plugin to centralize all types of metrics.
|
|
34
|
+
* @class
|
|
35
|
+
*/
|
|
36
|
+
var Metrics = /*#__PURE__*/function (_WebexPlugin) {
|
|
37
|
+
(0, _inherits2.default)(Metrics, _WebexPlugin);
|
|
38
|
+
var _super = _createSuper(Metrics);
|
|
39
|
+
/**
|
|
40
|
+
* Constructor
|
|
41
|
+
* @param args
|
|
42
|
+
* @constructor
|
|
43
|
+
* @private
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
function Metrics() {
|
|
47
|
+
var _this;
|
|
48
|
+
(0, _classCallCheck2.default)(this, Metrics);
|
|
49
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
50
|
+
args[_key] = arguments[_key];
|
|
51
|
+
}
|
|
52
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
53
|
+
// Call Diagnostic latencies
|
|
54
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "callDiagnosticLatencies", void 0);
|
|
55
|
+
// Helper classes to handle the different types of metrics
|
|
56
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "callDiagnosticMetrics", void 0);
|
|
57
|
+
_this.onReady();
|
|
58
|
+
return _this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* On Ready
|
|
63
|
+
*/
|
|
64
|
+
(0, _createClass2.default)(Metrics, [{
|
|
65
|
+
key: "onReady",
|
|
66
|
+
value: function onReady() {
|
|
67
|
+
var _this2 = this;
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
this.webex.once('ready', function () {
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
_this2.callDiagnosticMetrics = new _callDiagnosticMetrics.default({}, {
|
|
72
|
+
parent: _this2.webex
|
|
73
|
+
});
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
_this2.callDiagnosticLatencies = new _callDiagnosticMetricsLatencies.default({}, {
|
|
76
|
+
parent: _this2.webex
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Used for internal purposes only
|
|
83
|
+
* @param args
|
|
84
|
+
*/
|
|
85
|
+
}, {
|
|
86
|
+
key: "submitInternalEvent",
|
|
87
|
+
value: function submitInternalEvent(_ref) {
|
|
88
|
+
var name = _ref.name,
|
|
89
|
+
payload = _ref.payload,
|
|
90
|
+
options = _ref.options;
|
|
91
|
+
if (name === 'internal.reset.join.latencies') {
|
|
92
|
+
this.callDiagnosticLatencies.clearTimestamps();
|
|
93
|
+
} else {
|
|
94
|
+
this.callDiagnosticLatencies.saveTimestamp({
|
|
95
|
+
key: name
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Behavioral event
|
|
102
|
+
* @param args
|
|
103
|
+
*/
|
|
104
|
+
}, {
|
|
105
|
+
key: "submitBehavioralEvent",
|
|
106
|
+
value: function submitBehavioralEvent(_ref2) {
|
|
107
|
+
var name = _ref2.name,
|
|
108
|
+
payload = _ref2.payload,
|
|
109
|
+
options = _ref2.options;
|
|
110
|
+
this.callDiagnosticLatencies.saveTimestamp({
|
|
111
|
+
key: name
|
|
112
|
+
});
|
|
113
|
+
throw new Error('Not implemented.');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Operational event
|
|
118
|
+
* @param args
|
|
119
|
+
*/
|
|
120
|
+
}, {
|
|
121
|
+
key: "submitOperationalEvent",
|
|
122
|
+
value: function submitOperationalEvent(_ref3) {
|
|
123
|
+
var name = _ref3.name,
|
|
124
|
+
payload = _ref3.payload,
|
|
125
|
+
options = _ref3.options;
|
|
126
|
+
throw new Error('Not implemented.');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Call Analyzer: Media Quality Event
|
|
131
|
+
* @param args
|
|
132
|
+
*/
|
|
133
|
+
}, {
|
|
134
|
+
key: "submitMQE",
|
|
135
|
+
value: function submitMQE(_ref4) {
|
|
136
|
+
var name = _ref4.name,
|
|
137
|
+
payload = _ref4.payload,
|
|
138
|
+
options = _ref4.options;
|
|
139
|
+
this.callDiagnosticLatencies.saveTimestamp({
|
|
140
|
+
key: name
|
|
141
|
+
});
|
|
142
|
+
this.callDiagnosticMetrics.submitMQE({
|
|
143
|
+
name: name,
|
|
144
|
+
payload: payload,
|
|
145
|
+
options: options
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Call Analyzer: Feature Usage Event
|
|
151
|
+
* @param args
|
|
152
|
+
*/
|
|
153
|
+
}, {
|
|
154
|
+
key: "submitFeatureEvent",
|
|
155
|
+
value: function submitFeatureEvent(_ref5) {
|
|
156
|
+
var name = _ref5.name,
|
|
157
|
+
payload = _ref5.payload,
|
|
158
|
+
options = _ref5.options;
|
|
159
|
+
throw new Error('Not implemented.');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Call Analyzer: Client Event
|
|
164
|
+
* @public
|
|
165
|
+
* @param args
|
|
166
|
+
*/
|
|
167
|
+
}, {
|
|
168
|
+
key: "submitClientEvent",
|
|
169
|
+
value: function submitClientEvent(_ref6) {
|
|
170
|
+
var name = _ref6.name,
|
|
171
|
+
payload = _ref6.payload,
|
|
172
|
+
options = _ref6.options;
|
|
173
|
+
if (!this.callDiagnosticLatencies || !this.callDiagnosticMetrics) {
|
|
174
|
+
// @ts-ignore
|
|
175
|
+
this.webex.logger.log("NewMetrics: @submitClientEvent. Attempted to submit before webex.ready. Event name: ".concat(name));
|
|
176
|
+
return _promise.default.resolve();
|
|
177
|
+
}
|
|
178
|
+
this.callDiagnosticLatencies.saveTimestamp({
|
|
179
|
+
key: name,
|
|
180
|
+
options: {
|
|
181
|
+
meetingId: options === null || options === void 0 ? void 0 : options.meetingId
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
return this.callDiagnosticMetrics.submitClientEvent({
|
|
185
|
+
name: name,
|
|
186
|
+
payload: payload,
|
|
187
|
+
options: options
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Submit a pre-login metric to clientmetrics
|
|
193
|
+
* @public
|
|
194
|
+
* @param payload
|
|
195
|
+
* @param preLoginId - pre-login ID of user
|
|
196
|
+
* @returns
|
|
197
|
+
*/
|
|
198
|
+
}, {
|
|
199
|
+
key: "postPreLoginMetric",
|
|
200
|
+
value: function postPreLoginMetric(payload, preLoginId) {
|
|
201
|
+
var _this3 = this;
|
|
202
|
+
// @ts-ignore
|
|
203
|
+
return this.webex.request({
|
|
204
|
+
method: 'POST',
|
|
205
|
+
api: 'metrics',
|
|
206
|
+
resource: 'clientmetrics-prelogin',
|
|
207
|
+
headers: {
|
|
208
|
+
authorization: false,
|
|
209
|
+
'x-prelogin-userid': preLoginId
|
|
210
|
+
},
|
|
211
|
+
body: {
|
|
212
|
+
metrics: [payload]
|
|
213
|
+
}
|
|
214
|
+
}).then(function (res) {
|
|
215
|
+
// @ts-ignore
|
|
216
|
+
_this3.webex.logger.log("NewMetrics: @postPreLoginMetric. Request successful:", res);
|
|
217
|
+
return res;
|
|
218
|
+
}).catch(function (err) {
|
|
219
|
+
// @ts-ignore
|
|
220
|
+
_this3.logger.error("NewMetrics: @postPreLoginMetric. Request failed:", "err: ".concat((0, _utils.generateCommonErrorMetadata)(err)));
|
|
221
|
+
return _promise.default.reject(err);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Issue request to alias a user's pre-login ID with their CI UUID
|
|
227
|
+
* @param {string} preLoginId
|
|
228
|
+
* @returns {Object} HttpResponse object
|
|
229
|
+
*/
|
|
230
|
+
}, {
|
|
231
|
+
key: "clientMetricsAliasUser",
|
|
232
|
+
value: function clientMetricsAliasUser(preLoginId) {
|
|
233
|
+
var _this4 = this;
|
|
234
|
+
// @ts-ignore
|
|
235
|
+
return this.webex.request({
|
|
236
|
+
method: 'POST',
|
|
237
|
+
api: 'metrics',
|
|
238
|
+
resource: 'clientmetrics',
|
|
239
|
+
headers: {
|
|
240
|
+
'x-prelogin-userid': preLoginId
|
|
241
|
+
},
|
|
242
|
+
body: {},
|
|
243
|
+
qs: {
|
|
244
|
+
alias: true
|
|
245
|
+
}
|
|
246
|
+
}).then(function (res) {
|
|
247
|
+
// @ts-ignore
|
|
248
|
+
_this4.webex.logger.log("NewMetrics: @clientMetricsAliasUser. Request successful:", res);
|
|
249
|
+
return res;
|
|
250
|
+
}).catch(function (err) {
|
|
251
|
+
// @ts-ignore
|
|
252
|
+
_this4.logger.error("NewMetrics: @clientMetricsAliasUser. Request failed:", "err: ".concat((0, _utils.generateCommonErrorMetadata)(err)));
|
|
253
|
+
return _promise.default.reject(err);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Returns a promise that will resolve to fetch options for submitting a metric.
|
|
259
|
+
*
|
|
260
|
+
* This is to support quickly submitting metrics when the browser/tab is closing.
|
|
261
|
+
* Calling submitClientEvent will not work because there some async steps that will
|
|
262
|
+
* not complete before the browser is closed. Instead, we pre-gather all the
|
|
263
|
+
* information/options needed for the request(s), and then simply and quickly
|
|
264
|
+
* fire the fetch(es) when beforeUnload is triggered.
|
|
265
|
+
*
|
|
266
|
+
* We must use fetch instead of request because fetch has a keepalive option that
|
|
267
|
+
* allows the request it to outlive the page.
|
|
268
|
+
*
|
|
269
|
+
* Note: the timings values will be wrong, but setMetricTimingsAndFetch() will
|
|
270
|
+
* properly adjust them before submitting.
|
|
271
|
+
*
|
|
272
|
+
* @public
|
|
273
|
+
* @param {Object} arg
|
|
274
|
+
* @param {String} arg.name - event name
|
|
275
|
+
* @param {Object} arg.payload - event payload
|
|
276
|
+
* @param {Object} arg.options - other options
|
|
277
|
+
* @returns {Promise} promise that resolves to options to be used with fetch
|
|
278
|
+
*/
|
|
279
|
+
}, {
|
|
280
|
+
key: "buildClientEventFetchRequestOptions",
|
|
281
|
+
value: (function () {
|
|
282
|
+
var _buildClientEventFetchRequestOptions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref7) {
|
|
283
|
+
var name, payload, options;
|
|
284
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
285
|
+
while (1) switch (_context.prev = _context.next) {
|
|
286
|
+
case 0:
|
|
287
|
+
name = _ref7.name, payload = _ref7.payload, options = _ref7.options;
|
|
288
|
+
return _context.abrupt("return", this.callDiagnosticMetrics.buildClientEventFetchRequestOptions({
|
|
289
|
+
name: name,
|
|
290
|
+
payload: payload,
|
|
291
|
+
options: options
|
|
292
|
+
}));
|
|
293
|
+
case 2:
|
|
294
|
+
case "end":
|
|
295
|
+
return _context.stop();
|
|
296
|
+
}
|
|
297
|
+
}, _callee, this);
|
|
298
|
+
}));
|
|
299
|
+
function buildClientEventFetchRequestOptions(_x) {
|
|
300
|
+
return _buildClientEventFetchRequestOptions.apply(this, arguments);
|
|
301
|
+
}
|
|
302
|
+
return buildClientEventFetchRequestOptions;
|
|
303
|
+
}()
|
|
304
|
+
/**
|
|
305
|
+
* Submits a metric from pre-built request options via the fetch API. Updates
|
|
306
|
+
* the "$timings" and "originTime" values to Date.now() since the existing times
|
|
307
|
+
* were set when the options were built (not submitted).
|
|
308
|
+
* @param {any} options - the pre-built request options for submitting a metric
|
|
309
|
+
* @returns {Promise} promise that resolves to the response object
|
|
310
|
+
*/
|
|
311
|
+
)
|
|
312
|
+
}, {
|
|
313
|
+
key: "setMetricTimingsAndFetch",
|
|
314
|
+
value: function setMetricTimingsAndFetch(options) {
|
|
315
|
+
// @ts-ignore
|
|
316
|
+
return this.webex.setTimingsAndFetch((0, _callDiagnosticMetrics2.setMetricTimings)(options));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Returns true if the specified serviceErrorCode maps to an expected error.
|
|
321
|
+
* @param {number} serviceErrorCode the service error code
|
|
322
|
+
* @returns {boolean}
|
|
323
|
+
*/
|
|
324
|
+
}, {
|
|
325
|
+
key: "isServiceErrorExpected",
|
|
326
|
+
value: function isServiceErrorExpected(serviceErrorCode) {
|
|
327
|
+
return this.callDiagnosticMetrics.isServiceErrorExpected(serviceErrorCode);
|
|
328
|
+
}
|
|
329
|
+
}]);
|
|
330
|
+
return Metrics;
|
|
331
|
+
}(_webexCore.WebexPlugin);
|
|
332
|
+
_class = Metrics;
|
|
333
|
+
// eslint-disable-next-line no-use-before-define
|
|
334
|
+
(0, _defineProperty2.default)(Metrics, "instance", void 0);
|
|
335
|
+
var _default = exports.default = Metrics;
|
|
336
|
+
//# sourceMappingURL=new-metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_webexCore","require","_callDiagnosticMetrics","_interopRequireDefault","_callDiagnosticMetricsLatencies","_callDiagnosticMetrics2","_utils","_class","_createSuper","Derived","hasNativeReflectConstruct","_isNativeReflectConstruct","_createSuperInternal","Super","_getPrototypeOf2","default","result","NewTarget","constructor","_Reflect$construct","arguments","apply","_possibleConstructorReturn2","Reflect","sham","Proxy","Boolean","prototype","valueOf","call","e","Metrics","_WebexPlugin","_inherits2","_super","_this","_classCallCheck2","_len","length","args","Array","_key","concat","_defineProperty2","_assertThisInitialized2","onReady","_createClass2","key","value","_this2","webex","once","callDiagnosticMetrics","CallDiagnosticMetrics","parent","callDiagnosticLatencies","CallDiagnosticLatencies","submitInternalEvent","_ref","name","payload","options","clearTimestamps","saveTimestamp","submitBehavioralEvent","_ref2","Error","submitOperationalEvent","_ref3","submitMQE","_ref4","submitFeatureEvent","_ref5","submitClientEvent","_ref6","logger","log","_promise","resolve","meetingId","postPreLoginMetric","preLoginId","_this3","request","method","api","resource","headers","authorization","body","metrics","then","res","catch","err","error","generateCommonErrorMetadata","reject","clientMetricsAliasUser","_this4","qs","alias","_buildClientEventFetchRequestOptions","_asyncToGenerator2","_regenerator","mark","_callee","_ref7","wrap","_callee$","_context","prev","next","abrupt","buildClientEventFetchRequestOptions","stop","_x","setMetricTimingsAndFetch","setTimingsAndFetch","setMetricTimings","isServiceErrorExpected","serviceErrorCode","WebexPlugin","_default","exports"],"sources":["new-metrics.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable class-methods-use-this */\n/* eslint-disable valid-jsdoc */\n\n// @ts-ignore\nimport {WebexPlugin} from '@webex/webex-core';\n\nimport CallDiagnosticMetrics from './call-diagnostic/call-diagnostic-metrics';\nimport {\n RecursivePartial,\n ClientEvent,\n FeatureEvent,\n BehavioralEvent,\n OperationalEvent,\n MediaQualityEvent,\n InternalEvent,\n SubmitClientEventOptions,\n} from './metrics.types';\nimport CallDiagnosticLatencies from './call-diagnostic/call-diagnostic-metrics-latencies';\nimport {setMetricTimings} from './call-diagnostic/call-diagnostic-metrics.util';\nimport {generateCommonErrorMetadata} from './utils';\n\n/**\n * Metrics plugin to centralize all types of metrics.\n * @class\n */\nclass Metrics extends WebexPlugin {\n // eslint-disable-next-line no-use-before-define\n static instance: Metrics;\n\n // Call Diagnostic latencies\n callDiagnosticLatencies: CallDiagnosticLatencies;\n // Helper classes to handle the different types of metrics\n callDiagnosticMetrics: CallDiagnosticMetrics;\n\n /**\n * Constructor\n * @param args\n * @constructor\n * @private\n * @returns\n */\n constructor(...args) {\n super(...args);\n\n this.onReady();\n }\n\n /**\n * On Ready\n */\n private onReady() {\n // @ts-ignore\n this.webex.once('ready', () => {\n // @ts-ignore\n this.callDiagnosticMetrics = new CallDiagnosticMetrics({}, {parent: this.webex});\n // @ts-ignore\n this.callDiagnosticLatencies = new CallDiagnosticLatencies({}, {parent: this.webex});\n });\n }\n\n /**\n * Used for internal purposes only\n * @param args\n */\n submitInternalEvent({\n name,\n payload,\n options,\n }: {\n name: InternalEvent['name'];\n payload?: RecursivePartial<InternalEvent['payload']>;\n options?: any;\n }) {\n if (name === 'internal.reset.join.latencies') {\n this.callDiagnosticLatencies.clearTimestamps();\n } else {\n this.callDiagnosticLatencies.saveTimestamp({key: name});\n }\n }\n\n /**\n * Behavioral event\n * @param args\n */\n submitBehavioralEvent({\n name,\n payload,\n options,\n }: {\n name: BehavioralEvent['name'];\n payload?: RecursivePartial<BehavioralEvent['payload']>;\n options?: any;\n }) {\n this.callDiagnosticLatencies.saveTimestamp({key: name});\n throw new Error('Not implemented.');\n }\n\n /**\n * Operational event\n * @param args\n */\n submitOperationalEvent({\n name,\n payload,\n options,\n }: {\n name: OperationalEvent['name'];\n payload?: RecursivePartial<OperationalEvent['payload']>;\n options?: any;\n }) {\n throw new Error('Not implemented.');\n }\n\n /**\n * Call Analyzer: Media Quality Event\n * @param args\n */\n submitMQE({\n name,\n payload,\n options,\n }: {\n name: MediaQualityEvent['name'];\n payload: RecursivePartial<MediaQualityEvent['payload']> & {\n intervals: MediaQualityEvent['payload']['intervals'];\n };\n options: any;\n }) {\n this.callDiagnosticLatencies.saveTimestamp({key: name});\n this.callDiagnosticMetrics.submitMQE({name, payload, options});\n }\n\n /**\n * Call Analyzer: Feature Usage Event\n * @param args\n */\n submitFeatureEvent({\n name,\n payload,\n options,\n }: {\n name: FeatureEvent['name'];\n payload?: RecursivePartial<FeatureEvent['payload']>;\n options: any;\n }) {\n throw new Error('Not implemented.');\n }\n\n /**\n * Call Analyzer: Client Event\n * @public\n * @param args\n */\n public submitClientEvent({\n name,\n payload,\n options,\n }: {\n name: ClientEvent['name'];\n payload?: RecursivePartial<ClientEvent['payload']>;\n options?: SubmitClientEventOptions;\n }): Promise<any> {\n if (!this.callDiagnosticLatencies || !this.callDiagnosticMetrics) {\n // @ts-ignore\n this.webex.logger.log(\n `NewMetrics: @submitClientEvent. Attempted to submit before webex.ready. Event name: ${name}`\n );\n\n return Promise.resolve();\n }\n this.callDiagnosticLatencies.saveTimestamp({\n key: name,\n options: {meetingId: options?.meetingId},\n });\n\n return this.callDiagnosticMetrics.submitClientEvent({name, payload, options});\n }\n\n /**\n * Submit a pre-login metric to clientmetrics\n * @public\n * @param payload\n * @param preLoginId - pre-login ID of user\n * @returns\n */\n public postPreLoginMetric(payload: any, preLoginId: string): Promise<any> {\n // @ts-ignore\n return this.webex\n .request({\n method: 'POST',\n api: 'metrics',\n resource: 'clientmetrics-prelogin',\n headers: {\n authorization: false,\n 'x-prelogin-userid': preLoginId,\n },\n body: {\n metrics: [payload],\n },\n })\n .then((res) => {\n // @ts-ignore\n this.webex.logger.log(`NewMetrics: @postPreLoginMetric. Request successful:`, res);\n\n return res;\n })\n .catch((err) => {\n // @ts-ignore\n this.logger.error(\n `NewMetrics: @postPreLoginMetric. Request failed:`,\n `err: ${generateCommonErrorMetadata(err)}`\n );\n\n return Promise.reject(err);\n });\n }\n\n /**\n * Issue request to alias a user's pre-login ID with their CI UUID\n * @param {string} preLoginId\n * @returns {Object} HttpResponse object\n */\n public clientMetricsAliasUser(preLoginId: string) {\n // @ts-ignore\n return this.webex\n .request({\n method: 'POST',\n api: 'metrics',\n resource: 'clientmetrics',\n headers: {\n 'x-prelogin-userid': preLoginId,\n },\n body: {},\n qs: {\n alias: true,\n },\n })\n .then((res) => {\n // @ts-ignore\n this.webex.logger.log(`NewMetrics: @clientMetricsAliasUser. Request successful:`, res);\n\n return res;\n })\n .catch((err) => {\n // @ts-ignore\n this.logger.error(\n `NewMetrics: @clientMetricsAliasUser. Request failed:`,\n `err: ${generateCommonErrorMetadata(err)}`\n );\n\n return Promise.reject(err);\n });\n }\n\n /**\n * Returns a promise that will resolve to fetch options for submitting a metric.\n *\n * This is to support quickly submitting metrics when the browser/tab is closing.\n * Calling submitClientEvent will not work because there some async steps that will\n * not complete before the browser is closed. Instead, we pre-gather all the\n * information/options needed for the request(s), and then simply and quickly\n * fire the fetch(es) when beforeUnload is triggered.\n *\n * We must use fetch instead of request because fetch has a keepalive option that\n * allows the request it to outlive the page.\n *\n * Note: the timings values will be wrong, but setMetricTimingsAndFetch() will\n * properly adjust them before submitting.\n *\n * @public\n * @param {Object} arg\n * @param {String} arg.name - event name\n * @param {Object} arg.payload - event payload\n * @param {Object} arg.options - other options\n * @returns {Promise} promise that resolves to options to be used with fetch\n */\n public async buildClientEventFetchRequestOptions({\n name,\n payload,\n options,\n }: {\n name: ClientEvent['name'];\n payload?: RecursivePartial<ClientEvent['payload']>;\n options?: SubmitClientEventOptions;\n }): Promise<any> {\n return this.callDiagnosticMetrics.buildClientEventFetchRequestOptions({\n name,\n payload,\n options,\n });\n }\n\n /**\n * Submits a metric from pre-built request options via the fetch API. Updates\n * the \"$timings\" and \"originTime\" values to Date.now() since the existing times\n * were set when the options were built (not submitted).\n\n * @param {any} options - the pre-built request options for submitting a metric\n * @returns {Promise} promise that resolves to the response object\n */\n public setMetricTimingsAndFetch(options: any): Promise<any> {\n // @ts-ignore\n return this.webex.setTimingsAndFetch(setMetricTimings(options));\n }\n\n /**\n * Returns true if the specified serviceErrorCode maps to an expected error.\n * @param {number} serviceErrorCode the service error code\n * @returns {boolean}\n */\n public isServiceErrorExpected(serviceErrorCode: number): boolean {\n return this.callDiagnosticMetrics.isServiceErrorExpected(serviceErrorCode);\n }\n}\n\nexport default Metrics;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAKA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,sBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAWA,IAAAG,+BAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,uBAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAAoD,IAAAM,MAAA;AApBpD;AACA;AACA;AAEA;AAAA,SAAAC,aAAAC,OAAA,QAAAC,yBAAA,GAAAC,yBAAA,oBAAAC,qBAAA,QAAAC,KAAA,OAAAC,gBAAA,CAAAC,OAAA,EAAAN,OAAA,GAAAO,MAAA,MAAAN,yBAAA,QAAAO,SAAA,OAAAH,gBAAA,CAAAC,OAAA,QAAAG,WAAA,EAAAF,MAAA,GAAAG,kBAAA,CAAAN,KAAA,EAAAO,SAAA,EAAAH,SAAA,YAAAD,MAAA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AgD,KAAA,CAAJhD,IAAI,EACJC,OAAO,GAAA+C,KAAA,CAAP/C,OAAO,EACPC,OAAO,GAAA8C,KAAA,CAAP9C,OAAO;cAAA,OAAAiD,QAAA,CAAAG,MAAA,WAMA,IAAI,CAAC7D,qBAAqB,CAAC8D,mCAAmC,CAAC;gBACpEvD,IAAI,EAAJA,IAAI;gBACJC,OAAO,EAAPA,OAAO;gBACPC,OAAO,EAAPA;cACF,CAAC,CAAC;YAAA;YAAA;cAAA,OAAAiD,QAAA,CAAAK,IAAA;UAAA;QAAA,GAAAT,OAAA;MAAA,CACH;MAAA,SAAAQ,oCAAAE,EAAA;QAAA,OAAAd,oCAAA,CAAAjF,KAAA,OAAAD,SAAA;MAAA;MAAA,OAAA8F,mCAAA;IAAA;IAED;AACF;AACA;AACA;AACA;AACA;AACA;IANE;EAAA;IAAAnE,GAAA;IAAAC,KAAA,EAQA,SAAAqE,yBAAgCxD,OAAY,EAAgB;MAC1D;MACA,OAAO,IAAI,CAACX,KAAK,CAACoE,kBAAkB,CAAC,IAAAC,wCAAgB,EAAC1D,OAAO,CAAC,CAAC;IACjE;;IAEA;AACF;AACA;AACA;AACA;EAJE;IAAAd,GAAA;IAAAC,KAAA,EAKA,SAAAwE,uBAA8BC,gBAAwB,EAAW;MAC/D,OAAO,IAAI,CAACrE,qBAAqB,CAACoE,sBAAsB,CAACC,gBAAgB,CAAC;IAC5E;EAAC;EAAA,OAAA1F,OAAA;AAAA,EA/RmB2F,sBAAW;AAAAnH,MAAA,GAA3BwB,OAAO;AACX;AAAA,IAAAY,gBAAA,CAAA5B,OAAA,EADIgB,OAAO;AAAA,IAAA4F,QAAA,GAAAC,OAAA,CAAA7G,OAAA,GAkSEgB,OAAO"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
5
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.generateCommonErrorMetadata = void 0;
|
|
9
|
+
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
|
|
10
|
+
/* eslint-disable import/prefer-default-export */
|
|
11
|
+
/**
|
|
12
|
+
* Generates common metadata for errors
|
|
13
|
+
* @param {any} error
|
|
14
|
+
* @returns {object}
|
|
15
|
+
*/
|
|
16
|
+
var generateCommonErrorMetadata = exports.generateCommonErrorMetadata = function generateCommonErrorMetadata(error) {
|
|
17
|
+
if (error instanceof Error) {
|
|
18
|
+
return (0, _stringify.default)({
|
|
19
|
+
message: error === null || error === void 0 ? void 0 : error.message,
|
|
20
|
+
name: error === null || error === void 0 ? void 0 : error.name,
|
|
21
|
+
stack: error === null || error === void 0 ? void 0 : error.stack
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return error;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["generateCommonErrorMetadata","exports","error","Error","_stringify","default","message","name","stack"],"sources":["utils.ts"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\n/**\n * Generates common metadata for errors\n * @param {any} error\n * @returns {object}\n */\nexport const generateCommonErrorMetadata = (error) => {\n if (error instanceof Error) {\n return JSON.stringify({\n message: error?.message,\n name: error?.name,\n stack: error?.stack,\n });\n }\n\n return error;\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,2BAA2B,GAAAC,OAAA,CAAAD,2BAAA,GAAG,SAA9BA,2BAA2BA,CAAIE,KAAK,EAAK;EACpD,IAAIA,KAAK,YAAYC,KAAK,EAAE;IAC1B,OAAO,IAAAC,UAAA,CAAAC,OAAA,EAAe;MACpBC,OAAO,EAAEJ,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEI,OAAO;MACvBC,IAAI,EAAEL,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEK,IAAI;MACjBC,KAAK,EAAEN,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEM;IAChB,CAAC,CAAC;EACJ;EAEA,OAAON,KAAK;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/internal-plugin-metrics",
|
|
3
|
-
"version": "2.59.8",
|
|
4
3
|
"description": "",
|
|
5
4
|
"license": "MIT",
|
|
6
5
|
"main": "dist/index.js",
|
|
7
6
|
"devMain": "src/index.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/webex/webex-js-sdk.git",
|
|
11
11
|
"directory": "packages/@webex/internal-plugin-metrics"
|
|
12
12
|
},
|
|
13
13
|
"engines": {
|
|
14
|
-
"node": ">=
|
|
14
|
+
"node": ">=16"
|
|
15
15
|
},
|
|
16
16
|
"browserify": {
|
|
17
17
|
"transform": [
|
|
@@ -22,32 +22,37 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@babel/core": "^7.17.10",
|
|
24
24
|
"@sinonjs/fake-timers": "^6.0.1",
|
|
25
|
-
"@webex/babel-config-legacy": "
|
|
26
|
-
"@webex/eslint-config-legacy": "
|
|
27
|
-
"@webex/jest-config-legacy": "
|
|
28
|
-
"@webex/legacy-tools": "
|
|
29
|
-
"@webex/test-helper-chai": "2.
|
|
30
|
-
"@webex/test-helper-mocha": "2.
|
|
31
|
-
"@webex/test-helper-mock-webex": "2.
|
|
32
|
-
"@webex/test-helper-test-users": "2.
|
|
25
|
+
"@webex/babel-config-legacy": "^0.0.0",
|
|
26
|
+
"@webex/eslint-config-legacy": "^0.0.0",
|
|
27
|
+
"@webex/jest-config-legacy": "^0.0.0",
|
|
28
|
+
"@webex/legacy-tools": "^0.0.0",
|
|
29
|
+
"@webex/test-helper-chai": "^2.60.0-next.1",
|
|
30
|
+
"@webex/test-helper-mocha": "^2.60.0-next.1",
|
|
31
|
+
"@webex/test-helper-mock-webex": "^2.60.0-next.1",
|
|
32
|
+
"@webex/test-helper-test-users": "^2.60.0-next.1",
|
|
33
33
|
"eslint": "^8.24.0",
|
|
34
34
|
"prettier": "^2.7.1",
|
|
35
35
|
"sinon": "^9.2.4"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@webex/common": "2.
|
|
39
|
-
"@webex/common-timers": "2.
|
|
40
|
-
"@webex/
|
|
41
|
-
"@webex/
|
|
42
|
-
"@webex/
|
|
38
|
+
"@webex/common": "^2.60.0-next.1",
|
|
39
|
+
"@webex/common-timers": "^2.60.0-next.1",
|
|
40
|
+
"@webex/event-dictionary-ts": "^1.0.1313",
|
|
41
|
+
"@webex/internal-plugin-device": "^2.60.0-next.1",
|
|
42
|
+
"@webex/internal-plugin-metrics": "^2.60.0-next.1",
|
|
43
|
+
"@webex/test-helper-chai": "^2.60.0-next.1",
|
|
44
|
+
"@webex/test-helper-mock-webex": "^2.60.0-next.1",
|
|
45
|
+
"@webex/webex-core": "^2.60.0-next.1"
|
|
43
46
|
},
|
|
44
47
|
"scripts": {
|
|
45
48
|
"build": "yarn build:src",
|
|
46
49
|
"build:src": "webex-legacy-tools build -dest \"./dist\" -src \"./src\" -js -ts -maps",
|
|
50
|
+
"deploy:npm": "yarn npm publish",
|
|
47
51
|
"test": "yarn test:style && yarn test:unit && yarn test:integration && yarn test:browser",
|
|
48
52
|
"test:browser": "webex-legacy-tools test --integration --unit --runner karma",
|
|
49
53
|
"test:integration": "webex-legacy-tools test --integration --runner mocha",
|
|
50
54
|
"test:style": "eslint ./src/**/*.*",
|
|
51
55
|
"test:unit": "webex-legacy-tools test --unit --runner jest"
|
|
52
|
-
}
|
|
53
|
-
|
|
56
|
+
},
|
|
57
|
+
"version": "2.60.0-next.1"
|
|
58
|
+
}
|
package/src/batcher.js
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/* eslint-disable class-methods-use-this */
|
|
2
|
+
/* eslint-disable valid-jsdoc */
|
|
3
|
+
|
|
4
|
+
import {uniqueId} from 'lodash';
|
|
5
|
+
import Batcher from '../batcher';
|
|
6
|
+
import {prepareDiagnosticMetricItem} from './call-diagnostic-metrics.util';
|
|
7
|
+
import {CALL_DIAGNOSTIC_LOG_IDENTIFIER} from './config';
|
|
8
|
+
import {generateCommonErrorMetadata} from '../utils';
|
|
9
|
+
|
|
10
|
+
const CallDiagnosticEventsBatcher = Batcher.extend({
|
|
11
|
+
namespace: 'Metrics',
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Prepare item
|
|
15
|
+
* @param item
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
prepareItem(item) {
|
|
19
|
+
return Promise.resolve(prepareDiagnosticMetricItem(this.webex, item));
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Prepare request, add time sensitive date etc.
|
|
24
|
+
* @param queue
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
prepareRequest(queue) {
|
|
28
|
+
// Add sent timestamp
|
|
29
|
+
queue.forEach((item) => {
|
|
30
|
+
item.eventPayload.originTime = item.eventPayload.originTime || {};
|
|
31
|
+
item.eventPayload.originTime.sent = new Date().toISOString();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return Promise.resolve(queue);
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param payload
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
submitHttpRequest(payload) {
|
|
43
|
+
const batchId = uniqueId('call-diagnostic-metrics-batch-');
|
|
44
|
+
this.webex.logger.log(
|
|
45
|
+
CALL_DIAGNOSTIC_LOG_IDENTIFIER,
|
|
46
|
+
`CallDiagnosticEventsBatcher: @submitHttpRequest#${batchId}. Sending the request:`,
|
|
47
|
+
'payload:',
|
|
48
|
+
payload
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return this.webex
|
|
52
|
+
.request({
|
|
53
|
+
method: 'POST',
|
|
54
|
+
service: 'metrics',
|
|
55
|
+
resource: 'clientmetrics',
|
|
56
|
+
body: {
|
|
57
|
+
metrics: payload,
|
|
58
|
+
},
|
|
59
|
+
waitForServiceTimeout: this.webex.config.metrics.waitForServiceTimeout,
|
|
60
|
+
})
|
|
61
|
+
.then((res) => {
|
|
62
|
+
this.webex.logger.log(
|
|
63
|
+
CALL_DIAGNOSTIC_LOG_IDENTIFIER,
|
|
64
|
+
`CallDiagnosticEventsBatcher: @submitHttpRequest#${batchId}. Request successful:`,
|
|
65
|
+
`response:`,
|
|
66
|
+
res
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return res;
|
|
70
|
+
})
|
|
71
|
+
.catch((err) => {
|
|
72
|
+
this.webex.logger.error(
|
|
73
|
+
CALL_DIAGNOSTIC_LOG_IDENTIFIER,
|
|
74
|
+
`CallDiagnosticEventsBatcher: @submitHttpRequest#${batchId}. Request failed:`,
|
|
75
|
+
`error: ${generateCommonErrorMetadata(err)}`
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
return Promise.reject(err);
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
export default CallDiagnosticEventsBatcher;
|