diff --git a/examples/metrics-advanced/src/main.rs b/examples/metrics-advanced/src/main.rs index 9c5ab6f284..ed1572ade6 100644 --- a/examples/metrics-advanced/src/main.rs +++ b/examples/metrics-advanced/src/main.rs @@ -2,7 +2,7 @@ use opentelemetry::global; use opentelemetry::Key; use opentelemetry::KeyValue; use opentelemetry_sdk::metrics::{ - data::Temporality, Aggregation, Instrument, PeriodicReader, SdkMeterProvider, Stream, + Aggregation, Instrument, PeriodicReader, SdkMeterProvider, Stream, Temporality, }; use opentelemetry_sdk::{runtime, Resource}; use std::error::Error; diff --git a/examples/metrics-basic/src/main.rs b/examples/metrics-basic/src/main.rs index 8f8e81fca4..cf854fa05f 100644 --- a/examples/metrics-basic/src/main.rs +++ b/examples/metrics-basic/src/main.rs @@ -8,7 +8,7 @@ use std::vec; fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider { let exporter = opentelemetry_stdout::MetricExporterBuilder::default() // Build exporter using Delta Temporality (Defaults to Temporality::Cumulative) - // .with_temporality(data::Temporality::Delta) + // .with_temporality(opentelemetry_sdk::metrics::Temporality::Delta) .build(); let reader = PeriodicReader::builder(exporter, runtime::Tokio).build(); let provider = SdkMeterProvider::builder() diff --git a/opentelemetry-otlp/CHANGELOG.md b/opentelemetry-otlp/CHANGELOG.md index a02bc05504..ce9b545568 100644 --- a/opentelemetry-otlp/CHANGELOG.md +++ b/opentelemetry-otlp/CHANGELOG.md @@ -10,7 +10,7 @@ ``` Updated Signature: ```rust - MetricsExporterBuilder::default().with_temporality(Temporality::Delta) + MetricsExporterBuilder::default().with_temporality(opentelemetry_sdk::metrics::Temporality::Delta) ``` - ([#2221](https://github.com/open-telemetry/opentelemetry-rust/pull/2221)) **Replaced**: - The `opentelemetry_otlp::new_pipeline().{trace,logging,metrics}()` interface is now replaced with `{TracerProvider,SdkMeterProvider,LoggerProvider}::builder()`. diff --git a/opentelemetry-otlp/src/exporter/http/mod.rs b/opentelemetry-otlp/src/exporter/http/mod.rs index 1b18686a3e..da6c280a61 100644 --- a/opentelemetry-otlp/src/exporter/http/mod.rs +++ b/opentelemetry-otlp/src/exporter/http/mod.rs @@ -99,7 +99,7 @@ impl Default for HttpConfig { /// /// ``` /// # #[cfg(feature="metrics")] -/// use opentelemetry_sdk::metrics::data::Temporality; +/// use opentelemetry_sdk::metrics::Temporality; /// /// # fn main() -> Result<(), Box> { /// // Create a span exporter you can use to when configuring tracer providers @@ -243,7 +243,7 @@ impl HttpExporterBuilder { #[cfg(feature = "metrics")] pub fn build_metrics_exporter( mut self, - temporality: opentelemetry_sdk::metrics::data::Temporality, + temporality: opentelemetry_sdk::metrics::Temporality, ) -> opentelemetry_sdk::metrics::MetricResult { use crate::{ OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_HEADERS, diff --git a/opentelemetry-otlp/src/exporter/tonic/mod.rs b/opentelemetry-otlp/src/exporter/tonic/mod.rs index e55d13f526..f041eeee2d 100644 --- a/opentelemetry-otlp/src/exporter/tonic/mod.rs +++ b/opentelemetry-otlp/src/exporter/tonic/mod.rs @@ -81,7 +81,7 @@ impl TryFrom for tonic::codec::CompressionEncoding { /// /// ```no_run /// # #[cfg(feature="metrics")] -/// use opentelemetry_sdk::metrics::data::Temporality; +/// use opentelemetry_sdk::metrics::Temporality; /// /// # fn main() -> Result<(), Box> { /// // Create a span exporter you can use to when configuring tracer providers @@ -273,7 +273,7 @@ impl TonicExporterBuilder { #[cfg(feature = "metrics")] pub(crate) fn build_metrics_exporter( self, - temporality: opentelemetry_sdk::metrics::data::Temporality, + temporality: opentelemetry_sdk::metrics::Temporality, ) -> opentelemetry_sdk::metrics::MetricResult { use crate::MetricExporter; use metrics::TonicMetricsClient; diff --git a/opentelemetry-otlp/src/lib.rs b/opentelemetry-otlp/src/lib.rs index c8d7c0308a..42201f2672 100644 --- a/opentelemetry-otlp/src/lib.rs +++ b/opentelemetry-otlp/src/lib.rs @@ -132,7 +132,7 @@ //! use opentelemetry::{global, KeyValue, trace::Tracer}; //! use opentelemetry_sdk::{trace::{self, RandomIdGenerator, Sampler}, Resource}; //! # #[cfg(feature = "metrics")] -//! use opentelemetry_sdk::metrics::data::Temporality; +//! use opentelemetry_sdk::metrics::Temporality; //! use opentelemetry_otlp::{Protocol, WithExportConfig, WithTonicConfig}; //! use std::time::Duration; //! # #[cfg(feature = "grpc-tonic")] diff --git a/opentelemetry-otlp/src/metric.rs b/opentelemetry-otlp/src/metric.rs index 3d5f9b981f..d2ba22e4c0 100644 --- a/opentelemetry-otlp/src/metric.rs +++ b/opentelemetry-otlp/src/metric.rs @@ -19,8 +19,7 @@ use core::fmt; use opentelemetry_sdk::metrics::MetricResult; use opentelemetry_sdk::metrics::{ - data::{ResourceMetrics, Temporality}, - exporter::PushMetricExporter, + data::ResourceMetrics, exporter::PushMetricExporter, Temporality, }; use std::fmt::{Debug, Formatter}; diff --git a/opentelemetry-proto/src/transform/metrics.rs b/opentelemetry-proto/src/transform/metrics.rs index 2e9b2c1402..fdc5ef80de 100644 --- a/opentelemetry-proto/src/transform/metrics.rs +++ b/opentelemetry-proto/src/transform/metrics.rs @@ -12,8 +12,9 @@ pub mod tonic { use opentelemetry_sdk::metrics::data::{ self, Exemplar as SdkExemplar, ExponentialHistogram as SdkExponentialHistogram, Gauge as SdkGauge, Histogram as SdkHistogram, Metric as SdkMetric, - ScopeMetrics as SdkScopeMetrics, Sum as SdkSum, Temporality, + ScopeMetrics as SdkScopeMetrics, Sum as SdkSum, }; + use opentelemetry_sdk::metrics::Temporality; use opentelemetry_sdk::Resource as SdkResource; use crate::proto::tonic::{ diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index af0e6e64cb..9960421fca 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -46,6 +46,8 @@ - Users calling public APIs that return these constructs (e.g, LoggerProvider::shutdown(), MeterProvider::force_flush()) should now import them from the SDK instead of the API. - Developers creating custom exporters should ensure they import these constructs from the SDK, not the API. +- **BREAKING**: `Temporality` enum moved from `opentelemetry_sdk::metrics::data::Temporality` to `opentelemetry_sdk::metrics::Temporality`. + ## v0.26.0 Released 2024-Sep-30 diff --git a/opentelemetry-sdk/benches/metric.rs b/opentelemetry-sdk/benches/metric.rs index 941bcdda14..e53a035a4d 100644 --- a/opentelemetry-sdk/benches/metric.rs +++ b/opentelemetry-sdk/benches/metric.rs @@ -8,11 +8,9 @@ use opentelemetry::{ }; use opentelemetry_sdk::{ metrics::{ - data::{ResourceMetrics, Temporality}, - new_view, - reader::MetricReader, - Aggregation, Instrument, InstrumentKind, ManualReader, MetricResult, Pipeline, - SdkMeterProvider, Stream, View, + data::ResourceMetrics, new_view, reader::MetricReader, Aggregation, Instrument, + InstrumentKind, ManualReader, MetricResult, Pipeline, SdkMeterProvider, Stream, + Temporality, View, }, Resource, }; diff --git a/opentelemetry-sdk/src/metrics/data/mod.rs b/opentelemetry-sdk/src/metrics/data/mod.rs index 83b8ed5e97..4df366b868 100644 --- a/opentelemetry-sdk/src/metrics/data/mod.rs +++ b/opentelemetry-sdk/src/metrics/data/mod.rs @@ -6,9 +6,7 @@ use opentelemetry::{InstrumentationScope, KeyValue}; use crate::Resource; -pub use self::temporality::Temporality; - -mod temporality; +use super::Temporality; /// A collection of [ScopeMetrics] and the associated [Resource] that created them. #[derive(Debug)] diff --git a/opentelemetry-sdk/src/metrics/data/temporality.rs b/opentelemetry-sdk/src/metrics/data/temporality.rs deleted file mode 100644 index ba44d34a8e..0000000000 --- a/opentelemetry-sdk/src/metrics/data/temporality.rs +++ /dev/null @@ -1,22 +0,0 @@ -/// Defines the window that an aggregation was calculated over. -#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, Hash)] -#[non_exhaustive] -pub enum Temporality { - /// A measurement interval that continues to expand forward in time from a - /// starting point. - /// - /// New measurements are added to all previous measurements since a start time. - #[default] - Cumulative, - - /// A measurement interval that resets each cycle. - /// - /// Measurements from one cycle are recorded independently, measurements from - /// other cycles do not affect them. - Delta, - - /// Configures Synchronous Counter and Histogram instruments to use - /// Delta aggregation temporality, which allows them to shed memory - /// following a cardinality explosion, thus use less memory. - LowMemory, -} diff --git a/opentelemetry-sdk/src/metrics/exporter.rs b/opentelemetry-sdk/src/metrics/exporter.rs index a4e192c414..33c1fcb6be 100644 --- a/opentelemetry-sdk/src/metrics/exporter.rs +++ b/opentelemetry-sdk/src/metrics/exporter.rs @@ -5,7 +5,7 @@ use crate::metrics::MetricResult; use crate::metrics::data::ResourceMetrics; -use super::data::Temporality; +use super::Temporality; /// Exporter handles the delivery of metric data to external receivers. /// diff --git a/opentelemetry-sdk/src/metrics/instrument.rs b/opentelemetry-sdk/src/metrics/instrument.rs index f73246a2ce..e5373e8023 100644 --- a/opentelemetry-sdk/src/metrics/instrument.rs +++ b/opentelemetry-sdk/src/metrics/instrument.rs @@ -7,7 +7,7 @@ use opentelemetry::{ use crate::metrics::{aggregation::Aggregation, internal::Measure}; -use super::data::Temporality; +use super::Temporality; /// The identifier of a group of instruments that all perform the same function. #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] diff --git a/opentelemetry-sdk/src/metrics/internal/aggregate.rs b/opentelemetry-sdk/src/metrics/internal/aggregate.rs index e004240c60..9bc95b43b5 100644 --- a/opentelemetry-sdk/src/metrics/internal/aggregate.rs +++ b/opentelemetry-sdk/src/metrics/internal/aggregate.rs @@ -2,7 +2,10 @@ use std::{marker, sync::Arc}; use opentelemetry::KeyValue; -use crate::metrics::data::{Aggregation, Gauge, Temporality}; +use crate::metrics::{ + data::{Aggregation, Gauge}, + Temporality, +}; use super::{ exponential_histogram::ExpoHistogram, histogram::Histogram, last_value::LastValue, diff --git a/opentelemetry-sdk/src/metrics/internal/exponential_histogram.rs b/opentelemetry-sdk/src/metrics/internal/exponential_histogram.rs index 13f4200112..7efc6c77c3 100644 --- a/opentelemetry-sdk/src/metrics/internal/exponential_histogram.rs +++ b/opentelemetry-sdk/src/metrics/internal/exponential_histogram.rs @@ -3,9 +3,9 @@ use std::{collections::HashMap, f64::consts::LOG2_E, sync::Mutex, time::SystemTi use once_cell::sync::Lazy; use opentelemetry::{otel_debug, KeyValue}; -use crate::{ - metrics::data::{self, Aggregation, Temporality}, - metrics::AttributeSet, +use crate::metrics::{ + data::{self, Aggregation}, + AttributeSet, Temporality, }; use super::Number; diff --git a/opentelemetry-sdk/src/metrics/internal/histogram.rs b/opentelemetry-sdk/src/metrics/internal/histogram.rs index 05a6e07e23..f4690850a3 100644 --- a/opentelemetry-sdk/src/metrics/internal/histogram.rs +++ b/opentelemetry-sdk/src/metrics/internal/histogram.rs @@ -3,7 +3,8 @@ use std::ops::DerefMut; use std::{sync::Mutex, time::SystemTime}; use crate::metrics::data::HistogramDataPoint; -use crate::metrics::data::{self, Aggregation, Temporality}; +use crate::metrics::data::{self, Aggregation}; +use crate::metrics::Temporality; use opentelemetry::KeyValue; use super::ValueMap; diff --git a/opentelemetry-sdk/src/metrics/internal/precomputed_sum.rs b/opentelemetry-sdk/src/metrics/internal/precomputed_sum.rs index 7bd843f4cd..21fd208a8b 100644 --- a/opentelemetry-sdk/src/metrics/internal/precomputed_sum.rs +++ b/opentelemetry-sdk/src/metrics/internal/precomputed_sum.rs @@ -1,6 +1,7 @@ use opentelemetry::KeyValue; -use crate::metrics::data::{self, Aggregation, DataPoint, Temporality}; +use crate::metrics::data::{self, Aggregation, DataPoint}; +use crate::metrics::Temporality; use super::{last_value::Assign, AtomicTracker, Number, ValueMap}; use std::{collections::HashMap, mem::replace, ops::DerefMut, sync::Mutex, time::SystemTime}; diff --git a/opentelemetry-sdk/src/metrics/internal/sum.rs b/opentelemetry-sdk/src/metrics/internal/sum.rs index 40b95a5e60..148fcbd042 100644 --- a/opentelemetry-sdk/src/metrics/internal/sum.rs +++ b/opentelemetry-sdk/src/metrics/internal/sum.rs @@ -3,7 +3,8 @@ use std::ops::DerefMut; use std::vec; use std::{sync::Mutex, time::SystemTime}; -use crate::metrics::data::{self, Aggregation, DataPoint, Temporality}; +use crate::metrics::data::{self, Aggregation, DataPoint}; +use crate::metrics::Temporality; use opentelemetry::KeyValue; use super::{Aggregator, AtomicTracker, Number}; diff --git a/opentelemetry-sdk/src/metrics/manual_reader.rs b/opentelemetry-sdk/src/metrics/manual_reader.rs index 21bd2a3976..639469a5a1 100644 --- a/opentelemetry-sdk/src/metrics/manual_reader.rs +++ b/opentelemetry-sdk/src/metrics/manual_reader.rs @@ -5,10 +5,10 @@ use std::{ use opentelemetry::otel_debug; -use crate::metrics::{MetricError, MetricResult}; +use crate::metrics::{MetricError, MetricResult, Temporality}; use super::{ - data::{ResourceMetrics, Temporality}, + data::ResourceMetrics, pipeline::Pipeline, reader::{MetricReader, SdkProducer}, }; diff --git a/opentelemetry-sdk/src/metrics/mod.rs b/opentelemetry-sdk/src/metrics/mod.rs index f8c440050d..2d4d3f0437 100644 --- a/opentelemetry-sdk/src/metrics/mod.rs +++ b/opentelemetry-sdk/src/metrics/mod.rs @@ -69,6 +69,29 @@ use std::hash::{Hash, Hasher}; use opentelemetry::{Key, KeyValue, Value}; +/// Defines the window that an aggregation was calculated over. +#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum Temporality { + /// A measurement interval that continues to expand forward in time from a + /// starting point. + /// + /// New measurements are added to all previous measurements since a start time. + #[default] + Cumulative, + + /// A measurement interval that resets each cycle. + /// + /// Measurements from one cycle are recorded independently, measurements from + /// other cycles do not affect them. + Delta, + + /// Configures Synchronous Counter and Histogram instruments to use + /// Delta aggregation temporality, which allows them to shed memory + /// following a cardinality explosion, thus use less memory. + LowMemory, +} + /// A unique set of attributes that can be used as instrument identifiers. /// /// This must implement [Hash], [PartialEq], and [Eq] so it may be used as @@ -132,7 +155,7 @@ impl Hash for AttributeSet { mod tests { use self::data::{DataPoint, HistogramDataPoint, ScopeMetrics}; use super::*; - use crate::metrics::data::{ResourceMetrics, Temporality}; + use crate::metrics::data::ResourceMetrics; use crate::testing::metrics::InMemoryMetricExporterBuilder; use crate::{runtime, testing::metrics::InMemoryMetricExporter}; use opentelemetry::metrics::{Counter, Meter, UpDownCounter}; diff --git a/opentelemetry-sdk/src/metrics/periodic_reader.rs b/opentelemetry-sdk/src/metrics/periodic_reader.rs index 6484d25126..7a00e3978a 100644 --- a/opentelemetry-sdk/src/metrics/periodic_reader.rs +++ b/opentelemetry-sdk/src/metrics/periodic_reader.rs @@ -396,7 +396,7 @@ impl MetricReader for PeriodicReader { /// If not configured, the Cumulative temporality SHOULD be used. /// /// [metric-reader]: https://github.com/open-telemetry/opentelemetry-specification/blob/0a78571045ca1dca48621c9648ec3c832c3c541c/specification/metrics/sdk.md#metricreader - fn temporality(&self, kind: InstrumentKind) -> super::data::Temporality { + fn temporality(&self, kind: InstrumentKind) -> super::Temporality { kind.temporality_preference(self.exporter.temporality()) } } @@ -404,10 +404,11 @@ impl MetricReader for PeriodicReader { #[cfg(all(test, feature = "testing"))] mod tests { use super::PeriodicReader; + use crate::metrics::reader::MetricReader; use crate::metrics::MetricError; use crate::{ - metrics::data::ResourceMetrics, metrics::reader::MetricReader, metrics::SdkMeterProvider, - runtime, testing::metrics::InMemoryMetricExporter, Resource, + metrics::data::ResourceMetrics, metrics::SdkMeterProvider, runtime, + testing::metrics::InMemoryMetricExporter, Resource, }; use opentelemetry::metrics::MeterProvider; use std::sync::mpsc; diff --git a/opentelemetry-sdk/src/metrics/reader.rs b/opentelemetry-sdk/src/metrics/reader.rs index b700c13230..8016a0dab4 100644 --- a/opentelemetry-sdk/src/metrics/reader.rs +++ b/opentelemetry-sdk/src/metrics/reader.rs @@ -3,11 +3,7 @@ use std::{fmt, sync::Weak}; use crate::metrics::MetricResult; -use super::{ - data::{ResourceMetrics, Temporality}, - pipeline::Pipeline, - InstrumentKind, -}; +use super::{data::ResourceMetrics, pipeline::Pipeline, InstrumentKind, Temporality}; /// The interface used between the SDK and an exporter. /// diff --git a/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs b/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs index 223c84fe70..8f7ab21830 100644 --- a/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs +++ b/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs @@ -1,8 +1,9 @@ use crate::metrics::data; -use crate::metrics::data::{Histogram, Metric, ResourceMetrics, ScopeMetrics, Temporality}; +use crate::metrics::data::{Histogram, Metric, ResourceMetrics, ScopeMetrics}; use crate::metrics::exporter::PushMetricExporter; use crate::metrics::MetricError; use crate::metrics::MetricResult; +use crate::metrics::Temporality; use async_trait::async_trait; use std::collections::VecDeque; use std::fmt; diff --git a/opentelemetry-sdk/src/testing/metrics/metric_reader.rs b/opentelemetry-sdk/src/testing/metrics/metric_reader.rs index 96c3c939ba..c535fb1c93 100644 --- a/opentelemetry-sdk/src/testing/metrics/metric_reader.rs +++ b/opentelemetry-sdk/src/testing/metrics/metric_reader.rs @@ -1,12 +1,9 @@ use std::sync::{Arc, Mutex, Weak}; -use crate::metrics::MetricResult; use crate::metrics::{ - data::{ResourceMetrics, Temporality}, - pipeline::Pipeline, - reader::MetricReader, - InstrumentKind, + data::ResourceMetrics, pipeline::Pipeline, reader::MetricReader, InstrumentKind, }; +use crate::metrics::{MetricResult, Temporality}; #[derive(Debug, Clone)] pub struct TestMetricReader { diff --git a/opentelemetry-stdout/CHANGELOG.md b/opentelemetry-stdout/CHANGELOG.md index 0305afac9b..25dae67b41 100644 --- a/opentelemetry-stdout/CHANGELOG.md +++ b/opentelemetry-stdout/CHANGELOG.md @@ -12,7 +12,7 @@ ``` Updated Signature: ```rust - MetricsExporterBuilder::default().with_temporality(Temporality::Delta) + MetricsExporterBuilder::default().with_temporality(opentelemetry_sdk::metrics::Temporality::Delta) ``` - **Renamed** - ([#2255](https://github.com/open-telemetry/opentelemetry-rust/pull/2255)): de-pluralize Metric types. diff --git a/opentelemetry-stdout/src/metrics/exporter.rs b/opentelemetry-stdout/src/metrics/exporter.rs index d9e191b8aa..8d688df404 100644 --- a/opentelemetry-stdout/src/metrics/exporter.rs +++ b/opentelemetry-stdout/src/metrics/exporter.rs @@ -2,10 +2,10 @@ use async_trait::async_trait; use chrono::{DateTime, Utc}; use core::{f64, fmt}; use opentelemetry_sdk::metrics::{ - data::{self, ScopeMetrics, Temporality}, + data::{self, ScopeMetrics}, exporter::PushMetricExporter, }; -use opentelemetry_sdk::metrics::{MetricError, MetricResult}; +use opentelemetry_sdk::metrics::{MetricError, MetricResult, Temporality}; use std::fmt::Debug; use std::sync::atomic; @@ -137,7 +137,7 @@ fn print_metrics(metrics: &[ScopeMetrics]) { fn print_sum(sum: &data::Sum) { println!("\t\tSum DataPoints"); println!("\t\tMonotonic : {}", sum.is_monotonic); - if sum.temporality == data::Temporality::Cumulative { + if sum.temporality == Temporality::Cumulative { println!("\t\tTemporality : Cumulative"); } else { println!("\t\tTemporality : Delta"); @@ -151,7 +151,7 @@ fn print_gauge(gauge: &data::Gauge) { } fn print_histogram(histogram: &data::Histogram) { - if histogram.temporality == data::Temporality::Cumulative { + if histogram.temporality == Temporality::Cumulative { println!("\t\tTemporality : Cumulative"); } else { println!("\t\tTemporality : Delta");