From 8bdd18995d64053c8f76c64f86186560e14f4ea3 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Mon, 30 Sep 2024 14:02:31 -0700 Subject: [PATCH] For Delta Temporarlity, avoid exporting when no new measurements are made (#2153) --- opentelemetry-sdk/CHANGELOG.md | 3 +++ opentelemetry-sdk/src/metrics/mod.rs | 1 - opentelemetry-sdk/src/metrics/periodic_reader.rs | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index 5061d12112..4b6679940a 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -11,6 +11,9 @@ external sources to be sent through OpenTelemetry. [#2105](https://github.com/open-telemetry/opentelemetry-rust/pull/2105) - Feature: `SimpleSpanProcessor::new` is now public [#2119](https://github.com/open-telemetry/opentelemetry-rust/pull/2119) +- For Delta Temporality, exporters are not invoked unless there were new + measurements since the last collect/export. + [#2153](https://github.com/open-telemetry/opentelemetry-rust/pull/2153) ## v0.25.0 diff --git a/opentelemetry-sdk/src/metrics/mod.rs b/opentelemetry-sdk/src/metrics/mod.rs index cd6cc84643..a9b61622e3 100644 --- a/opentelemetry-sdk/src/metrics/mod.rs +++ b/opentelemetry-sdk/src/metrics/mod.rs @@ -973,7 +973,6 @@ mod tests { } #[tokio::test(flavor = "multi_thread", worker_threads = 1)] - #[ignore = "Known bug: https://github.com/open-telemetry/opentelemetry-rust/issues/1598"] async fn delta_memory_efficiency_test() { // Run this test with stdout enabled to see output. // cargo test delta_memory_efficiency_test --features=testing -- --nocapture diff --git a/opentelemetry-sdk/src/metrics/periodic_reader.rs b/opentelemetry-sdk/src/metrics/periodic_reader.rs index f6aafeb06b..2c2cccf624 100644 --- a/opentelemetry-sdk/src/metrics/periodic_reader.rs +++ b/opentelemetry-sdk/src/metrics/periodic_reader.rs @@ -235,6 +235,10 @@ struct PeriodicReaderWorker { impl PeriodicReaderWorker { async fn collect_and_export(&mut self) -> Result<()> { self.reader.collect(&mut self.rm)?; + if self.rm.scope_metrics.is_empty() { + // No metrics to export. + return Ok(()); + } let export = self.reader.exporter.export(&mut self.rm); let timeout = self.runtime.delay(self.timeout);