Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix metric collections during PeriodicReader shutdown #1375

Merged
merged 8 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
`SpanData` now stores `events` as `SpanEvents` instead of `EvictedQueue` where
`SpanEvents` is a struct with a `Vec` of events and `dropped_count`.

- [#1375](https://github.com/open-telemetry/opentelemetry-rust/pull/1375/) Fix metric collections during PeriodicReader shutdown

## v0.21.1

### Fixed
Expand Down
13 changes: 8 additions & 5 deletions opentelemetry-sdk/src/metrics/periodic_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,21 @@
if inner.is_shutdown {
return Err(MetricsError::Other("reader is already shut down".into()));
}
inner.is_shutdown = true;

let (sender, receiver) = oneshot::channel();
inner
.message_sender
.try_send(Message::Shutdown(sender))
.map_err(|e| MetricsError::Other(e.to_string()))?;

drop(inner); // don't hold lock when blocking on future

futures_executor::block_on(receiver)
.map_err(|err| MetricsError::Other(err.to_string()))
.and_then(|res| res)
let shutdown_result = futures_executor::block_on(receiver)
.map_err(|err| MetricsError::Other(err.to_string()))?;

Check warning on line 386 in opentelemetry-sdk/src/metrics/periodic_reader.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/periodic_reader.rs#L385-L386

Added lines #L385 - L386 were not covered by tests

// Acquire the lock again to set the shutdown flag
let mut inner = self.inner.lock()?;
inner.is_shutdown = true;

shutdown_result

Check warning on line 392 in opentelemetry-sdk/src/metrics/periodic_reader.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/periodic_reader.rs#L389-L392

Added lines #L389 - L392 were not covered by tests
}
}
Loading