@@ -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,35 @@ 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
+ #[ derive( Debug ) ]
269
+ struct DeltaTemporalitySelector ;
270
+
271
+ impl TemporalitySelector for DeltaTemporalitySelector {
272
+ #[ rustfmt:: skip]
273
+ fn temporality ( & self , kind : InstrumentKind ) -> Temporality {
274
+ match kind {
275
+ InstrumentKind :: Counter
276
+ | InstrumentKind :: Histogram
277
+ | InstrumentKind :: ObservableCounter
278
+ | InstrumentKind :: Gauge
279
+ | InstrumentKind :: ObservableGauge => {
280
+ Temporality :: Delta
281
+ }
282
+ InstrumentKind :: UpDownCounter
283
+ | InstrumentKind :: ObservableUpDownCounter => {
284
+ Temporality :: Cumulative
285
+ }
286
+ }
287
+ }
288
+ }
289
+
251
290
/// An interface for OTLP metrics clients
252
291
#[ async_trait]
253
292
pub trait MetricsClient : fmt:: Debug + Send + Sync + ' static {
0 commit comments