Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opentelemetry-api: fix wrong conditional on duplicated events log provider warning #4299

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
lzchen marked this conversation as resolved.
Show resolved Hide resolved
_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