@@ -44,24 +44,21 @@ export function toResourceMetrics(
44
44
attributes : toAttributes ( resourceMetrics . resource . attributes ) ,
45
45
droppedAttributesCount : 0 ,
46
46
} ,
47
- schemaUrl : undefined , // TODO: Schema Url does not exist yet in the SDK.
47
+ schemaUrl : undefined ,
48
48
scopeMetrics : toScopeMetrics ( resourceMetrics . scopeMetrics ) ,
49
49
} ;
50
50
}
51
51
52
52
export function toScopeMetrics ( scopeMetrics : ScopeMetrics [ ] ) : IScopeMetrics [ ] {
53
53
return Array . from (
54
- scopeMetrics . map ( metrics => {
55
- const scopeMetrics : IScopeMetrics = {
56
- scope : {
57
- name : metrics . scope . name ,
58
- version : metrics . scope . version ,
59
- } ,
60
- metrics : metrics . metrics . map ( metricData => toMetric ( metricData ) ) ,
61
- schemaUrl : metrics . scope . schemaUrl ,
62
- } ;
63
- return scopeMetrics ;
64
- } )
54
+ scopeMetrics . map ( metrics => ( {
55
+ scope : {
56
+ name : metrics . scope . name ,
57
+ version : metrics . scope . version ,
58
+ } ,
59
+ metrics : metrics . metrics . map ( metricData => toMetric ( metricData ) ) ,
60
+ schemaUrl : metrics . scope . schemaUrl ,
61
+ } ) )
65
62
) ;
66
63
}
67
64
@@ -76,27 +73,31 @@ export function toMetric(metricData: MetricData): IMetric {
76
73
metricData . aggregationTemporality
77
74
) ;
78
75
79
- if ( metricData . dataPointType === DataPointType . SUM ) {
80
- out . sum = {
81
- aggregationTemporality,
82
- isMonotonic : metricData . isMonotonic ,
83
- dataPoints : toSingularDataPoints ( metricData ) ,
84
- } ;
85
- } else if ( metricData . dataPointType === DataPointType . GAUGE ) {
86
- // Instrument is a gauge.
87
- out . gauge = {
88
- dataPoints : toSingularDataPoints ( metricData ) ,
89
- } ;
90
- } else if ( metricData . dataPointType === DataPointType . HISTOGRAM ) {
91
- out . histogram = {
92
- aggregationTemporality,
93
- dataPoints : toHistogramDataPoints ( metricData ) ,
94
- } ;
95
- } else if ( metricData . dataPointType === DataPointType . EXPONENTIAL_HISTOGRAM ) {
96
- out . exponentialHistogram = {
97
- aggregationTemporality,
98
- dataPoints : toExponentialHistogramDataPoints ( metricData ) ,
99
- } ;
76
+ switch ( metricData . dataPointType ) {
77
+ case DataPointType . SUM :
78
+ out . sum = {
79
+ aggregationTemporality,
80
+ isMonotonic : metricData . isMonotonic ,
81
+ dataPoints : toSingularDataPoints ( metricData ) ,
82
+ } ;
83
+ break ;
84
+ case DataPointType . GAUGE :
85
+ out . gauge = {
86
+ dataPoints : toSingularDataPoints ( metricData ) ,
87
+ } ;
88
+ break ;
89
+ case DataPointType . HISTOGRAM :
90
+ out . histogram = {
91
+ aggregationTemporality,
92
+ dataPoints : toHistogramDataPoints ( metricData ) ,
93
+ } ;
94
+ break ;
95
+ case DataPointType . EXPONENTIAL_HISTOGRAM :
96
+ out . exponentialHistogram = {
97
+ aggregationTemporality,
98
+ dataPoints : toExponentialHistogramDataPoints ( metricData ) ,
99
+ } ;
100
+ break ;
100
101
}
101
102
102
103
return out ;
@@ -115,10 +116,13 @@ function toSingularDataPoint(
115
116
timeUnixNano : hrTimeToNanoseconds ( dataPoint . endTime ) ,
116
117
} ;
117
118
118
- if ( valueType === ValueType . INT ) {
119
- out . asInt = dataPoint . value as number ;
120
- } else if ( valueType === ValueType . DOUBLE ) {
121
- out . asDouble = dataPoint . value as number ;
119
+ switch ( valueType ) {
120
+ case ValueType . INT :
121
+ out . asInt = dataPoint . value as number ;
122
+ break ;
123
+ case ValueType . DOUBLE :
124
+ out . asDouble = dataPoint . value as number ;
125
+ break ;
122
126
}
123
127
124
128
return out ;
@@ -177,13 +181,10 @@ function toExponentialHistogramDataPoints(
177
181
function toAggregationTemporality (
178
182
temporality : AggregationTemporality
179
183
) : EAggregationTemporality {
180
- if ( temporality === AggregationTemporality . DELTA ) {
181
- return EAggregationTemporality . AGGREGATION_TEMPORALITY_DELTA ;
184
+ switch ( temporality ) {
185
+ case AggregationTemporality . DELTA :
186
+ return EAggregationTemporality . AGGREGATION_TEMPORALITY_DELTA ;
187
+ case AggregationTemporality . CUMULATIVE :
188
+ return EAggregationTemporality . AGGREGATION_TEMPORALITY_CUMULATIVE ;
182
189
}
183
-
184
- if ( temporality === AggregationTemporality . CUMULATIVE ) {
185
- return EAggregationTemporality . AGGREGATION_TEMPORALITY_CUMULATIVE ;
186
- }
187
-
188
- return EAggregationTemporality . AGGREGATION_TEMPORALITY_UNSPECIFIED ;
189
190
}
0 commit comments