@webex/internal-plugin-metrics 3.4.0 → 3.5.0-next.10

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 (69) 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 +169 -0
  4. package/dist/business-metrics.js.map +1 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +1 -1
  6. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -1
  7. package/dist/call-diagnostic/call-diagnostic-metrics.js +27 -11
  8. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -1
  9. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +14 -4
  10. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -1
  11. package/dist/call-diagnostic/config.js +13 -3
  12. package/dist/call-diagnostic/config.js.map +1 -1
  13. package/dist/{behavioral/behavioral-metrics.js → generic-metrics.js} +77 -92
  14. package/dist/generic-metrics.js.map +1 -0
  15. package/dist/index.js +22 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/metrics.js +1 -1
  18. package/dist/metrics.types.js.map +1 -1
  19. package/dist/new-metrics.js +124 -24
  20. package/dist/new-metrics.js.map +1 -1
  21. package/dist/operational-metrics.js +56 -0
  22. package/dist/operational-metrics.js.map +1 -0
  23. package/dist/rtcMetrics/constants.js +11 -0
  24. package/dist/rtcMetrics/constants.js.map +1 -0
  25. package/dist/rtcMetrics/index.js +202 -0
  26. package/dist/rtcMetrics/index.js.map +1 -0
  27. package/dist/types/behavioral-metrics.d.ts +25 -0
  28. package/dist/types/business-metrics.d.ts +47 -0
  29. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +27 -6
  30. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +2 -1
  31. package/dist/types/call-diagnostic/config.d.ts +3 -0
  32. package/dist/types/generic-metrics.d.ts +63 -0
  33. package/dist/types/index.d.ts +5 -2
  34. package/dist/types/metrics.types.d.ts +27 -14
  35. package/dist/types/new-metrics.d.ts +42 -9
  36. package/dist/types/operational-metrics.d.ts +19 -0
  37. package/dist/types/rtcMetrics/constants.d.ts +4 -0
  38. package/dist/types/rtcMetrics/index.d.ts +71 -0
  39. package/package.json +12 -12
  40. package/src/behavioral-metrics.ts +40 -0
  41. package/src/business-metrics.ts +118 -0
  42. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +1 -1
  43. package/src/call-diagnostic/call-diagnostic-metrics.ts +30 -9
  44. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +17 -4
  45. package/src/call-diagnostic/config.ts +12 -0
  46. package/src/generic-metrics.ts +146 -0
  47. package/src/index.ts +7 -1
  48. package/src/metrics.types.ts +32 -16
  49. package/src/new-metrics.ts +100 -13
  50. package/src/operational-metrics.ts +24 -0
  51. package/src/rtcMetrics/constants.ts +3 -0
  52. package/src/rtcMetrics/index.ts +186 -0
  53. package/test/unit/spec/behavioral/behavioral-metrics.ts +51 -10
  54. package/test/unit/spec/business/business-metrics.ts +182 -0
  55. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +2 -1
  56. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +4 -6
  57. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +418 -12
  58. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +22 -8
  59. package/test/unit/spec/new-metrics.ts +32 -3
  60. package/test/unit/spec/operational/operational-metrics.ts +115 -0
  61. package/test/unit/spec/prelogin-metrics-batcher.ts +3 -1
  62. package/test/unit/spec/rtcMetrics/index.ts +155 -0
  63. package/dist/behavioral/behavioral-metrics.js.map +0 -1
  64. package/dist/behavioral/config.js +0 -11
  65. package/dist/behavioral/config.js.map +0 -1
  66. package/dist/types/behavioral/behavioral-metrics.d.ts +0 -63
  67. package/dist/types/behavioral/config.d.ts +0 -1
  68. package/src/behavioral/behavioral-metrics.ts +0 -179
  69. package/src/behavioral/config.ts +0 -3
@@ -1,179 +0,0 @@
1
- import {merge} from 'lodash';
2
- import {BrowserDetection} from '@webex/common';
3
- import {StatelessWebexPlugin} from '@webex/webex-core';
4
- import {getOSNameInternal} from '../metrics';
5
- import {BEHAVIORAL_LOG_IDENTIFIER} from './config';
6
- import {
7
- MetricEventProduct,
8
- MetricEventAgent,
9
- MetricEventVerb,
10
- BehavioralEventContext,
11
- BehavioralEvent,
12
- BehavioralEventPayload,
13
- } from '../metrics.types';
14
- import ClientMetricsBatcher from '../client-metrics-batcher';
15
-
16
- const {getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();
17
-
18
- /**
19
- * @description Util class to handle Behavioral Metrics
20
- * @export
21
- * @class BehavioralMetrics
22
- */
23
- export default class BehavioralMetrics extends StatelessWebexPlugin {
24
- // @ts-ignore
25
- private clientMetricsBatcher: ClientMetricsBatcher;
26
- private logger: any; // to avoid adding @ts-ignore everywhere
27
- private device: any;
28
- private version: string;
29
-
30
- /**
31
- * Constructor
32
- * @param {any[]} args
33
- */
34
- constructor(...args) {
35
- super(...args);
36
- // @ts-ignore
37
- this.logger = this.webex.logger;
38
- // @ts-ignore
39
- this.device = this.webex.internal.device;
40
- // @ts-ignore
41
- this.version = this.webex.version;
42
- // @ts-ignore
43
- this.clientMetricsBatcher = new ClientMetricsBatcher({}, {parent: this.webex});
44
- }
45
-
46
- /**
47
- * Returns the deviceId from our registration with WDM.
48
- * @returns {string} deviceId or empty string
49
- */
50
- private getDeviceId(): string {
51
- const {url} = this.device;
52
- if (url && url.length !== 0) {
53
- const n = url.lastIndexOf('/');
54
- if (n !== -1) {
55
- return url.substring(n + 1);
56
- }
57
- }
58
-
59
- return '';
60
- }
61
-
62
- /**
63
- * Returns the context object to be submitted with all behavioral metrics.
64
- * @returns {BehavioralEventContext}
65
- */
66
- private getContext(): BehavioralEventContext {
67
- const context: BehavioralEventContext = {
68
- app: {
69
- version: this.version,
70
- },
71
- device: {
72
- id: this.getDeviceId(),
73
- },
74
- locale: window.navigator.language,
75
- os: {
76
- name: getOSNameInternal(),
77
- version: getOSVersion(),
78
- },
79
- };
80
-
81
- return context;
82
- }
83
-
84
- /**
85
- * Returns the default tags to be included with all behavioral metrics.
86
- * @returns {BehavioralEventPayload}
87
- */
88
- private getDefaultTags(): BehavioralEventPayload {
89
- const tags = {
90
- browser: getBrowserName(),
91
- browserHeight: window.innerHeight,
92
- browserVersion: getBrowserVersion(),
93
- browserWidth: window.innerWidth,
94
- domain: window.location.hostname,
95
- inIframe: window.self !== window.top,
96
- locale: window.navigator.language,
97
- os: getOSNameInternal(),
98
- };
99
-
100
- return tags;
101
- }
102
-
103
- /**
104
- * Creates the object to send to our metrics endpoint for a behavioral event
105
- * @param {MetricEventProduct} product
106
- * @param {MetricEventAgent} agent
107
- * @param {string} target
108
- * @param {MetricEventVerb} verb
109
- * @returns {BehavioralEventPayload}
110
- */
111
- private createEventObject({
112
- product,
113
- agent,
114
- target,
115
- verb,
116
- payload,
117
- }: {
118
- product: MetricEventProduct;
119
- agent: MetricEventAgent;
120
- target: string;
121
- verb: MetricEventVerb;
122
- payload?: BehavioralEventPayload;
123
- }): BehavioralEvent {
124
- const metricName = `${product}.${agent}.${target}.${verb}`;
125
- let allTags: BehavioralEventPayload = payload;
126
- allTags = merge(allTags, this.getDefaultTags());
127
-
128
- const event: BehavioralEvent = {
129
- context: this.getContext(),
130
- metricName,
131
- tags: allTags,
132
- timestamp: Date.now(),
133
- type: ['behavioral'],
134
- };
135
-
136
- return event;
137
- }
138
-
139
- /**
140
- * Returns true once we're ready to submit behavioral metrics, after startup.
141
- * @returns {boolean} true when deviceId is defined and non-empty
142
- */
143
- public isReadyToSubmitBehavioralEvents(): boolean {
144
- const deviceId = this.getDeviceId();
145
-
146
- return deviceId && deviceId.length !== 0;
147
- }
148
-
149
- /**
150
- * Submit a behavioral metric to our metrics endpoint.
151
- * @param {MetricEventProduct} product the product from which the metric is being submitted, e.g. 'webex' web client, 'wxcc_desktop'
152
- * @param {MetricEventAgent} agent the source of the action for this metric
153
- * @param {string} target the 'thing' that this metric includes information about
154
- * @param {MetricEventVerb} verb the action that this metric includes information about
155
- * @param {BehavioralEventPayload} payload information specific to this event. This should be flat, i.e. it should not include nested objects.
156
- * @returns {Promise<any>}
157
- */
158
- public submitBehavioralEvent({
159
- product,
160
- agent,
161
- target,
162
- verb,
163
- payload,
164
- }: {
165
- product: MetricEventProduct;
166
- agent: MetricEventAgent;
167
- target: string;
168
- verb: MetricEventVerb;
169
- payload?: BehavioralEventPayload;
170
- }) {
171
- this.logger.log(
172
- BEHAVIORAL_LOG_IDENTIFIER,
173
- `BehavioralMetrics: @submitBehavioralEvent. Submit Behavioral event: ${product}.${agent}.${target}.${verb}`
174
- );
175
- const behavioralEvent = this.createEventObject({product, agent, target, verb, payload});
176
-
177
- return this.clientMetricsBatcher.request(behavioralEvent);
178
- }
179
- }
@@ -1,3 +0,0 @@
1
- /* eslint-disable import/prefer-default-export */
2
-
3
- export const BEHAVIORAL_LOG_IDENTIFIER = 'behavioral-events -> ';