Skip to content

Commit

Permalink
opentelemetry-test-utils: don't crash in TestBase.get_sorted_metrics …
Browse files Browse the repository at this point in the history
…without metrics (#4194)
  • Loading branch information
xrmx authored Sep 18, 2024
1 parent 6919f65 commit 71db261
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ def disable_logging(highest_level=logging.CRITICAL):
logging.disable(logging.NOTSET)

def get_sorted_metrics(self):
metrics_data = self.memory_metrics_reader.get_metrics_data()
resource_metrics = (
self.memory_metrics_reader.get_metrics_data().resource_metrics
metrics_data.resource_metrics if metrics_data else []
)

all_metrics = []
Expand Down
21 changes: 21 additions & 0 deletions tests/opentelemetry-test-utils/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from opentelemetry.test.test_base import TestBase


class TestBaseTestCase(TestBase):
def test_get_sorted_metrics_works_without_metrics(self):
metrics = self.get_sorted_metrics()
self.assertEqual(metrics, [])

0 comments on commit 71db261

Please sign in to comment.