Skip to content

Commit 0e94994

Browse files
committed
otlp: Add DeltaTemporalitySelector
1 parent 36c2a8e commit 0e94994

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

opentelemetry-otlp/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pub use crate::span::{
226226

227227
#[cfg(feature = "metrics")]
228228
pub use crate::metric::{
229-
MetricsExporter, MetricsExporterBuilder, OtlpMetricPipeline,
229+
DeltaTemporalitySelector, MetricsExporter, MetricsExporterBuilder, OtlpMetricPipeline,
230230
OTEL_EXPORTER_OTLP_METRICS_COMPRESSION, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT,
231231
OTEL_EXPORTER_OTLP_METRICS_HEADERS, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT,
232232
};

opentelemetry-otlp/src/metric.rs

+28
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,34 @@ impl<RT, EB: Debug> Debug for OtlpMetricPipeline<RT, EB> {
247247
.finish()
248248
}
249249
}
250+
/// A temporality selector that returns [`Delta`][Temporality::Delta] for all
251+
/// instruments except `UpDownCounter` and `ObservableUpDownCounter`.
252+
///
253+
/// This should be used over the default if you export your data to a service
254+
/// like DataDog that works better with delta aggregation¹.
255+
///
256+
/// ¹ as per DataDog documentation:
257+
/// <https://docs.datadoghq.com/opentelemetry/guide/otlp_delta_temporality/>
258+
#[non_exhaustive]
259+
pub struct DeltaTemporalitySelector;
260+
261+
impl TemporalitySelector for DeltaTemporalitySelector {
262+
fn temporality(&self, kind: InstrumentKind) -> Temporality {
263+
#[rustfmt::skip]
264+
match kind {
265+
InstrumentKind::Counter
266+
| InstrumentKind::Histogram
267+
| InstrumentKind::ObservableCounter
268+
| InstrumentKind::ObservableGauge => {
269+
Temporality::Delta
270+
}
271+
InstrumentKind::UpDownCounter
272+
| InstrumentKind::ObservableUpDownCounter => {
273+
Temporality::Cumulative
274+
}
275+
}
276+
}
277+
}
250278

251279
/// An interface for OTLP metrics clients
252280
#[async_trait]

0 commit comments

Comments
 (0)