diff --git a/opencensus/metrics/export/metric_descriptor.py b/opencensus/metrics/export/metric_descriptor.py index cbb258547..5bde7bb23 100644 --- a/opencensus/metrics/export/metric_descriptor.py +++ b/opencensus/metrics/export/metric_descriptor.py @@ -130,8 +130,8 @@ def __init__(self, name, description, unit, type_, label_keys): if type_ not in MetricDescriptorType: raise ValueError("Invalid type") - if not label_keys: - raise ValueError("label_keys must not be empty or null") + if label_keys is None: + raise ValueError("label_keys must not be None") if any(key is None for key in label_keys): raise ValueError("label_keys must not contain null keys") diff --git a/tests/unit/metrics/export/test_metric_descriptor.py b/tests/unit/metrics/export/test_metric_descriptor.py index 30eef9e2b..2a5f7b80c 100644 --- a/tests/unit/metrics/export/test_metric_descriptor.py +++ b/tests/unit/metrics/export/test_metric_descriptor.py @@ -53,6 +53,11 @@ def test_null_label_keys(self): NAME, DESCRIPTION, UNIT, metric_descriptor.MetricDescriptorType.GAUGE_DOUBLE, None) + def test_empty_label_keys(self): + metric_descriptor.MetricDescriptor( + NAME, DESCRIPTION, UNIT, + metric_descriptor.MetricDescriptorType.GAUGE_DOUBLE, []) + def test_null_label_key_values(self): with self.assertRaises(ValueError): metric_descriptor.MetricDescriptor(