From 94261fbaf3ae143556837215329d15b367bde163 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 19 Nov 2024 12:07:04 +0100 Subject: [PATCH 1/3] opentelemetry-api: fix wrong conditional on duplicated events log provider warning --- .../src/opentelemetry/_events/__init__.py | 2 +- .../tests/events/test_event_logger_provider.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/_events/__init__.py b/opentelemetry-api/src/opentelemetry/_events/__init__.py index a291055ec7..e1e6a675a5 100644 --- a/opentelemetry-api/src/opentelemetry/_events/__init__.py +++ b/opentelemetry-api/src/opentelemetry/_events/__init__.py @@ -192,7 +192,7 @@ def set_elp() -> None: did_set = _EVENT_LOGGER_PROVIDER_SET_ONCE.do_once(set_elp) - if log and did_set: + if log and not did_set: _logger.warning( "Overriding of current EventLoggerProvider is not allowed" ) diff --git a/opentelemetry-api/tests/events/test_event_logger_provider.py b/opentelemetry-api/tests/events/test_event_logger_provider.py index 4c8bb54c8d..1c258a05a4 100644 --- a/opentelemetry-api/tests/events/test_event_logger_provider.py +++ b/opentelemetry-api/tests/events/test_event_logger_provider.py @@ -11,13 +11,27 @@ class TestGlobals(EventsGlobalsTest, unittest.TestCase): - def test_set_event_logger_provider(self): + @patch("opentelemetry._events._logger") + def test_set_event_logger_provider(self, logger_mock): elp_mock = Mock() # pylint: disable=protected-access self.assertIsNone(events._EVENT_LOGGER_PROVIDER) set_event_logger_provider(elp_mock) self.assertIs(events._EVENT_LOGGER_PROVIDER, elp_mock) self.assertIs(get_event_logger_provider(), elp_mock) + logger_mock.warning.assert_not_called() + + @patch("opentelemetry._events._logger") + def test_set_event_logger_provider_will_warn_second_call( + self, logger_mock + ): + elp_mock = Mock() + set_event_logger_provider(elp_mock) + set_event_logger_provider(elp_mock) + + logger_mock.warning.assert_called_once_with( + "Overriding of current EventLoggerProvider is not allowed" + ) def test_get_event_logger_provider(self): # pylint: disable=protected-access From 5dcbf28435b90685745e631d307d2fb03be2a6ad Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 19 Nov 2024 12:11:15 +0100 Subject: [PATCH 2/3] Add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47fac23541..bf0ae6a891 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#4259](https://github.com/open-telemetry/opentelemetry-python/pull/4259)) - sdk: setup EventLogger when OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED is set ([#4270](https://github.com/open-telemetry/opentelemetry-python/pull/4270)) +- api: fix logging of duplicate EventLogger setup warning + ([#4299](https://github.com/open-telemetry/opentelemetry-python/pull/4299)) ## Version 1.28.0/0.49b0 (2024-11-05) From 0b4353d370f0d250decf34114c046f680a933d5e Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 19 Nov 2024 12:22:33 +0100 Subject: [PATCH 3/3] Please pylint --- opentelemetry-api/tests/events/test_event_logger_provider.py | 1 + 1 file changed, 1 insertion(+) diff --git a/opentelemetry-api/tests/events/test_event_logger_provider.py b/opentelemetry-api/tests/events/test_event_logger_provider.py index 1c258a05a4..425697bfa3 100644 --- a/opentelemetry-api/tests/events/test_event_logger_provider.py +++ b/opentelemetry-api/tests/events/test_event_logger_provider.py @@ -21,6 +21,7 @@ def test_set_event_logger_provider(self, logger_mock): self.assertIs(get_event_logger_provider(), elp_mock) logger_mock.warning.assert_not_called() + # pylint: disable=no-self-use @patch("opentelemetry._events._logger") def test_set_event_logger_provider_will_warn_second_call( self, logger_mock