Skip to content

Commit 7c2eab6

Browse files
committed
Cleanup deprecation messages and test for them
1 parent 0382fc2 commit 7c2eab6

4 files changed

Lines changed: 24 additions & 4 deletions

File tree

opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@ def _init_logging(
327327

328328
if setup_logging_handler:
329329
warnings.warn(
330-
"Setting the OTel Logging handler from the SDK and the "
331-
"`OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED` are deprecated. "
332-
"You should install the opentelemetry-instrumentation-logging",
330+
"The `OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED` environment variable "
331+
"and the `LoggingHandler` in `opentelemetry-sdk` that it controls are deprecated."
332+
"Install `opentelemetry-instrumentation-logging` package instead.",
333333
DeprecationWarning,
334334
)
335335

opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,8 @@ def __init__(
497497
self._logger_provider = logger_provider or get_logger_provider()
498498

499499
warnings.warn(
500-
"This is deprecated you should use the one in opentelemetry-instrumentation-logging",
500+
"`LoggingHandler` in `opentelemetry-sdk` is deprecated. Use the "
501+
"handler from `opentelemetry-instrumentation-logging` instead.",
501502
DeprecationWarning,
502503
)
503504

opentelemetry-sdk/tests/logs/test_handler.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838

3939
# pylint: disable=too-many-public-methods
4040
class TestLoggingHandler(unittest.TestCase):
41+
def test_warns_when_used(self):
42+
with self.assertWarnsRegex(
43+
DeprecationWarning,
44+
"`LoggingHandler` in `opentelemetry-sdk` is deprecated",
45+
):
46+
LoggingHandler()
47+
4148
def test_handler_default_log_level(self):
4249
processor, logger, handler = set_up_test_logging(logging.NOTSET)
4350

opentelemetry-sdk/tests/test_configurator.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,18 @@ def test_logging_init_exporter_without_handler_setup(self):
843843
getLogger(__name__).error("hello")
844844
self.assertFalse(provider.processors[0].exporter.export_called)
845845

846+
def test_logging_init_with_setup_logging_handler_to_true_warns(self):
847+
resource = Resource.create({})
848+
with self.assertWarnsRegex(
849+
DeprecationWarning,
850+
"and the `LoggingHandler` in `opentelemetry-sdk` that it controls are deprecated",
851+
):
852+
_init_logging(
853+
{"otlp": DummyOTLPLogExporter},
854+
resource=resource,
855+
setup_logging_handler=True,
856+
)
857+
846858
@patch.dict(
847859
environ,
848860
{"OTEL_RESOURCE_ATTRIBUTES": "service.name=otlp-service"},

0 commit comments

Comments
 (0)