@@ -8,82 +8,22 @@ import {EventPayload, Table} from './metrics.types';
8
8
*/
9
9
export default class BusinessMetrics extends GenericMetrics {
10
10
/**
11
- * unfortunately, the pinot team does not allow changes to the schema of wbxapp_callend_metrics
12
- * so we have to shim this layer specifically for this
13
- * https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Table+wbxapp_callend_metrics
14
- * @param {EventPayload } payload payload of the metric
15
- * @returns {Promise<any> }
16
- */
17
- private submitCallEndEvent ( { payload} : { payload : EventPayload } ) {
18
- const event = {
19
- type : [ 'business' ] ,
20
- eventPayload : {
21
- key : 'callEnd' ,
22
- client_timestamp : new Date ( ) . toISOString ( ) ,
23
- appType : 'Web Client' ,
24
- value : {
25
- ...payload ,
26
- } ,
27
- } ,
28
- } ;
29
-
30
- return this . submitEvent ( {
31
- kind : 'buisness-events:wbxapp_callend_metrics -> ' ,
32
- name : 'wbxapp_callend_metrics' ,
33
- event,
34
- } ) ;
35
- }
36
-
37
- /**
38
- * Submit a buisness metric to our metrics endpoint, going to the default business_ucf table
39
- * all event payload keys are converted into a hex string value
40
- * unfortunately, the pinot team does not allow changes to the schema of business_metrics
41
- * so we have to shim this layer specifically for this
42
- * https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Table%3A+business_metrics
11
+ * Build the metric event to submit.
43
12
* @param {string } name of the metric
44
- * @param {EventPayload } payload payload of the metric
45
- * @returns {Promise<any> }
46
- */
47
- private submitBusinessMetricsEvent ( { name, payload} : { name : string ; payload : EventPayload } ) {
48
- const event = {
49
- type : [ 'business' ] ,
50
- eventPayload : {
51
- key : name ,
52
- client_timestamp : new Date ( ) . toISOString ( ) ,
53
- appType : 'Web Client' ,
54
- value : {
55
- ...this . getContext ( ) ,
56
- ...this . getBrowserDetails ( ) ,
57
- ...payload ,
58
- } ,
59
- } ,
60
- } ;
61
-
62
- return this . submitEvent ( { kind : 'buisness-events:business_metrics -> ' , name, event} ) ;
63
- }
64
-
65
- /**
66
- * Submit a buisness metric to our metrics endpoint, going to the default business_ucf table
67
- * all event payload keys are converted into a hex string value
68
- * https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Business+metrics++-%3E+ROMA
69
- * @param {string } name of the metric
70
- * @param {EventPayload } user payload of the metric
71
- * @returns {Promise<any> }
13
+ * @param {EventPayload } payload user payload of the metric
14
+ * @param {EventPayload } metadata to include outside of eventPayload.value
15
+ * @returns {object }
72
16
*/
73
- private submitDefaultEvent ( { name, payload} : { name : string ; payload : EventPayload } ) {
74
- const event = {
17
+ private buildEvent ( { name, payload, metadata } : { name : string ; payload : object ; metadata : object } ) {
18
+ return {
75
19
type : [ 'business' ] ,
76
20
eventPayload : {
77
21
key : name ,
78
- appType : 'Web Client' ,
79
22
client_timestamp : new Date ( ) . toISOString ( ) ,
80
- context : this . getContext ( ) ,
81
- browserDetails : this . getBrowserDetails ( ) ,
23
+ ...metadata ,
82
24
value : payload ,
83
25
} ,
84
26
} ;
85
-
86
- return this . submitEvent ( { kind : 'buisness-events:default -> ' , name, event} ) ;
87
27
}
88
28
89
29
/**
@@ -93,30 +33,80 @@ export default class BusinessMetrics extends GenericMetrics {
93
33
* @param {string } name of the metric, ignored if going to wbxapp_callend_metrics
94
34
* @param {EventPayload } payload user payload of the metric
95
35
* @param {Table } table optional - to submit the metric to and adapt the sent schema
36
+ * @param {EventPayload } metadata optional - to include outside of eventPayload.value
96
37
* @returns {Promise<any> }
97
38
*/
98
39
public submitBusinessEvent ( {
99
40
name,
100
41
payload,
101
42
table,
43
+ metadata,
102
44
} : {
103
45
name : string ;
104
46
payload : EventPayload ;
105
47
table ?: Table ;
48
+ metadata ?: EventPayload ;
106
49
} ) : Promise < void > {
107
50
if ( ! table ) {
108
51
table = 'default' ;
109
52
}
53
+ if ( ! metadata ) {
54
+ metadata = { } ;
55
+ }
56
+ if ( ! metadata . appType ) {
57
+ metadata . appType = 'Web Client' ;
58
+ }
110
59
switch ( table ) {
111
- case 'wbxapp_callend_metrics' :
112
- return this . submitCallEndEvent ( { payload} ) ;
113
- case 'business_metrics' :
114
- return this . submitBusinessMetricsEvent ( { name, payload} ) ;
60
+ case 'wbxapp_callend_metrics' : {
61
+ // https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Table+wbxapp_callend_metrics
62
+ const callEndEvent = this . buildEvent ( { name : 'callEnd' , payload, metadata} ) ;
63
+
64
+ return this . submitEvent ( {
65
+ kind : 'buisness-events:wbxapp_callend_metrics -> ' ,
66
+ name : 'wbxapp_callend_metrics' ,
67
+ event : callEndEvent ,
68
+ } ) ;
69
+ }
70
+
71
+ case 'business_metrics' : {
72
+ // all event payload keys are converted into a hex string value
73
+ // unfortunately, the pinot team does not allow changes to the schema of business_metrics
74
+ // so we have to shim this layer specifically for this
75
+ // https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Table%3A+business_metrics
76
+ const businessEvent = this . buildEvent ( {
77
+ name,
78
+ payload : {
79
+ ...this . getContext ( ) ,
80
+ ...this . getBrowserDetails ( ) ,
81
+ ...payload ,
82
+ } ,
83
+ metadata,
84
+ } ) ;
85
+
86
+ return this . submitEvent ( {
87
+ kind : 'buisness-events:business_metrics -> ' ,
88
+ name,
89
+ event : businessEvent ,
90
+ } ) ;
91
+ }
92
+
115
93
case 'business_ucf' :
116
- return this . submitDefaultEvent ( { name, payload} ) ;
117
94
case 'default' :
118
- default :
119
- return this . submitDefaultEvent ( { name, payload} ) ;
95
+ default : {
96
+ // all event payload keys are converted into a hex string value
97
+ // https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Business+metrics++-%3E+ROMA
98
+ const defaultEvent = this . buildEvent ( {
99
+ name,
100
+ payload,
101
+ metadata : {
102
+ context : this . getContext ( ) ,
103
+ browserDetails : this . getBrowserDetails ( ) ,
104
+ ...metadata ,
105
+ } ,
106
+ } ) ;
107
+
108
+ return this . submitEvent ( { kind : 'buisness-events:default -> ' , name, event : defaultEvent } ) ;
109
+ }
120
110
}
121
111
}
122
112
}
0 commit comments