Skip to content

Commit

Permalink
[release/v1.28.x-0.49bx] opentelemetry-sdk: setup EventLogger when in…
Browse files Browse the repository at this point in the history
…itializing logging (open-telemetry#4270) (open-telemetry#4283)

* opentelemetry-sdk: setup EventLogger when initializing logging (open-telemetry#4270)

* Move cherry-picked changelog entry to Unreleased section

---------

Co-authored-by: Riccardo Magliocchetti <[email protected]>
  • Loading branch information
aabmass and xrmx authored Nov 15, 2024
1 parent 2929ebd commit ea809eb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix crash exporting a log record with None body
([#4276](https://github.com/open-telemetry/opentelemetry-python/pull/4276))
- sdk: setup EventLogger when OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED is set
([#4270](https://github.com/open-telemetry/opentelemetry-python/pull/4270))

## Version 1.28.1/0.49b1 (2024-11-08)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from typing_extensions import Literal

from opentelemetry._events import set_event_logger_provider
from opentelemetry._logs import set_logger_provider
from opentelemetry.environment_variables import (
OTEL_LOGS_EXPORTER,
Expand All @@ -33,6 +34,7 @@
OTEL_TRACES_EXPORTER,
)
from opentelemetry.metrics import set_meter_provider
from opentelemetry.sdk._events import EventLoggerProvider
from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor, LogExporter
from opentelemetry.sdk.environment_variables import (
Expand Down Expand Up @@ -248,6 +250,9 @@ def _init_logging(

logging.getLogger().addHandler(handler)

event_logger_provider = EventLoggerProvider(logger_provider=provider)
set_event_logger_provider(event_logger_provider)


def _import_exporters(
trace_exporter_names: Sequence[str],
Expand Down
24 changes: 24 additions & 0 deletions opentelemetry-sdk/tests/test_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,14 +586,32 @@ def setUp(self):
"opentelemetry.sdk._configuration.set_logger_provider"
)

self.event_logger_provider_instance_mock = Mock()
self.event_logger_provider_patch = patch(
"opentelemetry.sdk._configuration.EventLoggerProvider",
return_value=self.event_logger_provider_instance_mock,
)
self.set_event_logger_provider_patch = patch(
"opentelemetry.sdk._configuration.set_event_logger_provider"
)

self.processor_mock = self.processor_patch.start()
self.provider_mock = self.provider_patch.start()
self.set_provider_mock = self.set_provider_patch.start()

self.event_logger_provider_mock = (
self.event_logger_provider_patch.start()
)
self.set_event_logger_provider_mock = (
self.set_event_logger_provider_patch.start()
)

def tearDown(self):
self.processor_patch.stop()
self.set_provider_patch.stop()
self.provider_patch.stop()
self.event_logger_provider_patch.stop()
self.set_event_logger_provider_patch.stop()
root_logger = getLogger("root")
root_logger.handlers = [
handler
Expand All @@ -616,6 +634,12 @@ def test_logging_init_empty(self):
provider.resource.attributes.get("telemetry.auto.version"),
"auto-version",
)
self.event_logger_provider_mock.assert_called_once_with(
logger_provider=provider
)
self.set_event_logger_provider_mock.assert_called_once_with(
self.event_logger_provider_instance_mock
)

@patch.dict(
environ,
Expand Down

0 comments on commit ea809eb

Please sign in to comment.