Skip to content

Commit 463f6fe

Browse files
committed
opentelemetry-test-utils: don't crash in TestBase.get_sorted_metrics without metrics
1 parent 0c9c624 commit 463f6fe

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

tests/opentelemetry-test-utils/src/opentelemetry/test/test_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ def disable_logging(highest_level=logging.CRITICAL):
144144
logging.disable(logging.NOTSET)
145145

146146
def get_sorted_metrics(self):
147+
metrics_data = self.memory_metrics_reader.get_metrics_data()
147148
resource_metrics = (
148-
self.memory_metrics_reader.get_metrics_data().resource_metrics
149+
metrics_data.resource_metrics if metrics_data else []
149150
)
150151

151152
all_metrics = []
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from opentelemetry.test.test_base import TestBase
16+
17+
18+
class TestBaseTestCase(TestBase):
19+
def test_get_sorted_metrics_works_without_metrics(self):
20+
metrics = self.get_sorted_metrics()
21+
self.assertEqual(metrics, [])

0 commit comments

Comments
 (0)