Conversation
…te double shutdown warning
Pull request dashboard statusWaiting on the author · refreshed 2026-09-13 22:53 UTC Respond to 1 review item (e.g. link a commit, explain why not, ask a follow-up):
Status above doesn't look right?
|
|
please sign the CLA |
|
how does this PR fix #5157? |
|
@ocelotl Thank you for reviewing! Regarding how this PR addresses #5157: The traceback captured in #5157 shows two symptoms occurring together:
These two failures share a single root cause:
This PR fixes both:
|
|
/dashboard route:reviewers |
|
@dlowzzxx, this pull request was routed to reviewers. |
|
Ok, I looked into this, and I think this PR is valuable, but it still does not fix #5157. You are right that there is a leaked ticker thread, but it does not cause the issue here in the way this PR is intended to fix it:
#5157 is 2 separate problems, I am adding their fixes here:
I'll comment in this PR diff with the parts of this PR I find valuable. |
| data_points=data_points, | ||
| aggregation_temporality=aggregation_temporality, | ||
| ) | ||
| else: |
There was a problem hiding this comment.
This is a genuine bug fix, Aggregation is a public API so we can expect to handle this case.
A user with a custom Aggregation would get a warning with every export, so we probably want to reconsider this particular approach.
There was a problem hiding this comment.
Addressed: warnings are now deduplicated via self._unsupported_aggregation_warned using (instrument, type(view_instrument_match._aggregation)) as the key, ensuring unmapped or custom aggregations only log a warning once per instrument.
There was a problem hiding this comment.
I would suggest another approach: take look here.
I think it is better to put the check this PR attempts to introduce there as well. If we use the current approach from this PR the warning shows once and only if the process starts after its logging is set up, if not the warning is lost and the user never realizes their data is gone. Here we can just keep the else/continue.
There was a problem hiding this comment.
Addressed: moved the unsupported aggregation check to _check_view_instrument_compatibility (returning False so the incompatible view is not applied, matching #5461) and kept the clean else: continue fallback in MetricReaderStorage.collect().
| @@ -0,0 +1 @@ | |||
| `opentelemetry-sdk`: log a warning and skip unmapped aggregations in `MetricReaderStorage.collect` to prevent `UnboundLocalError`, and shut down periodic metric readers in tests to prevent background daemon thread leaks. | |||
There was a problem hiding this comment.
This should be updated, test case changes are not something we want to tell users about.
There was a problem hiding this comment.
Updated: simplified the changelog fragment to describe only user-facing SDK behavior (skip unmapped aggregations in MetricReaderStorage.collect and log a warning once per instrument to prevent UnboundLocalError).
| @@ -245,11 +245,14 @@ def test_exporter_temporality_preference(self): | |||
| }, | |||
| ) | |||
| pmr = PeriodicExportingMetricReader(exporter) | |||
| @@ -258,11 +261,14 @@ def test_exporter_aggregation_preference(self): | |||
| }, | |||
| ) | |||
| pmr = PeriodicExportingMetricReader(exporter) | |||
There was a problem hiding this comment.
Updated to self.addCleanup(pmr.shutdown) as in #5641.
ocelotl
left a comment
There was a problem hiding this comment.
This PR contains valuable changes but needs refactoring, its changes are also not a fix for the target issue.
|
@ocelotl Thank you for the detailed review and clarifying the root cause for #5157! I have refactored this PR according to your feedback:
/dashboard route:reviewers |
|
@ocelotl All review feedback and inline threads have been addressed and updated:
Latest commit: b232b18 /dashboard route:reviewers |
|
thanks! please resolve the conflicts ✌️ so I can continue reviewing and approving |
…y-python into fix/metrics-test-thread-leak-collector-fallback-5157
|
@ocelotl Conflicts with main have been resolved cleanly! All tests pass. Ready for your review and approval ✌️ /dashboard route:reviewers |
| warn_key = (instrument, type(view_instrument_match._aggregation)) | ||
| if warn_key not in self._unsupported_aggregation_warned: | ||
| self._unsupported_aggregation_warned.add(warn_key) | ||
| _logger.warning( |
There was a problem hiding this comment.
This would render something like this
Unsupported aggregation <opentelemetry.sdk.metrics._internal.aggregation._SumAggregation object at 0x79db26bccc20> for instrument <opentelemetry.sdk.metrics._internal.instrument._Counter object at 0x79db26bccad0>
Better to use type(view_instrument_match._aggregation).__name__ and instrument.name.
There was a problem hiding this comment.
Addressed: updated warning formatting to use ype(view._aggregation).name and instrument.name.
…rument_compatibility (open-telemetry#5622)
|
@ocelotl Thank you for the review and guidance! I have updated the implementation to align with PR #5461:
Commit: /dashboard route:reviewers |
…ad-leak-collector-fallback-5157
|
Rebased on latest |
Description
Related to #5157
Context
In
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/metric_reader_storage.py,MetricReaderStorage.collect()iterates through view instrument matches and assignsdatadepending on the aggregation instance. When an unmapped or custom aggregation was encountered, no branch was taken, leavingdataunassigned and resulting inUnboundLocalError: cannot access local variable 'data' where it is not associated with a valuewhen constructingMetric(...).Changes
else:fallback in the aggregationisinstancechain incollect(). Deduplicates warnings usingself._unsupported_aggregation_warnedso the warning is logged only once per(instrument, type(_aggregation))pair, avoiding log/stderr flooding during periodic export cycles.try/finallywithself.addCleanup(pmr.shutdown)intest_exporter_temporality_preferenceandtest_exporter_aggregation_preference.test_collect_skips_unsupported_aggregationtotest_metric_reader_storage.py(avoiding module-level mock of_ViewInstrumentMatchby directly populating_instrument_view_instrument_matches) and asserted that unsupported aggregations are skipped and repeat collections do not re-emit the warning..changelog/5622.fixed.