Skip to content

Commit

Permalink
opentelemetry-api: fix wrong conditional on duplicated events log pro…
Browse files Browse the repository at this point in the history
…vider warning (#4299)
  • Loading branch information
xrmx authored Nov 19, 2024
1 parent 9fe1f19 commit 6fdaf44
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/src/opentelemetry/_events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
17 changes: 16 additions & 1 deletion opentelemetry-api/tests/events/test_event_logger_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,28 @@


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()

# pylint: disable=no-self-use
@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
Expand Down

0 comments on commit 6fdaf44

Please sign in to comment.