Repository: open-telemetry/opentelemetry-python

Issue:
Make Configuration object return boolean values
Many times, configuration values are just boolean values. The `Configuration` object now only returns the literal configuration value. It would be useful to have this object return `True` instead of `"True"` to keep code a bit shorter
We could have this:
```python
if Configuration().SOME_CONFIGURATION:
    ...
```
Instead of this:
```python
if Configuration().SOME_CONFIGURATION == "True":
    ...
```



Discussion:
What about integer types as well?

Resolving patch:
diff --git a/ext/opentelemetry-ext-django/src/opentelemetry/ext/django/__init__.py b/ext/opentelemetry-ext-django/src/opentelemetry/ext/django/__init__.py
--- a/ext/opentelemetry-ext-django/src/opentelemetry/ext/django/__init__.py
+++ b/ext/opentelemetry-ext-django/src/opentelemetry/ext/django/__init__.py
@@ -41,7 +41,7 @@ def _instrument(self, **kwargs):
         # built inside the Configuration class itself with the magic method
         # __bool__
 
-        if Configuration().DJANGO_INSTRUMENT != "True":
+        if not Configuration().DJANGO_INSTRUMENT:
             return
 
         # This can not be solved, but is an inherent problem of this approach:
diff --git a/opentelemetry-api/src/opentelemetry/configuration/__init__.py b/opentelemetry-api/src/opentelemetry/configuration/__init__.py
--- a/opentelemetry-api/src/opentelemetry/configuration/__init__.py
+++ b/opentelemetry-api/src/opentelemetry/configuration/__init__.py
@@ -78,6 +78,11 @@
 OpenTelemetry API provided providers are the default ones used if no
 configuration is found in the environment variables).
 
+Configuration values that are exactly ``"True"`` or ``"False"`` will be
+converted to its boolean values of ``True`` and ``False`` respectively.
+
+Configuration values that can be casted to integers or floats will be casted.
+
 This object can be used by any OpenTelemetry component, native or external.
 For that reason, the ``Configuration`` object is designed to be immutable.
 If a component would change the value of one of the ``Configuration`` object
@@ -110,6 +115,20 @@ def __new__(cls) -> "Configuration":
 
                     key = match.group(1)
 
+                    if value == "True":
+                        value = True
+                    elif value == "False":
+                        value = False
+                    else:
+                        try:
+                            value = int(value)
+                        except ValueError:
+                            pass
+                        try:
+                            value = float(value)
+                        except ValueError:
+                            pass
+
                     setattr(Configuration, "_{}".format(key), value)
                     setattr(
                         Configuration,


Test patch:
diff --git a/opentelemetry-api/tests/configuration/test_configuration.py b/opentelemetry-api/tests/configuration/test_configuration.py
--- a/opentelemetry-api/tests/configuration/test_configuration.py
+++ b/opentelemetry-api/tests/configuration/test_configuration.py
@@ -88,3 +88,58 @@ def test_reset(self):
         self.assertIsNone(
             Configuration().TRACER_PROVIDER
         )  # pylint: disable=no-member
+
+    @patch.dict(
+        "os.environ",  # type: ignore
+        {
+            "OPENTELEMETRY_PYTHON_TRUE": "True",
+            "OPENTELEMETRY_PYTHON_FALSE": "False",
+        },
+    )
+    def test_boolean(self):
+        self.assertIsInstance(
+            Configuration().TRUE, bool
+        )  # pylint: disable=no-member
+        self.assertIsInstance(
+            Configuration().FALSE, bool
+        )  # pylint: disable=no-member
+        self.assertTrue(Configuration().TRUE)  # pylint: disable=no-member
+        self.assertFalse(Configuration().FALSE)  # pylint: disable=no-member
+
+    @patch.dict(
+        "os.environ",  # type: ignore
+        {
+            "OPENTELEMETRY_PYTHON_POSITIVE_INTEGER": "123",
+            "OPENTELEMETRY_PYTHON_NEGATIVE_INTEGER": "-123",
+            "OPENTELEMETRY_PYTHON_NON_INTEGER": "-12z3",
+        },
+    )
+    def test_integer(self):
+        self.assertEqual(
+            Configuration().POSITIVE_INTEGER, 123
+        )  # pylint: disable=no-member
+        self.assertEqual(
+            Configuration().NEGATIVE_INTEGER, -123
+        )  # pylint: disable=no-member
+        self.assertEqual(
+            Configuration().NON_INTEGER, "-12z3"
+        )  # pylint: disable=no-member
+
+    @patch.dict(
+        "os.environ",  # type: ignore
+        {
+            "OPENTELEMETRY_PYTHON_POSITIVE_FLOAT": "123.123",
+            "OPENTELEMETRY_PYTHON_NEGATIVE_FLOAT": "-123.123",
+            "OPENTELEMETRY_PYTHON_NON_FLOAT": "-12z3.123",
+        },
+    )
+    def test_float(self):
+        self.assertEqual(
+            Configuration().POSITIVE_FLOAT, 123.123
+        )  # pylint: disable=no-member
+        self.assertEqual(
+            Configuration().NEGATIVE_FLOAT, -123.123
+        )  # pylint: disable=no-member
+        self.assertEqual(
+            Configuration().NON_FLOAT, "-12z3.123"
+        )  # pylint: disable=no-member