Skip to content

Commit 22b40b0

Browse files
authored
Merge branch 'main' into histogram-advisory
2 parents 7841b6b + 29aad2e commit 22b40b0

File tree

7 files changed

+9
-15
lines changed

7 files changed

+9
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
([#4353](https://github.com/open-telemetry/opentelemetry-python/pull/4353))
1414
- Add support for `explicit_bucket_boundaries` advisory for Histograms
1515
([#4361](https://github.com/open-telemetry/opentelemetry-python/pull/4361))
16+
- sdk: don't log or print warnings when the SDK has been disabled
17+
([#4371](https://github.com/open-telemetry/opentelemetry-python/pull/4371))
1618

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

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,6 @@ def get_logger(
670670
attributes: Optional[Attributes] = None,
671671
) -> Logger:
672672
if self._disabled:
673-
warnings.warn("SDK is disabled.")
674673
return NoOpLogger(
675674
name,
676675
version=version,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,6 @@ def get_meter(
561561
attributes: Optional[Attributes] = None,
562562
) -> Meter:
563563
if self._disabled:
564-
_logger.warning("SDK is disabled.")
565564
return NoOpMeter(name, version=version, schema_url=schema_url)
566565

567566
if self._shutdown:

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
these attributes can be included in the Resource.*
2424
2525
Resource objects are created with `Resource.create`, which accepts attributes
26-
(key-values). Resources should NOT be created via constructor, and working with
26+
(key-values). Resources should NOT be created via constructor except by `ResourceDetector`
27+
instances which can't use `Resource.create` to avoid infinite loops. Working with
2728
`Resource` objects should only be done via the Resource API methods. Resource
2829
attributes can also be passed at process invocation in the
2930
:envvar:`OTEL_RESOURCE_ATTRIBUTES` environment variable. You should register
@@ -175,6 +176,8 @@ def create(
175176
) -> "Resource":
176177
"""Creates a new `Resource` from attributes.
177178
179+
`ResourceDetector` instances should not call this method.
180+
178181
Args:
179182
attributes: Optional zero or more key-value pairs.
180183
schema_url: Optional URL pointing to the schema
@@ -316,6 +319,7 @@ def __init__(self, raise_on_error: bool = False) -> None:
316319

317320
@abc.abstractmethod
318321
def detect(self) -> "Resource":
322+
"""Don't call `Resource.create` here to avoid an infinite loop, instead instantiate `Resource` directly"""
319323
raise NotImplementedError()
320324

321325

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,6 @@ def get_tracer(
12281228
attributes: typing.Optional[types.Attributes] = None,
12291229
) -> "trace_api.Tracer":
12301230
if self._disabled:
1231-
logger.warning("SDK is disabled.")
12321231
return NoOpTracer()
12331232
if not instrumenting_module_name: # Reject empty strings too.
12341233
instrumenting_module_name = ""

opentelemetry-sdk/tests/logs/test_handler.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import logging
1616
import os
1717
import unittest
18-
import warnings
1918
from unittest.mock import Mock, patch
2019

2120
from opentelemetry._logs import NoOpLoggerProvider, SeverityNumber
@@ -290,11 +289,7 @@ def test_handler_root_logger_with_disabled_sdk_does_not_go_into_recursion_error(
290289
processor, logger = set_up_test_logging(
291290
logging.NOTSET, root_logger=True
292291
)
293-
with warnings.catch_warnings(record=True) as cw:
294-
logger.warning("hello")
295-
296-
self.assertEqual(len(cw), 1)
297-
self.assertEqual("SDK is disabled.", str(cw[0].message))
292+
logger.warning("hello")
298293

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

opentelemetry-sdk/tests/logs/test_logs.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# pylint: disable=protected-access
1616

1717
import unittest
18-
import warnings
1918
from unittest.mock import Mock, patch
2019

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

7170
@patch.dict("os.environ", {OTEL_SDK_DISABLED: "true"})
7271
def test_get_logger_with_sdk_disabled(self):
73-
with warnings.catch_warnings(record=True) as cw:
74-
logger = LoggerProvider().get_logger(Mock())
72+
logger = LoggerProvider().get_logger(Mock())
7573

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

8076
@patch.object(Resource, "create")
8177
def test_logger_provider_init(self, resource_patch):

0 commit comments

Comments
 (0)