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

[release/v1.28.x-0.49bx] opentelemetry-sdk: setup EventLogger when initializing logging (#4270) #4283

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

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

- Fix metrics export with exemplar and no context and filtering observable instruments
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