Skip to content

Commit

Permalink
otlp: Add DeltaTemporalitySelector (#1568)
Browse files Browse the repository at this point in the history
Co-authored-by: Cijo Thomas <[email protected]>
  • Loading branch information
svix-jplatte and cijothomas authored Feb 27, 2024
1 parent fe85521 commit ef47010
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## vNext

### Added

- Added `DeltaTemporalitySelector` ([#1568])

[#1568]: https://github.com/open-telemetry/opentelemetry-rust/pull/1568

## v0.15.0

### Changed
Expand Down
39 changes: 39 additions & 0 deletions opentelemetry-otlp/src/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ where
}
}

/// Build with delta temporality selector.
///
/// This temporality selector is equivalent to OTLP Metrics Exporter's
/// `Delta` temporality preference (see [its documentation][exporter-docs]).
///
/// [exporter-docs]: https://github.com/open-telemetry/opentelemetry-specification/blob/a1c13d59bb7d0fb086df2b3e1eaec9df9efef6cc/specification/metrics/sdk_exporters/otlp.md#additional-configuration
pub fn with_delta_temporality(self) -> Self {
self.with_temporality_selector(DeltaTemporalitySelector)
}

/// Build with the given aggregation selector
pub fn with_aggregation_selector<T: AggregationSelector + 'static>(self, selector: T) -> Self {
OtlpMetricPipeline {
Expand Down Expand Up @@ -248,6 +258,35 @@ impl<RT, EB: Debug> Debug for OtlpMetricPipeline<RT, EB> {
}
}

/// A temporality selector that returns [`Delta`][Temporality::Delta] for all
/// instruments except `UpDownCounter` and `ObservableUpDownCounter`.
///
/// This temporality selector is equivalent to OTLP Metrics Exporter's
/// `Delta` temporality preference (see [its documentation][exporter-docs]).
///
/// [exporter-docs]: https://github.com/open-telemetry/opentelemetry-specification/blob/a1c13d59bb7d0fb086df2b3e1eaec9df9efef6cc/specification/metrics/sdk_exporters/otlp.md#additional-configuration
#[derive(Debug)]
struct DeltaTemporalitySelector;

impl TemporalitySelector for DeltaTemporalitySelector {
#[rustfmt::skip]
fn temporality(&self, kind: InstrumentKind) -> Temporality {
match kind {
InstrumentKind::Counter
| InstrumentKind::Histogram
| InstrumentKind::ObservableCounter
| InstrumentKind::Gauge
| InstrumentKind::ObservableGauge => {
Temporality::Delta
}
InstrumentKind::UpDownCounter
| InstrumentKind::ObservableUpDownCounter => {
Temporality::Cumulative
}
}
}
}

/// An interface for OTLP metrics clients
#[async_trait]
pub trait MetricsClient: fmt::Debug + Send + Sync + 'static {
Expand Down

0 comments on commit ef47010

Please sign in to comment.