From addbe306a634dcaf8276050188898c93510371fb Mon Sep 17 00:00:00 2001 From: Eason Chen Date: Sun, 19 Jul 2026 20:51:23 +0800 Subject: [PATCH 1/2] Fix _BaseConfigurator.__new__ crash for subclasses with __init__ arguments object.__new__ raises TypeError when passed extra arguments if __new__ is overridden, so any Configurator subclass defining an __init__ with parameters crashed on first instantiation. Call object.__new__(cls) without forwarding arguments; type.__call__ still passes them to __init__. --- .../opentelemetry/sdk/_configuration/__init__.py | 2 +- opentelemetry-sdk/tests/test_configurator.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index 128c1e22fe..12912a6d04 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -681,7 +681,7 @@ class _BaseConfigurator(ABC): def __new__(cls, *args, **kwargs): if cls._instance is None: - cls._instance = object.__new__(cls, *args, **kwargs) + cls._instance = object.__new__(cls) return cls._instance diff --git a/opentelemetry-sdk/tests/test_configurator.py b/opentelemetry-sdk/tests/test_configurator.py index 694ed3e9e7..ea922049e6 100644 --- a/opentelemetry-sdk/tests/test_configurator.py +++ b/opentelemetry-sdk/tests/test_configurator.py @@ -1487,6 +1487,21 @@ def test_custom_configurator(self, mock_init_comp): } mock_init_comp.assert_called_once_with(**kwargs) + def test_custom_configurator_with_init_args(self): + class ConfiguratorWithArgs(_OTelSDKConfigurator): + def __init__(self, name, strict=False): + super().__init__() + self.name = name + self.strict = strict + + def _configure(self, **kwargs): + pass + + configurator = ConfiguratorWithArgs("TEST_NAME", strict=True) + self.assertEqual(configurator.name, "TEST_NAME") + self.assertTrue(configurator.strict) + self.assertIs(configurator, ConfiguratorWithArgs("TEST_NAME")) + # Any test that calls _init_logging with setup_logging_handler=True # should call _init_logging within this context manager, to From 8db05d8a8e7d7bf600f6a667905a4a0fa8862d0c Mon Sep 17 00:00:00 2001 From: Eason Chen Date: Sun, 19 Jul 2026 20:51:47 +0800 Subject: [PATCH 2/2] Add changelog fragment for #5441 --- .changelog/5441.fixed | 1 + 1 file changed, 1 insertion(+) create mode 100644 .changelog/5441.fixed diff --git a/.changelog/5441.fixed b/.changelog/5441.fixed new file mode 100644 index 0000000000..ee10a97e2c --- /dev/null +++ b/.changelog/5441.fixed @@ -0,0 +1 @@ +`opentelemetry-sdk`: fix `TypeError` when instantiating a `_BaseConfigurator` subclass whose `__init__` takes arguments