Describe your environment
OS: Debian
Python version: 3.12.9 (main, Apr 8 2025, 01:41:13) [GCC 12.2.0]
SDK version: 1.38.0
API version: 1.38.0
What happened?
We have gotten some errors on Sentry while exporting metrics because the dictionary changed size during iteration.
The error happens on file opentelemetry/sdk/metrics/_internal/metric_reader_storage.py in collect at line 149.
Steps to Reproduce
Unfortunately this happens about three times a day and we haven't found how to trigger it.
Expected Result
Metrics should be exported successfully.
Actual Result
Sometimes the metrics fails with the error: RuntimeError: dictionary changed size during iteration
Additional context
Stack trace

Would you like to implement a fix?
None
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
Describe your environment
OS: Debian
Python version: 3.12.9 (main, Apr 8 2025, 01:41:13) [GCC 12.2.0]
SDK version: 1.38.0
API version: 1.38.0
What happened?
We have gotten some errors on Sentry while exporting metrics because the dictionary changed size during iteration.
The error happens on file
opentelemetry/sdk/metrics/_internal/metric_reader_storage.pyincollectat line 149.Steps to Reproduce
Unfortunately this happens about three times a day and we haven't found how to trigger it.
Expected Result
Metrics should be exported successfully.
Actual Result
Sometimes the metrics fails with the error:
RuntimeError: dictionary changed size during iterationAdditional context
Stack trace

Would you like to implement a fix?
None
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding
+1orme too, to help us triage it. Learn more here.