Skip to content

Commit

Permalink
add check for measurement attributes (open-telemetry#2468)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Boten authored Feb 18, 2022
1 parent e117db1 commit b516a94
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ def consume_measurement(self, measurement: Measurement) -> None:
for key, value in measurement.attributes.items():
if key in self._attribute_keys:
attributes[key] = value
else:
elif measurement.attributes is not None:
attributes = measurement.attributes
else:
attributes = {}

attributes = frozenset(attributes.items())

Expand Down
16 changes: 16 additions & 0 deletions opentelemetry-sdk/tests/metrics/test_view_instrument_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ def test_consume_measurement(self):
},
)

view_instrument_match = _ViewInstrumentMatch(
"name",
"unit",
"description",
self.mock_aggregation_class,
self.mock_instrumentation_info,
self.mock_resource,
)
view_instrument_match.consume_measurement(
Measurement(value=0, attributes=None)
)
self.assertEqual(
view_instrument_match._attributes_aggregation,
{frozenset({}): self.mock_aggregation_instance},
)

def test_collect(self):

view_instrument_match = _ViewInstrumentMatch(
Expand Down

0 comments on commit b516a94

Please sign in to comment.