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:
parent
a707bb938b
commit
845cf21e51
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()`.
|
||||
|
|
|
@ -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<dyn std::error::Error>> {
|
||||
/// // 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<crate::MetricExporter> {
|
||||
use crate::{
|
||||
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_HEADERS,
|
||||
|
|
|
@ -81,7 +81,7 @@ impl TryFrom<Compression> for tonic::codec::CompressionEncoding {
|
|||
///
|
||||
/// ```no_run
|
||||
/// # #[cfg(feature="metrics")]
|
||||
/// use opentelemetry_sdk::metrics::data::Temporality;
|
||||
/// use opentelemetry_sdk::metrics::Temporality;
|
||||
///
|
||||
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// // 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<crate::MetricExporter> {
|
||||
use crate::MetricExporter;
|
||||
use metrics::TonicMetricsClient;
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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::{
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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,
|
||||
}
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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},
|
||||
};
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<T: Debug>(sum: &data::Sum<T>) {
|
||||
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<T: Debug>(gauge: &data::Gauge<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");
|
||||
} else {
|
||||
println!("\t\tTemporality : Delta");
|
||||
|
|
Loading…
Reference in New Issue