Skip to content

Commit fa3dee3

Browse files
add metric type
1 parent fefcd34 commit fa3dee3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/otel/metrics.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ fn flatten_exemplar(exemplars: &[Exemplar]) -> Map<String, Value> {
8282
/// and returns a `Vec` of `Map` of the flattened json
8383
/// this function is reused in all json objects that have number data points
8484
fn flatten_number_data_points(data_points: &[NumberDataPoint]) -> Vec<Map<String, Value>> {
85+
println!("data points: {:?}", data_points);
8586
data_points
8687
.iter()
8788
.map(|data_point| {
@@ -392,21 +393,26 @@ fn flatten_summary(summary: &Summary) -> Vec<Map<String, Value>> {
392393
pub fn flatten_metrics_record(metrics_record: &Metric) -> Vec<Map<String, Value>> {
393394
let mut data_points_json = Vec::new();
394395
let mut metric_json = Map::new();
395-
396+
let mut metric_type = String::default();
396397
match &metrics_record.data {
397398
Some(metric::Data::Gauge(gauge)) => {
399+
metric_type = "gauge".to_string();
398400
data_points_json.extend(flatten_gauge(gauge));
399401
}
400402
Some(metric::Data::Sum(sum)) => {
403+
metric_type = "sum".to_string();
401404
data_points_json.extend(flatten_sum(sum));
402405
}
403406
Some(metric::Data::Histogram(histogram)) => {
407+
metric_type = "histogram".to_string();
404408
data_points_json.extend(flatten_histogram(histogram));
405409
}
406410
Some(metric::Data::ExponentialHistogram(exp_histogram)) => {
411+
metric_type = "exponential_histogram".to_string();
407412
data_points_json.extend(flatten_exp_histogram(exp_histogram));
408413
}
409414
Some(metric::Data::Summary(summary)) => {
415+
metric_type = "summary".to_string();
410416
data_points_json.extend(flatten_summary(summary));
411417
}
412418
None => {}
@@ -423,6 +429,7 @@ pub fn flatten_metrics_record(metrics_record: &Metric) -> Vec<Map<String, Value>
423429
"metric_unit".to_string(),
424430
Value::String(metrics_record.unit.clone()),
425431
);
432+
metric_json.insert("metric_type".to_string(), Value::String(metric_type));
426433
insert_attributes(&mut metric_json, &metrics_record.metadata);
427434
for data_point_json in &mut data_points_json {
428435
for (key, value) in &metric_json {

0 commit comments

Comments
 (0)