From f418d8a05e19ad935d44553301772e25c9bd4412 Mon Sep 17 00:00:00 2001 From: Eason Chen Date: Sun, 19 Jul 2026 20:51:23 +0800 Subject: [PATCH 1/3] 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 acb4ab2febffec70eb47e8e0a0ac75f5a80a653e Mon Sep 17 00:00:00 2001 From: Eason Chen Date: Sun, 19 Jul 2026 20:51:47 +0800 Subject: [PATCH 2/3] 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 From 0f6abda1a6a9f3258619bfb8a938a470747a7d99 Mon Sep 17 00:00:00 2001 From: Eason Chen Date: Thu, 23 Jul 2026 15:44:10 +0800 Subject: [PATCH 3/3] Use super().__new__ instead of hardcoding object in singleton __new__ Follows cooperative multiple inheritance conventions so the MRO's __new__ chain isn't silently skipped if a mixin is added later. Co-authored-by: herin049 <40302054+herin049@users.noreply.github.com> --- .../src/opentelemetry/sdk/_configuration/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index 12912a6d04..d04c476172 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) + cls._instance = super().__new__(cls) return cls._instance