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-sdk: don't print warnings if SDK is disabled #4371

Merged
merged 3 commits into from
Dec 24, 2024
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 @@ -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
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
Loading