Skip to content

Commit

Permalink
Fix log message (open-telemetry#2414)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl authored Jan 26, 2022
1 parent 5cd7a74 commit b339ca7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def shutdown(self):

if not metric_reader_result:
_logger.warning(
"MetricReader {metric_reader} failed to shutdown"
"MetricReader %s failed to shutdown", metric_reader
)

overall_result = overall_result and metric_reader_result
Expand Down
16 changes: 13 additions & 3 deletions opentelemetry-sdk/tests/metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from logging import WARNING
from unittest import TestCase
from unittest.mock import Mock, patch
from unittest.mock import MagicMock, Mock, patch

from opentelemetry.sdk._metrics import Meter, MeterProvider
from opentelemetry.sdk._metrics.instrument import (
Expand Down Expand Up @@ -92,14 +92,24 @@ def test_get_meter_duplicate(self):

def test_shutdown(self):

mock_metric_reader_0 = Mock(**{"shutdown.return_value": False})
mock_metric_reader_0 = MagicMock(
**{
"shutdown.return_value": False,
"__str__.return_value": "mock_metric_reader_0",
}
)
mock_metric_reader_1 = Mock(**{"shutdown.return_value": True})

meter_provider = MeterProvider(
metric_readers=[mock_metric_reader_0, mock_metric_reader_1]
)

self.assertFalse(meter_provider.shutdown())
with self.assertLogs(level=WARNING) as log:
self.assertFalse(meter_provider.shutdown())
self.assertEqual(
log.records[0].getMessage(),
"MetricReader mock_metric_reader_0 failed to shutdown",
)
mock_metric_reader_0.shutdown.assert_called_once()
mock_metric_reader_1.shutdown.assert_called_once()

Expand Down

0 comments on commit b339ca7

Please sign in to comment.