diff --git a/opentelemetry-otlp/src/metric.rs b/opentelemetry-otlp/src/metric.rs index c8bdb38d9e..207e822d10 100644 --- a/opentelemetry-otlp/src/metric.rs +++ b/opentelemetry-otlp/src/metric.rs @@ -144,11 +144,6 @@ impl PushMetricExporter for MetricExporter { self.client.export(metrics).await } - async fn force_flush(&self) -> MetricResult<()> { - // this component is stateless - Ok(()) - } - fn shutdown(&self) -> MetricResult<()> { self.client.shutdown() } diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index 937e3b0c6b..191a6ef8f1 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -211,6 +211,15 @@ metadata, a feature introduced in version 0.1.40. [#2418](https://github.com/ope - Continue enabling one of the async runtime feature flags: `rt-tokio`, `rt-tokio-current-thread`, or `rt-async-std`. +`PushMetricExporter` now provides default implementation for the following methods. +Custom exporter authors may rely on the defaults, if applicable. + * `force_flush()` +default implementation returns Ok(()) Result. + * `shutdown()` default +implementation returns Ok(()) Result. + * `temporality()` default implementation +returns `Temporality::Cumulative`. + ## 0.27.1 Released 2024-Nov-27 diff --git a/opentelemetry-sdk/src/metrics/exporter.rs b/opentelemetry-sdk/src/metrics/exporter.rs index 33c1fcb6be..dd9136eb82 100644 --- a/opentelemetry-sdk/src/metrics/exporter.rs +++ b/opentelemetry-sdk/src/metrics/exporter.rs @@ -21,14 +21,20 @@ pub trait PushMetricExporter: Send + Sync + 'static { async fn export(&self, metrics: &mut ResourceMetrics) -> MetricResult<()>; /// Flushes any metric data held by an exporter. - async fn force_flush(&self) -> MetricResult<()>; + async fn force_flush(&self) -> MetricResult<()> { + Ok(()) + } /// Releases any held computational resources. /// /// After Shutdown is called, calls to Export will perform no operation and /// instead will return an error indicating the shutdown state. - fn shutdown(&self) -> MetricResult<()>; + fn shutdown(&self) -> MetricResult<()> { + Ok(()) + } /// Access the [Temporality] of the MetricExporter. - fn temporality(&self) -> Temporality; + fn temporality(&self) -> Temporality { + Temporality::Cumulative + } } diff --git a/opentelemetry-sdk/src/metrics/periodic_reader.rs b/opentelemetry-sdk/src/metrics/periodic_reader.rs index 2cee6c4d0d..efe51731e2 100644 --- a/opentelemetry-sdk/src/metrics/periodic_reader.rs +++ b/opentelemetry-sdk/src/metrics/periodic_reader.rs @@ -472,7 +472,7 @@ mod tests { use crate::{ metrics::{ data::ResourceMetrics, exporter::PushMetricExporter, reader::MetricReader, MetricError, - MetricResult, SdkMeterProvider, Temporality, + MetricResult, SdkMeterProvider, }, testing::metrics::InMemoryMetricExporter, Resource, @@ -518,18 +518,6 @@ mod tests { Ok(()) } } - - async fn force_flush(&self) -> MetricResult<()> { - Ok(()) - } - - fn shutdown(&self) -> MetricResult<()> { - Ok(()) - } - - fn temporality(&self) -> Temporality { - Temporality::Cumulative - } } #[derive(Debug, Clone, Default)] @@ -543,18 +531,10 @@ mod tests { Ok(()) } - async fn force_flush(&self) -> MetricResult<()> { - Ok(()) - } - fn shutdown(&self) -> MetricResult<()> { self.is_shutdown.store(true, Ordering::Relaxed); Ok(()) } - - fn temporality(&self) -> Temporality { - Temporality::Cumulative - } } #[test] diff --git a/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs b/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs index 1d6f9c2754..170a2c4c93 100644 --- a/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs +++ b/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs @@ -273,14 +273,6 @@ impl PushMetricExporter for InMemoryMetricExporter { .map_err(MetricError::from) } - async fn force_flush(&self) -> MetricResult<()> { - Ok(()) // In this implementation, flush does nothing - } - - fn shutdown(&self) -> MetricResult<()> { - Ok(()) - } - fn temporality(&self) -> Temporality { self.temporality } diff --git a/opentelemetry-stdout/src/metrics/exporter.rs b/opentelemetry-stdout/src/metrics/exporter.rs index 54feb33c41..d939a35bc9 100644 --- a/opentelemetry-stdout/src/metrics/exporter.rs +++ b/opentelemetry-stdout/src/metrics/exporter.rs @@ -54,11 +54,6 @@ impl PushMetricExporter for MetricExporter { } } - async fn force_flush(&self) -> MetricResult<()> { - // exporter holds no state, nothing to flush - Ok(()) - } - fn shutdown(&self) -> MetricResult<()> { self.is_shutdown.store(true, atomic::Ordering::SeqCst); Ok(())