@webex/internal-plugin-metrics 2.59.3-next.1 → 2.59.4
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/.eslintrc.js +6 -6
- package/README.md +42 -42
- package/babel.config.js +3 -3
- package/dist/batcher.js +2 -2
- package/dist/batcher.js.map +1 -1
- package/dist/call-diagnostic-events-batcher.js +5 -5
- package/dist/call-diagnostic-events-batcher.js.map +1 -1
- package/dist/client-metrics-batcher.js +2 -2
- package/dist/client-metrics-batcher.js.map +1 -1
- package/dist/config.js +2 -2
- package/dist/config.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/metrics.js +11 -11
- package/dist/metrics.js.map +1 -1
- package/jest.config.js +3 -3
- package/package.json +16 -17
- package/process +1 -1
- package/src/batcher.js +99 -99
- package/src/call-diagnostic-events-batcher.js +62 -62
- package/src/client-metrics-batcher.js +31 -31
- package/src/config.js +42 -42
- package/src/index.js +15 -15
- package/src/metrics.js +165 -165
- package/test/unit/spec/batcher.js +181 -181
- package/test/unit/spec/call-diagnostic-events-batcher.js +195 -195
- package/test/unit/spec/client-metrics-batcher.js +181 -181
- package/test/unit/spec/metrics.js +364 -364
package/src/metrics.js
CHANGED
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
/* eslint-disable default-param-last */
|
|
2
|
-
|
|
3
|
-
/*!
|
|
4
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {WebexPlugin} from '@webex/webex-core';
|
|
8
|
-
import {BrowserDetection} from '@webex/common';
|
|
9
|
-
import {OS_NAME, OSMap, CLIENT_NAME} from './config';
|
|
10
|
-
|
|
11
|
-
import Batcher from './batcher';
|
|
12
|
-
import ClientMetricsBatcher from './client-metrics-batcher';
|
|
13
|
-
import CallDiagnosticEventsBatcher from './call-diagnostic-events-batcher';
|
|
14
|
-
|
|
15
|
-
const {getOSName, getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();
|
|
16
|
-
|
|
17
|
-
export function getOSNameInternal() {
|
|
18
|
-
return OSMap[getOSName()] ?? OS_NAME.OTHERS;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function getSparkUserAgent(webex) {
|
|
22
|
-
const {appName, appVersion, appPlatform} = webex?.config ?? {};
|
|
23
|
-
|
|
24
|
-
let sparkUserAgent = CLIENT_NAME;
|
|
25
|
-
|
|
26
|
-
if (appName) {
|
|
27
|
-
sparkUserAgent += ` ${appName}/${appVersion ?? '0.0'}`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (appPlatform) {
|
|
31
|
-
sparkUserAgent += ` ${appPlatform}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return sparkUserAgent;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const Metrics = WebexPlugin.extend({
|
|
38
|
-
children: {
|
|
39
|
-
batcher: Batcher,
|
|
40
|
-
clientMetricsBatcher: ClientMetricsBatcher,
|
|
41
|
-
callDiagnosticEventsBatcher: CallDiagnosticEventsBatcher,
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
namespace: 'Metrics',
|
|
45
|
-
|
|
46
|
-
submit(key, value) {
|
|
47
|
-
return this.batcher.request({key, ...value});
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* This corresponds to #sendSemiStructured() in the deprecated metrics handler
|
|
52
|
-
* @param {string} eventName
|
|
53
|
-
* @param {Object} props
|
|
54
|
-
* @param {string} preLoginId
|
|
55
|
-
* @returns {Object} HttpResponse object
|
|
56
|
-
*/
|
|
57
|
-
submitClientMetrics(eventName, props = {}, preLoginId) {
|
|
58
|
-
if (!eventName) {
|
|
59
|
-
throw Error('Missing behavioral metric name. Please provide one');
|
|
60
|
-
}
|
|
61
|
-
const payload = {metricName: eventName};
|
|
62
|
-
|
|
63
|
-
payload.tags = {
|
|
64
|
-
...props.tags,
|
|
65
|
-
browser: getBrowserName(),
|
|
66
|
-
os: getOSNameInternal(),
|
|
67
|
-
|
|
68
|
-
// Node does not like this so we need to check if it exists or not
|
|
69
|
-
// eslint-disable-next-line no-undef
|
|
70
|
-
domain:
|
|
71
|
-
typeof window !== 'undefined' ? window.location.hostname || 'non-browser' : 'non-browser', // Check what else we could measure
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
payload.fields = {
|
|
75
|
-
...props.fields,
|
|
76
|
-
browser_version: getBrowserVersion(),
|
|
77
|
-
os_version: getOSVersion(),
|
|
78
|
-
sdk_version: this.webex.version,
|
|
79
|
-
platform: 'Web',
|
|
80
|
-
spark_user_agent: getSparkUserAgent(this.webex),
|
|
81
|
-
client_id: this.webex.credentials.config.client_id,
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
payload.type = props.type || this.webex.config.metrics.type;
|
|
85
|
-
|
|
86
|
-
payload.context = {
|
|
87
|
-
...props.context,
|
|
88
|
-
app: {
|
|
89
|
-
version: this.webex.version,
|
|
90
|
-
},
|
|
91
|
-
locale: 'en-US',
|
|
92
|
-
os: {
|
|
93
|
-
name: getOSNameInternal(),
|
|
94
|
-
version: getOSVersion(),
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
if (props.eventPayload) {
|
|
99
|
-
payload.eventPayload = props.eventPayload;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Mocking the time in tests when running in node
|
|
103
|
-
// is impossible so unable to use Date.now()
|
|
104
|
-
payload.timestamp = new Date().valueOf();
|
|
105
|
-
|
|
106
|
-
if (preLoginId) {
|
|
107
|
-
const _payload = {
|
|
108
|
-
metrics: [payload],
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// Do not batch these because pre-login events occur during onboarding, so we will be partially blind
|
|
112
|
-
// to users' progress through the reg flow if we wait to persist pre-login metrics for people who drop off because
|
|
113
|
-
// their metrics will not post from a queue flush in time
|
|
114
|
-
return this.postPreLoginMetric(_payload, preLoginId);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return this.clientMetricsBatcher.request(payload);
|
|
118
|
-
},
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Issue request to alias a user's pre-login ID with their CI UUID
|
|
122
|
-
* @param {string} preLoginId
|
|
123
|
-
* @returns {Object} HttpResponse object
|
|
124
|
-
*/
|
|
125
|
-
aliasUser(preLoginId) {
|
|
126
|
-
return this.request({
|
|
127
|
-
method: 'POST',
|
|
128
|
-
api: 'metrics',
|
|
129
|
-
resource: 'clientmetrics',
|
|
130
|
-
headers: {
|
|
131
|
-
'x-prelogin-userid': preLoginId,
|
|
132
|
-
},
|
|
133
|
-
body: {},
|
|
134
|
-
qs: {
|
|
135
|
-
alias: true,
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
},
|
|
139
|
-
|
|
140
|
-
postPreLoginMetric(payload, preLoginId) {
|
|
141
|
-
return this.webex.credentials.getClientToken().then((token) =>
|
|
142
|
-
this.request({
|
|
143
|
-
method: 'POST',
|
|
144
|
-
api: 'metrics',
|
|
145
|
-
resource: 'clientmetrics-prelogin',
|
|
146
|
-
headers: {
|
|
147
|
-
authorization: token.toString(),
|
|
148
|
-
'x-prelogin-userid': preLoginId,
|
|
149
|
-
},
|
|
150
|
-
body: payload,
|
|
151
|
-
})
|
|
152
|
-
);
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
submitCallDiagnosticEvents(payload) {
|
|
156
|
-
const event = {
|
|
157
|
-
type: 'diagnostic-event',
|
|
158
|
-
eventPayload: payload,
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
return this.callDiagnosticEventsBatcher.request(event);
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
export default Metrics;
|
|
1
|
+
/* eslint-disable default-param-last */
|
|
2
|
+
|
|
3
|
+
/*!
|
|
4
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {WebexPlugin} from '@webex/webex-core';
|
|
8
|
+
import {BrowserDetection} from '@webex/common';
|
|
9
|
+
import {OS_NAME, OSMap, CLIENT_NAME} from './config';
|
|
10
|
+
|
|
11
|
+
import Batcher from './batcher';
|
|
12
|
+
import ClientMetricsBatcher from './client-metrics-batcher';
|
|
13
|
+
import CallDiagnosticEventsBatcher from './call-diagnostic-events-batcher';
|
|
14
|
+
|
|
15
|
+
const {getOSName, getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();
|
|
16
|
+
|
|
17
|
+
export function getOSNameInternal() {
|
|
18
|
+
return OSMap[getOSName()] ?? OS_NAME.OTHERS;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getSparkUserAgent(webex) {
|
|
22
|
+
const {appName, appVersion, appPlatform} = webex?.config ?? {};
|
|
23
|
+
|
|
24
|
+
let sparkUserAgent = CLIENT_NAME;
|
|
25
|
+
|
|
26
|
+
if (appName) {
|
|
27
|
+
sparkUserAgent += ` ${appName}/${appVersion ?? '0.0'}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (appPlatform) {
|
|
31
|
+
sparkUserAgent += ` ${appPlatform}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return sparkUserAgent;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const Metrics = WebexPlugin.extend({
|
|
38
|
+
children: {
|
|
39
|
+
batcher: Batcher,
|
|
40
|
+
clientMetricsBatcher: ClientMetricsBatcher,
|
|
41
|
+
callDiagnosticEventsBatcher: CallDiagnosticEventsBatcher,
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
namespace: 'Metrics',
|
|
45
|
+
|
|
46
|
+
submit(key, value) {
|
|
47
|
+
return this.batcher.request({key, ...value});
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* This corresponds to #sendSemiStructured() in the deprecated metrics handler
|
|
52
|
+
* @param {string} eventName
|
|
53
|
+
* @param {Object} props
|
|
54
|
+
* @param {string} preLoginId
|
|
55
|
+
* @returns {Object} HttpResponse object
|
|
56
|
+
*/
|
|
57
|
+
submitClientMetrics(eventName, props = {}, preLoginId) {
|
|
58
|
+
if (!eventName) {
|
|
59
|
+
throw Error('Missing behavioral metric name. Please provide one');
|
|
60
|
+
}
|
|
61
|
+
const payload = {metricName: eventName};
|
|
62
|
+
|
|
63
|
+
payload.tags = {
|
|
64
|
+
...props.tags,
|
|
65
|
+
browser: getBrowserName(),
|
|
66
|
+
os: getOSNameInternal(),
|
|
67
|
+
|
|
68
|
+
// Node does not like this so we need to check if it exists or not
|
|
69
|
+
// eslint-disable-next-line no-undef
|
|
70
|
+
domain:
|
|
71
|
+
typeof window !== 'undefined' ? window.location.hostname || 'non-browser' : 'non-browser', // Check what else we could measure
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
payload.fields = {
|
|
75
|
+
...props.fields,
|
|
76
|
+
browser_version: getBrowserVersion(),
|
|
77
|
+
os_version: getOSVersion(),
|
|
78
|
+
sdk_version: this.webex.version,
|
|
79
|
+
platform: 'Web',
|
|
80
|
+
spark_user_agent: getSparkUserAgent(this.webex),
|
|
81
|
+
client_id: this.webex.credentials.config.client_id,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
payload.type = props.type || this.webex.config.metrics.type;
|
|
85
|
+
|
|
86
|
+
payload.context = {
|
|
87
|
+
...props.context,
|
|
88
|
+
app: {
|
|
89
|
+
version: this.webex.version,
|
|
90
|
+
},
|
|
91
|
+
locale: 'en-US',
|
|
92
|
+
os: {
|
|
93
|
+
name: getOSNameInternal(),
|
|
94
|
+
version: getOSVersion(),
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
if (props.eventPayload) {
|
|
99
|
+
payload.eventPayload = props.eventPayload;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Mocking the time in tests when running in node
|
|
103
|
+
// is impossible so unable to use Date.now()
|
|
104
|
+
payload.timestamp = new Date().valueOf();
|
|
105
|
+
|
|
106
|
+
if (preLoginId) {
|
|
107
|
+
const _payload = {
|
|
108
|
+
metrics: [payload],
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Do not batch these because pre-login events occur during onboarding, so we will be partially blind
|
|
112
|
+
// to users' progress through the reg flow if we wait to persist pre-login metrics for people who drop off because
|
|
113
|
+
// their metrics will not post from a queue flush in time
|
|
114
|
+
return this.postPreLoginMetric(_payload, preLoginId);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return this.clientMetricsBatcher.request(payload);
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Issue request to alias a user's pre-login ID with their CI UUID
|
|
122
|
+
* @param {string} preLoginId
|
|
123
|
+
* @returns {Object} HttpResponse object
|
|
124
|
+
*/
|
|
125
|
+
aliasUser(preLoginId) {
|
|
126
|
+
return this.request({
|
|
127
|
+
method: 'POST',
|
|
128
|
+
api: 'metrics',
|
|
129
|
+
resource: 'clientmetrics',
|
|
130
|
+
headers: {
|
|
131
|
+
'x-prelogin-userid': preLoginId,
|
|
132
|
+
},
|
|
133
|
+
body: {},
|
|
134
|
+
qs: {
|
|
135
|
+
alias: true,
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
postPreLoginMetric(payload, preLoginId) {
|
|
141
|
+
return this.webex.credentials.getClientToken().then((token) =>
|
|
142
|
+
this.request({
|
|
143
|
+
method: 'POST',
|
|
144
|
+
api: 'metrics',
|
|
145
|
+
resource: 'clientmetrics-prelogin',
|
|
146
|
+
headers: {
|
|
147
|
+
authorization: token.toString(),
|
|
148
|
+
'x-prelogin-userid': preLoginId,
|
|
149
|
+
},
|
|
150
|
+
body: payload,
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
submitCallDiagnosticEvents(payload) {
|
|
156
|
+
const event = {
|
|
157
|
+
type: 'diagnostic-event',
|
|
158
|
+
eventPayload: payload,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return this.callDiagnosticEventsBatcher.request(event);
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
export default Metrics;
|