Move Temporality enum opentelemetry_sdk::metrics::data:: to opentelemetry_sdk::metrics:: (#2289)

Co-authored-by: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com>
This commit is contained in:
Cijo Thomas 2024-11-08 13:49:26 -08:00 committed by GitHub
parent a707bb938b
commit 845cf21e51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 72 additions and 72 deletions

View File

@ -2,7 +2,7 @@ use opentelemetry::global;
use opentelemetry::Key; use opentelemetry::Key;
use opentelemetry::KeyValue; use opentelemetry::KeyValue;
use opentelemetry_sdk::metrics::{ use opentelemetry_sdk::metrics::{
data::Temporality, Aggregation, Instrument, PeriodicReader, SdkMeterProvider, Stream, Aggregation, Instrument, PeriodicReader, SdkMeterProvider, Stream, Temporality,
}; };
use opentelemetry_sdk::{runtime, Resource}; use opentelemetry_sdk::{runtime, Resource};
use std::error::Error; use std::error::Error;

View File

@ -8,7 +8,7 @@ use std::vec;
fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider { fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider {
let exporter = opentelemetry_stdout::MetricExporterBuilder::default() let exporter = opentelemetry_stdout::MetricExporterBuilder::default()
// Build exporter using Delta Temporality (Defaults to Temporality::Cumulative) // Build exporter using Delta Temporality (Defaults to Temporality::Cumulative)
// .with_temporality(data::Temporality::Delta) // .with_temporality(opentelemetry_sdk::metrics::Temporality::Delta)
.build(); .build();
let reader = PeriodicReader::builder(exporter, runtime::Tokio).build(); let reader = PeriodicReader::builder(exporter, runtime::Tokio).build();
let provider = SdkMeterProvider::builder() let provider = SdkMeterProvider::builder()

View File

@ -10,7 +10,7 @@
``` ```
Updated Signature: Updated Signature:
```rust ```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**: - ([#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()`. - The `opentelemetry_otlp::new_pipeline().{trace,logging,metrics}()` interface is now replaced with `{TracerProvider,SdkMeterProvider,LoggerProvider}::builder()`.

View File

@ -99,7 +99,7 @@ impl Default for HttpConfig {
/// ///
/// ``` /// ```
/// # #[cfg(feature="metrics")] /// # #[cfg(feature="metrics")]
/// use opentelemetry_sdk::metrics::data::Temporality; /// use opentelemetry_sdk::metrics::Temporality;
/// ///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> { /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// // Create a span exporter you can use to when configuring tracer providers /// // Create a span exporter you can use to when configuring tracer providers
@ -243,7 +243,7 @@ impl HttpExporterBuilder {
#[cfg(feature = "metrics")] #[cfg(feature = "metrics")]
pub fn build_metrics_exporter( pub fn build_metrics_exporter(
mut self, mut self,
temporality: opentelemetry_sdk::metrics::data::Temporality, temporality: opentelemetry_sdk::metrics::Temporality,
) -> opentelemetry_sdk::metrics::MetricResult<crate::MetricExporter> { ) -> opentelemetry_sdk::metrics::MetricResult<crate::MetricExporter> {
use crate::{ use crate::{
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_HEADERS, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_HEADERS,

View File

@ -81,7 +81,7 @@ impl TryFrom<Compression> for tonic::codec::CompressionEncoding {
/// ///
/// ```no_run /// ```no_run
/// # #[cfg(feature="metrics")] /// # #[cfg(feature="metrics")]
/// use opentelemetry_sdk::metrics::data::Temporality; /// use opentelemetry_sdk::metrics::Temporality;
/// ///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> { /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// // Create a span exporter you can use to when configuring tracer providers /// // Create a span exporter you can use to when configuring tracer providers
@ -273,7 +273,7 @@ impl TonicExporterBuilder {
#[cfg(feature = "metrics")] #[cfg(feature = "metrics")]
pub(crate) fn build_metrics_exporter( pub(crate) fn build_metrics_exporter(
self, self,
temporality: opentelemetry_sdk::metrics::data::Temporality, temporality: opentelemetry_sdk::metrics::Temporality,
) -> opentelemetry_sdk::metrics::MetricResult<crate::MetricExporter> { ) -> opentelemetry_sdk::metrics::MetricResult<crate::MetricExporter> {
use crate::MetricExporter; use crate::MetricExporter;
use metrics::TonicMetricsClient; use metrics::TonicMetricsClient;

View File

@ -132,7 +132,7 @@
//! use opentelemetry::{global, KeyValue, trace::Tracer}; //! use opentelemetry::{global, KeyValue, trace::Tracer};
//! use opentelemetry_sdk::{trace::{self, RandomIdGenerator, Sampler}, Resource}; //! use opentelemetry_sdk::{trace::{self, RandomIdGenerator, Sampler}, Resource};
//! # #[cfg(feature = "metrics")] //! # #[cfg(feature = "metrics")]
//! use opentelemetry_sdk::metrics::data::Temporality; //! use opentelemetry_sdk::metrics::Temporality;
//! use opentelemetry_otlp::{Protocol, WithExportConfig, WithTonicConfig}; //! use opentelemetry_otlp::{Protocol, WithExportConfig, WithTonicConfig};
//! use std::time::Duration; //! use std::time::Duration;
//! # #[cfg(feature = "grpc-tonic")] //! # #[cfg(feature = "grpc-tonic")]

View File

@ -19,8 +19,7 @@ use core::fmt;
use opentelemetry_sdk::metrics::MetricResult; use opentelemetry_sdk::metrics::MetricResult;
use opentelemetry_sdk::metrics::{ use opentelemetry_sdk::metrics::{
data::{ResourceMetrics, Temporality}, data::ResourceMetrics, exporter::PushMetricExporter, Temporality,
exporter::PushMetricExporter,
}; };
use std::fmt::{Debug, Formatter}; use std::fmt::{Debug, Formatter};

View File

@ -12,8 +12,9 @@ pub mod tonic {
use opentelemetry_sdk::metrics::data::{ use opentelemetry_sdk::metrics::data::{
self, Exemplar as SdkExemplar, ExponentialHistogram as SdkExponentialHistogram, self, Exemplar as SdkExemplar, ExponentialHistogram as SdkExponentialHistogram,
Gauge as SdkGauge, Histogram as SdkHistogram, Metric as SdkMetric, 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 opentelemetry_sdk::Resource as SdkResource;
use crate::proto::tonic::{ use crate::proto::tonic::{

View File

@ -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. - 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. - 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 ## v0.26.0
Released 2024-Sep-30 Released 2024-Sep-30

View File

@ -8,11 +8,9 @@ use opentelemetry::{
}; };
use opentelemetry_sdk::{ use opentelemetry_sdk::{
metrics::{ metrics::{
data::{ResourceMetrics, Temporality}, data::ResourceMetrics, new_view, reader::MetricReader, Aggregation, Instrument,
new_view, InstrumentKind, ManualReader, MetricResult, Pipeline, SdkMeterProvider, Stream,
reader::MetricReader, Temporality, View,
Aggregation, Instrument, InstrumentKind, ManualReader, MetricResult, Pipeline,
SdkMeterProvider, Stream, View,
}, },
Resource, Resource,
}; };

View File

@ -6,9 +6,7 @@ use opentelemetry::{InstrumentationScope, KeyValue};
use crate::Resource; use crate::Resource;
pub use self::temporality::Temporality; use super::Temporality;
mod temporality;
/// A collection of [ScopeMetrics] and the associated [Resource] that created them. /// A collection of [ScopeMetrics] and the associated [Resource] that created them.
#[derive(Debug)] #[derive(Debug)]

View File

@ -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,
}

View File

@ -5,7 +5,7 @@ use crate::metrics::MetricResult;
use crate::metrics::data::ResourceMetrics; use crate::metrics::data::ResourceMetrics;
use super::data::Temporality; use super::Temporality;
/// Exporter handles the delivery of metric data to external receivers. /// Exporter handles the delivery of metric data to external receivers.
/// ///

View File

@ -7,7 +7,7 @@ use opentelemetry::{
use crate::metrics::{aggregation::Aggregation, internal::Measure}; 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. /// The identifier of a group of instruments that all perform the same function.
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]

View File

@ -2,7 +2,10 @@ use std::{marker, sync::Arc};
use opentelemetry::KeyValue; use opentelemetry::KeyValue;
use crate::metrics::data::{Aggregation, Gauge, Temporality}; use crate::metrics::{
data::{Aggregation, Gauge},
Temporality,
};
use super::{ use super::{
exponential_histogram::ExpoHistogram, histogram::Histogram, last_value::LastValue, exponential_histogram::ExpoHistogram, histogram::Histogram, last_value::LastValue,

View File

@ -3,9 +3,9 @@ use std::{collections::HashMap, f64::consts::LOG2_E, sync::Mutex, time::SystemTi
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use opentelemetry::{otel_debug, KeyValue}; use opentelemetry::{otel_debug, KeyValue};
use crate::{ use crate::metrics::{
metrics::data::{self, Aggregation, Temporality}, data::{self, Aggregation},
metrics::AttributeSet, AttributeSet, Temporality,
}; };
use super::Number; use super::Number;

View File

@ -3,7 +3,8 @@ use std::ops::DerefMut;
use std::{sync::Mutex, time::SystemTime}; use std::{sync::Mutex, time::SystemTime};
use crate::metrics::data::HistogramDataPoint; 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 opentelemetry::KeyValue;
use super::ValueMap; use super::ValueMap;

View File

@ -1,6 +1,7 @@
use opentelemetry::KeyValue; 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 super::{last_value::Assign, AtomicTracker, Number, ValueMap};
use std::{collections::HashMap, mem::replace, ops::DerefMut, sync::Mutex, time::SystemTime}; use std::{collections::HashMap, mem::replace, ops::DerefMut, sync::Mutex, time::SystemTime};

View File

@ -3,7 +3,8 @@ use std::ops::DerefMut;
use std::vec; use std::vec;
use std::{sync::Mutex, time::SystemTime}; 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 opentelemetry::KeyValue;
use super::{Aggregator, AtomicTracker, Number}; use super::{Aggregator, AtomicTracker, Number};

View File

@ -5,10 +5,10 @@ use std::{
use opentelemetry::otel_debug; use opentelemetry::otel_debug;
use crate::metrics::{MetricError, MetricResult}; use crate::metrics::{MetricError, MetricResult, Temporality};
use super::{ use super::{
data::{ResourceMetrics, Temporality}, data::ResourceMetrics,
pipeline::Pipeline, pipeline::Pipeline,
reader::{MetricReader, SdkProducer}, reader::{MetricReader, SdkProducer},
}; };

View File

@ -69,6 +69,29 @@ use std::hash::{Hash, Hasher};
use opentelemetry::{Key, KeyValue, Value}; 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. /// 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 /// This must implement [Hash], [PartialEq], and [Eq] so it may be used as
@ -132,7 +155,7 @@ impl Hash for AttributeSet {
mod tests { mod tests {
use self::data::{DataPoint, HistogramDataPoint, ScopeMetrics}; use self::data::{DataPoint, HistogramDataPoint, ScopeMetrics};
use super::*; use super::*;
use crate::metrics::data::{ResourceMetrics, Temporality}; use crate::metrics::data::ResourceMetrics;
use crate::testing::metrics::InMemoryMetricExporterBuilder; use crate::testing::metrics::InMemoryMetricExporterBuilder;
use crate::{runtime, testing::metrics::InMemoryMetricExporter}; use crate::{runtime, testing::metrics::InMemoryMetricExporter};
use opentelemetry::metrics::{Counter, Meter, UpDownCounter}; use opentelemetry::metrics::{Counter, Meter, UpDownCounter};

View File

@ -396,7 +396,7 @@ impl MetricReader for PeriodicReader {
/// If not configured, the Cumulative temporality SHOULD be used. /// 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 /// [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()) kind.temporality_preference(self.exporter.temporality())
} }
} }
@ -404,10 +404,11 @@ impl MetricReader for PeriodicReader {
#[cfg(all(test, feature = "testing"))] #[cfg(all(test, feature = "testing"))]
mod tests { mod tests {
use super::PeriodicReader; use super::PeriodicReader;
use crate::metrics::reader::MetricReader;
use crate::metrics::MetricError; use crate::metrics::MetricError;
use crate::{ use crate::{
metrics::data::ResourceMetrics, metrics::reader::MetricReader, metrics::SdkMeterProvider, metrics::data::ResourceMetrics, metrics::SdkMeterProvider, runtime,
runtime, testing::metrics::InMemoryMetricExporter, Resource, testing::metrics::InMemoryMetricExporter, Resource,
}; };
use opentelemetry::metrics::MeterProvider; use opentelemetry::metrics::MeterProvider;
use std::sync::mpsc; use std::sync::mpsc;

View File

@ -3,11 +3,7 @@ use std::{fmt, sync::Weak};
use crate::metrics::MetricResult; use crate::metrics::MetricResult;
use super::{ use super::{data::ResourceMetrics, pipeline::Pipeline, InstrumentKind, Temporality};
data::{ResourceMetrics, Temporality},
pipeline::Pipeline,
InstrumentKind,
};
/// The interface used between the SDK and an exporter. /// The interface used between the SDK and an exporter.
/// ///

View File

@ -1,8 +1,9 @@
use crate::metrics::data; 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::exporter::PushMetricExporter;
use crate::metrics::MetricError; use crate::metrics::MetricError;
use crate::metrics::MetricResult; use crate::metrics::MetricResult;
use crate::metrics::Temporality;
use async_trait::async_trait; use async_trait::async_trait;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::fmt; use std::fmt;

View File

@ -1,12 +1,9 @@
use std::sync::{Arc, Mutex, Weak}; use std::sync::{Arc, Mutex, Weak};
use crate::metrics::MetricResult;
use crate::metrics::{ use crate::metrics::{
data::{ResourceMetrics, Temporality}, data::ResourceMetrics, pipeline::Pipeline, reader::MetricReader, InstrumentKind,
pipeline::Pipeline,
reader::MetricReader,
InstrumentKind,
}; };
use crate::metrics::{MetricResult, Temporality};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct TestMetricReader { pub struct TestMetricReader {

View File

@ -12,7 +12,7 @@
``` ```
Updated Signature: Updated Signature:
```rust ```rust
MetricsExporterBuilder::default().with_temporality(Temporality::Delta) MetricsExporterBuilder::default().with_temporality(opentelemetry_sdk::metrics::Temporality::Delta)
``` ```
- **Renamed** - **Renamed**
- ([#2255](https://github.com/open-telemetry/opentelemetry-rust/pull/2255)): de-pluralize Metric types. - ([#2255](https://github.com/open-telemetry/opentelemetry-rust/pull/2255)): de-pluralize Metric types.

View File

@ -2,10 +2,10 @@ use async_trait::async_trait;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use core::{f64, fmt}; use core::{f64, fmt};
use opentelemetry_sdk::metrics::{ use opentelemetry_sdk::metrics::{
data::{self, ScopeMetrics, Temporality}, data::{self, ScopeMetrics},
exporter::PushMetricExporter, exporter::PushMetricExporter,
}; };
use opentelemetry_sdk::metrics::{MetricError, MetricResult}; use opentelemetry_sdk::metrics::{MetricError, MetricResult, Temporality};
use std::fmt::Debug; use std::fmt::Debug;
use std::sync::atomic; use std::sync::atomic;
@ -137,7 +137,7 @@ fn print_metrics(metrics: &[ScopeMetrics]) {
fn print_sum<T: Debug>(sum: &data::Sum<T>) { fn print_sum<T: Debug>(sum: &data::Sum<T>) {
println!("\t\tSum DataPoints"); println!("\t\tSum DataPoints");
println!("\t\tMonotonic : {}", sum.is_monotonic); println!("\t\tMonotonic : {}", sum.is_monotonic);
if sum.temporality == data::Temporality::Cumulative { if sum.temporality == Temporality::Cumulative {
println!("\t\tTemporality : Cumulative"); println!("\t\tTemporality : Cumulative");
} else { } else {
println!("\t\tTemporality : Delta"); println!("\t\tTemporality : Delta");
@ -151,7 +151,7 @@ fn print_gauge<T: Debug>(gauge: &data::Gauge<T>) {
} }
fn print_histogram<T: Debug>(histogram: &data::Histogram<T>) { fn print_histogram<T: Debug>(histogram: &data::Histogram<T>) {
if histogram.temporality == data::Temporality::Cumulative { if histogram.temporality == Temporality::Cumulative {
println!("\t\tTemporality : Cumulative"); println!("\t\tTemporality : Cumulative");
} else { } else {
println!("\t\tTemporality : Delta"); println!("\t\tTemporality : Delta");