diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index 919467a998..4633447021 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -13,15 +13,19 @@ *Behavior Change*: When enforcing `max_links_per_span`, `max_events_per_span` from `SpanLimits`, links/events are kept in the first-come order. The previous "eviction" based approach is no longer performed. - + *Breaking Change Affecting Exporter authors*: - + `SpanData` now stores `links` as `SpanLinks` instead of `EvictedQueue` where `SpanLinks` is a struct with a `Vec` of links and `dropped_count`. `SpanData` now stores `events` as `SpanEvents` instead of `EvictedQueue` where `SpanEvents` is a struct with a `Vec` of events and `dropped_count`. +### Fixed + +- Fix metric export corruption if gauges have not received a last value. (#1363) + ## v0.21.0 ### Added diff --git a/opentelemetry-sdk/src/metrics/internal/last_value.rs b/opentelemetry-sdk/src/metrics/internal/last_value.rs index 28e9a0a107..57f35fc166 100644 --- a/opentelemetry-sdk/src/metrics/internal/last_value.rs +++ b/opentelemetry-sdk/src/metrics/internal/last_value.rs @@ -55,8 +55,12 @@ impl> LastValue { pub(crate) fn compute_aggregation(&self, dest: &mut Vec>) { let mut values = match self.values.lock() { Ok(guard) if !guard.is_empty() => guard, - _ => return, + _ => { + dest.clear(); // poisoned or no values recorded yet + return; + } }; + let n = values.len(); if n > dest.capacity() { dest.reserve(n - dest.capacity());