Skip to content

Commit 393df75

Browse files
committed
Move metric data
1 parent acaa98d commit 393df75

20 files changed

+230
-207
lines changed

.cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"datapoint",
3737
"deque",
3838
"Dirkjan",
39+
"downcasting",
3940
"EPYC",
4041
"hasher",
4142
"Isobel",
File renamed without changes.

opentelemetry-sdk/src/metrics/data/mod.rs renamed to opentelemetry-sdk/src/export/metrics.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
1-
//! Types for delivery of pre-aggregated metric time series data.
1+
//! Interfaces for exporting metrics
2+
use async_trait::async_trait;
23

4+
use crate::metrics::{MetricResult, Temporality};
5+
use crate::Resource;
6+
use opentelemetry::{InstrumentationScope, KeyValue};
37
use std::{any, borrow::Cow, fmt, time::SystemTime};
48

5-
use opentelemetry::{InstrumentationScope, KeyValue};
9+
/// Exporter handles the delivery of metric data to external receivers.
10+
///
11+
/// This is the final component in the metric push pipeline.
12+
#[async_trait]
13+
pub trait PushMetricExporter: Send + Sync + 'static {
14+
/// Export serializes and transmits metric data to a receiver.
15+
///
16+
/// All retry logic must be contained in this function. The SDK does not
17+
/// implement any retry logic. All errors returned by this function are
18+
/// considered unrecoverable and will be reported to a configured error
19+
/// Handler.
20+
async fn export(&self, metrics: &mut ResourceMetrics) -> MetricResult<()>;
621

7-
use crate::Resource;
22+
/// Flushes any metric data held by an exporter.
23+
async fn force_flush(&self) -> MetricResult<()>;
24+
25+
/// Releases any held computational resources.
26+
///
27+
/// After Shutdown is called, calls to Export will perform no operation and
28+
/// instead will return an error indicating the shutdown state.
29+
fn shutdown(&self) -> MetricResult<()>;
830

9-
use super::Temporality;
31+
/// Access the [Temporality] of the MetricExporter.
32+
fn temporality(&self) -> Temporality;
33+
}
1034

1135
/// A collection of [ScopeMetrics] and the associated [Resource] that created them.
1236
#[derive(Debug)]

opentelemetry-sdk/src/export/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#[cfg_attr(docsrs, doc(cfg(feature = "logs")))]
55
pub mod logs;
66

7+
#[cfg(feature = "metrics")]
8+
#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
9+
pub mod metrics;
10+
711
#[cfg(feature = "trace")]
812
#[cfg_attr(docsrs, doc(cfg(feature = "trace")))]
913
pub mod trace;

opentelemetry-sdk/src/metrics/aggregation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ impl Aggregation {
150150
#[cfg(test)]
151151
mod tests {
152152
use crate::metrics::{
153+
aggregation::Aggregation,
153154
internal::{EXPO_MAX_SCALE, EXPO_MIN_SCALE},
154-
Aggregation,
155155
};
156+
156157
use crate::metrics::{MetricError, MetricResult};
157158

158159
#[test]
Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1 @@
1-
//! Interfaces for exporting metrics
2-
use async_trait::async_trait;
31

4-
use crate::metrics::MetricResult;
5-
6-
use crate::metrics::data::ResourceMetrics;
7-
8-
use super::Temporality;
9-
10-
/// Exporter handles the delivery of metric data to external receivers.
11-
///
12-
/// This is the final component in the metric push pipeline.
13-
#[async_trait]
14-
pub trait PushMetricExporter: Send + Sync + 'static {
15-
/// Export serializes and transmits metric data to a receiver.
16-
///
17-
/// All retry logic must be contained in this function. The SDK does not
18-
/// implement any retry logic. All errors returned by this function are
19-
/// considered unrecoverable and will be reported to a configured error
20-
/// Handler.
21-
async fn export(&self, metrics: &mut ResourceMetrics) -> MetricResult<()>;
22-
23-
/// Flushes any metric data held by an exporter.
24-
async fn force_flush(&self) -> MetricResult<()>;
25-
26-
/// Releases any held computational resources.
27-
///
28-
/// After Shutdown is called, calls to Export will perform no operation and
29-
/// instead will return an error indicating the shutdown state.
30-
fn shutdown(&self) -> MetricResult<()>;
31-
32-
/// Access the [Temporality] of the MetricExporter.
33-
fn temporality(&self) -> Temporality;
34-
}

opentelemetry-sdk/src/metrics/internal/aggregate.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use std::{
88

99
use opentelemetry::KeyValue;
1010

11-
use crate::metrics::{data::Aggregation, Temporality};
11+
use crate::export::metrics::Aggregation;
12+
use crate::metrics::Temporality;
1213

1314
use super::{
1415
exponential_histogram::ExpoHistogram, histogram::Histogram, last_value::LastValue,
@@ -199,7 +200,7 @@ impl<T: Number> AggregateBuilder<T> {
199200

200201
#[cfg(test)]
201202
mod tests {
202-
use crate::metrics::data::{
203+
use crate::export::metrics::{
203204
ExponentialBucket, ExponentialHistogram, ExponentialHistogramDataPoint, Gauge,
204205
GaugeDataPoint, Histogram, HistogramDataPoint, Sum, SumDataPoint,
205206
};

0 commit comments

Comments
 (0)