Skip to content

Commit

Permalink
Fix metric export data for unused gauges (#1363)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtescher authored Nov 9, 2023
1 parent 4f1c3a2 commit 5527a11
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion opentelemetry-sdk/src/metrics/internal/last_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ impl<T: Number<T>> LastValue<T> {
pub(crate) fn compute_aggregation(&self, dest: &mut Vec<DataPoint<T>>) {
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());
Expand Down

0 comments on commit 5527a11

Please sign in to comment.