Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/metrics-advanced/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/metrics-basic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(Temporality::Delta)
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
.build();
let reader = PeriodicReader::builder(exporter, runtime::Tokio).build();
let provider = SdkMeterProvider::builder()
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-otlp/src/exporter/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
///
/// ```
/// # #[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
Expand Down Expand Up @@ -243,7 +243,7 @@
#[cfg(feature = "metrics")]
pub fn build_metrics_exporter(
mut self,
temporality: opentelemetry_sdk::metrics::data::Temporality,
temporality: opentelemetry_sdk::metrics::Temporality,

Check warning on line 246 in opentelemetry-otlp/src/exporter/http/mod.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/exporter/http/mod.rs#L246

Added line #L246 was not covered by tests
) -> opentelemetry_sdk::metrics::MetricResult<crate::MetricExporter> {
use crate::{
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_HEADERS,
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-otlp/src/exporter/tonic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
///
/// ```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
Expand Down Expand Up @@ -273,7 +273,7 @@
#[cfg(feature = "metrics")]
pub(crate) fn build_metrics_exporter(
self,
temporality: opentelemetry_sdk::metrics::data::Temporality,
temporality: opentelemetry_sdk::metrics::Temporality,

Check warning on line 276 in opentelemetry-otlp/src/exporter/tonic/mod.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/exporter/tonic/mod.rs#L276

Added line #L276 was not covered by tests
) -> opentelemetry_sdk::metrics::MetricResult<crate::MetricExporter> {
use crate::MetricExporter;
use metrics::TonicMetricsClient;
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
3 changes: 1 addition & 2 deletions opentelemetry-otlp/src/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
3 changes: 2 additions & 1 deletion opentelemetry-proto/src/transform/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 3 additions & 5 deletions opentelemetry-sdk/benches/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
4 changes: 1 addition & 3 deletions opentelemetry-sdk/src/metrics/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
22 changes: 0 additions & 22 deletions opentelemetry-sdk/src/metrics/data/temporality.rs

This file was deleted.

2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/metrics/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/metrics/instrument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 4 additions & 1 deletion opentelemetry-sdk/src/metrics/internal/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion opentelemetry-sdk/src/metrics/internal/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion opentelemetry-sdk/src/metrics/internal/precomputed_sum.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 2 additions & 1 deletion opentelemetry-sdk/src/metrics/internal/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/src/metrics/manual_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down
25 changes: 24 additions & 1 deletion opentelemetry-sdk/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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};
Expand Down
7 changes: 4 additions & 3 deletions opentelemetry-sdk/src/metrics/periodic_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,18 +396,19 @@ 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())
}
}

#[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;
Expand Down
6 changes: 1 addition & 5 deletions opentelemetry-sdk/src/metrics/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 2 additions & 5 deletions opentelemetry-sdk/src/testing/metrics/metric_reader.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-stdout/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-stdout/src/metrics/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
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;

Expand Down Expand Up @@ -137,7 +137,7 @@
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 {

Check warning on line 140 in opentelemetry-stdout/src/metrics/exporter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-stdout/src/metrics/exporter.rs#L140

Added line #L140 was not covered by tests
println!("\t\tTemporality : Cumulative");
} else {
println!("\t\tTemporality : Delta");
Expand All @@ -151,7 +151,7 @@
}

fn print_histogram<T: Debug>(histogram: &data::Histogram<T>) {
if histogram.temporality == data::Temporality::Cumulative {
if histogram.temporality == Temporality::Cumulative {

Check warning on line 154 in opentelemetry-stdout/src/metrics/exporter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-stdout/src/metrics/exporter.rs#L154

Added line #L154 was not covered by tests
println!("\t\tTemporality : Cumulative");
} else {
println!("\t\tTemporality : Delta");
Expand Down
Loading