@@ -81,47 +81,73 @@ opentelemetry::sdk::common::ExportResult Exporter::Export(
8181 point_data_with_attributes.point_data )) {
8282 auto value = nostd::get<sdk::metrics::SumPointData>(
8383 point_data_with_attributes.point_data );
84- MetricsEventType event_type = MetricsEventType::ULongMetric;
84+ ValueType new_value = value.value_ ;
85+
86+ MetricsEventType event_type;
87+
8588 if (nostd::holds_alternative<double >(value.value_ )) {
8689 event_type = MetricsEventType::DoubleMetric;
90+ } else {
91+ if (!value.is_monotonic_ ) {
92+ // NOTE - Potential for minor precision loss implicitly going from
93+ // int64_t to double -
94+ // - A 64-bit integer can hold more significant decimal digits
95+ // than a standard
96+ // IEEE (64-bit) double precision floating-point
97+ // representation
98+ new_value = static_cast <double >(nostd::get<int64_t >(new_value));
99+ event_type = MetricsEventType::DoubleMetric;
100+
101+ } else {
102+ event_type = MetricsEventType::Uint64Metric;
103+ }
87104 }
88-
89105 body_length = SerializeNonHistogramMetrics (
90- sdk::metrics::AggregationType::kSum , event_type, value. value_ ,
106+ sdk::metrics::AggregationType::kSum , event_type, new_value ,
91107 metric_data.end_ts , metric_data.instrument_descriptor .name_ ,
92108 point_data_with_attributes.attributes );
93109 data_transport_->Send (event_type, buffer_non_histogram_,
94110 body_length + kBinaryHeaderSize );
95111
96112 } else if (nostd::holds_alternative<sdk::metrics::LastValuePointData>(
97113 point_data_with_attributes.point_data )) {
98- auto value = nostd::get<sdk::metrics::SumPointData >(
114+ auto value = nostd::get<sdk::metrics::LastValuePointData >(
99115 point_data_with_attributes.point_data );
100- MetricsEventType event_type = MetricsEventType::ULongMetric;
101- if (nostd::holds_alternative<double >(value.value_ )) {
102- event_type = MetricsEventType::DoubleMetric;
116+ ValueType new_value = value.value_ ;
117+ if (nostd::holds_alternative<int64_t >(value.value_ )) {
118+ // NOTE - Potential for minor precision loss implicitly going from
119+ // int64_t to double -
120+ // - A 64-bit integer can hold more significant decimal digits
121+ // than a standard
122+ // IEEE (64-bit) double precision floating-point representation
123+ new_value = static_cast <double >(nostd::get<int64_t >(new_value));
103124 }
125+ MetricsEventType event_type = MetricsEventType::DoubleMetric;
104126 body_length = SerializeNonHistogramMetrics (
105- sdk::metrics::AggregationType::kLastValue , event_type,
106- value.value_ , metric_data.end_ts ,
107- metric_data.instrument_descriptor .name_ ,
127+ sdk::metrics::AggregationType::kLastValue , event_type, new_value,
128+ metric_data.end_ts , metric_data.instrument_descriptor .name_ ,
108129 point_data_with_attributes.attributes );
109130 data_transport_->Send (event_type, buffer_non_histogram_,
110131 body_length + kBinaryHeaderSize );
111132 } else if (nostd::holds_alternative<sdk::metrics::HistogramPointData>(
112133 point_data_with_attributes.point_data )) {
113134 auto value = nostd::get<sdk::metrics::HistogramPointData>(
114135 point_data_with_attributes.point_data );
115- MetricsEventType event_type =
116- MetricsEventType::ExternallyAggregatedULongDistributionMetric;
136+ ValueType new_sum = value.sum_ ;
137+ ValueType new_min = value.min_ ;
138+ ValueType new_max = value.max_ ;
139+
117140 if (nostd::holds_alternative<double >(value.sum_ )) {
118- LOG_ERROR (" Geneva Exporter::Export- Double value is not supported "
119- " for Histogram" );
120- continue ;
141+ // TODO: Double is not supported by Geneva, convert it to int64_t
142+ new_sum = static_cast <int64_t >(nostd::get<double >(new_sum));
143+ new_min = static_cast <int64_t >(nostd::get<double >(new_min));
144+ new_max = static_cast <int64_t >(nostd::get<double >(new_max));
121145 }
146+ MetricsEventType event_type =
147+ MetricsEventType::ExternallyAggregatedUlongDistributionMetric;
122148 body_length = SerializeHistogramMetrics (
123149 sdk::metrics::AggregationType::kHistogram , event_type,
124- value.count_ , value. sum_ , value. min_ , value. max_ ,
150+ value.count_ , new_sum, new_min, new_max ,
125151 nostd::get<sdk::metrics::HistogramPointData>(
126152 point_data_with_attributes.point_data )
127153 .boundaries_ ,
@@ -232,13 +258,15 @@ size_t Exporter::SerializeNonHistogramMetrics(
232258 .count ());
233259
234260 SerializeInt<uint64_t >(buffer_non_histogram_, bufferIndex, windows_ticks);
235- if (event_type == MetricsEventType::ULongMetric ) {
261+ if (event_type == MetricsEventType::Uint64Metric ) {
236262 SerializeInt<uint64_t >(buffer_non_histogram_, bufferIndex,
237263 static_cast <uint64_t >(nostd::get<int64_t >(value)));
238- } else {
264+ } else if (event_type == MetricsEventType::DoubleMetric) {
239265 SerializeInt<uint64_t >(
240266 buffer_non_histogram_, bufferIndex,
241267 *(reinterpret_cast <const uint64_t *>(&(nostd::get<double >(value)))));
268+ } else {
269+ // Won't reach here.
242270 }
243271 return body_length;
244272}
@@ -290,7 +318,7 @@ size_t Exporter::SerializeHistogramMetrics(
290318 size_t index = 0 ;
291319 uint16_t bucket_count = 0 ;
292320 if (event_type ==
293- MetricsEventType::ExternallyAggregatedULongDistributionMetric ) {
321+ MetricsEventType::ExternallyAggregatedUlongDistributionMetric ) {
294322 for (auto boundary : boundaries) {
295323 if (counts[index] > 0 ) {
296324 SerializeInt<uint64_t >(buffer_histogram_, bufferIndex,
@@ -340,7 +368,7 @@ size_t Exporter::SerializeHistogramMetrics(
340368 // sum, min, max
341369
342370 if (event_type ==
343- MetricsEventType::ExternallyAggregatedULongDistributionMetric ) {
371+ MetricsEventType::ExternallyAggregatedUlongDistributionMetric ) {
344372 // sum
345373 SerializeInt<uint64_t >(buffer_histogram_, bufferIndex,
346374 static_cast <uint64_t >(nostd::get<int64_t >(sum)));
@@ -351,18 +379,7 @@ size_t Exporter::SerializeHistogramMetrics(
351379 SerializeInt<uint64_t >(buffer_histogram_, bufferIndex,
352380 static_cast <uint64_t >(nostd::get<int64_t >(max)));
353381 } else {
354- // sum
355- SerializeInt<uint64_t >(
356- buffer_histogram_, bufferIndex,
357- *(reinterpret_cast <const uint64_t *>(&(nostd::get<double >(sum)))));
358- // min
359- SerializeInt<uint64_t >(
360- buffer_histogram_, bufferIndex,
361- *(reinterpret_cast <const uint64_t *>(&(nostd::get<double >(min)))));
362- // max
363- SerializeInt<uint64_t >(
364- buffer_histogram_, bufferIndex,
365- *(reinterpret_cast <const uint64_t *>(&(nostd::get<double >(max)))));
382+ // won't reach here.
366383 }
367384 return body_length;
368385}
0 commit comments