@@ -16,7 +16,6 @@ import Foundation
16
16
import OpenTelemetryApi
17
17
import OpenTelemetrySdk
18
18
19
-
20
19
struct MetricsAdapter {
21
20
static func toProtoResourceMetrics( metricDataList: [ Metric ] ) -> [ Opentelemetry_Proto_Metrics_V1_ResourceMetrics ] {
22
21
let resourceAndLibraryMap = groupByResouceAndLibrary ( metricDataList: metricDataList)
@@ -26,7 +25,7 @@ struct MetricsAdapter {
26
25
var instrumentationLibraryMetrics = [ Opentelemetry_Proto_Metrics_V1_InstrumentationLibraryMetrics] ( )
27
26
resMap. value. forEach { instLibrary in
28
27
var protoInst =
29
- Opentelemetry_Proto_Metrics_V1_InstrumentationLibraryMetrics ( )
28
+ Opentelemetry_Proto_Metrics_V1_InstrumentationLibraryMetrics ( )
30
29
protoInst. instrumentationLibrary =
31
30
CommonAdapter . toProtoInstrumentationLibrary ( instrumentationLibraryInfo: instLibrary. key)
32
31
instLibrary. value. forEach {
@@ -38,112 +37,101 @@ struct MetricsAdapter {
38
37
resourceMetric. resource = ResourceAdapter . toProtoResource ( resource: resMap. key)
39
38
resourceMetric. instrumentationLibraryMetrics. append ( contentsOf: instrumentationLibraryMetrics)
40
39
resourceMetrics. append ( resourceMetric)
41
-
42
40
}
43
41
44
-
45
-
46
42
return resourceMetrics
47
43
}
48
44
49
- private static func groupByResouceAndLibrary( metricDataList: [ Metric ] ) -> [ Resource : [ InstrumentationLibraryInfo : [ Opentelemetry_Proto_Metrics_V1_Metric ] ] ] {
50
- var results = [ Resource : [ InstrumentationLibraryInfo : [ Opentelemetry_Proto_Metrics_V1_Metric] ] ] ( )
45
+ private static func groupByResouceAndLibrary( metricDataList: [ Metric ] ) -> [ Resource : [ InstrumentationLibraryInfo : [ Opentelemetry_Proto_Metrics_V1_Metric ] ] ] {
46
+ var results = [ Resource: [ InstrumentationLibraryInfo: [ Opentelemetry_Proto_Metrics_V1_Metric] ] ] ( )
51
47
52
48
metricDataList. forEach {
53
- results [ $0. resource, default: [ InstrumentationLibraryInfo : [ Opentelemetry_Proto_Metrics_V1_Metric] ] ( ) ] [ $0. instrumentationLibraryInfo, default: [ Opentelemetry_Proto_Metrics_V1_Metric] ( ) ]
49
+ results [ $0. resource, default: [ InstrumentationLibraryInfo: [ Opentelemetry_Proto_Metrics_V1_Metric] ] ( ) ] [ $0. instrumentationLibraryInfo, default: [ Opentelemetry_Proto_Metrics_V1_Metric] ( ) ]
54
50
. append ( toProtoMetric ( metric: $0) )
55
51
}
56
52
57
53
return results
58
54
}
59
55
60
56
static func toProtoMetric( metric: Metric ) -> Opentelemetry_Proto_Metrics_V1_Metric {
61
-
62
57
var protoMetric = Opentelemetry_Proto_Metrics_V1_Metric ( )
63
58
protoMetric. name = metric. name
64
59
protoMetric. description_p = metric. description
65
60
66
-
67
61
metric. data. forEach {
68
- switch metric. aggregationType {
69
- case . doubleSum:
70
- guard let sumData = $0 as? SumData < Double > else {
71
- break
72
- }
73
- var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleDataPoint ( )
74
- protoDataPoint. value = sumData. sum
75
- sumData. labels. forEach {
76
- var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue ( )
77
- kvp. key = $0. key
78
- kvp. value = $0. value
79
- protoDataPoint. labels. append ( kvp)
80
- }
62
+ switch metric. aggregationType {
63
+ case . doubleSum:
64
+ guard let sumData = $0 as? SumData < Double > else {
65
+ break
66
+ }
67
+ var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleDataPoint ( )
68
+ protoDataPoint. value = sumData. sum
69
+ sumData. labels. forEach {
70
+ var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue ( )
71
+ kvp. key = $0. key
72
+ kvp. value = $0. value
73
+ protoDataPoint. labels. append ( kvp)
74
+ }
81
75
82
- protoMetric. doubleSum. dataPoints. append ( protoDataPoint)
83
- break
84
- case . doubleSummary:
76
+ protoMetric. doubleSum. dataPoints. append ( protoDataPoint)
77
+ case . doubleSummary:
85
78
86
- guard let summaryData = $0 as? SummaryData < Double > else {
87
- break
88
- }
89
- var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleHistogramDataPoint ( )
90
- protoDataPoint. sum = summaryData. sum
91
- protoDataPoint. count = UInt64 ( summaryData. count)
92
- protoDataPoint. explicitBounds = [ summaryData. min, summaryData. max]
79
+ guard let summaryData = $0 as? SummaryData < Double > else {
80
+ break
81
+ }
82
+ var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleHistogramDataPoint ( )
83
+ protoDataPoint. sum = summaryData. sum
84
+ protoDataPoint. count = UInt64 ( summaryData. count)
85
+ protoDataPoint. explicitBounds = [ summaryData. min, summaryData. max]
93
86
94
- protoDataPoint. startTimeUnixNano = summaryData. startTimestamp. timeIntervalSince1970. toNanoseconds
95
- protoDataPoint. timeUnixNano = summaryData. timestamp. timeIntervalSince1970. toNanoseconds
87
+ protoDataPoint. startTimeUnixNano = summaryData. startTimestamp. timeIntervalSince1970. toNanoseconds
88
+ protoDataPoint. timeUnixNano = summaryData. timestamp. timeIntervalSince1970. toNanoseconds
96
89
97
- summaryData. labels. forEach {
98
- var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue ( )
99
- kvp. key = $0. key
100
- kvp. value = $0. value
101
- protoDataPoint. labels. append ( kvp)
102
- }
90
+ summaryData. labels. forEach {
91
+ var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue ( )
92
+ kvp. key = $0. key
93
+ kvp. value = $0. value
94
+ protoDataPoint. labels. append ( kvp)
95
+ }
103
96
104
- protoMetric. doubleHistogram. dataPoints. append ( protoDataPoint)
97
+ protoMetric. doubleHistogram. dataPoints. append ( protoDataPoint)
105
98
106
- break
107
- case . intSum:
108
- guard let sumData = $0 as? SumData < Int > else {
109
- break ;
110
- }
111
- var protoDataPoint = Opentelemetry_Proto_Metrics_V1_IntDataPoint ( )
112
- protoDataPoint. value = Int64 ( sumData. sum)
113
- sumData. labels. forEach {
114
- var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue ( )
115
- kvp. key = $0. key
116
- kvp. value = $0. value
117
- protoDataPoint. labels. append ( kvp)
118
- }
99
+ case . intSum:
100
+ guard let sumData = $0 as? SumData < Int > else {
101
+ break
102
+ }
103
+ var protoDataPoint = Opentelemetry_Proto_Metrics_V1_IntDataPoint ( )
104
+ protoDataPoint. value = Int64 ( sumData. sum)
105
+ sumData. labels. forEach {
106
+ var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue ( )
107
+ kvp. key = $0. key
108
+ kvp. value = $0. value
109
+ protoDataPoint. labels. append ( kvp)
110
+ }
119
111
120
- protoMetric. intSum. dataPoints. append ( protoDataPoint)
112
+ protoMetric. intSum. dataPoints. append ( protoDataPoint)
121
113
122
- break
123
- case . intSummary:
124
- guard let summaryData = $0 as? SummaryData < Int > else {
125
- break
126
- }
127
- var protoDataPoint = Opentelemetry_Proto_Metrics_V1_IntHistogramDataPoint ( )
128
- protoDataPoint. sum = Int64 ( summaryData. sum)
129
- protoDataPoint. count = UInt64 ( summaryData. count)
130
- protoDataPoint. bucketCounts = [ UInt64 ( summaryData. min) , UInt64 ( summaryData. max) ]
131
- protoDataPoint. startTimeUnixNano = summaryData. startTimestamp. timeIntervalSince1970. toNanoseconds
132
- protoDataPoint. timeUnixNano = summaryData. timestamp. timeIntervalSince1970. toNanoseconds
114
+ case . intSummary:
115
+ guard let summaryData = $0 as? SummaryData < Int > else {
116
+ break
117
+ }
118
+ var protoDataPoint = Opentelemetry_Proto_Metrics_V1_IntHistogramDataPoint ( )
119
+ protoDataPoint. sum = Int64 ( summaryData. sum)
120
+ protoDataPoint. count = UInt64 ( summaryData. count)
121
+ protoDataPoint. bucketCounts = [ UInt64 ( summaryData. min) , UInt64 ( summaryData. max) ]
122
+ protoDataPoint. startTimeUnixNano = summaryData. startTimestamp. timeIntervalSince1970. toNanoseconds
123
+ protoDataPoint. timeUnixNano = summaryData. timestamp. timeIntervalSince1970. toNanoseconds
133
124
134
- summaryData. labels. forEach {
135
- var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue ( )
136
- kvp. key = $0. key
137
- kvp. value = $0. value
138
- protoDataPoint. labels. append ( kvp)
139
- }
140
-
141
- protoMetric. intHistogram. dataPoints. append ( protoDataPoint)
125
+ summaryData. labels. forEach {
126
+ var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue ( )
127
+ kvp. key = $0. key
128
+ kvp. value = $0. value
129
+ protoDataPoint. labels. append ( kvp)
130
+ }
142
131
143
- break
132
+ protoMetric . intHistogram . dataPoints . append ( protoDataPoint )
144
133
}
145
134
}
146
135
return protoMetric
147
136
}
148
-
149
137
}
0 commit comments