Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b516a94

Browse files
author
Alex Boten
authored
add check for measurement attributes (open-telemetry#2468)
1 parent e117db1 commit b516a94

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/_metrics/_view_instrument_match.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ def consume_measurement(self, measurement: Measurement) -> None:
5959
for key, value in measurement.attributes.items():
6060
if key in self._attribute_keys:
6161
attributes[key] = value
62-
else:
62+
elif measurement.attributes is not None:
6363
attributes = measurement.attributes
64+
else:
65+
attributes = {}
6466

6567
attributes = frozenset(attributes.items())
6668

opentelemetry-sdk/tests/metrics/test_view_instrument_match.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ def test_consume_measurement(self):
8686
},
8787
)
8888

89+
view_instrument_match = _ViewInstrumentMatch(
90+
"name",
91+
"unit",
92+
"description",
93+
self.mock_aggregation_class,
94+
self.mock_instrumentation_info,
95+
self.mock_resource,
96+
)
97+
view_instrument_match.consume_measurement(
98+
Measurement(value=0, attributes=None)
99+
)
100+
self.assertEqual(
101+
view_instrument_match._attributes_aggregation,
102+
{frozenset({}): self.mock_aggregation_instance},
103+
)
104+
89105
def test_collect(self):
90106

91107
view_instrument_match = _ViewInstrumentMatch(

0 commit comments

Comments
 (0)