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 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