@@ -169,6 +169,16 @@ where
169
169
}
170
170
}
171
171
172
+ /// Build with [`DeltaTemporalitySelector`] as the temporality selector.
173
+ ///
174
+ /// This temporality selector is equivalent to OTLP Metrics Exporter's
175
+ /// `Delta` temporality preference (see [its documentation][exporter-docs]).
176
+ ///
177
+ /// [exporter-docs]: https://github.com/open-telemetry/opentelemetry-specification/blob/a1c13d59bb7d0fb086df2b3e1eaec9df9efef6cc/specification/metrics/sdk_exporters/otlp.md#additional-configuration
178
+ pub fn with_delta_temporality ( self ) -> Self {
179
+ self . with_temporality_selector ( DeltaTemporalitySelector )
180
+ }
181
+
172
182
/// Build with the given aggregation selector
173
183
pub fn with_aggregation_selector < T : AggregationSelector + ' static > ( self , selector : T ) -> Self {
174
184
OtlpMetricPipeline {
@@ -248,6 +258,36 @@ impl<RT, EB: Debug> Debug for OtlpMetricPipeline<RT, EB> {
248
258
}
249
259
}
250
260
261
+ /// A temporality selector that returns [`Delta`][Temporality::Delta] for all
262
+ /// instruments except `UpDownCounter` and `ObservableUpDownCounter`.
263
+ ///
264
+ /// This temporality selector is equivalent to OTLP Metrics Exporter's
265
+ /// `Delta` temporality preference (see [its documentation][exporter-docs]).
266
+ ///
267
+ /// [exporter-docs]: https://github.com/open-telemetry/opentelemetry-specification/blob/a1c13d59bb7d0fb086df2b3e1eaec9df9efef6cc/specification/metrics/sdk_exporters/otlp.md#additional-configuration
268
+ #[ non_exhaustive]
269
+ #[ derive( Debug ) ]
270
+ pub struct DeltaTemporalitySelector ;
271
+
272
+ impl TemporalitySelector for DeltaTemporalitySelector {
273
+ #[ rustfmt:: skip]
274
+ fn temporality ( & self , kind : InstrumentKind ) -> Temporality {
275
+ match kind {
276
+ InstrumentKind :: Counter
277
+ | InstrumentKind :: Histogram
278
+ | InstrumentKind :: ObservableCounter
279
+ | InstrumentKind :: Gauge
280
+ | InstrumentKind :: ObservableGauge => {
281
+ Temporality :: Delta
282
+ }
283
+ InstrumentKind :: UpDownCounter
284
+ | InstrumentKind :: ObservableUpDownCounter => {
285
+ Temporality :: Cumulative
286
+ }
287
+ }
288
+ }
289
+ }
290
+
251
291
/// An interface for OTLP metrics clients
252
292
#[ async_trait]
253
293
pub trait MetricsClient : fmt:: Debug + Send + Sync + ' static {
0 commit comments