We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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":
    ...
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `opentelemetry-api/src/opentelemetry/configuration/__init__.py`
Content:
```
1 # Copyright The OpenTelemetry Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 # FIXME find a better way to avoid all those "Expression has type "Any"" errors
16 # type: ignore
17 
18 """
19 Simple configuration manager
20 
21 This is a configuration manager for OpenTelemetry. It reads configuration
22 values from environment variables prefixed with ``OPENTELEMETRY_PYTHON_`` whose
23 characters are only alphanumeric characters and unserscores, except for the
24 first character after ``OPENTELEMETRY_PYTHON_`` which must not be a number.
25 
26 For example, these environment variables will be read:
27 
28 1. ``OPENTELEMETRY_PYTHON_SOMETHING``
29 2. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_``
30 3. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND__ELSE``
31 4. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND_else``
32 5. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND_else2``
33 
34 These won't:
35 
36 1. ``OPENTELEMETRY_PYTH_SOMETHING``
37 2. ``OPENTELEMETRY_PYTHON_2_SOMETHING_AND__ELSE``
38 3. ``OPENTELEMETRY_PYTHON_SOMETHING_%_ELSE``
39 
40 The values stored in the environment variables can be found in an instance of
41 ``opentelemetry.configuration.Configuration``. This class can be instantiated
42 freely because instantiating it returns always the same object.
43 
44 For example, if the environment variable
45 ``OPENTELEMETRY_PYTHON_METER_PROVIDER`` value is ``my_meter_provider``, then
46 ``Configuration().meter_provider == "my_meter_provider"`` would be ``True``.
47 
48 Non defined attributes will always return ``None``. This is intended to make it
49 easier to use the ``Configuration`` object in actual code, because it won't be
50 necessary to check for the attribute to be defined first.
51 
52 Environment variables used by OpenTelemetry
53 -------------------------------------------
54 
55 1. OPENTELEMETRY_PYTHON_METER_PROVIDER
56 2. OPENTELEMETRY_PYTHON_TRACER_PROVIDER
57 
58 The value of these environment variables should be the name of the entry point
59 that points to the class that implements either provider. This OpenTelemetry
60 API package provides one entry point for each, which can be found in the
61 setup.py file::
62 
63     entry_points={
64         ...
65         "opentelemetry_meter_provider": [
66             "default_meter_provider = "
67             "opentelemetry.metrics:DefaultMeterProvider"
68         ],
69         "opentelemetry_tracer_provider": [
70             "default_tracer_provider = "
71             "opentelemetry.trace:DefaultTracerProvider"
72         ],
73     }
74 
75 To use the meter provider above, then the
76 ``OPENTELEMETRY_PYTHON_METER_PROVIDER`` should be set to
77 ``"default_meter_provider"`` (this is not actually necessary since the
78 OpenTelemetry API provided providers are the default ones used if no
79 configuration is found in the environment variables).
80 
81 This object can be used by any OpenTelemetry component, native or external.
82 For that reason, the ``Configuration`` object is designed to be immutable.
83 If a component would change the value of one of the ``Configuration`` object
84 attributes then another component that relied on that value may break, leading
85 to bugs that are very hard to debug. To avoid this situation, the preferred
86 approach for components that need a different value than the one provided by
87 the ``Configuration`` object is to implement a mechanism that allows the user
88 to override this value instead of changing it.
89 """
90 
91 from os import environ
92 from re import fullmatch
93 
94 
95 class Configuration:
96     _instance = None
97 
98     __slots__ = []
99 
100     def __new__(cls) -> "Configuration":
101         if Configuration._instance is None:
102 
103             for key, value in environ.items():
104 
105                 match = fullmatch(
106                     r"OPENTELEMETRY_PYTHON_([A-Za-z_][\w_]*)", key
107                 )
108 
109                 if match is not None:
110 
111                     key = match.group(1)
112 
113                     setattr(Configuration, "_{}".format(key), value)
114                     setattr(
115                         Configuration,
116                         key,
117                         property(
118                             fget=lambda cls, key=key: getattr(
119                                 cls, "_{}".format(key)
120                             )
121                         ),
122                     )
123 
124                 Configuration.__slots__.append(key)
125 
126             Configuration.__slots__ = tuple(Configuration.__slots__)
127 
128             Configuration._instance = object.__new__(cls)
129 
130         return cls._instance
131 
132     def __getattr__(self, name):
133         return None
134 
135     @classmethod
136     def _reset(cls):
137         """
138         This method "resets" the global configuration attributes
139 
140         It is not intended to be used by production code but by testing code
141         only.
142         """
143 
144         for slot in cls.__slots__:
145             if slot in cls.__dict__.keys():
146                 delattr(cls, slot)
147                 delattr(cls, "_{}".format(slot))
148 
149         cls.__slots__ = []
150         cls._instance = None
151
```

Path: `ext/opentelemetry-ext-django/src/opentelemetry/ext/django/__init__.py`
Content:
```
1 # Copyright The OpenTelemetry Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 from logging import getLogger
16 
17 from django.conf import settings
18 
19 from opentelemetry.auto_instrumentation.instrumentor import BaseInstrumentor
20 from opentelemetry.configuration import Configuration
21 from opentelemetry.ext.django.middleware import _DjangoMiddleware
22 
23 _logger = getLogger(__name__)
24 
25 
26 class DjangoInstrumentor(BaseInstrumentor):
27     """An instrumentor for Django
28 
29     See `BaseInstrumentor`
30     """
31 
32     _opentelemetry_middleware = ".".join(
33         [_DjangoMiddleware.__module__, _DjangoMiddleware.__qualname__]
34     )
35 
36     def _instrument(self, **kwargs):
37 
38         # FIXME this is probably a pattern that will show up in the rest of the
39         # ext. Find a better way of implementing this.
40         # FIXME Probably the evaluation of strings into boolean values can be
41         # built inside the Configuration class itself with the magic method
42         # __bool__
43 
44         if Configuration().DJANGO_INSTRUMENT != "True":
45             return
46 
47         # This can not be solved, but is an inherent problem of this approach:
48         # the order of middleware entries matters, and here you have no control
49         # on that:
50         # https://docs.djangoproject.com/en/3.0/topics/http/middleware/#activating-middleware
51         # https://docs.djangoproject.com/en/3.0/ref/middleware/#middleware-ordering
52 
53         settings_middleware = getattr(settings, "MIDDLEWARE", [])
54         settings_middleware.append(self._opentelemetry_middleware)
55 
56         setattr(settings, "MIDDLEWARE", settings_middleware)
57 
58     def _uninstrument(self, **kwargs):
59         settings_middleware = getattr(settings, "MIDDLEWARE", None)
60 
61         # FIXME This is starting to smell like trouble. We have 2 mechanisms
62         # that may make this condition be True, one implemented in
63         # BaseInstrumentor and another one implemented in _instrument. Both
64         # stop _instrument from running and thus, settings_middleware not being
65         # set.
66         if settings_middleware is None or (
67             self._opentelemetry_middleware not in settings_middleware
68         ):
69             return
70 
71         settings_middleware.remove(self._opentelemetry_middleware)
72         setattr(settings, "MIDDLEWARE", settings_middleware)
73
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
         # 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 @@
 
                     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,

{"golden_diff": "diff --git a/ext/opentelemetry-ext-django/src/opentelemetry/ext/django/__init__.py b/ext/opentelemetry-ext-django/src/opentelemetry/ext/django/__init__.py\n--- a/ext/opentelemetry-ext-django/src/opentelemetry/ext/django/__init__.py\n+++ b/ext/opentelemetry-ext-django/src/opentelemetry/ext/django/__init__.py\n@@ -41,7 +41,7 @@\n         # built inside the Configuration class itself with the magic method\n         # __bool__\n \n-        if Configuration().DJANGO_INSTRUMENT != \"True\":\n+        if not Configuration().DJANGO_INSTRUMENT:\n             return\n \n         # This can not be solved, but is an inherent problem of this approach:\ndiff --git a/opentelemetry-api/src/opentelemetry/configuration/__init__.py b/opentelemetry-api/src/opentelemetry/configuration/__init__.py\n--- a/opentelemetry-api/src/opentelemetry/configuration/__init__.py\n+++ b/opentelemetry-api/src/opentelemetry/configuration/__init__.py\n@@ -78,6 +78,11 @@\n OpenTelemetry API provided providers are the default ones used if no\n configuration is found in the environment variables).\n \n+Configuration values that are exactly ``\"True\"`` or ``\"False\"`` will be\n+converted to its boolean values of ``True`` and ``False`` respectively.\n+\n+Configuration values that can be casted to integers or floats will be casted.\n+\n This object can be used by any OpenTelemetry component, native or external.\n For that reason, the ``Configuration`` object is designed to be immutable.\n If a component would change the value of one of the ``Configuration`` object\n@@ -110,6 +115,20 @@\n \n                     key = match.group(1)\n \n+                    if value == \"True\":\n+                        value = True\n+                    elif value == \"False\":\n+                        value = False\n+                    else:\n+                        try:\n+                            value = int(value)\n+                        except ValueError:\n+                            pass\n+                        try:\n+                            value = float(value)\n+                        except ValueError:\n+                            pass\n+\n                     setattr(Configuration, \"_{}\".format(key), value)\n                     setattr(\n                         Configuration,\n", "issue": "Make Configuration object return boolean values\nMany 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\r\nWe could have this:\r\n```python\r\nif Configuration().SOME_CONFIGURATION:\r\n    ...\r\n```\r\nInstead of this:\r\n```python\r\nif Configuration().SOME_CONFIGURATION == \"True\":\r\n    ...\r\n```\r\n\n", "before_files": [{"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n# FIXME find a better way to avoid all those \"Expression has type \"Any\"\" errors\n# type: ignore\n\n\"\"\"\nSimple configuration manager\n\nThis is a configuration manager for OpenTelemetry. It reads configuration\nvalues from environment variables prefixed with ``OPENTELEMETRY_PYTHON_`` whose\ncharacters are only alphanumeric characters and unserscores, except for the\nfirst character after ``OPENTELEMETRY_PYTHON_`` which must not be a number.\n\nFor example, these environment variables will be read:\n\n1. ``OPENTELEMETRY_PYTHON_SOMETHING``\n2. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_``\n3. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND__ELSE``\n4. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND_else``\n5. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND_else2``\n\nThese won't:\n\n1. ``OPENTELEMETRY_PYTH_SOMETHING``\n2. ``OPENTELEMETRY_PYTHON_2_SOMETHING_AND__ELSE``\n3. ``OPENTELEMETRY_PYTHON_SOMETHING_%_ELSE``\n\nThe values stored in the environment variables can be found in an instance of\n``opentelemetry.configuration.Configuration``. This class can be instantiated\nfreely because instantiating it returns always the same object.\n\nFor example, if the environment variable\n``OPENTELEMETRY_PYTHON_METER_PROVIDER`` value is ``my_meter_provider``, then\n``Configuration().meter_provider == \"my_meter_provider\"`` would be ``True``.\n\nNon defined attributes will always return ``None``. This is intended to make it\neasier to use the ``Configuration`` object in actual code, because it won't be\nnecessary to check for the attribute to be defined first.\n\nEnvironment variables used by OpenTelemetry\n-------------------------------------------\n\n1. OPENTELEMETRY_PYTHON_METER_PROVIDER\n2. OPENTELEMETRY_PYTHON_TRACER_PROVIDER\n\nThe value of these environment variables should be the name of the entry point\nthat points to the class that implements either provider. This OpenTelemetry\nAPI package provides one entry point for each, which can be found in the\nsetup.py file::\n\n    entry_points={\n        ...\n        \"opentelemetry_meter_provider\": [\n            \"default_meter_provider = \"\n            \"opentelemetry.metrics:DefaultMeterProvider\"\n        ],\n        \"opentelemetry_tracer_provider\": [\n            \"default_tracer_provider = \"\n            \"opentelemetry.trace:DefaultTracerProvider\"\n        ],\n    }\n\nTo use the meter provider above, then the\n``OPENTELEMETRY_PYTHON_METER_PROVIDER`` should be set to\n``\"default_meter_provider\"`` (this is not actually necessary since the\nOpenTelemetry API provided providers are the default ones used if no\nconfiguration is found in the environment variables).\n\nThis object can be used by any OpenTelemetry component, native or external.\nFor that reason, the ``Configuration`` object is designed to be immutable.\nIf a component would change the value of one of the ``Configuration`` object\nattributes then another component that relied on that value may break, leading\nto bugs that are very hard to debug. To avoid this situation, the preferred\napproach for components that need a different value than the one provided by\nthe ``Configuration`` object is to implement a mechanism that allows the user\nto override this value instead of changing it.\n\"\"\"\n\nfrom os import environ\nfrom re import fullmatch\n\n\nclass Configuration:\n    _instance = None\n\n    __slots__ = []\n\n    def __new__(cls) -> \"Configuration\":\n        if Configuration._instance is None:\n\n            for key, value in environ.items():\n\n                match = fullmatch(\n                    r\"OPENTELEMETRY_PYTHON_([A-Za-z_][\\w_]*)\", key\n                )\n\n                if match is not None:\n\n                    key = match.group(1)\n\n                    setattr(Configuration, \"_{}\".format(key), value)\n                    setattr(\n                        Configuration,\n                        key,\n                        property(\n                            fget=lambda cls, key=key: getattr(\n                                cls, \"_{}\".format(key)\n                            )\n                        ),\n                    )\n\n                Configuration.__slots__.append(key)\n\n            Configuration.__slots__ = tuple(Configuration.__slots__)\n\n            Configuration._instance = object.__new__(cls)\n\n        return cls._instance\n\n    def __getattr__(self, name):\n        return None\n\n    @classmethod\n    def _reset(cls):\n        \"\"\"\n        This method \"resets\" the global configuration attributes\n\n        It is not intended to be used by production code but by testing code\n        only.\n        \"\"\"\n\n        for slot in cls.__slots__:\n            if slot in cls.__dict__.keys():\n                delattr(cls, slot)\n                delattr(cls, \"_{}\".format(slot))\n\n        cls.__slots__ = []\n        cls._instance = None\n", "path": "opentelemetry-api/src/opentelemetry/configuration/__init__.py"}, {"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom logging import getLogger\n\nfrom django.conf import settings\n\nfrom opentelemetry.auto_instrumentation.instrumentor import BaseInstrumentor\nfrom opentelemetry.configuration import Configuration\nfrom opentelemetry.ext.django.middleware import _DjangoMiddleware\n\n_logger = getLogger(__name__)\n\n\nclass DjangoInstrumentor(BaseInstrumentor):\n    \"\"\"An instrumentor for Django\n\n    See `BaseInstrumentor`\n    \"\"\"\n\n    _opentelemetry_middleware = \".\".join(\n        [_DjangoMiddleware.__module__, _DjangoMiddleware.__qualname__]\n    )\n\n    def _instrument(self, **kwargs):\n\n        # FIXME this is probably a pattern that will show up in the rest of the\n        # ext. Find a better way of implementing this.\n        # FIXME Probably the evaluation of strings into boolean values can be\n        # built inside the Configuration class itself with the magic method\n        # __bool__\n\n        if Configuration().DJANGO_INSTRUMENT != \"True\":\n            return\n\n        # This can not be solved, but is an inherent problem of this approach:\n        # the order of middleware entries matters, and here you have no control\n        # on that:\n        # https://docs.djangoproject.com/en/3.0/topics/http/middleware/#activating-middleware\n        # https://docs.djangoproject.com/en/3.0/ref/middleware/#middleware-ordering\n\n        settings_middleware = getattr(settings, \"MIDDLEWARE\", [])\n        settings_middleware.append(self._opentelemetry_middleware)\n\n        setattr(settings, \"MIDDLEWARE\", settings_middleware)\n\n    def _uninstrument(self, **kwargs):\n        settings_middleware = getattr(settings, \"MIDDLEWARE\", None)\n\n        # FIXME This is starting to smell like trouble. We have 2 mechanisms\n        # that may make this condition be True, one implemented in\n        # BaseInstrumentor and another one implemented in _instrument. Both\n        # stop _instrument from running and thus, settings_middleware not being\n        # set.\n        if settings_middleware is None or (\n            self._opentelemetry_middleware not in settings_middleware\n        ):\n            return\n\n        settings_middleware.remove(self._opentelemetry_middleware)\n        setattr(settings, \"MIDDLEWARE\", settings_middleware)\n", "path": "ext/opentelemetry-ext-django/src/opentelemetry/ext/django/__init__.py"}], "after_files": [{"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n# FIXME find a better way to avoid all those \"Expression has type \"Any\"\" errors\n# type: ignore\n\n\"\"\"\nSimple configuration manager\n\nThis is a configuration manager for OpenTelemetry. It reads configuration\nvalues from environment variables prefixed with ``OPENTELEMETRY_PYTHON_`` whose\ncharacters are only alphanumeric characters and unserscores, except for the\nfirst character after ``OPENTELEMETRY_PYTHON_`` which must not be a number.\n\nFor example, these environment variables will be read:\n\n1. ``OPENTELEMETRY_PYTHON_SOMETHING``\n2. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_``\n3. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND__ELSE``\n4. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND_else``\n5. ``OPENTELEMETRY_PYTHON_SOMETHING_ELSE_AND_else2``\n\nThese won't:\n\n1. ``OPENTELEMETRY_PYTH_SOMETHING``\n2. ``OPENTELEMETRY_PYTHON_2_SOMETHING_AND__ELSE``\n3. ``OPENTELEMETRY_PYTHON_SOMETHING_%_ELSE``\n\nThe values stored in the environment variables can be found in an instance of\n``opentelemetry.configuration.Configuration``. This class can be instantiated\nfreely because instantiating it returns always the same object.\n\nFor example, if the environment variable\n``OPENTELEMETRY_PYTHON_METER_PROVIDER`` value is ``my_meter_provider``, then\n``Configuration().meter_provider == \"my_meter_provider\"`` would be ``True``.\n\nNon defined attributes will always return ``None``. This is intended to make it\neasier to use the ``Configuration`` object in actual code, because it won't be\nnecessary to check for the attribute to be defined first.\n\nEnvironment variables used by OpenTelemetry\n-------------------------------------------\n\n1. OPENTELEMETRY_PYTHON_METER_PROVIDER\n2. OPENTELEMETRY_PYTHON_TRACER_PROVIDER\n\nThe value of these environment variables should be the name of the entry point\nthat points to the class that implements either provider. This OpenTelemetry\nAPI package provides one entry point for each, which can be found in the\nsetup.py file::\n\n    entry_points={\n        ...\n        \"opentelemetry_meter_provider\": [\n            \"default_meter_provider = \"\n            \"opentelemetry.metrics:DefaultMeterProvider\"\n        ],\n        \"opentelemetry_tracer_provider\": [\n            \"default_tracer_provider = \"\n            \"opentelemetry.trace:DefaultTracerProvider\"\n        ],\n    }\n\nTo use the meter provider above, then the\n``OPENTELEMETRY_PYTHON_METER_PROVIDER`` should be set to\n``\"default_meter_provider\"`` (this is not actually necessary since the\nOpenTelemetry API provided providers are the default ones used if no\nconfiguration is found in the environment variables).\n\nConfiguration values that are exactly ``\"True\"`` or ``\"False\"`` will be\nconverted to its boolean values of ``True`` and ``False`` respectively.\n\nConfiguration values that can be casted to integers or floats will be casted.\n\nThis object can be used by any OpenTelemetry component, native or external.\nFor that reason, the ``Configuration`` object is designed to be immutable.\nIf a component would change the value of one of the ``Configuration`` object\nattributes then another component that relied on that value may break, leading\nto bugs that are very hard to debug. To avoid this situation, the preferred\napproach for components that need a different value than the one provided by\nthe ``Configuration`` object is to implement a mechanism that allows the user\nto override this value instead of changing it.\n\"\"\"\n\nfrom os import environ\nfrom re import fullmatch\n\n\nclass Configuration:\n    _instance = None\n\n    __slots__ = []\n\n    def __new__(cls) -> \"Configuration\":\n        if Configuration._instance is None:\n\n            for key, value in environ.items():\n\n                match = fullmatch(\n                    r\"OPENTELEMETRY_PYTHON_([A-Za-z_][\\w_]*)\", key\n                )\n\n                if match is not None:\n\n                    key = match.group(1)\n\n                    if value == \"True\":\n                        value = True\n                    elif value == \"False\":\n                        value = False\n                    else:\n                        try:\n                            value = int(value)\n                        except ValueError:\n                            pass\n                        try:\n                            value = float(value)\n                        except ValueError:\n                            pass\n\n                    setattr(Configuration, \"_{}\".format(key), value)\n                    setattr(\n                        Configuration,\n                        key,\n                        property(\n                            fget=lambda cls, key=key: getattr(\n                                cls, \"_{}\".format(key)\n                            )\n                        ),\n                    )\n\n                Configuration.__slots__.append(key)\n\n            Configuration.__slots__ = tuple(Configuration.__slots__)\n\n            Configuration._instance = object.__new__(cls)\n\n        return cls._instance\n\n    def __getattr__(self, name):\n        return None\n\n    @classmethod\n    def _reset(cls):\n        \"\"\"\n        This method \"resets\" the global configuration attributes\n\n        It is not intended to be used by production code but by testing code\n        only.\n        \"\"\"\n\n        for slot in cls.__slots__:\n            if slot in cls.__dict__.keys():\n                delattr(cls, slot)\n                delattr(cls, \"_{}\".format(slot))\n\n        cls.__slots__ = []\n        cls._instance = None\n", "path": "opentelemetry-api/src/opentelemetry/configuration/__init__.py"}, {"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom logging import getLogger\n\nfrom django.conf import settings\n\nfrom opentelemetry.auto_instrumentation.instrumentor import BaseInstrumentor\nfrom opentelemetry.configuration import Configuration\nfrom opentelemetry.ext.django.middleware import _DjangoMiddleware\n\n_logger = getLogger(__name__)\n\n\nclass DjangoInstrumentor(BaseInstrumentor):\n    \"\"\"An instrumentor for Django\n\n    See `BaseInstrumentor`\n    \"\"\"\n\n    _opentelemetry_middleware = \".\".join(\n        [_DjangoMiddleware.__module__, _DjangoMiddleware.__qualname__]\n    )\n\n    def _instrument(self, **kwargs):\n\n        # FIXME this is probably a pattern that will show up in the rest of the\n        # ext. Find a better way of implementing this.\n        # FIXME Probably the evaluation of strings into boolean values can be\n        # built inside the Configuration class itself with the magic method\n        # __bool__\n\n        if not Configuration().DJANGO_INSTRUMENT:\n            return\n\n        # This can not be solved, but is an inherent problem of this approach:\n        # the order of middleware entries matters, and here you have no control\n        # on that:\n        # https://docs.djangoproject.com/en/3.0/topics/http/middleware/#activating-middleware\n        # https://docs.djangoproject.com/en/3.0/ref/middleware/#middleware-ordering\n\n        settings_middleware = getattr(settings, \"MIDDLEWARE\", [])\n        settings_middleware.append(self._opentelemetry_middleware)\n\n        setattr(settings, \"MIDDLEWARE\", settings_middleware)\n\n    def _uninstrument(self, **kwargs):\n        settings_middleware = getattr(settings, \"MIDDLEWARE\", None)\n\n        # FIXME This is starting to smell like trouble. We have 2 mechanisms\n        # that may make this condition be True, one implemented in\n        # BaseInstrumentor and another one implemented in _instrument. Both\n        # stop _instrument from running and thus, settings_middleware not being\n        # set.\n        if settings_middleware is None or (\n            self._opentelemetry_middleware not in settings_middleware\n        ):\n            return\n\n        settings_middleware.remove(self._opentelemetry_middleware)\n        setattr(settings, \"MIDDLEWARE\", settings_middleware)\n", "path": "ext/opentelemetry-ext-django/src/opentelemetry/ext/django/__init__.py"}]}