Skip to content

Commit

Permalink
opentelemetry-sdk: don't print warnings if SDK is disabled (open-tele…
Browse files Browse the repository at this point in the history
…metry#4371)

* opentelemetry-sdk: don't print warnings if SDK is disabled

* Add changelog
  • Loading branch information
xrmx authored Dec 24, 2024
1 parent 92f221c commit 29aad2e
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#4364](https://github.com/open-telemetry/opentelemetry-python/pull/4364))
- Add Python 3.13 support
([#4353](https://github.com/open-telemetry/opentelemetry-python/pull/4353))
- sdk: don't log or print warnings when the SDK has been disabled
([#4371](https://github.com/open-telemetry/opentelemetry-python/pull/4371))

## Version 1.29.0/0.50b0 (2024-12-11)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,6 @@ def get_logger(
attributes: Optional[Attributes] = None,
) -> Logger:
if self._disabled:
warnings.warn("SDK is disabled.")
return NoOpLogger(
name,
version=version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ def get_meter(
attributes: Optional[Attributes] = None,
) -> Meter:
if self._disabled:
_logger.warning("SDK is disabled.")
return NoOpMeter(name, version=version, schema_url=schema_url)

if self._shutdown:
Expand Down
1 change: 0 additions & 1 deletion opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,6 @@ def get_tracer(
attributes: typing.Optional[types.Attributes] = None,
) -> "trace_api.Tracer":
if self._disabled:
logger.warning("SDK is disabled.")
return NoOpTracer()
if not instrumenting_module_name: # Reject empty strings too.
instrumenting_module_name = ""
Expand Down
7 changes: 1 addition & 6 deletions opentelemetry-sdk/tests/logs/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import logging
import os
import unittest
import warnings
from unittest.mock import Mock, patch

from opentelemetry._logs import NoOpLoggerProvider, SeverityNumber
Expand Down Expand Up @@ -290,11 +289,7 @@ def test_handler_root_logger_with_disabled_sdk_does_not_go_into_recursion_error(
processor, logger = set_up_test_logging(
logging.NOTSET, root_logger=True
)
with warnings.catch_warnings(record=True) as cw:
logger.warning("hello")

self.assertEqual(len(cw), 1)
self.assertEqual("SDK is disabled.", str(cw[0].message))
logger.warning("hello")

self.assertEqual(processor.emit_count(), 0)

Expand Down
6 changes: 1 addition & 5 deletions opentelemetry-sdk/tests/logs/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# pylint: disable=protected-access

import unittest
import warnings
from unittest.mock import Mock, patch

from opentelemetry.sdk._logs import LoggerProvider
Expand Down Expand Up @@ -70,12 +69,9 @@ def test_get_logger(self):

@patch.dict("os.environ", {OTEL_SDK_DISABLED: "true"})
def test_get_logger_with_sdk_disabled(self):
with warnings.catch_warnings(record=True) as cw:
logger = LoggerProvider().get_logger(Mock())
logger = LoggerProvider().get_logger(Mock())

self.assertIsInstance(logger, NoOpLogger)
self.assertEqual(len(cw), 1)
self.assertEqual("SDK is disabled.", str(cw[0].message))

@patch.object(Resource, "create")
def test_logger_provider_init(self, resource_patch):
Expand Down

0 comments on commit 29aad2e

Please sign in to comment.