Skip to content

Commit 8b50602

Browse files
committed
otlp: Add DeltaTemporalitySelector
1 parent 36c2a8e commit 8b50602

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-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

+30
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,36 @@ 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+
#[derive(Debug)]
260+
pub struct DeltaTemporalitySelector;
261+
262+
impl TemporalitySelector for DeltaTemporalitySelector {
263+
#[rustfmt::skip]
264+
fn temporality(&self, kind: InstrumentKind) -> Temporality {
265+
match kind {
266+
InstrumentKind::Counter
267+
| InstrumentKind::Histogram
268+
| InstrumentKind::ObservableCounter
269+
| InstrumentKind::Gauge
270+
| InstrumentKind::ObservableGauge => {
271+
Temporality::Delta
272+
}
273+
InstrumentKind::UpDownCounter
274+
| InstrumentKind::ObservableUpDownCounter => {
275+
Temporality::Cumulative
276+
}
277+
}
278+
}
279+
}
250280

251281
/// An interface for OTLP metrics clients
252282
#[async_trait]

0 commit comments

Comments
 (0)