-
Notifications
You must be signed in to change notification settings - Fork 1k
fix(sdk): handle unmapped aggregations defensively in MetricReaderStorage.collect #5622
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
base: main
Are you sure you want to change the base?
Changes from all commits
2ec9a74
1a2c139
1362fa4
8828d34
b232b18
35ad30d
d7ada04
8214967
822e57e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| `opentelemetry-sdk`: reject views with unsupported aggregations in `_check_view_instrument_compatibility` with a warning, and skip unmapped aggregations in `MetricReaderStorage.collect` to prevent `UnboundLocalError`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -245,6 +245,7 @@ def test_exporter_temporality_preference(self): | |
| }, | ||
| ) | ||
| pmr = PeriodicExportingMetricReader(exporter) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to self.addCleanup(pmr.shutdown) as in #5641. |
||
| self.addCleanup(pmr.shutdown) | ||
| for key, value in pmr._instrument_class_temporality.items(): | ||
| if key is not _Counter: | ||
| self.assertEqual(value, AggregationTemporality.CUMULATIVE) | ||
|
|
@@ -258,6 +259,7 @@ def test_exporter_aggregation_preference(self): | |
| }, | ||
| ) | ||
| pmr = PeriodicExportingMetricReader(exporter) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to self.addCleanup(pmr.shutdown) as in #5641. |
||
| self.addCleanup(pmr.shutdown) | ||
| for key, value in pmr._instrument_class_aggregation.items(): | ||
| if key is not _Counter: | ||
| self.assertTrue(isinstance(value, DefaultAggregation)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a genuine bug fix,
Aggregationis a public API so we can expect to handle this case.A user with a custom
Aggregationwould get a warning with every export, so we probably want to reconsider this particular approach.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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().