Skip to content

Commit

Permalink
missing metrics hadling
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Nov 14, 2024
1 parent 19b6b53 commit e17534d
Showing 1 changed file with 67 additions and 2 deletions.
69 changes: 67 additions & 2 deletions opentelemetry-user-events-metrics/src/exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Debug for MetricsExporter {
}

impl MetricsExporter {
async fn serialize_and_write(&self, resource_metric: &ResourceMetrics) -> Result<()> {
fn serialize_and_write(&self, resource_metric: &ResourceMetrics) -> Result<()> {
// Allocate a local buffer for each write operation
// TODO: Investigate if this can be optimized to avoid reallocation or
// allocate a fixed buffer size for all writes
Expand Down Expand Up @@ -176,6 +176,24 @@ impl PushMetricsExporter for MetricsExporter {
};
resource_metrics_list.push(resource_metric);
}
} else if let Some(gauge) = data.downcast_ref::<data::Gauge<f64>>() {
for data_point in &gauge.data_points {
let resource_metric = ResourceMetrics {
resource: metrics.resource.clone(),
scope_metrics: vec![ScopeMetrics {
scope: scope_metric.scope.clone(),
metrics: vec![Metric {
name: metric.name.clone(),
description: metric.description.clone(),
unit: metric.unit.clone(),
data: Box::new(data::Gauge {
data_points: vec![data_point.clone()],
}),
}],
}],
};
resource_metrics_list.push(resource_metric);
}
} else if let Some(sum) = data.downcast_ref::<data::Sum<u64>>() {
for data_point in &sum.data_points {
let resource_metric = ResourceMetrics {
Expand Down Expand Up @@ -283,13 +301,60 @@ impl PushMetricsExporter for MetricsExporter {
};
resource_metrics_list.push(resource_metric);
}
} else if let Some(exp_hist) =
data.downcast_ref::<data::ExponentialHistogram<f64>>()

Check warning on line 305 in opentelemetry-user-events-metrics/src/exporter/mod.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-user-events-metrics/src/exporter/mod.rs#L260-L305

Added lines #L260 - L305 were not covered by tests
{
for data_point in &exp_hist.data_points {
let resource_metric = ResourceMetrics {
resource: metrics.resource.clone(),
scope_metrics: vec![ScopeMetrics {
scope: scope_metric.scope.clone(),
metrics: vec![Metric {
name: metric.name.clone(),
description: metric.description.clone(),
unit: metric.unit.clone(),
data: Box::new(data::ExponentialHistogram {
temporality: exp_hist.temporality,
data_points: vec![ExponentialHistogramDataPoint {
attributes: data_point.attributes.clone(),
count: data_point.count,
start_time: data_point.start_time,
time: data_point.time,
min: data_point.min,
max: data_point.max,
sum: data_point.sum,
scale: data_point.scale,
zero_count: data_point.zero_count,
zero_threshold: data_point.zero_threshold,
positive_bucket: ExponentialBucket {
offset: data_point.positive_bucket.offset,
counts: data_point
.positive_bucket
.counts
.clone(),
},
negative_bucket: ExponentialBucket {
offset: data_point.negative_bucket.offset,
counts: data_point
.negative_bucket
.counts
.clone(),
},
exemplars: data_point.exemplars.clone(),
}],
}),
}],
}],
};
resource_metrics_list.push(resource_metric);
}
}

Check warning on line 351 in opentelemetry-user-events-metrics/src/exporter/mod.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-user-events-metrics/src/exporter/mod.rs#L307-L351

Added lines #L307 - L351 were not covered by tests
}
}

// Asynchronously serialize and write each ResourceMetrics to tracepoint
for resource_metric in resource_metrics_list {
self.serialize_and_write(&resource_metric).await?;
self.serialize_and_write(&resource_metric)?;

Check warning on line 357 in opentelemetry-user-events-metrics/src/exporter/mod.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-user-events-metrics/src/exporter/mod.rs#L356-L357

Added lines #L356 - L357 were not covered by tests
}
}
Ok(())
Expand Down

0 comments on commit e17534d

Please sign in to comment.