@webex/internal-plugin-metrics 3.3.1 → 3.4.0-next.2

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.
Files changed (49) hide show
  1. package/dist/behavioral-metrics.js +63 -0
  2. package/dist/behavioral-metrics.js.map +1 -0
  3. package/dist/business-metrics.js +62 -0
  4. package/dist/business-metrics.js.map +1 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics.js +3 -0
  6. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -1
  7. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +14 -11
  8. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -1
  9. package/dist/call-diagnostic/config.js +19 -13
  10. package/dist/call-diagnostic/config.js.map +1 -1
  11. package/dist/generic-metrics.js +184 -0
  12. package/dist/generic-metrics.js.map +1 -0
  13. package/dist/index.js +21 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/metrics.js +1 -1
  16. package/dist/metrics.types.js.map +1 -1
  17. package/dist/new-metrics.js +116 -23
  18. package/dist/new-metrics.js.map +1 -1
  19. package/dist/operational-metrics.js +56 -0
  20. package/dist/operational-metrics.js.map +1 -0
  21. package/dist/types/behavioral-metrics.d.ts +25 -0
  22. package/dist/types/business-metrics.d.ts +19 -0
  23. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +2 -2
  24. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +3 -2
  25. package/dist/types/call-diagnostic/config.d.ts +2 -0
  26. package/dist/types/generic-metrics.d.ts +63 -0
  27. package/dist/types/index.d.ts +4 -1
  28. package/dist/types/metrics.types.d.ts +47 -15
  29. package/dist/types/new-metrics.d.ts +39 -11
  30. package/dist/types/operational-metrics.d.ts +19 -0
  31. package/package.json +11 -11
  32. package/src/behavioral-metrics.ts +40 -0
  33. package/src/business-metrics.ts +30 -0
  34. package/src/call-diagnostic/call-diagnostic-metrics.ts +3 -0
  35. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +16 -17
  36. package/src/call-diagnostic/config.ts +9 -2
  37. package/src/generic-metrics.ts +146 -0
  38. package/src/index.ts +6 -0
  39. package/src/metrics.types.ts +82 -18
  40. package/src/new-metrics.ts +95 -18
  41. package/src/operational-metrics.ts +24 -0
  42. package/test/unit/spec/behavioral/behavioral-metrics.ts +205 -0
  43. package/test/unit/spec/business/business-metrics.ts +120 -0
  44. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +48 -52
  45. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +1 -1
  46. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +9 -0
  47. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +41 -22
  48. package/test/unit/spec/operational/operational-metrics.ts +115 -0
  49. package/test/unit/spec/prelogin-metrics-batcher.ts +1 -1
@@ -0,0 +1,115 @@
1
+ import sinon from 'sinon';
2
+ import {assert} from '@webex/test-helper-chai';
3
+ import {BrowserDetection} from '@webex/common';
4
+ import {OperationalMetrics, config, getOSNameInternal} from '@webex/internal-plugin-metrics';
5
+ import uuid from 'uuid';
6
+
7
+ //@ts-ignore
8
+ global.window = {location: {hostname: 'whatever'}, navigator: {language: 'language'}};
9
+ process.env.NODE_ENV = 'test';
10
+
11
+ const {getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();
12
+
13
+ describe('internal-plugin-metrics', () => {
14
+ describe('OperationalMetrics', () => {
15
+ let webex;
16
+ let now;
17
+ let operationalMetrics: OperationalMetrics;
18
+
19
+ const tags = {key: 'val'};
20
+
21
+ beforeEach(() => {
22
+ now = new Date();
23
+
24
+ webex = {
25
+ canAuthorize: true,
26
+ version: 'webex-version',
27
+ internal: {
28
+ services: {
29
+ get: () => 'locus-url',
30
+ },
31
+ metrics: {
32
+ submitClientMetrics: sinon.stub(),
33
+ config: {...config.metrics},
34
+ },
35
+ newMetrics: {},
36
+ device: {
37
+ userId: 'userId',
38
+ url: 'https://wdm-intb.ciscospark.com/wdm/api/v1/devices/deviceId',
39
+ orgId: 'orgId',
40
+ },
41
+ },
42
+ meetings: {
43
+ config: {
44
+ metrics: {
45
+ clientType: 'TEAMS_CLIENT',
46
+ subClientType: 'WEB_APP',
47
+ clientName: 'Cantina',
48
+ },
49
+ },
50
+ geoHintInfo: {
51
+ clientAddress: '1.3.4.5',
52
+ countryCode: 'UK',
53
+ },
54
+ },
55
+ credentials: {
56
+ isUnverifiedGuest: false,
57
+ },
58
+ prepareFetchOptions: sinon.stub().callsFake((opts: any) => ({...opts, foo: 'bar'})),
59
+ request: sinon.stub().resolves({body: {}}),
60
+ logger: {
61
+ log: sinon.stub(),
62
+ error: sinon.stub(),
63
+ },
64
+ };
65
+
66
+ sinon.createSandbox();
67
+ sinon.useFakeTimers(now.getTime());
68
+ operationalMetrics = new OperationalMetrics({}, {parent: webex});
69
+ sinon.stub(uuid, 'v4').returns('my-fake-id');
70
+ });
71
+
72
+ afterEach(() => {
73
+ sinon.restore();
74
+ });
75
+
76
+ describe('#sendEvent', () => {
77
+ it('should send correctly shaped operational event (check name building and internal tagged event building)', () => {
78
+ // For some reasons `jest` isn't available when testing form build server - so can't use `jest.fn()` here...
79
+ const requestCalls = [];
80
+ const request = function(arg) { requestCalls.push(arg) }
81
+
82
+ operationalMetrics.clientMetricsBatcher.request = request;
83
+
84
+ assert.equal(requestCalls.length, 0)
85
+ operationalMetrics.submitOperationalEvent({ name: "foobar", payload: {bar:"gee"} })
86
+ assert.equal(requestCalls.length, 1)
87
+ assert.deepEqual(requestCalls[0], {
88
+ context: {
89
+ app: {version: 'webex-version'},
90
+ device: {id: 'deviceId'},
91
+ locale: 'language',
92
+ os: {
93
+ name: getOSNameInternal(),
94
+ version: getOSVersion(),
95
+ },
96
+ },
97
+ metricName: 'foobar',
98
+ tags: {
99
+ browser: getBrowserName(),
100
+ browserHeight: window.innerHeight,
101
+ browserVersion: getBrowserVersion(),
102
+ browserWidth: window.innerWidth,
103
+ domain: window.location.hostname,
104
+ inIframe: false,
105
+ locale: window.navigator.language,
106
+ os: getOSNameInternal(),
107
+ bar: "gee"
108
+ },
109
+ timestamp: requestCalls[0].timestamp, // This is to bypass time check, which is correctly tested in behavioral-metrics tests.
110
+ type: ['operational'],
111
+ });
112
+ })
113
+ })
114
+ });
115
+ });
@@ -9,7 +9,6 @@ import MockWebex from '@webex/test-helper-mock-webex';
9
9
  import sinon from 'sinon';
10
10
  import FakeTimers from '@sinonjs/fake-timers';
11
11
  import {NewMetrics} from '@webex/internal-plugin-metrics';
12
- import {uniqueId} from 'lodash';
13
12
 
14
13
  const flushPromises = () => new Promise(setImmediate);
15
14
 
@@ -66,6 +65,7 @@ describe('internal-plugin-metrics', () => {
66
65
 
67
66
  // matching because the request includes a symbol key: value pair and sinon cannot handle to compare it..
68
67
  assert.match(webexRequestArgs, {
68
+ //@ts-ignore
69
69
  body: {
70
70
  metrics: [
71
71
  {