Skip to content

Commit

Permalink
Fix metric export data for unused gauges (open-telemetry#1363)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtescher committed Nov 13, 2023
1 parent a3a5283 commit f6fb7a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## vNext

### 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 f6fb7a6

Please sign in to comment.